summaryrefslogtreecommitdiff
path: root/scripts/force_yminmax.py
diff options
context:
space:
mode:
authorRoozbeh Pournader <roozbeh@google.com>2014-07-03 23:36:52 -0700
committerRoozbeh Pournader <roozbeh@google.com>2014-07-03 23:36:52 -0700
commit2b5dca5d77e7394df66fa8f2e8a827b1c6fec441 (patch)
tree89c70d0fd07ce51040aacc6c1de6941a4fa82107 /scripts/force_yminmax.py
parentf61afcb339de59c70645c662fb4b72482b02920d (diff)
Rework the font processing for Android.
yMin and yMax values needed for Android are now set after the subsetting in a separate script. The touchup script is also divided into Android-specific changes and general ones.
Diffstat (limited to 'scripts/force_yminmax.py')
-rwxr-xr-xscripts/force_yminmax.py46
1 files changed, 46 insertions, 0 deletions
diff --git a/scripts/force_yminmax.py b/scripts/force_yminmax.py
new file mode 100755
index 0000000..5644fe4
--- /dev/null
+++ b/scripts/force_yminmax.py
@@ -0,0 +1,46 @@
+#!/usr/bin/python
+"""Post-subset changes for Roboto for Android."""
+
+import sys
+
+from fontTools import ttLib
+
+
+def output_protruding_glyphs(font, ymin, ymax, file_name):
+ """Outputs all glyphs going outside the specified vertical range."""
+ protruding_glyphs = []
+ glyph_dict = font['glyf'].glyphs
+ for glyph_name, glyph in glyph_dict.items():
+ if glyph.numberOfContours == 0:
+ continue
+ if glyph.yMin < ymin or glyph.yMax > ymax:
+ protruding_glyphs.append(glyph_name)
+ if protruding_glyphs:
+ print "Protruding glyphs in %s:" % file_name,
+ print ', '.join(sorted(protruding_glyphs))
+
+
+YMIN = -555
+YMAX = 2163
+
+def main(argv):
+ """Forces yMin/yMax values and generates a new font."""
+ source_font_name = argv[1]
+ target_font_name = argv[2]
+ font = ttLib.TTFont(source_font_name, recalcBBoxes=False)
+
+ head = font['head']
+ head.yMin = YMIN
+ head.yMax = YMAX
+ output_protruding_glyphs(font, YMIN, YMAX, source_font_name)
+
+ font.save(target_font_name)
+
+ # Make sure the values are set correctly
+ font = ttLib.TTFont(target_font_name, recalcBBoxes=False)
+ head = font['head']
+ assert head.yMin == YMIN and head.yMax == YMAX
+
+
+if __name__ == "__main__":
+ main(sys.argv)