Graphics.DrawSVG method

OK I think I found out what is actually causing the issue… It looks like something alwyn did not consider…

His code does not handle the situation where there is more than one view box

This SVG XML fragment of the SVG file (I am only copying the relevant part) does not work right:

[code]<?xml version="1.0"?>
<svg version=“1.1” id=“topsvg”
xmlns=“http://www.w3.org/2000/svg” xmlns:xlink=“http://www.w3.org/1999/xlink
xmlns:cml=“http://www.xml-cml.org/schema” x=“0” y=“0” width=“300px” height=“300px” viewBox=“0 0 100 100”>

- Open Babel Depiction [/code]

If I edit the file to this:

[code]<?xml version="1.0"?>
<svg version=“1.1” id=“topsvg”
xmlns=“http://www.w3.org/2000/svg” xmlns:xlink=“http://www.w3.org/1999/xlink
xmlns:cml=“http://www.xml-cml.org/schema” x=“0” y=“0” width=“300” height=“300” viewBox="0 0 941.051 941.051">

- Open Babel Depiction [/code]

Apparently one can have hierarchical viewboxes and he does not support that…
I know that the software I am using put text in the SVG that is independent of the drawn structure a well as other elements.

I suspect that the second view box has the dimensions of the drawing commands for the structure so that teh structure ca be scaled independently (or within) of other elements in the SVG…

But as I don’t know the SVG spec I don’t know how to modify his code for general use…

As i don’t need anything BUT the structure I can customize his code for my specific use…

If thee is an SVG expert here, it would nice if they could extend what he did for fuller SVH support…

This open source project will never be 100% because he relies on Object2Ds and they are too limited… Never the less fuller SVG support would help the community…

As i said before Xojo inc SHOULD at least support rendering SVG with losses scaling, even if an API for us to create them would be too big a job…

There has to be some good, fast code they can license at a reasonable price and integrate into the framework to do that just that!!!

Supporting a standards based platform and application indpendant vector format is getting to be more and more important with the proliferation of resolutions and screen sizes for all the 1platforms/devices Xojo is looking to support!

I know MBS has a plugin that can handle SVG to some degree, but besides not having a current license, I find the MBS plugins in general not very “citizen developer”/RAD friendly… Figuring this out is likely faster than trying to figure out how to makethat plugin (or figure out if it can) do what i want!

In any case if Alwyn’s code (with my mods for this use case) is fast enough, I think i have my solution for this specific application.

  • Karen
1 Like

Alwyn’s code in general worked well for my needs on a Mac, but has major issues on Windows (only tested on Windows 10) < big sigh>

Guess i will go the pre-generated PNG route and take the quality hit when I need scaling…

Given the feature request in feedback for SVG is a number of years old, I don’t think Xojo will support it anytime soon, if ever …

So much time was wasted on the old “new” framework and the navigator in the new IDE that could have been put to a LOT better use providing us with features like this that actually give more capabilities to accomplish things and do it faster in our own apps … Oh well

  • karen

Thank you Dana for re-opening this topic.

I apologize for having been absent for a good few years from this discussion. I had to attend to important business duties during this time, and were unable to give attention to any of my pro bono projects (including this DrawSVG method).

I’ve noticed that Xojo made some nice improvements to their graphics library since I last worked on this project, and I’m thinking about starting up the DrawSVG method development again.

That being said I would like to determine if there is still a demand for such a “native” DrawSVG method. If you would find it useful for me to continue on with this method/project, please let me know in this thread.

And kudos to the Xojo team for all the progress they’ve made during the past few years… I was pleasantly surprised :slight_smile:

5 Likes

I just started to build a SVG exporter for my graphics program. In my case I need it as SVG is a commonly used format for cutting machines, for example of vinyl, cardboard, etc. I basically use Affinity Designer to generate test files and the replicate that. Haven’t made much progress yet, but I’m getting there.

I would for sure use it especially for web based vector drawing. @Claes_Lundstrom have you seen our packaging library product for XY cutters? Its a xojo app: lib

Well, since the Original post in 2015, SVG has become more and more popular and is a standard for many use cases. It is a shame that Xojo dont have a native support for their graphics system and being the Feedback case asking for this (<https://xojo.com/issue/10931>) more than 12 years old… having proyects like yours is the only hope for many users who need SVG suport.

So, YES, this is very useful

Definitely yes! SVG is now widely used as a vector data exchange format. I have a half-done set of SVGDocument classes to import and export vector data. When I started, the limited graphics functions offered by Xojo at the time did not encourage me to proceed any further than parsing a few simple shapes, but now things have changed. The GraphicsPath class is great and - though it still does not support subpaths and winding rules - it would make drawing an SVG much easier than before.

1 Like

Definitely yes! We also could use the SVG format to output to Plotters.

I use it all the time for that. Plotters and cutter that is.

Hi does your DrawSVG class have a method like getPointAtLength() as described here?

I’m basically making a plotter using a xojo app running on a raspberry pi. I need a way to convert an SVG path to movements for the motors. Basically I need to be able to get an x,y based on being so far through drawing the path line. So I can move the motor along that path.

And looking at their code, I need to do something like this to get the total length of the path so I can move the appropriate distance along the path each cycle:

var  pathLength = mypath.getTotalLength();

This would keep my pen moving at a consistent speed. I already do this for example when drawing a circle.

I’m going to go out and look at the github but was wondering how hard this would be to implement.