rename BaseGlyphV1Array to BaseGlyphV1List

As suggested by Peter Constable in https://github.com/googlefonts/colr-gradients-spec/issues/14 and https://github.com/googlefonts/colr-gradients-spec/issues/18
This commit is contained in:
Cosimo Lupo 2020-07-01 18:16:07 +01:00
parent 50546c03c4
commit 5f18d9891c
No known key found for this signature in database
GPG Key ID: 179A8F0895A02F4F
5 changed files with 24 additions and 24 deletions

View File

@ -132,7 +132,7 @@ def buildCOLR(
colr.BaseGlyphRecordArray = colr.LayerRecordArray = None
if colorGlyphsV1:
colr.BaseGlyphV1Array = buildBaseGlyphV1Array(colorGlyphsV1, glyphMap)
colr.BaseGlyphV1List = buildBaseGlyphV1List(colorGlyphsV1, glyphMap)
if version is None:
version = 1 if (varStore or colorGlyphsV1) else 0
@ -495,7 +495,7 @@ def buildLayerV1Array(
def buildBaseGlyphV1Record(
baseGlyph: str, layers: Union[_LayersList, ot.LayerV1Array]
) -> ot.BaseGlyphV1Array:
) -> ot.BaseGlyphV1List:
self = ot.BaseGlyphV1Record()
self.BaseGlyph = baseGlyph
if not isinstance(layers, ot.LayerV1Array):
@ -504,10 +504,10 @@ def buildBaseGlyphV1Record(
return self
def buildBaseGlyphV1Array(
def buildBaseGlyphV1List(
colorGlyphs: Union[_ColorGlyphsDict, Dict[str, ot.LayerV1Array]],
glyphMap: Optional[Mapping[str, int]] = None,
) -> ot.BaseGlyphV1Array:
) -> ot.BaseGlyphV1List:
if glyphMap is not None:
colorGlyphItems = sorted(
colorGlyphs.items(), key=lambda item: glyphMap[item[0]]
@ -518,7 +518,7 @@ def buildBaseGlyphV1Array(
buildBaseGlyphV1Record(baseGlyph, layers)
for baseGlyph, layers in colorGlyphItems
]
self = ot.BaseGlyphV1Array()
self = ot.BaseGlyphV1List()
self.BaseGlyphCount = len(records)
self.BaseGlyphV1Record = records
return self

View File

@ -1549,7 +1549,7 @@ 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', 'BaseGlyphV1Array', None, 'Version >= 1', 'Offset (from beginning of COLR table) to array of Version-1 Base Glyph records.'),
('LOffset', 'BaseGlyphV1List', None, 'Version >= 1', 'Offset (from beginning of COLR table) to array of Version-1 Base Glyph records.'),
('LOffset', 'VarStore', None, 'Version >= 1', 'Offset to variation store (may be NULL)'),
]),
@ -1572,14 +1572,14 @@ otData = [
('uint16', 'PaletteIndex', None, None, 'Index value to use with a selected color palette.'),
]),
('BaseGlyphV1Array', [
('BaseGlyphV1List', [
('uint32', 'BaseGlyphCount', None, None, 'Number of Version-1 Base Glyph records'),
('struct', 'BaseGlyphV1Record', 'BaseGlyphCount', 0, 'Array of Version-1 Base Glyph records'),
]),
('BaseGlyphV1Record', [
('GlyphID', 'BaseGlyph', None, None, 'Glyph ID of reference glyph.'),
('LOffset', 'LayerV1Array', None, None, 'Offset (from beginning of BaseGlyphV1Array) to LayerV1Array.'),
('LOffset', 'LayerV1Array', None, None, 'Offset (from beginning of BaseGlyphV1List) to LayerV1Array.'),
]),
('LayerV1Array', [

View File

@ -1197,7 +1197,7 @@ class BaseGlyphRecordArray(BaseTable):
return self.__dict__.copy()
class BaseGlyphV1Array(BaseTable):
class BaseGlyphV1List(BaseTable):
def preWrite(self, font):
self.BaseGlyphV1Record = sorted(

View File

@ -521,7 +521,7 @@ def test_buildBaseGlyphV1Record():
assert baseGlyphRec.LayerV1Array == layerArray
def test_buildBaseGlyphV1Array():
def test_buildBaseGlyphV1List():
colorGlyphs = {
"a": [("b", 0), ("c", 1)],
"d": [
@ -552,13 +552,13 @@ def test_buildBaseGlyphV1Array():
"h": 8,
}
baseGlyphArray = builder.buildBaseGlyphV1Array(colorGlyphs, glyphMap)
baseGlyphArray = builder.buildBaseGlyphV1List(colorGlyphs, glyphMap)
assert baseGlyphArray.BaseGlyphCount == len(colorGlyphs)
assert baseGlyphArray.BaseGlyphV1Record[0].BaseGlyph == "d"
assert baseGlyphArray.BaseGlyphV1Record[1].BaseGlyph == "a"
assert baseGlyphArray.BaseGlyphV1Record[2].BaseGlyph == "g"
baseGlyphArray = builder.buildBaseGlyphV1Array(colorGlyphs)
baseGlyphArray = builder.buildBaseGlyphV1List(colorGlyphs)
assert baseGlyphArray.BaseGlyphCount == len(colorGlyphs)
assert baseGlyphArray.BaseGlyphV1Record[0].BaseGlyph == "a"
assert baseGlyphArray.BaseGlyphV1Record[1].BaseGlyph == "d"
@ -706,18 +706,18 @@ class BuildCOLRTest(object):
assert colr.table.LayerRecordCount == 2
assert isinstance(colr.table.LayerRecordArray, ot.LayerRecordArray)
assert isinstance(colr.table.BaseGlyphV1Array, ot.BaseGlyphV1Array)
assert colr.table.BaseGlyphV1Array.BaseGlyphCount == 1
assert isinstance(colr.table.BaseGlyphV1List, ot.BaseGlyphV1List)
assert colr.table.BaseGlyphV1List.BaseGlyphCount == 1
assert isinstance(
colr.table.BaseGlyphV1Array.BaseGlyphV1Record[0], ot.BaseGlyphV1Record
colr.table.BaseGlyphV1List.BaseGlyphV1Record[0], ot.BaseGlyphV1Record
)
assert colr.table.BaseGlyphV1Array.BaseGlyphV1Record[0].BaseGlyph == "d"
assert colr.table.BaseGlyphV1List.BaseGlyphV1Record[0].BaseGlyph == "d"
assert isinstance(
colr.table.BaseGlyphV1Array.BaseGlyphV1Record[0].LayerV1Array,
colr.table.BaseGlyphV1List.BaseGlyphV1Record[0].LayerV1Array,
ot.LayerV1Array,
)
assert (
colr.table.BaseGlyphV1Array.BaseGlyphV1Record[0]
colr.table.BaseGlyphV1List.BaseGlyphV1Record[0]
.LayerV1Array.LayerV1Record[0]
.LayerGlyph
== "e"

View File

@ -71,7 +71,7 @@ COLR_V1_DATA = (
b"\x00\x00\x00\x16" # Offset to BaseGlyphRecordArray from beginning of table (22)
b"\x00\x00\x00\x1c" # Offset to LayerRecordArray from beginning of table (28)
b"\x00\x03" # LayerRecordCount (3)
b"\x00\x00\x00(" # Offset to BaseGlyphV1Array from beginning of table (40)
b"\x00\x00\x00(" # Offset to BaseGlyphV1List from beginning of table (40)
b"\x00\x00\x00\x00" # Offset to VarStore (NULL)
b"\x00\x06" # BaseGlyphRecord[0].BaseGlyph (6)
b"\x00\x00" # BaseGlyphRecord[0].FirstLayerIndex (0)
@ -82,9 +82,9 @@ COLR_V1_DATA = (
b"\x00\x01" # LayerRecord[1].PaletteIndex (1)
b"\x00\t" # LayerRecord[2].LayerGlyph (9)
b"\x00\x02" # LayerRecord[2].PaletteIndex (2)
b"\x00\x00\x00\x01" # BaseGlyphV1Array.BaseGlyphCount (1)
b"\x00\n" # BaseGlyphV1Array.BaseGlyphV1Record[0].BaseGlyph (10)
b"\x00\x00\x00\n" # Offset to LayerV1Array from beginning of BaseGlyphV1Array (10)
b"\x00\x00\x00\x01" # BaseGlyphV1List.BaseGlyphCount (1)
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\x03" # LayerV1Array.LayerCount (3)
b"\x00\x0b" # LayerV1Array.LayerV1Record[0].LayerGlyph (11)
b"\x00\x00\x00\x16" # Offset to Paint from beginning of LayerV1Array (22)
@ -190,7 +190,7 @@ COLR_V1_XML = [
" </LayerRecord>",
"</LayerRecordArray>",
"<!-- LayerRecordCount=3 -->",
"<BaseGlyphV1Array>",
"<BaseGlyphV1List>",
" <!-- BaseGlyphCount=1 -->",
' <BaseGlyphV1Record index="0">',
' <BaseGlyph value="glyph00010"/>',
@ -288,7 +288,7 @@ COLR_V1_XML = [
" </LayerV1Record>",
" </LayerV1Array>",
" </BaseGlyphV1Record>",
"</BaseGlyphV1Array>",
"</BaseGlyphV1List>",
]