Merge pull request #116 from guzba/master
support rect rx and ry for svg
This commit is contained in:
commit
cc79aad899
3 changed files with 40 additions and 1 deletions
|
@ -169,7 +169,31 @@ proc draw(
|
||||||
width = parseFloat(node.attr("width"))
|
width = parseFloat(node.attr("width"))
|
||||||
height = parseFloat(node.attr("height"))
|
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
|
var path: Path
|
||||||
|
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)
|
path.rect(x, y, width, height)
|
||||||
|
|
||||||
if ctx.fill != ColorRGBA():
|
if ctx.fill != ColorRGBA():
|
||||||
|
|
|
@ -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) =
|
proc arcTo*(path: var Path, x1, y1, x2, y2, radius: float32) =
|
||||||
path.arcTo(vec2(x1, y1), vec2(x2, y2), radius)
|
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) =
|
proc rect*(path: var Path, x, y, w, h: float32, clockwise = true) =
|
||||||
if clockwise:
|
if clockwise:
|
||||||
path.moveTo(x, y)
|
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