Rename LayerV1Array to LayerV1List, like with BaseGlyphV1List

See https://github.com/googlefonts/colr-gradients-spec/issues/14#issuecomment-652542829
This commit is contained in:
Cosimo Lupo 2020-07-01 18:22:03 +01:00
parent 5f18d9891c
commit b215c000df
No known key found for this signature in database
GPG Key ID: 179A8F0895A02F4F
4 changed files with 30 additions and 30 deletions

View File

@ -476,10 +476,10 @@ def buildLayerV1Record(layerGlyph: str, paint: _PaintInput) -> ot.LayerV1Record:
return self return self
def buildLayerV1Array( def buildLayerV1List(
layers: Sequence[Union[_LayerTuple, ot.LayerV1Record]] layers: Sequence[Union[_LayerTuple, ot.LayerV1Record]]
) -> ot.LayerV1Array: ) -> ot.LayerV1List:
self = ot.LayerV1Array() self = ot.LayerV1List()
self.LayerCount = len(layers) self.LayerCount = len(layers)
records = [] records = []
for layer in layers: for layer in layers:
@ -494,18 +494,18 @@ def buildLayerV1Array(
def buildBaseGlyphV1Record( def buildBaseGlyphV1Record(
baseGlyph: str, layers: Union[_LayersList, ot.LayerV1Array] baseGlyph: str, layers: Union[_LayersList, ot.LayerV1List]
) -> ot.BaseGlyphV1List: ) -> ot.BaseGlyphV1List:
self = ot.BaseGlyphV1Record() self = ot.BaseGlyphV1Record()
self.BaseGlyph = baseGlyph self.BaseGlyph = baseGlyph
if not isinstance(layers, ot.LayerV1Array): if not isinstance(layers, ot.LayerV1List):
layers = buildLayerV1Array(layers) layers = buildLayerV1List(layers)
self.LayerV1Array = layers self.LayerV1List = layers
return self return self
def buildBaseGlyphV1List( def buildBaseGlyphV1List(
colorGlyphs: Union[_ColorGlyphsDict, Dict[str, ot.LayerV1Array]], colorGlyphs: Union[_ColorGlyphsDict, Dict[str, ot.LayerV1List]],
glyphMap: Optional[Mapping[str, int]] = None, glyphMap: Optional[Mapping[str, int]] = None,
) -> ot.BaseGlyphV1List: ) -> ot.BaseGlyphV1List:
if glyphMap is not None: if glyphMap is not None:

View File

@ -1579,17 +1579,17 @@ otData = [
('BaseGlyphV1Record', [ ('BaseGlyphV1Record', [
('GlyphID', 'BaseGlyph', None, None, 'Glyph ID of reference glyph.'), ('GlyphID', 'BaseGlyph', None, None, 'Glyph ID of reference glyph.'),
('LOffset', 'LayerV1Array', None, None, 'Offset (from beginning of BaseGlyphV1List) to LayerV1Array.'), ('LOffset', 'LayerV1List', None, None, 'Offset (from beginning of BaseGlyphV1List) to LayerV1List.'),
]), ]),
('LayerV1Array', [ ('LayerV1List', [
('uint32', 'LayerCount', None, None, 'Number of Version-1 Layer records'), ('uint32', 'LayerCount', None, None, 'Number of Version-1 Layer records'),
('struct', 'LayerV1Record', 'LayerCount', 0, 'Array of Version-1 Layer records'), ('struct', 'LayerV1Record', 'LayerCount', 0, 'Array of Version-1 Layer records'),
]), ]),
('LayerV1Record', [ ('LayerV1Record', [
('GlyphID', 'LayerGlyph', None, None, 'Glyph ID of layer glyph (must be in z-order from bottom to top).'), ('GlyphID', 'LayerGlyph', None, None, 'Glyph ID of layer glyph (must be in z-order from bottom to top).'),
('LOffset', 'Paint', None, None, 'Offset (from beginning of LayerV1Array) to Paint subtable.'), ('LOffset', 'Paint', None, None, 'Offset (from beginning of LayerV1List) to Paint subtable.'),
]), ]),
('Affine2x2', [ ('Affine2x2', [

View File

@ -472,7 +472,7 @@ def test_buildLayerV1Record_from_dict():
assert layer.Paint.r0.value == 4 assert layer.Paint.r0.value == 4
def test_buildLayerV1Array(): def test_buildLayerV1List():
layers = [ layers = [
("a", 1), ("a", 1),
("b", {"format": 1, "paletteIndex": 2, "transparency": 0.5}), ("b", {"format": 1, "paletteIndex": 2, "transparency": 0.5}),
@ -504,7 +504,7 @@ def test_buildLayerV1Array():
), ),
builder.buildLayerV1Record("e", builder.buildSolidColorPaint(8)), builder.buildLayerV1Record("e", builder.buildSolidColorPaint(8)),
] ]
layersArray = builder.buildLayerV1Array(layers) layersArray = builder.buildLayerV1List(layers)
assert layersArray.LayerCount == len(layersArray.LayerV1Record) assert layersArray.LayerCount == len(layersArray.LayerV1Record)
assert all(isinstance(l, ot.LayerV1Record) for l in layersArray.LayerV1Record) assert all(isinstance(l, ot.LayerV1Record) for l in layersArray.LayerV1Record)
@ -513,12 +513,12 @@ def test_buildLayerV1Array():
def test_buildBaseGlyphV1Record(): def test_buildBaseGlyphV1Record():
baseGlyphRec = builder.buildBaseGlyphV1Record("a", [("b", 0), ("c", 1)]) baseGlyphRec = builder.buildBaseGlyphV1Record("a", [("b", 0), ("c", 1)])
assert baseGlyphRec.BaseGlyph == "a" assert baseGlyphRec.BaseGlyph == "a"
assert isinstance(baseGlyphRec.LayerV1Array, ot.LayerV1Array) assert isinstance(baseGlyphRec.LayerV1List, ot.LayerV1List)
layerArray = builder.buildLayerV1Array([("b", 0), ("c", 1)]) layerArray = builder.buildLayerV1List([("b", 0), ("c", 1)])
baseGlyphRec = builder.buildBaseGlyphV1Record("a", layerArray) baseGlyphRec = builder.buildBaseGlyphV1Record("a", layerArray)
assert baseGlyphRec.BaseGlyph == "a" assert baseGlyphRec.BaseGlyph == "a"
assert baseGlyphRec.LayerV1Array == layerArray assert baseGlyphRec.LayerV1List == layerArray
def test_buildBaseGlyphV1List(): def test_buildBaseGlyphV1List():
@ -538,7 +538,7 @@ def test_buildBaseGlyphV1List():
}, },
), ),
], ],
"g": builder.buildLayerV1Array([("h", 5)]), "g": builder.buildLayerV1List([("h", 5)]),
} }
glyphMap = { glyphMap = {
".notdef": 0, ".notdef": 0,
@ -713,12 +713,12 @@ class BuildCOLRTest(object):
) )
assert colr.table.BaseGlyphV1List.BaseGlyphV1Record[0].BaseGlyph == "d" assert colr.table.BaseGlyphV1List.BaseGlyphV1Record[0].BaseGlyph == "d"
assert isinstance( assert isinstance(
colr.table.BaseGlyphV1List.BaseGlyphV1Record[0].LayerV1Array, colr.table.BaseGlyphV1List.BaseGlyphV1Record[0].LayerV1List,
ot.LayerV1Array, ot.LayerV1List,
) )
assert ( assert (
colr.table.BaseGlyphV1List.BaseGlyphV1Record[0] colr.table.BaseGlyphV1List.BaseGlyphV1Record[0]
.LayerV1Array.LayerV1Record[0] .LayerV1List.LayerV1Record[0]
.LayerGlyph .LayerGlyph
== "e" == "e"
) )

View File

@ -84,14 +84,14 @@ COLR_V1_DATA = (
b"\x00\x02" # LayerRecord[2].PaletteIndex (2) b"\x00\x02" # LayerRecord[2].PaletteIndex (2)
b"\x00\x00\x00\x01" # BaseGlyphV1List.BaseGlyphCount (1) b"\x00\x00\x00\x01" # BaseGlyphV1List.BaseGlyphCount (1)
b"\x00\n" # BaseGlyphV1List.BaseGlyphV1Record[0].BaseGlyph (10) b"\x00\n" # BaseGlyphV1List.BaseGlyphV1Record[0].BaseGlyph (10)
b"\x00\x00\x00\n" # Offset to LayerV1Array from beginning of BaseGlyphV1List (10) b"\x00\x00\x00\n" # Offset to LayerV1List from beginning of BaseGlyphV1List (10)
b"\x00\x00\x00\x03" # LayerV1Array.LayerCount (3) b"\x00\x00\x00\x03" # LayerV1List.LayerCount (3)
b"\x00\x0b" # LayerV1Array.LayerV1Record[0].LayerGlyph (11) b"\x00\x0b" # LayerV1List.LayerV1Record[0].LayerGlyph (11)
b"\x00\x00\x00\x16" # Offset to Paint from beginning of LayerV1Array (22) b"\x00\x00\x00\x16" # Offset to Paint from beginning of LayerV1List (22)
b"\x00\x0c" # LayerV1Array.LayerV1Record[1].LayerGlyph (12) b"\x00\x0c" # LayerV1List.LayerV1Record[1].LayerGlyph (12)
b"\x00\x00\x00 " # Offset to Paint from beginning of LayerV1Array (32) b"\x00\x00\x00 " # Offset to Paint from beginning of LayerV1List (32)
b"\x00\r" # LayerV1Array.LayerV1Record[2].LayerGlyph (13) b"\x00\r" # LayerV1List.LayerV1Record[2].LayerGlyph (13)
b"\x00\x00\x00x" # Offset to Paint from beginning of LayerV1Array (120) b"\x00\x00\x00x" # Offset to Paint from beginning of LayerV1List (120)
b"\x00\x01" # Paint.Format (1) b"\x00\x01" # Paint.Format (1)
b"\x00\x02" # Paint.Color.PaletteIndex (2) b"\x00\x02" # Paint.Color.PaletteIndex (2)
b" \x00" # Paint.Color.Transparency.value (0.5) b" \x00" # Paint.Color.Transparency.value (0.5)
@ -194,7 +194,7 @@ COLR_V1_XML = [
" <!-- BaseGlyphCount=1 -->", " <!-- BaseGlyphCount=1 -->",
' <BaseGlyphV1Record index="0">', ' <BaseGlyphV1Record index="0">',
' <BaseGlyph value="glyph00010"/>', ' <BaseGlyph value="glyph00010"/>',
" <LayerV1Array>", " <LayerV1List>",
" <!-- LayerCount=3 -->", " <!-- LayerCount=3 -->",
' <LayerV1Record index="0">', ' <LayerV1Record index="0">',
' <LayerGlyph value="glyph00011"/>', ' <LayerGlyph value="glyph00011"/>',
@ -286,7 +286,7 @@ COLR_V1_XML = [
" </Affine>", " </Affine>",
" </Paint>", " </Paint>",
" </LayerV1Record>", " </LayerV1Record>",
" </LayerV1Array>", " </LayerV1List>",
" </BaseGlyphV1Record>", " </BaseGlyphV1Record>",
"</BaseGlyphV1List>", "</BaseGlyphV1List>",
] ]