WIP: add buildPaintColrLayers

This commit is contained in:
Cosimo Lupo 2020-11-03 19:11:24 +00:00
parent d285481215
commit 581416d77c
No known key found for this signature in database
GPG Key ID: 179A8F0895A02F4F
3 changed files with 23 additions and 8 deletions

View File

@ -39,7 +39,7 @@ T = TypeVar("T")
_Kwargs = Mapping[str, Any]
_PaintInput = Union[int, _Kwargs, ot.Paint, Tuple[str, "_PaintInput"]]
_PaintInputList = Sequence[_PaintInput]
_ColorGlyphsDict = Dict[str, Union[_PaintInputList, ot.LayerV1List]]
_ColorGlyphsDict = Dict[str, Union[_PaintInputList, _PaintInput]]
_ColorGlyphsV0Dict = Dict[str, Sequence[Tuple[str, int]]]
_Number = Union[int, float]
_ScalarInput = Union[_Number, VariableValue, Tuple[_Number, int]]
@ -55,7 +55,7 @@ _AffineTuple = Tuple[
]
_AffineInput = Union[_AffineTuple, ot.Affine2x3]
MAX_LAYER_V1_COUNT = 255
MAX_PAINT_COLR_LAYER_COUNT = 255
def populateCOLRv0(
@ -571,15 +571,23 @@ def buildPaint(paint: _PaintInput) -> ot.Paint:
def buildLayerV1List(layers: _PaintInputList) -> ot.LayerV1List:
self = ot.LayerV1List()
layerCount = len(layers)
if layerCount > MAX_LAYER_V1_COUNT:
raise OverflowError(
"LayerV1List.LayerCount: {layerCount} > {MAX_LAYER_V1_COUNT}"
)
self.LayerCount = layerCount
self.Paint = [buildPaint(layer) for layer in layers]
return self
def buildPaintColrLayers(firstLayerIndex: int, numLayers: int) -> ot.Paint:
self = ot.Paint()
self.Format = int(ot.Paint.Format.PaintColrLayers)
if numLayers > MAX_PAINT_COLR_LAYER_COUNT:
raise OverflowError(
"PaintColrLayers.NumLayers: {numLayers} > {MAX_PAINT_COLR_LAYER_COUNT}"
)
self.NumLayers = numLayers
self.FirstLayerIndex = firstLayerIndex
return self
def buildBaseGlyphV1Record(
baseGlyph: str, layers: Union[_PaintInputList, ot.LayerV1List]
) -> ot.BaseGlyphV1List:

View File

@ -1550,6 +1550,7 @@ otData = [
('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', 'VarStore', None, 'Version >= 1', 'Offset to variation store (may be NULL)'),
]),
@ -1579,11 +1580,11 @@ otData = [
('BaseGlyphV1Record', [
('GlyphID', 'BaseGlyph', None, None, 'Glyph ID of reference glyph.'),
('LOffset', 'LayerV1List', None, None, 'Offset (from beginning of BaseGlyphV1List) to LayerV1List.'),
('LOffset', 'Paint', None, None, 'Offset (from beginning of BaseGlyphV1Record) to Paint, typically a PaintColrLayers.'),
]),
('LayerV1List', [
('uint8', 'LayerCount', None, None, 'Number of Version-1 Layers'),
('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.'),
]),
@ -1660,4 +1661,9 @@ otData = [
('CompositeMode', 'CompositeMode', None, None, 'A CompositeMode enumeration value.'),
('LOffset24To(Paint)', 'BackdropPaint', None, None, 'Offset (from beginning of PaintComposite table) to backdrop Paint subtable.'),
]),
('PaintFormat8', [
('uint8', 'PaintFormat', None, None, 'Format identifier-format = 8'),
('uint8', 'NumLayers', None, None, 'Number of offsets to Paint to read from LayerV1List.'),
('uint32', 'FirstLayerIndex', None, None, 'Index into LayerV1List.'),
]),
]

View File

@ -1334,6 +1334,7 @@ class Paint(getFormatSwitchingBaseTableClass("uint8")):
PaintColrSlice = 5
PaintTransform = 6
PaintComposite = 7
PaintColrLayers = 8
def getFormatName(self):
try: