[cairo-commit] 2 commits - test/pdf2png.c test/svg2png.c
Adrian Johnson
ajohnson at kemper.freedesktop.org
Sat Apr 16 08:39:14 UTC 2016
test/pdf2png.c | 2 ++
test/svg2png.c | 39 +++++++++++++++++++++++++++++++++------
2 files changed, 35 insertions(+), 6 deletions(-)
New commits:
commit 00a36e46524790deb36048fddd911daa1cbcbe38
Author: Adrian Johnson <ajohnson at redneon.com>
Date: Sat Apr 16 18:05:41 2016 +0930
svg2png: fix deprecated warning
rsvg_pixbuf_from_file() is deprecated, replaced by
rsvg_handle_new_from_file() + rsvg_handle_render_cairo().
diff --git a/test/svg2png.c b/test/svg2png.c
index 1eecaf7..9a5c8c0 100644
--- a/test/svg2png.c
+++ b/test/svg2png.c
@@ -37,9 +37,13 @@
int main (int argc, char *argv[])
{
GError *error = NULL;
- GdkPixbuf *pixbuf;
+ RsvgHandle *handle;
+ RsvgDimensionData dimensions;
const char *filename = argv[1];
const char *output_filename = argv[2];
+ cairo_surface_t *surface;
+ cairo_t *cr;
+ cairo_status_t status;
if (argc != 3)
FAIL ("usage: svg2png input_file.svg output_file.png");
@@ -51,14 +55,37 @@ int main (int argc, char *argv[])
error = NULL;
rsvg_set_default_dpi (72.0);
- pixbuf = rsvg_pixbuf_from_file (filename, &error);
- if (error != NULL)
+
+ handle = rsvg_handle_new_from_file (filename, &error);
+ if (!handle)
+ FAIL (error->message);
+
+ rsvg_handle_get_dimensions (handle, &dimensions);
+
+ surface = cairo_image_surface_create (CAIRO_FORMAT_RGB24,
+ dimensions.width, dimensions.height);
+ cr = cairo_create (surface);
+ cairo_surface_destroy (surface);
+
+ cairo_set_source_rgb (cr, 1,1,1);
+ cairo_paint (cr);
+ cairo_push_group_with_content (cr, CAIRO_CONTENT_COLOR_ALPHA);
+
+ if (!rsvg_handle_render_cairo (handle, cr))
FAIL (error->message);
- gdk_pixbuf_save (pixbuf, output_filename, "png", &error, NULL);
- if (error != NULL)
+ cairo_pop_group_to_source (cr);
+ cairo_paint (cr);
+
+ status = cairo_surface_write_to_png (cairo_get_target (cr),
+ output_filename);
+ cairo_destroy (cr);
+ if (status)
+ FAIL (cairo_status_to_string (status));
+
+ if (!rsvg_handle_close (handle, &error))
FAIL (error->message);
- g_object_unref (pixbuf);
+ g_object_unref (handle);
return 0;
}
commit 11667ec47c69e3aa7b7128ddb39375f3ae4a0814
Author: Adrian Johnson <ajohnson at redneon.com>
Date: Sat Apr 16 17:42:56 2016 +0930
pdf2png: fix deprecated warning
diff --git a/test/pdf2png.c b/test/pdf2png.c
index 06fa05b..2369122 100644
--- a/test/pdf2png.c
+++ b/test/pdf2png.c
@@ -49,7 +49,9 @@ int main (int argc, char *argv[])
if (argc != 4)
FAIL ("usage: pdf2png input_file.pdf output_file.png page");
+#if !GLIB_CHECK_VERSION(2,36,0)
g_type_init ();
+#endif
if (g_path_is_absolute(filename)) {
absolute = g_strdup (filename);
More information about the cairo-commit
mailing list