summaryrefslogtreecommitdiff
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
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.
-rw-r--r--Makefile16
-rw-r--r--res/buildnumber.txt2
-rwxr-xr-xscripts/force_yminmax.py46
-rwxr-xr-xscripts/touchup_for_android.py85
4 files changed, 95 insertions, 54 deletions
diff --git a/Makefile b/Makefile
index d5cb739..af719f0 100644
--- a/Makefile
+++ b/Makefile
@@ -28,11 +28,13 @@ mono:
open -nWa "$(FONTLAB)" /tmp/makefonts.flw
android:
- rm -rf out/android/temp
- mkdir --parents out/android/temp
- for f in out/RobotoTTF/*.ttf out/RobotoCondensedTTF/*.ttf; do \
- temp_location=out/android/temp/$$(basename $$f); \
- final_location=out/android/$$(basename $$f); \
- python scripts/touchup_for_android.py $$f $$temp_location; \
- python $$HOME/noto/nototools/subset.py $$temp_location $$final_location; \
+ mkdir -p out/android
+ for source in out/RobotoTTF/*.ttf out/RobotoCondensedTTF/*.ttf; do \
+ touched=$$(mktemp); \
+ subsetted=$$(mktemp); \
+ final=out/android/$$(basename $$source); \
+ python scripts/touchup_for_android.py $$source $$touched; \
+ python $$HOME/noto/nototools/subset.py $$touched $$subsetted; \
+ python scripts/force_yminmax.py $$subsetted $$final; \
+ rm $$touched $$subsetted; \
done
diff --git a/res/buildnumber.txt b/res/buildnumber.txt
index 20094a6..dc4e0d2 100644
--- a/res/buildnumber.txt
+++ b/res/buildnumber.txt
@@ -1 +1 @@
-00982 \ No newline at end of file
+00983 \ No newline at end of file
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)
diff --git a/scripts/touchup_for_android.py b/scripts/touchup_for_android.py
index 8bcfc14..c25f456 100755
--- a/scripts/touchup_for_android.py
+++ b/scripts/touchup_for_android.py
@@ -9,22 +9,9 @@ from fontTools import ttLib
from nototools import font_data
-def output_protruding_glyphs(font, ymin, ymax, file_name):
- 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))
-
-
def drop_lookup(table, lookup_number):
"""Drop a lookup from an OpenType table by number.
-
+
Actually remove pointers from features to the lookup, which should be less
intrusive.
"""
@@ -34,19 +21,29 @@ def drop_lookup(table, lookup_number):
feature.Feature.LookupCount -= 1
+def get_font_name(font):
+ """Gets the name of the font from the name table."""
+ return font_data.get_name_records(font)[4]
+
+
def apply_temporary_fixes(font):
- """Apply some temporary fixes needed for Android."""
+ """Apply some temporary fixes."""
+
+ # Make sure macStyle is correct
+ font_name = get_font_name(font)
+ bold = ('Bold' in font_name) or ('Black' in font_name)
+ italic = 'Italic' in font_name
+ font['head'].macStyle = (italic << 1) | bold
+
+ # Mark the font free for installation, embedding, etc.
+ os2 = font['OS/2']
+ os2.fsType = 0
+
+ # Set the font vendor to Google
+ os2.achVendID = 'GOOG'
- # Remove tab, combining keycap, and the arrows from the cmap table
- font_data.delete_from_cmap(font, [0x0009, 0x20E3, 0x2191, 0x2193])
-
# Drop the lookup forming the ff ligature
drop_lookup(font['GSUB'], 5)
-
- # Drop tables not useful on Android
- for table in ['LTSH', 'hdmx', 'VDMX', 'gasp']:
- if table in font:
- del font[table]
# Fix version number from buildnumber.txt
from datetime import date
@@ -54,7 +51,9 @@ def apply_temporary_fixes(font):
build_number_txt = path.join(
path.dirname(__file__), os.pardir, 'res', 'buildnumber.txt')
build_number = open(build_number_txt).read().strip()
+
version_record = 'Version 2.0%s; %d' % (build_number, date.today().year)
+
for record in font['name'].names:
if record.nameID == 5:
if record.platformID == 1 and record.platEncID == 0: # MacRoman
@@ -66,34 +65,28 @@ def apply_temporary_fixes(font):
assert False
-def correct_font(source_font_name, target_font_name):
- """Corrects metrics and other meta information."""
- font = ttLib.TTFont(source_font_name)
-
- YMAX = 2163
- YMIN = -555
-
- head = font['head']
- head.yMax = YMAX
- head.yMin = YMIN
- output_protruding_glyphs(font, YMIN, YMAX, source_font_name)
-
+def apply_android_specific_fixes(font):
+ """Apply fixes needed for Android."""
+ # Set ascent, descent, and lineGap values to Android K values
hhea = font['hhea']
hhea.ascent = 1900
hhea.descent = -500
hhea.lineGap = 0
-
- basename = path.basename(source_font_name)
- bold = ('Bold' in basename) or ('Black' in basename)
- italic = 'Italic' in basename
- head.macStyle = (italic << 1) | bold
-
- os2 = font['OS/2']
- os2.fsType = 0
- os2.achVendID = 'GOOG'
-
+
+ # Remove tab, combining keycap, and the arrows from the cmap table
+ font_data.delete_from_cmap(font, [0x0009, 0x20E3, 0x2191, 0x2193])
+
+ # Drop tables not useful on Android
+ for table in ['LTSH', 'hdmx', 'VDMX', 'gasp']:
+ if table in font:
+ del font[table]
+
+
+def correct_font(source_font_name, target_font_name):
+ """Corrects metrics and other meta information."""
+ font = ttLib.TTFont(source_font_name)
apply_temporary_fixes(font)
-
+ apply_android_specific_fixes(font)
font.save(target_font_name)