From a4ef18e29638cd1a0c814adb762177a342898eeb Mon Sep 17 00:00:00 2001 From: Roozbeh Pournader Date: Wed, 29 Apr 2015 14:32:39 -0700 Subject: Add tests for vertical metrics of individual glyphs. The new tests check that every glyph fits in the [yMin, yMax] range. Also switch run_general_tests.py to test the hinted fonts instead of the unhinted fonts. --- scripts/common_tests.py | 26 +++++++++++++++++++++++--- scripts/run_general_tests.py | 7 ++++++- 2 files changed, 29 insertions(+), 4 deletions(-) diff --git a/scripts/common_tests.py b/scripts/common_tests.py index 531737c..f5a7793 100644 --- a/scripts/common_tests.py +++ b/scripts/common_tests.py @@ -282,11 +282,14 @@ class TestFeatures(FontTest): u''.join(chars_with_no_smcp).encode('UTF-8'))) +EXPECTED_YMIN = -555 +EXPECTED_YMAX = 2163 + class TestVerticalMetrics(FontTest): """Test the vertical metrics of fonts.""" def setUp(self): - _, self.fonts = self.loaded_fonts + self.font_files, self.fonts = self.loaded_fonts def test_ymin_ymax(self): """Tests yMin and yMax to be equal to Roboto v1 values. @@ -295,8 +298,25 @@ class TestVerticalMetrics(FontTest): """ for font in self.fonts: head_table = font['head'] - self.assertEqual(head_table.yMin, -555) - self.assertEqual(head_table.yMax, 2163) + self.assertEqual(head_table.yMin, EXPECTED_YMIN) + self.assertEqual(head_table.yMax, EXPECTED_YMAX) + + def test_glyphs_ymin_ymax(self): + """Tests yMin and yMax of all glyphs to not go outside the range.""" + for font_file, font in zip(self.font_files, self.fonts): + glyf_table = font['glyf'] + for glyph_name in glyf_table.glyphOrder: + try: + y_min = glyf_table[glyph_name].yMin + y_max = glyf_table[glyph_name].yMax + except AttributeError: + continue + + self.assertTrue( + EXPECTED_YMIN <= y_min and y_max <= EXPECTED_YMAX, + ('The vertical metrics for glyph %s in %s exceed the ' + 'acceptable range: yMin=%d, yMax=%d' % ( + glyph_name, font_file, y_min, y_max))) def test_hhea_table_metrics(self): """Tests ascent, descent, and lineGap to be equal to Roboto v1 values. diff --git a/scripts/run_general_tests.py b/scripts/run_general_tests.py index 1a9e965..68ca269 100755 --- a/scripts/run_general_tests.py +++ b/scripts/run_general_tests.py @@ -21,7 +21,7 @@ import unittest import common_tests FONTS = common_tests.load_fonts( - ['out/RobotoTTF/*.ttf', 'out/RobotoCondensedTTF/*.ttf'], + ['hinted/*.ttf'], expected_count=18) class TestItalicAngle(common_tests.TestItalicAngle): @@ -50,6 +50,11 @@ class TestFeatures(common_tests.TestFeatures): loaded_fonts = FONTS +class TestVerticalMetrics(common_tests.TestVerticalMetrics): + loaded_fonts = FONTS + test_ymin_ymax = None + test_hhea_table_metrics = None + if __name__ == '__main__': unittest.main() -- cgit v1.2.3