From a32fd30c2df4466c992a40294125a61a290e899a Mon Sep 17 00:00:00 2001 From: Cosimo Lupo Date: Thu, 16 Jan 2020 18:30:07 -0800 Subject: [PATCH] subset_test: add test for optimizing SinglePos format when all subsetted values are same --- Tests/subset/subset_test.py | 67 +++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) diff --git a/Tests/subset/subset_test.py b/Tests/subset/subset_test.py index 3d8c27ecf..2ffc55501 100644 --- a/Tests/subset/subset_test.py +++ b/Tests/subset/subset_test.py @@ -1,5 +1,6 @@ import io from fontTools.misc.py23 import * +from fontTools.misc.testTools import getXML from fontTools import subset from fontTools.fontBuilder import FontBuilder from fontTools.ttLib import TTFont, newTable @@ -768,5 +769,71 @@ def test_subset_feature_variations(): assert "dollar.rvrn" in font.getGlyphOrder() +def test_subset_single_pos_format(): + fb = FontBuilder(unitsPerEm=1000) + fb.setupGlyphOrder([".notdef", "a", "b", "c"]) + fb.setupCharacterMap({ord("a"): "a", ord("b"): "b", ord("c"): "c"}) + fb.setupNameTable({"familyName": "TestSingePosFormat", "styleName": "Regular"}) + fb.setupPost() + fb.addOpenTypeFeatures(""" + feature kern { + pos a -50; + pos b -40; + pos c -50; + } kern; + """) + + buf = io.BytesIO() + fb.save(buf) + buf.seek(0) + + font = TTFont(buf) + + # The input font has a SinglePos Format 2 subtable where each glyph has + # different ValueRecords + assert getXML(font["GPOS"].table.LookupList.Lookup[0].toXML, font) == [ + '', + ' ', + ' ', + ' ', + ' ', + ' ', + ' ', + ' ', + ' ', + ' ', + ' ', + ' ', + ' ', + ' ', + ' ', + ' ', + '', + ] + + options = subset.Options() + subsetter = subset.Subsetter(options) + subsetter.populate(unicodes=[ord("a"), ord("c")]) + subsetter.subset(font) + + # All the subsetted glyphs from the original SinglePos Format2 subtable + # now have the same ValueRecord, so we use a more compact Format 1 subtable. + assert getXML(font["GPOS"].table.LookupList.Lookup[0].toXML, font) == [ + '', + ' ', + ' ', + ' ', + ' ', + ' ', + ' ', + ' ', + ' ', + ' ', + ' ', + ' ', + '', + ] + + if __name__ == "__main__": sys.exit(unittest.main())