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

[Lona Studio] Display SVG files when selected within the file navigator #339

dabbott opened this Issue Mar 12, 2019 · 3 comments


None yet
2 participants
Copy link

dabbott commented Mar 12, 2019


Currently Lona Studio displays some image files, e.g. PNG files, when selected in the file navigator. However, it doesn't display SVG files, which it really should, since it handles them elsewhere correctly.

Here's what the image viewer looks like for PNG files:

Screen Shot 2019-03-12 at 11 08 36 AM

And here's what it currently looks like for SVG files:

Screen Shot 2019-03-12 at 11 08 43 AM

We want to use the same viewer as the PNG for SVG also.

Proposed Implementation

I think we want to add svg to the list of supported file types:

Screen Shot 2019-03-12 at 11 12 17 AM

Then when we read the data for the ImageDocument

content = NSImage(data: data)
we should render the SVG file to an image
static func render(

We might need to choose an arbitrary size for the image. We could use the viewBox of the svg to attempt to determine an "intrinsic" size of some kind, but that isn't really reliable. SVGs are designed to scale to any size, so they don't really have an intrinsic size, although viewBox is sometimes used like that. Maybe play around with it and see what looks best?

If you want to try using the viewBox, it's a little more effort, but you can access it by first generating an SVG.Node before rendering an image, e.g. here

let viewBox = svg.params.viewBox?.cgRect ?? CGRect(origin: .zero, size: size)


This comment has been minimized.

Copy link

klymenkoo commented Mar 12, 2019

I want to take this issue as well.


This comment has been minimized.

Copy link

klymenkoo commented Mar 13, 2019

I was able to display SVG images, but some images are rendered with pure black color for some reason (look screenshot 2):
Screen Shot 2019-03-12 at 10 11 23 PM
Screen Shot 2019-03-12 at 10 11 43 PM
Screen Shot 2019-03-12 at 10 11 34 PM

Any thoughts on what might cause this problem?


This comment has been minimized.

Copy link
Collaborator Author

dabbott commented Mar 13, 2019

I'm not sure, but those SVGs most likely use features that Lona's very primitive SVG renderer doesn't support yet. E.g. the firefox one might have gradients, but we can only draw solid colors for now. So I think what you have looks correct.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.