diff options
Diffstat (limited to 'svgbasic.go')
-rw-r--r-- | svgbasic.go | 40 |
1 files changed, 37 insertions, 3 deletions
diff --git a/svgbasic.go b/svgbasic.go index cc35073..f75d69f 100644 --- a/svgbasic.go +++ b/svgbasic.go @@ -31,7 +31,11 @@ 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 ", + "Q", " Q ", "q", " q ", + "Z", " Z ", "z", " z ") } // SVGBasicSegmentType describes a single curve or position segment @@ -79,6 +83,29 @@ 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': + 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] + case 'z': + segPtr.Cmd = 'Z' } } } @@ -127,10 +154,16 @@ 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 'Q', 'q': // Absolute/relative quadratic curve: x0, y0, x1, y1 + setup(4) + case 'V', 'v': // Absolute/relative vertical line to: y + 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) } @@ -168,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"` |