Пример #1
0
def test_buildColrV1():
    colorGlyphs = {
        "a": [("b", 0), ("c", 1)],
        "d": [
            ("e", {
                "format": 2,
                "paletteIndex": 2,
                "alpha": 0.8
            }),
            (
                "f",
                {
                    "format": 4,
                    "colorLine": {
                        "stops": [(0.0, 3), (1.0, 4)],
                        "extend": "reflect"
                    },
                    "c0": (0, 0),
                    "c1": (0, 0),
                    "r0": 10,
                    "r1": 0,
                },
            ),
        ],
        "g": [("h", 5)],
    }
    glyphMap = {
        ".notdef": 0,
        "a": 4,
        "b": 3,
        "c": 2,
        "d": 1,
        "e": 5,
        "f": 6,
        "g": 7,
        "h": 8,
    }

    # TODO(anthrotype) should we split into two tests? - seems two distinct validations
    layers, baseGlyphs = builder.buildColrV1(colorGlyphs, glyphMap)
    assert baseGlyphs.BaseGlyphCount == len(colorGlyphs)
    assert baseGlyphs.BaseGlyphV1Record[0].BaseGlyph == "d"
    assert baseGlyphs.BaseGlyphV1Record[1].BaseGlyph == "a"
    assert baseGlyphs.BaseGlyphV1Record[2].BaseGlyph == "g"

    layers, baseGlyphs = builder.buildColrV1(colorGlyphs)
    assert baseGlyphs.BaseGlyphCount == len(colorGlyphs)
    assert baseGlyphs.BaseGlyphV1Record[0].BaseGlyph == "a"
    assert baseGlyphs.BaseGlyphV1Record[1].BaseGlyph == "d"
    assert baseGlyphs.BaseGlyphV1Record[2].BaseGlyph == "g"
Пример #2
0
def test_buildColrV1_more_than_255_paints():
    num_paints = 364
    colorGlyphs = {
        "a": [
            {
                "format": 6,  # PaintGlyph
                "paint": 0,
                "glyph": name,
            } for name in (f"glyph{i}" for i in range(num_paints))
        ],
    }
    layers, baseGlyphs = builder.buildColrV1(colorGlyphs)
    paints = layers.Paint

    assert len(paints) == num_paints + 1

    assert all(paints[i].Format == ot.PaintFormat.PaintGlyph
               for i in range(255))

    assert paints[255].Format == ot.PaintFormat.PaintColrLayers
    assert paints[255].FirstLayerIndex == 0
    assert paints[255].NumLayers == 255

    assert all(paints[i].Format == ot.PaintFormat.PaintGlyph
               for i in range(256, num_paints + 1))

    assert baseGlyphs.BaseGlyphCount == len(colorGlyphs)
    assert baseGlyphs.BaseGlyphV1Record[0].BaseGlyph == "a"
    assert (baseGlyphs.BaseGlyphV1Record[0].Paint.Format ==
            ot.PaintFormat.PaintColrLayers)
    assert baseGlyphs.BaseGlyphV1Record[0].Paint.FirstLayerIndex == 255
    assert baseGlyphs.BaseGlyphV1Record[
        0].Paint.NumLayers == num_paints + 1 - 255
Пример #3
0
def test_unbuildColrV1_noLayers():
    _, baseGlyphsV1 = buildColrV1(TEST_COLOR_GLYPHS)
    # Just looking to see we don't crash
    unbuildColrV1(None, baseGlyphsV1)
Пример #4
0
def test_unbuildColrV1():
    layers, baseGlyphs = buildColrV1(TEST_COLOR_GLYPHS)
    colorGlyphs = unbuildColrV1(layers, baseGlyphs)
    assert colorGlyphs == TEST_COLOR_GLYPHS
Пример #5
0
def test_unbuildColrV1():
    layersV1, baseGlyphsV1 = buildColrV1(TEST_COLOR_GLYPHS)
    colorGlyphs = unbuildColrV1(layersV1, baseGlyphsV1, ignoreVarIdx=True)
    assert colorGlyphs == TEST_COLOR_GLYPHS