support rect rx and ry for svg
This commit is contained in:
parent
056948d50f
commit
b4edd635d5
3 changed files with 40 additions and 1 deletions
|
@ -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)
|
||||
|
|
|
@ -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 |
Loading…
Reference in a new issue