From: Michael Orlitzky Date: Fri, 4 Aug 2023 01:58:15 +0000 (-0400) Subject: example.c: use GdkPixbuf instead of Cairo for SVG -> PNG conversion. X-Git-Tag: 0.0.1~49 X-Git-Url: https://gitweb.michael.orlitzky.com/?a=commitdiff_plain;h=6bf209a934fc0b73a4e0dabddbb8de1e4ec5d799;p=libsvgtiny-pixbuf.git example.c: use GdkPixbuf instead of Cairo for SVG -> PNG conversion. --- diff --git a/example.c b/example.c index fa1e000..3dab2ba 100644 --- a/example.c +++ b/example.c @@ -5,6 +5,8 @@ #include /* read */ #include +#include +#include #include /* Convenient typedefs for libsvgtiny */ @@ -153,7 +155,6 @@ diagram_t* svgtiny_diagram_from_path(char* path, int width, int height) { return diagram; } - /* * @brief Create a cairo context from a libsvgtiny diagram. * @@ -242,18 +243,15 @@ cairo_t* cairo_context_from_diagram(diagram_t* diagram) { return cr; } - int main(int argc, char** argv) { - int exit_code = 0; - char* svgpath; char* pngpath; int pngwidth = 1024, pngheight = 1024; diagram_t* diagram; - cairo_surface_t *surface; cairo_t *cr = 0; - cairo_status_t crs; + + GdkPixbuf* pb; /* Parse arguments, and maybe print usage */ if (argc < 3) { @@ -276,14 +274,16 @@ int main(int argc, char** argv) { return 1; } - crs = cairo_surface_write_to_png(cairo_get_target(cr), pngpath); - if (crs != CAIRO_STATUS_SUCCESS) { - fprintf(stderr, - "cairo_surface_write_to_png failed: %s\n", - cairo_status_to_string(crs)); - svgtiny_free(diagram); - cairo_destroy(cr); - return 1; + pb = gdk_pixbuf_get_from_surface(cairo_get_target(cr), + 0, + 0, + pngwidth, + pngheight); + + + if (pb) { + gdk_pixbuf_save(pb, pngpath, "png", NULL, NULL); + g_object_unref(pb); } return 0;