1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
|
#include "fitz-internal.h"
fz_device *
fz_new_device(fz_context *ctx, void *user)
{
fz_device *dev = fz_malloc_struct(ctx, fz_device);
dev->hints = 0;
dev->flags = 0;
dev->user = user;
dev->ctx = ctx;
dev->error_depth = 0;
return dev;
}
void
fz_free_device(fz_device *dev)
{
if (dev == NULL)
return;
if (dev->free_user)
dev->free_user(dev);
fz_free(dev->ctx, dev);
}
void
fz_enable_device_hints(fz_device *dev, int hints)
{
dev->hints |= hints;
}
void
fz_disable_device_hints(fz_device *dev, int hints)
{
dev->hints &= ~hints;
}
void
fz_fill_path(fz_device *dev, fz_path *path, int even_odd, const fz_matrix *ctm,
fz_colorspace *colorspace, float *color, float alpha)
{
if (dev->error_depth)
return;
if (dev->fill_path)
dev->fill_path(dev, path, even_odd, ctm, colorspace, color, alpha);
}
void
fz_stroke_path(fz_device *dev, fz_path *path, fz_stroke_state *stroke, const fz_matrix *ctm,
fz_colorspace *colorspace, float *color, float alpha)
{
if (dev->error_depth)
return;
if (dev->stroke_path)
dev->stroke_path(dev, path, stroke, ctm, colorspace, color, alpha);
}
void
fz_clip_path(fz_device *dev, fz_path *path, const fz_rect *rect, int even_odd, const fz_matrix *ctm)
{
fz_context *ctx = dev->ctx;
if (dev->error_depth)
{
dev->error_depth++;
return;
}
fz_try(ctx)
{
if (dev->clip_path)
dev->clip_path(dev, path, rect, even_odd, ctm);
}
fz_catch(ctx)
{
dev->error_depth = 1;
strcpy(dev->errmess, fz_caught(ctx));
/* Error swallowed */
}
}
void
fz_clip_stroke_path(fz_device *dev, fz_path *path, const fz_rect *rect, fz_stroke_state *stroke, const fz_matrix *ctm)
{
fz_context *ctx = dev->ctx;
if (dev->error_depth)
{
dev->error_depth++;
return;
}
fz_try(ctx)
{
if (dev->clip_stroke_path)
dev->clip_stroke_path(dev, path, rect, stroke, ctm);
}
fz_catch(ctx)
{
dev->error_depth = 1;
strcpy(dev->errmess, fz_caught(ctx));
/* Error swallowed */
}
}
void
fz_fill_text(fz_device *dev, fz_text *text, const fz_matrix *ctm,
fz_colorspace *colorspace, float *color, float alpha)
{
if (dev->error_depth)
return;
if (dev->fill_text)
dev->fill_text(dev, text, ctm, colorspace, color, alpha);
}
void
fz_stroke_text(fz_device *dev, fz_text *text, fz_stroke_state *stroke, const fz_matrix *ctm,
fz_colorspace *colorspace, float *color, float alpha)
{
if (dev->error_depth)
return;
if (dev->stroke_text)
dev->stroke_text(dev, text, stroke, ctm, colorspace, color, alpha);
}
void
fz_clip_text(fz_device *dev, fz_text *text, const fz_matrix *ctm, int accumulate)
{
fz_context *ctx = dev->ctx;
if (dev->error_depth)
{
if (accumulate == 0 || accumulate == 1)
dev->error_depth++;
return;
}
fz_try(ctx)
{
if (dev->clip_text)
dev->clip_text(dev, text, ctm, accumulate);
}
fz_catch(ctx)
{
if (accumulate == 2)
fz_rethrow(ctx);
dev->error_depth = 1;
strcpy(dev->errmess, fz_caught(ctx));
/* Error swallowed */
}
}
void
fz_clip_stroke_text(fz_device *dev, fz_text *text, fz_stroke_state *stroke, const fz_matrix *ctm)
{
fz_context *ctx = dev->ctx;
if (dev->error_depth)
{
dev->error_depth++;
return;
}
fz_try(ctx)
{
if (dev->clip_stroke_text)
dev->clip_stroke_text(dev, text, stroke, ctm);
}
fz_catch(ctx)
{
dev->error_depth = 1;
strcpy(dev->errmess, fz_caught(ctx));
/* Error swallowed */
}
}
void
fz_ignore_text(fz_device *dev, fz_text *text, const fz_matrix *ctm)
{
if (dev->error_depth)
return;
if (dev->ignore_text)
dev->ignore_text(dev, text, ctm);
}
void
fz_pop_clip(fz_device *dev)
{
if (dev->error_depth)
{
dev->error_depth--;
if (dev->error_depth == 0)
fz_throw(dev->ctx, "%s", dev->errmess);
return;
}
if (dev->pop_clip)
dev->pop_clip(dev);
}
void
fz_fill_shade(fz_device *dev, fz_shade *shade, const fz_matrix *ctm, float alpha)
{
if (dev->error_depth)
return;
if (dev->fill_shade)
dev->fill_shade(dev, shade, ctm, alpha);
}
void
fz_fill_image(fz_device *dev, fz_image *image, const fz_matrix *ctm, float alpha)
{
if (dev->error_depth)
return;
if (dev->fill_image)
dev->fill_image(dev, image, ctm, alpha);
}
void
fz_fill_image_mask(fz_device *dev, fz_image *image, const fz_matrix *ctm,
fz_colorspace *colorspace, float *color, float alpha)
{
if (dev->error_depth)
return;
if (dev->fill_image_mask)
dev->fill_image_mask(dev, image, ctm, colorspace, color, alpha);
}
void
fz_clip_image_mask(fz_device *dev, fz_image *image, const fz_rect *rect, const fz_matrix *ctm)
{
fz_context *ctx = dev->ctx;
if (dev->error_depth)
{
dev->error_depth++;
return;
}
fz_try(ctx)
{
if (dev->clip_image_mask)
dev->clip_image_mask(dev, image, rect, ctm);
}
fz_catch(ctx)
{
dev->error_depth = 1;
strcpy(dev->errmess, fz_caught(ctx));
/* Error swallowed */
}
}
void
fz_begin_mask(fz_device *dev, const fz_rect *area, int luminosity, fz_colorspace *colorspace, float *bc)
{
fz_context *ctx = dev->ctx;
if (dev->error_depth)
{
dev->error_depth++;
return;
}
fz_try(ctx)
{
if (dev->begin_mask)
dev->begin_mask(dev, area, luminosity, colorspace, bc);
}
fz_catch(ctx)
{
dev->error_depth = 1;
strcpy(dev->errmess, fz_caught(ctx));
/* Error swallowed */
}
}
void
fz_end_mask(fz_device *dev)
{
if (dev->error_depth)
{
/* Converts from mask to clip, so no change in stack depth */
return;
}
if (dev->end_mask)
dev->end_mask(dev);
}
void
fz_begin_group(fz_device *dev, const fz_rect *area, int isolated, int knockout, int blendmode, float alpha)
{
fz_context *ctx = dev->ctx;
if (dev->error_depth)
{
dev->error_depth++;
return;
}
fz_try(ctx)
{
if (dev->begin_group)
dev->begin_group(dev, area, isolated, knockout, blendmode, alpha);
}
fz_catch(ctx)
{
dev->error_depth = 1;
strcpy(dev->errmess, fz_caught(ctx));
/* Error swallowed */
}
}
void
fz_end_group(fz_device *dev)
{
if (dev->error_depth)
{
dev->error_depth--;
if (dev->error_depth == 0)
fz_throw(dev->ctx, "%s", dev->errmess);
return;
}
if (dev->end_group)
dev->end_group(dev);
}
void
fz_begin_tile(fz_device *dev, const fz_rect *area, const fz_rect *view, float xstep, float ystep, const fz_matrix *ctm)
{
(void)fz_begin_tile_id(dev, area, view, xstep, ystep, ctm, 0);
}
int
fz_begin_tile_id(fz_device *dev, const fz_rect *area, const fz_rect *view, float xstep, float ystep, const fz_matrix *ctm, int id)
{
fz_context *ctx = dev->ctx;
int ret = 0;
if (dev->error_depth)
{
dev->error_depth++;
return 0;
}
fz_try(ctx)
{
if (dev->begin_tile)
ret = dev->begin_tile(dev, area, view, xstep, ystep, ctm, id);
}
fz_catch(ctx)
{
dev->error_depth = 1;
strcpy(dev->errmess, fz_caught(ctx));
/* Error swallowed */
}
return ret;
}
void
fz_end_tile(fz_device *dev)
{
if (dev->error_depth)
{
dev->error_depth--;
if (dev->error_depth == 0)
fz_throw(dev->ctx, "%s", dev->errmess);
return;
}
if (dev->end_tile)
dev->end_tile(dev);
}
|