summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoe Westcott <joewestcott@users.noreply.github.com>2019-02-04 14:21:12 +0000
committerJoe Westcott <joewestcott@users.noreply.github.com>2019-02-04 14:21:12 +0000
commitf0fc8388f6baa9b9e425e64bcf56dba615ece2c8 (patch)
tree84ad731a86c53571bf507009ad9437a5aab00d14
parent82f8581de0da69bda7696183c7e9d890be24fa63 (diff)
SVG closepath support
-rw-r--r--svgbasic.go6
-rw-r--r--svgwrite.go2
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)
}