From f0fc8388f6baa9b9e425e64bcf56dba615ece2c8 Mon Sep 17 00:00:00 2001 From: Joe Westcott Date: Mon, 4 Feb 2019 14:21:12 +0000 Subject: SVG closepath support --- svgbasic.go | 6 ++++-- svgwrite.go | 2 ++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/svgbasic.go b/svgbasic.go index cb8e91e..cc35073 100644 --- a/svgbasic.go +++ b/svgbasic.go @@ -129,6 +129,8 @@ func pathParse(pathStr string) (segs []SVGBasicSegmentType, err error) { setup(6) case 'L', 'l': // Absolute/relative lineto: x, y setup(2) + case 'Z', 'z': // closepath instruction (takes no arguments) + break default: err = fmt.Errorf("expecting SVG path command at position %d, got %s", j, str) } @@ -165,8 +167,8 @@ type SVGBasicType struct { // descriptor. Only a small subset of the SVG standard, in particular the path // information generated by jSignature, is supported. The returned path data // includes only the commands 'M' (absolute moveto: x, y), 'L' (absolute -// lineto: x, y), and 'C' (absolute cubic Bézier curve: cx0, cy0, cx1, cy1, -// x1,y1). +// lineto: x, y), 'C' (absolute cubic Bézier curve: cx0, cy0, cx1, cy1, +// x1,y1) and 'Z' (closepath). func SVGBasicParse(buf []byte) (sig SVGBasicType, err error) { type pathType struct { D string `xml:"d,attr"` diff --git a/svgwrite.go b/svgwrite.go index 04f6cb3..7e455fb 100644 --- a/svgwrite.go +++ b/svgwrite.go @@ -50,6 +50,8 @@ 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 'Z': + f.Line(x, y, originX, originY) default: f.SetErrorf("Unexpected path command '%c'", seg.Cmd) } -- cgit v1.2.1-24-ge1ad