~ubuntu-branches/ubuntu/intrepid/cairo/intrepid-updates

« back to all changes in this revision

Viewing changes to boilerplate/cairo-boilerplate-ps.c

  • Committer: Bazaar Package Importer
  • Author(s): Fabien Tassin
  • Date: 2008-09-25 16:22:33 UTC
  • mfrom: (1.1.9 upstream)
  • Revision ID: james.westby@ubuntu.com-20080925162233-btx61ymk181i7mcc
Tags: 1.7.6-0ubuntu1
* New upstream version. Most noticable changes are:
  - some API changes with especially the removal of
    cairo_font_options_set_lcd_filter and cairo_font_options_get_lcd_filter
  - xlib: Faster bookkeeping
  - PS: Fix gradients with non-constant alpha
  - Fix deadlock in user-font code
* debian/patches/00list: Remove 03_from_git_fix_lcd_filter_default.dpatch,
  add debian/patches/03_fix_ftbfs_withing_xcb.dpatch
* debian/libcairo2.symbols, debian/libcairo-directfb2.symbols: update
  list of symbols

Show diffs side-by-side

added added

removed removed

Lines of Context:
32
32
#include <cairo-ps-surface-private.h>
33
33
#include <cairo-paginated-surface-private.h>
34
34
 
 
35
#if HAVE_SIGNAL_H
 
36
#include <stdlib.h>
 
37
#include <signal.h>
 
38
#endif
 
39
 
35
40
cairo_user_data_key_t   ps_closure_key;
36
41
 
37
42
typedef struct _ps_target_closure
42
47
    cairo_surface_t     *target;
43
48
} ps_target_closure_t;
44
49
 
 
50
static cairo_status_t
 
51
_cairo_boilerplate_ps_surface_set_creation_date (cairo_surface_t *abstract_surface,
 
52
                                                 time_t date)
 
53
{
 
54
    cairo_paginated_surface_t *paginated = (cairo_paginated_surface_t*) abstract_surface;
 
55
    cairo_ps_surface_t *surface;
 
56
 
 
57
    if (cairo_surface_get_type (abstract_surface) != CAIRO_SURFACE_TYPE_PS)
 
58
        return CAIRO_STATUS_SURFACE_TYPE_MISMATCH;
 
59
 
 
60
    surface = (cairo_ps_surface_t*) paginated->target;
 
61
 
 
62
    surface->has_creation_date = TRUE;
 
63
    surface->creation_date = date;
 
64
 
 
65
    return CAIRO_STATUS_SUCCESS;
 
66
}
 
67
 
45
68
cairo_surface_t *
46
69
_cairo_boilerplate_ps_create_surface (const char                 *name,
47
70
                                      cairo_content_t             content,
48
71
                                      int                         width,
49
72
                                      int                         height,
 
73
                                      int                         max_width,
 
74
                                      int                         max_height,
50
75
                                      cairo_boilerplate_mode_t    mode,
 
76
                                      int                         id,
51
77
                                      void                      **closure)
52
78
{
53
79
    ps_target_closure_t *ptc;
54
80
    cairo_surface_t *surface;
 
81
    cairo_status_t status;
55
82
 
56
83
    /* Sanitize back to a real cairo_content_t value. */
57
84
    if (content == CAIRO_TEST_CONTENT_COLOR_ALPHA_FLATTENED)
59
86
 
60
87
    *closure = ptc = xmalloc (sizeof (ps_target_closure_t));
61
88
 
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);
64
91
 
65
92
    ptc->width = width;
66
93
    ptc->height = height;
67
94
 
68
95
    surface = cairo_ps_surface_create (ptc->filename, width, height);
69
 
    if (cairo_surface_status (surface)) {
70
 
        free (ptc->filename);
71
 
        free (ptc);
72
 
        return NULL;
73
 
    }
 
96
    if (cairo_surface_status (surface))
 
97
        goto CLEANUP_FILENAME;
 
98
 
 
99
    _cairo_boilerplate_ps_surface_set_creation_date (surface, 0);
74
100
    cairo_surface_set_fallback_resolution (surface, 72., 72.);
75
101
 
76
102
    if (content == CAIRO_CONTENT_COLOR) {
78
104
        surface = cairo_surface_create_similar (ptc->target,
79
105
                                                CAIRO_CONTENT_COLOR,
80
106
                                                width, height);
 
107
        if (cairo_surface_status (surface))
 
108
            goto CLEANUP_TARGET;
81
109
    } else {
82
110
        ptc->target = NULL;
83
111
    }
84
112
 
85
 
    if (cairo_surface_set_user_data (surface,
86
 
                                     &ps_closure_key,
87
 
                                     ptc,
88
 
                                     NULL) != CAIRO_STATUS_SUCCESS) {
89
 
        cairo_surface_destroy (surface);
90
 
        if (ptc->target != NULL)
91
 
            cairo_surface_destroy (ptc->target);
92
 
        free (ptc->filename);
93
 
        free (ptc);
94
 
        return NULL;
95
 
    }
96
 
 
 
113
    status = cairo_surface_set_user_data (surface, &ps_closure_key, ptc, NULL);
 
114
    if (status == CAIRO_STATUS_SUCCESS)
 
115
        return surface;
 
116
 
 
117
    cairo_surface_destroy (surface);
 
118
    surface = cairo_boilerplate_surface_create_in_error (status);
 
119
 
 
120
  CLEANUP_TARGET:
 
121
    cairo_surface_destroy (ptc->target);
 
122
  CLEANUP_FILENAME:
 
123
    free (ptc->filename);
 
124
    free (ptc);
97
125
    return surface;
98
126
}
99
127
 
100
128
cairo_status_t
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)
102
130
{
103
 
    ps_target_closure_t *ptc = cairo_surface_get_user_data (surface, &ps_closure_key);
104
 
    char    command[4096];
 
131
    ps_target_closure_t *ptc = cairo_surface_get_user_data (surface,
 
132
                                                            &ps_closure_key);
 
133
    cairo_status_t status;
105
134
 
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);
122
152
 
 
153
        if (status)
 
154
            return status;
 
155
 
123
156
        cairo_surface_finish (surface);
 
157
        status = cairo_surface_status (surface);
 
158
        if (status)
 
159
            return status;
 
160
 
124
161
        surface = ptc->target;
125
162
    }
126
163
 
127
164
    cairo_surface_finish (surface);
 
165
    status = cairo_surface_status (surface);
 
166
    if (status)
 
167
        return status;
 
168
 
 
169
    return CAIRO_STATUS_SUCCESS;
 
170
}
 
171
 
 
172
cairo_status_t
 
173
_cairo_boilerplate_ps_surface_write_to_png (cairo_surface_t *surface, const char *filename)
 
174
{
 
175
    ps_target_closure_t *ptc = cairo_surface_get_user_data (surface,
 
176
                                                            &ps_closure_key);
 
177
    char    command[4096];
 
178
    int exitstatus;
 
179
 
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));
 
186
#endif
 
187
    if (exitstatus)
 
188
        return CAIRO_STATUS_WRITE_ERROR;
 
189
 
 
190
    return CAIRO_STATUS_SUCCESS;
 
191
}
 
192
 
 
193
cairo_surface_t *
 
194
_cairo_boilerplate_ps_get_image_surface (cairo_surface_t *surface,
 
195
                                          int width,
 
196
                                          int height)
 
197
{
 
198
    ps_target_closure_t *ptc = cairo_surface_get_user_data (surface,
 
199
                                                            &ps_closure_key);
 
200
    char *filename;
 
201
    cairo_status_t status;
 
202
 
 
203
    xasprintf (&filename, "%s.png", ptc->filename);
 
204
    status = _cairo_boilerplate_ps_surface_write_to_png (surface, filename);
 
205
    if (status)
 
206
        return cairo_boilerplate_surface_create_in_error (status);
 
207
 
 
208
    surface = cairo_boilerplate_get_image_surface_from_png (filename,
 
209
                                                            width,
 
210
                                                            height,
 
211
                                                            ptc->target == NULL);
 
212
 
 
213
    remove (filename);
 
214
    free (filename);
 
215
 
 
216
    return surface;
133
217
}
134
218
 
135
219
void