diff --git a/AUTHORS b/AUTHORS index b922060b0..488f4c0b7 100644 --- a/AUTHORS +++ b/AUTHORS @@ -9,6 +9,7 @@ Christian Biesinger BeOS backend Billy Biggs Pixman code merge. Optimization. Fixes for subtle rendering bugs. Hans Breuer win32 bug fixes, build fixes, and improvements Brian Cameron Flag bug in Sun's X server +Carlos Garcia Campos libspectre integration into the test-suite Damien Carbery Build fixes Andrew Chant Adding const where needed Steve Chaplin Bug fixes for PNG reading diff --git a/configure.ac b/configure.ac index 2c5c4df1e..a3daae7ef 100644 --- a/configure.ac +++ b/configure.ac @@ -337,7 +337,9 @@ CAIRO_ENABLE_SURFACE_BACKEND(ps, PostScript, yes, [ dnl =========================================================================== +SPECTRE_VERSION_REQUIRED=0.2.0 test_ps=no +any2ppm_ps=no if test "x$use_ps" = "xyes"; then AC_CHECK_PROG(GS, gs, gs) if test "$GS"; then @@ -347,9 +349,16 @@ if test "x$use_ps" = "xyes"; then AC_MSG_WARN([PS backend will not be tested since ghostscript is not available]) test_ps="no (requires ghostscript)" fi + + libspectre_DEPENDENCY="libspectre >= $SPECTRE_VERSION_REQUIRED" + PKG_CHECK_MODULES(LIBSPECTRE, $libspectre_DEPENDENCY, + [any2ppm_ps=yes], + [AC_MSG_RESULT(no)]) fi AM_CONDITIONAL(CAIRO_CAN_TEST_PS_SURFACE, test "x$test_ps" = "xyes") +AC_SUBST(LIBSPECTRE_CFLAGS) +AC_SUBST(LIBSPECTRE_LIBS) dnl =========================================================================== @@ -365,11 +374,12 @@ dnl =========================================================================== # enhancement not to gobble nearly 1GiB of memory during test/large-font. POPPLER_VERSION_REQUIRED=0.9.2 test_pdf=no +any2ppm_pdf=no if test "x$use_pdf" = "xyes"; then poppler_DEPENDENCY="poppler-glib >= $POPPLER_VERSION_REQUIRED" PKG_CHECK_MODULES(POPPLER, $poppler_DEPENDENCY pango gtk+-2.0, [CAIRO_CHECK_FUNCS_WITH_FLAGS(poppler_page_render, [$POPPLER_CFLAGS], [$POPPLER_LIBS], - [test_pdf=yes], + [test_pdf=yes; any2ppm_pdf=yes], [AC_MSG_RESULT(no); test_pdf="no (requires $poppler_DEPENDENCY)"])], [AC_MSG_RESULT(no); test_pdf="no (requires $poppler_DEPENDENCY)"]) if test "x$test_pdf" = "xyes"; then @@ -395,11 +405,12 @@ CAIRO_ENABLE_SURFACE_BACKEND(svg, SVG, yes, [ LIBRSVG_VERSION_REQUIRED=2.15.0 test_svg=no +any2ppm_svg=no if test "x$use_svg" = "xyes"; then librsvg_DEPENDENCY="librsvg-2.0 >= $LIBRSVG_VERSION_REQUIRED" PKG_CHECK_MODULES(LIBRSVG, $librsvg_DEPENDENCY gdk-2.0, [CAIRO_CHECK_FUNCS_WITH_FLAGS(rsvg_pixbuf_from_file, [$LIBRSVG_CFLAGS], [$LIBRSVG_LIBS], - [test_svg=yes], + [test_svg=yes; any2ppm_svg=yes], [AC_MSG_RESULT(no); test_svg="no (requires $librsvg_DEPENDENCY)"])], [AC_MSG_RESULT(no); test_svg="no (requires $librsvg_DEPENDENCY)"]) if test "x$test_svg" = "xyes"; then @@ -436,8 +447,9 @@ CAIRO_ENABLE_FONT_BACKEND(user, user, always) dnl =========================================================================== dnl Build the external converter if we have any of the test backends AM_CONDITIONAL(BUILD_ANY2PPM, - test "x$test_svg" = "xyes" \ - -o "x$test_pdf" = "xyes" ) # -o "x$test_ps" = "xyes") + test "x$any2ppm_svg" = "xyes" \ + -o "x$any2ppm_pdf" = "xyes" \ + -o "x$any2ppm_ps" = "xyes") dnl =========================================================================== diff --git a/test/Makefile.am b/test/Makefile.am index 339bc18ab..8790a9058 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -1072,10 +1072,10 @@ check_PROGRAMS += imagediff png-flatten if BUILD_ANY2PPM check_PROGRAMS += any2ppm -any2ppm_CFLAGS = $(POPPLER_CFLAGS) $(LIBRSVG_CFLAGS) +any2ppm_CFLAGS = $(POPPLER_CFLAGS) $(LIBRSVG_CFLAGS) $(LIBSPECTRE_CFLAGS) # add LDADD, so poppler/librsvg uses "our" cairo any2ppm_LDFLAGS = $(CAIRO_TEST_UNDEFINED_LDFLAGS) -any2ppm_LDADD = $(LDADD) $(POPPLER_LIBS) $(LIBRSVG_LIBS) +any2ppm_LDADD = $(LDADD) $(POPPLER_LIBS) $(LIBRSVG_LIBS) $(LIBSPECTRE_LIBS) endif if CAIRO_CAN_TEST_PDF_SURFACE 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 * + * Contributor(s): + * Carlos Garcia Campos + * * Adapted from pdf2png.c: * Copyright © 2005 Red Hat, Inc. * @@ -70,6 +73,7 @@ #endif #if CAIRO_CAN_TEST_PS_SURFACE +#include #endif #if HAVE_FCNTL_H && HAVE_SIGNAL_H && HAVE_SYS_STAT_H && HAVE_SYS_SOCKET_H && HAVE_SYS_POLL_H && HAVE_SYS_UN_H @@ -346,12 +350,77 @@ svg_convert (char **argv, int fd) #endif #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