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