aboutsummaryrefslogtreecommitdiff
path: root/Tests/colorLib/unbuilder_test.py
blob: 3548968056c0423340931eb8a09ab300657b36e8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
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": {
        "Format": int(ot.PaintFormat.PaintColrLayers),
        "Layers": [
            {
                "Format": int(ot.PaintFormat.PaintGlyph),
                "Paint": {
                    "Format": int(ot.PaintFormat.PaintSolid),
                    "PaletteIndex": 2,
                    "Alpha": 0.5,
                },
                "Glyph": "glyph00011",
            },
            {
                "Format": int(ot.PaintFormat.PaintGlyph),
                "Paint": {
                    "Format": int(ot.PaintFormat.PaintVarLinearGradient),
                    "ColorLine": {
                        "Extend": "repeat",
                        "ColorStop": [
                            {
                                "StopOffset": 0.0,
                                "PaletteIndex": 3,
                                "Alpha": 1.0,
                                "VarIndexBase": 0,
                            },
                            {
                                "StopOffset": 0.5,
                                "PaletteIndex": 4,
                                "Alpha": 1.0,
                                "VarIndexBase": 1,
                            },
                            {
                                "StopOffset": 1.0,
                                "PaletteIndex": 5,
                                "Alpha": 1.0,
                                "VarIndexBase": 2,
                            },
                        ],
                    },
                    "x0": 1,
                    "y0": 2,
                    "x1": -3,
                    "y1": -4,
                    "x2": 5,
                    "y2": 6,
                    "VarIndexBase": 0xFFFFFFFF,
                },
                "Glyph": "glyph00012",
            },
            {
                "Format": int(ot.PaintFormat.PaintGlyph),
                "Paint": {
                    "Format": int(ot.PaintFormat.PaintVarTransform),
                    "Paint": {
                        "Format": int(ot.PaintFormat.PaintRadialGradient),
                        "ColorLine": {
                            "Extend": "pad",
                            "ColorStop": [
                                {
                                    "StopOffset": 0,
                                    "PaletteIndex": 6,
                                    "Alpha": 1.0,
                                },
                                {
                                    "StopOffset": 1.0,
                                    "PaletteIndex": 7,
                                    "Alpha": 0.4,
                                },
                            ],
                        },
                        "x0": 7,
                        "y0": 8,
                        "r0": 9,
                        "x1": 10,
                        "y1": 11,
                        "r1": 12,
                    },
                    "Transform": {
                        "xx": -13.0,
                        "yx": 14.0,
                        "xy": 15.0,
                        "yy": -17.0,
                        "dx": 18.0,
                        "dy": 19.0,
                        "VarIndexBase": 3,
                    },
                },
                "Glyph": "glyph00013",
            },
            {
                "Format": int(ot.PaintFormat.PaintVarTranslate),
                "Paint": {
                    "Format": int(ot.PaintFormat.PaintRotate),
                    "Paint": {
                        "Format": int(ot.PaintFormat.PaintVarSkew),
                        "Paint": {
                            "Format": int(ot.PaintFormat.PaintGlyph),
                            "Paint": {
                                "Format": int(ot.PaintFormat.PaintSolid),
                                "PaletteIndex": 2,
                                "Alpha": 0.5,
                            },
                            "Glyph": "glyph00011",
                        },
                        "xSkewAngle": -11.0,
                        "ySkewAngle": 5.0,
                        "VarIndexBase": 4,
                    },
                    "angle": 45.0,
                },
                "dx": 257.0,
                "dy": 258.0,
                "VarIndexBase": 5,
            },
        ],
    },
    "glyph00014": {
        "Format": int(ot.PaintFormat.PaintComposite),
        "SourcePaint": {
            "Format": int(ot.PaintFormat.PaintColrGlyph),
            "Glyph": "glyph00010",
        },
        "CompositeMode": "src_over",
        "BackdropPaint": {
            "Format": int(ot.PaintFormat.PaintTransform),
            "Paint": {
                "Format": int(ot.PaintFormat.PaintColrGlyph),
                "Glyph": "glyph00010",
            },
            "Transform": {
                "xx": 1.0,
                "yx": 0.0,
                "xy": 0.0,
                "yy": 1.0,
                "dx": 300.0,
                "dy": 0.0,
            },
        },
    },
    "glyph00015": {
        "Format": int(ot.PaintFormat.PaintGlyph),
        "Paint": {
            "Format": int(ot.PaintFormat.PaintSweepGradient),
            "ColorLine": {
                "Extend": "pad",
                "ColorStop": [
                    {
                        "StopOffset": 0.0,
                        "PaletteIndex": 3,
                        "Alpha": 1.0,
                    },
                    {
                        "StopOffset": 1.0,
                        "PaletteIndex": 5,
                        "Alpha": 1.0,
                    },
                ],
            },
            "centerX": 259,
            "centerY": 300,
            "startAngle": 45.0,
            "endAngle": 135.0,
        },
        "Glyph": "glyph00011",
    },
    "glyph00016": {
        "Format": int(ot.PaintFormat.PaintColrLayers),
        "Layers": [
            {
                "Format": int(ot.PaintFormat.PaintGlyph),
                "Paint": {
                    "Format": int(ot.PaintFormat.PaintVarSolid),
                    "PaletteIndex": 2,
                    "Alpha": 0.5,
                    "VarIndexBase": 6,
                },
                "Glyph": "glyph00011",
            },
            {
                "Format": int(ot.PaintFormat.PaintGlyph),
                "Paint": {
                    "Format": int(ot.PaintFormat.PaintVarLinearGradient),
                    "ColorLine": {
                        "Extend": "repeat",
                        "ColorStop": [
                            {
                                "StopOffset": 0.0,
                                "PaletteIndex": 3,
                                "Alpha": 1.0,
                                "VarIndexBase": 7,
                            },
                            {
                                "StopOffset": 0.5,
                                "PaletteIndex": 4,
                                "Alpha": 1.0,
                                "VarIndexBase": 8,
                            },
                            {
                                "StopOffset": 1.0,
                                "PaletteIndex": 5,
                                "Alpha": 1.0,
                                "VarIndexBase": 9,
                            },
                        ],
                    },
                    "x0": 1,
                    "y0": 2,
                    "x1": -3,
                    "y1": -4,
                    "x2": 5,
                    "y2": 6,
                    "VarIndexBase": 0xFFFFFFFF,
                },
                "Glyph": "glyph00012",
            },
        ],
    }
}


def test_unbuildColrV1():
    layers, baseGlyphs = buildColrV1(TEST_COLOR_GLYPHS)
    colorGlyphs = unbuildColrV1(layers, baseGlyphs)
    assert colorGlyphs == TEST_COLOR_GLYPHS

def test_unbuildColrV1_noLayers():
    _, baseGlyphsV1 = buildColrV1(TEST_COLOR_GLYPHS)
    # Just looking to see we don't crash
    unbuildColrV1(None, baseGlyphsV1)