Sign up

How do I load a SVG file and show a specific layer in a GtkImage?

This can be achieved using either image.setFromPixelbufSub() or image.renderCairoSub(). The pixelbuf approach seems to be the simpler.

I have this:

import rsvg.Handle : RHandle = Handle;

...

auto svg = new RHandle(file);

auto pixbuf = svg.getPixbufSub("#layer");
image.setFromPixbuf(pixbuf);

image is a GtkImage

The code above is segfaulting in the setFromPixbuf() method. I don't know how to fix it.

I also tried the cairo approach, which seems to be a bit overkill, and I also didn't got it to work.

Does anyone have any suggestions on how to accomplish this or why the code is failing?

Thanks in advance,
Filipe

Re: How do I load a SVG file and show a specific layer in a GtkImage?

On 30-06-18 21:51, FFY00 wrote:

This can be achieved using either image.setFromPixelbufSub() or image.renderCairoSub(). The pixelbuf approach seems to be the simpler.

I have this:

import rsvg.Handle : RHandle = Handle;

...

auto svg = new RHandle(file);

auto pixbuf = svg.getPixbufSub("#layer");
image.setFromPixbuf(pixbuf);

image is a GtkImage

The code above is segfaulting in the setFromPixbuf() method. I don't know how to fix it.

I also tried the cairo approach, which seems to be a bit overkill, and I also didn't got it to work.

Does anyone have any suggestions on how to accomplish this or why the code is failing?

Thanks in advance,
Filipe

I can't reproduce this locally, do you have a more complete example?

Re: How do I load a SVG file and show a specific layer in a GtkImage?

On Sat, 30 Jun 2018 22:26:14 +0200, Mike Wey wrote:

I can't reproduce this locally, do you have a more complete example?

I created a simple project and implemented this. It was working, so I did a clean build of the project and it worked too. Probably meson failed to update the gresources or something like that. I am so sorry for wasting your time.

Re: How do I load a SVG file and show a specific layer in a GtkImage?

On Sat, 30 Jun 2018 20:45:57 GMT, FFY00 wrote:

On Sat, 30 Jun 2018 22:26:14 +0200, Mike Wey wrote:

I can't reproduce this locally, do you have a more complete example?

I created a simple project and implemented this. It was working, so I did a clean build of the project and it worked too. Probably meson failed to update the gresources or something like that. I am so sorry for wasting your time.

Do you have an example of building gresources in Meson for a D program. I want to avoid having a D program read an SVG file to create a Pixbuf, and whilst there appears to be no immediate data mechanism of using the SVG data, there is a way of using gresources.

Re: How do I load a SVG file and show a specific layer in a GtkImage?

On 8/26/18 12:42 PM, Russel Winder wrote:

Do you have an example of building gresources in Meson for a D program. I want to avoid having a D program read an SVG file to create a Pixbuf, and whilst there appears to be no immediate data mechanism of using the SVG data, there is a way of using gresources.

The gnome module in meson has a compileresources function:<br>http://mesonbuild.com/Gnome-module.html#gnomecompileresources

You will probably need to set gresource_bundle to true when using it
with Dlang.