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)
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
def test_buildPoint(): pt = builder.buildPoint(0, 1) assert pt.x == builder.VariableInt(0) assert pt.y == builder.VariableInt(1) pt = builder.buildPoint(builder.VariableInt(2, varIdx=1), builder.VariableInt(3, varIdx=2)) assert pt.x == builder.VariableInt(2, varIdx=1) assert pt.y == builder.VariableInt(3, varIdx=2) # float coords are rounded pt = builder.buildPoint(x=-2.5, y=3.5) assert pt.x == builder.VariableInt(-2) assert pt.y == builder.VariableInt(4) # tuple args are cast to VariableInt namedtuple pt = builder.buildPoint((1, 2), (3, 4)) assert pt.x == builder.VariableInt(1, varIdx=2) assert pt.y == builder.VariableInt(3, varIdx=4)
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
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