COLRv1: define new PaintSweepGradient, amend tests with new format numbers

This commit is contained in:
Cosimo Lupo 2021-02-03 18:21:03 +00:00
parent 728258d66f
commit 93c23eaaf7
No known key found for this signature in database
GPG Key ID: 179A8F0895A02F4F
5 changed files with 85 additions and 58 deletions

View File

@ -549,6 +549,23 @@ class LayerV1ListBuilder:
return ot_paint
def buildPaintSweepGradient(
self,
colorLine: _ColorLineInput,
centerX: _ScalarInput,
centerY: _ScalarInput,
startAngle: _ScalarInput,
endAngle: _ScalarInput,
) -> ot.Paint:
ot_paint = ot.Paint()
ot_paint.Format = int(ot.Paint.Format.PaintSweepGradient)
ot_paint.ColorLine = _to_color_line(colorLine)
ot_paint.centerX = _to_variable_int16(centerX)
ot_paint.centerY = _to_variable_int16(centerY)
ot_paint.startAngle = _to_variable_f16dot16_float(startAngle)
ot_paint.endAngle = _to_variable_f16dot16_float(endAngle)
return ot_paint
def buildPaintGlyph(self, glyph: str, paint: _PaintInput) -> ot.Paint:
ot_paint = ot.Paint()
ot_paint.Format = int(ot.Paint.Format.PaintGlyph)

View File

@ -1648,38 +1648,47 @@ otData = [
('PaintFormat5', [
('uint8', 'PaintFormat', None, None, 'Format identifier-format = 5'),
('Offset24', 'Paint', None, None, 'Offset (from beginning of PaintGlyph table) to Paint subtable.'),
('GlyphID', 'Glyph', None, None, 'Glyph ID for the source outline.'),
('Offset24', 'ColorLine', None, None, 'Offset (from beginning of PaintSweep table) to ColorLine subtable.'),
('VarInt16', 'centerX', None, None, 'Center x coordinate.'),
('VarInt16', 'centerY', None, None, 'Center y coordinate.'),
('VarFixed', 'startAngle', None, None, 'Start of the angular range of the gradient.'),
('VarFixed', 'endAngle', None, None, 'End of the angular range of the gradient.'),
]),
('PaintFormat6', [
('uint8', 'PaintFormat', None, None, 'Format identifier-format = 6'),
('GlyphID', 'Glyph', None, None, 'Virtual glyph ID for a BaseGlyphV1List base glyph.'),
('Offset24', 'Paint', None, None, 'Offset (from beginning of PaintGlyph table) to Paint subtable.'),
('GlyphID', 'Glyph', None, None, 'Glyph ID for the source outline.'),
]),
('PaintFormat7', [
('uint8', 'PaintFormat', None, None, 'Format identifier-format = 7'),
('Offset24', 'Paint', None, None, 'Offset (from beginning of PaintTransformed table) to Paint subtable.'),
('Affine2x3', 'Transform', None, None, 'Offset (from beginning of PaintTrasformed table) to Affine2x3 subtable.'),
('GlyphID', 'Glyph', None, None, 'Virtual glyph ID for a BaseGlyphV1List base glyph.'),
]),
('PaintFormat8', [
('uint8', 'PaintFormat', None, None, 'Format identifier-format = 8'),
('Offset24', 'Paint', None, None, 'Offset (from beginning of PaintTransformed table) to Paint subtable.'),
('Affine2x3', 'Transform', None, None, 'Offset (from beginning of PaintTrasformed table) to Affine2x3 subtable.'),
]),
('PaintFormat9', [
('uint8', 'PaintFormat', None, None, 'Format identifier-format = 9'),
('Offset24', 'Paint', None, None, 'Offset (from beginning of PaintTranslate table) to Paint subtable.'),
('VarFixed', 'dx', None, None, 'Translation in x direction.'),
('VarFixed', 'dy', None, None, 'Translation in y direction.'),
]),
('PaintFormat9', [
('uint8', 'PaintFormat', None, None, 'Format identifier-format = 9'),
('PaintFormat10', [
('uint8', 'PaintFormat', None, None, 'Format identifier-format = 10'),
('Offset24', 'Paint', None, None, 'Offset (from beginning of PaintRotate table) to Paint subtable.'),
('VarFixed', 'angle', None, None, ''),
('VarFixed', 'centerX', None, None, ''),
('VarFixed', 'centerY', None, None, ''),
]),
('PaintFormat10', [
('uint8', 'PaintFormat', None, None, 'Format identifier-format = 10'),
('PaintFormat11', [
('uint8', 'PaintFormat', None, None, 'Format identifier-format = 11'),
('Offset24', 'Paint', None, None, 'Offset (from beginning of PaintSkew table) to Paint subtable.'),
('VarFixed', 'xSkewAngle', None, None, ''),
('VarFixed', 'ySkewAngle', None, None, ''),
@ -1687,8 +1696,8 @@ otData = [
('VarFixed', 'centerY', None, None, ''),
]),
('PaintFormat11', [
('uint8', 'PaintFormat', None, None, 'Format identifier-format = 11'),
('PaintFormat12', [
('uint8', 'PaintFormat', None, None, 'Format identifier-format = 12'),
('LOffset24To(Paint)', 'SourcePaint', None, None, 'Offset (from beginning of PaintComposite table) to source Paint subtable.'),
('CompositeMode', 'CompositeMode', None, None, 'A CompositeMode enumeration value.'),
('LOffset24To(Paint)', 'BackdropPaint', None, None, 'Offset (from beginning of PaintComposite table) to backdrop Paint subtable.'),

View File

@ -1331,13 +1331,14 @@ class Paint(getFormatSwitchingBaseTableClass("uint8")):
PaintSolid = 2
PaintLinearGradient = 3
PaintRadialGradient = 4
PaintGlyph = 5
PaintColrGlyph = 6
PaintTransform = 7
PaintTranslate = 8
PaintRotate = 9
PaintSkew = 10
PaintComposite = 11
PaintSweepGradient = 5
PaintGlyph = 6
PaintColrGlyph = 7
PaintTransform = 8
PaintTranslate = 9
PaintRotate = 10
PaintSkew = 11
PaintComposite = 12
def getFormatName(self):
try:

View File

@ -545,10 +545,10 @@ def test_buildPaintComposite():
composite = layerBuilder.buildPaintComposite(
mode=ot.CompositeMode.SRC_OVER,
source={
"format": 11,
"format": 12,
"mode": "src_over",
"source": {"format": 5, "glyph": "c", "paint": 2},
"backdrop": {"format": 5, "glyph": "b", "paint": 1},
"source": {"format": 6, "glyph": "c", "paint": 2},
"backdrop": {"format": 6, "glyph": "b", "paint": 1},
},
backdrop=layerBuilder.buildPaintGlyph(
"a", layerBuilder.buildPaintSolid(paletteIndex=0, alpha=1.0)
@ -679,7 +679,7 @@ def test_buildColrV1_more_than_255_paints():
colorGlyphs = {
"a": [
{
"format": 5, # PaintGlyph
"format": 6, # PaintGlyph
"paint": 0,
"glyph": name,
}
@ -775,18 +775,18 @@ def assertNoV0Content(colr):
def test_build_layerv1list_empty():
# Nobody uses PaintColrLayers (format 8), no layerlist
# Nobody uses PaintColrLayers (format 1), no layerlist
colr = builder.buildCOLR(
{
"a": {
"format": 5, # PaintGlyph
"format": 6, # PaintGlyph
"paint": {"format": 2, "paletteIndex": 2, "alpha": 0.8},
"glyph": "b",
},
# A list of 1 shouldn't become a PaintColrLayers
"b": [
{
"format": 5, # PaintGlyph
"format": 6, # PaintGlyph
"paint": {
"format": 3,
"colorLine": {
@ -832,17 +832,17 @@ def test_build_layerv1list_simple():
# All layers use the same solid paint
solid_paint = {"format": 2, "paletteIndex": 2, "alpha": 0.8}
backdrop = {
"format": 5, # PaintGlyph
"format": 6, # PaintGlyph
"paint": solid_paint,
"glyph": "back",
}
a_foreground = {
"format": 5, # PaintGlyph
"format": 6, # PaintGlyph
"paint": solid_paint,
"glyph": "a_fore",
}
b_foreground = {
"format": 5, # PaintGlyph
"format": 6, # PaintGlyph
"paint": solid_paint,
"glyph": "b_fore",
}
@ -882,33 +882,33 @@ def test_build_layerv1list_with_sharing():
solid_paint = {"format": 2, "paletteIndex": 2, "alpha": 0.8}
backdrop = [
{
"format": 5, # PaintGlyph
"format": 6, # PaintGlyph
"paint": solid_paint,
"glyph": "back1",
},
{
"format": 5, # PaintGlyph
"format": 6, # PaintGlyph
"paint": solid_paint,
"glyph": "back2",
},
]
a_foreground = {
"format": 5, # PaintGlyph
"format": 6, # PaintGlyph
"paint": solid_paint,
"glyph": "a_fore",
}
b_background = {
"format": 5, # PaintGlyph
"format": 6, # PaintGlyph
"paint": solid_paint,
"glyph": "b_back",
}
b_foreground = {
"format": 5, # PaintGlyph
"format": 6, # PaintGlyph
"paint": solid_paint,
"glyph": "b_fore",
}
c_background = {
"format": 5, # PaintGlyph
"format": 6, # PaintGlyph
"paint": solid_paint,
"glyph": "c_back",
}
@ -951,7 +951,7 @@ def test_build_layerv1list_with_sharing():
def test_build_layerv1list_with_overlaps():
paints = [
{
"format": 5, # PaintGlyph
"format": 6, # PaintGlyph
"paint": {"format": 2, "paletteIndex": 2, "alpha": 0.8},
"glyph": c,
}

View File

@ -131,11 +131,11 @@ COLR_V1_SAMPLE = (
(b"\x01", "BaseGlyphV1Record[0].Paint.Format (1)"),
(b"\x04", "BaseGlyphV1Record[0].Paint.NumLayers (4)"),
(b"\x00\x00\x00\x00", "BaseGlyphV1Record[0].Paint.FirstLayerIndex (0)"),
(b"\x0B", "BaseGlyphV1Record[1].Paint.Format (11)"),
(b"\x0C", "BaseGlyphV1Record[1].Paint.Format (12)"),
(b"\x00\x00<", "Offset to SourcePaint from beginning of PaintComposite (60)"),
(b"\x03", "BaseGlyphV1Record[1].Paint.CompositeMode [SRC_OVER] (3)"),
(b"\x00\x00\x08", "Offset to BackdropPaint from beginning of PaintComposite (8)"),
(b"\x07", "BaseGlyphV1Record[1].Paint.BackdropPaint.Format (7)"),
(b"\x08", "BaseGlyphV1Record[1].Paint.BackdropPaint.Format (8)"),
(b"\x00\x00\x34", "Offset to Paint from beginning of PaintTransform (52)"),
(b"\x00\x01\x00\x00\x00\x00\x00\x00", "Affine2x3.xx.value (1.0)"),
(b"\x00\x00\x00\x00\x00\x00\x00\x00", "Affine2x3.xy.value (0.0)"),
@ -143,7 +143,7 @@ COLR_V1_SAMPLE = (
(b"\x00\x01\x00\x00\x00\x00\x00\x00", "Affine2x3.yy.value (1.0)"),
(b"\x01\x2c\x00\x00\x00\x00\x00\x00", "Affine2x3.dx.value (300.0)"),
(b"\x00\x00\x00\x00\x00\x00\x00\x00", "Affine2x3.dy.value (0.0)"),
(b"\x06", "BaseGlyphV1Record[1].Paint.SourcePaint.Format (6)"),
(b"\x07", "BaseGlyphV1Record[1].Paint.SourcePaint.Format (7)"),
(b"\x00\n", "BaseGlyphV1Record[1].Paint.SourcePaint.Glyph (10)"),
(b"\x00\x00\x00\x04", "LayerV1List.LayerCount (4)"),
(
@ -163,11 +163,11 @@ COLR_V1_SAMPLE = (
"Fourth Offset to Paint table from beginning of LayerV1List (246)",
),
# PaintGlyph glyph00011
(b"\x05", "LayerV1List.Paint[0].Format (5)"),
(b"\x06", "LayerV1List.Paint[0].Format (6)"),
(b"\x00\x01<", "Offset24 to Paint subtable from beginning of PaintGlyph (316)"),
(b"\x00\x0b", "LayerV1List.Paint[0].Glyph (glyph00011)"),
# PaintGlyph glyph00012
(b"\x05", "LayerV1List.Paint[1].Format (5)"),
(b"\x06", "LayerV1List.Paint[1].Format (6)"),
(b"\x00\x00\x06", "Offset to Paint subtable from beginning of PaintGlyph (6)"),
(b"\x00\x0c", "LayerV1List.Paint[1].Glyph (glyph00012)"),
(b"\x03", "LayerV1List.Paint[1].Paint.Format (3)"),
@ -202,10 +202,10 @@ COLR_V1_SAMPLE = (
(b"@\x00", "ColorLine.ColorStop[2].Color.Alpha.value (1.0)"),
(b"\x00\x00\x00\x00", "ColorLine.ColorStop[2].Color.Alpha.varIdx (0)"),
# PaintGlyph glyph00013
(b"\x05", "LayerV1List.Paint[2].Format (5)"),
(b"\x06", "LayerV1List.Paint[2].Format (6)"),
(b"\x00\x00\x06", "Offset to Paint subtable from beginning of PaintGlyph (6)"),
(b"\x00\r", "LayerV1List.Paint[2].Glyph (13)"),
(b"\x07", "LayerV1List.Paint[2].Paint.Format (5)"),
(b"\x08", "LayerV1List.Paint[2].Paint.Format (8)"),
(b"\x00\x00\x34", "Offset to Paint subtable from beginning of PaintTransform (52)"),
(b"\xff\xf3\x00\x00\x00\x00\x00\x00", "Affine2x3.xx.value (-13)"),
(b"\x00\x0e\x00\x00\x00\x00\x00\x00", "Affine2x3.xy.value (14)"),
@ -230,25 +230,25 @@ COLR_V1_SAMPLE = (
(b"\x00\x07", "ColorLine.ColorStop[1].Color.PaletteIndex (7)"),
(b"\x19\x9a\x00\x00\x00\x00", "ColorLine.ColorStop[1].Color.Alpha.value (0.4)"),
# PaintTranslate
(b"\x08", "LayerV1List.Paint[3].Format (8)"),
(b"\x09", "LayerV1List.Paint[3].Format (9)"),
(b"\x00\x00\x14", "Offset to Paint subtable from beginning of PaintTranslate (20)"),
(b"\x01\x01\x00\x00\x00\x00\x00\x00", "dx.value (257)"),
(b"\x01\x02\x00\x00\x00\x00\x00\x00", "dy.value (258)"),
# PaintRotate
(b"\x09", "LayerV1List.Paint[3].Paint.Format (9)"),
(b"\x0a", "LayerV1List.Paint[3].Paint.Format (10)"),
(b"\x00\x00\x1c", "Offset to Paint subtable from beginning of PaintRotate (28)"),
(b"\x00\x2d\x00\x00\x00\x00\x00\x00", "angle.value (45)"),
(b"\x00\xff\x00\x00\x00\x00\x00\x00", "centerX.value (255)"),
(b"\x01\x00\x00\x00\x00\x00\x00\x00", "centerY.value (256)"),
# PaintSkew
(b"\x0a", "LayerV1List.Paint[3].Paint.Paint.Format (10)"),
(b"\x0b", "LayerV1List.Paint[3].Paint.Paint.Format (11)"),
(b"\x00\x00\x24", "Offset to Paint subtable from beginning of PaintSkew (36)"),
(b"\xff\xf5\x00\x00\x00\x00\x00\x00", "xSkewAngle (-11)"),
(b"\x00\x05\x00\x00\x00\x00\x00\x00", "ySkewAngle (5)"),
(b"\x00\xfd\x00\x00\x00\x00\x00\x00", "centerX.value (253)"),
(b"\x00\xfe\x00\x00\x00\x00\x00\x00", "centerY.value (254)"),
# PaintGlyph
(b"\x05", "LayerV1List.Paint[2].Format (5)"),
(b"\x06", "LayerV1List.Paint[2].Format (6)"),
(b"\x00\x00\x06", "Offset to Paint subtable from beginning of PaintGlyph (6)"),
(b"\x00\x0b", "LayerV1List.Paint[2].Glyph (11)"),
# PaintSolid
@ -296,13 +296,13 @@ COLR_V1_XML = [
" </BaseGlyphV1Record>",
' <BaseGlyphV1Record index="1">',
' <BaseGlyph value="glyph00014"/>',
' <Paint Format="11"><!-- PaintComposite -->',
' <SourcePaint Format="6"><!-- PaintColrGlyph -->',
' <Paint Format="12"><!-- PaintComposite -->',
' <SourcePaint Format="7"><!-- PaintColrGlyph -->',
' <Glyph value="glyph00010"/>',
" </SourcePaint>",
' <CompositeMode value="src_over"/>',
' <BackdropPaint Format="7"><!-- PaintTransform -->',
' <Paint Format="6"><!-- PaintColrGlyph -->',
' <BackdropPaint Format="8"><!-- PaintTransform -->',
' <Paint Format="7"><!-- PaintColrGlyph -->',
' <Glyph value="glyph00010"/>',
" </Paint>",
" <Transform>",
@ -319,7 +319,7 @@ COLR_V1_XML = [
"</BaseGlyphV1List>",
"<LayerV1List>",
" <!-- LayerCount=4 -->",
' <Paint index="0" Format="5"><!-- PaintGlyph -->',
' <Paint index="0" Format="6"><!-- PaintGlyph -->',
' <Paint Format="2"><!-- PaintSolid -->',
" <Color>",
' <PaletteIndex value="2"/>',
@ -328,7 +328,7 @@ COLR_V1_XML = [
" </Paint>",
' <Glyph value="glyph00011"/>',
" </Paint>",
' <Paint index="1" Format="5"><!-- PaintGlyph -->',
' <Paint index="1" Format="6"><!-- PaintGlyph -->',
' <Paint Format="3"><!-- PaintLinearGradient -->',
" <ColorLine>",
' <Extend value="repeat"/>',
@ -364,8 +364,8 @@ COLR_V1_XML = [
" </Paint>",
' <Glyph value="glyph00012"/>',
" </Paint>",
' <Paint index="2" Format="5"><!-- PaintGlyph -->',
' <Paint Format="7"><!-- PaintTransform -->',
' <Paint index="2" Format="6"><!-- PaintGlyph -->',
' <Paint Format="8"><!-- PaintTransform -->',
' <Paint Format="4"><!-- PaintRadialGradient -->',
" <ColorLine>",
' <Extend value="pad"/>',
@ -403,10 +403,10 @@ COLR_V1_XML = [
" </Paint>",
' <Glyph value="glyph00013"/>',
" </Paint>",
' <Paint index="3" Format="8"><!-- PaintTranslate -->',
' <Paint Format="9"><!-- PaintRotate -->',
' <Paint Format="10"><!-- PaintSkew -->',
' <Paint Format="5"><!-- PaintGlyph -->',
' <Paint index="3" Format="9"><!-- PaintTranslate -->',
' <Paint Format="10"><!-- PaintRotate -->',
' <Paint Format="11"><!-- PaintSkew -->',
' <Paint Format="6"><!-- PaintGlyph -->',
' <Paint Format="2"><!-- PaintSolid -->',
" <Color>",
' <PaletteIndex value="2"/>',