Skip to content

Commit

Permalink
[test/any2ppm] Enable PS conversion using libspectre.
Browse files Browse the repository at this point in the history
Complete the vector trilogy using libspectre to provide a similar
interface (to poppler and librsvg) around GhostScript.
  • Loading branch information
Carlos Garcia Campos authored and Chris Wilson committed Oct 9, 2008
1 parent ddd1615 commit 3e6afb3
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 8 deletions.
1 change: 1 addition & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ Christian Biesinger <cbiesinger@web.de> BeOS backend
Billy Biggs <vektor@dumbterm.net> Pixman code merge. Optimization. Fixes for subtle rendering bugs.
Hans Breuer <hans@breuer.org> win32 bug fixes, build fixes, and improvements
Brian Cameron <brian.cameron@sun.com> Flag bug in Sun's X server
Carlos Garcia Campos <carlosgc@gnome.org> libspectre integration into the test-suite
Damien Carbery <damien.carbery@sun.com> Build fixes
Andrew Chant <andrew.chant@utoronto.ca> Adding const where needed
Steve Chaplin <stevech1097@yahoo.com.au> Bug fixes for PNG reading
Expand Down
20 changes: 16 additions & 4 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 ===========================================================================

Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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 ===========================================================================

Expand Down
4 changes: 2 additions & 2 deletions test/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
73 changes: 71 additions & 2 deletions test/any2ppm.c
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down

0 comments on commit 3e6afb3

Please sign in to comment.