Merge pull request #118 from guzba/master
strokes wrNonZero + more parsing linecap linejoin
This commit is contained in:
commit
dbe17be7cc
3 changed files with 55 additions and 18 deletions
|
@ -142,13 +142,12 @@ proc strokeSegment*(
|
|||
image: Image,
|
||||
segment: Segment,
|
||||
color: ColorRGBA,
|
||||
strokeWidth = 1.0,
|
||||
blendMode = bmNormal
|
||||
strokeWidth = 1.0
|
||||
) =
|
||||
var path: Path
|
||||
path.moveTo(segment.at)
|
||||
path.lineTo(segment.to)
|
||||
image.strokePath(path, color, strokeWidth, wrNonZero, blendMode)
|
||||
image.strokePath(path, color, strokeWidth)
|
||||
|
||||
proc strokeSegment*(mask: Mask, segment: Segment, strokeWidth: float32) =
|
||||
var path: Path
|
||||
|
|
|
@ -8,6 +8,8 @@ const svgSignature* = "<?xml"
|
|||
type Ctx = object
|
||||
fill, stroke: ColorRGBA
|
||||
strokeWidth: float32
|
||||
strokeLineCap: LineCap
|
||||
strokeLineJoin: LineJoin
|
||||
transform: Mat3
|
||||
|
||||
template failInvalid() =
|
||||
|
@ -25,6 +27,8 @@ proc decodeCtx(inherited: Ctx, node: XmlNode): Ctx =
|
|||
fill = node.attr("fill")
|
||||
stroke = node.attr("stroke")
|
||||
strokeWidth = node.attr("stroke-width")
|
||||
strokeLineCap = node.attr("stroke-linecap")
|
||||
strokeLineJoin = node.attr("stroke-linejoin")
|
||||
transform = node.attr("transform")
|
||||
|
||||
if fill == "":
|
||||
|
@ -46,6 +50,40 @@ proc decodeCtx(inherited: Ctx, node: XmlNode): Ctx =
|
|||
else:
|
||||
result.strokeWidth = parseFloat(strokeWidth)
|
||||
|
||||
if strokeLineCap == "":
|
||||
discard # Inherit
|
||||
else:
|
||||
case strokeLineCap:
|
||||
of "butt":
|
||||
result.strokeLineCap = lcButt
|
||||
of "round":
|
||||
result.strokeLineCap = lcRound
|
||||
of "square":
|
||||
result.strokeLineCap = lcSquare
|
||||
of "inherit":
|
||||
discard
|
||||
else:
|
||||
raise newException(
|
||||
PixieError, "Invalid stroke-linecap value " & strokeLineCap
|
||||
)
|
||||
|
||||
if strokeLineJoin == "":
|
||||
discard # Inherit
|
||||
else:
|
||||
case strokeLineJoin:
|
||||
of "miter":
|
||||
result.strokeLineJoin = ljMiter
|
||||
of "round":
|
||||
result.strokeLineJoin = ljRound
|
||||
of "bevel":
|
||||
result.strokeLineJoin = ljBevel
|
||||
of "inherit":
|
||||
discard
|
||||
else:
|
||||
raise newException(
|
||||
PixieError, "Invalid stroke-linejoin value " & strokeLineJoin
|
||||
)
|
||||
|
||||
if transform == "":
|
||||
discard # Inherit
|
||||
else:
|
||||
|
|
|
@ -8,6 +8,12 @@ type
|
|||
wrNonZero
|
||||
wrEvenOdd
|
||||
|
||||
LineCap* = enum
|
||||
lcButt, lcRound, lcSquare
|
||||
|
||||
LineJoin* = enum
|
||||
ljMiter, ljRound, ljBevel
|
||||
|
||||
PathCommandKind* = enum
|
||||
## Type of path commands
|
||||
Close,
|
||||
|
@ -1314,11 +1320,10 @@ proc strokePath*(
|
|||
path: SomePath,
|
||||
color: ColorRGBA,
|
||||
strokeWidth = 1.0,
|
||||
windingRule = wrNonZero,
|
||||
blendMode = bmNormal
|
||||
) =
|
||||
let strokeShapes = strokeShapes(parseSomePath(path), strokeWidth)
|
||||
image.fillShapes(strokeShapes, color, windingRule, blendMode)
|
||||
image.fillShapes(strokeShapes, color, wrNonZero, blendMode)
|
||||
|
||||
proc strokePath*(
|
||||
image: Image,
|
||||
|
@ -1326,14 +1331,13 @@ proc strokePath*(
|
|||
color: ColorRGBA,
|
||||
strokeWidth = 1.0,
|
||||
pos: Vec2,
|
||||
windingRule = wrNonZero,
|
||||
blendMode = bmNormal
|
||||
) =
|
||||
var strokeShapes = strokeShapes(parseSomePath(path), strokeWidth)
|
||||
for shape in strokeShapes.mitems:
|
||||
for segment in shape.mitems:
|
||||
segment += pos
|
||||
image.fillShapes(strokeShapes, color, windingRule, blendMode)
|
||||
image.fillShapes(strokeShapes, color, wrNonZero, blendMode)
|
||||
|
||||
proc strokePath*(
|
||||
image: Image,
|
||||
|
@ -1341,49 +1345,45 @@ proc strokePath*(
|
|||
color: ColorRGBA,
|
||||
strokeWidth = 1.0,
|
||||
mat: Mat3,
|
||||
windingRule = wrNonZero,
|
||||
blendMode = bmNormal
|
||||
) =
|
||||
var strokeShapes = strokeShapes(parseSomePath(path), strokeWidth)
|
||||
for shape in strokeShapes.mitems:
|
||||
for segment in shape.mitems:
|
||||
segment = mat * segment
|
||||
image.fillShapes(strokeShapes, color, windingRule, blendMode)
|
||||
image.fillShapes(strokeShapes, color, wrNonZero, blendMode)
|
||||
|
||||
proc strokePath*(
|
||||
mask: Mask,
|
||||
path: SomePath,
|
||||
strokeWidth = 1.0,
|
||||
windingRule = wrNonZero
|
||||
strokeWidth = 1.0
|
||||
) =
|
||||
let strokeShapes = strokeShapes(parseSomePath(path), strokeWidth)
|
||||
mask.fillShapes(strokeShapes, windingRule)
|
||||
mask.fillShapes(strokeShapes, wrNonZero)
|
||||
|
||||
proc strokePath*(
|
||||
mask: Mask,
|
||||
path: SomePath,
|
||||
strokeWidth = 1.0,
|
||||
pos: Vec2,
|
||||
windingRule = wrNonZero
|
||||
pos: Vec2
|
||||
) =
|
||||
var strokeShapes = strokeShapes(parseSomePath(path), strokeWidth)
|
||||
for shape in strokeShapes.mitems:
|
||||
for segment in shape.mitems:
|
||||
segment += pos
|
||||
mask.fillShapes(strokeShapes, windingRule)
|
||||
mask.fillShapes(strokeShapes, wrNonZero)
|
||||
|
||||
proc strokePath*(
|
||||
mask: Mask,
|
||||
path: SomePath,
|
||||
strokeWidth = 1.0,
|
||||
mat: Mat3,
|
||||
windingRule = wrNonZero
|
||||
mat: Mat3
|
||||
) =
|
||||
var strokeShapes = strokeShapes(parseSomePath(path), strokeWidth)
|
||||
for shape in strokeShapes.mitems:
|
||||
for segment in shape.mitems:
|
||||
segment = mat * segment
|
||||
mask.fillShapes(strokeShapes, windingRule)
|
||||
mask.fillShapes(strokeShapes, wrNonZero)
|
||||
|
||||
when defined(release):
|
||||
{.pop.}
|
||||
|
|
Loading…
Reference in a new issue