From eaece2cb0d1aa84b7e3316cd2dcd9597c3ff07e8 Mon Sep 17 00:00:00 2001 From: Roozbeh Pournader Date: Thu, 8 Jan 2015 00:33:56 -0800 Subject: More refactoring of touchup and test scripts. --- scripts/common_tests.py | 26 ++++++++++++++++ scripts/run_android_tests.py | 4 +++ scripts/run_web_tests.py | 68 ++++++++++-------------------------------- scripts/temporary_touchups.py | 10 +++++++ scripts/touchup_for_android.py | 18 ----------- scripts/touchup_for_web.py | 5 ---- 6 files changed, 55 insertions(+), 76 deletions(-) diff --git a/scripts/common_tests.py b/scripts/common_tests.py index 8fff95c..b4c0bfa 100644 --- a/scripts/common_tests.py +++ b/scripts/common_tests.py @@ -103,6 +103,23 @@ class TestMetaInfo(FontTest): self.assertEqual(revision, expected_version) +class TestNames(FontTest): + """Tests various strings in the name table.""" + + def setUp(self): + _, self.fonts = self.loaded_fonts + self.names = [] + for font in self.fonts: + self.names.append(font_data.get_name_records(font)) + + def test_copyright(self): + """Tests the copyright message.""" + for records in self.names: + self.assertEqual( + records[0], + 'Copyright 2014 Google Inc. All Rights Reserved.') + + class TestDigitWidths(FontTest): """Tests the width of digits.""" @@ -189,3 +206,12 @@ class TestVerticalMetrics(FontTest): self.assertEqual(head_table.yMin, -555) self.assertEqual(head_table.yMax, 2163) + def test_hhea_table_metrics(self): + """Tests ascent, descent, and lineGap to be equal to Roboto v1 values. + """ + for font in self.fonts: + hhea_table = font['hhea'] + self.assertEqual(hhea_table.descent, -500) + self.assertEqual(hhea_table.ascent, 1900) + self.assertEqual(hhea_table.lineGap, 0) + diff --git a/scripts/run_android_tests.py b/scripts/run_android_tests.py index 060965b..26730b0 100755 --- a/scripts/run_android_tests.py +++ b/scripts/run_android_tests.py @@ -19,6 +19,10 @@ class TestMetaInfo(common_tests.TestMetaInfo): loaded_fonts = FONTS +class TestNames(common_tests.TestNames): + loaded_fonts = FONTS + + class TestDigitWidths(common_tests.TestDigitWidths): loaded_fonts = FONTS diff --git a/scripts/run_web_tests.py b/scripts/run_web_tests.py index 896b450..eae3acf 100755 --- a/scripts/run_web_tests.py +++ b/scripts/run_web_tests.py @@ -1,45 +1,27 @@ #!/usr/bin/python """Test assumptions that web fonts rely on.""" -import glob -import json import unittest -from fontTools import ttLib -from nototools import coverage from nototools import font_data -from nototools import render -from nototools import unicode_data +import common_tests -def load_fonts(): - """Load all web fonts.""" - all_font_files = glob.glob('out/web/*.ttf') - all_fonts = [ttLib.TTFont(font) for font in all_font_files] - assert len(all_font_files) == 18 - return all_font_files, all_fonts +FONTS = common_tests.load_fonts( + ['out/web/*.ttf'], + expected_count=18) +class TestCharacterCoverage(common_tests.TestCharacterCoverage): + loaded_fonts = FONTS + test_inclusion_of_sound_recording_copyright = None -class TestVerticalMetrics(unittest.TestCase): - """Test the vertical metrics of fonts.""" - def setUp(self): - _, self.fonts = load_fonts() - - def test_ymin_ymax(self): - """Tests yMin and yMax to be equal to the old values.""" - for font in self.fonts: - head_table = font['head'] - self.assertEqual(head_table.yMin, -555) - self.assertEqual(head_table.yMax, 2163) +class TestVerticalMetrics(common_tests.TestVerticalMetrics): + loaded_fonts = FONTS - def test_other_metrics(self): - """Tests other vertical metrics to be equal to the old values.""" + def test_os2_metrics(self): + """Tests OS/2 vertical metrics to be equal to the old values.""" for font in self.fonts: - hhea_table = font['hhea'] - self.assertEqual(hhea_table.descent, -500) - self.assertEqual(hhea_table.ascent, 1900) - os2_table = font['OS/2'] self.assertEqual(os2_table.sTypoDescender, -512) self.assertEqual(os2_table.sTypoAscender, 1536) @@ -48,29 +30,9 @@ class TestVerticalMetrics(unittest.TestCase): self.assertEqual(os2_table.usWinAscent, 1946) -class TestCharacterCoverage(unittest.TestCase): - """Tests character coverage.""" - - def setUp(self): - _, self.fonts = load_fonts() - - -class TestNames(unittest.TestCase): - """Tests various strings in the name table.""" - - def setUp(self): - self.family_name = 'RobotoDraft' - _, self.fonts = load_fonts() - self.names = [] - for font in self.fonts: - self.names.append(font_data.get_name_records(font)) - - def test_copyright(self): - """Tests the copyright message.""" - for records in self.names: - self.assertEqual( - records[0], - 'Copyright 2014 Google Inc. All Rights Reserved.') +class TestNames(common_tests.TestNames): + loaded_fonts = FONTS + family_name = 'RobotoDraft' def test_family_name(self): """Tests the family name.""" @@ -98,7 +60,7 @@ class TestHints(unittest.TestCase): """Tests hints.""" def setUp(self): - _, self.fonts = load_fonts() + _, self.fonts = FONTS def test_existance_of_hints(self): """Tests all glyphs and makes sure non-composite ones have hints.""" diff --git a/scripts/temporary_touchups.py b/scripts/temporary_touchups.py index 7971e23..189a6e1 100644 --- a/scripts/temporary_touchups.py +++ b/scripts/temporary_touchups.py @@ -21,3 +21,13 @@ def apply_temporary_fixes(font): font_data.set_name_record(font, 5, version_record) font['head'].fontRevision = float(version_number) + # Set ascent, descent, and lineGap values to Android K values + hhea = font['hhea'] + hhea.ascent = 1900 + hhea.descent = -500 + hhea.lineGap = 0 + + # Copyright message + font_data.set_name_record( + font, 0, 'Copyright 2014 Google Inc. All Rights Reserved.') + diff --git a/scripts/touchup_for_android.py b/scripts/touchup_for_android.py index 76a39ae..d811303 100755 --- a/scripts/touchup_for_android.py +++ b/scripts/touchup_for_android.py @@ -9,26 +9,8 @@ from nototools import font_data import temporary_touchups -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. - """ - for feature in table.table.FeatureList.FeatureRecord: - if lookup_number in feature.Feature.LookupListIndex: - feature.Feature.LookupListIndex.remove(lookup_number) - feature.Feature.LookupCount -= 1 - - 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 tab, combining keycap, and the arrows from the cmap table. # # Arrows are removed to maximize consistency of arrows, since the rest diff --git a/scripts/touchup_for_web.py b/scripts/touchup_for_web.py index a5a282c..d0efddc 100755 --- a/scripts/touchup_for_web.py +++ b/scripts/touchup_for_web.py @@ -33,11 +33,6 @@ def apply_web_specific_fixes(font, family_name): 'Bold', 'Bold Italic', 'Black', 'Black Italic']) full_name = family_name + ' ' + subfamily_name - year = '2014' - - # Copyright message - font_data.set_name_record( - font, 0, 'Copyright %s Google Inc. All Rights Reserved.' % year) # Family name font_data.set_name_record(font, 1, family_name) -- cgit v1.2.3