42
47
cairo_surface_t *target;
43
48
} ps_target_closure_t;
51
_cairo_boilerplate_ps_surface_set_creation_date (cairo_surface_t *abstract_surface,
54
cairo_paginated_surface_t *paginated = (cairo_paginated_surface_t*) abstract_surface;
55
cairo_ps_surface_t *surface;
57
if (cairo_surface_get_type (abstract_surface) != CAIRO_SURFACE_TYPE_PS)
58
return CAIRO_STATUS_SURFACE_TYPE_MISMATCH;
60
surface = (cairo_ps_surface_t*) paginated->target;
62
surface->has_creation_date = TRUE;
63
surface->creation_date = date;
65
return CAIRO_STATUS_SUCCESS;
46
69
_cairo_boilerplate_ps_create_surface (const char *name,
47
70
cairo_content_t content,
50
75
cairo_boilerplate_mode_t mode,
53
79
ps_target_closure_t *ptc;
54
80
cairo_surface_t *surface;
81
cairo_status_t status;
56
83
/* Sanitize back to a real cairo_content_t value. */
57
84
if (content == CAIRO_TEST_CONTENT_COLOR_ALPHA_FLATTENED)
60
87
*closure = ptc = xmalloc (sizeof (ps_target_closure_t));
62
xasprintf (&ptc->filename, "%s-ps-%s-out.ps",
63
name, cairo_boilerplate_content_name (content));
89
xasprintf (&ptc->filename, "%s-out.ps", name);
90
xunlink (ptc->filename);
65
92
ptc->width = width;
66
93
ptc->height = height;
68
95
surface = cairo_ps_surface_create (ptc->filename, width, height);
69
if (cairo_surface_status (surface)) {
96
if (cairo_surface_status (surface))
97
goto CLEANUP_FILENAME;
99
_cairo_boilerplate_ps_surface_set_creation_date (surface, 0);
74
100
cairo_surface_set_fallback_resolution (surface, 72., 72.);
76
102
if (content == CAIRO_CONTENT_COLOR) {
78
104
surface = cairo_surface_create_similar (ptc->target,
79
105
CAIRO_CONTENT_COLOR,
107
if (cairo_surface_status (surface))
82
110
ptc->target = NULL;
85
if (cairo_surface_set_user_data (surface,
88
NULL) != CAIRO_STATUS_SUCCESS) {
89
cairo_surface_destroy (surface);
90
if (ptc->target != NULL)
91
cairo_surface_destroy (ptc->target);
113
status = cairo_surface_set_user_data (surface, &ps_closure_key, ptc, NULL);
114
if (status == CAIRO_STATUS_SUCCESS)
117
cairo_surface_destroy (surface);
118
surface = cairo_boilerplate_surface_create_in_error (status);
121
cairo_surface_destroy (ptc->target);
123
free (ptc->filename);
101
_cairo_boilerplate_ps_surface_write_to_png (cairo_surface_t *surface, const char *filename)
129
_cairo_boilerplate_ps_finish_surface (cairo_surface_t *surface)
103
ps_target_closure_t *ptc = cairo_surface_get_user_data (surface, &ps_closure_key);
131
ps_target_closure_t *ptc = cairo_surface_get_user_data (surface,
133
cairo_status_t status;
106
135
/* Both surface and ptc->target were originally created at the
107
136
* same dimensions. We want a 1:1 copy here, so we first clear any
118
147
cairo_set_source_surface (cr, surface, 0, 0);
119
148
cairo_paint (cr);
120
149
cairo_show_page (cr);
150
status = cairo_status (cr);
121
151
cairo_destroy (cr);
123
156
cairo_surface_finish (surface);
157
status = cairo_surface_status (surface);
124
161
surface = ptc->target;
127
164
cairo_surface_finish (surface);
165
status = cairo_surface_status (surface);
169
return CAIRO_STATUS_SUCCESS;
173
_cairo_boilerplate_ps_surface_write_to_png (cairo_surface_t *surface, const char *filename)
175
ps_target_closure_t *ptc = cairo_surface_get_user_data (surface,
128
180
sprintf (command, "gs -q -r72 -g%dx%d -dSAFER -dBATCH -dNOPAUSE -sDEVICE=pngalpha -sOutputFile=%s %s",
129
181
ptc->width, ptc->height, filename, ptc->filename);
130
if (system (command) == 0)
131
return CAIRO_STATUS_SUCCESS;
132
return CAIRO_STATUS_WRITE_ERROR;
182
exitstatus = system (command);
183
#if _XOPEN_SOURCE && HAVE_SIGNAL_H
184
if (WIFSIGNALED (exitstatus))
185
raise (WTERMSIG (exitstatus));
188
return CAIRO_STATUS_WRITE_ERROR;
190
return CAIRO_STATUS_SUCCESS;
194
_cairo_boilerplate_ps_get_image_surface (cairo_surface_t *surface,
198
ps_target_closure_t *ptc = cairo_surface_get_user_data (surface,
201
cairo_status_t status;
203
xasprintf (&filename, "%s.png", ptc->filename);
204
status = _cairo_boilerplate_ps_surface_write_to_png (surface, filename);
206
return cairo_boilerplate_surface_create_in_error (status);
208
surface = cairo_boilerplate_get_image_surface_from_png (filename,
211
ptc->target == NULL);