Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download
7858 views
1
#ifndef MUPDF_FITZ_DEVICE_H
2
#define MUPDF_FITZ_DEVICE_H
3
4
#include "mupdf/fitz/system.h"
5
#include "mupdf/fitz/context.h"
6
#include "mupdf/fitz/math.h"
7
#include "mupdf/fitz/colorspace.h"
8
#include "mupdf/fitz/image.h"
9
#include "mupdf/fitz/shade.h"
10
#include "mupdf/fitz/path.h"
11
#include "mupdf/fitz/text.h"
12
13
/*
14
The different format handlers (pdf, xps etc) interpret pages to a
15
device. These devices can then process the stream of calls they
16
recieve in various ways:
17
The trace device outputs debugging information for the calls.
18
The draw device will render them.
19
The list device stores them in a list to play back later.
20
The text device performs text extraction and searching.
21
The bbox device calculates the bounding box for the page.
22
Other devices can (and will) be written in future.
23
*/
24
typedef struct fz_device_s fz_device;
25
26
enum
27
{
28
/* Flags */
29
FZ_DEVFLAG_MASK = 1,
30
FZ_DEVFLAG_COLOR = 2,
31
FZ_DEVFLAG_UNCACHEABLE = 4,
32
FZ_DEVFLAG_FILLCOLOR_UNDEFINED = 8,
33
FZ_DEVFLAG_STROKECOLOR_UNDEFINED = 16,
34
FZ_DEVFLAG_STARTCAP_UNDEFINED = 32,
35
FZ_DEVFLAG_DASHCAP_UNDEFINED = 64,
36
FZ_DEVFLAG_ENDCAP_UNDEFINED = 128,
37
FZ_DEVFLAG_LINEJOIN_UNDEFINED = 256,
38
FZ_DEVFLAG_MITERLIMIT_UNDEFINED = 512,
39
FZ_DEVFLAG_LINEWIDTH_UNDEFINED = 1024,
40
/* Arguably we should have a bit for the dash pattern itself being
41
* undefined, but that causes problems; do we assume that it should
42
* always be set to non-dashing at the start of every glyph? */
43
FZ_DEVFLAG_BBOX_DEFINED = 2048,
44
};
45
46
enum
47
{
48
/* PDF 1.4 -- standard separable */
49
FZ_BLEND_NORMAL,
50
FZ_BLEND_MULTIPLY,
51
FZ_BLEND_SCREEN,
52
FZ_BLEND_OVERLAY,
53
FZ_BLEND_DARKEN,
54
FZ_BLEND_LIGHTEN,
55
FZ_BLEND_COLOR_DODGE,
56
FZ_BLEND_COLOR_BURN,
57
FZ_BLEND_HARD_LIGHT,
58
FZ_BLEND_SOFT_LIGHT,
59
FZ_BLEND_DIFFERENCE,
60
FZ_BLEND_EXCLUSION,
61
62
/* PDF 1.4 -- standard non-separable */
63
FZ_BLEND_HUE,
64
FZ_BLEND_SATURATION,
65
FZ_BLEND_COLOR,
66
FZ_BLEND_LUMINOSITY,
67
68
/* For packing purposes */
69
FZ_BLEND_MODEMASK = 15,
70
FZ_BLEND_ISOLATED = 16,
71
FZ_BLEND_KNOCKOUT = 32
72
};
73
74
int fz_lookup_blendmode(const char *name);
75
char *fz_blendmode_name(int blendmode);
76
77
typedef struct fz_device_container_stack_s fz_device_container_stack;
78
79
struct fz_device_container_stack_s
80
{
81
fz_rect scissor;
82
int flags;
83
int user;
84
};
85
86
enum
87
{
88
fz_device_container_stack_is_clip_path = 1,
89
fz_device_container_stack_is_clip_stroke_path = 2,
90
fz_device_container_stack_is_clip_text = 4,
91
fz_device_container_stack_is_clip_stroke_text = 8,
92
fz_device_container_stack_is_clip_image_mask = 16,
93
fz_device_container_stack_in_mask = 32,
94
fz_device_container_stack_is_mask = 64,
95
fz_device_container_stack_is_group = 128,
96
};
97
98
struct fz_device_s
99
{
100
int hints;
101
int flags;
102
103
void (*drop_imp)(fz_context *, fz_device *);
104
105
void (*begin_page)(fz_context *, fz_device *, const fz_rect *rect, const fz_matrix *ctm);
106
void (*end_page)(fz_context *, fz_device *);
107
108
void (*fill_path)(fz_context *, fz_device *, fz_path *, int even_odd, const fz_matrix *, fz_colorspace *, float *color, float alpha);
109
void (*stroke_path)(fz_context *, fz_device *, fz_path *, fz_stroke_state *, const fz_matrix *, fz_colorspace *, float *color, float alpha);
110
void (*clip_path)(fz_context *, fz_device *, fz_path *, const fz_rect *rect, int even_odd, const fz_matrix *);
111
void (*clip_stroke_path)(fz_context *, fz_device *, fz_path *, const fz_rect *rect, fz_stroke_state *, const fz_matrix *);
112
113
void (*fill_text)(fz_context *, fz_device *, fz_text *, const fz_matrix *, fz_colorspace *, float *color, float alpha);
114
void (*stroke_text)(fz_context *, fz_device *, fz_text *, fz_stroke_state *, const fz_matrix *, fz_colorspace *, float *color, float alpha);
115
void (*clip_text)(fz_context *, fz_device *, fz_text *, const fz_matrix *, int accumulate);
116
void (*clip_stroke_text)(fz_context *, fz_device *, fz_text *, fz_stroke_state *, const fz_matrix *);
117
void (*ignore_text)(fz_context *, fz_device *, fz_text *, const fz_matrix *);
118
119
void (*fill_shade)(fz_context *, fz_device *, fz_shade *shd, const fz_matrix *ctm, float alpha);
120
void (*fill_image)(fz_context *, fz_device *, fz_image *img, const fz_matrix *ctm, float alpha);
121
void (*fill_image_mask)(fz_context *, fz_device *, fz_image *img, const fz_matrix *ctm, fz_colorspace *, float *color, float alpha);
122
void (*clip_image_mask)(fz_context *, fz_device *, fz_image *img, const fz_rect *rect, const fz_matrix *ctm);
123
124
void (*pop_clip)(fz_context *, fz_device *);
125
126
void (*begin_mask)(fz_context *, fz_device *, const fz_rect *, int luminosity, fz_colorspace *, float *bc);
127
void (*end_mask)(fz_context *, fz_device *);
128
void (*begin_group)(fz_context *, fz_device *, const fz_rect *, int isolated, int knockout, int blendmode, float alpha);
129
void (*end_group)(fz_context *, fz_device *);
130
131
int (*begin_tile)(fz_context *, fz_device *, const fz_rect *area, const fz_rect *view, float xstep, float ystep, const fz_matrix *ctm, int id);
132
void (*end_tile)(fz_context *, fz_device *);
133
134
fz_rect d1_rect;
135
136
int error_depth;
137
char errmess[256];
138
139
int container_len;
140
int container_cap;
141
fz_device_container_stack *container;
142
fz_rect scissor_accumulator;
143
};
144
145
void fz_begin_page(fz_context *ctx, fz_device *dev, const fz_rect *rect, const fz_matrix *ctm);
146
void fz_end_page(fz_context *ctx, fz_device *dev);
147
void fz_fill_path(fz_context *ctx, fz_device *dev, fz_path *path, int even_odd, const fz_matrix *ctm, fz_colorspace *colorspace, float *color, float alpha);
148
void fz_stroke_path(fz_context *ctx, fz_device *dev, fz_path *path, fz_stroke_state *stroke, const fz_matrix *ctm, fz_colorspace *colorspace, float *color, float alpha);
149
void fz_clip_path(fz_context *ctx, fz_device *dev, fz_path *path, const fz_rect *rect, int even_odd, const fz_matrix *ctm);
150
void fz_clip_stroke_path(fz_context *ctx, fz_device *dev, fz_path *path, const fz_rect *rect, fz_stroke_state *stroke, const fz_matrix *ctm);
151
void fz_fill_text(fz_context *ctx, fz_device *dev, fz_text *text, const fz_matrix *ctm, fz_colorspace *colorspace, float *color, float alpha);
152
void fz_stroke_text(fz_context *ctx, fz_device *dev, fz_text *text, fz_stroke_state *stroke, const fz_matrix *ctm, fz_colorspace *colorspace, float *color, float alpha);
153
void fz_clip_text(fz_context *ctx, fz_device *dev, fz_text *text, const fz_matrix *ctm, int accumulate);
154
void fz_clip_stroke_text(fz_context *ctx, fz_device *dev, fz_text *text, fz_stroke_state *stroke, const fz_matrix *ctm);
155
void fz_ignore_text(fz_context *ctx, fz_device *dev, fz_text *text, const fz_matrix *ctm);
156
void fz_pop_clip(fz_context *ctx, fz_device *dev);
157
void fz_fill_shade(fz_context *ctx, fz_device *dev, fz_shade *shade, const fz_matrix *ctm, float alpha);
158
void fz_fill_image(fz_context *ctx, fz_device *dev, fz_image *image, const fz_matrix *ctm, float alpha);
159
void fz_fill_image_mask(fz_context *ctx, fz_device *dev, fz_image *image, const fz_matrix *ctm, fz_colorspace *colorspace, float *color, float alpha);
160
void fz_clip_image_mask(fz_context *ctx, fz_device *dev, fz_image *image, const fz_rect *rect, const fz_matrix *ctm);
161
void fz_begin_mask(fz_context *ctx, fz_device *dev, const fz_rect *area, int luminosity, fz_colorspace *colorspace, float *bc);
162
void fz_end_mask(fz_context *ctx, fz_device *dev);
163
void fz_begin_group(fz_context *ctx, fz_device *dev, const fz_rect *area, int isolated, int knockout, int blendmode, float alpha);
164
void fz_end_group(fz_context *ctx, fz_device *dev);
165
void fz_begin_tile(fz_context *ctx, fz_device *dev, const fz_rect *area, const fz_rect *view, float xstep, float ystep, const fz_matrix *ctm);
166
int fz_begin_tile_id(fz_context *ctx, fz_device *dev, const fz_rect *area, const fz_rect *view, float xstep, float ystep, const fz_matrix *ctm, int id);
167
void fz_end_tile(fz_context *ctx, fz_device *dev);
168
169
void *fz_new_device(fz_context *ctx, int size);
170
171
/*
172
fz_drop_device: Free a devices of any type and its resources.
173
*/
174
void fz_drop_device(fz_context *ctx, fz_device *dev);
175
176
/*
177
fz_enable_device_hints : Enable hints in a device.
178
179
hints: mask of hints to enable.
180
181
For example: By default the draw device renders shadings. For some
182
purposes (perhaps rendering fast low quality thumbnails) you may want
183
to tell it to ignore shadings. For this you would enable the
184
FZ_IGNORE_SHADE hint.
185
*/
186
void fz_enable_device_hints(fz_context *ctx, fz_device *dev, int hints);
187
188
/*
189
fz_disable_device_hints : Disable hints in a device.
190
191
hints: mask of hints to disable.
192
193
For example: By default the text extraction device ignores images.
194
For some purposes however (such as extracting HTML) you may want to
195
enable the capturing of image data too. For this you would disable
196
the FZ_IGNORE_IMAGE hint.
197
*/
198
void fz_disable_device_hints(fz_context *ctx, fz_device *dev, int hints);
199
200
enum
201
{
202
/* Hints */
203
FZ_IGNORE_IMAGE = 1,
204
FZ_IGNORE_SHADE = 2,
205
FZ_DONT_INTERPOLATE_IMAGES = 4,
206
FZ_MAINTAIN_CONTAINER_STACK = 8,
207
FZ_NO_CACHE = 16,
208
};
209
210
/*
211
Cookie support - simple communication channel between app/library.
212
*/
213
214
typedef struct fz_cookie_s fz_cookie;
215
216
/*
217
Provide two-way communication between application and library.
218
Intended for multi-threaded applications where one thread is
219
rendering pages and another thread wants read progress
220
feedback or abort a job that takes a long time to finish. The
221
communication is unsynchronized without locking.
222
223
abort: The appliation should set this field to 0 before
224
calling fz_run_page to render a page. At any point when the
225
page is being rendered the application my set this field to 1
226
which will cause the rendering to finish soon. This field is
227
checked periodically when the page is rendered, but exactly
228
when is not known, therefore there is no upper bound on
229
exactly when the the rendering will abort. If the application
230
did not provide a set of locks to fz_new_context, it must also
231
await the completion of fz_run_page before issuing another
232
call to fz_run_page. Note that once the application has set
233
this field to 1 after it called fz_run_page it may not change
234
the value again.
235
236
progress: Communicates rendering progress back to the
237
application and is read only. Increments as a page is being
238
rendered. The value starts out at 0 and is limited to less
239
than or equal to progress_max, unless progress_max is -1.
240
241
progress_max: Communicates the known upper bound of rendering
242
back to the application and is read only. The maximum value
243
that the progress field may take. If there is no known upper
244
bound on how long the rendering may take this value is -1 and
245
progress is not limited. Note that the value of progress_max
246
may change from -1 to a positive value once an upper bound is
247
known, so take this into consideration when comparing the
248
value of progress to that of progress_max.
249
250
errors: count of errors during current rendering.
251
252
incomplete_ok: If this is set to 1 by the caller, then TRYLATER
253
errors are swallowed as they occur, setting the 'incomplete' flag.
254
Rendering continues as much as possible ignoring errors. The caller
255
is expected to check the 'incomplete' flag at the end to see if the
256
rendering may be considered final or not.
257
258
incomplete: Initially should be set to 0. Will be set to non-zero
259
if a TRYLATER error is thrown during rendering and the incomplete_ok
260
flag is set.
261
*/
262
struct fz_cookie_s
263
{
264
int abort;
265
int progress;
266
int progress_max; /* -1 for unknown */
267
int errors;
268
int incomplete_ok;
269
int incomplete;
270
};
271
272
/*
273
fz_new_trace_device: Create a device to print a debug trace of
274
all device calls.
275
*/
276
fz_device *fz_new_trace_device(fz_context *ctx);
277
278
/*
279
fz_new_bbox_device: Create a device to compute the bounding
280
box of all marks on a page.
281
282
The returned bounding box will be the union of all bounding
283
boxes of all objects on a page.
284
*/
285
fz_device *fz_new_bbox_device(fz_context *ctx, fz_rect *rectp);
286
287
/*
288
fz_new_test_device: Create a device to test for features.
289
290
Currently only tests for the presence of non-grayscale colors.
291
292
threshold: The difference from grayscale that will be tolerated.
293
Typical values to use are either 0 (be exact) and 0.02 (allow an
294
imperceptible amount of slop).
295
*/
296
fz_device *fz_new_test_device(fz_context *ctx, int *is_color, float threshold);
297
298
/*
299
fz_new_draw_device: Create a device to draw on a pixmap.
300
301
dest: Target pixmap for the draw device. See fz_new_pixmap*
302
for how to obtain a pixmap. The pixmap is not cleared by the
303
draw device, see fz_clear_pixmap* for how to clear it prior to
304
calling fz_new_draw_device. Free the device by calling
305
fz_drop_device.
306
*/
307
fz_device *fz_new_draw_device(fz_context *ctx, fz_pixmap *dest);
308
309
/*
310
fz_new_draw_device_with_bbox: Create a device to draw on a pixmap.
311
312
dest: Target pixmap for the draw device. See fz_new_pixmap*
313
for how to obtain a pixmap. The pixmap is not cleared by the
314
draw device, see fz_clear_pixmap* for how to clear it prior to
315
calling fz_new_draw_device. Free the device by calling
316
fz_drop_device.
317
318
clip: Bounding box to restrict any marking operations of the
319
draw device.
320
*/
321
fz_device *fz_new_draw_device_with_bbox(fz_context *ctx, fz_pixmap *dest, const fz_irect *clip);
322
323
fz_device *fz_new_draw_device_type3(fz_context *ctx, fz_pixmap *dest);
324
325
#endif
326
327