summaryrefslogtreecommitdiff
path: root/test/pdf2png.c
diff options
context:
space:
mode:
authorCarl Worth <cworth@cworth.org>2006-05-02 16:54:49 -0700
committerCarl Worth <cworth@cworth.org>2006-05-02 16:57:27 -0700
commit253472492ee2a690646a30b32cf8180f5b6e3299 (patch)
tree067e082a7fc5c8dd19ef08350f627310923f19e6 /test/pdf2png.c
parente7459428dc87f7372dd7d5bd903341d619ee726f (diff)
pdf2png: Use new poppler_page_render to render directly through cairo.
...as opposed to using poppler_page_render_to_pixbuf.
Diffstat (limited to 'test/pdf2png.c')
-rw-r--r--test/pdf2png.c38
1 files changed, 27 insertions, 11 deletions
diff --git a/test/pdf2png.c b/test/pdf2png.c
index 3edb17cc3..c8ea0db03 100644
--- a/test/pdf2png.c
+++ b/test/pdf2png.c
@@ -1,5 +1,6 @@
/*
* Copyright © 2005 Red Hat, Inc.
+ * Copyright © 2006 Red Hat, Inc.
*
* Permission to use, copy, modify, distribute, and sell this software
* and its documentation for any purpose is hereby granted without
@@ -20,7 +21,8 @@
* OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
* IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*
- * Author: Kristian Høgsberg <krh@redhat.com>
+ * Authors: Kristian Høgsberg <krh@redhat.com>
+ * Carl Worth <cworth@redhat.com>
*/
#include <stdlib.h>
@@ -35,13 +37,15 @@ int main (int argc, char *argv[])
{
PopplerDocument *document;
PopplerPage *page;
- GdkPixbuf *pixbuf;
double width, height;
GError *error;
const char *filename = argv[1];
const char *output_filename = argv[2];
const char *page_label = argv[3];
gchar *absolute, *uri;
+ cairo_surface_t *surface;
+ cairo_t *cr;
+ cairo_status_t status;
if (argc != 4)
FAIL ("usage: pdf2png input_file.pdf output_file.png page");
@@ -73,16 +77,28 @@ int main (int argc, char *argv[])
poppler_page_get_size (page, &width, &height);
- pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB, FALSE, 8,
- width * PIXELS_PER_POINT,
- height * PIXELS_PER_POINT);
- gdk_pixbuf_fill (pixbuf, 0xffffffff);
- poppler_page_render_to_pixbuf (page, 0, 0, width , height,
- PIXELS_PER_POINT, 0, pixbuf);
+ surface = cairo_image_surface_create (CAIRO_FORMAT_RGB24,
+ width * PIXELS_PER_POINT,
+ height * PIXELS_PER_POINT);
+ cr = cairo_create (surface);
- gdk_pixbuf_save (pixbuf, output_filename, "png", &error, NULL);
- if (error != NULL)
- FAIL (error->message);
+ /* Clear background */
+ cairo_set_source_rgb (cr, 1.0, 1.0, 1.0); /* white */
+ cairo_paint (cr);
+
+ poppler_page_render (page, cr);
+
+ status = cairo_status (cr);
+ if (status)
+ FAIL (cairo_status_to_string (status));
+
+ cairo_destroy (cr);
+
+ cairo_surface_write_to_png (surface, output_filename);
+
+ status = cairo_surface_status (surface);
+ if (status)
+ FAIL (cairo_status_to_string (status));
return 0;
}