Skip to content

Commit

Permalink
Fix icon.OptimizeSVG
Browse files Browse the repository at this point in the history
  • Loading branch information
k1LoW committed Jan 12, 2021
1 parent a194f40 commit ff843df
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion icon/fetcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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, "<?xml?>") {
Expand Down

0 comments on commit ff843df

Please sign in to comment.