Exemplo n.º 1
0
def test_buildLayerV1Array():
    layers = [
        ("a", 1),
        ("b", {
            "format": 1,
            "paletteIndex": 2,
            "transparency": 0.5
        }),
        (
            "c",
            {
                "format": 2,
                "colorLine": {
                    "stops": [(0.0, 3), (1.0, 4)],
                    "extend": "repeat"
                },
                "p0": (100, 200),
                "p1": (150, 250),
            },
        ),
        (
            "d",
            {
                "format": 3,
                "colorLine": {
                    "stops": [
                        {
                            "offset": 0.0,
                            "paletteIndex": 5
                        },
                        {
                            "offset": 0.5,
                            "paletteIndex": 6,
                            "transparency": 0.8
                        },
                        {
                            "offset": 1.0,
                            "paletteIndex": 7
                        },
                    ]
                },
                "c0": (50, 50),
                "c1": (75, 75),
                "r0": 30,
                "r1": 10,
            },
        ),
        builder.buildLayerV1Record("e", builder.buildSolidColorPaint(8)),
    ]
    layersArray = builder.buildLayerV1Array(layers)

    assert layersArray.LayerCount == len(layersArray.LayerV1Record)
    assert all(
        isinstance(l, ot.LayerV1Record) for l in layersArray.LayerV1Record)
Exemplo n.º 2
0
def test_buildSolidColorPaint():
    p = builder.buildSolidColorPaint(0)
    assert p.Format == 1
    assert p.Color.PaletteIndex == 0
    assert p.Color.Transparency.value == 0.0
    assert p.Color.Transparency.varIdx == 0

    p = builder.buildSolidColorPaint(1, transparency=0.5)
    assert p.Format == 1
    assert p.Color.PaletteIndex == 1
    assert p.Color.Transparency.value == 0.5
    assert p.Color.Transparency.varIdx == 0

    p = builder.buildSolidColorPaint(3,
                                     transparency=builder.VariableFloat(
                                         0.5, varIdx=2))
    assert p.Format == 1
    assert p.Color.PaletteIndex == 3
    assert p.Color.Transparency.value == 0.5
    assert p.Color.Transparency.varIdx == 2
Exemplo n.º 3
0
def test_buildSolidColorPaint():
    p = builder.buildSolidColorPaint(0)
    assert p.Format == 1
    assert p.Color.PaletteIndex == 0
    assert p.Color.Alpha.value == 1.0
    assert p.Color.Alpha.varIdx == 0

    p = builder.buildSolidColorPaint(1, alpha=0.5)
    assert p.Format == 1
    assert p.Color.PaletteIndex == 1
    assert p.Color.Alpha.value == 0.5
    assert p.Color.Alpha.varIdx == 0

    p = builder.buildSolidColorPaint(3,
                                     alpha=builder.VariableFloat(0.5,
                                                                 varIdx=2))
    assert p.Format == 1
    assert p.Color.PaletteIndex == 3
    assert p.Color.Alpha.value == 0.5
    assert p.Color.Alpha.varIdx == 2
Exemplo n.º 4
0
def test_splitSolidAndGradientGlyphs():
    colorGlyphs = {
        "a": [
            ("b", 0),
            ("c", 1),
            ("d", {
                "format": 1,
                "paletteIndex": 2
            }),
            ("e", builder.buildSolidColorPaint(paletteIndex=3)),
        ]
    }

    colorGlyphsV0, colorGlyphsV1 = builder._splitSolidAndGradientGlyphs(
        colorGlyphs)

    assert colorGlyphsV0 == {"a": [("b", 0), ("c", 1), ("d", 2), ("e", 3)]}
    assert not colorGlyphsV1

    colorGlyphs = {
        "a":
        [("b", builder.buildSolidColorPaint(paletteIndex=0, transparency=1.0))]
    }

    colorGlyphsV0, colorGlyphsV1 = builder._splitSolidAndGradientGlyphs(
        colorGlyphs)

    assert not colorGlyphsV0
    assert colorGlyphsV1 == colorGlyphs

    colorGlyphs = {
        "a": [("b", 0)],
        "c": [
            ("d", 1),
            (
                "e",
                {
                    "format": 2,
                    "colorLine": {
                        "stops": [(0.0, 2), (1.0, 3)]
                    },
                    "p0": (0, 0),
                    "p1": (10, 10),
                },
            ),
        ],
    }

    colorGlyphsV0, colorGlyphsV1 = builder._splitSolidAndGradientGlyphs(
        colorGlyphs)

    assert colorGlyphsV0 == {"a": [("b", 0)]}
    assert "a" not in colorGlyphsV1
    assert "c" in colorGlyphsV1
    assert len(colorGlyphsV1["c"]) == 2

    layer_d = colorGlyphsV1["c"][0]
    assert layer_d[0] == "d"
    assert isinstance(layer_d[1], ot.Paint)
    assert layer_d[1].Format == 1

    layer_e = colorGlyphsV1["c"][1]
    assert layer_e[0] == "e"
    assert isinstance(layer_e[1], ot.Paint)
    assert layer_e[1].Format == 2
Exemplo n.º 5
0
def test_buildLayerV1Record():
    layer = builder.buildLayerV1Record("a", 2)
    assert layer.LayerGlyph == "a"
    assert layer.Paint.Format == 1
    assert layer.Paint.Color.PaletteIndex == 2

    layer = builder.buildLayerV1Record("a",
                                       builder.buildSolidColorPaint(3, 0.9))
    assert layer.Paint.Format == 1
    assert layer.Paint.Color.PaletteIndex == 3
    assert layer.Paint.Color.Transparency.value == 0.9

    layer = builder.buildLayerV1Record(
        "a",
        builder.buildLinearGradientPaint({"stops": [(0.0, 3), (1.0, 4)]},
                                         (100, 200), (150, 250)),
    )
    assert layer.Paint.Format == 2
    assert layer.Paint.ColorLine.ColorStop[0].StopOffset.value == 0.0
    assert layer.Paint.ColorLine.ColorStop[0].Color.PaletteIndex == 3
    assert layer.Paint.ColorLine.ColorStop[1].StopOffset.value == 1.0
    assert layer.Paint.ColorLine.ColorStop[1].Color.PaletteIndex == 4
    assert layer.Paint.p0.x.value == 100
    assert layer.Paint.p0.y.value == 200
    assert layer.Paint.p1.x.value == 150
    assert layer.Paint.p1.y.value == 250

    layer = builder.buildLayerV1Record(
        "a",
        builder.buildRadialGradientPaint(
            {
                "stops": [
                    (0.0, 5),
                    {
                        "offset": 0.5,
                        "paletteIndex": 6,
                        "transparency": 0.8
                    },
                    (1.0, 7),
                ]
            },
            (50, 50),
            (75, 75),
            30,
            10,
        ),
    )
    assert layer.Paint.Format == 3
    assert layer.Paint.ColorLine.ColorStop[0].StopOffset.value == 0.0
    assert layer.Paint.ColorLine.ColorStop[0].Color.PaletteIndex == 5
    assert layer.Paint.ColorLine.ColorStop[1].StopOffset.value == 0.5
    assert layer.Paint.ColorLine.ColorStop[1].Color.PaletteIndex == 6
    assert layer.Paint.ColorLine.ColorStop[1].Color.Transparency.value == 0.8
    assert layer.Paint.ColorLine.ColorStop[2].StopOffset.value == 1.0
    assert layer.Paint.ColorLine.ColorStop[2].Color.PaletteIndex == 7
    assert layer.Paint.c0.x.value == 50
    assert layer.Paint.c0.y.value == 50
    assert layer.Paint.c1.x.value == 75
    assert layer.Paint.c1.y.value == 75
    assert layer.Paint.r0.value == 30
    assert layer.Paint.r1.value == 10