treeform / pixie

Full-featured 2d graphics library for Nim.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Support for Inkscape SVG files

Patitotective opened this issue · comments

I'm creating an application that requires to load images in SVG format. Most of those images are created by Inkscape and it fails loading them.
Looking at the source code, I think the problem is that Inkscape's SVG files do not have the viewBox attribute.

import std/httpclient
import pixie/fileformats/svg

let
  client = newHttpClient()
  data = client.getContent("https://appimage.github.io/database/SonicLineup/icons/scalable/sonic-lineup-icon.svg")
  image = data.decodeSvg()
/home/cristobal/.../trial.nim(7) trial
/home/cristobal/.nimble/pkgs/pixie-4.1.0/pixie/fileformats/svg.nim(603) decodeSvg
Error: unhandled exception: Unable to load SVG [PixieError]
Error: execution of an external program failed: '/home/cristobal/.../trial '

That is correct no viewBox is what breaks this.

But that is not the only issue with the sonic-lineup-icon.svg SVG file. SVG can be quite complex... in fact they can contain JS/HTML inside them requiring a full browser to render. We don't plant to support such files. Most programs (unless you are a browser) use some sort of SVG-but-simpler version of SVG where only the common features are supported. This is what we do here.

Your svg file contains a ton of extra inkscape: parameters and tags.

Your file uses defs and marker which appear to be quite complex.

There are tons of other tags I have not seen before.

I don't think we will ever support the file you have sorry. There is just to much "fancy" there.

The vector tool we use - figma export much simpler SVG files. The SVG icons we find online are much simpler as well.

Have you tried using the PlainSVG feature? https://wiki.inkscape.org/wiki/PlainSVG

Have you tried flatting everything to simple paths and shapes?

Have you tried using the PlainSVG feature?

The thing is that I download those SVG files at run-time, so I'd need to install inkscape to convert them to PlainSVG (?)
Maybe using another library to simplify them

Hey, I am going to close this, as we can't support every arbitrary SVG files (too complex). But if you have a specific SVG feature that you think is pretty common that we don't support feel free to open an issue on that. Or even better a PR.