Exemple #1
0
def test_buildLinearGradientPaint():
    color_stops = [
        builder.buildColorStop(0.0, 0),
        builder.buildColorStop(0.5, 1),
        builder.buildColorStop(1.0, 2, transparency=0.8),
    ]
    color_line = builder.buildColorLine(color_stops,
                                        extend=builder.ExtendMode.REPEAT)
    p0 = builder.buildPoint(x=100, y=200)
    p1 = builder.buildPoint(x=150, y=250)

    gradient = builder.buildLinearGradientPaint(color_line, p0, p1)
    assert gradient.Format == 2
    assert gradient.ColorLine == color_line
    assert gradient.p0 == p0
    assert gradient.p1 == p1
    assert gradient.p2 == gradient.p1
    assert gradient.p2 is not gradient.p1

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

    gradient = builder.buildLinearGradientPaint(color_line,
                                                p0,
                                                p1,
                                                p2=(150, 230))
    assert gradient.p2 == builder.buildPoint(x=150, y=230)
    assert gradient.p2 != gradient.p1
Exemple #2
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
Exemple #3
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)
Exemple #4
0
def test_buildColorStop():
    s = builder.buildColorStop(0.1, 2)
    assert s.StopOffset == builder.VariableFloat(0.1)
    assert s.Color.PaletteIndex == 2
    assert s.Color.Transparency == builder._DEFAULT_TRANSPARENCY

    s = builder.buildColorStop(offset=0.2, paletteIndex=3, transparency=0.4)
    assert s.StopOffset == builder.VariableFloat(0.2)
    assert s.Color == builder.buildColor(3, transparency=0.4)

    s = builder.buildColorStop(
        offset=builder.VariableFloat(0.0, varIdx=1),
        paletteIndex=0,
        transparency=builder.VariableFloat(0.3, varIdx=2),
    )
    assert s.StopOffset == builder.VariableFloat(0.0, varIdx=1)
    assert s.Color.PaletteIndex == 0
    assert s.Color.Transparency == builder.VariableFloat(0.3, varIdx=2)
Exemple #5
0
def test_buildColorStop():
    s = builder.buildColorStop(0.1, 2)
    assert s.StopOffset == builder.VariableFloat(0.1)
    assert s.Color.PaletteIndex == 2
    assert s.Color.Alpha == builder._DEFAULT_ALPHA

    s = builder.buildColorStop(offset=0.2, paletteIndex=3, alpha=0.4)
    assert s.StopOffset == builder.VariableFloat(0.2)
    assert s.Color == builder.buildColorIndex(3, alpha=0.4)

    s = builder.buildColorStop(
        offset=builder.VariableFloat(0.0, varIdx=1),
        paletteIndex=0,
        alpha=builder.VariableFloat(0.3, varIdx=2),
    )
    assert s.StopOffset == builder.VariableFloat(0.0, varIdx=1)
    assert s.Color.PaletteIndex == 0
    assert s.Color.Alpha == builder.VariableFloat(0.3, varIdx=2)
Exemple #6
0
def test_buildRadialGradientPaint():
    color_stops = [
        builder.buildColorStop(0.0, 0),
        builder.buildColorStop(0.5, 1),
        builder.buildColorStop(1.0, 2, transparency=0.8),
    ]
    color_line = builder.buildColorLine(color_stops,
                                        extend=builder.ExtendMode.REPEAT)
    c0 = builder.buildPoint(x=100, y=200)
    c1 = builder.buildPoint(x=150, y=250)
    r0 = builder.VariableInt(10)
    r1 = builder.VariableInt(5)

    gradient = builder.buildRadialGradientPaint(color_line, c0, c1, r0, r1)
    assert gradient.Format == 3
    assert gradient.ColorLine == color_line
    assert gradient.c0 == c0
    assert gradient.c1 == c1
    assert gradient.r0 == r0
    assert gradient.r1 == r1
    assert gradient.Affine is None

    gradient = builder.buildRadialGradientPaint({"stops": color_stops}, c0, c1,
                                                r0, r1)
    assert gradient.ColorLine.Extend == builder.ExtendMode.PAD
    assert gradient.ColorLine.ColorStop == color_stops

    matrix = builder.buildAffine2x2(2.0, 0.0, 0.0, 2.0)
    gradient = builder.buildRadialGradientPaint(color_line,
                                                c0,
                                                c1,
                                                r0,
                                                r1,
                                                affine=matrix)
    assert gradient.Affine == matrix

    gradient = builder.buildRadialGradientPaint(color_line,
                                                c0,
                                                c1,
                                                r0,
                                                r1,
                                                affine=(2.0, 0.0, 0.0, 2.0))
    assert gradient.Affine == matrix
Exemple #7
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
Exemple #8
0
def test_buildRadialGradientPaint():
    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 = builder.buildRadialGradientPaint(color_line, c0, c1, r0, r1)
    assert gradient.Format == 3
    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
    assert gradient.Transform is None

    gradient = builder.buildRadialGradientPaint({"stops": color_stops}, c0, c1,
                                                r0, r1)
    assert gradient.ColorLine.Extend == builder.ExtendMode.PAD
    assert gradient.ColorLine.ColorStop == color_stops

    matrix = builder.buildAffine2x2(2.0, 0.0, 0.0, 2.0)
    gradient = builder.buildRadialGradientPaint(color_line,
                                                c0,
                                                c1,
                                                r0,
                                                r1,
                                                transform=matrix)
    assert gradient.Transform == matrix

    gradient = builder.buildRadialGradientPaint(color_line,
                                                c0,
                                                c1,
                                                r0,
                                                r1,
                                                transform=(2.0, 0.0, 0.0, 2.0))
    assert gradient.Transform == matrix
Exemple #9
0
def test_buildColorLine():
    stops = [(0.0, 0), (0.5, 1), (1.0, 2)]

    cline = builder.buildColorLine(stops)
    assert cline.Extend == builder.ExtendMode.PAD
    assert cline.StopCount == 3
    assert [(cs.StopOffset.value, cs.Color.PaletteIndex)
            for cs in cline.ColorStop] == stops

    cline = builder.buildColorLine(stops, extend="pad")
    assert cline.Extend == builder.ExtendMode.PAD

    cline = builder.buildColorLine(stops, extend=builder.ExtendMode.REPEAT)
    assert cline.Extend == builder.ExtendMode.REPEAT

    cline = builder.buildColorLine(stops, extend=builder.ExtendMode.REFLECT)
    assert cline.Extend == builder.ExtendMode.REFLECT

    cline = builder.buildColorLine([builder.buildColorStop(*s) for s in stops])
    assert [(cs.StopOffset.value, cs.Color.PaletteIndex)
            for cs in cline.ColorStop] == stops

    stops = [
        {
            "offset": (0.0, 1),
            "paletteIndex": 0,
            "transparency": (0.5, 2)
        },
        {
            "offset": (1.0, 3),
            "paletteIndex": 1,
            "transparency": (0.3, 4)
        },
    ]
    cline = builder.buildColorLine(stops)
    assert [{
        "offset": cs.StopOffset,
        "paletteIndex": cs.Color.PaletteIndex,
        "transparency": cs.Color.Transparency,
    } for cs in cline.ColorStop] == stops