From 800bf85b2f23f31eab1475983a1e116d97340e46 Mon Sep 17 00:00:00 2001 From: Cosimo Lupo Date: Thu, 29 Jul 2021 15:35:08 +0200 Subject: [PATCH] add ClipList.Format so we can bump when we finally get >16bit GIDs https://github.com/googlefonts/colr-gradients-spec/issues/346 --- Lib/fontTools/colorLib/builder.py | 1 + Lib/fontTools/ttLib/tables/otData.py | 3 ++- Lib/fontTools/ttLib/tables/otTables.py | 4 +++- Tests/colorLib/builder_test.py | 1 + Tests/ttLib/tables/C_O_L_R_test.py | 7 ++++--- 5 files changed, 11 insertions(+), 5 deletions(-) diff --git a/Lib/fontTools/colorLib/builder.py b/Lib/fontTools/colorLib/builder.py index 8254d948a..c2315afbf 100644 --- a/Lib/fontTools/colorLib/builder.py +++ b/Lib/fontTools/colorLib/builder.py @@ -252,6 +252,7 @@ def buildCOLR( def buildClipList(clipBoxes: Dict[str, _ClipBoxInput]) -> ot.ClipList: clipList = ot.ClipList() + clipList.Format = 0 clipList.clips = {name: buildClipBox(box) for name, box in clipBoxes.items()} return clipList diff --git a/Lib/fontTools/ttLib/tables/otData.py b/Lib/fontTools/ttLib/tables/otData.py index 554df3373..416a932a6 100755 --- a/Lib/fontTools/ttLib/tables/otData.py +++ b/Lib/fontTools/ttLib/tables/otData.py @@ -1601,7 +1601,8 @@ otData = [ ('LOffset', 'Paint', 'LayerCount', 0, 'Array of offsets to Paint tables, from the start of the LayerList table.'), ]), - ('ClipList', [ + ('ClipListFormat0', [ + ('uint8', 'Format', None, None, 'Format for ClipList with 16bit glyph IDs: 0'), ('uint32', 'ClipCount', None, None, 'Number of Clip records.'), ('struct', 'ClipRecord', 'ClipCount', 0, 'Array of Clip records sorted by glyph ID.'), ]), diff --git a/Lib/fontTools/ttLib/tables/otTables.py b/Lib/fontTools/ttLib/tables/otTables.py index 6aee98a04..ff32e2dd4 100644 --- a/Lib/fontTools/ttLib/tables/otTables.py +++ b/Lib/fontTools/ttLib/tables/otTables.py @@ -1307,7 +1307,7 @@ class ClipBox(getFormatSwitchingBaseTableClass("uint8")): return f"{self.__class__.__name__}{self.as_tuple()}" -class ClipList(BaseTable): +class ClipList(getFormatSwitchingBaseTableClass("uint8")): def populateDefaults(self, propagator=None): if not hasattr(self, "clips"): @@ -1410,6 +1410,8 @@ class ClipList(BaseTable): tableName = name if name else self.__class__.__name__ if attrs is None: attrs = [] + if hasattr(self, "Format"): + attrs.append(("Format", self.Format)) xmlWriter.begintag(tableName, attrs) xmlWriter.newline() # sort clips alphabetically to ensure deterministic XML dump diff --git a/Tests/colorLib/builder_test.py b/Tests/colorLib/builder_test.py index 205ef053e..0a99a0288 100644 --- a/Tests/colorLib/builder_test.py +++ b/Tests/colorLib/builder_test.py @@ -1681,6 +1681,7 @@ class BuildCOLRTest(object): }, ) + assert colr.table.ClipList.Format == 0 clipBoxes = colr.table.ClipList.clips assert [ (baseGlyph, clipBox.as_tuple()) for baseGlyph, clipBox in clipBoxes.items() diff --git a/Tests/ttLib/tables/C_O_L_R_test.py b/Tests/ttLib/tables/C_O_L_R_test.py index 63fc96c54..aeee80f3f 100644 --- a/Tests/ttLib/tables/C_O_L_R_test.py +++ b/Tests/ttLib/tables/C_O_L_R_test.py @@ -298,13 +298,14 @@ COLR_V1_SAMPLE = ( (b" \x00", "Paint.Alpha (0.5)"), # ClipList + (b'\x00', "ClipList.Format (0)"), (b'\x00\x00\x00\x02', "ClipList.ClipCount (2)"), (b'\x00\x0a', "ClipRecord[0].StartGlyphID (10)"), (b'\x00\x0a', "ClipRecord[0].EndGlyphID (10)"), - (b'\x00\x00\x12', "Offset to ClipBox subtable from beginning of ClipList (18)"), + (b'\x00\x00\x13', "Offset to ClipBox subtable from beginning of ClipList (19)"), (b'\x00\x0e', "ClipRecord[1].StartGlyphID (14)"), (b'\x00\x0f', "ClipRecord[1].EndGlyphID (15)"), - (b'\x00\x00\x1f', "Offset to ClipBox subtable from beginning of ClipList (31)"), + (b'\x00\x00\x20', "Offset to ClipBox subtable from beginning of ClipList (32)"), (b'\x01', "ClipBox.Format (1)"), (b'\x00\x00', "ClipBox.xMin (0)"), @@ -505,7 +506,7 @@ COLR_V1_XML = [ ' ', " ", "", - "", + '', " ", ' ', ' ',