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 = {
|
2021-02-10 18:44:28 +00:00
|
|
|
"glyph00010": {
|
|
|
|
"Format": int(ot.PaintFormat.PaintColrLayers),
|
|
|
|
"Layers": [
|
2021-02-04 21:57:20 -08:00
|
|
|
{
|
|
|
|
"Format": int(ot.PaintFormat.PaintGlyph),
|
|
|
|
"Paint": {
|
|
|
|
"Format": int(ot.PaintFormat.PaintSolid),
|
2021-07-22 11:53:53 +01:00
|
|
|
"PaletteIndex": 2,
|
|
|
|
"Alpha": 0.5,
|
2021-02-03 16:47:59 +00:00
|
|
|
},
|
2021-02-10 18:44:28 +00:00
|
|
|
"Glyph": "glyph00011",
|
2021-02-03 16:47:59 +00:00
|
|
|
},
|
2021-02-04 21:57:20 -08:00
|
|
|
{
|
|
|
|
"Format": int(ot.PaintFormat.PaintGlyph),
|
|
|
|
"Paint": {
|
2021-02-10 22:33:48 -08:00
|
|
|
"Format": int(ot.PaintFormat.PaintVarLinearGradient),
|
2021-02-04 21:57:20 -08:00
|
|
|
"ColorLine": {
|
2021-02-10 18:44:28 +00:00
|
|
|
"Extend": "repeat",
|
2021-02-04 21:57:20 -08:00
|
|
|
"ColorStop": [
|
|
|
|
{
|
2021-07-22 11:53:53 +01:00
|
|
|
"StopOffset": 0.0,
|
|
|
|
"PaletteIndex": 3,
|
|
|
|
"Alpha": 1.0,
|
|
|
|
"VarIndexBase": 0,
|
2021-02-04 21:57:20 -08:00
|
|
|
},
|
|
|
|
{
|
2021-07-22 11:53:53 +01:00
|
|
|
"StopOffset": 0.5,
|
|
|
|
"PaletteIndex": 4,
|
|
|
|
"Alpha": 1.0,
|
|
|
|
"VarIndexBase": 1,
|
2021-02-04 21:57:20 -08:00
|
|
|
},
|
2021-02-03 16:47:59 +00:00
|
|
|
{
|
2021-07-22 11:53:53 +01:00
|
|
|
"StopOffset": 1.0,
|
|
|
|
"PaletteIndex": 5,
|
|
|
|
"Alpha": 1.0,
|
|
|
|
"VarIndexBase": 2,
|
2021-02-03 16:47:59 +00:00
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
2021-07-22 11:53:53 +01:00
|
|
|
"x0": 1,
|
|
|
|
"y0": 2,
|
|
|
|
"x1": -3,
|
|
|
|
"y1": -4,
|
|
|
|
"x2": 5,
|
|
|
|
"y2": 6,
|
|
|
|
"VarIndexBase": 0xFFFFFFFF,
|
2021-02-03 16:47:59 +00:00
|
|
|
},
|
2021-02-10 18:44:28 +00:00
|
|
|
"Glyph": "glyph00012",
|
2021-02-03 16:47:59 +00:00
|
|
|
},
|
2021-02-04 21:57:20 -08:00
|
|
|
{
|
|
|
|
"Format": int(ot.PaintFormat.PaintGlyph),
|
|
|
|
"Paint": {
|
2021-02-10 22:33:48 -08:00
|
|
|
"Format": int(ot.PaintFormat.PaintVarTransform),
|
2021-02-04 21:57:20 -08:00
|
|
|
"Paint": {
|
|
|
|
"Format": int(ot.PaintFormat.PaintRadialGradient),
|
|
|
|
"ColorLine": {
|
2021-02-10 18:44:28 +00:00
|
|
|
"Extend": "pad",
|
2021-02-04 21:57:20 -08:00
|
|
|
"ColorStop": [
|
|
|
|
{
|
2021-02-10 22:33:48 -08:00
|
|
|
"StopOffset": 0,
|
2021-07-22 11:53:53 +01:00
|
|
|
"PaletteIndex": 6,
|
|
|
|
"Alpha": 1.0,
|
2021-02-04 21:57:20 -08:00
|
|
|
},
|
|
|
|
{
|
2021-02-10 22:33:48 -08:00
|
|
|
"StopOffset": 1.0,
|
2021-07-22 11:53:53 +01:00
|
|
|
"PaletteIndex": 7,
|
|
|
|
"Alpha": 0.4,
|
2021-02-04 21:57:20 -08:00
|
|
|
},
|
|
|
|
],
|
2021-02-03 16:47:59 +00:00
|
|
|
},
|
2021-02-10 22:33:48 -08:00
|
|
|
"x0": 7,
|
|
|
|
"y0": 8,
|
|
|
|
"r0": 9,
|
|
|
|
"x1": 10,
|
|
|
|
"y1": 11,
|
|
|
|
"r1": 12,
|
2021-02-10 18:44:28 +00:00
|
|
|
},
|
|
|
|
"Transform": {
|
2021-07-22 11:53:53 +01:00
|
|
|
"xx": -13.0,
|
|
|
|
"yx": 14.0,
|
|
|
|
"xy": 15.0,
|
|
|
|
"yy": -17.0,
|
|
|
|
"dx": 18.0,
|
|
|
|
"dy": 19.0,
|
|
|
|
"VarIndexBase": 3,
|
2021-02-03 16:47:59 +00:00
|
|
|
},
|
|
|
|
},
|
2021-02-10 18:44:28 +00:00
|
|
|
"Glyph": "glyph00013",
|
2021-02-03 16:47:59 +00:00
|
|
|
},
|
2021-02-04 21:57:20 -08:00
|
|
|
{
|
2021-02-10 22:33:48 -08:00
|
|
|
"Format": int(ot.PaintFormat.PaintVarTranslate),
|
2021-02-04 21:57:20 -08:00
|
|
|
"Paint": {
|
|
|
|
"Format": int(ot.PaintFormat.PaintRotate),
|
|
|
|
"Paint": {
|
2021-02-10 22:33:48 -08:00
|
|
|
"Format": int(ot.PaintFormat.PaintVarSkew),
|
2021-02-04 21:57:20 -08:00
|
|
|
"Paint": {
|
|
|
|
"Format": int(ot.PaintFormat.PaintGlyph),
|
|
|
|
"Paint": {
|
|
|
|
"Format": int(ot.PaintFormat.PaintSolid),
|
2021-07-22 11:53:53 +01:00
|
|
|
"PaletteIndex": 2,
|
|
|
|
"Alpha": 0.5,
|
2021-02-04 21:57:20 -08:00
|
|
|
},
|
2021-02-10 18:44:28 +00:00
|
|
|
"Glyph": "glyph00011",
|
2021-02-04 21:57:20 -08:00
|
|
|
},
|
2021-07-22 11:53:53 +01:00
|
|
|
"xSkewAngle": -11.0,
|
|
|
|
"ySkewAngle": 5.0,
|
|
|
|
"VarIndexBase": 4,
|
2021-02-04 21:57:20 -08:00
|
|
|
},
|
2021-02-10 22:33:48 -08:00
|
|
|
"angle": 45.0,
|
2021-02-04 21:57:20 -08:00
|
|
|
},
|
2021-07-22 11:53:53 +01:00
|
|
|
"dx": 257.0,
|
|
|
|
"dy": 258.0,
|
|
|
|
"VarIndexBase": 5,
|
2021-02-04 21:57:20 -08:00
|
|
|
},
|
|
|
|
],
|
2021-02-10 18:44:28 +00:00
|
|
|
},
|
2021-02-03 16:47:59 +00:00
|
|
|
"glyph00014": {
|
2021-02-04 21:57:20 -08:00
|
|
|
"Format": int(ot.PaintFormat.PaintComposite),
|
|
|
|
"SourcePaint": {
|
|
|
|
"Format": int(ot.PaintFormat.PaintColrGlyph),
|
|
|
|
"Glyph": "glyph00010",
|
2021-02-03 16:47:59 +00:00
|
|
|
},
|
2021-02-10 18:44:28 +00:00
|
|
|
"CompositeMode": "src_over",
|
2021-02-04 21:57:20 -08:00
|
|
|
"BackdropPaint": {
|
|
|
|
"Format": int(ot.PaintFormat.PaintTransform),
|
|
|
|
"Paint": {
|
|
|
|
"Format": int(ot.PaintFormat.PaintColrGlyph),
|
|
|
|
"Glyph": "glyph00010",
|
2021-02-03 16:47:59 +00:00
|
|
|
},
|
2021-02-10 18:44:28 +00:00
|
|
|
"Transform": {
|
2021-02-10 22:33:48 -08:00
|
|
|
"xx": 1.0,
|
|
|
|
"yx": 0.0,
|
|
|
|
"xy": 0.0,
|
|
|
|
"yy": 1.0,
|
|
|
|
"dx": 300.0,
|
|
|
|
"dy": 0.0,
|
2021-02-10 18:44:28 +00:00
|
|
|
},
|
2021-02-03 16:47:59 +00:00
|
|
|
},
|
|
|
|
},
|
2021-02-04 12:16:29 +00:00
|
|
|
"glyph00015": {
|
2021-02-04 21:57:20 -08:00
|
|
|
"Format": int(ot.PaintFormat.PaintGlyph),
|
|
|
|
"Paint": {
|
|
|
|
"Format": int(ot.PaintFormat.PaintSweepGradient),
|
|
|
|
"ColorLine": {
|
2021-02-10 18:44:28 +00:00
|
|
|
"Extend": "pad",
|
2021-02-04 21:57:20 -08:00
|
|
|
"ColorStop": [
|
2021-02-10 18:44:28 +00:00
|
|
|
{
|
2021-02-10 22:33:48 -08:00
|
|
|
"StopOffset": 0.0,
|
2021-07-22 11:53:53 +01:00
|
|
|
"PaletteIndex": 3,
|
|
|
|
"Alpha": 1.0,
|
2021-02-10 18:44:28 +00:00
|
|
|
},
|
|
|
|
{
|
2021-02-10 22:33:48 -08:00
|
|
|
"StopOffset": 1.0,
|
2021-07-22 11:53:53 +01:00
|
|
|
"PaletteIndex": 5,
|
|
|
|
"Alpha": 1.0,
|
2021-02-10 18:44:28 +00:00
|
|
|
},
|
2021-02-04 12:16:29 +00:00
|
|
|
],
|
|
|
|
},
|
2021-02-10 22:33:48 -08:00
|
|
|
"centerX": 259,
|
|
|
|
"centerY": 300,
|
|
|
|
"startAngle": 45.0,
|
|
|
|
"endAngle": 135.0,
|
2021-02-04 12:16:29 +00:00
|
|
|
},
|
2021-02-10 18:44:28 +00:00
|
|
|
"Glyph": "glyph00011",
|
2021-02-04 12:16:29 +00:00
|
|
|
},
|
2021-02-10 18:44:28 +00:00
|
|
|
"glyph00016": {
|
|
|
|
"Format": int(ot.PaintFormat.PaintColrLayers),
|
|
|
|
"Layers": [
|
2021-02-04 21:57:20 -08:00
|
|
|
{
|
|
|
|
"Format": int(ot.PaintFormat.PaintGlyph),
|
|
|
|
"Paint": {
|
2021-02-10 22:33:48 -08:00
|
|
|
"Format": int(ot.PaintFormat.PaintVarSolid),
|
2021-07-22 11:53:53 +01:00
|
|
|
"PaletteIndex": 2,
|
|
|
|
"Alpha": 0.5,
|
|
|
|
"VarIndexBase": 6,
|
2021-02-04 21:57:20 -08:00
|
|
|
},
|
2021-02-10 18:44:28 +00:00
|
|
|
"Glyph": "glyph00011",
|
2021-02-03 16:47:59 +00:00
|
|
|
},
|
2021-02-04 21:57:20 -08:00
|
|
|
{
|
|
|
|
"Format": int(ot.PaintFormat.PaintGlyph),
|
|
|
|
"Paint": {
|
2021-02-10 22:33:48 -08:00
|
|
|
"Format": int(ot.PaintFormat.PaintVarLinearGradient),
|
2021-02-04 21:57:20 -08:00
|
|
|
"ColorLine": {
|
2021-02-10 18:44:28 +00:00
|
|
|
"Extend": "repeat",
|
2021-02-04 21:57:20 -08:00
|
|
|
"ColorStop": [
|
|
|
|
{
|
2021-07-22 11:53:53 +01:00
|
|
|
"StopOffset": 0.0,
|
|
|
|
"PaletteIndex": 3,
|
|
|
|
"Alpha": 1.0,
|
|
|
|
"VarIndexBase": 7,
|
2021-02-04 21:57:20 -08:00
|
|
|
},
|
|
|
|
{
|
2021-07-22 11:53:53 +01:00
|
|
|
"StopOffset": 0.5,
|
|
|
|
"PaletteIndex": 4,
|
|
|
|
"Alpha": 1.0,
|
|
|
|
"VarIndexBase": 8,
|
2021-02-04 21:57:20 -08:00
|
|
|
},
|
|
|
|
{
|
2021-07-22 11:53:53 +01:00
|
|
|
"StopOffset": 1.0,
|
|
|
|
"PaletteIndex": 5,
|
|
|
|
"Alpha": 1.0,
|
|
|
|
"VarIndexBase": 9,
|
2021-02-04 21:57:20 -08:00
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
2021-07-22 11:53:53 +01:00
|
|
|
"x0": 1,
|
|
|
|
"y0": 2,
|
|
|
|
"x1": -3,
|
|
|
|
"y1": -4,
|
|
|
|
"x2": 5,
|
|
|
|
"y2": 6,
|
|
|
|
"VarIndexBase": 0xFFFFFFFF,
|
2021-02-03 16:47:59 +00:00
|
|
|
},
|
2021-02-10 18:44:28 +00:00
|
|
|
"Glyph": "glyph00012",
|
2021-02-03 16:47:59 +00:00
|
|
|
},
|
2021-02-04 21:57:20 -08:00
|
|
|
],
|
2022-06-13 16:50:01 +01:00
|
|
|
},
|
|
|
|
# When PaintColrLayers contains more than 255 layers, we build a tree
|
|
|
|
# of nested PaintColrLayers of max 255 items (NumLayers field is a uint8).
|
|
|
|
# Below we test that unbuildColrV1 restores a flat list of layers without
|
|
|
|
# nested PaintColrLayers.
|
|
|
|
"glyph00017": {
|
|
|
|
"Format": int(ot.PaintFormat.PaintColrLayers),
|
|
|
|
"Layers": [
|
|
|
|
{
|
|
|
|
"Format": int(ot.PaintFormat.PaintGlyph),
|
|
|
|
"Paint": {
|
|
|
|
"Format": int(ot.PaintFormat.PaintSolid),
|
|
|
|
"PaletteIndex": i,
|
|
|
|
"Alpha": 1.0,
|
|
|
|
},
|
|
|
|
"Glyph": "glyph{str(18 + i).zfill(5)}",
|
|
|
|
}
|
|
|
|
for i in range(256)
|
|
|
|
],
|
|
|
|
},
|
2021-02-03 16:47:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
def test_unbuildColrV1():
|
2021-11-02 15:59:30 -07:00
|
|
|
layers, baseGlyphs = buildColrV1(TEST_COLOR_GLYPHS)
|
|
|
|
colorGlyphs = unbuildColrV1(layers, baseGlyphs)
|
2021-02-03 16:47:59 +00:00
|
|
|
assert colorGlyphs == TEST_COLOR_GLYPHS
|
2021-11-02 15:59:30 -07:00
|
|
|
|
2022-06-13 16:50:01 +01:00
|
|
|
|
2021-11-02 15:59:30 -07:00
|
|
|
def test_unbuildColrV1_noLayers():
|
|
|
|
_, baseGlyphsV1 = buildColrV1(TEST_COLOR_GLYPHS)
|
|
|
|
# Just looking to see we don't crash
|
2022-06-13 16:50:01 +01:00
|
|
|
unbuildColrV1(None, baseGlyphsV1)
|