Skip to content

Commit

Permalink
Add fix and test for serializing SVG without width or height attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
sdassow authored and andydotxyz committed Dec 8, 2024
1 parent c57f7f0 commit dbc933c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
4 changes: 2 additions & 2 deletions internal/svg/svg.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,8 @@ func IsResourceSVG(res fyne.Resource) bool {
type svg struct {
XMLName xml.Name `xml:"svg"`
XMLNS string `xml:"xmlns,attr"`
Width string `xml:"width,attr"`
Height string `xml:"height,attr"`
Width string `xml:"width,attr,omitempty"`
Height string `xml:"height,attr,omitempty"`
ViewBox string `xml:"viewBox,attr,omitempty"`
Paths []*pathObj `xml:"path"`
Rects []*rectObj `xml:"rect"`
Expand Down
13 changes: 13 additions & 0 deletions theme/icons_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package theme_test
import (
"fmt"
"path/filepath"
"regexp"
"testing"

"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -50,6 +51,18 @@ func TestIconThemeChangeContent(t *testing.T) {
assert.NotEqual(t, content, cancel.Content())
}

func TestIconThemeResourceWithViewboxOnly(t *testing.T) {
r1 := &fyne.StaticResource{
StaticName: "unsplash.svg",
StaticContent: []byte(`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M7.5 6.75V0h9v6.75h-9zm9 3.75H24V24H0V10.5h7.5v6.75h9V10.5z"></path></svg>`),
}
r2 := theme.NewThemedResource(r1)
re := regexp.MustCompile(`\s+fill\S+`)
content := re.ReplaceAll(r2.Content(), []byte(""))

assert.Equal(t, r1.Content(), content)
}

func TestNewThemedResource_StaticResourceSupport(t *testing.T) {
fyne.CurrentApp().Settings().SetTheme(theme.DarkTheme())
custom := theme.NewThemedResource(helperNewStaticResource())
Expand Down

0 comments on commit dbc933c

Please sign in to comment.