Skip to content

Commit

Permalink
[boilerplate] Add a PS 2 target.
Browse files Browse the repository at this point in the history
Ensure that we can generate PS2 output when required by creating a PS
level 2 target and using GhostScript for conformance testing.
  • Loading branch information
Chris Wilson committed Sep 26, 2008
1 parent 0c030d3 commit e0f2147
Show file tree
Hide file tree
Showing 192 changed files with 277 additions and 116 deletions.
29 changes: 20 additions & 9 deletions boilerplate/cairo-boilerplate-ps-private.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,26 @@
#define _CAIRO_BOILERPLATE_PS_PRIVATE_H_

cairo_surface_t *
_cairo_boilerplate_ps_create_surface (const char *name,
cairo_content_t content,
int width,
int height,
int max_width,
int max_height,
cairo_boilerplate_mode_t mode,
int id,
void **closure);
_cairo_boilerplate_ps2_create_surface (const char *name,
cairo_content_t content,
int width,
int height,
int max_width,
int max_height,
cairo_boilerplate_mode_t mode,
int id,
void **closure);

cairo_surface_t *
_cairo_boilerplate_ps3_create_surface (const char *name,
cairo_content_t content,
int width,
int height,
int max_width,
int max_height,
cairo_boilerplate_mode_t mode,
int id,
void **closure);

void
_cairo_boilerplate_ps_cleanup (void *closure);
Expand Down
55 changes: 49 additions & 6 deletions boilerplate/cairo-boilerplate-ps.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,14 @@
#include <signal.h>
#endif

cairo_user_data_key_t ps_closure_key;
static const cairo_user_data_key_t ps_closure_key;

typedef struct _ps_target_closure
{
typedef struct _ps_target_closure {
char *filename;
int width;
int height;
cairo_surface_t *target;
cairo_ps_level_t level;
} ps_target_closure_t;

static cairo_status_t
Expand All @@ -65,9 +65,10 @@ _cairo_boilerplate_ps_surface_set_creation_date (cairo_surface_t *abstract_surfa
return CAIRO_STATUS_SUCCESS;
}

cairo_surface_t *
static cairo_surface_t *
_cairo_boilerplate_ps_create_surface (const char *name,
cairo_content_t content,
cairo_ps_level_t level,
int width,
int height,
int max_width,
Expand All @@ -89,13 +90,15 @@ _cairo_boilerplate_ps_create_surface (const char *name,
xasprintf (&ptc->filename, "%s-out.ps", name);
xunlink (ptc->filename);

ptc->level = level;
ptc->width = width;
ptc->height = height;

surface = cairo_ps_surface_create (ptc->filename, width, height);
if (cairo_surface_status (surface))
goto CLEANUP_FILENAME;

cairo_ps_surface_restrict_to_level (surface, level);
_cairo_boilerplate_ps_surface_set_creation_date (surface, 0);
cairo_surface_set_fallback_resolution (surface, 72., 72.);

Expand Down Expand Up @@ -125,6 +128,44 @@ _cairo_boilerplate_ps_create_surface (const char *name,
return surface;
}

cairo_surface_t *
_cairo_boilerplate_ps2_create_surface (const char *name,
cairo_content_t content,
int width,
int height,
int max_width,
int max_height,
cairo_boilerplate_mode_t mode,
int id,
void **closure)
{
return _cairo_boilerplate_ps_create_surface (name, content,
CAIRO_PS_LEVEL_2,
width, height,
max_width, max_height,
mode, id,
closure);
}

cairo_surface_t *
_cairo_boilerplate_ps3_create_surface (const char *name,
cairo_content_t content,
int width,
int height,
int max_width,
int max_height,
cairo_boilerplate_mode_t mode,
int id,
void **closure)
{
return _cairo_boilerplate_ps_create_surface (name, content,
CAIRO_PS_LEVEL_3,
width, height,
max_width, max_height,
mode, id,
closure);
}

cairo_status_t
_cairo_boilerplate_ps_finish_surface (cairo_surface_t *surface)
{
Expand Down Expand Up @@ -177,8 +218,10 @@ _cairo_boilerplate_ps_surface_write_to_png (cairo_surface_t *surface, const char
char command[4096];
int exitstatus;

sprintf (command, "gs -q -r72 -g%dx%d -dSAFER -dBATCH -dNOPAUSE -sDEVICE=pngalpha -sOutputFile=%s %s",
ptc->width, ptc->height, filename, ptc->filename);
sprintf (command, "gs -q -r72 -g%dx%d -dSAFER -dBATCH -dNOPAUSE -sDEVICE=pngalpha -sOutputFile=%s %s %s",
ptc->width, ptc->height, filename,
ptc->level == CAIRO_PS_LEVEL_2 ? "-c 2 .setlanguagelevel -f" : "",
ptc->filename);
exitstatus = system (command);
#if _XOPEN_SOURCE && HAVE_SIGNAL_H
if (WIFSIGNALED (exitstatus))
Expand Down
23 changes: 19 additions & 4 deletions boilerplate/cairo-boilerplate.c
Original file line number Diff line number Diff line change
Expand Up @@ -445,16 +445,31 @@ static cairo_boilerplate_target_t targets[] =
_cairo_boilerplate_xlib_synchronize},
#endif
#if CAIRO_HAS_PS_SURFACE && CAIRO_CAN_TEST_PS_SURFACE
{ "ps", ".ps", CAIRO_SURFACE_TYPE_PS,
{ "ps2", ".ps", CAIRO_SURFACE_TYPE_PS,
CAIRO_TEST_CONTENT_COLOR_ALPHA_FLATTENED, 0,
_cairo_boilerplate_ps_create_surface,
_cairo_boilerplate_ps2_create_surface,
_cairo_boilerplate_ps_finish_surface,
_cairo_boilerplate_ps_get_image_surface,
_cairo_boilerplate_ps_surface_write_to_png,
_cairo_boilerplate_ps_cleanup,
NULL, TRUE },
{ "ps", ".ps", CAIRO_INTERNAL_SURFACE_TYPE_META, CAIRO_CONTENT_COLOR, 0,
_cairo_boilerplate_ps_create_surface,
{ "ps2", ".ps", CAIRO_INTERNAL_SURFACE_TYPE_META, CAIRO_CONTENT_COLOR, 0,
_cairo_boilerplate_ps2_create_surface,
_cairo_boilerplate_ps_finish_surface,
_cairo_boilerplate_ps_get_image_surface,
_cairo_boilerplate_ps_surface_write_to_png,
_cairo_boilerplate_ps_cleanup,
NULL, TRUE },
{ "ps3", ".ps", CAIRO_SURFACE_TYPE_PS,
CAIRO_TEST_CONTENT_COLOR_ALPHA_FLATTENED, 0,
_cairo_boilerplate_ps3_create_surface,
_cairo_boilerplate_ps_finish_surface,
_cairo_boilerplate_ps_get_image_surface,
_cairo_boilerplate_ps_surface_write_to_png,
_cairo_boilerplate_ps_cleanup,
NULL, TRUE },
{ "ps3", ".ps", CAIRO_INTERNAL_SURFACE_TYPE_META, CAIRO_CONTENT_COLOR, 0,
_cairo_boilerplate_ps3_create_surface,
_cairo_boilerplate_ps_finish_surface,
_cairo_boilerplate_ps_get_image_surface,
_cairo_boilerplate_ps_surface_write_to_png,
Expand Down
Loading

0 comments on commit e0f2147

Please sign in to comment.