Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SVG images often render incorrectly #5240

Open
2 tasks done
rasteric opened this issue Nov 5, 2024 · 2 comments
Open
2 tasks done

SVG images often render incorrectly #5240

rasteric opened this issue Nov 5, 2024 · 2 comments
Labels
unverified A bug that has been reported but not verified

Comments

@rasteric
Copy link

rasteric commented Nov 5, 2024

Checklist

  • I have searched the issue tracker for open issues that relate to the same problem, before opening a new one.
  • This issue only relates to a single bug. I will open new issues for any other problems.

Describe the bug

The SVG rendering in Fyne is fairly limited. For example, many of the SVGs in this package:

https://dribbble.com/shots/8934409-Diversity-Avatars

are rendered incorrectly. The corresponding PNGs work. I understand it is a very complex file format but if there is a way to bump up the 3rd party dependency responsible for SVG loading and rendering to a better version, it should be done. SVGs are clearly preferred (also in the docs) and superior to PNGs but only when they work. It shouldn't be like rolling a die whether an SVG works or not.

How to reproduce

  1. Download https://dribbble.com/shots/8934409-Diversity-Avatars
  2. Create an app loading and displaying the images in SVG format.
  3. Compare to how they should look.

Screenshots

These are not supposed to look like this (though the second one is kind of entertaining):

Screenshot from 2024-11-05 11-58-26
Screenshot from 2024-11-05 12-00-58

Example code

package main

import (
	"fyne.io/fyne/v2"
	"fyne.io/fyne/v2/app"
	"fyne.io/fyne/v2/canvas"
	"fyne.io/fyne/v2/container"
	"fyne.io/fyne/v2/dialog"
	"fyne.io/fyne/v2/storage"
	"fyne.io/fyne/v2/theme"
	"fyne.io/fyne/v2/widget"
)

func main() {
	a := app.NewWithID("svg-test")
	win := a.NewWindow("SVG Test")
	img := canvas.NewImageFromResource(theme.AccountIcon())
	card := widget.NewCard("image", "", img)
	button := widget.NewButton("Load SVG", func() {
		dlg := dialog.NewFileOpen(func(in fyne.URIReadCloser, err error) {
			if err == nil {
				img := canvas.NewImageFromReader(in, "file.svg")
				if err != nil {
					dialog.ShowError(err, win)
					return
				}
				img.FillMode = canvas.ImageFillContain
				card.SetContent(img)
			}
		}, win)
		dlg.SetFilter(storage.NewExtensionFileFilter([]string{".svg"}))
		dlg.SetConfirmText("Change Image")
		dlg.SetDismissText("Cancel")
		dlg.SetFileName("some.svg")
		dlg.Show()
	})
	bd := container.NewBorder(nil, button, nil, nil, card)
	win.SetContent(bd)
	win.Resize(fyne.Size{Width: 400, Height: 400})
	win.ShowAndRun()
}

Fyne version

2.5.2

Go compiler version

1.22.0 linux/amd64

Operating system and version

Linux Mint 22 Cinnamon

Additional Information

No response

@rasteric rasteric added the unverified A bug that has been reported but not verified label Nov 5, 2024
@andydotxyz
Copy link
Member

This issue would help from being more specific.
There are already open tickets to report that text and gradients are not currently working.
Additionally CSS properties are not supported.
From the large icon set referenced it is not clear if there is anything outside of that list which is newly reported so that we can hunt down the cause and fix it.

@rasteric
Copy link
Author

rasteric commented Nov 6, 2024

I understand the concern. I've provided a link to an icon set that mostly doesn't work and a minimal program to test the images in it. Unfortunately, I don't know enough about the SVG format to be of more help. I certainly can't identify why these don't work in particular. Perhaps someone else can explain why they don't work.

If you plan to keep to support for SVGs partial for the time being (which is how I interpret your remark above), then I would suggest you mention the limitations in the docs, perhaps add a function to determine whether an SVG file is interpretable, or perhaps remove the recommendation to use SVG images from the docs.

As I said, right now it's like rolling a dice. Some images work, others don't, and there is no function in Fyne to determine programmatically which will work and which get displayed as mangled garbage. That makes the format almost unusable for some purposes (e.g. for user-provided images).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
unverified A bug that has been reported but not verified
Projects
None yet
Development

No branches or pull requests

2 participants