diff options
author | Richard Stöckl <richard.stoeckl@aon.at> | 2019-08-28 17:10:23 +0200 |
---|---|---|
committer | Richard Stöckl <richard.stoeckl@aon.at> | 2019-08-28 17:10:23 +0200 |
commit | 936c634e15265fb3c7239e07c71fc3c6ac027d98 (patch) | |
tree | 1c26b83fe3bd9ec45f29236ff9f0c9e1f46981ea | |
parent | 7b84d27f314deae8fab88961e3b835cea57f13cd (diff) |
added SVG support for quadratic curves
-rw-r--r-- | svgbasic.go | 14 | ||||
-rw-r--r-- | svgwrite.go | 5 |
2 files changed, 18 insertions, 1 deletions
diff --git a/svgbasic.go b/svgbasic.go index 6900afa..0eea754 100644 --- a/svgbasic.go +++ b/svgbasic.go @@ -33,7 +33,8 @@ func init() { "C", " C ", "c", " c ", "M", " M ", "m", " m ", "H", " H ", "h", " h ", - "V", " V ", "v", " v ") + "V", " V ", "v", " v ", + "Q", " Q ", "q", " q ", ) } // SVGBasicSegmentType describes a single curve or position segment @@ -81,6 +82,15 @@ func absolutizePath(segs []SVGBasicSegmentType) { segPtr.Cmd = 'C' x = segPtr.Arg[4] y = segPtr.Arg[5] + case 'Q': + x = seg.Arg[2] + y = seg.Arg[3] + case 'q': + adjust(0, x, y) + adjust(2, x, y) + segPtr.Cmd = 'Q' + x = segPtr.Arg[2] + y = segPtr.Arg[3] case 'H': x = seg.Arg[0] case 'h': @@ -146,6 +156,8 @@ func pathParse(pathStr string) (segs []SVGBasicSegmentType, err error) { setup(1) case 'L', 'l': // Absolute/relative lineto: x, y setup(2) + case 'Q', 'q': // Absolute/relative quadratic curve: x0, y0, x1, y1 + setup(4) case 'V', 'v': // Absolute/relative vertical line to: x setup(1) case 'Z', 'z': // closepath instruction (takes no arguments) diff --git a/svgwrite.go b/svgwrite.go index a612539..d438393 100644 --- a/svgwrite.go +++ b/svgwrite.go @@ -59,6 +59,11 @@ func (f *Fpdf) SVGBasicWrite(sb *SVGBasicType, scale float64) { newX, newY = val(4) f.CurveCubic(x, y, cx0, cy0, newX, newY, cx1, cy1, "D") x, y = newX, newY + case 'Q': + cx0, cy0 = val(0) + newX, newY = val(2) + f.Curve(x, y, cx0, cy0, newX, newY, "D") + x, y = newX, newY case 'H': newX = xval(0) f.Line(x, y, newX, y) |