Skip to content

Commit

Permalink
Merge pull request #154 from MattMasters/master
Browse files Browse the repository at this point in the history
Added ViewBox field to Svg
  • Loading branch information
llgcode authored Aug 10, 2019
2 parents e46834f + 524ae66 commit 49fffa2
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
1 change: 1 addition & 0 deletions draw2dsvg/svg.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ type Svg struct {
Xmlns string `xml:"xmlns,attr"`
Width string `xml:"width,attr,omitempty"`
Height string `xml:"height,attr,omitempty"`
ViewBox string `xml:"viewBox,attr,omitempty"`
Fonts []*Font `xml:"defs>font"`
Masks []*Mask `xml:"defs>mask"`
Groups []*Group `xml:"g"`
Expand Down
23 changes: 23 additions & 0 deletions draw2dsvg/xml_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,3 +83,26 @@ func TestXml_WidthHeight(t *testing.T) {
svg.Width, svg.Height = "640px", "480"
t.Run("with width, height", subtest)
}

func TestXml_ViewBox(t *testing.T) {
expect := `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 100 -10 -100" fill="none" stroke="none">
<defs></defs>
</svg>`

svg := NewSvg()
subtest := func(t *testing.T) {
out, err := xml.MarshalIndent(svg, "", " ")
if err != nil {
t.Fatal(err)
}
if string(out) != expect {
t.Errorf("svg output is not as expected\n"+
"got:\n%s\n\n"+
"want:\n%s\n",
string(out),
expect)
}
}
svg.ViewBox = "0 100 -10 -100"
t.Run("with viewBox", subtest)
}

0 comments on commit 49fffa2

Please sign in to comment.