Merge pull request #116 from guzba/master

support rect rx and ry for svg
This commit is contained in:
treeform 2021-02-19 09:04:40 -08:00 committed by GitHub
commit cc79aad899
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 40 additions and 1 deletions

View file

@ -169,8 +169,32 @@ proc draw(
width = parseFloat(node.attr("width"))
height = parseFloat(node.attr("height"))
var rx, ry: float32
if node.attr("rx").len > 0:
rx = max(parseFloat(node.attr("rx")), 0)
if node.attr("ry").len > 0:
ry = max(parseFloat(node.attr("ry")), 0)
var path: Path
path.rect(x, y, width, height)
if rx > 0 or ry > 0:
if rx == 0:
rx = ry
elif ry == 0:
ry = rx
rx = min(rx, width / 2)
ry = min(ry, height / 2)
path.moveTo(x + rx, y)
path.lineTo(x + width - rx, y)
path.ellipticalArcTo(rx, ry, 0, false, true, x + width, y + ry)
path.lineTo(x + width, y + height - ry)
path.ellipticalArcTo(rx, ry, 0, false, true, x + width - rx, y + height)
path.lineTo(x + rx, y + height)
path.ellipticalArcTo(rx, ry, 0, false, true, x, y + height - ry)
path.lineTo(x, y + ry)
path.ellipticalArcTo(rx, ry, 0, false, true, x + rx, y)
else:
path.rect(x, y, width, height)
if ctx.fill != ColorRGBA():
img.fillPath(path, ctx.fill, ctx.transform)

View file

@ -353,6 +353,21 @@ proc arcTo*(path: var Path, ctrl1, ctrl2: Vec2, radius: float32) {.inline.} =
proc arcTo*(path: var Path, x1, y1, x2, y2, radius: float32) =
path.arcTo(vec2(x1, y1), vec2(x2, y2), radius)
proc ellipticalArcTo*(
path: var Path,
rx, ry: float32,
xAxisRotation: float32,
largeArcFlag, sweepFlag: bool,
x, y: float32
) =
path.commands.add(PathCommand(
kind: Arc,
numbers: @[
rx, ry, xAxisRotation, largeArcFlag.float32, sweepFlag.float32, x, y
]
))
path.at = vec2(x, y)
proc rect*(path: var Path, x, y, w, h: float32, clockwise = true) =
if clockwise:
path.moveTo(x, y)

Binary file not shown.

Before

Width:  |  Height:  |  Size: 27 KiB

After

Width:  |  Height:  |  Size: 27 KiB