[cairo-commit]
cairo/test .cvsignore, 1.57, 1.58 Makefile.am, 1.100,
1.101 cairo-test.c, 1.64, 1.65 pdf2png.c, NONE, 1.1
Carl Worth
commit at pdx.freedesktop.org
Wed Dec 7 16:06:14 PST 2005
Committed by: cworth
Update of /cvs/cairo/cairo/test
In directory gabe:/tmp/cvs-serv21078/test
Modified Files:
.cvsignore Makefile.am cairo-test.c
Added Files:
pdf2png.c
Log Message:
2005-12-07 Carl Worth <cworth at cworth.org>
* configure.in: Add checks for poppler and friends which are
needed by pdf2png. Set CAIRO_CAN_TEST_PDF_SURFACE as both a
#define and an automake conditional.
* test/Makefile.am: Build pdf2png if possible.
* test/cairo-test.c: (create_pdf_surface),
(pdf_surface_write_to_png), (cleanup_pdf), (cairo_test_expecting):
Add support for testing the PDF backend.
* test/pdf2png.c: (main): New utility program to convert a PDF
file into a PNG image using poppler (thanks to Kristian Høgsberg).
* test/.cvsignore: Ignore new stuff generated by PDF backend
testing.
Index: .cvsignore
===================================================================
RCS file: /cvs/cairo/cairo/test/.cvsignore,v
retrieving revision 1.57
retrieving revision 1.58
diff -u -d -r1.57 -r1.58
--- .cvsignore 12 Oct 2005 20:37:00 -0000 1.57
+++ .cvsignore 8 Dec 2005 00:06:12 -0000 1.58
@@ -40,6 +40,7 @@
paint
paint-with-alpha
path-data
+pdf2png
pdf-clip
pdf-clip.pdf
pdf-surface
@@ -76,6 +77,8 @@
*-image-out.png
*-image-argb32-out.png
*-image-rgb24-out.png
+*-pdf-rgb24-out.png
+*-pdf-rgb24-out.pdf
*-ps-rgb24-out.png
*-ps-rgb24-out.ps
*-xcb-out.png
Index: Makefile.am
===================================================================
RCS file: /cvs/cairo/cairo/test/Makefile.am,v
retrieving revision 1.100
retrieving revision 1.101
diff -u -d -r1.100 -r1.101
--- Makefile.am 14 Oct 2005 04:04:28 -0000 1.100
+++ Makefile.am 8 Dec 2005 00:06:12 -0000 1.101
@@ -327,6 +327,12 @@
noinst_PROGRAMS = imagediff
imagediff_LDADD = $(LDADDS)
+if CAIRO_CAN_TEST_PDF_SURFACE
+noinst_PROGRAMS += pdf2png
+pdf2png_CFLAGS = $(POPPLER_CFLAGS)
+pdf2png_LDADD = $(LDADDS) $(POPPLER_LIBS)
+endif
+
CLEANFILES = \
*.ps \
*-out.png \
Index: cairo-test.c
===================================================================
RCS file: /cvs/cairo/cairo/test/cairo-test.c,v
retrieving revision 1.64
retrieving revision 1.65
diff -u -d -r1.64 -r1.65
--- cairo-test.c 7 Dec 2005 19:53:30 -0000 1.64
+++ cairo-test.c 8 Dec 2005 00:06:12 -0000 1.65
@@ -574,8 +574,74 @@
free (ptc->filename);
free (ptc);
}
+#endif /* CAIRO_HAS_PS_SURFACE */
-#endif
+#if CAIRO_HAS_PDF_SURFACE && CAIRO_CAN_TEST_PDF_SURFACE
+#include "cairo-pdf.h"
+
+cairo_user_data_key_t pdf_closure_key;
+
+typedef struct _pdf_target_closure
+{
+ char *filename;
+ int width;
+ int height;
+} pdf_target_closure_t;
+
+static cairo_surface_t *
+create_pdf_surface (cairo_test_t *test,
+ cairo_format_t format,
+ void **closure)
+{
+ int width = test->width;
+ int height = test->height;
+ pdf_target_closure_t *ptc;
+ cairo_surface_t *surface;
+
+ /* XXX: Is this the only format supported by the PDF surface backend? */
+ assert (format == CAIRO_FORMAT_RGB24);
+
+ *closure = ptc = xmalloc (sizeof (pdf_target_closure_t));
+
+ ptc->width = width;
+ ptc->height = height;
+
+ xasprintf (&ptc->filename, "%s-%s%s", test->name, "pdf-rgb24-out", ".pdf");
+ surface = cairo_pdf_surface_create (ptc->filename, width, height);
+ if (cairo_surface_status (surface)) {
+ free (ptc->filename);
+ free (ptc);
+ return NULL;
+ }
+ cairo_pdf_surface_set_dpi (surface, 72., 72.);
+ cairo_surface_set_user_data (surface, &pdf_closure_key, ptc, NULL);
+ return surface;
+}
+
+static cairo_status_t
+pdf_surface_write_to_png (cairo_surface_t *surface, const char *filename)
+{
+ pdf_target_closure_t *ptc = cairo_surface_get_user_data (surface, &pdf_closure_key);
+ char command[4096];
+
+ cairo_surface_finish (surface);
+ sprintf (command, "./pdf2png %s %s 1",
+ ptc->filename, filename);
+
+ if (system (command) != 0)
+ return CAIRO_STATUS_WRITE_ERROR;
+
+ return CAIRO_STATUS_SUCCESS;
+}
+
+static void
+cleanup_pdf (void *closure)
+{
+ pdf_target_closure_t *ptc = closure;
+ free (ptc->filename);
+ free (ptc);
+}
+#endif /* CAIRO_HAS_PDF_SURFACE && CAIRO_CAN_TEST_PDF_SURFACE */
static cairo_test_status_t
cairo_test_for_target (cairo_test_t *test,
@@ -725,7 +791,7 @@
{ "ps", CAIRO_FORMAT_RGB24,
create_ps_surface, ps_surface_write_to_png, cleanup_ps },
#endif
-#if 0 && CAIRO_HAS_PDF_SURFACE
+#if CAIRO_HAS_PDF_SURFACE && CAIRO_CAN_TEST_PDF_SURFACE
{ "pdf", CAIRO_FORMAT_RGB24,
create_pdf_surface, pdf_surface_write_to_png, cleanup_pdf },
#endif
--- NEW FILE: pdf2png.c ---
(This appears to be a binary file; contents omitted.)
More information about the cairo-commit
mailing list