diff options
Diffstat (limited to 'scripts')
-rw-r--r-- | scripts/roboto_data.py | 27 | ||||
-rwxr-xr-x | scripts/run_android_tests.py | 22 | ||||
-rw-r--r-- | scripts/temporary_touchups.py | 14 | ||||
-rwxr-xr-x | scripts/touchup_for_android.py | 18 |
4 files changed, 76 insertions, 5 deletions
diff --git a/scripts/roboto_data.py b/scripts/roboto_data.py new file mode 100644 index 0000000..ef2a773 --- /dev/null +++ b/scripts/roboto_data.py @@ -0,0 +1,27 @@ +#!/usr/bin/python +"""Post-build changes for Roboto for Android.""" + +import re + +WEIGHTS = { + 'Thin': 250, + 'Light': 300, + 'Regular': 400, + 'Medium': 500, + 'Bold': 700, + 'Black': 900, +} + +_ALL_WEIGHTS_RE = re.compile( + '(' + '|'.join(WEIGHTS.keys()) + ')' +) + + +def extract_weight_name(font_name): + """Extracts the weight part of the name from a font name.""" + match = re.search(_ALL_WEIGHTS_RE, font_name) + if match is None: + assert font_name in ['Roboto Italic', 'Roboto Condensed Italic'] + return 'Regular' + else: + return match.group(1) diff --git a/scripts/run_android_tests.py b/scripts/run_android_tests.py index adb2c06..1c9e45c 100755 --- a/scripts/run_android_tests.py +++ b/scripts/run_android_tests.py @@ -11,6 +11,8 @@ from nototools import font_data from nototools import render from nototools import unicode_data +import roboto_data + def load_fonts(): """Load all fonts built for Android.""" @@ -20,6 +22,22 @@ def load_fonts(): return all_font_files, all_fonts +class TestMetaInfo(unittest.TestCase): + """Test various meta information.""" + + def setUp(self): + _, self.fonts = load_fonts() + + def test_us_weight(self): + "Tests the usWeight of the fonts to be correct.""" + for font in self.fonts: + weight = roboto_data.extract_weight_name(font_data.font_name(font)) + expected_numeric_weight = roboto_data.WEIGHTS[weight] + self.assertEqual( + font['OS/2'].usWeightClass, + expected_numeric_weight) + + class TestVerticalMetrics(unittest.TestCase): """Test the vertical metrics of fonts.""" @@ -108,6 +126,10 @@ class TestSpacingMarks(unittest.TestCase): u'\u03D2'): print 'Testing %s combinations' % base_letter for mark in self.marks_to_test: + if mark == 0x02DE: + # Skip rhotic hook, as it's perhaps OK for it to form + # ligatures + continue mark = unichr(mark) advances = self.get_advances(base_letter + mark, font) self.assertEqual(len(advances), 2, diff --git a/scripts/temporary_touchups.py b/scripts/temporary_touchups.py new file mode 100644 index 0000000..1891bc2 --- /dev/null +++ b/scripts/temporary_touchups.py @@ -0,0 +1,14 @@ +#!/usr/bin/python +"""Temporary post-build changes for Roboto.""" + +from nototools import font_data + +import roboto_data + +def apply_temporary_fixes(font): + """Apply some temporary fixes.""" + # Fix usWeight: + font_name = font_data.font_name(font) + weight = roboto_data.extract_weight_name(font_name) + weight_number = roboto_data.WEIGHTS[weight] + font['OS/2'].usWeightClass = weight_number diff --git a/scripts/touchup_for_android.py b/scripts/touchup_for_android.py index 7c1a5d3..8019852 100755 --- a/scripts/touchup_for_android.py +++ b/scripts/touchup_for_android.py @@ -10,6 +10,8 @@ from fontTools import ttLib from nototools import font_data from nototools import unicode_data +import temporary_touchups + def drop_lookup(table, lookup_number): """Drop a lookup from an OpenType table by number. @@ -149,13 +151,19 @@ def apply_android_specific_fixes(font): hhea.descent = -500 hhea.lineGap = 0 - # Remove tab, combining keycap, the arrows, and unassigned characters - # from the cmap table + # Remove tab, combining keycap, and the arrows from the cmap table. + # + # Arrows are removed to maximize consistency of arrows, since the rest + # of the arrows come from Noto Symbols. + # + # And here are the bugs for the other two issues: # https://code.google.com/a/google.com/p/roboto/issues/detail?id=51 # https://code.google.com/a/google.com/p/roboto/issues/detail?id=52 - # https://code.google.com/a/google.com/p/roboto/issues/detail?id=53 font_data.delete_from_cmap(font, [ - 0x0009, 0x20E3, 0x2072, 0x2073, 0x208F, 0x2191, 0x2193]) + 0x0009, # tab + 0x20E3, # combining keycap + 0x2191, 0x2193, # vertical arrows + ]) # Drop tables not useful on Android for table in ['LTSH', 'hdmx', 'VDMX', 'gasp']: @@ -166,7 +174,7 @@ def apply_android_specific_fixes(font): 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) apply_android_specific_fixes(font) font.save(target_font_name) |