summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoozbeh Pournader <roozbeh@google.com>2015-01-07 11:45:20 -0800
committerJames Godfrey-Kittle <jamesgk@google.com>2015-04-16 12:16:24 -0700
commit0fd852f5cb306362f44a89686356bbad47da93d9 (patch)
tree7c0359d0194316428510020d5333f6fb8d089ca8
parent94a70f1b9f0407dfe335f70dbfd3a73bbb26afc0 (diff)
Move get_advances to a new layout module.
-rw-r--r--scripts/layout.py20
-rw-r--r--scripts/run_exhaustive_tests.py20
2 files changed, 24 insertions, 16 deletions
diff --git a/scripts/layout.py b/scripts/layout.py
new file mode 100644
index 0000000..fbcaa82
--- /dev/null
+++ b/scripts/layout.py
@@ -0,0 +1,20 @@
+"""Test general health of the fonts."""
+
+import json
+
+from nototools import render
+
+_advance_cache = {}
+def get_advances(text, font):
+ """Get a list of horizontal advances for text rendered in a font."""
+ try:
+ return _advance_cache[(text, font)]
+ except KeyError:
+ pass
+
+ hb_output = render.run_harfbuzz_on_text(text, font, None)
+ hb_output = json.loads(hb_output)
+ advances = [glyph['ax'] for glyph in hb_output]
+ _advance_cache[(text, font)] = advances
+ return advances
+
diff --git a/scripts/run_exhaustive_tests.py b/scripts/run_exhaustive_tests.py
index cdc770b..9bf7011 100644
--- a/scripts/run_exhaustive_tests.py
+++ b/scripts/run_exhaustive_tests.py
@@ -1,15 +1,14 @@
#!/usr/bin/python
-"""Test general health of the fonts."""
+"""Time-consuming tests for general health of the fonts."""
import glob
-import json
import unittest
from fontTools import ttLib
from nototools import coverage
-from nototools import render
from nototools import unicode_data
+import layout
def load_fonts():
"""Load all major fonts."""
@@ -30,24 +29,13 @@ class TestSpacingMarks(unittest.TestCase):
if unicode_data.category(char) in ['Lm', 'Sk']]
self.advance_cache = {}
- def get_advances(self, text, font):
- """Get a list of horizontal advances for text rendered in a font."""
- try:
- return self.advance_cache[(text, font)]
- except KeyError:
- hb_output = render.run_harfbuzz_on_text(text, font, '')
- hb_output = json.loads(hb_output)
- advances = [glyph['ax'] for glyph in hb_output]
- self.advance_cache[(text, font)] = advances
- return advances
-
def test_individual_spacing_marks(self):
"""Tests that spacing marks are spacing by themselves."""
for font in self.font_files:
print 'Testing %s for stand-alone spacing marks...' % font
for mark in self.marks_to_test:
mark = unichr(mark)
- advances = self.get_advances(mark, font)
+ advances = layout.get_advances(mark, font)
assert len(advances) == 1
self.assertNotEqual(advances[0], 0)
@@ -67,7 +55,7 @@ class TestSpacingMarks(unittest.TestCase):
# ligatures
continue
mark = unichr(mark)
- advances = self.get_advances(base_letter + mark, font)
+ advances = layout.get_advances(base_letter + mark, font)
self.assertEqual(len(advances), 2,
'The sequence <%04X, %04X> combines, '
'but it should not' % (ord(base_letter), ord(mark)))