예제 #1
0
def test_buildPaintLinearGradient():
    layerBuilder = LayerV1ListBuilder()
    color_stops = [
        builder.buildColorStop(0.0, 0),
        builder.buildColorStop(0.5, 1),
        builder.buildColorStop(1.0, 2, alpha=0.8),
    ]
    color_line = builder.buildColorLine(color_stops,
                                        extend=builder.ExtendMode.REPEAT)
    p0 = (builder.VariableInt(100), builder.VariableInt(200))
    p1 = (builder.VariableInt(150), builder.VariableInt(250))

    gradient = layerBuilder.buildPaintLinearGradient(color_line, p0, p1)
    assert gradient.Format == 3
    assert gradient.ColorLine == color_line
    assert (gradient.x0, gradient.y0) == p0
    assert (gradient.x1, gradient.y1) == p1
    assert (gradient.x2, gradient.y2) == p1

    gradient = layerBuilder.buildPaintLinearGradient({"stops": color_stops},
                                                     p0, p1)
    assert gradient.ColorLine.Extend == builder.ExtendMode.PAD
    assert gradient.ColorLine.ColorStop == color_stops

    gradient = layerBuilder.buildPaintLinearGradient(color_line,
                                                     p0,
                                                     p1,
                                                     p2=(150, 230))
    assert (gradient.x2.value, gradient.y2.value) == (150, 230)
    assert (gradient.x2, gradient.y2) != (gradient.x1, gradient.y1)
예제 #2
0
def test_buildPaintComposite():
    layerBuilder = LayerV1ListBuilder()
    composite = layerBuilder.buildPaintComposite(
        mode=ot.CompositeMode.SRC_OVER,
        source={
            "format": 8,
            "mode": "src_over",
            "source": {"format": 5, "glyph": "c", "paint": 2},
            "backdrop": {"format": 5, "glyph": "b", "paint": 1},
        },
        backdrop=layerBuilder.buildPaintGlyph(
            "a", layerBuilder.buildPaintSolid(paletteIndex=0, alpha=1.0)
        ),
    )

    assert composite.Format == ot.Paint.Format.PaintComposite
    assert composite.SourcePaint.Format == ot.Paint.Format.PaintComposite
    assert composite.SourcePaint.SourcePaint.Format == ot.Paint.Format.PaintGlyph
    assert composite.SourcePaint.SourcePaint.Glyph == "c"
    assert composite.SourcePaint.SourcePaint.Paint.Format == ot.Paint.Format.PaintSolid
    assert composite.SourcePaint.SourcePaint.Paint.Color.PaletteIndex == 2
    assert composite.SourcePaint.CompositeMode == ot.CompositeMode.SRC_OVER
    assert composite.SourcePaint.BackdropPaint.Format == ot.Paint.Format.PaintGlyph
    assert composite.SourcePaint.BackdropPaint.Glyph == "b"
    assert (
        composite.SourcePaint.BackdropPaint.Paint.Format == ot.Paint.Format.PaintSolid
    )
    assert composite.SourcePaint.BackdropPaint.Paint.Color.PaletteIndex == 1
    assert composite.CompositeMode == ot.CompositeMode.SRC_OVER
    assert composite.BackdropPaint.Format == ot.Paint.Format.PaintGlyph
    assert composite.BackdropPaint.Glyph == "a"
    assert composite.BackdropPaint.Paint.Format == ot.Paint.Format.PaintSolid
    assert composite.BackdropPaint.Paint.Color.PaletteIndex == 0
예제 #3
0
def test_buildPaintGlyph_RadialGradient():
    layerBuilder = LayerV1ListBuilder()
    layer = layerBuilder.buildPaintGlyph(
        "a",
        layerBuilder.buildPaintRadialGradient(
            {
                "stops": [
                    (0.0, 5),
                    {"offset": 0.5, "paletteIndex": 6, "alpha": 0.8},
                    (1.0, 7),
                ]
            },
            (50, 50),
            (75, 75),
            30,
            10,
        ),
    )
    assert layer.Paint.Format == ot.Paint.Format.PaintRadialGradient
    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.Alpha.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.x0.value == 50
    assert layer.Paint.y0.value == 50
    assert layer.Paint.r0.value == 30
    assert layer.Paint.x1.value == 75
    assert layer.Paint.y1.value == 75
    assert layer.Paint.r1.value == 10
예제 #4
0
def test_buildPaintRadialGradient():
    layerBuilder = LayerV1ListBuilder()
    color_stops = [
        builder.buildColorStop(0.0, 0),
        builder.buildColorStop(0.5, 1),
        builder.buildColorStop(1.0, 2, alpha=0.8),
    ]
    color_line = builder.buildColorLine(color_stops,
                                        extend=builder.ExtendMode.REPEAT)
    c0 = (builder.VariableInt(100), builder.VariableInt(200))
    c1 = (builder.VariableInt(150), builder.VariableInt(250))
    r0 = builder.VariableInt(10)
    r1 = builder.VariableInt(5)

    gradient = layerBuilder.buildPaintRadialGradient(color_line, c0, c1, r0,
                                                     r1)
    assert gradient.Format == ot.Paint.Format.PaintRadialGradient
    assert gradient.ColorLine == color_line
    assert (gradient.x0, gradient.y0) == c0
    assert (gradient.x1, gradient.y1) == c1
    assert gradient.r0 == r0
    assert gradient.r1 == r1

    gradient = layerBuilder.buildPaintRadialGradient({"stops": color_stops},
                                                     c0, c1, r0, r1)
    assert gradient.ColorLine.Extend == builder.ExtendMode.PAD
    assert gradient.ColorLine.ColorStop == color_stops
예제 #5
0
def test_buildPaintGlyph_Solid():
    layerBuilder = LayerV1ListBuilder()
    layer = layerBuilder.buildPaintGlyph("a", 2)
    assert layer.Glyph == "a"
    assert layer.Paint.Format == ot.Paint.Format.PaintSolid
    assert layer.Paint.Color.PaletteIndex == 2

    layer = layerBuilder.buildPaintGlyph("a", layerBuilder.buildPaintSolid(3, 0.9))
    assert layer.Paint.Format == ot.Paint.Format.PaintSolid
    assert layer.Paint.Color.PaletteIndex == 3
    assert layer.Paint.Color.Alpha.value == 0.9
예제 #6
0
def test_buildPaintSolid():
    p = LayerV1ListBuilder().buildPaintSolid(0)
    assert p.Format == ot.Paint.Format.PaintSolid
    assert p.Color.PaletteIndex == 0
    assert p.Color.Alpha.value == 1.0
    assert p.Color.Alpha.varIdx == 0

    p = LayerV1ListBuilder().buildPaintSolid(1, alpha=0.5)
    assert p.Format == ot.Paint.Format.PaintSolid
    assert p.Color.PaletteIndex == 1
    assert p.Color.Alpha.value == 0.5
    assert p.Color.Alpha.varIdx == 0

    p = LayerV1ListBuilder().buildPaintSolid(3,
                                             alpha=builder.VariableFloat(
                                                 0.5, varIdx=2))
    assert p.Format == ot.Paint.Format.PaintSolid
    assert p.Color.PaletteIndex == 3
    assert p.Color.Alpha.value == 0.5
    assert p.Color.Alpha.varIdx == 2
예제 #7
0
def test_split_color_glyphs_by_version():
    layerBuilder = LayerV1ListBuilder()
    colorGlyphs = {
        "a": [
            ("b", 0),
            ("c", 1),
            ("d", 2),
            ("e", 3),
        ]
    }

    colorGlyphsV0, colorGlyphsV1 = builder._split_color_glyphs_by_version(
        colorGlyphs)

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

    colorGlyphs = {
        "a": [("b", layerBuilder.buildPaintSolid(paletteIndex=0, alpha=0.0))]
    }

    colorGlyphsV0, colorGlyphsV1 = builder._split_color_glyphs_by_version(
        colorGlyphs)

    assert not colorGlyphsV0
    assert colorGlyphsV1 == colorGlyphs

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

    colorGlyphsV0, colorGlyphsV1 = builder._split_color_glyphs_by_version(
        colorGlyphs)

    assert colorGlyphsV0 == {"a": [("b", 0)]}
    assert "a" not in colorGlyphsV1
    assert "c" in colorGlyphsV1
    assert len(colorGlyphsV1["c"]) == 2
예제 #8
0
def test_buildPaintTranslate():
    layerBuilder = LayerV1ListBuilder()
    paint = layerBuilder.buildPaintTranslate(
        paint=layerBuilder.buildPaintGlyph(
            "a", layerBuilder.buildPaintSolid(paletteIndex=0, alpha=1.0)),
        dx=123,
        dy=-345,
    )

    assert paint.Format == ot.Paint.Format.PaintTranslate
    assert paint.Paint.Format == ot.Paint.Format.PaintGlyph
    assert paint.dx.value == 123
    assert paint.dy.value == -345
예제 #9
0
def test_buildPaintGlyph_Dict_LinearGradient():
    layerBuilder = LayerV1ListBuilder()
    layer = layerBuilder.buildPaintGlyph(
        "a",
        {
            "format": 3,
            "colorLine": {"stops": [(0.0, 0), (1.0, 1)]},
            "p0": (0, 0),
            "p1": (10, 10),
        },
    )
    assert layer.Paint.Format == ot.Paint.Format.PaintLinearGradient
    assert layer.Paint.ColorLine.ColorStop[0].StopOffset.value == 0.0
예제 #10
0
def test_buildPaintRotate():
    layerBuilder = LayerV1ListBuilder()
    paint = layerBuilder.buildPaintRotate(
        paint=layerBuilder.buildPaintGlyph(
            "a", layerBuilder.buildPaintSolid(paletteIndex=0, alpha=1.0)),
        angle=15,
        centerX=127,
        centerY=129,
    )

    assert paint.Format == ot.Paint.Format.PaintRotate
    assert paint.Paint.Format == ot.Paint.Format.PaintGlyph
    assert paint.angle.value == 15
    assert paint.centerX.value == 127
    assert paint.centerY.value == 129
예제 #11
0
def test_buildPaintGlyph_Dict_RadialGradient():
    layerBuilder = LayerV1ListBuilder()
    layer = layerBuilder.buildPaintGlyph(
        "a",
        {
            "format": 4,
            "colorLine": {"stops": [(0.0, 0), (1.0, 1)]},
            "c0": (0, 0),
            "c1": (10, 10),
            "r0": 4,
            "r1": 0,
        },
    )
    assert layer.Paint.Format == ot.Paint.Format.PaintRadialGradient
    assert layer.Paint.r0.value == 4
예제 #12
0
def test_buildPaintGlyph_LinearGradient():
    layerBuilder = LayerV1ListBuilder()
    layer = layerBuilder.buildPaintGlyph(
        "a",
        layerBuilder.buildPaintLinearGradient({"stops": [(0.0, 3), (1.0, 4)]},
                                              (100, 200), (150, 250)),
    )
    assert layer.Paint.Format == ot.Paint.Format.PaintLinearGradient
    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.x0.value == 100
    assert layer.Paint.y0.value == 200
    assert layer.Paint.x1.value == 150
    assert layer.Paint.y1.value == 250
예제 #13
0
def test_buildPaintSkew():
    layerBuilder = LayerV1ListBuilder()
    paint = layerBuilder.buildPaintSkew(
        paint=layerBuilder.buildPaintGlyph(
            "a", layerBuilder.buildPaintSolid(paletteIndex=0, alpha=1.0)),
        xSkewAngle=15,
        ySkewAngle=42,
        centerX=127,
        centerY=129,
    )

    assert paint.Format == ot.Paint.Format.PaintSkew
    assert paint.Paint.Format == ot.Paint.Format.PaintGlyph
    assert paint.xSkewAngle.value == 15
    assert paint.ySkewAngle.value == 42
    assert paint.centerX.value == 127
    assert paint.centerY.value == 129
예제 #14
0
def test_buildPaintTransform():
    layerBuilder = LayerV1ListBuilder()
    paint = layerBuilder.buildPaintTransform(
        transform=builder.buildAffine2x3((1, 2, 3, 4, 5, 6)),
        paint=layerBuilder.buildPaintGlyph(
            glyph="a",
            paint=layerBuilder.buildPaintSolid(paletteIndex=0, alpha=1.0),
        ),
    )

    assert paint.Format == ot.Paint.Format.PaintTransform
    assert paint.Paint.Format == ot.Paint.Format.PaintGlyph
    assert paint.Paint.Paint.Format == ot.Paint.Format.PaintSolid

    assert paint.Transform.xx.value == 1.0
    assert paint.Transform.yx.value == 2.0
    assert paint.Transform.xy.value == 3.0
    assert paint.Transform.yy.value == 4.0
    assert paint.Transform.dx.value == 5.0
    assert paint.Transform.dy.value == 6.0

    paint = layerBuilder.buildPaintTransform(
        (1, 0, 0, 0.3333, 10, 10),
        {
            "format": 4,
            "colorLine": {
                "stops": [(0.0, 0), (1.0, 1)]
            },
            "c0": (100, 100),
            "c1": (100, 100),
            "r0": 0,
            "r1": 50,
        },
    )

    assert paint.Format == ot.Paint.Format.PaintTransform
    assert paint.Transform.xx.value == 1.0
    assert paint.Transform.yx.value == 0.0
    assert paint.Transform.xy.value == 0.0
    assert paint.Transform.yy.value == 0.3333
    assert paint.Transform.dx.value == 10
    assert paint.Transform.dy.value == 10
    assert paint.Paint.Format == ot.Paint.Format.PaintRadialGradient
예제 #15
0
def test_buildPaintSweepGradient():
    layerBuilder = LayerV1ListBuilder()
    paint = layerBuilder.buildPaintSweepGradient(
        colorLine=builder.buildColorLine(stops=[
            builder.buildColorStop(0.0, 0),
            builder.buildColorStop(0.5, 1),
            builder.buildColorStop(1.0, 2, alpha=0.8),
        ], ),
        centerX=127,
        centerY=129,
        startAngle=15,
        endAngle=42,
    )

    assert paint.Format == ot.PaintFormat.PaintSweepGradient
    assert paint.centerX.value == 127
    assert paint.centerY.value == 129
    assert paint.startAngle.value == 15
    assert paint.endAngle.value == 42
예제 #16
0
def test_buildPaintColrGlyph():
    paint = LayerV1ListBuilder().buildPaintColrGlyph("a")
    assert paint.Format == ot.Paint.Format.PaintColrGlyph
    assert paint.Glyph == "a"
예제 #17
0
def test_buildPaintGlyph_Dict_Solid():
    layerBuilder = LayerV1ListBuilder()
    layer = layerBuilder.buildPaintGlyph("a", {"format": 2, "paletteIndex": 0})
    assert layer.Glyph == "a"
    assert layer.Paint.Format == ot.Paint.Format.PaintSolid
    assert layer.Paint.Color.PaletteIndex == 0