[cairo-commit] test/pdf2png.c
Carl Worth
cworth at kemper.freedesktop.org
Tue May 2 17:01:12 PDT 2006
test/pdf2png.c | 38 +++++++++++++++++++++++++++-----------
1 files changed, 27 insertions(+), 11 deletions(-)
New commits:
diff-tree 253472492ee2a690646a30b32cf8180f5b6e3299 (from e7459428dc87f7372dd7d5bd903341d619ee726f)
Author: Carl Worth <cworth at cworth.org>
Date: Tue May 2 16:54:49 2006 -0700
pdf2png: Use new poppler_page_render to render directly through cairo.
...as opposed to using poppler_page_render_to_pixbuf.
diff --git a/test/pdf2png.c b/test/pdf2png.c
index 3edb17c..c8ea0db 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 at redhat.com>
+ * Authors: Kristian Høgsberg <krh at redhat.com>
+ * Carl Worth <cworth at 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;
}
More information about the cairo-commit
mailing list