SVG Workaround

Ok, so one of my new Xojo projects relies heavily on the use of SVG images, and I had to implement a workaround to load SVG images as picture objects.

There is a catch however… you need to have the free open source Inkscape tool installed.

I’ve only implemented the workaround for Windows at this point, but it shouldn’t be too difficult to update the method with compiler directives for OS X and/or Linux. Once the SVG is loaded, you can use it like you would any other picture object (e.g. PNG, JPG, BMP, etc…)

This is bit of a hairy hack, but at least it opens the door for SVG usage in your applications (even if your app will be dependent on Inkscape being installed):

Function OpenSVG(file As FolderItem) As Picture
  Dim s As new Shell
  Dim tempFile As FolderItem
  Dim p As Picture
  
  tempFile = GetTemporaryFolderItem() // get a temp file

  // convert SVG to PNG
  s.Execute """C:\\Program Files (x86)\\Inkscape\\inkscape.exe"" -z -f """ + file.NativePath + """ -j -e """ + tempFile.NativePath + """"

  p = Picture.Open(tempFile)
  
  tempFile.Delete() // delete temp file
  
  return p
  
End Function

…and you would use it like…

  Dim svgFile As new FolderItem(path to your SVG file)
  Dim pic As Picture
  
  pic = OpenSVG(svgFile)

I’m sure there are plenty of ways to improve this method (e.g. not having inkscape path hardcoded, support for OSX and/or Linux)… but I thought this method might help some.

SVG to PNG conversion can be achieved using small external tools and loaded as PNG after. For a moment I thought you were proposing a method of translating SVG to some sort of Object2D primitives. :stuck_out_tongue:
Probably this one is a candidate: https://github.com/nokia-developer/svg-converter

A method of translating SVG to Object2D would be first prize, but I’ll have to settle for bronze at this point :wink:

For technical reasons beyond the scope of this post, my app needs to load SVG images in realtime, so converting them to PNG beforehand isn’t an option.

Feedback case <https://xojo.com/issue/10931> is getting most of my points.

I’ll have a look at the svg-converter that you’ve suggested.

With your abilities, probably we’ll get a plug-in. :slight_smile:

…if only I had the time.

I haven’t even found a way to install Inkscape on 10.9. Forgot the reason, but it wasn’t possible.

It needs X11. Is that?

I suppose any command line tool can be used to convert SVG images to PNG in the above method (like Rick already mentioned)… Inkscape is a great tool for editing SVG though.

Are you an Apple or Microsoft user Beatrix?

10.9 = Mavericks = Apple. I’ve used Inkscape before so I know how to install X11. Will try again…

Being a Windows user I didn’t catch the meaning of that equation from your previous post. Good to know for future references. :slight_smile:

X11?

X11 was installed in OS X prior versions, but I do not need it anymore, so for Mavericks I do not know.

I checked, X11 is in Applications/Utilities of the boot volume.

The name of last version I downloaded is Inkscape-0.48.5+X11 (I do not get time to install it).
I installed the Windows version and testings (for other) needs worked fine.

You will need to install XQuartz

I was feeling that, but since it was not in the file name I was thinking my memory was bad. I certainly saw that on their web site.

[quote=116411:@Alwyn Bester]I suppose any command line tool can be used to convert SVG images to PNG in the above method (like Rick already mentioned)… Inkscape is a great tool for editing SVG though.
[/quote]
Imagemagick might be useful for the conversion. Have not tried though.
http://www.imagemagick.org/Usage/draw/#svg

Cool… will check it out.