diff options
author | Roozbeh Pournader <roozbeh@google.com> | 2014-07-24 18:33:26 -0700 |
---|---|---|
committer | Roozbeh Pournader <roozbeh@google.com> | 2014-07-24 18:33:26 -0700 |
commit | 3a8f38ed8e34c6021444f2ef43527a8f3ded09df (patch) | |
tree | f7d1946beb7d7e3d58c57384a80045e37d90956e /scripts | |
parent | 4ce7b6f9beeb1fe6e3f227e943a8d05585adce4f (diff) |
Change the width of decimal digits to the same value.
Fixes issue 33, and the following external bugs:
https://code.google.com/p/android-developer-preview/issues/detail?id=330
https://b.corp.google.com/issue?id=16299966
Diffstat (limited to 'scripts')
-rwxr-xr-x | scripts/touchup_for_android.py | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/scripts/touchup_for_android.py b/scripts/touchup_for_android.py index c25f456..8a942d9 100755 --- a/scripts/touchup_for_android.py +++ b/scripts/touchup_for_android.py @@ -1,6 +1,7 @@ #!/usr/bin/python """Post-build changes for Roboto for Android.""" +import collections import os from os import path import sys @@ -26,6 +27,23 @@ def get_font_name(font): return font_data.get_name_records(font)[4] +DIGITS = ['zero', 'one', 'two', 'three', 'four', + 'five', 'six', 'seven', 'eight', 'nine'] + +def fix_digit_widths(font): + """Change all digit widths in the font to be the same.""" + hmtx_table = font['hmtx'] + widths = [hmtx_table[digit][0] for digit in DIGITS] + if len(set(widths)) > 1: + width_counter = collections.Counter(widths) + most_common_width = width_counter.most_common(1)[0][0] + print 'Digit widths were %s.' % repr(widths) + print 'Setting all glyph widths to %d.' % most_common_width + for digit in DIGITS: + assert abs(hmtx_table[digit][0] - most_common_width) <= 1 + hmtx_table[digit][0] = most_common_width + + def apply_temporary_fixes(font): """Apply some temporary fixes.""" @@ -45,6 +63,9 @@ def apply_temporary_fixes(font): # Drop the lookup forming the ff ligature drop_lookup(font['GSUB'], 5) + # Fix the digit widths + fix_digit_widths(font) + # Fix version number from buildnumber.txt from datetime import date |