From 8309aaf8d805ab2564e8b3c4d1ae0f07121ddcd0 Mon Sep 17 00:00:00 2001 From: Cosimo Lupo Date: Wed, 27 Apr 2022 15:58:29 +0100 Subject: [PATCH] [subset_test] add failing test to repro SinglePosFormat2 with ValueFormat=0 reproduces #2602 --- Tests/subset/subset_test.py | 48 +++++++++++++++++++++++++++++++++++-- 1 file changed, 46 insertions(+), 2 deletions(-) diff --git a/Tests/subset/subset_test.py b/Tests/subset/subset_test.py index facafb2a7..2c51a5a9e 100644 --- a/Tests/subset/subset_test.py +++ b/Tests/subset/subset_test.py @@ -953,7 +953,8 @@ def test_subset_feature_variations_drop_all(featureVarsTestFont): # https://github.com/fonttools/fonttools/issues/1881#issuecomment-619415044 -def test_subset_single_pos_format(): +@pytest.fixture +def singlepos2_font(): fb = FontBuilder(unitsPerEm=1000) fb.setupGlyphOrder([".notdef", "a", "b", "c"]) fb.setupCharacterMap({ord("a"): "a", ord("b"): "b", ord("c"): "c"}) @@ -971,8 +972,11 @@ def test_subset_single_pos_format(): fb.save(buf) buf.seek(0) - font = TTFont(buf) + return TTFont(buf) + +def test_subset_single_pos_format(singlepos2_font): + font = singlepos2_font # 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) == [ @@ -1018,6 +1022,46 @@ def test_subset_single_pos_format(): '', ] +def test_subset_single_pos_format2_all_None(singlepos2_font): + # https://github.com/fonttools/fonttools/issues/2602 + font = singlepos2_font + gpos = font["GPOS"].table + subtable = gpos.LookupList.Lookup[0].SubTable[0] + assert subtable.Format == 2 + # Hack a SinglePosFormat2 with ValueFormat = 0; our own buildSinglePos + # never makes these as a SinglePosFormat1 is more compact, but they can + # be found in the wild. + subtable.Value = [None] * subtable.ValueCount + subtable.ValueFormat = 0 + + assert getXML(subtable.toXML, font) == [ + '', + ' ', + ' ', + ' ', + ' ', + ' ', + ' ', + ' ', + '', + ] + + options = subset.Options() + subsetter = subset.Subsetter(options) + subsetter.populate(unicodes=[ord("a"), ord("c")]) + subsetter.subset(font) + + # Check it was downgraded to Format1 after subsetting + assert getXML(font["GPOS"].table.LookupList.Lookup[0].SubTable[0].toXML, font) == [ + '', + ' ', + ' ', + ' ', + ' ', + ' ', + '', + ] + @pytest.fixture def ttf_path(tmp_path):