From dbc933ce08f6cc4c56e303fd2aa7772b65ecb73b Mon Sep 17 00:00:00 2001 From: Simon Dassow Date: Sat, 7 Dec 2024 15:54:37 +0100 Subject: [PATCH] Add fix and test for serializing SVG without width or height attributes --- internal/svg/svg.go | 4 ++-- theme/icons_test.go | 13 +++++++++++++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/internal/svg/svg.go b/internal/svg/svg.go index c89be41d8b..9300c06c03 100644 --- a/internal/svg/svg.go +++ b/internal/svg/svg.go @@ -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"` diff --git a/theme/icons_test.go b/theme/icons_test.go index 2f13f80a5b..091441a7b8 100644 --- a/theme/icons_test.go +++ b/theme/icons_test.go @@ -3,6 +3,7 @@ package theme_test import ( "fmt" "path/filepath" + "regexp" "testing" "github.com/stretchr/testify/assert" @@ -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(``), + } + 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())