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

« back to all changes in this revision

Viewing changes to boilerplate/cairo-boilerplate-pdf.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-pdf-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 pdf_closure_key;
36
41
 
37
42
typedef struct _pdf_target_closure
49
54
                                       cairo_content_t            content,
50
55
                                       int                        width,
51
56
                                       int                        height,
 
57
                                       int                        max_width,
 
58
                                       int                        max_height,
52
59
                                       cairo_boilerplate_mode_t   mode,
 
60
                                       int                        id,
53
61
                                       void                     **closure)
54
62
{
55
63
    pdf_target_closure_t *ptc;
56
64
    cairo_surface_t *surface;
 
65
    cairo_status_t status;
57
66
 
58
67
    /* Sanitize back to a real cairo_content_t value. */
59
68
    if (content == CAIRO_TEST_CONTENT_COLOR_ALPHA_FLATTENED)
64
73
    ptc->width = width;
65
74
    ptc->height = height;
66
75
 
67
 
    xasprintf (&ptc->filename, "%s-pdf-%s-out.pdf",
68
 
               name, cairo_boilerplate_content_name (content));
 
76
    xasprintf (&ptc->filename, "%s-out.pdf", name);
 
77
    xunlink (ptc->filename);
69
78
 
70
79
    surface = cairo_pdf_surface_create (ptc->filename, width, height);
71
 
    if (cairo_surface_status (surface)) {
72
 
        free (ptc->filename);
73
 
        free (ptc);
74
 
        return NULL;
75
 
    }
 
80
    if (cairo_surface_status (surface))
 
81
        goto CLEANUP_FILENAME;
 
82
 
76
83
    cairo_surface_set_fallback_resolution (surface, 72., 72.);
77
84
 
78
85
    if (content == CAIRO_CONTENT_COLOR) {
80
87
        surface = cairo_surface_create_similar (ptc->target,
81
88
                                                CAIRO_CONTENT_COLOR,
82
89
                                                width, height);
 
90
        if (cairo_surface_status (surface))
 
91
            goto CLEANUP_TARGET;
83
92
    } else {
84
93
        ptc->target = NULL;
85
94
    }
86
95
 
87
 
    cairo_boilerplate_surface_set_user_data (surface,
88
 
                                             &pdf_closure_key,
89
 
                                             ptc, NULL);
90
 
 
 
96
    status = cairo_surface_set_user_data (surface, &pdf_closure_key, ptc, NULL);
 
97
    if (status == CAIRO_STATUS_SUCCESS)
 
98
        return surface;
 
99
 
 
100
    cairo_surface_destroy (surface);
 
101
    surface = cairo_boilerplate_surface_create_in_error (status);
 
102
 
 
103
  CLEANUP_TARGET:
 
104
    cairo_surface_destroy (ptc->target);
 
105
  CLEANUP_FILENAME:
 
106
    free (ptc->filename);
 
107
    free (ptc);
91
108
    return surface;
92
109
}
93
110
 
94
111
cairo_status_t
95
 
_cairo_boilerplate_pdf_surface_write_to_png (cairo_surface_t *surface, const char *filename)
 
112
_cairo_boilerplate_pdf_finish_surface (cairo_surface_t          *surface)
96
113
{
97
 
    pdf_target_closure_t *ptc = cairo_surface_get_user_data (surface, &pdf_closure_key);
98
 
    char    command[4096];
 
114
    pdf_target_closure_t *ptc = cairo_surface_get_user_data (surface,
 
115
                                                             &pdf_closure_key);
 
116
    cairo_status_t status;
99
117
 
100
118
    /* Both surface and ptc->target were originally created at the
101
119
     * same dimensions. We want a 1:1 copy here, so we first clear any
112
130
        cairo_set_source_surface (cr, surface, 0, 0);
113
131
        cairo_paint (cr);
114
132
        cairo_show_page (cr);
 
133
        status = cairo_status (cr);
115
134
        cairo_destroy (cr);
116
135
 
 
136
        if (status)
 
137
            return status;
 
138
 
117
139
        cairo_surface_finish (surface);
 
140
        status = cairo_surface_status (surface);
 
141
        if (status)
 
142
            return status;
 
143
 
118
144
        surface = ptc->target;
119
145
    }
120
146
 
121
147
    cairo_surface_finish (surface);
 
148
    status = cairo_surface_status (surface);
 
149
    if (status)
 
150
        return status;
 
151
 
 
152
    return CAIRO_STATUS_SUCCESS;
 
153
}
 
154
 
 
155
cairo_status_t
 
156
_cairo_boilerplate_pdf_surface_write_to_png (cairo_surface_t *surface, const char *filename)
 
157
{
 
158
    pdf_target_closure_t *ptc = cairo_surface_get_user_data (surface, &pdf_closure_key);
 
159
    char    command[4096];
 
160
    int exitstatus;
 
161
 
122
162
    sprintf (command, "./pdf2png %s %s 1",
123
163
             ptc->filename, filename);
124
164
 
125
 
    if (system (command) != 0)
 
165
    exitstatus = system (command);
 
166
#if _XOPEN_SOURCE && HAVE_SIGNAL_H
 
167
    if (WIFSIGNALED (exitstatus))
 
168
        raise (WTERMSIG (exitstatus));
 
169
#endif
 
170
    if (exitstatus)
126
171
        return CAIRO_STATUS_WRITE_ERROR;
127
172
 
128
173
    return CAIRO_STATUS_SUCCESS;
129
174
}
130
175
 
 
176
static cairo_surface_t *
 
177
_cairo_boilerplate_pdf_convert_to_image (cairo_surface_t *surface)
 
178
{
 
179
    pdf_target_closure_t *ptc = cairo_surface_get_user_data (surface,
 
180
                                                             &pdf_closure_key);
 
181
    FILE *file;
 
182
    cairo_surface_t *image;
 
183
 
 
184
    file = cairo_boilerplate_open_any2ppm (ptc->filename, 1);
 
185
    if (file == NULL)
 
186
        return cairo_boilerplate_surface_create_in_error (CAIRO_STATUS_READ_ERROR);
 
187
 
 
188
    image = cairo_boilerplate_image_surface_create_from_ppm_stream (file);
 
189
    fclose (file);
 
190
 
 
191
    return image;
 
192
}
 
193
 
 
194
cairo_surface_t *
 
195
_cairo_boilerplate_pdf_get_image_surface (cairo_surface_t *surface,
 
196
                                          int width,
 
197
                                          int height)
 
198
{
 
199
    cairo_surface_t *image;
 
200
 
 
201
    image = _cairo_boilerplate_pdf_convert_to_image (surface);
 
202
    cairo_surface_set_device_offset (image,
 
203
                                     cairo_image_surface_get_width (image) - width,
 
204
                                     cairo_image_surface_get_height (image) - height);
 
205
    surface = _cairo_boilerplate_get_image_surface (image, width, height);
 
206
    cairo_surface_destroy (image);
 
207
 
 
208
    return surface;
 
209
}
 
210
 
131
211
void
132
212
_cairo_boilerplate_pdf_cleanup (void *closure)
133
213
{