commit
645590fb1e
4 changed files with 44 additions and 10 deletions
|
@ -186,22 +186,35 @@ proc draw(
|
||||||
if ctx.stroke != ColorRGBA() and ctx.strokeWidth > 0:
|
if ctx.stroke != ColorRGBA() and ctx.strokeWidth > 0:
|
||||||
img.strokePath(path, ctx.stroke, ctx.strokeWidth, ctx.transform)
|
img.strokePath(path, ctx.stroke, ctx.strokeWidth, ctx.transform)
|
||||||
|
|
||||||
of "circle":
|
of "circle", "ellipse":
|
||||||
# Reference for magic constant:
|
# Reference for magic constant:
|
||||||
# https://dl3.pushbulletusercontent.com/a3fLVC8boTzRoxevD1OgCzRzERB9z2EZ/unknown.png
|
# https://dl3.pushbulletusercontent.com/a3fLVC8boTzRoxevD1OgCzRzERB9z2EZ/unknown.png
|
||||||
let
|
let ctx = decodeCtx(ctxStack[^1], node)
|
||||||
ctx = decodeCtx(ctxStack[^1], node)
|
|
||||||
|
var cx, cy: float32 # Default to 0.0 unless set by cx and cy on node
|
||||||
|
if node.attr("cx") != "":
|
||||||
cx = parseFloat(node.attr("cx"))
|
cx = parseFloat(node.attr("cx"))
|
||||||
|
if node.attr("cy") != "":
|
||||||
cy = parseFloat(node.attr("cy"))
|
cy = parseFloat(node.attr("cy"))
|
||||||
r = parseFloat(node.attr("r"))
|
|
||||||
magic = (4.0 * (-1.0 + sqrt(2.0)) / 3) * r
|
var rx, ry: float32
|
||||||
|
if node.tag == "circle":
|
||||||
|
rx = parseFloat(node.attr("r"))
|
||||||
|
ry = rx
|
||||||
|
else:
|
||||||
|
rx = parseFloat(node.attr("rx"))
|
||||||
|
ry = parseFloat(node.attr("ry"))
|
||||||
|
|
||||||
|
let
|
||||||
|
magicX = (4.0 * (-1.0 + sqrt(2.0)) / 3) * rx
|
||||||
|
magicY = (4.0 * (-1.0 + sqrt(2.0)) / 3) * ry
|
||||||
|
|
||||||
let path = newPath()
|
let path = newPath()
|
||||||
path.moveTo(cx + r, cy)
|
path.moveTo(cx + rx, cy)
|
||||||
path.bezierCurveTo(cx + r, cy + magic, cx + magic, cy + r, cx, cy + r)
|
path.bezierCurveTo(cx + rx, cy + magicY, cx + magicX, cy + ry, cx, cy + ry)
|
||||||
path.bezierCurveTo(cx - magic, cy + r, cx - r, cy + magic, cx - r, cy)
|
path.bezierCurveTo(cx - magicX, cy + ry, cx - rx, cy + magicY, cx - rx, cy)
|
||||||
path.bezierCurveTo(cx - r, cy - magic, cx - magic, cy - r, cx, cy - r)
|
path.bezierCurveTo(cx - rx, cy - magicY, cx - magicX, cy - ry, cx, cy - ry)
|
||||||
path.bezierCurveTo(cx + magic, cy - r, cx + r, cy - magic, cx + r, cy)
|
path.bezierCurveTo(cx + magicX, cy - ry, cx + rx, cy - magicY, cx + rx, cy)
|
||||||
path.closePath()
|
path.closePath()
|
||||||
|
|
||||||
let d = $path
|
let d = $path
|
||||||
|
|
BIN
tests/images/svg/ellipse01.png
Normal file
BIN
tests/images/svg/ellipse01.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 24 KiB |
20
tests/images/svg/ellipse01.svg
Normal file
20
tests/images/svg/ellipse01.svg
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
<?xml version="1.0" standalone="no"?>
|
||||||
|
<svg width="12cm" height="4cm" viewBox="0 0 1200 400"
|
||||||
|
xmlns="http://www.w3.org/2000/svg" version="1.1">
|
||||||
|
<desc>Example ellipse01 - examples of ellipses</desc>
|
||||||
|
|
||||||
|
<!-- Show outline of viewport using 'rect' element -->
|
||||||
|
<rect x="1" y="1" width="1198" height="398"
|
||||||
|
fill="none" stroke="blue" stroke-width="2" />
|
||||||
|
|
||||||
|
<g transform="translate(300 200)">
|
||||||
|
<ellipse rx="250" ry="100"
|
||||||
|
fill="red" />
|
||||||
|
</g>
|
||||||
|
|
||||||
|
<ellipse transform="translate(900 200) rotate(-30)"
|
||||||
|
rx="250" ry="100"
|
||||||
|
fill="none" stroke="blue" stroke-width="20" />
|
||||||
|
|
||||||
|
</svg>
|
||||||
|
|
After Width: | Height: | Size: 609 B |
|
@ -7,6 +7,7 @@ const files = [
|
||||||
"rect01",
|
"rect01",
|
||||||
"rect02",
|
"rect02",
|
||||||
"circle01",
|
"circle01",
|
||||||
|
"ellipse01",
|
||||||
"triangle01",
|
"triangle01",
|
||||||
"quad01",
|
"quad01",
|
||||||
"Ghostscript_Tiger"
|
"Ghostscript_Tiger"
|
||||||
|
|
Loading…
Reference in a new issue