2021-02-03 16:47:59 +00:00
|
|
|
from fontTools.ttLib.tables import otTables as ot
|
|
|
|
from fontTools.colorLib.builder import buildColrV1
|
|
|
|
from fontTools.colorLib.unbuilder import unbuildColrV1
|
|
|
|
import pytest
|
|
|
|
|
|
|
|
|
|
|
|
TEST_COLOR_GLYPHS = {
|
|
|
|
"glyph00010": [
|
|
|
|
{
|
2021-02-05 12:11:43 +00:00
|
|
|
"format": int(ot.PaintFormat.PaintGlyph),
|
2021-02-03 16:47:59 +00:00
|
|
|
"glyph": "glyph00011",
|
|
|
|
"paint": {
|
2021-02-05 12:11:43 +00:00
|
|
|
"format": int(ot.PaintFormat.PaintSolid),
|
2021-02-03 16:47:59 +00:00
|
|
|
"paletteIndex": 2,
|
|
|
|
"alpha": 0.5,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2021-02-05 12:11:43 +00:00
|
|
|
"format": int(ot.PaintFormat.PaintGlyph),
|
2021-02-03 16:47:59 +00:00
|
|
|
"glyph": "glyph00012",
|
|
|
|
"paint": {
|
2021-02-05 12:11:43 +00:00
|
|
|
"format": int(ot.PaintFormat.PaintLinearGradient),
|
2021-02-03 16:47:59 +00:00
|
|
|
"colorLine": {
|
|
|
|
"stops": [
|
|
|
|
{"offset": 0.0, "paletteIndex": 3, "alpha": 1.0},
|
|
|
|
{"offset": 0.5, "paletteIndex": 4, "alpha": 1.0},
|
|
|
|
{"offset": 1.0, "paletteIndex": 5, "alpha": 1.0},
|
|
|
|
],
|
|
|
|
"extend": "repeat",
|
|
|
|
},
|
|
|
|
"p0": (1, 2),
|
|
|
|
"p1": (-3, -4),
|
|
|
|
"p2": (5, 6),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2021-02-05 12:11:43 +00:00
|
|
|
"format": int(ot.PaintFormat.PaintGlyph),
|
2021-02-03 16:47:59 +00:00
|
|
|
"glyph": "glyph00013",
|
|
|
|
"paint": {
|
2021-02-05 12:11:43 +00:00
|
|
|
"format": int(ot.PaintFormat.PaintTransform),
|
2021-02-03 16:47:59 +00:00
|
|
|
"transform": (-13.0, 14.0, 15.0, -17.0, 18.0, 19.0),
|
|
|
|
"paint": {
|
2021-02-05 12:11:43 +00:00
|
|
|
"format": int(ot.PaintFormat.PaintRadialGradient),
|
2021-02-03 16:47:59 +00:00
|
|
|
"colorLine": {
|
|
|
|
"stops": [
|
|
|
|
{"offset": 0.0, "paletteIndex": 6, "alpha": 1.0},
|
|
|
|
{
|
|
|
|
"offset": 1.0,
|
|
|
|
"paletteIndex": 7,
|
|
|
|
"alpha": 0.4,
|
|
|
|
},
|
|
|
|
],
|
|
|
|
"extend": "pad",
|
|
|
|
},
|
|
|
|
"c0": (7, 8),
|
|
|
|
"r0": 9,
|
|
|
|
"c1": (10, 11),
|
|
|
|
"r1": 12,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2021-02-05 12:11:43 +00:00
|
|
|
"format": int(ot.PaintFormat.PaintTranslate),
|
2021-02-03 16:47:59 +00:00
|
|
|
"dx": 257.0,
|
|
|
|
"dy": 258.0,
|
|
|
|
"paint": {
|
2021-02-05 12:11:43 +00:00
|
|
|
"format": int(ot.PaintFormat.PaintRotate),
|
2021-02-03 16:47:59 +00:00
|
|
|
"angle": 45.0,
|
|
|
|
"centerX": 255.0,
|
|
|
|
"centerY": 256.0,
|
|
|
|
"paint": {
|
2021-02-05 12:11:43 +00:00
|
|
|
"format": int(ot.PaintFormat.PaintSkew),
|
2021-02-03 16:47:59 +00:00
|
|
|
"xSkewAngle": -11.0,
|
|
|
|
"ySkewAngle": 5.0,
|
|
|
|
"centerX": 253.0,
|
|
|
|
"centerY": 254.0,
|
|
|
|
"paint": {
|
2021-02-05 12:11:43 +00:00
|
|
|
"format": int(ot.PaintFormat.PaintGlyph),
|
2021-02-03 16:47:59 +00:00
|
|
|
"glyph": "glyph00011",
|
|
|
|
"paint": {
|
2021-02-05 12:11:43 +00:00
|
|
|
"format": int(ot.PaintFormat.PaintSolid),
|
2021-02-03 16:47:59 +00:00
|
|
|
"paletteIndex": 2,
|
|
|
|
"alpha": 0.5,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
],
|
|
|
|
"glyph00014": {
|
2021-02-05 12:11:43 +00:00
|
|
|
"format": int(ot.PaintFormat.PaintComposite),
|
2021-02-03 16:47:59 +00:00
|
|
|
"mode": "src_over",
|
|
|
|
"source": {
|
2021-02-05 12:11:43 +00:00
|
|
|
"format": int(ot.PaintFormat.PaintColrGlyph),
|
2021-02-03 16:47:59 +00:00
|
|
|
"glyph": "glyph00010",
|
|
|
|
},
|
|
|
|
"backdrop": {
|
2021-02-05 12:11:43 +00:00
|
|
|
"format": int(ot.PaintFormat.PaintTransform),
|
2021-02-03 16:47:59 +00:00
|
|
|
"transform": (1.0, 0.0, 0.0, 1.0, 300.0, 0.0),
|
|
|
|
"paint": {
|
2021-02-05 12:11:43 +00:00
|
|
|
"format": int(ot.PaintFormat.PaintColrGlyph),
|
2021-02-03 16:47:59 +00:00
|
|
|
"glyph": "glyph00010",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2021-02-04 12:16:29 +00:00
|
|
|
"glyph00015": {
|
2021-02-05 12:11:43 +00:00
|
|
|
"format": int(ot.PaintFormat.PaintGlyph),
|
2021-02-04 12:16:29 +00:00
|
|
|
"glyph": "glyph00011",
|
|
|
|
"paint": {
|
2021-02-05 12:11:43 +00:00
|
|
|
"format": int(ot.PaintFormat.PaintSweepGradient),
|
2021-02-04 12:16:29 +00:00
|
|
|
"colorLine": {
|
|
|
|
"stops": [
|
|
|
|
{"offset": 0.0, "paletteIndex": 3, "alpha": 1.0},
|
|
|
|
{"offset": 1.0, "paletteIndex": 5, "alpha": 1.0},
|
|
|
|
],
|
|
|
|
"extend": "pad",
|
|
|
|
},
|
|
|
|
"centerX": 259,
|
|
|
|
"centerY": 300,
|
|
|
|
"startAngle": 45.0,
|
|
|
|
"endAngle": 135.0,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
"glyph00016": [
|
2021-02-03 16:47:59 +00:00
|
|
|
{
|
2021-02-05 12:11:43 +00:00
|
|
|
"format": int(ot.PaintFormat.PaintGlyph),
|
2021-02-03 16:47:59 +00:00
|
|
|
"glyph": "glyph00011",
|
|
|
|
"paint": {
|
2021-02-05 12:11:43 +00:00
|
|
|
"format": int(ot.PaintFormat.PaintSolid),
|
2021-02-03 16:47:59 +00:00
|
|
|
"paletteIndex": 2,
|
|
|
|
"alpha": 0.5,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2021-02-05 12:11:43 +00:00
|
|
|
"format": int(ot.PaintFormat.PaintGlyph),
|
2021-02-03 16:47:59 +00:00
|
|
|
"glyph": "glyph00012",
|
|
|
|
"paint": {
|
2021-02-05 12:11:43 +00:00
|
|
|
"format": int(ot.PaintFormat.PaintLinearGradient),
|
2021-02-03 16:47:59 +00:00
|
|
|
"colorLine": {
|
|
|
|
"stops": [
|
|
|
|
{"offset": 0.0, "paletteIndex": 3, "alpha": 1.0},
|
|
|
|
{"offset": 0.5, "paletteIndex": 4, "alpha": 1.0},
|
|
|
|
{"offset": 1.0, "paletteIndex": 5, "alpha": 1.0},
|
|
|
|
],
|
|
|
|
"extend": "repeat",
|
|
|
|
},
|
|
|
|
"p0": (1, 2),
|
|
|
|
"p1": (-3, -4),
|
|
|
|
"p2": (5, 6),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
],
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
def test_unbuildColrV1():
|
|
|
|
layersV1, baseGlyphsV1 = buildColrV1(TEST_COLOR_GLYPHS)
|
|
|
|
colorGlyphs = unbuildColrV1(layersV1, baseGlyphsV1, ignoreVarIdx=True)
|
|
|
|
assert colorGlyphs == TEST_COLOR_GLYPHS
|