1

I want use the librsvg to render part of some svg files. When I use those code:

        try {
            handle = new Rsvg.Handle.from_file(inputtext);
        } catch (GLib.Error e) {error ("%s", e.message);}

    if(handle.has_sub("##sub0") && handle.has_sub("##sub1"))
    {sub=0; stdout.printf("found sub0 and sub1.\n");}

nothing happend. of course id="sub0" and id="sub1" is in the svg file, and handle also work (can render whole svg correctlly).

id (str or None) – An element's id within the SVG, or None to render the whole SVG. For example, if you have a layer called “layer1” that you wish to render, pass “##layer1” as the id.

according to https://lazka.github.io/pgi-docs/Rsvg-2.0/classes/Handle.html, search the id in svg need to prefix with "##".

If i use handle.has_sub("sub0"), the code still no work.

eexpress
  • 386
  • 1
  • 14
  • Why is this tagged C# & Vala? Looks like your using Vala so you should probably remove c# – Zander Brown Mar 23 '19 at 12:23
  • 1
    Also I suggest using [vala](https://valadoc.org/librsvg-2.0/Rsvg.Handle.has_sub.html) or the original [c docs](https://developer.gnome.org/rsvg/2.44/rsvg-RsvgHandle.html#rsvg-handle-has-sub) (which seem to suggest just one #) – Zander Brown Mar 23 '19 at 12:24
  • 1
    An id is referenced with a single # when using a URI, so it makes sense to try a single #. The C docs, as AlexB points out, state ' starting with "##", for example, "#layer1"' which could be confusing – AlThomas Mar 23 '19 at 23:57
  • Thanks very much, AlThomas and AlexB. when use "#sub0", it works. – eexpress Mar 26 '19 at 11:08

0 Answers0