Jump to content

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

From Wikipedia, the free encyclopedia
Computing desk
< December 9 << Nov | December | Jan >> December 11 >
Welcome to the Wikipedia Computing Reference Desk Archives
The page you are currently viewing is a transcluded archive page. While you can leave answers for any questions shown below, please ask new questions on one of the current reference desk pages.


December 10

[edit]

SVG to coordinates

[edit]

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)[reply]

SVG files can be read in a Text editor, of which there are many. For example if your line path is expressed as
<polyline points="50,150 50,200 200,200 200,100" stroke="red" stroke-width="4" fill="none" />
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 [1]. DroneB (talk) 12:23, 11 December 2019 (UTC)[reply]