From ff843df0bddcf845641c8b106d2a520c21a1cc9b Mon Sep 17 00:00:00 2001 From: k1LoW Date: Tue, 12 Jan 2021 10:08:07 +0900 Subject: [PATCH] Fix icon.OptimizeSVG --- icon/fetcher.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/icon/fetcher.go b/icon/fetcher.go index bfe68c87..dac69a1f 100644 --- a/icon/fetcher.go +++ b/icon/fetcher.go @@ -19,7 +19,7 @@ import ( "github.com/nfnt/resize" ) -var sizeRe = regexp.MustCompile("^A([0-9.]+)") +var sizeRe = regexp.MustCompile(`\A([0-9.]+)`) type Fetcher interface { Fetch(iconPath, prefix string) error @@ -117,6 +117,13 @@ func OptimizeSVG(b []byte, width, height float64) ([]byte, error) { }, }, attrs...) + if !hasViewBox { + s.Attr = append(s.Attr, xml.Attr{ + Name: xml.Name{Local: "viewBox"}, + Value: fmt.Sprintf("0 0 %g %g", cw, ch), + }) + } + // If there are no line breaks, Graphviz will not recognize it as SVG. docstr := strings.Replace(strings.Replace(imgdoc.OutputXML(false), "?>", "?>\n", 1), "-->", "-->\n", 1) if strings.Contains(docstr, "") {