Writng an SVG Parser, question about Line, Polyline

Discuss SVG code, accessible via the XML Editor.
EddieRich
Posts: 5
Joined: Wed Jun 21, 2017 10:51 pm

Writng an SVG Parser, question about Line, Polyline

Postby EddieRich » Wed Jun 21, 2017 11:09 pm

Hello,

I am writing an SVG Parser (in C#) so our customers can use inkscape to draw shapes for our laser cutting machines.
I have created SVG files with just lines and polylines, but inkscape saves them as paths.
Circle and ellipse save as circle and ellipse, as does a rectangle.
I need to handle all the "shapes" that inkscape may generate in the SVG file.

Question is, does/can inkscape save a line as an xml "<Line" element, or does it always use paths?

~suv
Posts: 2272
Joined: Sun May 10, 2009 2:07 am

Re: Writng an SVG Parser, question about Line, Polyline

Postby ~suv » Thu Jun 22, 2017 12:46 am

EddieRich wrote:Question is, does/can inkscape save a line as an xml "<Line" element, (...)
No.
Core inkscape supports reading (rendering) of the SVG basic shapes but neither writing (creating) nor editing of such element types.
To edit the geometry of these basic shape elements in Inkscape (i.e. to use the node tool ( :tool_node: ) to edit the position of the points), the shapes need to be converted to path first (Shift+Ctrl+C).
EddieRich wrote:(...) or does it always use paths?
Yes.
Inkscape only supports writing path elements for (open or closed) lines with straight segments drawn e.g. with the Pencil or the Pen tool.

EddieRich
Posts: 5
Joined: Wed Jun 21, 2017 10:51 pm

Re: Writng an SVG Parser, question about Line, Polyline

Postby EddieRich » Sat Jun 24, 2017 12:08 am

Fantastic, thanks for the quick reply ~suv.
The fewer shapes I need to parse, the better :D

~suv
Posts: 2272
Joined: Sun May 10, 2009 2:07 am

Re: Writng an SVG Parser, question about Line, Polyline

Postby ~suv » Sat Jun 24, 2017 12:28 am

EddieRich wrote:The fewer shapes I need to parse, the better
Just keep in mind that users often work with third-party content (directly opened, or imported), which of course might contain these valid SVG elements, or that users might apply Inkscape extensions which could add such elements to the current drawing. As long as the user does not manually convert these basic shape elements (line, polyline, polygon) to path (in order to edit their geometry), they will persist.
In my experience, it is not safe to assume that users never have Inkscape SVG files with content other than what was purely generated (newly drawn) in core inkscape itself.

EddieRich
Posts: 5
Joined: Wed Jun 21, 2017 10:51 pm

Re: Writng an SVG Parser, question about Line, Polyline

Postby EddieRich » Fri Jul 14, 2017 11:24 pm

~suv wrote:In my experience, it is not safe to assume that users ...


That has been my experience as well. Never assume anything when it comes to the end user. :)


Return to “SVG / XML Code”