diff options
Diffstat (limited to 'scripts/touchup_for_android.py')
-rwxr-xr-x | scripts/touchup_for_android.py | 51 |
1 files changed, 10 insertions, 41 deletions
diff --git a/scripts/touchup_for_android.py b/scripts/touchup_for_android.py index e13adea..9855717 100755 --- a/scripts/touchup_for_android.py +++ b/scripts/touchup_for_android.py @@ -16,44 +16,16 @@ """Post-build changes for Roboto for Android.""" -import os -from os import path import sys from fontTools import ttLib from nototools import font_data - -def apply_temporary_fixes(font): - """Apply some temporary fixes. - """ - # Fix version number from buildnumber.txt - from datetime import date - - 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.%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 - record.string = version_record - elif record.platformID == 3 and record.platEncID == 1: - # Windows UCS-2 - record.string = version_record.encode('UTF-16BE') - else: - assert False +import temporary_touchups 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 # Remove combining keycap and the arrows from the cmap table: # https://github.com/google/roboto/issues/99 @@ -68,23 +40,20 @@ def apply_android_specific_fixes(font): if table in font: del font[table] - # Set bold bits for Black (macStyle bit 0, fsSelection bit 5, subfamily) - name_records = font_data.get_name_records(font) - family_name = name_records[1] - subfam_name = name_records[2] - if family_name.endswith('Black'): - font['head'].macStyle |= (1 << 0) - font['OS/2'].fsSelection |= (1 << 5) - font['OS/2'].fsSelection &= ~(1 << 6) - new_subfam_name = ( - ('Bold ' + subfam_name) if subfam_name != 'Regular' else 'Bold') - font_data.set_name_record(font, 2, new_subfam_name) + # turn off round-to-grid flags in certain problem components + # https://github.com/google/roboto/issues/153 + glyph_set = font.getGlyphSet() + ellipsis = glyph_set['ellipsis']._glyph + for component in ellipsis.components: + component.flags &= ~(1 << 2) 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) + temporary_touchups.apply_temporary_fixes(font) + temporary_touchups.update_version_and_revision(font) apply_android_specific_fixes(font) font.save(target_font_name) |