summaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
authorRoozbeh Pournader <roozbeh@google.com>2015-04-27 16:58:38 -0700
committerRoozbeh Pournader <roozbeh@google.com>2015-04-27 16:58:38 -0700
commitc0fd8ad77c8203d0e3baaf71b77ae1da6ed3f80e (patch)
treeaa038ea56e0f9caeb463291ccb02bdb2765b1599 /scripts
parent1e26bfe5302f43f8690040143af65c9d5809f2fd (diff)
parent8faeb294ae6ae7cc3f4a90915d3660830c76ecef (diff)
Merge pull request #27 from google/st-ligatures
Add tests for s-t and longs-t discretionary ligatures.
Diffstat (limited to 'scripts')
-rw-r--r--scripts/common_tests.py24
-rw-r--r--scripts/layout.py26
2 files changed, 39 insertions, 11 deletions
diff --git a/scripts/common_tests.py b/scripts/common_tests.py
index 926652a..1b015b8 100644
--- a/scripts/common_tests.py
+++ b/scripts/common_tests.py
@@ -1,3 +1,5 @@
+# coding=UTF-8
+#
# Copyright 2015 Google Inc. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -167,7 +169,7 @@ class TestDigitWidths(FontTest):
"""Tests the width of digits."""
def setUp(self):
- _, self.fonts = self.loaded_fonts
+ self.font_files, self.fonts = self.loaded_fonts
self.digits = [
'zero', 'one', 'two', 'three', 'four',
'five', 'six', 'seven', 'eight', 'nine']
@@ -179,6 +181,17 @@ class TestDigitWidths(FontTest):
widths = [hmtx_table[digit][0] for digit in self.digits]
self.assertEqual(len(set(widths)), 1)
+ def test_superscript_digits(self):
+ """Tests that 'numr' features maps digits to Unicode superscripts."""
+ ascii_digits = '0123456789'
+ superscript_digits = u'⁰¹²³⁴⁵⁶⁷⁸⁹'
+ for font_file in self.font_files:
+ numr_glyphs = layout.get_advances(
+ ascii_digits, font_file, '--features=numr')
+ superscript_glyphs = layout.get_advances(
+ superscript_digits, font_file)
+ self.assertEqual(superscript_glyphs, numr_glyphs)
+
class TestCharacterCoverage(FontTest):
"""Tests character coverage."""
@@ -232,6 +245,15 @@ class TestLigatures(FontTest):
advances = layout.get_advances('ff', fontfile)
self.assertEqual(len(advances), 2)
+ def test_st_ligatures(self):
+ """Tests that st ligatures are formed by dlig."""
+ for fontfile in self.fontfiles:
+ for combination in [u'st', u'ſt']:
+ normal = layout.get_glyphs(combination, fontfile)
+ ligated = layout.get_glyphs(
+ combination, fontfile, '--features=dlig')
+ self.assertTrue(len(normal) == 2 and len(ligated) == 1)
+
class TestVerticalMetrics(FontTest):
"""Test the vertical metrics of fonts."""
diff --git a/scripts/layout.py b/scripts/layout.py
index 91cf8e8..343f359 100644
--- a/scripts/layout.py
+++ b/scripts/layout.py
@@ -18,35 +18,41 @@ import json
from nototools import render
-def _run_harfbuzz(text, font, language):
+def _run_harfbuzz(text, font, language, extra_parameters=None):
"""Run harfbuzz on some text and return the shaped list."""
- hb_output = render.run_harfbuzz_on_text(text, font, language)
+ try:
+ # if extra_parameters is a string, split it into a list
+ extra_parameters = extra_parameters.split(' ')
+ except AttributeError:
+ pass
+ hb_output = render.run_harfbuzz_on_text(
+ text, font, language, extra_parameters)
return json.loads(hb_output)
_advance_cache = {}
-def get_advances(text, font):
+def get_advances(text, font, extra_parameters=None):
"""Get a list of horizontal advances for text rendered in a font."""
try:
- return _advance_cache[(text, font)]
+ return _advance_cache[(text, font, extra_parameters)]
except KeyError:
pass
- hb_output = _run_harfbuzz(text, font, None)
+ hb_output = _run_harfbuzz(text, font, None, extra_parameters)
advances = [glyph['ax'] for glyph in hb_output]
- _advance_cache[(text, font)] = advances
+ _advance_cache[(text, font, extra_parameters)] = advances
return advances
_shape_cache = {}
-def get_glyphs(text, font):
+def get_glyphs(text, font, extra_parameters=None):
"""Get a list of shaped glyphs for text rendered in a font."""
try:
- return _shape_cache[(text, font)]
+ return _shape_cache[(text, font, extra_parameters)]
except KeyError:
pass
- hb_output = _run_harfbuzz(text, font, None)
+ hb_output = _run_harfbuzz(text, font, None, extra_parameters)
shapes = [glyph['g'] for glyph in hb_output]
- _shape_cache[(text, font)] = shapes
+ _shape_cache[(text, font, extra_parameters)] = shapes
return shapes