summaryrefslogtreecommitdiff
path: root/test/any2ppm.c
diff options
context:
space:
mode:
authorCarlos Garcia Campos <carlosgc@gnome.org>2008-10-09 12:11:51 +0100
committerChris Wilson <chris@chris-wilson.co.uk>2008-10-09 12:25:08 +0100
commit3e6afb353da1fee624b519f5a96b3303c7eb91ae (patch)
tree7ee0b57689da54493ff162cba43b4a676468bd16 /test/any2ppm.c
parentddd1615a1777181c6e8db1dbafacb68535ed163a (diff)
downloadcairo-3e6afb353da1fee624b519f5a96b3303c7eb91ae.tar.gz
[test/any2ppm] Enable PS conversion using libspectre.
Complete the vector trilogy using libspectre to provide a similar interface (to poppler and librsvg) around GhostScript.
Diffstat (limited to 'test/any2ppm.c')
-rw-r--r--test/any2ppm.c73
1 files changed, 71 insertions, 2 deletions
diff --git a/test/any2ppm.c b/test/any2ppm.c
index 412bbb8bc..36c742fcb 100644
--- a/test/any2ppm.c
+++ b/test/any2ppm.c
@@ -22,6 +22,9 @@
*
* Author: Chris Wilson <chris@chris-wilson.co.uk>
*
+ * Contributor(s):
+ * Carlos Garcia Campos <carlosgc@gnome.org>
+ *
* Adapted from pdf2png.c:
* Copyright © 2005 Red Hat, Inc.
*
@@ -70,6 +73,7 @@
#endif
#if CAIRO_CAN_TEST_PS_SURFACE
+#include <libspectre/spectre.h>
#endif
#if HAVE_FCNTL_H && HAVE_SIGNAL_H && HAVE_SYS_STAT_H && HAVE_SYS_SOCKET_H && HAVE_SYS_POLL_H && HAVE_SYS_UN_H
@@ -347,11 +351,76 @@ svg_convert (char **argv, int fd)
#if CAIRO_CAN_TEST_PS_SURFACE
static const char *
+_spectre_render_page (const char *filename,
+ const char *page_label,
+ cairo_surface_t **surface_out)
+{
+ static const cairo_user_data_key_t key;
+
+ SpectreDocument *document;
+ SpectreStatus status;
+ int width, height, stride;
+ unsigned char *pixels;
+ cairo_surface_t *surface;
+
+ document = spectre_document_new ();
+ spectre_document_load (document, filename);
+ status = spectre_document_status (document);
+ if (status) {
+ spectre_document_free (document);
+ return spectre_status_to_string (status);
+ }
+
+ if (page_label) {
+ SpectrePage *page;
+ SpectreRenderContext *rc;
+
+ page = spectre_document_get_page_by_label (document, page_label);
+ spectre_document_free (document);
+ if (page == NULL)
+ return "page not found";
+
+ spectre_page_get_size (page, &width, &height);
+ rc = spectre_render_context_new ();
+ spectre_render_context_set_page_size (rc, width, height);
+ spectre_page_render (page, rc, &pixels, &stride);
+ spectre_render_context_free (rc);
+ status = spectre_page_status (page);
+ spectre_page_free (page);
+ if (status) {
+ free (pixels);
+ return spectre_status_to_string (status);
+ }
+ } else {
+ spectre_document_get_page_size (document, &width, &height);
+ spectre_document_render (document, &pixels, &stride);
+ spectre_document_free (document);
+ }
+
+ surface = cairo_image_surface_create_for_data (pixels,
+ CAIRO_FORMAT_RGB24,
+ width, height,
+ stride);
+ cairo_surface_set_user_data (surface, &key,
+ pixels, (cairo_destroy_func_t) free);
+ *surface_out = surface;
+ return NULL;
+}
+
+static const char *
ps_convert (char **argv, int fd)
{
- /* XXX libspectre */
+ const char *err;
+ cairo_surface_t *surface = NULL; /* silence compiler warning */
- return "no method to convert PS";
+ err = _spectre_render_page (argv[0], argv[1], &surface);
+ if (err != NULL)
+ return err;
+
+ err = write_ppm (surface, fd);
+ cairo_surface_destroy (surface);
+
+ return err;
}
#endif