summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRasmus Andersson <rasmus@notion.se>2022-10-16 02:23:56 +0300
committerRasmus Andersson <rasmus@notion.se>2022-10-16 02:23:56 +0300
commitadf3654b33feafaed1741f8e27c3837c6e12715c (patch)
tree1feacd8c6db37f366fff6ba57d49f8c4b1a65fe1
parent4fd701d52951de68cfb3e56d65e9b038e960c189 (diff)
downloadinter-adf3654b33feafaed1741f8e27c3837c6e12715c.tar.xz
workaround for bug in glyphslib/fontmake that generates UFO glyphs with fractional widths. Closes #508
-rwxr-xr-xmisc/tools/find-ufo-frac-advance-widths.sh15
-rw-r--r--misc/tools/postprocess_instance_ufo.py21
2 files changed, 33 insertions, 3 deletions
diff --git a/misc/tools/find-ufo-frac-advance-widths.sh b/misc/tools/find-ufo-frac-advance-widths.sh
new file mode 100755
index 000000000..5c5c93a7c
--- /dev/null
+++ b/misc/tools/find-ufo-frac-advance-widths.sh
@@ -0,0 +1,15 @@
+#!/bin/bash
+#
+# This script finds UFO glyphs with fractional advance width, which is invalid.
+# See https://github.com/rsms/inter/issues/508
+#
+cd "$(dirname "$0")"/../../build/ufo
+ADVANCES=$(rg 'advance width'|awk 'BEGIN {FS=" "} {print $2}')
+NOTREALLYFLOATS=$((rg '\.0\b'|wc -l) <<< "$ADVANCES")
+FLOATS=$((rg '\.\d+'|wc -l) <<< "$ADVANCES")
+INTS=$((rg -v '\.'|wc -l) <<< "$ADVANCES")
+
+printf "Total: $((INTS+FLOATS)) (sanity: $(wc -l <<< "$ADVANCES"))\nFloats: $((FLOATS-NOTREALLYFLOATS))\nInts: $((INTS+NOTREALLYFLOATS))\n"
+
+echo "Occurance Fraction"
+(rg -o '\.\d{1,12}'|sort|uniq -c) <<< "$ADVANCES"
diff --git a/misc/tools/postprocess_instance_ufo.py b/misc/tools/postprocess_instance_ufo.py
index 26d29aa96..37be67d0f 100644
--- a/misc/tools/postprocess_instance_ufo.py
+++ b/misc/tools/postprocess_instance_ufo.py
@@ -15,12 +15,27 @@ def ufo_set_wws(ufo):
ufo.info.openTypeNameWWSSubfamilyName = subfamily
+# See https://github.com/rsms/inter/issues/508
+# TODO: Remove when https://github.com/googlefonts/glyphsLib/issues/821 is fixed
+def fix_fractional_advance_width(ufo):
+ for g in ufo:
+ g.width = round(g.width)
+
+
def main(argv):
ufo_file = argv[1]
- if ufo_file.find("Display") == -1:
- return # skip fonts of "default" family
+
+ # TODO: Uncomment when https://github.com/googlefonts/glyphsLib/issues/821 is fixed
+ # if ufo_file.find("Display") == -1:
+ # return # skip fonts of "default" family
+
ufo = defcon.Font(ufo_file)
- ufo_set_wws(ufo)
+
+ if ufo_file.find("Display") != -1:
+ ufo_set_wws(ufo)
+
+ fix_fractional_advance_width(ufo)
+
ufo.save(ufo_file)