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 --- svgwrite.go | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) (limited to 'svgwrite.go') diff --git a/svgwrite.go b/svgwrite.go index 7e455fb..a612539 100644 --- a/svgwrite.go +++ b/svgwrite.go @@ -29,8 +29,17 @@ func (f *Fpdf) SVGBasicWrite(sb *SVGBasicType, scale float64) { var cx0, cy0, cx1, cy1 float64 var path []SVGBasicSegmentType var seg SVGBasicSegmentType + sval := func(origin float64, arg int) float64 { + return origin + scale*seg.Arg[arg] + } + xval := func(arg int) float64 { + return sval(originX, arg) + } + yval := func(arg int) float64 { + return sval(originY, arg) + } val := func(arg int) (float64, float64) { - return originX + scale*seg.Arg[arg], originY + scale*seg.Arg[arg+1] + return xval(arg), yval(arg + 1) } for j := 0; j < len(sb.Segments) && f.Ok(); j++ { path = sb.Segments[j] @@ -50,6 +59,14 @@ 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 'H': + newX = xval(0) + f.Line(x, y, newX, y) + x = newX + case 'V': + newY = yval(0) + f.Line(x, y, x, newY) + y = newY case 'Z': f.Line(x, y, originX, originY) 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 --- svgwrite.go | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'svgwrite.go') diff --git a/svgwrite.go b/svgwrite.go index a612539..d438393 100644 --- a/svgwrite.go +++ b/svgwrite.go @@ -59,6 +59,11 @@ 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 'Q': + cx0, cy0 = val(0) + newX, newY = val(2) + f.Curve(x, y, cx0, cy0, newX, newY, "D") + x, y = newX, newY case 'H': newX = xval(0) f.Line(x, y, newX, y) -- 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 --- svgwrite.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'svgwrite.go') 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) } -- cgit v1.2.1-24-ge1ad From a915207ea990b8fe8a380595d6eeeeb26022604b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Richard=20St=C3=B6ckl?= Date: Wed, 28 Aug 2019 20:38:00 +0200 Subject: set new coordinates on z instruction --- svgwrite.go | 1 + 1 file changed, 1 insertion(+) (limited to 'svgwrite.go') diff --git a/svgwrite.go b/svgwrite.go index 7045199..398a6da 100644 --- a/svgwrite.go +++ b/svgwrite.go @@ -76,6 +76,7 @@ func (f *Fpdf) SVGBasicWrite(sb *SVGBasicType, scale float64) { y = newY case 'Z': f.Line(x, y, startX, startY) + x, y = startX, startY default: f.SetErrorf("Unexpected path command '%c'", seg.Cmd) } -- cgit v1.2.1-24-ge1ad