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
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
|
#ifndef MUPDF_INTERNAL_H
#define MUPDF_INTERNAL_H
#include "mupdf.h"
#include "fitz-internal.h"
void pdf_set_str_len(pdf_obj *obj, int newlen);
void *pdf_get_indirect_document(pdf_obj *obj);
void pdf_set_int(pdf_obj *obj, int i);
/*
* PDF Images
*/
typedef struct pdf_image_params_s pdf_image_params;
struct pdf_image_params_s
{
int type;
fz_colorspace *colorspace;
union
{
struct
{
int columns;
int rows;
int k;
int eol;
int eba;
int eob;
int bi1;
}
fax;
struct
{
int ct;
}
jpeg;
struct
{
int columns;
int colors;
int predictor;
int bpc;
}
flate;
struct
{
int columns;
int colors;
int predictor;
int bpc;
int ec;
}
lzw;
}
u;
};
typedef struct pdf_image_s pdf_image;
struct pdf_image_s
{
fz_image base;
fz_pixmap *tile;
int n, bpc;
pdf_image_params params;
fz_buffer *buffer;
int colorkey[FZ_MAX_COLORS * 2];
float decode[FZ_MAX_COLORS * 2];
int imagemask;
int interpolate;
int usecolorkey;
};
enum
{
PDF_IMAGE_RAW,
PDF_IMAGE_FAX,
PDF_IMAGE_JPEG,
PDF_IMAGE_RLD,
PDF_IMAGE_FLATE,
PDF_IMAGE_LZW,
PDF_IMAGE_JPX
};
/*
* tokenizer and low-level object parser
*/
enum
{
PDF_TOK_ERROR, PDF_TOK_EOF,
PDF_TOK_OPEN_ARRAY, PDF_TOK_CLOSE_ARRAY,
PDF_TOK_OPEN_DICT, PDF_TOK_CLOSE_DICT,
PDF_TOK_OPEN_BRACE, PDF_TOK_CLOSE_BRACE,
PDF_TOK_NAME, PDF_TOK_INT, PDF_TOK_REAL, PDF_TOK_STRING, PDF_TOK_KEYWORD,
PDF_TOK_R, PDF_TOK_TRUE, PDF_TOK_FALSE, PDF_TOK_NULL,
PDF_TOK_OBJ, PDF_TOK_ENDOBJ,
PDF_TOK_STREAM, PDF_TOK_ENDSTREAM,
PDF_TOK_XREF, PDF_TOK_TRAILER, PDF_TOK_STARTXREF,
PDF_NUM_TOKENS
};
enum
{
PDF_LEXBUF_SMALL = 256,
PDF_LEXBUF_LARGE = 65536
};
typedef struct pdf_lexbuf_s pdf_lexbuf;
typedef struct pdf_lexbuf_large_s pdf_lexbuf_large;
struct pdf_lexbuf_s
{
fz_context *ctx;
int size;
int base_size;
int len;
int i;
float f;
char *scratch;
char buffer[PDF_LEXBUF_SMALL];
};
struct pdf_lexbuf_large_s
{
pdf_lexbuf base;
char buffer[PDF_LEXBUF_LARGE - PDF_LEXBUF_SMALL];
};
void pdf_lexbuf_init(fz_context *ctx, pdf_lexbuf *lexbuf, int size);
void pdf_lexbuf_fin(pdf_lexbuf *lexbuf);
ptrdiff_t pdf_lexbuf_grow(pdf_lexbuf *lexbuf);
int pdf_lex(fz_stream *f, pdf_lexbuf *lexbuf);
pdf_obj *pdf_parse_array(pdf_document *doc, fz_stream *f, pdf_lexbuf *buf);
pdf_obj *pdf_parse_dict(pdf_document *doc, fz_stream *f, pdf_lexbuf *buf);
pdf_obj *pdf_parse_stm_obj(pdf_document *doc, fz_stream *f, pdf_lexbuf *buf);
pdf_obj *pdf_parse_ind_obj(pdf_document *doc, fz_stream *f, pdf_lexbuf *buf, int *num, int *gen, int *stm_ofs);
/*
pdf_print_token: print a lexed token to a buffer, growing if necessary
*/
void pdf_print_token(fz_context *ctx, fz_buffer *buf, int tok, pdf_lexbuf *lex);
/*
* xref and object / stream api
*/
typedef struct pdf_xref_entry_s pdf_xref_entry;
struct pdf_xref_entry_s
{
char type; /* 0=unset (f)ree i(n)use (o)bjstm */
int ofs; /* file offset / objstm object number */
int gen; /* generation / objstm index */
int stm_ofs; /* on-disk stream */
fz_buffer *stm_buf; /* in-memory stream (for updated objects) */
pdf_obj *obj; /* stored/cached object */
};
typedef struct pdf_crypt_s pdf_crypt;
typedef struct pdf_ocg_descriptor_s pdf_ocg_descriptor;
typedef struct pdf_ocg_entry_s pdf_ocg_entry;
typedef struct pdf_hotspot_s pdf_hotspot;
struct pdf_ocg_entry_s
{
int num;
int gen;
int state;
};
struct pdf_ocg_descriptor_s
{
int len;
pdf_ocg_entry *ocgs;
pdf_obj *intent;
};
enum
{
HOTSPOT_POINTER_DOWN = 0x1,
HOTSPOT_POINTER_OVER = 0x2
};
struct pdf_hotspot_s
{
int num;
int gen;
int state;
};
typedef struct pdf_js_s pdf_js;
struct pdf_document_s
{
fz_document super;
fz_context *ctx;
fz_stream *file;
int version;
int startxref;
int file_size;
pdf_crypt *crypt;
pdf_obj *trailer;
pdf_ocg_descriptor *ocg;
pdf_hotspot hotspot;
int len;
pdf_xref_entry *table;
int page_len;
int page_cap;
pdf_obj **page_objs;
pdf_obj **page_refs;
pdf_lexbuf_large lexbuf;
pdf_annot *focus;
pdf_obj *focus_obj;
pdf_js *js;
int recalculating;
int dirty;
};
pdf_document *pdf_open_document_no_run(fz_context *ctx, const char *filename);
pdf_document *pdf_open_document_no_run_with_stream(fz_stream *file);
void pdf_cache_object(pdf_document *doc, int num, int gen);
fz_stream *pdf_open_inline_stream(pdf_document *doc, pdf_obj *stmobj, int length, fz_stream *chain, pdf_image_params *params);
fz_buffer *pdf_load_image_stream(pdf_document *doc, int num, int gen, int orig_num, int orig_gen, pdf_image_params *params);
fz_stream *pdf_open_image_stream(pdf_document *doc, int num, int gen, int orig_num, int orig_gen, pdf_image_params *params);
fz_stream *pdf_open_stream_with_offset(pdf_document *doc, int num, int gen, pdf_obj *dict, int stm_ofs);
fz_stream *pdf_open_image_decomp_stream(fz_context *ctx, fz_buffer *, pdf_image_params *params, int *factor);
fz_stream *pdf_open_contents_stream(pdf_document *xref, pdf_obj *obj);
fz_buffer *pdf_load_raw_renumbered_stream(pdf_document *doc, int num, int gen, int orig_num, int orig_gen);
fz_buffer *pdf_load_renumbered_stream(pdf_document *doc, int num, int gen, int orig_num, int orig_gen);
fz_stream *pdf_open_raw_renumbered_stream(pdf_document *doc, int num, int gen, int orig_num, int orig_gen);
void pdf_repair_xref(pdf_document *doc, pdf_lexbuf *buf);
void pdf_repair_obj_stms(pdf_document *doc);
void pdf_resize_xref(pdf_document *doc, int newcap);
pdf_obj *pdf_new_ref(pdf_document *doc, pdf_obj *obj);
void pdf_print_xref(pdf_document *);
/*
* Encryption
*/
pdf_crypt *pdf_new_crypt(fz_context *ctx, pdf_obj *enc, pdf_obj *id);
void pdf_free_crypt(fz_context *ctx, pdf_crypt *crypt);
void pdf_crypt_obj(fz_context *ctx, pdf_crypt *crypt, pdf_obj *obj, int num, int gen);
void pdf_crypt_buffer(fz_context *ctx, pdf_crypt *crypt, fz_buffer *buf, int num, int gen);
fz_stream *pdf_open_crypt(fz_stream *chain, pdf_crypt *crypt, int num, int gen);
fz_stream *pdf_open_crypt_with_filter(fz_stream *chain, pdf_crypt *crypt, char *name, int num, int gen);
int pdf_crypt_version(pdf_document *doc);
int pdf_crypt_revision(pdf_document *doc);
char *pdf_crypt_method(pdf_document *doc);
int pdf_crypt_length(pdf_document *doc);
unsigned char *pdf_crypt_key(pdf_document *doc);
#ifndef NDEBUG
void pdf_print_crypt(pdf_crypt *crypt);
#endif
/*
* Functions, Colorspaces, Shadings and Images
*/
typedef struct pdf_function_s pdf_function;
pdf_function *pdf_load_function(pdf_document *doc, pdf_obj *ref, int in, int out);
void pdf_eval_function(fz_context *ctx, pdf_function *func, float *in, int inlen, float *out, int outlen);
pdf_function *pdf_keep_function(fz_context *ctx, pdf_function *func);
void pdf_drop_function(fz_context *ctx, pdf_function *func);
unsigned int pdf_function_size(pdf_function *func);
fz_colorspace *pdf_load_colorspace(pdf_document *doc, pdf_obj *obj);
fz_pixmap *pdf_expand_indexed_pixmap(fz_context *ctx, fz_pixmap *src);
fz_shade *pdf_load_shading(pdf_document *doc, pdf_obj *obj);
fz_image *pdf_load_inline_image(pdf_document *doc, pdf_obj *rdb, pdf_obj *dict, fz_stream *file);
int pdf_is_jpx_image(fz_context *ctx, pdf_obj *dict);
/*
* Pattern
*/
typedef struct pdf_pattern_s pdf_pattern;
struct pdf_pattern_s
{
fz_storable storable;
int ismask;
float xstep;
float ystep;
fz_matrix matrix;
fz_rect bbox;
pdf_obj *resources;
pdf_obj *contents;
};
pdf_pattern *pdf_load_pattern(pdf_document *doc, pdf_obj *obj);
pdf_pattern *pdf_keep_pattern(fz_context *ctx, pdf_pattern *pat);
void pdf_drop_pattern(fz_context *ctx, pdf_pattern *pat);
/*
* XObject
*/
typedef struct pdf_xobject_s pdf_xobject;
struct pdf_xobject_s
{
fz_storable storable;
fz_matrix matrix;
fz_rect bbox;
int isolated;
int knockout;
int transparency;
fz_colorspace *colorspace;
pdf_obj *resources;
pdf_obj *contents;
pdf_obj *me;
};
pdf_xobject *pdf_load_xobject(pdf_document *doc, pdf_obj *obj);
pdf_obj *pdf_new_xobject(pdf_document *doc, fz_rect *bbox, fz_matrix *mat);
pdf_xobject *pdf_keep_xobject(fz_context *ctx, pdf_xobject *xobj);
void pdf_drop_xobject(fz_context *ctx, pdf_xobject *xobj);
void pdf_update_xobject_contents(pdf_document *xref, pdf_xobject *form, fz_buffer *buffer);
void pdf_update_appearance(pdf_document *doc, pdf_obj *obj);
/*
* CMap
*/
typedef struct pdf_cmap_s pdf_cmap;
typedef struct pdf_range_s pdf_range;
enum { PDF_CMAP_SINGLE, PDF_CMAP_RANGE, PDF_CMAP_TABLE, PDF_CMAP_MULTI };
struct pdf_range_s
{
unsigned short low;
/* Next, we pack 2 fields into the same unsigned short. Top 14 bits
* are the extent, bottom 2 bits are flags: single, range, table,
* multi */
unsigned short extent_flags;
unsigned short offset; /* range-delta or table-index */
};
struct pdf_cmap_s
{
fz_storable storable;
char cmap_name[32];
char usecmap_name[32];
pdf_cmap *usecmap;
int wmode;
int codespace_len;
struct
{
unsigned short n;
unsigned short low;
unsigned short high;
} codespace[40];
int rlen, rcap;
pdf_range *ranges;
int tlen, tcap;
unsigned short *table;
};
pdf_cmap *pdf_new_cmap(fz_context *ctx);
pdf_cmap *pdf_keep_cmap(fz_context *ctx, pdf_cmap *cmap);
void pdf_drop_cmap(fz_context *ctx, pdf_cmap *cmap);
void pdf_free_cmap_imp(fz_context *ctx, fz_storable *cmap);
unsigned int pdf_cmap_size(fz_context *ctx, pdf_cmap *cmap);
int pdf_cmap_wmode(fz_context *ctx, pdf_cmap *cmap);
void pdf_set_cmap_wmode(fz_context *ctx, pdf_cmap *cmap, int wmode);
void pdf_set_usecmap(fz_context *ctx, pdf_cmap *cmap, pdf_cmap *usecmap);
void pdf_add_codespace(fz_context *ctx, pdf_cmap *cmap, int low, int high, int n);
void pdf_map_range_to_table(fz_context *ctx, pdf_cmap *cmap, int low, int *map, int len);
void pdf_map_range_to_range(fz_context *ctx, pdf_cmap *cmap, int srclo, int srchi, int dstlo);
void pdf_map_one_to_many(fz_context *ctx, pdf_cmap *cmap, int one, int *many, int len);
void pdf_sort_cmap(fz_context *ctx, pdf_cmap *cmap);
int pdf_lookup_cmap(pdf_cmap *cmap, int cpt);
int pdf_lookup_cmap_full(pdf_cmap *cmap, int cpt, int *out);
int pdf_decode_cmap(pdf_cmap *cmap, unsigned char *s, int *cpt);
pdf_cmap *pdf_new_identity_cmap(fz_context *ctx, int wmode, int bytes);
pdf_cmap *pdf_load_cmap(fz_context *ctx, fz_stream *file);
pdf_cmap *pdf_load_system_cmap(fz_context *ctx, char *name);
pdf_cmap *pdf_load_builtin_cmap(fz_context *ctx, char *name);
pdf_cmap *pdf_load_embedded_cmap(pdf_document *doc, pdf_obj *ref);
#ifndef NDEBUG
void pdf_print_cmap(fz_context *ctx, pdf_cmap *cmap);
#endif
/*
* Font
*/
enum
{
PDF_FD_FIXED_PITCH = 1 << 0,
PDF_FD_SERIF = 1 << 1,
PDF_FD_SYMBOLIC = 1 << 2,
PDF_FD_SCRIPT = 1 << 3,
PDF_FD_NONSYMBOLIC = 1 << 5,
PDF_FD_ITALIC = 1 << 6,
PDF_FD_ALL_CAP = 1 << 16,
PDF_FD_SMALL_CAP = 1 << 17,
PDF_FD_FORCE_BOLD = 1 << 18
};
enum { PDF_ROS_CNS, PDF_ROS_GB, PDF_ROS_JAPAN, PDF_ROS_KOREA };
void pdf_load_encoding(char **estrings, char *encoding);
int pdf_lookup_agl(char *name);
const char **pdf_lookup_agl_duplicates(int ucs);
extern const unsigned short pdf_doc_encoding[256];
extern const char * const pdf_mac_roman[256];
extern const char * const pdf_mac_expert[256];
extern const char * const pdf_win_ansi[256];
extern const char * const pdf_standard[256];
typedef struct pdf_font_desc_s pdf_font_desc;
typedef struct pdf_hmtx_s pdf_hmtx;
typedef struct pdf_vmtx_s pdf_vmtx;
struct pdf_hmtx_s
{
unsigned short lo;
unsigned short hi;
int w; /* type3 fonts can be big! */
};
struct pdf_vmtx_s
{
unsigned short lo;
unsigned short hi;
short x;
short y;
short w;
};
struct pdf_font_desc_s
{
fz_storable storable;
unsigned int size;
fz_font *font;
/* FontDescriptor */
int flags;
float italic_angle;
float ascent;
float descent;
float cap_height;
float x_height;
float missing_width;
/* Encoding (CMap) */
pdf_cmap *encoding;
pdf_cmap *to_ttf_cmap;
int cid_to_gid_len;
unsigned short *cid_to_gid;
/* ToUnicode */
pdf_cmap *to_unicode;
int cid_to_ucs_len;
unsigned short *cid_to_ucs;
/* Metrics (given in the PDF file) */
int wmode;
int hmtx_len, hmtx_cap;
pdf_hmtx dhmtx;
pdf_hmtx *hmtx;
int vmtx_len, vmtx_cap;
pdf_vmtx dvmtx;
pdf_vmtx *vmtx;
int is_embedded;
};
void pdf_set_font_wmode(fz_context *ctx, pdf_font_desc *font, int wmode);
void pdf_set_default_hmtx(fz_context *ctx, pdf_font_desc *font, int w);
void pdf_set_default_vmtx(fz_context *ctx, pdf_font_desc *font, int y, int w);
void pdf_add_hmtx(fz_context *ctx, pdf_font_desc *font, int lo, int hi, int w);
void pdf_add_vmtx(fz_context *ctx, pdf_font_desc *font, int lo, int hi, int x, int y, int w);
void pdf_end_hmtx(fz_context *ctx, pdf_font_desc *font);
void pdf_end_vmtx(fz_context *ctx, pdf_font_desc *font);
pdf_hmtx pdf_lookup_hmtx(fz_context *ctx, pdf_font_desc *font, int cid);
pdf_vmtx pdf_lookup_vmtx(fz_context *ctx, pdf_font_desc *font, int cid);
void pdf_load_to_unicode(pdf_document *doc, pdf_font_desc *font, char **strings, char *collection, pdf_obj *cmapstm);
int pdf_font_cid_to_gid(fz_context *ctx, pdf_font_desc *fontdesc, int cid);
unsigned char *pdf_lookup_builtin_font(char *name, unsigned int *len);
unsigned char *pdf_lookup_substitute_font(int mono, int serif, int bold, int italic, unsigned int *len);
unsigned char *pdf_lookup_substitute_cjk_font(int ros, int serif, unsigned int *len);
pdf_font_desc *pdf_load_type3_font(pdf_document *doc, pdf_obj *rdb, pdf_obj *obj);
pdf_font_desc *pdf_load_font(pdf_document *doc, pdf_obj *rdb, pdf_obj *obj);
pdf_font_desc *pdf_new_font_desc(fz_context *ctx);
pdf_font_desc *pdf_keep_font(fz_context *ctx, pdf_font_desc *fontdesc);
void pdf_drop_font(fz_context *ctx, pdf_font_desc *font);
#ifndef NDEBUG
void pdf_print_font(fz_context *ctx, pdf_font_desc *fontdesc);
#endif
fz_rect pdf_measure_text(fz_context *ctx, pdf_font_desc *fontdesc, unsigned char *buf, int len);
float pdf_text_stride(fz_context *ctx, pdf_font_desc *fontdesc, float fontsize, unsigned char *buf, int len, float room, int *count);
/*
* Interactive features
*/
struct pdf_annot_s
{
pdf_obj *obj;
fz_rect rect;
fz_rect pagerect;
pdf_xobject *ap;
fz_matrix matrix;
pdf_annot *next;
int type;
};
fz_link_dest pdf_parse_link_dest(pdf_document *doc, pdf_obj *dest);
fz_link_dest pdf_parse_action(pdf_document *doc, pdf_obj *action);
pdf_obj *pdf_lookup_dest(pdf_document *doc, pdf_obj *needle);
pdf_obj *pdf_lookup_name(pdf_document *doc, char *which, pdf_obj *needle);
pdf_obj *pdf_load_name_tree(pdf_document *doc, char *which);
fz_link *pdf_load_link_annots(pdf_document *, pdf_obj *annots, fz_matrix page_ctm);
pdf_annot *pdf_load_annots(pdf_document *, pdf_obj *annots, fz_matrix page_ctm);
void pdf_free_annot(fz_context *ctx, pdf_annot *link);
int pdf_field_type(pdf_document *doc, pdf_obj *field);
char *pdf_field_value(pdf_document *doc, pdf_obj *field);
int pdf_field_set_value(pdf_document *doc, pdf_obj *field, char *text);
char *pdf_field_border_style(pdf_document *doc, pdf_obj *field);
void pdf_field_set_border_style(pdf_document *doc, pdf_obj *field, char *text);
void pdf_field_set_button_caption(pdf_document *doc, pdf_obj *field, char *text);
void pdf_field_set_fill_color(pdf_document *doc, pdf_obj *field, pdf_obj *col);
void pdf_field_set_text_color(pdf_document *doc, pdf_obj *field, pdf_obj *col);
int pdf_field_display(pdf_document *doc, pdf_obj *field);
void pdf_field_set_display(pdf_document *doc, pdf_obj *field, int d);
pdf_obj *pdf_lookup_field(pdf_obj *form, char *name);
void pdf_field_reset(pdf_document *doc, pdf_obj *field);
/*
* Page tree, pages and related objects
*/
struct pdf_page_s
{
fz_matrix ctm; /* calculated from mediabox and rotate */
fz_rect mediabox;
int rotate;
int transparency;
pdf_obj *resources;
pdf_obj *contents;
fz_link *links;
pdf_annot *annots;
};
/*
* Content stream parsing
*/
void pdf_run_glyph(pdf_document *doc, pdf_obj *resources, fz_buffer *contents, fz_device *dev, fz_matrix ctm, void *gstate);
/*
* PDF interface to store
*/
void pdf_store_item(fz_context *ctx, pdf_obj *key, void *val, unsigned int itemsize);
void *pdf_find_item(fz_context *ctx, fz_store_free_fn *free, pdf_obj *key);
void pdf_remove_item(fz_context *ctx, fz_store_free_fn *free, pdf_obj *key);
/*
* PDF interaction interface
*/
int pdf_has_unsaved_changes(pdf_document *doc);
int pdf_pass_event(pdf_document *doc, pdf_page *page, fz_ui_event *ui_event);
fz_rect *pdf_poll_screen_update(pdf_document *doc);
fz_widget *pdf_focused_widget(pdf_document *doc);
fz_widget *pdf_first_widget(pdf_document *doc, pdf_page *page);
fz_widget *pdf_next_widget(fz_widget *previous);
char *pdf_text_widget_text(pdf_document *doc, fz_widget *tw);
int pdf_text_widget_max_len(pdf_document *doc, fz_widget *tw);
int pdf_text_widget_content_type(pdf_document *doc, fz_widget *tw);
int pdf_text_widget_set_text(pdf_document *doc, fz_widget *tw, char *text);
int pdf_choice_widget_options(pdf_document *doc, fz_widget *tw, char *opts[]);
int pdf_choice_widget_is_multiselect(pdf_document *doc, fz_widget *tw);
int pdf_choice_widget_value(pdf_document *doc, fz_widget *tw, char *opts[]);
void pdf_choice_widget_set_value(pdf_document *doc, fz_widget *tw, int n, char *opts[]);
/*
* Javascript handler
*/
typedef struct pdf_js_event_s
{
pdf_obj *target;
char *value;
int rc;
} pdf_js_event;
pdf_js *pdf_new_js(pdf_document *doc);
void pdf_drop_js(pdf_js *js);
void pdf_js_load_document_level(pdf_js *js);
void pdf_js_setup_event(pdf_js *js, pdf_js_event *e);
pdf_js_event *pdf_js_get_event(pdf_js *js);
void pdf_js_execute(pdf_js *js, char *code);
void pdf_js_execute_count(pdf_js *js, char *code, int count);
/*
* Javascript engine interface
*/
typedef struct pdf_jsimp_s pdf_jsimp;
typedef struct pdf_jsimp_type_s pdf_jsimp_type;
typedef struct pdf_jsimp_obj_s pdf_jsimp_obj;
typedef void (pdf_jsimp_dtr)(void *jsctx, void *obj);
typedef pdf_jsimp_obj *(pdf_jsimp_method)(void *jsctx, void *obj, int argc, pdf_jsimp_obj *args[]);
typedef pdf_jsimp_obj *(pdf_jsimp_getter)(void *jsctx, void *obj);
typedef void (pdf_jsimp_setter)(void *jsctx, void *obj, pdf_jsimp_obj *val);
enum
{
JS_TYPE_UNKNOWN,
JS_TYPE_NULL,
JS_TYPE_STRING,
JS_TYPE_NUMBER,
JS_TYPE_ARRAY
};
pdf_jsimp *pdf_new_jsimp(fz_context *ctx, void *jsctx);
void pdf_drop_jsimp(pdf_jsimp *imp);
pdf_jsimp_type *pdf_jsimp_new_type(pdf_jsimp *imp, pdf_jsimp_dtr *dtr);
void pdf_jsimp_drop_type(pdf_jsimp *imp, pdf_jsimp_type *type);
void pdf_jsimp_addmethod(pdf_jsimp *imp, pdf_jsimp_type *type, char *name, pdf_jsimp_method *meth);
void pdf_jsimp_addproperty(pdf_jsimp *imp, pdf_jsimp_type *type, char *name, pdf_jsimp_getter *get, pdf_jsimp_setter *set);
void pdf_jsimp_set_global_type(pdf_jsimp *imp, pdf_jsimp_type *type);
pdf_jsimp_obj *pdf_jsimp_new_obj(pdf_jsimp *imp, pdf_jsimp_type *type, void *obj);
void pdf_jsimp_drop_obj(pdf_jsimp *imp, pdf_jsimp_obj *obj);
int pdf_jsimp_to_type(pdf_jsimp *imp, pdf_jsimp_obj *obj);
pdf_jsimp_obj *pdf_jsimp_from_string(pdf_jsimp *imp, char *str);
char *pdf_jsimp_to_string(pdf_jsimp *imp, pdf_jsimp_obj *obj);
pdf_jsimp_obj *pdf_jsimp_from_number(pdf_jsimp *imp, double num);
double pdf_jsimp_to_number(pdf_jsimp *imp, pdf_jsimp_obj *obj);
int pdf_jsimp_array_len(pdf_jsimp *imp, pdf_jsimp_obj *obj);
pdf_jsimp_obj *pdf_jsimp_array_item(pdf_jsimp *imp, pdf_jsimp_obj *obj, int i);
void pdf_jsimp_execute(pdf_jsimp *imp, char *code);
void pdf_jsimp_execute_count(pdf_jsimp *imp, char *code, int count);
#endif
|