colorLib: use IntEnum instead of 'magic' Paint format integers
makes code more readable
This commit is contained in:
parent
53b0034b35
commit
1803283baf
@ -370,7 +370,7 @@ def buildPaintSolid(
|
||||
paletteIndex: int, alpha: _ScalarInput = _DEFAULT_ALPHA
|
||||
) -> ot.Paint:
|
||||
self = ot.Paint()
|
||||
self.Format = 1
|
||||
self.Format = int(ot.Paint.Format.PaintSolid)
|
||||
self.Color = buildColorIndex(paletteIndex, alpha)
|
||||
return self
|
||||
|
||||
@ -437,7 +437,7 @@ def buildPaintLinearGradient(
|
||||
p2: Optional[_PointTuple] = None,
|
||||
) -> ot.Paint:
|
||||
self = ot.Paint()
|
||||
self.Format = 2
|
||||
self.Format = int(ot.Paint.Format.PaintLinearGradient)
|
||||
self.ColorLine = _to_color_line(colorLine)
|
||||
|
||||
if p2 is None:
|
||||
@ -474,7 +474,7 @@ def buildPaintRadialGradient(
|
||||
) -> ot.Paint:
|
||||
|
||||
self = ot.Paint()
|
||||
self.Format = 3
|
||||
self.Format = int(ot.Paint.Format.PaintRadialGradient)
|
||||
self.ColorLine = _to_color_line(colorLine)
|
||||
|
||||
for i, (x, y), r in [(0, c0, r0), (1, c1, r1)]:
|
||||
@ -487,7 +487,7 @@ def buildPaintRadialGradient(
|
||||
|
||||
def buildPaintGlyph(glyph: str, paint: _PaintInput) -> ot.Paint:
|
||||
self = ot.Paint()
|
||||
self.Format = 4
|
||||
self.Format = int(ot.Paint.Format.PaintGlyph)
|
||||
self.Glyph = glyph
|
||||
self.Paint = buildPaint(paint)
|
||||
return self
|
||||
@ -495,14 +495,14 @@ def buildPaintGlyph(glyph: str, paint: _PaintInput) -> ot.Paint:
|
||||
|
||||
def buildPaintColorGlyph(glyph: str) -> ot.Paint:
|
||||
self = ot.Paint()
|
||||
self.Format = 5
|
||||
self.Format = int(ot.Paint.Format.PaintColorGlyph)
|
||||
self.Glyph = glyph
|
||||
return self
|
||||
|
||||
|
||||
def buildPaintTransform(transform: _AffineInput, paint: _PaintInput) -> ot.Paint:
|
||||
self = ot.Paint()
|
||||
self.Format = 6
|
||||
self.Format = int(ot.Paint.Format.PaintTransform)
|
||||
if not isinstance(transform, ot.Affine2x3):
|
||||
transform = buildAffine2x3(*transform)
|
||||
self.Transform = transform
|
||||
@ -514,7 +514,7 @@ def buildPaintComposite(
|
||||
mode: _CompositeInput, source: _PaintInput, backdrop: _PaintInput
|
||||
):
|
||||
self = ot.Paint()
|
||||
self.Format = 7
|
||||
self.Format = int(ot.Paint.Format.PaintComposite)
|
||||
self.SourcePaint = buildPaint(source)
|
||||
self.CompositeMode = _to_composite_mode(mode)
|
||||
self.BackdropPaint = buildPaint(backdrop)
|
||||
|
@ -207,19 +207,19 @@ def test_buildColorIndex():
|
||||
|
||||
def test_buildPaintSolid():
|
||||
p = builder.buildPaintSolid(0)
|
||||
assert p.Format == 1
|
||||
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 = builder.buildPaintSolid(1, alpha=0.5)
|
||||
assert p.Format == 1
|
||||
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 = builder.buildPaintSolid(3, alpha=builder.VariableFloat(0.5, varIdx=2))
|
||||
assert p.Format == 1
|
||||
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
|
||||
@ -333,7 +333,7 @@ def test_buildPaintRadialGradient():
|
||||
r1 = builder.VariableInt(5)
|
||||
|
||||
gradient = builder.buildPaintRadialGradient(color_line, c0, c1, r0, r1)
|
||||
assert gradient.Format == 3
|
||||
assert gradient.Format == ot.Paint.Format.PaintRadialGradient
|
||||
assert gradient.ColorLine == color_line
|
||||
assert (gradient.x0, gradient.y0) == c0
|
||||
assert (gradient.x1, gradient.y1) == c1
|
||||
@ -348,11 +348,11 @@ def test_buildPaintRadialGradient():
|
||||
def test_buildPaintGlyph():
|
||||
layer = builder.buildPaintGlyph("a", 2)
|
||||
assert layer.Glyph == "a"
|
||||
assert layer.Paint.Format == 1
|
||||
assert layer.Paint.Format == ot.Paint.Format.PaintSolid
|
||||
assert layer.Paint.Color.PaletteIndex == 2
|
||||
|
||||
layer = builder.buildPaintGlyph("a", builder.buildPaintSolid(3, 0.9))
|
||||
assert layer.Paint.Format == 1
|
||||
assert layer.Paint.Format == ot.Paint.Format.PaintSolid
|
||||
assert layer.Paint.Color.PaletteIndex == 3
|
||||
assert layer.Paint.Color.Alpha.value == 0.9
|
||||
|
||||
@ -362,7 +362,7 @@ def test_buildPaintGlyph():
|
||||
{"stops": [(0.0, 3), (1.0, 4)]}, (100, 200), (150, 250)
|
||||
),
|
||||
)
|
||||
assert layer.Paint.Format == 2
|
||||
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
|
||||
@ -388,7 +388,7 @@ def test_buildPaintGlyph():
|
||||
10,
|
||||
),
|
||||
)
|
||||
assert layer.Paint.Format == 3
|
||||
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
|
||||
@ -407,7 +407,7 @@ def test_buildPaintGlyph():
|
||||
def test_buildPaintGlyph_from_dict():
|
||||
layer = builder.buildPaintGlyph("a", {"format": 1, "paletteIndex": 0})
|
||||
assert layer.Glyph == "a"
|
||||
assert layer.Paint.Format == 1
|
||||
assert layer.Paint.Format == ot.Paint.Format.PaintSolid
|
||||
assert layer.Paint.Color.PaletteIndex == 0
|
||||
|
||||
layer = builder.buildPaintGlyph(
|
||||
@ -419,7 +419,7 @@ def test_buildPaintGlyph_from_dict():
|
||||
"p1": (10, 10),
|
||||
},
|
||||
)
|
||||
assert layer.Paint.Format == 2
|
||||
assert layer.Paint.Format == ot.Paint.Format.PaintLinearGradient
|
||||
assert layer.Paint.ColorLine.ColorStop[0].StopOffset.value == 0.0
|
||||
|
||||
layer = builder.buildPaintGlyph(
|
||||
@ -433,7 +433,7 @@ def test_buildPaintGlyph_from_dict():
|
||||
"r1": 0,
|
||||
},
|
||||
)
|
||||
assert layer.Paint.Format == 3
|
||||
assert layer.Paint.Format == ot.Paint.Format.PaintRadialGradient
|
||||
assert layer.Paint.r0.value == 4
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user