From 950f332ccae35cbc9a295052b0d68b8cb975d506 Mon Sep 17 00:00:00 2001 From: Michael Stapelberg Date: Sun, 22 Nov 2020 17:13:22 +0100 Subject: [PATCH] SVG: use a single path element instead of many rects This avoids small gaps between QR code squares. I learnt about this approach from https://github.com/papnkukn/qrcode-svg --- qrcodegeneratorsvg.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/qrcodegeneratorsvg.go b/qrcodegeneratorsvg.go index 3202f54..626a357 100644 --- a/qrcodegeneratorsvg.go +++ b/qrcodegeneratorsvg.go @@ -16,6 +16,7 @@ package qrbill import ( "bytes" + "fmt" svg "github.com/ajstarks/svgo" "github.com/makiuchi-d/gozxing" @@ -60,14 +61,17 @@ func renderResultSVG(code *encoder.QRCode, width, height, quietZone int) ([]byte s.Group(`shape-rendering="crispEdges"`) + pathdata := "" for inputY, outputY := 0, topPadding; inputY < inputHeight; inputY, outputY = inputY+1, outputY+multiple { // Write the contents of this row of the barcode for inputX, outputX := 0, leftPadding; inputX < inputWidth; inputX, outputX = inputX+1, outputX+multiple { if input.Get(inputX, inputY) == 1 { - s.Rect(outputX, outputY, multiple, multiple, "fill:black;stroke:none;") + pathdata += fmt.Sprintf("M%d,%d V%d H%d V%d H%d Z ", + outputX, outputY, outputY+multiple, outputX+multiple, outputY, outputX) } } } + s.Path(pathdata, "fill:black;stroke:none;") s.Gend()