summaryrefslogtreecommitdiff
path: root/scripts/common_tests.py
diff options
context:
space:
mode:
authorJames Godfrey-Kittle <jamesgk@google.com>2015-08-31 16:54:15 -0700
committerJames Godfrey-Kittle <jamesgk@google.com>2015-08-31 16:54:15 -0700
commita527f8faa39de6957b093b5b3f0c4a128ac3b4b0 (patch)
treeff47fa90bc78e1b096adf37dde3a4156388805a7 /scripts/common_tests.py
parent9d6cd8e1df2941e63d65e651f3cf4954fd07924c (diff)
Add test to compare glyph sizes between fonts.
For now, we just check which glyphs are unchanged between the Thin and Bold masters, and make sure only those glyphs are unchanged between Thin, Regular, and Bold output (ignoring empty glyphs).
Diffstat (limited to 'scripts/common_tests.py')
-rw-r--r--scripts/common_tests.py54
1 files changed, 54 insertions, 0 deletions
diff --git a/scripts/common_tests.py b/scripts/common_tests.py
index 56f0b9d..54dff86 100644
--- a/scripts/common_tests.py
+++ b/scripts/common_tests.py
@@ -27,6 +27,7 @@ import freetype
import layout
import roboto_data
+from glyph_area_pen import GlyphAreaPen
def get_rendered_char_height(font_filename, font_size, char, target='mono'):
@@ -331,3 +332,56 @@ class TestVerticalMetrics(FontTest):
self.assertEqual(hhea_table.ascent, 1900)
self.assertEqual(hhea_table.lineGap, 0)
+
+class TestGlyphAreas(unittest.TestCase):
+ """Tests that glyph areas between weights have the right ratios."""
+
+ def setUp(self):
+ """Determine which glyphs are intentionally unchanged."""
+
+ self.unchanged = set()
+ pen = self.pen = GlyphAreaPen()
+ thin, bold = self.getFonts(self.masters[1], "Roboto", "Thin", "Bold")
+ for glyph in thin:
+ glyph.draw(pen)
+ thin_area = pen.unload()
+ bold[glyph.name].draw(pen)
+ bold_area = pen.unload()
+ if thin_area == bold_area:
+ if thin_area:
+ self.unchanged.add(glyph.name)
+ else:
+ assert thin_area and bold_area
+
+ def getFonts(self, fonts, family, *weights):
+ """Extract fonts of certain family and weights from given font list."""
+
+ fonts = dict((f.info.styleName, f) for f in fonts
+ if f.info.familyName == family)
+ return [fonts[w] for w in weights]
+
+ def test_output(self):
+ """Test that only empty or intentionally unchanged glyphs are unchanged.
+ """
+
+ pen = self.pen
+ thin, regular, bold = self.getFonts(
+ self.loaded_fonts[1], "Roboto", "Thin", "Regular", "Bold")
+ regular_areas = {}
+ for glyph in regular:
+ glyph.draw(pen)
+ regular_areas[glyph.name] = pen.unload()
+
+ for other in [thin, bold]:
+ for name, regular_area in regular_areas.iteritems():
+ other[name].draw(pen)
+ other_area = pen.unload()
+ if not regular_area: # glyph probably contains only components
+ self.assertFalse(other_area)
+ continue
+ unchanged = regular_area == other_area
+ if unchanged:
+ msg = name + " has not changed, but should have."
+ else:
+ msg = name + " has changed, but should not have."
+ self.assertEqual(unchanged, name in self.unchanged, msg)