Wikipedia:Reference desk/Archives/Computing/2019 December 10

= December 10 =

SVG to coordinates
I have a very very simple SVG file that I drew myself. Just a few dozen points, nothing fancy.

I'm using the Cairo_(graphics) library to render some graphics, and my goal is the add this very simple SVG into my Cairo canvas.

Normally I would be using a SVG library to open the SVG, export the path and render it. But in this case, since the SVG file is so simple, I plan on directly re-drawing the path in my source code. This way I do not add the burden of yet another library dependency. Basically I want to convert my simple SVG file to an array of (x,y) coordinates so that I can loop over the array and call Cairo's draw line function to draw it step by step. Is there a tool (preferable an online one) that can convert a SVG file to a list of (x,y) coordinates? The SVG contains a single non-self-intersecting path. Thanks. Mũeller (talk) 10:37, 10 December 2019 (UTC)
 * SVG files can be read in a Text editor, of which there are many. For example if your line path is expressed as


 * then the list of (x,y) coordinates can be extracted as (50,150) (50,200) (200,200) (200,100). You would translate this to:

cairo_move_to (cr, 50, 150); cairo_line_to (cr, 50,200); cairo_line_to (cr, 200,200); cairo_line_to (cr, 200,100);
 * where cr is a cairo context. See . DroneB (talk) 12:23, 11 December 2019 (UTC)