diff --git a/src/pixie/fileformats/svg.nim b/src/pixie/fileformats/svg.nim index 0ad3dd1..beed00d 100644 --- a/src/pixie/fileformats/svg.nim +++ b/src/pixie/fileformats/svg.nim @@ -221,6 +221,18 @@ proc decodeCtx(inherited: Ctx, node: XmlNode): Ctx = else: failInvalidTransform(transform) +proc fill(img: Image, ctx: Ctx, path: Path) {.inline.} = + img.fillPath(path, ctx.fill, ctx.transform, ctx.fillRule) + +proc stroke(img: Image, ctx: Ctx, path: Path) {.inline.} = + img.strokePath( + path, + ctx.stroke, + ctx.transform, + ctx.strokeWidth, + miterLimit = ctx.strokeMiterLimit + ) + proc draw(img: Image, node: XmlNode, ctxStack: var seq[Ctx]) = if node.kind != xnElement: # Skip @@ -243,15 +255,9 @@ proc draw(img: Image, node: XmlNode, ctxStack: var seq[Ctx]) = ctx = decodeCtx(ctxStack[^1], node) path = parsePath(d) if ctx.fill != ColorRGBX(): - img.fillPath(path, ctx.fill, ctx.transform, ctx.fillRule) + img.fill(ctx, path) if ctx.shouldStroke: - img.strokePath( - path, - ctx.stroke, - ctx.transform, - ctx.strokeWidth, - miterLimit = ctx.strokeMiterLimit - ) + img.stroke(ctx, path) of "line": let @@ -267,15 +273,9 @@ proc draw(img: Image, node: XmlNode, ctxStack: var seq[Ctx]) = path.closePath() if ctx.fill != ColorRGBX(): - img.fillPath(path, ctx.fill, ctx.transform) + img.fill(ctx, path) if ctx.shouldStroke: - img.strokePath( - path, - ctx.stroke, - ctx.transform, - ctx.strokeWidth, - miterLimit = ctx.strokeMiterLimit - ) + img.stroke(ctx, path) of "polyline", "polygon": let @@ -309,15 +309,9 @@ proc draw(img: Image, node: XmlNode, ctxStack: var seq[Ctx]) = path.closePath() if ctx.fill != ColorRGBX(): - img.fillPath(path, ctx.fill, ctx.transform) + img.fill(ctx, path) if ctx.shouldStroke: - img.strokePath( - path, - ctx.stroke, - ctx.transform, - ctx.strokeWidth, - miterLimit = ctx.strokeMiterLimit - ) + img.stroke(ctx, path) of "rect": let @@ -353,15 +347,9 @@ proc draw(img: Image, node: XmlNode, ctxStack: var seq[Ctx]) = path.rect(x, y, width, height) if ctx.fill != ColorRGBX(): - img.fillPath(path, ctx.fill, ctx.transform) + img.fill(ctx, path) if ctx.shouldStroke: - img.strokePath( - path, - ctx.stroke, - ctx.transform, - ctx.strokeWidth, - miterLimit = ctx.strokeMiterLimit - ) + img.stroke(ctx, path) of "circle", "ellipse": let @@ -381,15 +369,9 @@ proc draw(img: Image, node: XmlNode, ctxStack: var seq[Ctx]) = path.ellipse(cx, cy, rx, ry) if ctx.fill != ColorRGBX(): - img.fillPath(path, ctx.fill, ctx.transform) + img.fill(ctx, path) if ctx.shouldStroke: - img.strokePath( - path, - ctx.stroke, - ctx.transform, - ctx.strokeWidth, - miterLimit = ctx.strokeMiterLimit - ) + img.stroke(ctx, path) else: raise newException(PixieError, "Unsupported SVG tag: " & node.tag & ".") diff --git a/tests/images/svg/flat-color-icons.png b/tests/images/svg/flat-color-icons.png index 661bd07..1af1b33 100644 Binary files a/tests/images/svg/flat-color-icons.png and b/tests/images/svg/flat-color-icons.png differ diff --git a/tests/images/svg/ionicons.png b/tests/images/svg/ionicons.png index 2b2838a..7d74d34 100644 Binary files a/tests/images/svg/ionicons.png and b/tests/images/svg/ionicons.png differ