From 1cb7e36bbd54007221ba1b12af76f7c45b8b59c8 Mon Sep 17 00:00:00 2001 From: Cosimo Lupo Date: Mon, 28 Jun 2021 16:13:47 +0100 Subject: [PATCH] COLRv1: rename otData structs to remove 'V1' to match updated draft spec This is a breaking change (but the COLRv1 API was already marked as unstable and subject to change) The changes in this PR are meant to match the changes from the COLRv1 draft spec at: https://github.com/googlefonts/colr-gradients-spec/pull/302 --- Lib/fontTools/colorLib/builder.py | 28 +++---- Lib/fontTools/colorLib/unbuilder.py | 10 +-- Lib/fontTools/subset/__init__.py | 10 +-- Lib/fontTools/ttLib/tables/otData.py | 22 ++--- Lib/fontTools/ttLib/tables/otTables.py | 12 +-- Tests/colorLib/builder_test.py | 90 ++++++++++---------- Tests/subset/subset_test.py | 6 +- Tests/ttLib/tables/C_O_L_R_test.py | 112 ++++++++++++------------- 8 files changed, 145 insertions(+), 145 deletions(-) diff --git a/Lib/fontTools/colorLib/builder.py b/Lib/fontTools/colorLib/builder.py index d880dab23..dec832335 100644 --- a/Lib/fontTools/colorLib/builder.py +++ b/Lib/fontTools/colorLib/builder.py @@ -218,7 +218,7 @@ def buildCOLR( populateCOLRv0(colr, colorGlyphsV0, glyphMap) - colr.LayerV1List, colr.BaseGlyphV1List = buildColrV1(colorGlyphsV1, glyphMap) + colr.LayerList, colr.BaseGlyphList = buildColrV1(colorGlyphsV1, glyphMap) if version is None: version = 1 if (varStore or colorGlyphsV1) else 0 @@ -404,7 +404,7 @@ def _reuse_ranges(num_layers: int) -> Generator[Tuple[int, int], None, None]: yield (lbound, ubound) -class LayerV1ListBuilder: +class LayerListBuilder: slices: List[ot.Paint] layers: List[ot.Paint] reusePool: Mapping[Tuple[Any, ...], int] @@ -536,19 +536,19 @@ class LayerV1ListBuilder: def buildPaint(self, paint: _PaintInput) -> ot.Paint: return self.tableBuilder.build(ot.Paint, paint) - def build(self) -> Optional[ot.LayerV1List]: + def build(self) -> Optional[ot.LayerList]: if not self.layers: return None - layers = ot.LayerV1List() + layers = ot.LayerList() layers.LayerCount = len(self.layers) layers.Paint = self.layers return layers -def buildBaseGlyphV1Record( - baseGlyph: str, layerBuilder: LayerV1ListBuilder, paint: _PaintInput -) -> ot.BaseGlyphV1List: - self = ot.BaseGlyphV1Record() +def buildBaseGlyphPaintRecord( + baseGlyph: str, layerBuilder: LayerListBuilder, paint: _PaintInput +) -> ot.BaseGlyphList: + self = ot.BaseGlyphPaintRecord() self.BaseGlyph = baseGlyph self.Paint = layerBuilder.buildPaint(paint) return self @@ -564,7 +564,7 @@ def _format_glyph_errors(errors: Mapping[str, Exception]) -> str: def buildColrV1( colorGlyphs: _ColorGlyphsDict, glyphMap: Optional[Mapping[str, int]] = None, -) -> Tuple[Optional[ot.LayerV1List], ot.BaseGlyphV1List]: +) -> Tuple[Optional[ot.LayerList], ot.BaseGlyphList]: if glyphMap is not None: colorGlyphItems = sorted( colorGlyphs.items(), key=lambda item: glyphMap[item[0]] @@ -574,24 +574,24 @@ def buildColrV1( errors = {} baseGlyphs = [] - layerBuilder = LayerV1ListBuilder() + layerBuilder = LayerListBuilder() for baseGlyph, paint in colorGlyphItems: try: - baseGlyphs.append(buildBaseGlyphV1Record(baseGlyph, layerBuilder, paint)) + baseGlyphs.append(buildBaseGlyphPaintRecord(baseGlyph, layerBuilder, paint)) except (ColorLibError, OverflowError, ValueError, TypeError) as e: errors[baseGlyph] = e if errors: failed_glyphs = _format_glyph_errors(errors) - exc = ColorLibError(f"Failed to build BaseGlyphV1List:\n{failed_glyphs}") + exc = ColorLibError(f"Failed to build BaseGlyphList:\n{failed_glyphs}") exc.errors = errors raise exc from next(iter(errors.values())) layers = layerBuilder.build() - glyphs = ot.BaseGlyphV1List() + glyphs = ot.BaseGlyphList() glyphs.BaseGlyphCount = len(baseGlyphs) - glyphs.BaseGlyphV1Record = baseGlyphs + glyphs.BaseGlyphPaintRecord = baseGlyphs return (layers, glyphs) diff --git a/Lib/fontTools/colorLib/unbuilder.py b/Lib/fontTools/colorLib/unbuilder.py index 43582bde3..0d10cff40 100644 --- a/Lib/fontTools/colorLib/unbuilder.py +++ b/Lib/fontTools/colorLib/unbuilder.py @@ -3,10 +3,10 @@ from .table_builder import TableUnbuilder def unbuildColrV1(layerV1List, baseGlyphV1List): - unbuilder = LayerV1ListUnbuilder(layerV1List.Paint) + unbuilder = LayerListUnbuilder(layerV1List.Paint) return { rec.BaseGlyph: unbuilder.unbuildPaint(rec.Paint) - for rec in baseGlyphV1List.BaseGlyphV1Record + for rec in baseGlyphV1List.BaseGlyphPaintRecord } @@ -18,7 +18,7 @@ def _flatten(lst): yield el -class LayerV1ListUnbuilder: +class LayerListUnbuilder: def __init__(self, layers): self.layers = layers @@ -71,8 +71,8 @@ if __name__ == "__main__": sys.exit(f"error: No COLR table version=1 found in {fontfile}") colorGlyphs = unbuildColrV1( - colr.table.LayerV1List, - colr.table.BaseGlyphV1List, + colr.table.LayerList, + colr.table.BaseGlyphList, ignoreVarIdx=not colr.table.VarStore, ) diff --git a/Lib/fontTools/subset/__init__.py b/Lib/fontTools/subset/__init__.py index a9b0583a7..8fa98f40e 100644 --- a/Lib/fontTools/subset/__init__.py +++ b/Lib/fontTools/subset/__init__.py @@ -2055,7 +2055,7 @@ def closure_glyphs(self, s): self.ColorLayers = self._decompileColorLayersV0(self.table) self.ColorLayersV1 = { rec.BaseGlyph: rec.Paint - for rec in self.table.BaseGlyphV1List.BaseGlyphV1Record + for rec in self.table.BaseGlyphList.BaseGlyphPaintRecord } decompose = s.glyphs @@ -2083,14 +2083,14 @@ def subset_glyphs(self, s): if self.version == 0: return bool(self.ColorLayers) - colorGlyphsV1 = unbuildColrV1(self.table.LayerV1List, self.table.BaseGlyphV1List) - self.table.LayerV1List, self.table.BaseGlyphV1List = buildColrV1( + colorGlyphsV1 = unbuildColrV1(self.table.LayerList, self.table.BaseGlyphList) + self.table.LayerList, self.table.BaseGlyphList = buildColrV1( {g: colorGlyphsV1[g] for g in colorGlyphsV1 if g in s.glyphs} ) del self.ColorLayersV1 layersV0 = self.ColorLayers - if not self.table.BaseGlyphV1List.BaseGlyphV1Record: + if not self.table.BaseGlyphList.BaseGlyphPaintRecord: # no more COLRv1 glyphs: downgrade to version 0 self.version = 0 del self.table @@ -2131,7 +2131,7 @@ def prune_post_subset(self, font, options): if colr.table.LayerRecordArray: for layer in colr.table.LayerRecordArray.LayerRecord: colors_by_index[layer.PaletteIndex].append(layer) - for record in colr.table.BaseGlyphV1List.BaseGlyphV1Record: + for record in colr.table.BaseGlyphList.BaseGlyphPaintRecord: record.Paint.traverse(colr.table, collect_colors_by_index) # don't remap palette entry index 0xFFFF, this is always the foreground color diff --git a/Lib/fontTools/ttLib/tables/otData.py b/Lib/fontTools/ttLib/tables/otData.py index c42941693..a471773a9 100755 --- a/Lib/fontTools/ttLib/tables/otData.py +++ b/Lib/fontTools/ttLib/tables/otData.py @@ -1546,8 +1546,8 @@ otData = [ ('LOffset', 'BaseGlyphRecordArray', None, None, 'Offset (from beginning of COLR table) to Base Glyph records.'), ('LOffset', 'LayerRecordArray', None, None, 'Offset (from beginning of COLR table) to Layer Records.'), ('uint16', 'LayerRecordCount', None, None, 'Number of Layer Records.'), - ('LOffset', 'BaseGlyphV1List', None, 'Version >= 1', 'Offset (from beginning of COLR table) to array of Version-1 Base Glyph records.'), - ('LOffset', 'LayerV1List', None, 'Version >= 1', 'Offset (from beginning of COLR table) to LayerV1List.'), + ('LOffset', 'BaseGlyphList', None, 'Version >= 1', 'Offset (from beginning of COLR table) to array of Version-1 Base Glyph records.'), + ('LOffset', 'LayerList', None, 'Version >= 1', 'Offset (from beginning of COLR table) to LayerList.'), ('LOffset', 'VarStore', None, 'Version >= 1', 'Offset to variation store (may be NULL)'), ]), @@ -1570,19 +1570,19 @@ otData = [ ('uint16', 'PaletteIndex', None, None, 'Index value to use with a selected color palette.'), ]), - ('BaseGlyphV1List', [ + ('BaseGlyphList', [ ('uint32', 'BaseGlyphCount', None, None, 'Number of Version-1 Base Glyph records'), - ('struct', 'BaseGlyphV1Record', 'BaseGlyphCount', 0, 'Array of Version-1 Base Glyph records'), + ('struct', 'BaseGlyphPaintRecord', 'BaseGlyphCount', 0, 'Array of Version-1 Base Glyph records'), ]), - ('BaseGlyphV1Record', [ + ('BaseGlyphPaintRecord', [ ('GlyphID', 'BaseGlyph', None, None, 'Glyph ID of reference glyph.'), - ('LOffset', 'Paint', None, None, 'Offset (from beginning of BaseGlyphV1Record) to Paint, typically a PaintColrLayers.'), + ('LOffset', 'Paint', None, None, 'Offset (from beginning of BaseGlyphPaintRecord) to Paint, typically a PaintColrLayers.'), ]), - ('LayerV1List', [ + ('LayerList', [ ('uint32', 'LayerCount', None, None, 'Number of Version-1 Layers'), - ('LOffset', 'Paint', 'LayerCount', 0, 'Array of offsets to Paint tables, from the start of the LayerV1List table.'), + ('LOffset', 'Paint', 'LayerCount', 0, 'Array of offsets to Paint tables, from the start of the LayerList table.'), ]), # COLRv1 Affine2x3 uses the same column-major order to serialize a 2D @@ -1643,8 +1643,8 @@ otData = [ # PaintColrLayers ('PaintFormat1', [ ('uint8', 'PaintFormat', None, None, 'Format identifier-format = 1'), - ('uint8', 'NumLayers', None, None, 'Number of offsets to Paint to read from LayerV1List.'), - ('uint32', 'FirstLayerIndex', None, None, 'Index into LayerV1List.'), + ('uint8', 'NumLayers', None, None, 'Number of offsets to Paint to read from LayerList.'), + ('uint32', 'FirstLayerIndex', None, None, 'Index into LayerList.'), ]), # PaintSolid @@ -1733,7 +1733,7 @@ otData = [ # PaintColrGlyph ('PaintFormat11', [ ('uint8', 'PaintFormat', None, None, 'Format identifier-format = 11'), - ('GlyphID', 'Glyph', None, None, 'Virtual glyph ID for a BaseGlyphV1List base glyph.'), + ('GlyphID', 'Glyph', None, None, 'Virtual glyph ID for a BaseGlyphList base glyph.'), ]), # PaintTransform diff --git a/Lib/fontTools/ttLib/tables/otTables.py b/Lib/fontTools/ttLib/tables/otTables.py index 4c8ef04d1..9a54c66bb 100644 --- a/Lib/fontTools/ttLib/tables/otTables.py +++ b/Lib/fontTools/ttLib/tables/otTables.py @@ -1245,11 +1245,11 @@ class BaseGlyphRecordArray(BaseTable): return self.__dict__.copy() -class BaseGlyphV1List(BaseTable): +class BaseGlyphList(BaseTable): def preWrite(self, font): - self.BaseGlyphV1Record = sorted( - self.BaseGlyphV1Record, + self.BaseGlyphPaintRecord = sorted( + self.BaseGlyphPaintRecord, key=lambda rec: font.getGlyphID(rec.BaseGlyph) ) return self.__dict__.copy() @@ -1375,16 +1375,16 @@ class Paint(getFormatSwitchingBaseTableClass("uint8")): def getChildren(self, colr): if self.Format == PaintFormat.PaintColrLayers: - return colr.LayerV1List.Paint[ + return colr.LayerList.Paint[ self.FirstLayerIndex : self.FirstLayerIndex + self.NumLayers ] if self.Format == PaintFormat.PaintColrGlyph: - for record in colr.BaseGlyphV1List.BaseGlyphV1Record: + for record in colr.BaseGlyphList.BaseGlyphPaintRecord: if record.BaseGlyph == self.Glyph: return [record.Paint] else: - raise KeyError(f"{self.Glyph!r} not in colr.BaseGlyphV1List") + raise KeyError(f"{self.Glyph!r} not in colr.BaseGlyphList") children = [] for conv in self.getConverters(): diff --git a/Tests/colorLib/builder_test.py b/Tests/colorLib/builder_test.py index ff246646e..ac42de780 100644 --- a/Tests/colorLib/builder_test.py +++ b/Tests/colorLib/builder_test.py @@ -2,7 +2,7 @@ from fontTools.ttLib import newTable from fontTools.ttLib.tables import otTables as ot from fontTools.colorLib import builder from fontTools.colorLib.geometry import round_start_circle_stable_containment, Circle -from fontTools.colorLib.builder import LayerV1ListBuilder, _build_n_ary_tree +from fontTools.colorLib.builder import LayerListBuilder, _build_n_ary_tree from fontTools.colorLib.table_builder import TableBuilder from fontTools.colorLib.errors import ColorLibError import pytest @@ -10,11 +10,11 @@ from typing import List def _build(cls, source): - return LayerV1ListBuilder().tableBuilder.build(cls, source) + return LayerListBuilder().tableBuilder.build(cls, source) def _buildPaint(source): - return LayerV1ListBuilder().buildPaint(source) + return LayerListBuilder().buildPaint(source) def test_buildCOLR_v0(): @@ -994,15 +994,15 @@ def test_buildColrV1(): # TODO(anthrotype) should we split into two tests? - seems two distinct validations layers, baseGlyphs = builder.buildColrV1(colorGlyphs, glyphMap) assert baseGlyphs.BaseGlyphCount == len(colorGlyphs) - assert baseGlyphs.BaseGlyphV1Record[0].BaseGlyph == "d" - assert baseGlyphs.BaseGlyphV1Record[1].BaseGlyph == "a" - assert baseGlyphs.BaseGlyphV1Record[2].BaseGlyph == "g" + assert baseGlyphs.BaseGlyphPaintRecord[0].BaseGlyph == "d" + assert baseGlyphs.BaseGlyphPaintRecord[1].BaseGlyph == "a" + assert baseGlyphs.BaseGlyphPaintRecord[2].BaseGlyph == "g" layers, baseGlyphs = builder.buildColrV1(colorGlyphs) assert baseGlyphs.BaseGlyphCount == len(colorGlyphs) - assert baseGlyphs.BaseGlyphV1Record[0].BaseGlyph == "a" - assert baseGlyphs.BaseGlyphV1Record[1].BaseGlyph == "d" - assert baseGlyphs.BaseGlyphV1Record[2].BaseGlyph == "g" + assert baseGlyphs.BaseGlyphPaintRecord[0].BaseGlyph == "a" + assert baseGlyphs.BaseGlyphPaintRecord[1].BaseGlyph == "d" + assert baseGlyphs.BaseGlyphPaintRecord[2].BaseGlyph == "g" def test_buildColrV1_more_than_255_paints(): @@ -1037,16 +1037,16 @@ def test_buildColrV1_more_than_255_paints(): ) assert baseGlyphs.BaseGlyphCount == len(colorGlyphs) - assert baseGlyphs.BaseGlyphV1Record[0].BaseGlyph == "a" + assert baseGlyphs.BaseGlyphPaintRecord[0].BaseGlyph == "a" assert ( - baseGlyphs.BaseGlyphV1Record[0].Paint.Format == ot.PaintFormat.PaintColrLayers + baseGlyphs.BaseGlyphPaintRecord[0].Paint.Format == ot.PaintFormat.PaintColrLayers ) - assert baseGlyphs.BaseGlyphV1Record[0].Paint.FirstLayerIndex == 255 - assert baseGlyphs.BaseGlyphV1Record[0].Paint.NumLayers == num_paints + 1 - 255 + assert baseGlyphs.BaseGlyphPaintRecord[0].Paint.FirstLayerIndex == 255 + assert baseGlyphs.BaseGlyphPaintRecord[0].Paint.NumLayers == num_paints + 1 - 255 def test_split_color_glyphs_by_version(): - layerBuilder = LayerV1ListBuilder() + layerBuilder = LayerListBuilder() colorGlyphs = { "a": [ ("b", 0), @@ -1141,15 +1141,15 @@ def test_build_layerv1list_empty(): assertIsColrV1(colr) assertNoV0Content(colr) - # 2 v1 glyphs, none in LayerV1List - assert colr.table.BaseGlyphV1List.BaseGlyphCount == 2 - assert len(colr.table.BaseGlyphV1List.BaseGlyphV1Record) == 2 - assert colr.table.LayerV1List is None + # 2 v1 glyphs, none in LayerList + assert colr.table.BaseGlyphList.BaseGlyphCount == 2 + assert len(colr.table.BaseGlyphList.BaseGlyphPaintRecord) == 2 + assert colr.table.LayerList is None def _paint_names(paints) -> List[str]: # prints a predictable string from a paint list to enable - # semi-readable assertions on a LayerV1List order. + # semi-readable assertions on a LayerList order. result = [] for paint in paints: if paint.Format == int(ot.PaintFormat.PaintGlyph): @@ -1181,7 +1181,7 @@ def test_build_layerv1list_simple(): "Glyph": "b_fore", } - # list => PaintColrLayers, contents should land in LayerV1List + # list => PaintColrLayers, contents should land in LayerList colr = builder.buildCOLR( { "a": ( @@ -1205,12 +1205,12 @@ def test_build_layerv1list_simple(): assertIsColrV1(colr) assertNoV0Content(colr) - # 2 v1 glyphs, 4 paints in LayerV1List + # 2 v1 glyphs, 4 paints in LayerList # A single shared backdrop isn't worth accessing by slice - assert colr.table.BaseGlyphV1List.BaseGlyphCount == 2 - assert len(colr.table.BaseGlyphV1List.BaseGlyphV1Record) == 2 - assert colr.table.LayerV1List.LayerCount == 4 - assert _paint_names(colr.table.LayerV1List.Paint) == [ + assert colr.table.BaseGlyphList.BaseGlyphCount == 2 + assert len(colr.table.BaseGlyphList.BaseGlyphPaintRecord) == 2 + assert colr.table.LayerList.LayerCount == 4 + assert _paint_names(colr.table.LayerList.Paint) == [ "back", "a_fore", "back", @@ -1254,7 +1254,7 @@ def test_build_layerv1list_with_sharing(): "Glyph": "c_back", } - # list => PaintColrLayers, which means contents should be in LayerV1List + # list => PaintColrLayers, which means contents should be in LayerList colr = builder.buildCOLR( { "a": (ot.PaintFormat.PaintColrLayers, backdrop + [a_foreground]), @@ -1270,17 +1270,17 @@ def test_build_layerv1list_with_sharing(): assertIsColrV1(colr) assertNoV0Content(colr) - # 2 v1 glyphs, 4 paints in LayerV1List + # 2 v1 glyphs, 4 paints in LayerList # A single shared backdrop isn't worth accessing by slice - baseGlyphs = colr.table.BaseGlyphV1List.BaseGlyphV1Record - assert colr.table.BaseGlyphV1List.BaseGlyphCount == 3 + baseGlyphs = colr.table.BaseGlyphList.BaseGlyphPaintRecord + assert colr.table.BaseGlyphList.BaseGlyphCount == 3 assert len(baseGlyphs) == 3 assert _paint_names([b.Paint for b in baseGlyphs]) == [ "Layers[0:3]", "Layers[3:6]", "Layers[6:8]", ] - assert _paint_names(colr.table.LayerV1List.Paint) == [ + assert _paint_names(colr.table.LayerList.Paint) == [ "back1", "back2", "a_fore", @@ -1290,7 +1290,7 @@ def test_build_layerv1list_with_sharing(): "c_back", "Layers[0:2]", ] - assert colr.table.LayerV1List.LayerCount == 8 + assert colr.table.LayerList.LayerCount == 8 def test_build_layerv1list_with_overlaps(): @@ -1306,7 +1306,7 @@ def test_build_layerv1list_with_overlaps(): for c in "abcdefghi" ] - # list => PaintColrLayers, which means contents should be in LayerV1List + # list => PaintColrLayers, which means contents should be in LayerList colr = builder.buildCOLR( { "a": (ot.PaintFormat.PaintColrLayers, paints[0:4]), @@ -1319,10 +1319,10 @@ def test_build_layerv1list_with_overlaps(): assertIsColrV1(colr) assertNoV0Content(colr) - baseGlyphs = colr.table.BaseGlyphV1List.BaseGlyphV1Record - # assert colr.table.BaseGlyphV1List.BaseGlyphCount == 2 + baseGlyphs = colr.table.BaseGlyphList.BaseGlyphPaintRecord + # assert colr.table.BaseGlyphList.BaseGlyphCount == 2 - assert _paint_names(colr.table.LayerV1List.Paint) == [ + assert _paint_names(colr.table.LayerList.Paint) == [ "a", "b", "c", @@ -1340,7 +1340,7 @@ def test_build_layerv1list_with_overlaps(): "Layers[4:7]", "Layers[7:11]", ] - assert colr.table.LayerV1List.LayerCount == 11 + assert colr.table.LayerList.LayerCount == 11 def test_explicit_version_1(): @@ -1469,14 +1469,14 @@ class BuildCOLRTest(object): assert colr.table.LayerRecordCount == 2 assert isinstance(colr.table.LayerRecordArray, ot.LayerRecordArray) - assert isinstance(colr.table.BaseGlyphV1List, ot.BaseGlyphV1List) - assert colr.table.BaseGlyphV1List.BaseGlyphCount == 1 + assert isinstance(colr.table.BaseGlyphList, ot.BaseGlyphList) + assert colr.table.BaseGlyphList.BaseGlyphCount == 1 assert isinstance( - colr.table.BaseGlyphV1List.BaseGlyphV1Record[0], ot.BaseGlyphV1Record + colr.table.BaseGlyphList.BaseGlyphPaintRecord[0], ot.BaseGlyphPaintRecord ) - assert colr.table.BaseGlyphV1List.BaseGlyphV1Record[0].BaseGlyph == "d" - assert isinstance(colr.table.LayerV1List, ot.LayerV1List) - assert colr.table.LayerV1List.Paint[0].Glyph == "e" + assert colr.table.BaseGlyphList.BaseGlyphPaintRecord[0].BaseGlyph == "d" + assert isinstance(colr.table.LayerList, ot.LayerList) + assert colr.table.LayerList.Paint[0].Glyph == "e" def test_explicit_version_0(self): colr = builder.buildCOLR({"a": [("b", 0), ("c", 1)]}, version=0) @@ -1527,9 +1527,9 @@ class BuildCOLRTest(object): }, ) - assert colr.table.LayerV1List is None, "PaintColrLayers should be gone" - assert colr.table.BaseGlyphV1List.BaseGlyphCount == 1 - paint = colr.table.BaseGlyphV1List.BaseGlyphV1Record[0].Paint + assert colr.table.LayerList is None, "PaintColrLayers should be gone" + assert colr.table.BaseGlyphList.BaseGlyphCount == 1 + paint = colr.table.BaseGlyphList.BaseGlyphPaintRecord[0].Paint assert paint.Format == ot.PaintFormat.PaintGlyph assert paint.Paint.Format == ot.PaintFormat.PaintSolid diff --git a/Tests/subset/subset_test.py b/Tests/subset/subset_test.py index d9b942b7e..0933ca472 100644 --- a/Tests/subset/subset_test.py +++ b/Tests/subset/subset_test.py @@ -1150,11 +1150,11 @@ def test_subset_COLRv1_and_CPAL(colrv1_path): colr = subset_font["COLR"].table assert colr.Version == 1 assert len(colr.BaseGlyphRecordArray.BaseGlyphRecord) == 1 - assert len(colr.BaseGlyphV1List.BaseGlyphV1Record) == 3 # was 4 + assert len(colr.BaseGlyphList.BaseGlyphPaintRecord) == 3 # was 4 - base = colr.BaseGlyphV1List.BaseGlyphV1Record[0] + base = colr.BaseGlyphList.BaseGlyphPaintRecord[0] assert base.BaseGlyph == "uniE001" - layers = colr.LayerV1List.Paint[ + layers = colr.LayerList.Paint[ base.Paint.FirstLayerIndex: base.Paint.FirstLayerIndex + base.Paint.NumLayers ] assert len(layers) == 2 diff --git a/Tests/ttLib/tables/C_O_L_R_test.py b/Tests/ttLib/tables/C_O_L_R_test.py index b8202e78d..aa420074b 100644 --- a/Tests/ttLib/tables/C_O_L_R_test.py +++ b/Tests/ttLib/tables/C_O_L_R_test.py @@ -107,8 +107,8 @@ COLR_V1_SAMPLE = ( ), (b"\x00\x00\x00 ", "Offset to LayerRecordArray from beginning of table (32)"), (b"\x00\x03", "LayerRecordCount (3)"), - (b"\x00\x00\x00,", "Offset to BaseGlyphV1List from beginning of table (44)"), - (b"\x00\x00\x00\xac", "Offset to LayerV1List from beginning of table (172)"), + (b"\x00\x00\x00,", "Offset to BaseGlyphList from beginning of table (44)"), + (b"\x00\x00\x00\xac", "Offset to LayerList from beginning of table (172)"), (b"\x00\x00\x00\x00", "Offset to VarStore (NULL)"), (b"\x00\x06", "BaseGlyphRecord[0].BaseGlyph (6)"), (b"\x00\x00", "BaseGlyphRecord[0].FirstLayerIndex (0)"), @@ -119,33 +119,33 @@ COLR_V1_SAMPLE = ( (b"\x00\x01", "LayerRecord[1].PaletteIndex (1)"), (b"\x00\t", "LayerRecord[2].LayerGlyph (9)"), (b"\x00\x02", "LayerRecord[2].PaletteIndex (2)"), - # BaseGlyphV1List - (b"\x00\x00\x00\x03", "BaseGlyphV1List.BaseGlyphCount (3)"), - (b"\x00\n", "BaseGlyphV1List.BaseGlyphV1Record[0].BaseGlyph (10)"), + # BaseGlyphList + (b"\x00\x00\x00\x03", "BaseGlyphList.BaseGlyphCount (3)"), + (b"\x00\n", "BaseGlyphList.BaseGlyphPaintRecord[0].BaseGlyph (10)"), ( b"\x00\x00\x00\x16", - "Offset to Paint table from beginning of BaseGlyphV1List (22)", + "Offset to Paint table from beginning of BaseGlyphList (22)", ), - (b"\x00\x0e", "BaseGlyphV1List.BaseGlyphV1Record[1].BaseGlyph (14)"), + (b"\x00\x0e", "BaseGlyphList.BaseGlyphPaintRecord[1].BaseGlyph (14)"), ( b"\x00\x00\x00\x1c", - "Offset to Paint table from beginning of BaseGlyphV1List (28)", + "Offset to Paint table from beginning of BaseGlyphList (28)", ), - (b"\x00\x0f", "BaseGlyphV1List.BaseGlyphV1Record[2].BaseGlyph (15)"), + (b"\x00\x0f", "BaseGlyphList.BaseGlyphPaintRecord[2].BaseGlyph (15)"), ( b"\x00\x00\x00\x5b", - "Offset to Paint table from beginning of BaseGlyphV1List (91)", + "Offset to Paint table from beginning of BaseGlyphList (91)", ), - # BaseGlyphV1Record[0] - (b"\x01", "BaseGlyphV1Record[0].Paint.Format (1)"), - (b"\x04", "BaseGlyphV1Record[0].Paint.NumLayers (4)"), - (b"\x00\x00\x00\x00", "BaseGlyphV1Record[0].Paint.FirstLayerIndex (0)"), - # BaseGlyphV1Record[1] - (b"\x14", "BaseGlyphV1Record[1].Paint.Format (20)"), + # BaseGlyphPaintRecord[0] + (b"\x01", "BaseGlyphPaintRecord[0].Paint.Format (1)"), + (b"\x04", "BaseGlyphPaintRecord[0].Paint.NumLayers (4)"), + (b"\x00\x00\x00\x00", "BaseGlyphPaintRecord[0].Paint.FirstLayerIndex (0)"), + # BaseGlyphPaintRecord[1] + (b"\x14", "BaseGlyphPaintRecord[1].Paint.Format (20)"), (b"\x00\x00<", "Offset to SourcePaint from beginning of PaintComposite (60)"), - (b"\x03", "BaseGlyphV1Record[1].Paint.CompositeMode [SRC_OVER] (3)"), + (b"\x03", "BaseGlyphPaintRecord[1].Paint.CompositeMode [SRC_OVER] (3)"), (b"\x00\x00\x08", "Offset to BackdropPaint from beginning of PaintComposite (8)"), - (b"\x0d", "BaseGlyphV1Record[1].Paint.BackdropPaint.Format (13)"), + (b"\x0d", "BaseGlyphPaintRecord[1].Paint.BackdropPaint.Format (13)"), (b"\x00\x00\x34", "Offset to Paint from beginning of PaintVarTransform (52)"), (b"\x00\x01\x00\x00\xff\xff\xff\xff", "Affine2x3.xx.value (1.0)"), (b"\x00\x00\x00\x00\xff\xff\xff\xff", "Affine2x3.xy.value (0.0)"), @@ -153,13 +153,13 @@ COLR_V1_SAMPLE = ( (b"\x00\x01\x00\x00\xff\xff\xff\xff", "Affine2x3.yy.value (1.0)"), (b"\x01\x2c\x00\x00\xff\xff\xff\xff", "Affine2x3.dx.value (300.0)"), (b"\x00\x00\x00\x00\xff\xff\xff\xff", "Affine2x3.dy.value (0.0)"), - (b"\x0b", "BaseGlyphV1Record[1].Paint.SourcePaint.Format (11)"), - (b"\x00\n", "BaseGlyphV1Record[1].Paint.SourcePaint.Glyph (10)"), - # BaseGlyphV1Record[2] - (b"\x0a", "BaseGlyphV1Record[2].Paint.Format (10)"), + (b"\x0b", "BaseGlyphPaintRecord[1].Paint.SourcePaint.Format (11)"), + (b"\x00\n", "BaseGlyphPaintRecord[1].Paint.SourcePaint.Glyph (10)"), + # BaseGlyphPaintRecord[2] + (b"\x0a", "BaseGlyphPaintRecord[2].Paint.Format (10)"), (b"\x00\x00\x06", "Offset to Paint subtable from beginning of PaintGlyph (6)"), - (b"\x00\x0b", "BaseGlyphV1Record[2].Paint.Glyph (11)"), - (b"\x08", "BaseGlyphV1Record[2].Paint.Paint.Format (8)"), + (b"\x00\x0b", "BaseGlyphPaintRecord[2].Paint.Glyph (11)"), + (b"\x08", "BaseGlyphPaintRecord[2].Paint.Paint.Format (8)"), (b"\x00\x00\x10", "Offset to ColorLine from beginning of PaintSweepGradient (16)"), (b"\x01\x03", "centerX (259)"), (b"\x01\x2c", "centerY (300)"), @@ -173,38 +173,38 @@ COLR_V1_SAMPLE = ( (b"@\x00", "ColorLine.ColorStop[1].StopOffset (1.0)"), (b"\x00\x05", "ColorLine.ColorStop[1].Color.PaletteIndex (5)"), (b"@\x00", "ColorLine.ColorStop[1].Color.Alpha (1.0)"), - # LayerV1List - (b"\x00\x00\x00\x04", "LayerV1List.LayerCount (4)"), + # LayerList + (b"\x00\x00\x00\x04", "LayerList.LayerCount (4)"), ( b"\x00\x00\x00\x14", - "First Offset to Paint table from beginning of LayerV1List (20)", + "First Offset to Paint table from beginning of LayerList (20)", ), ( b"\x00\x00\x00\x23", - "Second Offset to Paint table from beginning of LayerV1List (35)", + "Second Offset to Paint table from beginning of LayerList (35)", ), ( b"\x00\x00\x00\x4e", - "Third Offset to Paint table from beginning of LayerV1List (78)", + "Third Offset to Paint table from beginning of LayerList (78)", ), ( b"\x00\x00\x00\xb7", - "Fourth Offset to Paint table from beginning of LayerV1List (183)", + "Fourth Offset to Paint table from beginning of LayerList (183)", ), # PaintGlyph glyph00011 - (b"\x0a", "LayerV1List.Paint[0].Format (10)"), + (b"\x0a", "LayerList.Paint[0].Format (10)"), (b"\x00\x00\x06", "Offset24 to Paint subtable from beginning of PaintGlyph (6)"), - (b"\x00\x0b", "LayerV1List.Paint[0].Glyph (glyph00011)"), + (b"\x00\x0b", "LayerList.Paint[0].Glyph (glyph00011)"), # PaintVarSolid - (b"\x03", "LayerV1List.Paint[0].Paint.Format (3)"), + (b"\x03", "LayerList.Paint[0].Paint.Format (3)"), (b"\x00\x02", "Paint.Color.PaletteIndex (2)"), (b" \x00", "Paint.Color.Alpha.value (0.5)"), (b"\xff\xff\xff\xff", "Paint.Color.Alpha.varIdx (0xFFFFFFFF)"), # PaintGlyph glyph00012 - (b"\x0a", "LayerV1List.Paint[1].Format (10)"), + (b"\x0a", "LayerList.Paint[1].Format (10)"), (b"\x00\x00\x06", "Offset to Paint subtable from beginning of PaintGlyph (6)"), - (b"\x00\x0c", "LayerV1List.Paint[1].Glyph (glyph00012)"), - (b"\x04", "LayerV1List.Paint[1].Paint.Format (4)"), + (b"\x00\x0c", "LayerList.Paint[1].Glyph (glyph00012)"), + (b"\x04", "LayerList.Paint[1].Paint.Format (4)"), (b"\x00\x00\x10", "Offset to ColorLine from beginning of PaintLinearGradient (16)"), (b"\x00\x01", "Paint.x0 (1)"), (b"\x00\x02", "Paint.y0 (2)"), @@ -224,10 +224,10 @@ COLR_V1_SAMPLE = ( (b"\x00\x05", "ColorLine.ColorStop[2].Color.PaletteIndex (5)"), (b"@\x00", "ColorLine.ColorStop[2].Color.Alpha (1.0)"), # PaintGlyph glyph00013 - (b"\x0a", "LayerV1List.Paint[2].Format (10)"), + (b"\x0a", "LayerList.Paint[2].Format (10)"), (b"\x00\x00\x06", "Offset to Paint subtable from beginning of PaintGlyph (6)"), - (b"\x00\r", "LayerV1List.Paint[2].Glyph (13)"), - (b"\x0c", "LayerV1List.Paint[2].Paint.Format (12)"), + (b"\x00\r", "LayerList.Paint[2].Glyph (13)"), + (b"\x0c", "LayerList.Paint[2].Paint.Format (12)"), (b"\x00\x00\x1c", "Offset to Paint subtable from beginning of PaintTransform (28)"), (b"\xff\xf3\x00\x00", "Affine2x3.xx (-13)"), (b"\x00\x0e\x00\x00", "Affine2x3.xy (14)"), @@ -235,7 +235,7 @@ COLR_V1_SAMPLE = ( (b"\xff\xef\x00\x00", "Affine2x3.yy (-17)"), (b"\x00\x12\x00\x00", "Affine2x3.yy (18)"), (b"\x00\x13\x00\x00", "Affine2x3.yy (19)"), - (b"\x07", "LayerV1List.Paint[2].Paint.Paint.Format (7)"), + (b"\x07", "LayerList.Paint[2].Paint.Paint.Format (7)"), (b"\x00\x00(", "Offset to ColorLine from beginning of PaintVarRadialGradient (40)"), (b"\x00\x07\xff\xff\xff\xff", "Paint.x0.value (7)"), (b"\x00\x08\xff\xff\xff\xff", "Paint.y0.value (8)"), @@ -252,29 +252,29 @@ COLR_V1_SAMPLE = ( (b"\x00\x07", "ColorLine.ColorStop[1].Color.PaletteIndex (7)"), (b"\x19\x9a\xff\xff\xff\xff", "ColorLine.ColorStop[1].Color.Alpha.value (0.4)"), # PaintTranslate - (b"\x0e", "LayerV1List.Paint[3].Format (14)"), + (b"\x0e", "LayerList.Paint[3].Format (14)"), (b"\x00\x00\x0c", "Offset to Paint subtable from beginning of PaintTranslate (12)"), (b"\x01\x01\x00\x00", "dx (257)"), (b"\x01\x02\x00\x00", "dy (258)"), # PaintRotate - (b"\x10", "LayerV1List.Paint[3].Paint.Format (16)"), + (b"\x10", "LayerList.Paint[3].Paint.Format (16)"), (b"\x00\x00\x10", "Offset to Paint subtable from beginning of PaintRotate (16)"), (b"\x00\x2d\x00\x00", "angle (45)"), (b"\x00\xff\x00\x00", "centerX (255)"), (b"\x01\x00\x00\x00", "centerY (256)"), # PaintSkew - (b"\x12", "LayerV1List.Paint[3].Paint.Paint.Format (18)"), + (b"\x12", "LayerList.Paint[3].Paint.Paint.Format (18)"), (b"\x00\x00\x14", "Offset to Paint subtable from beginning of PaintSkew (20)"), (b"\xff\xf5\x00\x00", "xSkewAngle (-11)"), (b"\x00\x05\x00\x00", "ySkewAngle (5)"), (b"\x00\xfd\x00\x00", "centerX.value (253)"), (b"\x00\xfe\x00\x00", "centerY.value (254)"), # PaintGlyph - (b"\x0a", "LayerV1List.Paint[3].Paint.Paint.Paint.Format (10)"), + (b"\x0a", "LayerList.Paint[3].Paint.Paint.Paint.Format (10)"), (b"\x00\x00\x06", "Offset to Paint subtable from beginning of PaintGlyph (6)"), - (b"\x00\x0b", "LayerV1List.Paint[2].Glyph (11)"), + (b"\x00\x0b", "LayerList.Paint[2].Glyph (11)"), # PaintSolid - (b"\x02", "LayerV1List.Paint[0].Paint.Paint.Paint.Paint.Format (2)"), + (b"\x02", "LayerList.Paint[0].Paint.Paint.Paint.Paint.Format (2)"), (b"\x00\x02", "Paint.Color.PaletteIndex (2)"), (b" \x00", "Paint.Color.Alpha (0.5)"), ) @@ -306,16 +306,16 @@ COLR_V1_XML = [ " ", "", "", - "", + "", " ", - ' ', + ' ', ' ', ' ', ' ', ' ', " ", - " ", - ' ', + " ", + ' ', ' ', ' ', ' ', @@ -336,8 +336,8 @@ COLR_V1_XML = [ " ", " ", " ", - " ", - ' ', + " ", + ' ', ' ', ' ', ' ', @@ -366,9 +366,9 @@ COLR_V1_XML = [ " ", ' ', " ", - " ", - "", - "", + " ", + "", + "", " ", ' ', ' ', @@ -478,7 +478,7 @@ COLR_V1_XML = [ ' ', ' ', " ", - "", + "", ]