From 24eb3f719774d8c330f46747d7a850c5362cc74f Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Thu, 30 Jan 2025 13:52:03 +0000 Subject: [PATCH 1/2] [otData] Fix DeltaValue repeat value The "" marker is used when a custom converter expects a list. For DeltaValues, we expect a list as a single value, not a list to be enumerated in XML. So, None is appropriate here. Cryptic, I know... Fixes https://github.com/fonttools/fonttools/pull/3757 --- Lib/fontTools/ttLib/tables/otData.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lib/fontTools/ttLib/tables/otData.py b/Lib/fontTools/ttLib/tables/otData.py index 3a01f5934..f538aeb48 100644 --- a/Lib/fontTools/ttLib/tables/otData.py +++ b/Lib/fontTools/ttLib/tables/otData.py @@ -385,7 +385,7 @@ otData = [ ( "DeltaValue", "DeltaValue", - "", + None, "DeltaFormat in (1,2,3)", "Array of compressed data", ), From 5b3176f4fdc27505700594cb93f83fa51253db1d Mon Sep 17 00:00:00 2001 From: Cosimo Lupo Date: Tue, 4 Feb 2025 10:20:41 +0000 Subject: [PATCH 2/2] add test for parsing and compiling DeviceTable's DeltaValue --- Lib/fontTools/misc/testTools.py | 3 + Tests/ttLib/tables/otTables_test.py | 88 +++++++++++++++++++++++++++++ 2 files changed, 91 insertions(+) diff --git a/Lib/fontTools/misc/testTools.py b/Lib/fontTools/misc/testTools.py index 7d7872148..f4127fe61 100644 --- a/Lib/fontTools/misc/testTools.py +++ b/Lib/fontTools/misc/testTools.py @@ -58,6 +58,9 @@ class FakeFont: self.tables = {} self.cfg = Config() + def __contains__(self, tag): + return tag in self.tables + def __getitem__(self, tag): return self.tables[tag] diff --git a/Tests/ttLib/tables/otTables_test.py b/Tests/ttLib/tables/otTables_test.py index db33e4c65..01bc97db8 100644 --- a/Tests/ttLib/tables/otTables_test.py +++ b/Tests/ttLib/tables/otTables_test.py @@ -4,6 +4,7 @@ from fontTools.misc.xmlWriter import XMLWriter from fontTools.ttLib.tables.otBase import OTTableReader, OTTableWriter import fontTools.ttLib.tables.otTables as otTables from io import StringIO +from textwrap import dedent import unittest @@ -735,6 +736,93 @@ class ColrV1Test(unittest.TestCase): assert len(visited) == 1 +def test_parse_Device_DeltaValue_from_XML_and_compile(): + # https://github.com/fonttools/fonttools/pull/3757 + font = FakeFont([".notdef", "five"]) + + gpos_xml = dedent( + """\ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + """ + ) + + gpos = parseXmlInto(font, otTables.GPOS(), gpos_xml) + + anchor = gpos.LookupList.Lookup[0].SubTable[0].EntryExitRecord[0].EntryAnchor + assert anchor.XDeviceTable.DeltaValue == [1, 2] + assert anchor.YDeviceTable.DeltaValue == [3] + + writer = OTTableWriter() + gpos.compile(writer, font) + data = writer.getAllData() + + reader = OTTableReader(data, tableTag="GPOS") + gpos2 = otTables.GPOS() + gpos2.decompile(reader, font) + + assert dedent("\n".join(getXML(gpos2.toXML, font)[1:-1])) == gpos_xml + + if __name__ == "__main__": import sys