From 7b84d27f314deae8fab88961e3b835cea57f13cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Richard=20St=C3=B6ckl?= Date: Wed, 28 Aug 2019 16:46:46 +0200 Subject: added SVG support for horizontal and vertical lines --- svgbasic.go | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) (limited to 'svgbasic.go') diff --git a/svgbasic.go b/svgbasic.go index cc35073..6900afa 100644 --- a/svgbasic.go +++ b/svgbasic.go @@ -31,7 +31,9 @@ func init() { pathCmdSub = strings.NewReplacer(",", " ", "L", " L ", "l", " l ", "C", " C ", "c", " c ", - "M", " M ", "m", " m ") + "M", " M ", "m", " m ", + "H", " H ", "h", " h ", + "V", " V ", "v", " v ") } // SVGBasicSegmentType describes a single curve or position segment @@ -79,6 +81,19 @@ func absolutizePath(segs []SVGBasicSegmentType) { segPtr.Cmd = 'C' x = segPtr.Arg[4] y = segPtr.Arg[5] + case 'H': + x = seg.Arg[0] + case 'h': + segPtr.Arg[0] += x + segPtr.Cmd = 'H' + x += seg.Arg[0] + case 'V': + y = seg.Arg[0] + case 'v': + segPtr.Arg[0] += y + segPtr.Cmd = 'V' + y += seg.Arg[0] + } } } @@ -127,8 +142,12 @@ func pathParse(pathStr string) (segs []SVGBasicSegmentType, err error) { setup(2) case 'C', 'c': // Absolute/relative Bézier curve: cx0, cy0, cx1, cy1, x1, y1 setup(6) + case 'H', 'h': // Absolute/relative horizontal line to: x + setup(1) case 'L', 'l': // Absolute/relative lineto: x, y setup(2) + case 'V', 'v': // Absolute/relative vertical line to: x + setup(1) case 'Z', 'z': // closepath instruction (takes no arguments) break default: -- cgit v1.2.1-24-ge1ad From 936c634e15265fb3c7239e07c71fc3c6ac027d98 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Richard=20St=C3=B6ckl?= Date: Wed, 28 Aug 2019 17:10:23 +0200 Subject: added SVG support for quadratic curves --- svgbasic.go | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'svgbasic.go') 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) -- cgit v1.2.1-24-ge1ad From 761de3879c5b4b3e0b7d2d9d30ced3aa56f8a39d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Richard=20St=C3=B6ckl?= Date: Wed, 28 Aug 2019 19:05:11 +0200 Subject: added closepath support in SVG --- svgbasic.go | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'svgbasic.go') diff --git a/svgbasic.go b/svgbasic.go index 0eea754..51a93fe 100644 --- a/svgbasic.go +++ b/svgbasic.go @@ -34,7 +34,8 @@ func init() { "M", " M ", "m", " m ", "H", " H ", "h", " h ", "V", " V ", "v", " v ", - "Q", " Q ", "q", " q ", ) + "Q", " Q ", "q", " q ", + "Z", " Z ", "z", " z ") } // SVGBasicSegmentType describes a single curve or position segment @@ -103,7 +104,8 @@ func absolutizePath(segs []SVGBasicSegmentType) { segPtr.Arg[0] += y segPtr.Cmd = 'V' y += seg.Arg[0] - + case 'z': + segPtr.Cmd = 'Z' } } } @@ -161,7 +163,7 @@ func pathParse(pathStr string) (segs []SVGBasicSegmentType, err error) { case 'V', 'v': // Absolute/relative vertical line to: x setup(1) case 'Z', 'z': // closepath instruction (takes no arguments) - break + segs = append(segs, seg) default: err = fmt.Errorf("expecting SVG path command at position %d, got %s", j, str) } -- cgit v1.2.1-24-ge1ad From dd51a599c9b1e52e1479d8a6f6e7d802431cf8c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Richard=20St=C3=B6ckl?= Date: Wed, 28 Aug 2019 19:07:43 +0200 Subject: updated SVG comments --- svgbasic.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'svgbasic.go') diff --git a/svgbasic.go b/svgbasic.go index 51a93fe..f75d69f 100644 --- a/svgbasic.go +++ b/svgbasic.go @@ -160,7 +160,7 @@ func pathParse(pathStr string) (segs []SVGBasicSegmentType, err error) { setup(2) case 'Q', 'q': // Absolute/relative quadratic curve: x0, y0, x1, y1 setup(4) - case 'V', 'v': // Absolute/relative vertical line to: x + case 'V', 'v': // Absolute/relative vertical line to: y setup(1) case 'Z', 'z': // closepath instruction (takes no arguments) segs = append(segs, seg) @@ -201,7 +201,8 @@ type SVGBasicType struct { // information generated by jSignature, is supported. The returned path data // includes only the commands 'M' (absolute moveto: x, y), 'L' (absolute // lineto: x, y), 'C' (absolute cubic Bézier curve: cx0, cy0, cx1, cy1, -// x1,y1) and 'Z' (closepath). +// x1,y1), 'Q' (absolute quadratic Bézier curve: x0, y0, x1, y1) and 'Z' +// (closepath). func SVGBasicParse(buf []byte) (sig SVGBasicType, err error) { type pathType struct { D string `xml:"d,attr"` -- cgit v1.2.1-24-ge1ad