2

I'm developping an editor that must use SVG shapes to create diagrams. To open and display SVGs I use librsvg which is actually pretty good but only useful to render SVGs not to edit them.

I would like to access to shape's property and change their values (i.e. width, size ).

I use Cairo to draw them to the screen but I don't want to use the cairo's scale feature, cause it's not the same as changing the size of the shapes.

I use C++ builder XE3 on Win32.

Is anyone knows a good C/C++ library I could use to do so ?

Thanks for your help.

A.G.
  • 1,279
  • 1
  • 11
  • 28
  • Depends on what you need, but any standard out-of-the-box XML parser should give you the svg document side of things. – Erik Dahlström Jun 20 '13 at 10:42
  • Which tags do you want to edit? Just `rect` or all? – cubuspl42 Jun 20 '13 at 11:45
  • Erik Dahlström: For sure, parsing an XML is easy, but the best would be a lib that parse the XML and build in memory a tree made of structs that represent the shapes defined in the SVG file then it will be easy to modify the shapes' properties. – A.G. Jun 20 '13 at 13:41
  • cubuspl42: Most of them, rect, g, style, color, ... – A.G. Jun 20 '13 at 13:42

1 Answers1

0

Cairo's scale function scales the entire coordinate system, but you can use it on an individual shape if you translate first to the shape's origin; and if you bracket these changes with a save/restore pair it will only affect drawing done within this span. Resetting the matrix before stroking allows you to resize a drawing without changing the stroke-width (alternately, you can adjust the stroke_width by 1/scaling-factor).

cairo_matrix_t m;
cairo_get_matrix(cr, &m);
cairo_save(cr);
    cairo_translate(shape_x, shape_y);
    cairo_scale(shape_w, shape_h);
        //cairo_move_to(cr, x, y);   //perform the actual drawing
        //cairo_line_to(cr, x, y);
        //cairo_closepath(cr);
    cairo_set_matrix(cr, &m);
    cairo_stroke(cr);
cairo_restore(cr);

And if resetting the matrix explicitly like this, you don't actually need the save/restore anymore (translate and scale don't affect anything but the matrix, and stroke resets the path).

luser droog
  • 18,988
  • 3
  • 53
  • 105
  • I know that, but the render is not the same. Cause I won't to change the width and the height of some shapes but without changing the stroke size. And the scale function with scale the border size as well...and it doesn't resoble my need to also change the color. Thanks for your reply. – A.G. Jun 21 '13 at 06:37
  • That might be fixable. Since describing the path and performing the stroke happen at different times, you can change the matrix in the middle. – luser droog Jun 21 '13 at 06:44
  • It is possible. But I have to extract some private structures that are defined in .c files or private .h files, which mean that in a future release of librsvg I'll have to check if the structures are still the same. That why I'm looking for a lib that let me access to its internal structures without having to hack it. – A.G. Jun 21 '13 at 11:34