|
| 1 | +package tables |
| 2 | + |
| 3 | +import ( |
| 4 | + "testing" |
| 5 | + |
| 6 | + tu "github.com/go-text/typesetting/testutils" |
| 7 | +) |
| 8 | + |
| 9 | +func TestCOLR(t *testing.T) { |
| 10 | + ft := readFontFile(t, "color/NotoColorEmoji-Regular.ttf") |
| 11 | + colr, err := ParseCOLR(readTable(t, ft, "COLR")) |
| 12 | + tu.AssertNoErr(t, err) |
| 13 | + tu.Assert(t, len(colr.baseGlyphRecords) == 0) |
| 14 | + tu.Assert(t, len(colr.layerRecords) == 0) |
| 15 | + tu.Assert(t, len(colr.baseGlyphList.paintRecords) == 3845) |
| 16 | + tu.Assert(t, colr.baseGlyphList.paintRecords[0].Paint == PaintColrLayers{1, 3, 47625}) |
| 17 | + tu.Assert(t, colr.ClipList.clips[0].ClipBox == ClipBoxFormat1{1, 480, 192, 800, 512}) |
| 18 | + tu.Assert(t, colr.VarIndexMap == nil && colr.ItemVariationStore == nil) |
| 19 | + tu.Assert(t, len(colr.LayerList.paintTables) == 69264) |
| 20 | + |
| 21 | + clipBox, ok := colr.ClipList.Search(87) |
| 22 | + tu.Assert(t, ok && clipBox == ClipBoxFormat1{1, 64, -224, 1216, 928}) |
| 23 | + |
| 24 | + // reference from fonttools |
| 25 | + paint := colr.LayerList.paintTables[6] |
| 26 | + transform, ok := paint.(PaintTransform) |
| 27 | + tu.Assert(t, ok) |
| 28 | + _, innerOK := transform.Paint.(PaintGlyph) |
| 29 | + tu.Assert(t, transform.Transform == Affine2x3{1, 0, 0, 1, 4.3119965, 0.375}) |
| 30 | + tu.Assert(t, innerOK) |
| 31 | + |
| 32 | + _, ok = colr.Search(1) |
| 33 | + tu.Assert(t, !ok) |
| 34 | + _, ok = colr.Search(0xFFFF) |
| 35 | + tu.Assert(t, !ok) |
| 36 | + |
| 37 | + pt, ok := colr.Search(12) |
| 38 | + asColrLayers, ok2 := pt.(PaintColrLayers) |
| 39 | + tu.Assert(t, ok && ok2) |
| 40 | + tu.Assert(t, asColrLayers == PaintColrLayers{1, 9, 2427}) |
| 41 | + |
| 42 | + for _, paint := range colr.baseGlyphList.paintRecords { |
| 43 | + if layers, ok := paint.Paint.(PaintColrLayers); ok { |
| 44 | + l, err := colr.LayerList.Resolve(layers) |
| 45 | + tu.AssertNoErr(t, err) |
| 46 | + tu.Assert(t, len(l) == int(layers.NumLayers)) |
| 47 | + } |
| 48 | + } |
| 49 | + |
| 50 | + ft = readFontFile(t, "color/CoralPixels-Regular.ttf") |
| 51 | + colr, err = ParseCOLR(readTable(t, ft, "COLR")) |
| 52 | + tu.AssertNoErr(t, err) |
| 53 | + tu.Assert(t, len(colr.baseGlyphRecords) == 335) |
| 54 | + tu.Assert(t, len(colr.layerRecords) == 5603) |
| 55 | + g1, g2 := colr.baseGlyphRecords[0], colr.baseGlyphRecords[1] |
| 56 | + tu.Assert(t, g1 == baseGlyph{0, 0, 11} && g2 == baseGlyph{2, 11, 18}) |
| 57 | + tu.Assert(t, colr.layerRecords[0].PaletteIndex == 4) |
| 58 | + |
| 59 | + _, ok = colr.Search(1) |
| 60 | + tu.Assert(t, !ok) |
| 61 | + _, ok = colr.Search(0xFFFF) |
| 62 | + tu.Assert(t, !ok) |
| 63 | + |
| 64 | + pt, ok = colr.Search(0) |
| 65 | + asLayers, ok2 := pt.(PaintColrLayersResolved) |
| 66 | + tu.Assert(t, ok && ok2) |
| 67 | + tu.Assert(t, len(asLayers) == 11) |
| 68 | + tu.Assert(t, asLayers[0].PaletteIndex == 4) |
| 69 | + tu.Assert(t, asLayers[10].PaletteIndex == 11) |
| 70 | +} |
| 71 | + |
| 72 | +func TestCPAL(t *testing.T) { |
| 73 | + ft := readFontFile(t, "color/NotoColorEmoji-Regular.ttf") |
| 74 | + cpal, _, err := ParseCPAL(readTable(t, ft, "CPAL")) |
| 75 | + tu.AssertNoErr(t, err) |
| 76 | + tu.Assert(t, cpal.Version == 0) |
| 77 | + tu.Assert(t, cpal.NumPaletteEntries == 5921) |
| 78 | + tu.Assert(t, cpal.numPalettes == 1 && len(cpal.ColorRecordIndices) == 1) |
| 79 | + |
| 80 | + ft = readFontFile(t, "color/CoralPixels-Regular.ttf") |
| 81 | + cpal, _, err = ParseCPAL(readTable(t, ft, "CPAL")) |
| 82 | + tu.AssertNoErr(t, err) |
| 83 | + tu.Assert(t, cpal.Version == 0) |
| 84 | + tu.Assert(t, cpal.NumPaletteEntries == 32) |
| 85 | + tu.Assert(t, cpal.numPalettes == 2 && len(cpal.ColorRecordIndices) == 2) |
| 86 | +} |
0 commit comments