Skip to content

Instantly share code, notes, and snippets.

View behdad's full-sized avatar
🦋

Behdad Esfahbod behdad

🦋
View GitHub Profile
@behdad
behdad / reproduce.sh
Last active March 22, 2025 01:43
Memory usage of loading glyph outlines
#!/bin/bash
export FONT_FILE=/path/to/RobotoFlex.ttf
git clone https://github.com/behdad/malloc-stats
(cd malloc-stats && make)
git clone https://github.com/harfbuzz/harfbuzz
cd harfbuzz
cp ../malloc-stats/malloc-stats.so .
meson build -Dglib=disabled -Dfreetype=enabled -Dfontations=enabled -Dbenchmark=enabled
@behdad
behdad / pingfangui.html
Last active October 12, 2024 16:13
PingFang UI font animation
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Unicode Character Weight Animation</title>
<style>
@keyframes weightAnimation {
0% {
font-weight: 100;
@behdad
behdad / gist:d08f958f8a5e2cb6badf6e32598427df
Created August 18, 2020 17:48
2016-02-13 Peter Constable opentype-layout smoking-gun message
Vlad:
I don’t see any attachment, and I have no idea what is in this amendment other than the little I glean from glancing over this thread.
Actually, I have no idea what’s been going into OFF for some time, though granted, I was out of this space for a while and only came back into it in the past year or so. However, I’ve been working on the DirectWrite platform in Windows during this time, and can say I’m not aware of anything that has gone into DirectWrite in that time that pertains to recent amendments to OFF except, perhaps, things related to USE. (DWrite has been picking up our shaping library from Andrew’s team.)
My concern is with changes going into OFF without knowing what the status is of platforms that actually implement support for OpenType fonts. And quite frankly, I’m SHOCKED to see that there are changes to the OS/2 table being rushed into OFF that Microsoft has not review.
I don’t see any indication of discussion in this list of a new OS/2 version with a usTypoWeightClass field. This mail thre

Keybase proof

I hereby claim:

  • I am behdad on github.
  • I am behdad (https://keybase.io/behdad) on keybase.
  • I have a public key whose fingerprint is C115 E6AE D747 7C7B DFC7 0F94 A426 3A73 9C48 7211

To claim this, I am signing this object:

@behdad
behdad / py
Created June 2, 2020 17:11
unionfind.py
from __future__ import print_function, division, absolute_import
#from fontTools.misc.py23 import *
class UnionFind(object):
def __init__(self, items):
self._sets = dict((x,set([x])) for x in items)
self._map = dict((x,x) for x in items)
def _union_pair(self, a, b):
diff --cc src/hb-ot-layout-gsub-table.hh
index 364ef189,364ef189..4de505aa
--- a/src/hb-ot-layout-gsub-table.hh
+++ b/src/hb-ot-layout-gsub-table.hh
@@@ -899,8 -899,8 +899,31 @@@ struct LigatureSubstFormat
bool subset (hb_subset_context_t *c) const
{
TRACE_SUBSET (this);
-- // TODO(subset)
-- return_trace (false);
diff --git a/Lib/fontTools/subset/__init__.py b/Lib/fontTools/subset/__init__.py
index 2ed17cc9..22d1e371 100644
--- a/Lib/fontTools/subset/__init__.py
+++ b/Lib/fontTools/subset/__init__.py
@@ -1719,6 +1719,8 @@ def subset_glyphs(self, s):
@_add_method(ttLib.getTableClass('hmtx'))
def subset_glyphs(self, s):
self.metrics = _dict_subset(self.metrics, s.glyphs)
+ for g in s.glyphs_emptied:
+ self.metrics[g] = (0,0)
diff --git a/Lib/fontTools/varLib/__init__.py b/Lib/fontTools/varLib/__init__.py
index 5f0f9bd2..1fd0320b 100644
--- a/Lib/fontTools/varLib/__init__.py
+++ b/Lib/fontTools/varLib/__init__.py
@@ -289,7 +289,10 @@ def _add_gvar(font, model, master_ttfs, tolerance=0.5, optimize=True):
gvar.reserved = 0
gvar.variations = {}
- for glyph in font.getGlyphOrder():
+ glyphs = font.getGlyphOrder()
/* Simple example to use pangocairo to render rotated text */
#include <math.h>
#include <pango/pangocairo.h>
static void
draw_text (cairo_t *cr)
{
#define RADIUS 200
#define N_WORDS 20
#!/bin/bash
time for x in */img*.jpg; do
out=`dirname $x`/4`basename $x`
if test -f $out; then
echo Skipping $x
else
echo $x
time convert -geometry 25% \
-pointsize 36 -fill white \