Go to most recent revision | Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
4680 | right-hear | 1 | #ifndef _FITZ_H_ |
2 | #define _FITZ_H_ |
||
3 | |||
4 | /* |
||
5 | * Include the standard libc headers. |
||
6 | */ |
||
7 | |||
8 | #include |
||
9 | #include |
||
10 | #include |
||
11 | #include |
||
12 | #include |
||
13 | #include |
||
14 | |||
15 | #include |
||
16 | #include |
||
17 | #include |
||
18 | #include |
||
19 | #include |
||
20 | |||
21 | #define nelem(x) (sizeof(x)/sizeof((x)[0])) |
||
22 | |||
23 | #define ABS(x) ( (x) < 0 ? -(x) : (x) ) |
||
24 | #define MIN(a,b) ( (a) < (b) ? (a) : (b) ) |
||
25 | #define MAX(a,b) ( (a) > (b) ? (a) : (b) ) |
||
26 | #define CLAMP(x,a,b) ( (x) > (b) ? (b) : ( (x) < (a) ? (a) : (x) ) ) |
||
27 | |||
28 | /* |
||
29 | * Some differences in libc can be smoothed over |
||
30 | */ |
||
31 | |||
32 | #ifdef _MSC_VER /* Microsoft Visual C */ |
||
33 | |||
34 | #pragma warning( disable: 4244 ) /* conversion from X to Y, possible loss of data */ |
||
35 | #pragma warning( disable: 4996 ) /* The POSIX name for this item is deprecated */ |
||
36 | #pragma warning( disable: 4996 ) /* This function or variable may be unsafe */ |
||
37 | |||
38 | #include |
||
39 | |||
40 | int gettimeofday(struct timeval *tv, struct timezone *tz); |
||
41 | |||
42 | #define snprintf _snprintf |
||
43 | #define strtoll _strtoi64 |
||
44 | |||
45 | #else /* Unix or close enough */ |
||
46 | |||
47 | #include |
||
48 | |||
49 | #ifndef O_BINARY |
||
50 | #define O_BINARY 0 |
||
51 | #endif |
||
52 | |||
53 | #endif |
||
54 | |||
55 | #ifndef M_PI |
||
56 | #define M_PI 3.14159265358979323846 |
||
57 | #endif |
||
58 | |||
59 | #ifndef M_SQRT2 |
||
60 | #define M_SQRT2 1.41421356237309504880 |
||
61 | #endif |
||
62 | |||
63 | /* |
||
64 | * Variadic macros, inline and restrict keywords |
||
65 | */ |
||
66 | |||
67 | #if __STDC_VERSION__ == 199901L /* C99 */ |
||
68 | |||
69 | #define fz_throw(...) fz_throw_imp(__FILE__, __LINE__, __func__, __VA_ARGS__) |
||
70 | #define fz_rethrow(cause, ...) fz_rethrow_imp(__FILE__, __LINE__, __func__, cause, __VA_ARGS__) |
||
71 | #define fz_catch(cause, ...) fz_catch_imp(__FILE__, __LINE__, __func__, cause, __VA_ARGS__) |
||
72 | |||
73 | #elif _MSC_VER >= 1500 /* MSVC 9 or newer */ |
||
74 | |||
75 | #define inline __inline |
||
76 | #define restrict __restrict |
||
77 | #define fz_throw(...) fz_throw_imp(__FILE__, __LINE__, __FUNCTION__, __VA_ARGS__) |
||
78 | #define fz_rethrow(cause, ...) fz_rethrow_imp(__FILE__, __LINE__, __FUNCTION__, cause, __VA_ARGS__) |
||
79 | #define fz_catch(cause, ...) fz_catch_imp(__FILE__, __LINE__, __FUNCTION__, cause, __VA_ARGS__) |
||
80 | |||
81 | #elif __GNUC__ >= 3 /* GCC 3 or newer */ |
||
82 | |||
83 | #define inline __inline |
||
84 | #define restrict __restrict |
||
85 | #define fz_throw(fmt...) fz_throw_imp(__FILE__, __LINE__, __FUNCTION__, fmt) |
||
86 | #define fz_rethrow(cause, fmt...) fz_rethrow_imp(__FILE__, __LINE__, __FUNCTION__, cause, fmt) |
||
87 | #define fz_catch(cause, fmt...) fz_catch_imp(__FILE__, __LINE__, __FUNCTION__, cause, fmt) |
||
88 | |||
89 | #else /* Unknown or ancient */ |
||
90 | |||
91 | #define inline |
||
92 | #define restrict |
||
93 | #define fz_throw fz_throw_impx |
||
94 | #define fz_rethrow fz_rethrow_impx |
||
95 | #define fz_catch fz_catch_impx |
||
96 | |||
97 | #endif |
||
98 | |||
99 | /* |
||
100 | * GCC can do type checking of printf strings |
||
101 | */ |
||
102 | |||
103 | #ifndef __printflike |
||
104 | #if __GNUC__ > 2 || __GNUC__ == 2 && __GNUC_MINOR__ >= 7 |
||
105 | #define __printflike(fmtarg, firstvararg) \ |
||
106 | __attribute__((__format__ (__printf__, fmtarg, firstvararg))) |
||
107 | #else |
||
108 | #define __printflike(fmtarg, firstvararg) |
||
109 | #endif |
||
110 | #endif |
||
111 | |||
112 | /* |
||
113 | * Error handling |
||
114 | */ |
||
115 | |||
116 | typedef int fz_error; |
||
117 | |||
118 | #define fz_okay ((fz_error)0) |
||
119 | |||
120 | void fz_warn(char *fmt, ...) __printflike(1, 2); |
||
121 | void fz_flush_warnings(void); |
||
122 | |||
123 | fz_error fz_throw_imp(const char *file, int line, const char *func, char *fmt, ...) __printflike(4, 5); |
||
124 | fz_error fz_rethrow_imp(const char *file, int line, const char *func, fz_error cause, char *fmt, ...) __printflike(5, 6); |
||
125 | void fz_catch_imp(const char *file, int line, const char *func, fz_error cause, char *fmt, ...) __printflike(5, 6); |
||
126 | |||
127 | fz_error fz_throw_impx(char *fmt, ...) __printflike(1, 2); |
||
128 | fz_error fz_rethrow_impx(fz_error cause, char *fmt, ...) __printflike(2, 3); |
||
129 | void fz_catch_impx(fz_error cause, char *fmt, ...) __printflike(2, 3); |
||
130 | |||
131 | /* extract the last error stack trace */ |
||
132 | int fz_get_error_count(void); |
||
133 | char *fz_get_error_line(int n); |
||
134 | |||
135 | /* |
||
136 | * Basic runtime and utility functions |
||
137 | */ |
||
138 | |||
139 | /* memory allocation */ |
||
140 | void *fz_malloc(int size); |
||
141 | void *fz_calloc(int count, int size); |
||
142 | void *fz_realloc(void *p, int count, int size); |
||
143 | void fz_free(void *p); |
||
144 | char *fz_strdup(char *s); |
||
145 | |||
146 | /* runtime (hah!) test for endian-ness */ |
||
147 | int fz_is_big_endian(void); |
||
148 | |||
149 | /* safe string functions */ |
||
150 | char *fz_strsep(char **stringp, const char *delim); |
||
151 | int fz_strlcpy(char *dst, const char *src, int n); |
||
152 | int fz_strlcat(char *dst, const char *src, int n); |
||
153 | |||
154 | /* Range checking atof */ |
||
155 | float fz_atof(const char *s); |
||
156 | |||
157 | /* utf-8 encoding and decoding */ |
||
158 | int chartorune(int *rune, char *str); |
||
159 | int runetochar(char *str, int *rune); |
||
160 | int runelen(int c); |
||
161 | |||
162 | /* getopt */ |
||
163 | extern int fz_getopt(int nargc, char * const *nargv, const char *ostr); |
||
164 | extern int fz_optind; |
||
165 | extern char *fz_optarg; |
||
166 | |||
167 | /* |
||
168 | * Generic hash-table with fixed-length keys. |
||
169 | */ |
||
170 | |||
171 | typedef struct fz_hash_table_s fz_hash_table; |
||
172 | |||
173 | fz_hash_table *fz_new_hash_table(int initialsize, int keylen); |
||
174 | void fz_debug_hash(fz_hash_table *table); |
||
175 | void fz_empty_hash(fz_hash_table *table); |
||
176 | void fz_free_hash(fz_hash_table *table); |
||
177 | |||
178 | void *fz_hash_find(fz_hash_table *table, void *key); |
||
179 | void fz_hash_insert(fz_hash_table *table, void *key, void *val); |
||
180 | void fz_hash_remove(fz_hash_table *table, void *key); |
||
181 | |||
182 | int fz_hash_len(fz_hash_table *table); |
||
183 | void *fz_hash_get_key(fz_hash_table *table, int idx); |
||
184 | void *fz_hash_get_val(fz_hash_table *table, int idx); |
||
185 | |||
186 | /* |
||
187 | * Math and geometry |
||
188 | */ |
||
189 | |||
190 | /* Multiply scaled two integers in the 0..255 range */ |
||
191 | static inline int fz_mul255(int a, int b) |
||
192 | { |
||
193 | /* see Jim Blinn's book "Dirty Pixels" for how this works */ |
||
194 | int x = a * b + 128; |
||
195 | x += x >> 8; |
||
196 | return x >> 8; |
||
197 | } |
||
198 | |||
199 | /* Expand a value A from the 0...255 range to the 0..256 range */ |
||
200 | #define FZ_EXPAND(A) ((A)+((A)>>7)) |
||
201 | |||
202 | /* Combine values A (in any range) and B (in the 0..256 range), |
||
203 | * to give a single value in the same range as A was. */ |
||
204 | #define FZ_COMBINE(A,B) (((A)*(B))>>8) |
||
205 | |||
206 | /* Combine values A and C (in the same (any) range) and B and D (in the |
||
207 | * 0..256 range), to give a single value in the same range as A and C were. */ |
||
208 | #define FZ_COMBINE2(A,B,C,D) (FZ_COMBINE((A), (B)) + FZ_COMBINE((C), (D))) |
||
209 | |||
210 | /* Blend SRC and DST (in the same range) together according to |
||
211 | * AMOUNT (in the 0...256 range). */ |
||
212 | #define FZ_BLEND(SRC, DST, AMOUNT) ((((SRC)-(DST))*(AMOUNT) + ((DST)<<8))>>8) |
||
213 | |||
214 | typedef struct fz_matrix_s fz_matrix; |
||
215 | typedef struct fz_point_s fz_point; |
||
216 | typedef struct fz_rect_s fz_rect; |
||
217 | typedef struct fz_bbox_s fz_bbox; |
||
218 | |||
219 | extern const fz_rect fz_unit_rect; |
||
220 | extern const fz_rect fz_empty_rect; |
||
221 | extern const fz_rect fz_infinite_rect; |
||
222 | |||
223 | extern const fz_bbox fz_unit_bbox; |
||
224 | extern const fz_bbox fz_empty_bbox; |
||
225 | extern const fz_bbox fz_infinite_bbox; |
||
226 | |||
227 | #define fz_is_empty_rect(r) ((r).x0 == (r).x1) |
||
228 | #define fz_is_infinite_rect(r) ((r).x0 > (r).x1) |
||
229 | #define fz_is_empty_bbox(b) ((b).x0 == (b).x1) |
||
230 | #define fz_is_infinite_bbox(b) ((b).x0 > (b).x1) |
||
231 | |||
232 | struct fz_matrix_s |
||
233 | { |
||
234 | float a, b, c, d, e, f; |
||
235 | }; |
||
236 | |||
237 | struct fz_point_s |
||
238 | { |
||
239 | float x, y; |
||
240 | }; |
||
241 | |||
242 | struct fz_rect_s |
||
243 | { |
||
244 | float x0, y0; |
||
245 | float x1, y1; |
||
246 | }; |
||
247 | |||
248 | struct fz_bbox_s |
||
249 | { |
||
250 | int x0, y0; |
||
251 | int x1, y1; |
||
252 | }; |
||
253 | |||
254 | extern const fz_matrix fz_identity; |
||
255 | |||
256 | fz_matrix fz_concat(fz_matrix one, fz_matrix two); |
||
257 | fz_matrix fz_scale(float sx, float sy); |
||
258 | fz_matrix fz_shear(float sx, float sy); |
||
259 | fz_matrix fz_rotate(float theta); |
||
260 | fz_matrix fz_translate(float tx, float ty); |
||
261 | fz_matrix fz_invert_matrix(fz_matrix m); |
||
262 | int fz_is_rectilinear(fz_matrix m); |
||
263 | float fz_matrix_expansion(fz_matrix m); |
||
264 | |||
265 | fz_bbox fz_round_rect(fz_rect r); |
||
266 | fz_bbox fz_intersect_bbox(fz_bbox a, fz_bbox b); |
||
267 | fz_rect fz_intersect_rect(fz_rect a, fz_rect b); |
||
268 | fz_bbox fz_union_bbox(fz_bbox a, fz_bbox b); |
||
269 | fz_rect fz_union_rect(fz_rect a, fz_rect b); |
||
270 | |||
271 | fz_point fz_transform_point(fz_matrix m, fz_point p); |
||
272 | fz_point fz_transform_vector(fz_matrix m, fz_point p); |
||
273 | fz_rect fz_transform_rect(fz_matrix m, fz_rect r); |
||
274 | fz_bbox fz_transform_bbox(fz_matrix m, fz_bbox b); |
||
275 | |||
276 | /* |
||
277 | * Basic crypto functions. |
||
278 | * Independent of the rest of fitz. |
||
279 | * For further encapsulation in filters, or not. |
||
280 | */ |
||
281 | |||
282 | /* md5 digests */ |
||
283 | |||
284 | typedef struct fz_md5_s fz_md5; |
||
285 | |||
286 | struct fz_md5_s |
||
287 | { |
||
288 | unsigned int state[4]; |
||
289 | unsigned int count[2]; |
||
290 | unsigned char buffer[64]; |
||
291 | }; |
||
292 | |||
293 | void fz_md5_init(fz_md5 *state); |
||
294 | void fz_md5_update(fz_md5 *state, const unsigned char *input, unsigned inlen); |
||
295 | void fz_md5_final(fz_md5 *state, unsigned char digest[16]); |
||
296 | |||
297 | /* sha-256 digests */ |
||
298 | |||
299 | typedef struct fz_sha256_s fz_sha256; |
||
300 | |||
301 | struct fz_sha256_s |
||
302 | { |
||
303 | unsigned int state[8]; |
||
304 | unsigned int count[2]; |
||
305 | union { |
||
306 | unsigned char u8[64]; |
||
307 | unsigned int u32[16]; |
||
308 | } buffer; |
||
309 | }; |
||
310 | |||
311 | void fz_sha256_init(fz_sha256 *state); |
||
312 | void fz_sha256_update(fz_sha256 *state, const unsigned char *input, unsigned int inlen); |
||
313 | void fz_sha256_final(fz_sha256 *state, unsigned char digest[32]); |
||
314 | |||
315 | /* arc4 crypto */ |
||
316 | |||
317 | typedef struct fz_arc4_s fz_arc4; |
||
318 | |||
319 | struct fz_arc4_s |
||
320 | { |
||
321 | unsigned x; |
||
322 | unsigned y; |
||
323 | unsigned char state[256]; |
||
324 | }; |
||
325 | |||
326 | void fz_arc4_init(fz_arc4 *state, const unsigned char *key, unsigned len); |
||
327 | void fz_arc4_encrypt(fz_arc4 *state, unsigned char *dest, const unsigned char *src, unsigned len); |
||
328 | |||
329 | /* AES block cipher implementation from XYSSL */ |
||
330 | |||
331 | typedef struct fz_aes_s fz_aes; |
||
332 | |||
333 | #define AES_DECRYPT 0 |
||
334 | #define AES_ENCRYPT 1 |
||
335 | |||
336 | struct fz_aes_s |
||
337 | { |
||
338 | int nr; /* number of rounds */ |
||
339 | unsigned long *rk; /* AES round keys */ |
||
340 | unsigned long buf[68]; /* unaligned data */ |
||
341 | }; |
||
342 | |||
343 | void aes_setkey_enc( fz_aes *ctx, const unsigned char *key, int keysize ); |
||
344 | void aes_setkey_dec( fz_aes *ctx, const unsigned char *key, int keysize ); |
||
345 | void aes_crypt_cbc( fz_aes *ctx, int mode, int length, |
||
346 | unsigned char iv[16], |
||
347 | const unsigned char *input, |
||
348 | unsigned char *output ); |
||
349 | |||
350 | /* |
||
351 | * Dynamic objects. |
||
352 | * The same type of objects as found in PDF and PostScript. |
||
353 | * Used by the filters and the mupdf parser. |
||
354 | */ |
||
355 | |||
356 | typedef struct fz_obj_s fz_obj; |
||
357 | |||
358 | extern fz_obj* (*fz_resolve_indirect)(fz_obj*); |
||
359 | |||
360 | fz_obj *fz_new_null(void); |
||
361 | fz_obj *fz_new_bool(int b); |
||
362 | fz_obj *fz_new_int(int i); |
||
363 | fz_obj *fz_new_real(float f); |
||
364 | fz_obj *fz_new_name(char *str); |
||
365 | fz_obj *fz_new_string(char *str, int len); |
||
366 | fz_obj *fz_new_indirect(int num, int gen, void *xref); |
||
367 | |||
368 | fz_obj *fz_new_array(int initialcap); |
||
369 | fz_obj *fz_new_dict(int initialcap); |
||
370 | fz_obj *fz_copy_array(fz_obj *array); |
||
371 | fz_obj *fz_copy_dict(fz_obj *dict); |
||
372 | |||
373 | fz_obj *fz_keep_obj(fz_obj *obj); |
||
374 | void fz_drop_obj(fz_obj *obj); |
||
375 | |||
376 | /* type queries */ |
||
377 | int fz_is_null(fz_obj *obj); |
||
378 | int fz_is_bool(fz_obj *obj); |
||
379 | int fz_is_int(fz_obj *obj); |
||
380 | int fz_is_real(fz_obj *obj); |
||
381 | int fz_is_name(fz_obj *obj); |
||
382 | int fz_is_string(fz_obj *obj); |
||
383 | int fz_is_array(fz_obj *obj); |
||
384 | int fz_is_dict(fz_obj *obj); |
||
385 | int fz_is_indirect(fz_obj *obj); |
||
386 | |||
387 | int fz_objcmp(fz_obj *a, fz_obj *b); |
||
388 | |||
389 | /* safe, silent failure, no error reporting */ |
||
390 | int fz_to_bool(fz_obj *obj); |
||
391 | int fz_to_int(fz_obj *obj); |
||
392 | float fz_to_real(fz_obj *obj); |
||
393 | char *fz_to_name(fz_obj *obj); |
||
394 | char *fz_to_str_buf(fz_obj *obj); |
||
395 | int fz_to_str_len(fz_obj *obj); |
||
396 | int fz_to_num(fz_obj *obj); |
||
397 | int fz_to_gen(fz_obj *obj); |
||
398 | |||
399 | int fz_array_len(fz_obj *array); |
||
400 | fz_obj *fz_array_get(fz_obj *array, int i); |
||
401 | void fz_array_put(fz_obj *array, int i, fz_obj *obj); |
||
402 | void fz_array_push(fz_obj *array, fz_obj *obj); |
||
403 | void fz_array_insert(fz_obj *array, fz_obj *obj); |
||
404 | |||
405 | int fz_dict_len(fz_obj *dict); |
||
406 | fz_obj *fz_dict_get_key(fz_obj *dict, int idx); |
||
407 | fz_obj *fz_dict_get_val(fz_obj *dict, int idx); |
||
408 | fz_obj *fz_dict_get(fz_obj *dict, fz_obj *key); |
||
409 | fz_obj *fz_dict_gets(fz_obj *dict, char *key); |
||
410 | fz_obj *fz_dict_getsa(fz_obj *dict, char *key, char *abbrev); |
||
411 | void fz_dict_put(fz_obj *dict, fz_obj *key, fz_obj *val); |
||
412 | void fz_dict_puts(fz_obj *dict, char *key, fz_obj *val); |
||
413 | void fz_dict_del(fz_obj *dict, fz_obj *key); |
||
414 | void fz_dict_dels(fz_obj *dict, char *key); |
||
415 | void fz_sort_dict(fz_obj *dict); |
||
416 | |||
417 | int fz_fprint_obj(FILE *fp, fz_obj *obj, int tight); |
||
418 | void fz_debug_obj(fz_obj *obj); |
||
419 | void fz_debug_ref(fz_obj *obj); |
||
420 | |||
421 | void fz_set_str_len(fz_obj *obj, int newlen); /* private */ |
||
422 | void *fz_get_indirect_xref(fz_obj *obj); /* private */ |
||
423 | |||
424 | /* |
||
425 | * Data buffers. |
||
426 | */ |
||
427 | |||
428 | typedef struct fz_buffer_s fz_buffer; |
||
429 | |||
430 | struct fz_buffer_s |
||
431 | { |
||
432 | int refs; |
||
433 | unsigned char *data; |
||
434 | int cap, len; |
||
435 | }; |
||
436 | |||
437 | fz_buffer *fz_new_buffer(int size); |
||
438 | fz_buffer *fz_keep_buffer(fz_buffer *buf); |
||
439 | void fz_drop_buffer(fz_buffer *buf); |
||
440 | |||
441 | void fz_resize_buffer(fz_buffer *buf, int size); |
||
442 | void fz_grow_buffer(fz_buffer *buf); |
||
443 | |||
444 | /* |
||
445 | * Buffered reader. |
||
446 | * Only the data between rp and wp is valid data. |
||
447 | */ |
||
448 | |||
449 | typedef struct fz_stream_s fz_stream; |
||
450 | |||
451 | struct fz_stream_s |
||
452 | { |
||
453 | int refs; |
||
454 | int error; |
||
455 | int eof; |
||
456 | int pos; |
||
457 | int avail; |
||
458 | int bits; |
||
459 | unsigned char *bp, *rp, *wp, *ep; |
||
460 | void *state; |
||
461 | int (*read)(fz_stream *stm, unsigned char *buf, int len); |
||
462 | void (*close)(fz_stream *stm); |
||
463 | void (*seek)(fz_stream *stm, int offset, int whence); |
||
464 | unsigned char buf[4096]; |
||
465 | }; |
||
466 | |||
467 | fz_stream *fz_open_fd(int file); |
||
468 | fz_stream *fz_open_file(const char *filename); |
||
469 | fz_stream *fz_open_file_w(const wchar_t *filename); /* only on win32 */ |
||
470 | fz_stream *fz_open_buffer(fz_buffer *buf); |
||
471 | fz_stream *fz_open_memory(unsigned char *data, int len); |
||
472 | void fz_close(fz_stream *stm); |
||
473 | |||
474 | fz_stream *fz_new_stream(void*, int(*)(fz_stream*, unsigned char*, int), void(*)(fz_stream *)); |
||
475 | fz_stream *fz_keep_stream(fz_stream *stm); |
||
476 | void fz_fill_buffer(fz_stream *stm); |
||
477 | |||
478 | int fz_tell(fz_stream *stm); |
||
479 | void fz_seek(fz_stream *stm, int offset, int whence); |
||
480 | |||
481 | int fz_read(fz_stream *stm, unsigned char *buf, int len); |
||
482 | void fz_read_line(fz_stream *stm, char *buf, int max); |
||
483 | fz_error fz_read_all(fz_buffer **bufp, fz_stream *stm, int initial); |
||
484 | |||
485 | static inline int fz_read_byte(fz_stream *stm) |
||
486 | { |
||
487 | if (stm->rp == stm->wp) |
||
488 | { |
||
489 | fz_fill_buffer(stm); |
||
490 | return stm->rp < stm->wp ? *stm->rp++ : EOF; |
||
491 | } |
||
492 | return *stm->rp++; |
||
493 | } |
||
494 | |||
495 | static inline int fz_peek_byte(fz_stream *stm) |
||
496 | { |
||
497 | if (stm->rp == stm->wp) |
||
498 | { |
||
499 | fz_fill_buffer(stm); |
||
500 | return stm->rp < stm->wp ? *stm->rp : EOF; |
||
501 | } |
||
502 | return *stm->rp; |
||
503 | } |
||
504 | |||
505 | static inline void fz_unread_byte(fz_stream *stm) |
||
506 | { |
||
507 | if (stm->rp > stm->bp) |
||
508 | stm->rp--; |
||
509 | } |
||
510 | |||
511 | static inline int fz_is_eof(fz_stream *stm) |
||
512 | { |
||
513 | if (stm->rp == stm->wp) |
||
514 | { |
||
515 | if (stm->eof) |
||
516 | return 1; |
||
517 | return fz_peek_byte(stm) == EOF; |
||
518 | } |
||
519 | return 0; |
||
520 | } |
||
521 | |||
522 | static inline unsigned int fz_read_bits(fz_stream *stm, int n) |
||
523 | { |
||
524 | unsigned int x; |
||
525 | |||
526 | if (n <= stm->avail) |
||
527 | { |
||
528 | stm->avail -= n; |
||
529 | x = (stm->bits >> stm->avail) & ((1 << n) - 1); |
||
530 | } |
||
531 | else |
||
532 | { |
||
533 | x = stm->bits & ((1 << stm->avail) - 1); |
||
534 | n -= stm->avail; |
||
535 | stm->avail = 0; |
||
536 | |||
537 | while (n > 8) |
||
538 | { |
||
539 | x = (x << 8) | fz_read_byte(stm); |
||
540 | n -= 8; |
||
541 | } |
||
542 | |||
543 | if (n > 0) |
||
544 | { |
||
545 | stm->bits = fz_read_byte(stm); |
||
546 | stm->avail = 8 - n; |
||
547 | x = (x << n) | (stm->bits >> stm->avail); |
||
548 | } |
||
549 | } |
||
550 | |||
551 | return x; |
||
552 | } |
||
553 | |||
554 | static inline void fz_sync_bits(fz_stream *stm) |
||
555 | { |
||
556 | stm->avail = 0; |
||
557 | } |
||
558 | |||
559 | static inline int fz_is_eof_bits(fz_stream *stm) |
||
560 | { |
||
561 | return fz_is_eof(stm) && (stm->avail == 0 || stm->bits == EOF); |
||
562 | } |
||
563 | |||
564 | /* |
||
565 | * Data filters. |
||
566 | */ |
||
567 | |||
568 | fz_stream *fz_open_copy(fz_stream *chain); |
||
569 | fz_stream *fz_open_null(fz_stream *chain, int len); |
||
570 | fz_stream *fz_open_arc4(fz_stream *chain, unsigned char *key, unsigned keylen); |
||
571 | fz_stream *fz_open_aesd(fz_stream *chain, unsigned char *key, unsigned keylen); |
||
572 | fz_stream *fz_open_a85d(fz_stream *chain); |
||
573 | fz_stream *fz_open_ahxd(fz_stream *chain); |
||
574 | fz_stream *fz_open_rld(fz_stream *chain); |
||
575 | fz_stream *fz_open_dctd(fz_stream *chain, fz_obj *param); |
||
576 | fz_stream *fz_open_faxd(fz_stream *chain, fz_obj *param); |
||
577 | fz_stream *fz_open_flated(fz_stream *chain); |
||
578 | fz_stream *fz_open_lzwd(fz_stream *chain, fz_obj *param); |
||
579 | fz_stream *fz_open_predict(fz_stream *chain, fz_obj *param); |
||
580 | fz_stream *fz_open_jbig2d(fz_stream *chain, fz_buffer *global); |
||
581 | |||
582 | /* |
||
583 | * Resources and other graphics related objects. |
||
584 | */ |
||
585 | |||
586 | enum { FZ_MAX_COLORS = 32 }; |
||
587 | |||
588 | int fz_find_blendmode(char *name); |
||
589 | char *fz_blendmode_name(int blendmode); |
||
590 | |||
591 | /* |
||
592 | * Pixmaps have n components per pixel. the last is always alpha. |
||
593 | * premultiplied alpha when rendering, but non-premultiplied for colorspace |
||
594 | * conversions and rescaling. |
||
595 | */ |
||
596 | |||
597 | typedef struct fz_pixmap_s fz_pixmap; |
||
598 | typedef struct fz_colorspace_s fz_colorspace; |
||
599 | |||
600 | struct fz_pixmap_s |
||
601 | { |
||
602 | int refs; |
||
603 | int x, y, w, h, n; |
||
604 | fz_pixmap *mask; /* explicit soft/image mask */ |
||
605 | int interpolate; |
||
606 | int xres, yres; |
||
607 | fz_colorspace *colorspace; |
||
608 | unsigned char *samples; |
||
609 | int free_samples; |
||
610 | }; |
||
611 | |||
612 | /* will return NULL if soft limit is exceeded */ |
||
613 | fz_pixmap *fz_new_pixmap_with_limit(fz_colorspace *colorspace, int w, int h); |
||
614 | |||
615 | fz_pixmap *fz_new_pixmap_with_data(fz_colorspace *colorspace, int w, int h, unsigned char *samples); |
||
616 | fz_pixmap *fz_new_pixmap_with_rect(fz_colorspace *, fz_bbox bbox); |
||
617 | fz_pixmap *fz_new_pixmap_with_rect_and_data(fz_colorspace *, fz_bbox bbox, unsigned char *samples); |
||
618 | fz_pixmap *fz_new_pixmap(fz_colorspace *, int w, int h); |
||
619 | fz_pixmap *fz_keep_pixmap(fz_pixmap *pix); |
||
620 | void fz_drop_pixmap(fz_pixmap *pix); |
||
621 | void fz_clear_pixmap(fz_pixmap *pix); |
||
622 | void fz_clear_pixmap_with_color(fz_pixmap *pix, int value); |
||
623 | void fz_clear_pixmap_rect_with_color(fz_pixmap *pix, int value, fz_bbox r); |
||
624 | void fz_copy_pixmap_rect(fz_pixmap *dest, fz_pixmap *src, fz_bbox r); |
||
625 | void fz_premultiply_pixmap(fz_pixmap *pix); |
||
626 | fz_pixmap *fz_alpha_from_gray(fz_pixmap *gray, int luminosity); |
||
627 | fz_bbox fz_bound_pixmap(fz_pixmap *pix); |
||
628 | void fz_invert_pixmap(fz_pixmap *pix); |
||
629 | void fz_gamma_pixmap(fz_pixmap *pix, float gamma); |
||
630 | |||
631 | fz_pixmap *fz_scale_pixmap(fz_pixmap *src, float x, float y, float w, float h); |
||
632 | fz_pixmap *fz_scale_pixmap_gridfit(fz_pixmap *src, float x, float y, float w, float h, int gridfit); |
||
633 | |||
634 | fz_error fz_write_pnm(fz_pixmap *pixmap, char *filename); |
||
635 | fz_error fz_write_pam(fz_pixmap *pixmap, char *filename, int savealpha); |
||
636 | fz_error fz_write_png(fz_pixmap *pixmap, char *filename, int savealpha); |
||
637 | |||
638 | fz_error fz_load_jpx_image(fz_pixmap **imgp, unsigned char *data, int size, fz_colorspace *dcs); |
||
639 | |||
640 | /* |
||
641 | * Bitmaps have 1 component per bit. Only used for creating halftoned versions |
||
642 | * of contone buffers, and saving out. Samples are stored msb first, akin to |
||
643 | * pbms. |
||
644 | */ |
||
645 | |||
646 | typedef struct fz_bitmap_s fz_bitmap; |
||
647 | |||
648 | struct fz_bitmap_s |
||
649 | { |
||
650 | int refs; |
||
651 | int w, h, stride, n; |
||
652 | unsigned char *samples; |
||
653 | }; |
||
654 | |||
655 | fz_bitmap *fz_new_bitmap(int w, int h, int n); |
||
656 | fz_bitmap *fz_keep_bitmap(fz_bitmap *bit); |
||
657 | void fz_clear_bitmap(fz_bitmap *bit); |
||
658 | void fz_drop_bitmap(fz_bitmap *bit); |
||
659 | |||
660 | fz_error fz_write_pbm(fz_bitmap *bitmap, char *filename); |
||
661 | |||
662 | /* |
||
663 | * A halftone is a set of threshold tiles, one per component. Each threshold |
||
664 | * tile is a pixmap, possibly of varying sizes and phases. |
||
665 | */ |
||
666 | |||
667 | typedef struct fz_halftone_s fz_halftone; |
||
668 | |||
669 | struct fz_halftone_s |
||
670 | { |
||
671 | int refs; |
||
672 | int n; |
||
673 | fz_pixmap *comp[1]; |
||
674 | }; |
||
675 | |||
676 | fz_halftone *fz_new_halftone(int num_comps); |
||
677 | fz_halftone *fz_get_default_halftone(int num_comps); |
||
678 | fz_halftone *fz_keep_halftone(fz_halftone *half); |
||
679 | void fz_drop_halftone(fz_halftone *half); |
||
680 | |||
681 | fz_bitmap *fz_halftone_pixmap(fz_pixmap *pix, fz_halftone *ht); |
||
682 | |||
683 | /* |
||
684 | * Colorspace resources. |
||
685 | */ |
||
686 | |||
687 | extern fz_colorspace *fz_device_gray; |
||
688 | extern fz_colorspace *fz_device_rgb; |
||
689 | extern fz_colorspace *fz_device_bgr; |
||
690 | extern fz_colorspace *fz_device_cmyk; |
||
691 | |||
692 | struct fz_colorspace_s |
||
693 | { |
||
694 | int refs; |
||
695 | char name[16]; |
||
696 | int n; |
||
697 | void (*to_rgb)(fz_colorspace *, float *src, float *rgb); |
||
698 | void (*from_rgb)(fz_colorspace *, float *rgb, float *dst); |
||
699 | void (*free_data)(fz_colorspace *); |
||
700 | void *data; |
||
701 | }; |
||
702 | |||
703 | fz_colorspace *fz_new_colorspace(char *name, int n); |
||
704 | fz_colorspace *fz_keep_colorspace(fz_colorspace *colorspace); |
||
705 | void fz_drop_colorspace(fz_colorspace *colorspace); |
||
706 | |||
707 | void fz_convert_color(fz_colorspace *srcs, float *srcv, fz_colorspace *dsts, float *dstv); |
||
708 | void fz_convert_pixmap(fz_pixmap *src, fz_pixmap *dst); |
||
709 | |||
710 | fz_colorspace *fz_find_device_colorspace(char *name); |
||
711 | |||
712 | /* |
||
713 | * Fonts come in two variants: |
||
714 | * Regular fonts are handled by FreeType. |
||
715 | * Type 3 fonts have callbacks to the interpreter. |
||
716 | */ |
||
717 | |||
718 | struct fz_device_s; |
||
719 | |||
720 | typedef struct fz_font_s fz_font; |
||
721 | char *ft_error_string(int err); |
||
722 | |||
723 | struct fz_font_s |
||
724 | { |
||
725 | int refs; |
||
726 | char name[32]; |
||
727 | |||
728 | void *ft_face; /* has an FT_Face if used */ |
||
729 | int ft_substitute; /* ... substitute metrics */ |
||
730 | int ft_bold; /* ... synthesize bold */ |
||
731 | int ft_italic; /* ... synthesize italic */ |
||
732 | int ft_hint; /* ... force hinting for DynaLab fonts */ |
||
733 | |||
734 | /* origin of font data */ |
||
735 | char *ft_file; |
||
736 | unsigned char *ft_data; |
||
737 | int ft_size; |
||
738 | |||
739 | fz_matrix t3matrix; |
||
740 | fz_obj *t3resources; |
||
741 | fz_buffer **t3procs; /* has 256 entries if used */ |
||
742 | float *t3widths; /* has 256 entries if used */ |
||
743 | void *t3xref; /* a pdf_xref for the callback */ |
||
744 | fz_error (*t3run)(void *xref, fz_obj *resources, fz_buffer *contents, |
||
745 | struct fz_device_s *dev, fz_matrix ctm); |
||
746 | |||
747 | fz_rect bbox; |
||
748 | |||
749 | /* substitute metrics */ |
||
750 | int width_count; |
||
751 | int *width_table; |
||
752 | }; |
||
753 | |||
754 | fz_font *fz_new_type3_font(char *name, fz_matrix matrix); |
||
755 | |||
756 | fz_error fz_new_font_from_memory(fz_font **fontp, unsigned char *data, int len, int index); |
||
757 | fz_error fz_new_font_from_file(fz_font **fontp, char *path, int index); |
||
758 | |||
759 | fz_font *fz_keep_font(fz_font *font); |
||
760 | void fz_drop_font(fz_font *font); |
||
761 | |||
762 | void fz_debug_font(fz_font *font); |
||
763 | void fz_set_font_bbox(fz_font *font, float xmin, float ymin, float xmax, float ymax); |
||
764 | |||
765 | /* |
||
766 | * Vector path buffer. |
||
767 | * It can be stroked and dashed, or be filled. |
||
768 | * It has a fill rule (nonzero or even_odd). |
||
769 | * |
||
770 | * When rendering, they are flattened, stroked and dashed straight |
||
771 | * into the Global Edge List. |
||
772 | */ |
||
773 | |||
774 | typedef struct fz_path_s fz_path; |
||
775 | typedef struct fz_stroke_state_s fz_stroke_state; |
||
776 | |||
777 | typedef union fz_path_item_s fz_path_item; |
||
778 | |||
779 | typedef enum fz_path_item_kind_e |
||
780 | { |
||
781 | FZ_MOVETO, |
||
782 | FZ_LINETO, |
||
783 | FZ_CURVETO, |
||
784 | FZ_CLOSE_PATH |
||
785 | } fz_path_item_kind; |
||
786 | |||
787 | union fz_path_item_s |
||
788 | { |
||
789 | fz_path_item_kind k; |
||
790 | float v; |
||
791 | }; |
||
792 | |||
793 | struct fz_path_s |
||
794 | { |
||
795 | int len, cap; |
||
796 | fz_path_item *items; |
||
797 | }; |
||
798 | |||
799 | struct fz_stroke_state_s |
||
800 | { |
||
801 | int start_cap, dash_cap, end_cap; |
||
802 | int linejoin; |
||
803 | float linewidth; |
||
804 | float miterlimit; |
||
805 | float dash_phase; |
||
806 | int dash_len; |
||
807 | float dash_list[32]; |
||
808 | }; |
||
809 | |||
810 | fz_path *fz_new_path(void); |
||
811 | void fz_moveto(fz_path*, float x, float y); |
||
812 | void fz_lineto(fz_path*, float x, float y); |
||
813 | void fz_curveto(fz_path*, float, float, float, float, float, float); |
||
814 | void fz_curvetov(fz_path*, float, float, float, float); |
||
815 | void fz_curvetoy(fz_path*, float, float, float, float); |
||
816 | void fz_closepath(fz_path*); |
||
817 | void fz_free_path(fz_path *path); |
||
818 | |||
819 | void fz_transform_path(fz_path *path, fz_matrix transform); |
||
820 | |||
821 | fz_path *fz_clone_path(fz_path *old); |
||
822 | |||
823 | fz_rect fz_bound_path(fz_path *path, fz_stroke_state *stroke, fz_matrix ctm); |
||
824 | void fz_debug_path(fz_path *, int indent); |
||
825 | |||
826 | /* |
||
827 | * Text buffer. |
||
828 | * |
||
829 | * The trm field contains the a, b, c and d coefficients. |
||
830 | * The e and f coefficients come from the individual elements, |
||
831 | * together they form the transform matrix for the glyph. |
||
832 | * |
||
833 | * Glyphs are referenced by glyph ID. |
||
834 | * The Unicode text equivalent is kept in a separate array |
||
835 | * with indexes into the glyph array. |
||
836 | */ |
||
837 | |||
838 | typedef struct fz_text_s fz_text; |
||
839 | typedef struct fz_text_item_s fz_text_item; |
||
840 | |||
841 | struct fz_text_item_s |
||
842 | { |
||
843 | float x, y; |
||
844 | int gid; /* -1 for one gid to many ucs mappings */ |
||
845 | int ucs; /* -1 for one ucs to many gid mappings */ |
||
846 | }; |
||
847 | |||
848 | struct fz_text_s |
||
849 | { |
||
850 | fz_font *font; |
||
851 | fz_matrix trm; |
||
852 | int wmode; |
||
853 | int len, cap; |
||
854 | fz_text_item *items; |
||
855 | }; |
||
856 | |||
857 | fz_text *fz_new_text(fz_font *face, fz_matrix trm, int wmode); |
||
858 | void fz_add_text(fz_text *text, int gid, int ucs, float x, float y); |
||
859 | void fz_free_text(fz_text *text); |
||
860 | void fz_debug_text(fz_text*, int indent); |
||
861 | fz_rect fz_bound_text(fz_text *text, fz_matrix ctm); |
||
862 | fz_text *fz_clone_text(fz_text *old); |
||
863 | |||
864 | /* |
||
865 | * The shading code uses gouraud shaded triangle meshes. |
||
866 | */ |
||
867 | |||
868 | enum |
||
869 | { |
||
870 | FZ_LINEAR, |
||
871 | FZ_RADIAL, |
||
872 | FZ_MESH, |
||
873 | }; |
||
874 | |||
875 | typedef struct fz_shade_s fz_shade; |
||
876 | |||
877 | struct fz_shade_s |
||
878 | { |
||
879 | int refs; |
||
880 | |||
881 | fz_rect bbox; /* can be fz_infinite_rect */ |
||
882 | fz_colorspace *colorspace; |
||
883 | |||
884 | fz_matrix matrix; /* matrix from pattern dict */ |
||
885 | int use_background; /* background color for fills but not 'sh' */ |
||
886 | float background[FZ_MAX_COLORS]; |
||
887 | |||
888 | int use_function; |
||
889 | float function[256][FZ_MAX_COLORS + 1]; |
||
890 | |||
891 | int type; /* linear, radial, mesh */ |
||
892 | int extend[2]; |
||
893 | |||
894 | int mesh_len; |
||
895 | int mesh_cap; |
||
896 | float *mesh; /* [x y 0], [x y r], [x y t] or [x y c1 ... cn] */ |
||
897 | }; |
||
898 | |||
899 | fz_shade *fz_keep_shade(fz_shade *shade); |
||
900 | void fz_drop_shade(fz_shade *shade); |
||
901 | void fz_debug_shade(fz_shade *shade); |
||
902 | |||
903 | fz_rect fz_bound_shade(fz_shade *shade, fz_matrix ctm); |
||
904 | void fz_paint_shade(fz_shade *shade, fz_matrix ctm, fz_pixmap *dest, fz_bbox bbox); |
||
905 | |||
906 | /* |
||
907 | * Glyph cache |
||
908 | */ |
||
909 | |||
910 | typedef struct fz_glyph_cache_s fz_glyph_cache; |
||
911 | |||
912 | fz_glyph_cache *fz_new_glyph_cache(void); |
||
913 | fz_pixmap *fz_render_ft_glyph(fz_font *font, int cid, fz_matrix trm); |
||
914 | fz_pixmap *fz_render_t3_glyph(fz_font *font, int cid, fz_matrix trm, fz_colorspace *model); |
||
915 | fz_pixmap *fz_render_ft_stroked_glyph(fz_font *font, int gid, fz_matrix trm, fz_matrix ctm, fz_stroke_state *state); |
||
916 | fz_pixmap *fz_render_glyph(fz_glyph_cache*, fz_font*, int, fz_matrix, fz_colorspace *model); |
||
917 | fz_pixmap *fz_render_stroked_glyph(fz_glyph_cache*, fz_font*, int, fz_matrix, fz_matrix, fz_stroke_state *stroke); |
||
918 | void fz_free_glyph_cache(fz_glyph_cache *); |
||
919 | |||
920 | /* |
||
921 | * Scan converter |
||
922 | */ |
||
923 | |||
924 | int fz_get_aa_level(void); |
||
925 | void fz_set_aa_level(int bits); |
||
926 | |||
927 | typedef struct fz_gel_s fz_gel; |
||
928 | |||
929 | fz_gel *fz_new_gel(void); |
||
930 | void fz_insert_gel(fz_gel *gel, float x0, float y0, float x1, float y1); |
||
931 | void fz_reset_gel(fz_gel *gel, fz_bbox clip); |
||
932 | void fz_sort_gel(fz_gel *gel); |
||
933 | fz_bbox fz_bound_gel(fz_gel *gel); |
||
934 | void fz_free_gel(fz_gel *gel); |
||
935 | int fz_is_rect_gel(fz_gel *gel); |
||
936 | |||
937 | void fz_scan_convert(fz_gel *gel, int eofill, fz_bbox clip, fz_pixmap *pix, unsigned char *colorbv); |
||
938 | |||
939 | void fz_flatten_fill_path(fz_gel *gel, fz_path *path, fz_matrix ctm, float flatness); |
||
940 | void fz_flatten_stroke_path(fz_gel *gel, fz_path *path, fz_stroke_state *stroke, fz_matrix ctm, float flatness, float linewidth); |
||
941 | void fz_flatten_dash_path(fz_gel *gel, fz_path *path, fz_stroke_state *stroke, fz_matrix ctm, float flatness, float linewidth); |
||
942 | |||
943 | /* |
||
944 | * The device interface. |
||
945 | */ |
||
946 | |||
947 | enum |
||
948 | { |
||
949 | /* Hints */ |
||
950 | FZ_IGNORE_IMAGE = 1, |
||
951 | FZ_IGNORE_SHADE = 2, |
||
952 | |||
953 | /* Flags */ |
||
954 | FZ_CHARPROC_MASK = 1, |
||
955 | FZ_CHARPROC_COLOR = 2, |
||
956 | }; |
||
957 | |||
958 | typedef struct fz_device_s fz_device; |
||
959 | |||
960 | struct fz_device_s |
||
961 | { |
||
962 | int hints; |
||
963 | int flags; |
||
964 | |||
965 | void *user; |
||
966 | void (*free_user)(void *); |
||
967 | |||
968 | void (*fill_path)(void *, fz_path *, int even_odd, fz_matrix, fz_colorspace *, float *color, float alpha); |
||
969 | void (*stroke_path)(void *, fz_path *, fz_stroke_state *, fz_matrix, fz_colorspace *, float *color, float alpha); |
||
970 | void (*clip_path)(void *, fz_path *, fz_rect *rect, int even_odd, fz_matrix); |
||
971 | void (*clip_stroke_path)(void *, fz_path *, fz_rect *rect, fz_stroke_state *, fz_matrix); |
||
972 | |||
973 | void (*fill_text)(void *, fz_text *, fz_matrix, fz_colorspace *, float *color, float alpha); |
||
974 | void (*stroke_text)(void *, fz_text *, fz_stroke_state *, fz_matrix, fz_colorspace *, float *color, float alpha); |
||
975 | void (*clip_text)(void *, fz_text *, fz_matrix, int accumulate); |
||
976 | void (*clip_stroke_text)(void *, fz_text *, fz_stroke_state *, fz_matrix); |
||
977 | void (*ignore_text)(void *, fz_text *, fz_matrix); |
||
978 | |||
979 | void (*fill_shade)(void *, fz_shade *shd, fz_matrix ctm, float alpha); |
||
980 | void (*fill_image)(void *, fz_pixmap *img, fz_matrix ctm, float alpha); |
||
981 | void (*fill_image_mask)(void *, fz_pixmap *img, fz_matrix ctm, fz_colorspace *, float *color, float alpha); |
||
982 | void (*clip_image_mask)(void *, fz_pixmap *img, fz_rect *rect, fz_matrix ctm); |
||
983 | |||
984 | void (*pop_clip)(void *); |
||
985 | |||
986 | void (*begin_mask)(void *, fz_rect, int luminosity, fz_colorspace *, float *bc); |
||
987 | void (*end_mask)(void *); |
||
988 | void (*begin_group)(void *, fz_rect, int isolated, int knockout, int blendmode, float alpha); |
||
989 | void (*end_group)(void *); |
||
990 | |||
991 | void (*begin_tile)(void *, fz_rect area, fz_rect view, float xstep, float ystep, fz_matrix ctm); |
||
992 | void (*end_tile)(void *); |
||
993 | }; |
||
994 | |||
995 | void fz_fill_path(fz_device *dev, fz_path *path, int even_odd, fz_matrix ctm, fz_colorspace *colorspace, float *color, float alpha); |
||
996 | void fz_stroke_path(fz_device *dev, fz_path *path, fz_stroke_state *stroke, fz_matrix ctm, fz_colorspace *colorspace, float *color, float alpha); |
||
997 | void fz_clip_path(fz_device *dev, fz_path *path, fz_rect *rect, int even_odd, fz_matrix ctm); |
||
998 | void fz_clip_stroke_path(fz_device *dev, fz_path *path, fz_rect *rect, fz_stroke_state *stroke, fz_matrix ctm); |
||
999 | void fz_fill_text(fz_device *dev, fz_text *text, fz_matrix ctm, fz_colorspace *colorspace, float *color, float alpha); |
||
1000 | void fz_stroke_text(fz_device *dev, fz_text *text, fz_stroke_state *stroke, fz_matrix ctm, fz_colorspace *colorspace, float *color, float alpha); |
||
1001 | void fz_clip_text(fz_device *dev, fz_text *text, fz_matrix ctm, int accumulate); |
||
1002 | void fz_clip_stroke_text(fz_device *dev, fz_text *text, fz_stroke_state *stroke, fz_matrix ctm); |
||
1003 | void fz_ignore_text(fz_device *dev, fz_text *text, fz_matrix ctm); |
||
1004 | void fz_pop_clip(fz_device *dev); |
||
1005 | void fz_fill_shade(fz_device *dev, fz_shade *shade, fz_matrix ctm, float alpha); |
||
1006 | void fz_fill_image(fz_device *dev, fz_pixmap *image, fz_matrix ctm, float alpha); |
||
1007 | void fz_fill_image_mask(fz_device *dev, fz_pixmap *image, fz_matrix ctm, fz_colorspace *colorspace, float *color, float alpha); |
||
1008 | void fz_clip_image_mask(fz_device *dev, fz_pixmap *image, fz_rect *rect, fz_matrix ctm); |
||
1009 | void fz_begin_mask(fz_device *dev, fz_rect area, int luminosity, fz_colorspace *colorspace, float *bc); |
||
1010 | void fz_end_mask(fz_device *dev); |
||
1011 | void fz_begin_group(fz_device *dev, fz_rect area, int isolated, int knockout, int blendmode, float alpha); |
||
1012 | void fz_end_group(fz_device *dev); |
||
1013 | void fz_begin_tile(fz_device *dev, fz_rect area, fz_rect view, float xstep, float ystep, fz_matrix ctm); |
||
1014 | void fz_end_tile(fz_device *dev); |
||
1015 | |||
1016 | fz_device *fz_new_device(void *user); |
||
1017 | void fz_free_device(fz_device *dev); |
||
1018 | |||
1019 | fz_device *fz_new_trace_device(void); |
||
1020 | fz_device *fz_new_bbox_device(fz_bbox *bboxp); |
||
1021 | fz_device *fz_new_draw_device(fz_glyph_cache *cache, fz_pixmap *dest); |
||
1022 | fz_device *fz_new_draw_device_type3(fz_glyph_cache *cache, fz_pixmap *dest); |
||
1023 | |||
1024 | /* |
||
1025 | * Text extraction device |
||
1026 | */ |
||
1027 | |||
1028 | typedef struct fz_text_span_s fz_text_span; |
||
1029 | typedef struct fz_text_char_s fz_text_char; |
||
1030 | |||
1031 | struct fz_text_char_s |
||
1032 | { |
||
1033 | int c; |
||
1034 | fz_bbox bbox; |
||
1035 | }; |
||
1036 | |||
1037 | struct fz_text_span_s |
||
1038 | { |
||
1039 | fz_font *font; |
||
1040 | float size; |
||
1041 | int wmode; |
||
1042 | int len, cap; |
||
1043 | fz_text_char *text; |
||
1044 | fz_text_span *next; |
||
1045 | int eol; |
||
1046 | }; |
||
1047 | |||
1048 | fz_text_span *fz_new_text_span(void); |
||
1049 | void fz_free_text_span(fz_text_span *line); |
||
1050 | void fz_debug_text_span(fz_text_span *line); |
||
1051 | void fz_debug_text_span_xml(fz_text_span *span); |
||
1052 | |||
1053 | fz_device *fz_new_text_device(fz_text_span *text); |
||
1054 | |||
1055 | /* |
||
1056 | * Display list device -- record and play back device commands. |
||
1057 | */ |
||
1058 | |||
1059 | typedef struct fz_display_list_s fz_display_list; |
||
1060 | |||
1061 | fz_display_list *fz_new_display_list(void); |
||
1062 | void fz_free_display_list(fz_display_list *list); |
||
1063 | fz_device *fz_new_list_device(fz_display_list *list); |
||
1064 | void fz_execute_display_list(fz_display_list *list, fz_device *dev, fz_matrix ctm, fz_bbox area); |
||
1065 | |||
1066 | /* |
||
1067 | * Plotting functions. |
||
1068 | */ |
||
1069 | |||
1070 | void fz_accelerate(void); |
||
1071 | void fz_accelerate_arch(void); |
||
1072 | |||
1073 | void fz_decode_tile(fz_pixmap *pix, float *decode); |
||
1074 | void fz_decode_indexed_tile(fz_pixmap *pix, float *decode, int maxval); |
||
1075 | void fz_unpack_tile(fz_pixmap *dst, unsigned char * restrict src, int n, int depth, int stride, int scale); |
||
1076 | |||
1077 | void fz_paint_solid_alpha(unsigned char * restrict dp, int w, int alpha); |
||
1078 | void fz_paint_solid_color(unsigned char * restrict dp, int n, int w, unsigned char *color); |
||
1079 | |||
1080 | void fz_paint_span(unsigned char * restrict dp, unsigned char * restrict sp, int n, int w, int alpha); |
||
1081 | void fz_paint_span_with_color(unsigned char * restrict dp, unsigned char * restrict mp, int n, int w, unsigned char *color); |
||
1082 | |||
1083 | void fz_paint_image(fz_pixmap *dst, fz_bbox scissor, fz_pixmap *shape, fz_pixmap *img, fz_matrix ctm, int alpha); |
||
1084 | void fz_paint_image_with_color(fz_pixmap *dst, fz_bbox scissor, fz_pixmap *shape, fz_pixmap *img, fz_matrix ctm, unsigned char *colorbv); |
||
1085 | |||
1086 | void fz_paint_pixmap(fz_pixmap *dst, fz_pixmap *src, int alpha); |
||
1087 | void fz_paint_pixmap_with_mask(fz_pixmap *dst, fz_pixmap *src, fz_pixmap *msk); |
||
1088 | void fz_paint_pixmap_with_rect(fz_pixmap *dst, fz_pixmap *src, int alpha, fz_bbox bbox); |
||
1089 | |||
1090 | void fz_blend_pixmap(fz_pixmap *dst, fz_pixmap *src, int alpha, int blendmode, int isolated, fz_pixmap *shape); |
||
1091 | |||
1092 | enum |
||
1093 | { |
||
1094 | /* PDF 1.4 -- standard separable */ |
||
1095 | FZ_BLEND_NORMAL, |
||
1096 | FZ_BLEND_MULTIPLY, |
||
1097 | FZ_BLEND_SCREEN, |
||
1098 | FZ_BLEND_OVERLAY, |
||
1099 | FZ_BLEND_DARKEN, |
||
1100 | FZ_BLEND_LIGHTEN, |
||
1101 | FZ_BLEND_COLOR_DODGE, |
||
1102 | FZ_BLEND_COLOR_BURN, |
||
1103 | FZ_BLEND_HARD_LIGHT, |
||
1104 | FZ_BLEND_SOFT_LIGHT, |
||
1105 | FZ_BLEND_DIFFERENCE, |
||
1106 | FZ_BLEND_EXCLUSION, |
||
1107 | |||
1108 | /* PDF 1.4 -- standard non-separable */ |
||
1109 | FZ_BLEND_HUE, |
||
1110 | FZ_BLEND_SATURATION, |
||
1111 | FZ_BLEND_COLOR, |
||
1112 | FZ_BLEND_LUMINOSITY, |
||
1113 | |||
1114 | /* For packing purposes */ |
||
1115 | FZ_BLEND_MODEMASK = 15, |
||
1116 | FZ_BLEND_ISOLATED = 16, |
||
1117 | FZ_BLEND_KNOCKOUT = 32 |
||
1118 | }; |
||
1119 | |||
1120 | #endif><>><>><>><>=>>>8))><8))>>>> |