summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRichard Stöckl <richard.stoeckl@aon.at>2019-08-28 19:05:11 +0200
committerRichard Stöckl <richard.stoeckl@aon.at>2019-08-28 19:05:11 +0200
commit761de3879c5b4b3e0b7d2d9d30ced3aa56f8a39d (patch)
treea5610392f59f6d5a6b66a74bd7da3402f998526c
parent936c634e15265fb3c7239e07c71fc3c6ac027d98 (diff)
added closepath support in SVG
-rw-r--r--svgbasic.go8
-rw-r--r--svgwrite.go4
2 files changed, 8 insertions, 4 deletions
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)
}
diff --git a/svgwrite.go b/svgwrite.go
index d438393..7045199 100644
--- a/svgwrite.go
+++ b/svgwrite.go
@@ -29,6 +29,7 @@ func (f *Fpdf) SVGBasicWrite(sb *SVGBasicType, scale float64) {
var cx0, cy0, cx1, cy1 float64
var path []SVGBasicSegmentType
var seg SVGBasicSegmentType
+ var startX, startY float64
sval := func(origin float64, arg int) float64 {
return origin + scale*seg.Arg[arg]
}
@@ -48,6 +49,7 @@ func (f *Fpdf) SVGBasicWrite(sb *SVGBasicType, scale float64) {
switch seg.Cmd {
case 'M':
x, y = val(0)
+ startX, startY = x, y
f.SetXY(x, y)
case 'L':
newX, newY = val(0)
@@ -73,7 +75,7 @@ func (f *Fpdf) SVGBasicWrite(sb *SVGBasicType, scale float64) {
f.Line(x, y, x, newY)
y = newY
case 'Z':
- f.Line(x, y, originX, originY)
+ f.Line(x, y, startX, startY)
default:
f.SetErrorf("Unexpected path command '%c'", seg.Cmd)
}