Skip to content

RSvg 2.0 added to giddy#9

Merged
elementgreen merged 1 commit intoKymorphia:mainfrom
dejlek:dejan/rsvg
Feb 27, 2025
Merged

RSvg 2.0 added to giddy#9
elementgreen merged 1 commit intoKymorphia:mainfrom
dejlek:dejan/rsvg

Conversation

@dejlek
Copy link
Copy Markdown
Contributor

@dejlek dejlek commented Feb 27, 2025

This PR adds the RSvg package to giddy.

Here is a very simple example (from my gid-examples project):

import rsvg.handle;
import rsvg.types;

import gdkpixbuf.pixbuf;
import gdkpixbuf.types;

int main() {
    // Get the RSvg Handle object
    Handle h = Handle.newFromFile("d-simple.svg");
    h.setDpi(300);

    // Get the GdkPixbuf from the RSvg handle, and scale it down to 64 pixels.
    Pixbuf p = h.getPixbuf();
    Pixbuf smaller = p.scaleSimple(64, 64, InterpType.Bilinear);

    // Save it to a PNG file
    string[] ks;
    string[] vs;
    smaller.savev("d-simple.png", "png", ks, vs);

    return 0;
}

You can grab d-simple.svg from here: https://codeberg.org/dejan/gid-examples/src/branch/main/rsvg/d-simple.svg

And when you run it here is what happens:

dejan@mini:~/work/dejan/gid-examples/rsvg «git: main»
» ./gid-rsvg-example 
dejan@mini:~/work/dejan/gid-examples/rsvg «git: main»
» file d-simple.png 
d-simple.png: PNG image data, 64 x 64, 8-bit/color RGBA, non-interlaced

As you can see it did generate a PNG file scaled down to the 64 pixels. This is also a demonstration of the GdkPixbuf package as well btw. I will at some point in the future write another demo in which we will put this SVG into a Gtk 4 icon in the toolbar.

@elementgreen elementgreen merged commit ac362a2 into Kymorphia:main Feb 27, 2025
@elementgreen
Copy link
Copy Markdown
Contributor

Awesome! What do you think about having an official gid-examples repository? Or would you prefer to continue to host your own on codeberg? Was just thinking it would be nice to have a single repo for the Gtk4 examples as well as other examples for the various giD libraries. Open to either way really. If you decide to just continue to have your own examples repo, we can link it from the giD and gidgen docs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants