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,
|
image: Image,
|
||||||
segment: Segment,
|
segment: Segment,
|
||||||
color: ColorRGBA,
|
color: ColorRGBA,
|
||||||
strokeWidth = 1.0,
|
strokeWidth = 1.0
|
||||||
blendMode = bmNormal
|
|
||||||
) =
|
) =
|
||||||
var path: Path
|
var path: Path
|
||||||
path.moveTo(segment.at)
|
path.moveTo(segment.at)
|
||||||
path.lineTo(segment.to)
|
path.lineTo(segment.to)
|
||||||
image.strokePath(path, color, strokeWidth, wrNonZero, blendMode)
|
image.strokePath(path, color, strokeWidth)
|
||||||
|
|
||||||
proc strokeSegment*(mask: Mask, segment: Segment, strokeWidth: float32) =
|
proc strokeSegment*(mask: Mask, segment: Segment, strokeWidth: float32) =
|
||||||
var path: Path
|
var path: Path
|
||||||
|
|
|
@ -8,6 +8,8 @@ const svgSignature* = "<?xml"
|
||||||
type Ctx = object
|
type Ctx = object
|
||||||
fill, stroke: ColorRGBA
|
fill, stroke: ColorRGBA
|
||||||
strokeWidth: float32
|
strokeWidth: float32
|
||||||
|
strokeLineCap: LineCap
|
||||||
|
strokeLineJoin: LineJoin
|
||||||
transform: Mat3
|
transform: Mat3
|
||||||
|
|
||||||
template failInvalid() =
|
template failInvalid() =
|
||||||
|
@ -25,6 +27,8 @@ proc decodeCtx(inherited: Ctx, node: XmlNode): Ctx =
|
||||||
fill = node.attr("fill")
|
fill = node.attr("fill")
|
||||||
stroke = node.attr("stroke")
|
stroke = node.attr("stroke")
|
||||||
strokeWidth = node.attr("stroke-width")
|
strokeWidth = node.attr("stroke-width")
|
||||||
|
strokeLineCap = node.attr("stroke-linecap")
|
||||||
|
strokeLineJoin = node.attr("stroke-linejoin")
|
||||||
transform = node.attr("transform")
|
transform = node.attr("transform")
|
||||||
|
|
||||||
if fill == "":
|
if fill == "":
|
||||||
|
@ -46,6 +50,40 @@ proc decodeCtx(inherited: Ctx, node: XmlNode): Ctx =
|
||||||
else:
|
else:
|
||||||
result.strokeWidth = parseFloat(strokeWidth)
|
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 == "":
|
if transform == "":
|
||||||
discard # Inherit
|
discard # Inherit
|
||||||
else:
|
else:
|
||||||
|
|
|
@ -8,6 +8,12 @@ type
|
||||||
wrNonZero
|
wrNonZero
|
||||||
wrEvenOdd
|
wrEvenOdd
|
||||||
|
|
||||||
|
LineCap* = enum
|
||||||
|
lcButt, lcRound, lcSquare
|
||||||
|
|
||||||
|
LineJoin* = enum
|
||||||
|
ljMiter, ljRound, ljBevel
|
||||||
|
|
||||||
PathCommandKind* = enum
|
PathCommandKind* = enum
|
||||||
## Type of path commands
|
## Type of path commands
|
||||||
Close,
|
Close,
|
||||||
|
@ -1314,11 +1320,10 @@ proc strokePath*(
|
||||||
path: SomePath,
|
path: SomePath,
|
||||||
color: ColorRGBA,
|
color: ColorRGBA,
|
||||||
strokeWidth = 1.0,
|
strokeWidth = 1.0,
|
||||||
windingRule = wrNonZero,
|
|
||||||
blendMode = bmNormal
|
blendMode = bmNormal
|
||||||
) =
|
) =
|
||||||
let strokeShapes = strokeShapes(parseSomePath(path), strokeWidth)
|
let strokeShapes = strokeShapes(parseSomePath(path), strokeWidth)
|
||||||
image.fillShapes(strokeShapes, color, windingRule, blendMode)
|
image.fillShapes(strokeShapes, color, wrNonZero, blendMode)
|
||||||
|
|
||||||
proc strokePath*(
|
proc strokePath*(
|
||||||
image: Image,
|
image: Image,
|
||||||
|
@ -1326,14 +1331,13 @@ proc strokePath*(
|
||||||
color: ColorRGBA,
|
color: ColorRGBA,
|
||||||
strokeWidth = 1.0,
|
strokeWidth = 1.0,
|
||||||
pos: Vec2,
|
pos: Vec2,
|
||||||
windingRule = wrNonZero,
|
|
||||||
blendMode = bmNormal
|
blendMode = bmNormal
|
||||||
) =
|
) =
|
||||||
var strokeShapes = strokeShapes(parseSomePath(path), strokeWidth)
|
var strokeShapes = strokeShapes(parseSomePath(path), strokeWidth)
|
||||||
for shape in strokeShapes.mitems:
|
for shape in strokeShapes.mitems:
|
||||||
for segment in shape.mitems:
|
for segment in shape.mitems:
|
||||||
segment += pos
|
segment += pos
|
||||||
image.fillShapes(strokeShapes, color, windingRule, blendMode)
|
image.fillShapes(strokeShapes, color, wrNonZero, blendMode)
|
||||||
|
|
||||||
proc strokePath*(
|
proc strokePath*(
|
||||||
image: Image,
|
image: Image,
|
||||||
|
@ -1341,49 +1345,45 @@ proc strokePath*(
|
||||||
color: ColorRGBA,
|
color: ColorRGBA,
|
||||||
strokeWidth = 1.0,
|
strokeWidth = 1.0,
|
||||||
mat: Mat3,
|
mat: Mat3,
|
||||||
windingRule = wrNonZero,
|
|
||||||
blendMode = bmNormal
|
blendMode = bmNormal
|
||||||
) =
|
) =
|
||||||
var strokeShapes = strokeShapes(parseSomePath(path), strokeWidth)
|
var strokeShapes = strokeShapes(parseSomePath(path), strokeWidth)
|
||||||
for shape in strokeShapes.mitems:
|
for shape in strokeShapes.mitems:
|
||||||
for segment in shape.mitems:
|
for segment in shape.mitems:
|
||||||
segment = mat * segment
|
segment = mat * segment
|
||||||
image.fillShapes(strokeShapes, color, windingRule, blendMode)
|
image.fillShapes(strokeShapes, color, wrNonZero, blendMode)
|
||||||
|
|
||||||
proc strokePath*(
|
proc strokePath*(
|
||||||
mask: Mask,
|
mask: Mask,
|
||||||
path: SomePath,
|
path: SomePath,
|
||||||
strokeWidth = 1.0,
|
strokeWidth = 1.0
|
||||||
windingRule = wrNonZero
|
|
||||||
) =
|
) =
|
||||||
let strokeShapes = strokeShapes(parseSomePath(path), strokeWidth)
|
let strokeShapes = strokeShapes(parseSomePath(path), strokeWidth)
|
||||||
mask.fillShapes(strokeShapes, windingRule)
|
mask.fillShapes(strokeShapes, wrNonZero)
|
||||||
|
|
||||||
proc strokePath*(
|
proc strokePath*(
|
||||||
mask: Mask,
|
mask: Mask,
|
||||||
path: SomePath,
|
path: SomePath,
|
||||||
strokeWidth = 1.0,
|
strokeWidth = 1.0,
|
||||||
pos: Vec2,
|
pos: Vec2
|
||||||
windingRule = wrNonZero
|
|
||||||
) =
|
) =
|
||||||
var strokeShapes = strokeShapes(parseSomePath(path), strokeWidth)
|
var strokeShapes = strokeShapes(parseSomePath(path), strokeWidth)
|
||||||
for shape in strokeShapes.mitems:
|
for shape in strokeShapes.mitems:
|
||||||
for segment in shape.mitems:
|
for segment in shape.mitems:
|
||||||
segment += pos
|
segment += pos
|
||||||
mask.fillShapes(strokeShapes, windingRule)
|
mask.fillShapes(strokeShapes, wrNonZero)
|
||||||
|
|
||||||
proc strokePath*(
|
proc strokePath*(
|
||||||
mask: Mask,
|
mask: Mask,
|
||||||
path: SomePath,
|
path: SomePath,
|
||||||
strokeWidth = 1.0,
|
strokeWidth = 1.0,
|
||||||
mat: Mat3,
|
mat: Mat3
|
||||||
windingRule = wrNonZero
|
|
||||||
) =
|
) =
|
||||||
var strokeShapes = strokeShapes(parseSomePath(path), strokeWidth)
|
var strokeShapes = strokeShapes(parseSomePath(path), strokeWidth)
|
||||||
for shape in strokeShapes.mitems:
|
for shape in strokeShapes.mitems:
|
||||||
for segment in shape.mitems:
|
for segment in shape.mitems:
|
||||||
segment = mat * segment
|
segment = mat * segment
|
||||||
mask.fillShapes(strokeShapes, windingRule)
|
mask.fillShapes(strokeShapes, wrNonZero)
|
||||||
|
|
||||||
when defined(release):
|
when defined(release):
|
||||||
{.pop.}
|
{.pop.}
|
||||||
|
|
Loading…
Reference in a new issue