diff options
author | Tor Andersson <tor.andersson@artifex.com> | 2013-06-18 00:18:28 +0200 |
---|---|---|
committer | Tor Andersson <tor.andersson@artifex.com> | 2013-06-18 17:37:13 +0200 |
commit | 923ab857eed6cd29b539910bf74be2aa26d71f39 (patch) | |
tree | 30693266e5d9cd1eab9ab53e58807f0c33cb762e | |
parent | f35d1117b7d62c885586d43fc934e296d09b4380 (diff) | |
download | mupdf-923ab857eed6cd29b539910bf74be2aa26d71f39.tar.xz |
Split pdf.h into subheaders.
-rw-r--r-- | Makefile | 2 | ||||
-rw-r--r-- | include/mupdf/pdf.h | 1410 | ||||
-rw-r--r-- | include/mupdf/pdf/annot.h | 117 | ||||
-rw-r--r-- | include/mupdf/pdf/cmap.h | 78 | ||||
-rw-r--r-- | include/mupdf/pdf/crypt.h | 41 | ||||
-rw-r--r-- | include/mupdf/pdf/document.h | 209 | ||||
-rw-r--r-- | include/mupdf/pdf/event.h | 216 | ||||
-rw-r--r-- | include/mupdf/pdf/field.h | 37 | ||||
-rw-r--r-- | include/mupdf/pdf/font.h | 129 | ||||
-rw-r--r-- | include/mupdf/pdf/javascript.h | 70 | ||||
-rw-r--r-- | include/mupdf/pdf/object.h | 107 | ||||
-rw-r--r-- | include/mupdf/pdf/output-pdf.h | 18 | ||||
-rw-r--r-- | include/mupdf/pdf/page.h | 95 | ||||
-rw-r--r-- | include/mupdf/pdf/parse.h | 38 | ||||
-rw-r--r-- | include/mupdf/pdf/resource.h | 77 | ||||
-rw-r--r-- | include/mupdf/pdf/widget.h | 120 | ||||
-rw-r--r-- | include/mupdf/pdf/xref.h | 85 | ||||
-rw-r--r-- | pdf/pdf_object.c | 4 |
18 files changed, 1457 insertions, 1396 deletions
@@ -59,7 +59,7 @@ RM_CMD = $(QUIET_RM) rm -f $@ # --- Rules --- FITZ_HDR := include/mupdf/fitz.h $(wildcard include/mupdf/fitz/*.h) -MUPDF_HDR := $(FITZ_HDR) include/mupdf/pdf.h +MUPDF_HDR := $(FITZ_HDR) include/mupdf/pdf.h $(wildcard include/mupdf/pdf/*.h) MUXPS_HDR := $(FITZ_HDR) include/mupdf/xps.h MUCBZ_HDR := $(FITZ_HDR) include/mupdf/cbz.h MUIMAGE_HDR := $(FITZ_HDR) include/mupdf/image.h diff --git a/include/mupdf/pdf.h b/include/mupdf/pdf.h index 67a4e2c9..c2e069a9 100644 --- a/include/mupdf/pdf.h +++ b/include/mupdf/pdf.h @@ -1,1401 +1,25 @@ -#ifndef MUPDF_H -#define MUPDF_H +#ifndef MUPDF_PDF_H +#define MUPDF_PDF_H #include "mupdf/fitz.h" -typedef struct pdf_document_s pdf_document; +#include "mupdf/pdf/object.h" +#include "mupdf/pdf/document.h" +#include "mupdf/pdf/parse.h" +#include "mupdf/pdf/xref.h" +#include "mupdf/pdf/crypt.h" -/* - * Dynamic objects. - * The same type of objects as found in PDF and PostScript. - * Used by the filters and the mupdf parser. - */ +#include "mupdf/pdf/page.h" +#include "mupdf/pdf/resource.h" +#include "mupdf/pdf/cmap.h" +#include "mupdf/pdf/font.h" -typedef struct pdf_obj_s pdf_obj; +#include "mupdf/pdf/annot.h" +#include "mupdf/pdf/field.h" +#include "mupdf/pdf/widget.h" +#include "mupdf/pdf/event.h" +#include "mupdf/pdf/javascript.h" -pdf_obj *pdf_new_null(fz_context *ctx); -pdf_obj *pdf_new_bool(fz_context *ctx, int b); -pdf_obj *pdf_new_int(fz_context *ctx, int i); -pdf_obj *pdf_new_real(fz_context *ctx, float f); -pdf_obj *pdf_new_name(fz_context *ctx, const char *str); -pdf_obj *pdf_new_string(fz_context *ctx, const char *str, int len); -pdf_obj *pdf_new_indirect(fz_context *ctx, int num, int gen, void *doc); -pdf_obj *pdf_new_array(fz_context *ctx, int initialcap); -pdf_obj *pdf_new_dict(fz_context *ctx, int initialcap); -pdf_obj *pdf_new_rect(fz_context *ctx, const fz_rect *rect); -pdf_obj *pdf_new_matrix(fz_context *ctx, const fz_matrix *mtx); -pdf_obj *pdf_copy_array(fz_context *ctx, pdf_obj *array); -pdf_obj *pdf_copy_dict(fz_context *ctx, pdf_obj *dict); - -pdf_obj *pdf_new_obj_from_str(fz_context *ctx, const char *src); - -pdf_obj *pdf_keep_obj(pdf_obj *obj); -void pdf_drop_obj(pdf_obj *obj); - -/* type queries */ -int pdf_is_null(pdf_obj *obj); -int pdf_is_bool(pdf_obj *obj); -int pdf_is_int(pdf_obj *obj); -int pdf_is_real(pdf_obj *obj); -int pdf_is_name(pdf_obj *obj); -int pdf_is_string(pdf_obj *obj); -int pdf_is_array(pdf_obj *obj); -int pdf_is_dict(pdf_obj *obj); -int pdf_is_indirect(pdf_obj *obj); -int pdf_is_stream(pdf_document *doc, int num, int gen); - -int pdf_objcmp(pdf_obj *a, pdf_obj *b); - -/* obj marking and unmarking functions - to avoid infinite recursions. */ -int pdf_obj_marked(pdf_obj *obj); -int pdf_obj_mark(pdf_obj *obj); -void pdf_obj_unmark(pdf_obj *obj); - -/* safe, silent failure, no error reporting on type mismatches */ -int pdf_to_bool(pdf_obj *obj); -int pdf_to_int(pdf_obj *obj); -float pdf_to_real(pdf_obj *obj); -char *pdf_to_name(pdf_obj *obj); -char *pdf_to_str_buf(pdf_obj *obj); -pdf_obj *pdf_to_dict(pdf_obj *obj); -int pdf_to_str_len(pdf_obj *obj); -int pdf_to_num(pdf_obj *obj); -int pdf_to_gen(pdf_obj *obj); - -int pdf_array_len(pdf_obj *array); -pdf_obj *pdf_array_get(pdf_obj *array, int i); -void pdf_array_put(pdf_obj *array, int i, pdf_obj *obj); -void pdf_array_push(pdf_obj *array, pdf_obj *obj); -void pdf_array_push_drop(pdf_obj *array, pdf_obj *obj); -void pdf_array_insert(pdf_obj *array, pdf_obj *obj); -int pdf_array_contains(pdf_obj *array, pdf_obj *obj); - -int pdf_dict_len(pdf_obj *dict); -pdf_obj *pdf_dict_get_key(pdf_obj *dict, int idx); -pdf_obj *pdf_dict_get_val(pdf_obj *dict, int idx); -pdf_obj *pdf_dict_get(pdf_obj *dict, pdf_obj *key); -pdf_obj *pdf_dict_gets(pdf_obj *dict, const char *key); -pdf_obj *pdf_dict_getp(pdf_obj *dict, const char *key); -pdf_obj *pdf_dict_getsa(pdf_obj *dict, const char *key, const char *abbrev); -void pdf_dict_put(pdf_obj *dict, pdf_obj *key, pdf_obj *val); -void pdf_dict_puts(pdf_obj *dict, const char *key, pdf_obj *val); -void pdf_dict_puts_drop(pdf_obj *dict, const char *key, pdf_obj *val); -void pdf_dict_putp(pdf_obj *dict, const char *key, pdf_obj *val); -void pdf_dict_putp_drop(pdf_obj *dict, const char *key, pdf_obj *val); -void pdf_dict_del(pdf_obj *dict, pdf_obj *key); -void pdf_dict_dels(pdf_obj *dict, const char *key); -void pdf_sort_dict(pdf_obj *dict); - -int pdf_fprint_obj(FILE *fp, pdf_obj *obj, int tight); - -#ifndef NDEBUG -void pdf_print_obj(pdf_obj *obj); -void pdf_print_ref(pdf_obj *obj); -#endif - -char *pdf_to_utf8(pdf_document *xref, pdf_obj *src); -unsigned short *pdf_to_ucs2(pdf_document *xref, pdf_obj *src); /* sumatrapdf */ -pdf_obj *pdf_to_utf8_name(pdf_document *xref, pdf_obj *src); -char *pdf_from_ucs2(pdf_document *xref, unsigned short *str); -void pdf_to_ucs2_buf(unsigned short *buffer, pdf_obj *src); - -fz_rect *pdf_to_rect(fz_context *ctx, pdf_obj *array, fz_rect *rect); -fz_matrix *pdf_to_matrix(fz_context *ctx, pdf_obj *array, fz_matrix *mat); - -int pdf_count_objects(pdf_document *doc); -pdf_obj *pdf_resolve_indirect(pdf_obj *ref); -pdf_obj *pdf_load_object(pdf_document *doc, int num, int gen); - -fz_buffer *pdf_load_raw_stream(pdf_document *doc, int num, int gen); -fz_buffer *pdf_load_stream(pdf_document *doc, int num, int gen); -fz_stream *pdf_open_raw_stream(pdf_document *doc, int num, int gen); -fz_stream *pdf_open_stream(pdf_document *doc, int num, int gen); - -fz_image *pdf_load_image(pdf_document *doc, pdf_obj *obj); - -fz_outline *pdf_load_outline(pdf_document *doc); - -/* - pdf_create_object: Allocate a slot in the xref table and return a fresh unused object number. -*/ -int pdf_create_object(pdf_document *xref); - -/* - pdf_delete_object: Remove object from xref table, marking the slot as free. -*/ -void pdf_delete_object(pdf_document *xref, int num); - -/* - pdf_update_object: Replace object in xref table with the passed in object. -*/ -void pdf_update_object(pdf_document *xref, int num, pdf_obj *obj); - -/* - pdf_update_stream: Replace stream contents for object in xref table with the passed in buffer. - - The buffer contents must match the /Filter setting. - If storing uncompressed data, make sure to delete the /Filter key from - the stream dictionary. If storing deflated data, make sure to set the - /Filter value to /FlateDecode. -*/ -void pdf_update_stream(pdf_document *xref, int num, fz_buffer *buf); - -/* - pdf_new_pdf_device: Create a pdf device. Rendering to the device creates - new pdf content. WARNING: this device is work in progress. It doesn't - currently support all rendering cases. -*/ -fz_device *pdf_new_pdf_device(pdf_document *doc, pdf_obj *contents, pdf_obj *resources, const fz_matrix *ctm); - -/* - pdf_write_document: Write out the document to a file with all changes finalised. -*/ -void pdf_write_document(pdf_document *doc, char *filename, fz_write_options *opts); - -/* - pdf_open_document: Open a PDF document. - - Open a PDF document by reading its cross reference table, so - MuPDF can locate PDF objects inside the file. Upon an broken - cross reference table or other parse errors MuPDF will restart - parsing the file from the beginning to try to rebuild a - (hopefully correct) cross reference table to allow further - processing of the file. - - The returned pdf_document should be used when calling most - other PDF functions. Note that it wraps the context, so those - functions implicitly get access to the global state in - context. - - filename: a path to a file as it would be given to open(2). -*/ -pdf_document *pdf_open_document(fz_context *ctx, const char *filename); - -/* - pdf_open_document_with_stream: Opens a PDF document. - - Same as pdf_open_document, but takes a stream instead of a - filename to locate the PDF document to open. Increments the - reference count of the stream. See fz_open_file, - fz_open_file_w or fz_open_fd for opening a stream, and - fz_close for closing an open stream. -*/ -pdf_document *pdf_open_document_with_stream(fz_context *ctx, fz_stream *file); - -/* - pdf_close_document: Closes and frees an opened PDF document. - - The resource store in the context associated with pdf_document - is emptied. - - Does not throw exceptions. -*/ -void pdf_close_document(pdf_document *doc); - -/* - pdf_specific: down-cast an fz_document to a pdf_document. - Returns NULL if underlying document is not PDF -*/ -pdf_document *pdf_specifics(fz_document *doc); - -int pdf_needs_password(pdf_document *doc); -int pdf_authenticate_password(pdf_document *doc, const char *pw); - -enum -{ - PDF_PERM_PRINT = 1 << 2, - PDF_PERM_CHANGE = 1 << 3, - PDF_PERM_COPY = 1 << 4, - PDF_PERM_NOTES = 1 << 5, - PDF_PERM_FILL_FORM = 1 << 8, - PDF_PERM_ACCESSIBILITY = 1 << 9, - PDF_PERM_ASSEMBLE = 1 << 10, - PDF_PERM_HIGH_RES_PRINT = 1 << 11, - PDF_DEFAULT_PERM_FLAGS = 0xfffc -}; - -int pdf_has_permission(pdf_document *doc, int p); - -typedef struct pdf_page_s pdf_page; - -int pdf_lookup_page_number(pdf_document *doc, pdf_obj *pageobj); -int pdf_count_pages(pdf_document *doc); - -/* - pdf_load_page: Load a page and its resources. - - Locates the page in the PDF document and loads the page and its - resources. After pdf_load_page is it possible to retrieve the size - of the page using pdf_bound_page, or to render the page using - pdf_run_page_*. - - number: page number, where 0 is the first page of the document. -*/ -pdf_page *pdf_load_page(pdf_document *doc, int number); - -fz_link *pdf_load_links(pdf_document *doc, pdf_page *page); - -/* - pdf_bound_page: Determine the size of a page. - - Determine the page size in user space units, taking page rotation - into account. The page size is taken to be the crop box if it - exists (visible area after cropping), otherwise the media box will - be used (possibly including printing marks). - - Does not throw exceptions. -*/ -fz_rect *pdf_bound_page(pdf_document *doc, pdf_page *page, fz_rect *); - -/* - pdf_free_page: Frees a page and its resources. - - Does not throw exceptions. -*/ -void pdf_free_page(pdf_document *doc, pdf_page *page); - -typedef struct pdf_annot_s pdf_annot; - -/* - pdf_first_annot: Return the first annotation on a page. - - Does not throw exceptions. -*/ -pdf_annot *pdf_first_annot(pdf_document *doc, pdf_page *page); - -/* - pdf_next_annot: Return the next annotation on a page. - - Does not throw exceptions. -*/ -pdf_annot *pdf_next_annot(pdf_document *doc, pdf_annot *annot); - -/* - pdf_bound_annot: Return the rectangle for an annotation on a page. - - Does not throw exceptions. -*/ -fz_rect *pdf_bound_annot(pdf_document *doc, pdf_annot *annot, fz_rect *rect); - -/* - pdf_annot_type: Return the type of an annotation -*/ -fz_annot_type pdf_annot_type(pdf_annot *annot); - -/* - pdf_run_page: Interpret a loaded page and render it on a device. - - page: A page loaded by pdf_load_page. - - dev: Device used for rendering, obtained from fz_new_*_device. - - ctm: A transformation matrix applied to the objects on the page, - e.g. to scale or rotate the page contents as desired. -*/ -void pdf_run_page(pdf_document *doc, pdf_page *page, fz_device *dev, const fz_matrix *ctm, fz_cookie *cookie); - -void pdf_run_page_with_usage(pdf_document *doc, pdf_page *page, fz_device *dev, const fz_matrix *ctm, char *event, fz_cookie *cookie); - -/* - pdf_run_page_contents: Interpret a loaded page and render it on a device. - Just the main page contents without the annotations - - page: A page loaded by pdf_load_page. - - dev: Device used for rendering, obtained from fz_new_*_device. - - ctm: A transformation matrix applied to the objects on the page, - e.g. to scale or rotate the page contents as desired. -*/ -void pdf_run_page_contents(pdf_document *xref, pdf_page *page, fz_device *dev, const fz_matrix *ctm, fz_cookie *cookie); - -/* - pdf_run_annot: Interpret an annotation and render it on a device. - - page: A page loaded by pdf_load_page. - - annot: an annotation. - - dev: Device used for rendering, obtained from fz_new_*_device. - - ctm: A transformation matrix applied to the objects on the page, - e.g. to scale or rotate the page contents as desired. -*/ -void pdf_run_annot(pdf_document *xref, pdf_page *page, pdf_annot *annot, fz_device *dev, const fz_matrix *ctm, fz_cookie *cookie); - -/* - Metadata interface. -*/ -int pdf_meta(pdf_document *doc, int key, void *ptr, int size); - -/* - Presentation interface. -*/ -fz_transition *pdf_page_presentation(pdf_document *doc, pdf_page *page, float *duration); - -/* pdf-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); - -/* - * tokenizer and low-level object parser - */ - -typedef 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 -} pdf_token; - -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); - -pdf_token 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; - -typedef struct pdf_xref_s -{ - int len; - pdf_xref_entry *table; - pdf_obj *trailer; -} pdf_xref; - -/* - Document event structures are mostly opaque to the app. Only the type - is visible to the app. -*/ -typedef struct pdf_doc_event_s pdf_doc_event; - -/* - pdf_doc_event_cb: the type of function via which the app receives - document events. -*/ -typedef void (pdf_doc_event_cb)(pdf_doc_event *event, void *data); - -struct pdf_document_s -{ - fz_document super; - - fz_context *ctx; - fz_stream *file; - - int version; - int startxref; - int file_size; - pdf_crypt *crypt; - pdf_ocg_descriptor *ocg; - pdf_hotspot hotspot; - - int num_xref_sections; - pdf_xref *xref_sections; - int xref_altered; - - int page_len; - int page_cap; - pdf_obj **page_objs; - pdf_obj **page_refs; - int resources_localised; - - pdf_lexbuf_large lexbuf; - - pdf_annot *focus; - pdf_obj *focus_obj; - - pdf_js *js; - int recalculating; - int dirty; - void (*update_appearance)(pdf_document *xref, pdf_obj *annot); - - pdf_doc_event_cb *event_cb; - void *event_cb_data; -}; - -pdf_document *pdf_open_document_no_run(fz_context *ctx, const char *filename); -pdf_document *pdf_open_document_no_run_with_stream(fz_context *ctx, fz_stream *file); - -void pdf_localise_page_resources(pdf_document *xref); - -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, fz_compression_params *params); -fz_compressed_buffer *pdf_load_compressed_stream(pdf_document *doc, int num, int gen); -fz_stream *pdf_open_stream_with_offset(pdf_document *doc, int num, int gen, pdf_obj *dict, int stm_ofs); -fz_stream *pdf_open_compressed_stream(fz_context *ctx, fz_compressed_buffer *); -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, int *truncated); -fz_stream *pdf_open_raw_renumbered_stream(pdf_document *doc, int num, int gen, int orig_num, int orig_gen); - -pdf_obj *pdf_trailer(pdf_document *doc); -void pdf_set_populating_xref_trailer(pdf_document *doc, pdf_obj *trailer); -int pdf_xref_len(pdf_document *doc); -pdf_xref_entry *pdf_get_populating_xref_entry(pdf_document *doc, int i); -pdf_xref_entry *pdf_get_xref_entry(pdf_document *doc, int i); -void pdf_replace_xref(pdf_document *doc, pdf_xref_entry *entries, int n); - -void pdf_repair_xref(pdf_document *doc, pdf_lexbuf *buf); -void pdf_repair_obj_stms(pdf_document *doc); -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 - */ - -fz_function *pdf_load_function(pdf_document *doc, pdf_obj *ref, int in, int out); - -fz_colorspace *pdf_load_colorspace(pdf_document *doc, pdf_obj *obj); - -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; - int iteration; -}; - -pdf_xobject *pdf_load_xobject(pdf_document *doc, pdf_obj *obj); -pdf_obj *pdf_new_xobject(pdf_document *doc, const fz_rect *bbox, const 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); -void pdf_load_type3_glyphs(pdf_document *doc, pdf_font_desc *fontdesc, int nestedDepth); -pdf_font_desc *pdf_load_font(pdf_document *doc, pdf_obj *rdb, pdf_obj *obj, int nestedDepth); - -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, fz_rect *rect); -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_page *page; - pdf_obj *obj; - fz_rect rect; - fz_rect pagerect; - pdf_xobject *ap; - int ap_iteration; - fz_matrix matrix; - pdf_annot *next; - pdf_annot *next_changed; - int annot_type; - int widget_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, const fz_matrix *page_ctm); - -pdf_annot *pdf_load_annots(pdf_document *, pdf_obj *annots, pdf_page *page); -void pdf_update_annot(pdf_document *, pdf_annot *annot); -void pdf_free_annot(fz_context *ctx, pdf_annot *link); - -/* Field flags */ -enum -{ - Ff_Multiline = 1 << (13-1), - Ff_Password = 1 << (14-1), - Ff_NoToggleToOff = 1 << (15-1), - Ff_Radio = 1 << (16-1), - Ff_Pushbutton = 1 << (17-1), - Ff_Combo = 1 << (18-1), - Ff_FileSelect = 1 << (21-1), - Ff_MultiSelect = 1 << (22-1), - Ff_DoNotSpellCheck = 1 << (23-1), - Ff_DoNotScroll = 1 << (24-1), - Ff_Comb = 1 << (25-1), - Ff_RadioInUnison = 1 << (26-1) -}; - -pdf_obj *pdf_get_inheritable(pdf_document *doc, pdf_obj *obj, char *key); -int pdf_get_field_flags(pdf_document *doc, pdf_obj *obj); -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); -char *pdf_field_name(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; - pdf_annot *changed_annots; - pdf_annot *deleted_annots; - pdf_annot *tmp_annots; - pdf_obj *me; - float duration; - int transition_present; - fz_transition transition; -}; - -/* - * Content stream parsing - */ - -void pdf_run_glyph(pdf_document *doc, pdf_obj *resources, fz_buffer *contents, fz_device *dev, const fz_matrix *ctm, void *gstate, int nestedDepth); - -/* - * 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 - */ - -/* Types of widget */ -enum -{ - PDF_WIDGET_TYPE_NOT_WIDGET = -1, - PDF_WIDGET_TYPE_PUSHBUTTON, - PDF_WIDGET_TYPE_CHECKBOX, - PDF_WIDGET_TYPE_RADIOBUTTON, - PDF_WIDGET_TYPE_TEXT, - PDF_WIDGET_TYPE_LISTBOX, - PDF_WIDGET_TYPE_COMBOBOX, - PDF_WIDGET_TYPE_SIGNATURE -}; - -/* Types of text widget content */ -enum -{ - PDF_WIDGET_CONTENT_UNRESTRAINED, - PDF_WIDGET_CONTENT_NUMBER, - PDF_WIDGET_CONTENT_SPECIAL, - PDF_WIDGET_CONTENT_DATE, - PDF_WIDGET_CONTENT_TIME -}; - -/* Types of UI event */ -enum -{ - PDF_EVENT_TYPE_POINTER, -}; - -/* Types of pointer event */ -enum -{ - PDF_POINTER_DOWN, - PDF_POINTER_UP, -}; - -/* - UI events that can be passed to an interactive document. -*/ -typedef struct pdf_ui_event_s -{ - int etype; - union - { - struct - { - int ptype; - fz_point pt; - } pointer; - } event; -} pdf_ui_event; - -/* - pdf_init_ui_pointer_event: Set up a pointer event -*/ -void pdf_init_ui_pointer_event(pdf_ui_event *event, int type, float x, float y); - -/* - Widgets that may appear in PDF forms -*/ -typedef struct pdf_widget_s pdf_widget; - -/* - Determine whether changes have been made since the - document was opened or last saved. -*/ -int pdf_has_unsaved_changes(pdf_document *doc); - -/* - pdf_pass_event: Pass a UI event to an interactive - document. - - Returns a boolean indication of whether the ui_event was - handled. Example of use for the return value: when considering - passing the events that make up a drag, if the down event isn't - accepted then don't send the move events or the up event. -*/ -int pdf_pass_event(pdf_document *doc, pdf_page *page, pdf_ui_event *ui_event); - -/* - pdf_update_page: update a page for the sake of changes caused by a call - to pdf_pass_event. pdf_update_page regenerates any appearance streams that - are out of date, checks for cases where different appearance streams - should be selected because of state changes, and records internally - each annotation that has changed appearance. The list of changed annotations - is then available via pdf_poll_changed_annot. Note that a call to - pdf_pass_event for one page may lead to changes on any other, so an app - should call pdf_update_page for every page it currently displays. Also - it is important that the pdf_page object is the one used to last render - the page. If instead the app were to drop the page and reload it then - a call to pdf_update_page would not reliably be able to report all changed - areas. -*/ -void pdf_update_page(pdf_document *doc, pdf_page *page); - -fz_annot_type pdf_annot_obj_type(pdf_obj *obj); - -/* - pdf_poll_changed_annot: enumerate the changed annotations recoreded - by a call to pdf_update_page. -*/ -pdf_annot *pdf_poll_changed_annot(pdf_document *idoc, pdf_page *page); - -/* - pdf_focused_widget: returns the currently focussed widget - - Widgets can become focussed as a result of passing in ui events. - NULL is returned if there is no currently focussed widget. An - app may wish to create a native representative of the focussed - widget, e.g., to collect the text for a text widget, rather than - routing key strokes through pdf_pass_event. -*/ -pdf_widget *pdf_focused_widget(pdf_document *doc); - -/* - pdf_first_widget: get first widget when enumerating -*/ -pdf_widget *pdf_first_widget(pdf_document *doc, pdf_page *page); - -/* - pdf_next_widget: get next widget when enumerating -*/ -pdf_widget *pdf_next_widget(pdf_widget *previous); - -/* - pdf_widget_get_type: find out the type of a widget. - - The type determines what widget subclass the widget - can safely be cast to. -*/ -int pdf_widget_get_type(pdf_widget *widget); - -/* - pdf_bound_widget: get the bounding box of a widget. -*/ -fz_rect *pdf_bound_widget(pdf_widget *widget, fz_rect *); - -/* - pdf_text_widget_text: Get the text currently displayed in - a text widget. -*/ -char *pdf_text_widget_text(pdf_document *doc, pdf_widget *tw); - -/* - pdf_widget_text_max_len: get the maximum number of - characters permitted in a text widget -*/ -int pdf_text_widget_max_len(pdf_document *doc, pdf_widget *tw); - -/* - pdf_text_widget_content_type: get the type of content - required by a text widget -*/ -int pdf_text_widget_content_type(pdf_document *doc, pdf_widget *tw); - -/* - pdf_text_widget_set_text: Update the text of a text widget. - The text is first validated and accepted only if it passes. The - function returns whether validation passed. -*/ -int pdf_text_widget_set_text(pdf_document *doc, pdf_widget *tw, char *text); - -/* - pdf_choice_widget_options: get the list of options for a list - box or combo box. Returns the number of options and fills in their - names within the supplied array. Should first be called with a - NULL array to find out how big the array should be. -*/ -int pdf_choice_widget_options(pdf_document *doc, pdf_widget *tw, char *opts[]); - -/* - pdf_choice_widget_is_multiselect: returns whether a list box or - combo box supports selection of multiple options -*/ -int pdf_choice_widget_is_multiselect(pdf_document *doc, pdf_widget *tw); - -/* - pdf_choice_widget_value: get the value of a choice widget. - Returns the number of options curently selected and fills in - the supplied array with their strings. Should first be called - with NULL as the array to find out how big the array need to - be. The filled in elements should not be freed by the caller. -*/ -int pdf_choice_widget_value(pdf_document *doc, pdf_widget *tw, char *opts[]); - -/* - pdf_widget_set_value: set the value of a choice widget. The - caller should pass the number of options selected and an - array of their names -*/ -void pdf_choice_widget_set_value(pdf_document *doc, pdf_widget *tw, int n, char *opts[]); - -/* - pdf_signature_widget_byte_range: retrieve the byte range for a signature widget -*/ -int pdf_signature_widget_byte_range(pdf_document *doc, pdf_widget *widget, int (*byte_range)[2]); - -/* - pdf_signature_widget_contents: retrieve the contents for a signature widget -*/ -int pdf_signature_widget_contents(pdf_document *doc, pdf_widget *widget, char **contents); - -/* - fz_check_signature: check a signature's certificate chain and digest -*/ -int pdf_check_signature(fz_context *ctx, pdf_document *doc, pdf_widget *widget, char *file, char *ebuf, int ebufsize); - -/* - fz_create_annot: create a new annotation of the specified type on the - specified page. The returned pdf_annot structure is owned by the page - and does not need to be freed. -*/ -pdf_annot *pdf_create_annot(pdf_document *doc, pdf_page *page, fz_annot_type type); - -/* - fz_delete_annot: delete an annotation -*/ -void pdf_delete_annot(pdf_document *doc, pdf_page *page, pdf_annot *annot); - -/* - fz_set_annot_appearance: update the appearance of an annotation based - on a display list. -*/ -void pdf_set_annot_appearance(pdf_document *doc, pdf_annot *annot, fz_rect *rect, fz_display_list *disp_list); - -/* - fz_set_markup_annot_quadpoints: set the quadpoints for a text-markup annotation. -*/ -void pdf_set_markup_annot_quadpoints(pdf_document *doc, pdf_annot *annot, fz_point *qp, int n); - -void pdf_set_markup_obj_appearance(pdf_document *doc, pdf_obj *annot, float color[3], float alpha, float line_thickness, float line_height); - -/* - fz_set_markup_appearance: set the appearance stream of a text markup annotations, basing it on - its QuadPoints array -*/ -void pdf_set_markup_appearance(pdf_document *doc, pdf_annot *annot, float color[3], float alpha, float line_thickness, float line_height); - -/* - fz_set_ink_annot_list: set the details of an ink annotation. All the points of the multiple arcs - are carried in a single array, with the counts for each arc held in a secondary array. -*/ -void pdf_set_ink_annot_list(pdf_document *doc, pdf_annot *annot, fz_point *pts, int *counts, int ncount, float color[3], float thickness); -void pdf_set_ink_obj_appearance(pdf_document *doc, pdf_obj *annot); - -/* - Document events: the objects via which MuPDF informs the calling app - of occurrences emanating from the document, possibly from user interaction - or javascript execution. MuPDF informs the app of document events via a - callback. -*/ - -struct pdf_doc_event_s -{ - int type; -}; - -enum -{ - PDF_DOCUMENT_EVENT_ALERT, - PDF_DOCUMENT_EVENT_PRINT, - PDF_DOCUMENT_EVENT_LAUNCH_URL, - PDF_DOCUMENT_EVENT_MAIL_DOC, - PDF_DOCUMENT_EVENT_SUBMIT, - PDF_DOCUMENT_EVENT_EXEC_MENU_ITEM, - PDF_DOCUMENT_EVENT_EXEC_DIALOG -}; - -/* - pdf_set_doc_event_callback: set the function via which to receive - document events. -*/ -void pdf_set_doc_event_callback(pdf_document *doc, pdf_doc_event_cb *event_cb, void *data); - -/* - The various types of document events -*/ - -/* - pdf_alert_event: details of an alert event. In response the app should - display an alert dialog with the bittons specified by "button_type_group". - If "check_box_message" is non-NULL, a checkbox should be displayed in - the lower-left corned along with the messsage. - - "finally_checked" and "button_pressed" should be set by the app - before returning from the callback. "finally_checked" need be set - only if "check_box_message" is non-NULL. -*/ -typedef struct -{ - char *message; - int icon_type; - int button_group_type; - char *title; - char *check_box_message; - int initially_checked; - int finally_checked; - int button_pressed; -} pdf_alert_event; - -/* Possible values of icon_type */ -enum -{ - PDF_ALERT_ICON_ERROR, - PDF_ALERT_ICON_WARNING, - PDF_ALERT_ICON_QUESTION, - PDF_ALERT_ICON_STATUS -}; - -/* Possible values of button_group_type */ -enum -{ - PDF_ALERT_BUTTON_GROUP_OK, - PDF_ALERT_BUTTON_GROUP_OK_CANCEL, - PDF_ALERT_BUTTON_GROUP_YES_NO, - PDF_ALERT_BUTTON_GROUP_YES_NO_CANCEL -}; - -/* Possible values of button_pressed */ -enum -{ - PDF_ALERT_BUTTON_NONE, - PDF_ALERT_BUTTON_OK, - PDF_ALERT_BUTTON_CANCEL, - PDF_ALERT_BUTTON_NO, - PDF_ALERT_BUTTON_YES -}; - -/* - pdf_access_alert_event: access the details of an alert event - The returned pointer and all the data referred to by the - structire are owned by mupdf and need not be freed by the - caller. -*/ -pdf_alert_event *pdf_access_alert_event(pdf_doc_event *event); - -/* - pdf_access_exec_menu_item_event: access the details of am execMenuItem - event, which consists of just the name of the menu item -*/ -char *pdf_access_exec_menu_item_event(pdf_doc_event *event); - -/* - pdf_submit_event: details of a submit event. The app should submit - the specified data to the specified url. "get" determines whether - to use the GET or POST method. -*/ -typedef struct -{ - char *url; - char *data; - int data_len; - int get; -} pdf_submit_event; - -/* - pdf_access_submit_event: access the details of a submit event - The returned pointer and all data referred to by the structure are - owned by mupdf and need not be freed by the caller. -*/ -pdf_submit_event *pdf_access_submit_event(pdf_doc_event *event); - -/* - pdf_launch_url_event: details of a launch-url event. The app should - open the url, either in a new frame or in the current window. -*/ -typedef struct -{ - char *url; - int new_frame; -} pdf_launch_url_event; - -/* - pdf_access_launch_url_event: access the details of a launch-url - event. The returned pointer and all data referred to by the structure - are owned by mupdf and need not be freed by the caller. -*/ -pdf_launch_url_event *pdf_access_launch_url_event(pdf_doc_event *event); - -/* - pdf_mail_doc_event: details of a mail_doc event. The app should save - the current state of the document and email it using the specified - parameters. -*/ -typedef struct -{ - int ask_user; - char *to; - char *cc; - char *bcc; - char *subject; - char *message; -} pdf_mail_doc_event; - -/* - pdf_acccess_mail_doc_event: access the details of a mail-doc event. -*/ -pdf_mail_doc_event *pdf_access_mail_doc_event(pdf_doc_event *event); - -void pdf_event_issue_alert(pdf_document *doc, pdf_alert_event *event); -void pdf_event_issue_print(pdf_document *doc); -void pdf_event_issue_exec_menu_item(pdf_document *doc, char *item); -void pdf_event_issue_exec_dialog(pdf_document *doc); -void pdf_event_issue_launch_url(pdf_document *doc, char *url, int new_frame); -void pdf_event_issue_mail_doc(pdf_document *doc, pdf_mail_doc_event *event); - -/* - * Javascript handler - */ -typedef struct pdf_js_event_s -{ - pdf_obj *target; - char *value; - int rc; -} pdf_js_event; - -int pdf_js_supported(void); -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, - JS_TYPE_BOOLEAN -}; - -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); - -pdf_jsimp_obj *pdf_jsimp_property(pdf_jsimp *imp, pdf_jsimp_obj *obj, char *prop); - -void pdf_jsimp_execute(pdf_jsimp *imp, char *code); -void pdf_jsimp_execute_count(pdf_jsimp *imp, char *code, int count); +#include "mupdf/pdf/output-pdf.h" #endif diff --git a/include/mupdf/pdf/annot.h b/include/mupdf/pdf/annot.h new file mode 100644 index 00000000..52081a48 --- /dev/null +++ b/include/mupdf/pdf/annot.h @@ -0,0 +1,117 @@ +#ifndef MUPDF_PDF_ANNOT_H +#define MUPDF_PDF_ANNOT_H + +/* + pdf_first_annot: Return the first annotation on a page. + + Does not throw exceptions. +*/ +pdf_annot *pdf_first_annot(pdf_document *doc, pdf_page *page); + +/* + pdf_next_annot: Return the next annotation on a page. + + Does not throw exceptions. +*/ +pdf_annot *pdf_next_annot(pdf_document *doc, pdf_annot *annot); + +/* + pdf_bound_annot: Return the rectangle for an annotation on a page. + + Does not throw exceptions. +*/ +fz_rect *pdf_bound_annot(pdf_document *doc, pdf_annot *annot, fz_rect *rect); + +/* + pdf_annot_type: Return the type of an annotation +*/ +fz_annot_type pdf_annot_type(pdf_annot *annot); + +/* + pdf_run_annot: Interpret an annotation and render it on a device. + + page: A page loaded by pdf_load_page. + + annot: an annotation. + + dev: Device used for rendering, obtained from fz_new_*_device. + + ctm: A transformation matrix applied to the objects on the page, + e.g. to scale or rotate the page contents as desired. +*/ +void pdf_run_annot(pdf_document *xref, pdf_page *page, pdf_annot *annot, fz_device *dev, const fz_matrix *ctm, fz_cookie *cookie); + +struct pdf_annot_s +{ + pdf_page *page; + pdf_obj *obj; + fz_rect rect; + fz_rect pagerect; + pdf_xobject *ap; + int ap_iteration; + fz_matrix matrix; + pdf_annot *next; + pdf_annot *next_changed; + int annot_type; + int widget_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, const fz_matrix *page_ctm); + +pdf_annot *pdf_load_annots(pdf_document *, pdf_obj *annots, pdf_page *page); +void pdf_update_annot(pdf_document *, pdf_annot *annot); +void pdf_free_annot(fz_context *ctx, pdf_annot *link); + +/* + fz_create_annot: create a new annotation of the specified type on the + specified page. The returned pdf_annot structure is owned by the page + and does not need to be freed. +*/ +pdf_annot *pdf_create_annot(pdf_document *doc, pdf_page *page, fz_annot_type type); + +/* + fz_delete_annot: delete an annotation +*/ +void pdf_delete_annot(pdf_document *doc, pdf_page *page, pdf_annot *annot); + +/* + fz_set_annot_appearance: update the appearance of an annotation based + on a display list. +*/ +void pdf_set_annot_appearance(pdf_document *doc, pdf_annot *annot, fz_rect *rect, fz_display_list *disp_list); + +/* + fz_set_markup_annot_quadpoints: set the quadpoints for a text-markup annotation. +*/ +void pdf_set_markup_annot_quadpoints(pdf_document *doc, pdf_annot *annot, fz_point *qp, int n); + +void pdf_set_markup_obj_appearance(pdf_document *doc, pdf_obj *annot, float color[3], float alpha, float line_thickness, float line_height); + +/* + fz_set_markup_appearance: set the appearance stream of a text markup annotations, basing it on + its QuadPoints array +*/ +void pdf_set_markup_appearance(pdf_document *doc, pdf_annot *annot, float color[3], float alpha, float line_thickness, float line_height); + +/* + fz_set_ink_annot_list: set the details of an ink annotation. All the points of the multiple arcs + are carried in a single array, with the counts for each arc held in a secondary array. +*/ +void pdf_set_ink_annot_list(pdf_document *doc, pdf_annot *annot, fz_point *pts, int *counts, int ncount, float color[3], float thickness); +void pdf_set_ink_obj_appearance(pdf_document *doc, pdf_obj *annot); + +fz_annot_type pdf_annot_obj_type(pdf_obj *obj); + +/* + pdf_poll_changed_annot: enumerate the changed annotations recoreded + by a call to pdf_update_page. +*/ +pdf_annot *pdf_poll_changed_annot(pdf_document *idoc, pdf_page *page); + +#endif diff --git a/include/mupdf/pdf/cmap.h b/include/mupdf/pdf/cmap.h new file mode 100644 index 00000000..faa4a42c --- /dev/null +++ b/include/mupdf/pdf/cmap.h @@ -0,0 +1,78 @@ +#ifndef MUPDF_PDF_CMAP_H +#define MUPDF_PDF_CMAP_H + +/* + * 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 + +#endif diff --git a/include/mupdf/pdf/crypt.h b/include/mupdf/pdf/crypt.h new file mode 100644 index 00000000..fd47117a --- /dev/null +++ b/include/mupdf/pdf/crypt.h @@ -0,0 +1,41 @@ +#ifndef MUPDF_PDF_CRYPT_H +#define MUPDF_PDF_CRYPT_H + +/* + * 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 + +/* + pdf_signature_widget_byte_range: retrieve the byte range for a signature widget +*/ +int pdf_signature_widget_byte_range(pdf_document *doc, pdf_widget *widget, int (*byte_range)[2]); + +/* + pdf_signature_widget_contents: retrieve the contents for a signature widget +*/ +int pdf_signature_widget_contents(pdf_document *doc, pdf_widget *widget, char **contents); + +/* + fz_check_signature: check a signature's certificate chain and digest +*/ +int pdf_check_signature(fz_context *ctx, pdf_document *doc, pdf_widget *widget, char *file, char *ebuf, int ebufsize); + +#endif diff --git a/include/mupdf/pdf/document.h b/include/mupdf/pdf/document.h new file mode 100644 index 00000000..a096384d --- /dev/null +++ b/include/mupdf/pdf/document.h @@ -0,0 +1,209 @@ +#ifndef MUPDF_PDF_DOCUMENT_H +#define MUPDF_PDF_DOCUMENT_H + +typedef struct pdf_lexbuf_s pdf_lexbuf; +typedef struct pdf_lexbuf_large_s pdf_lexbuf_large; +typedef struct pdf_xref_s pdf_xref; +typedef struct pdf_crypt_s pdf_crypt; +typedef struct pdf_ocg_descriptor_s pdf_ocg_descriptor; + +typedef struct pdf_page_s pdf_page; +typedef struct pdf_annot_s pdf_annot; +typedef struct pdf_widget_s pdf_widget; +typedef struct pdf_hotspot_s pdf_hotspot; +typedef struct pdf_js_s pdf_js; + +enum +{ + PDF_LEXBUF_SMALL = 256, + PDF_LEXBUF_LARGE = 65536 +}; + +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]; +}; + +struct pdf_hotspot_s +{ + int num; + int gen; + int state; +}; + +/* + Document event structures are mostly opaque to the app. Only the type + is visible to the app. +*/ +typedef struct pdf_doc_event_s pdf_doc_event; + +/* + pdf_doc_event_cb: the type of function via which the app receives + document events. +*/ +typedef void (pdf_doc_event_cb)(pdf_doc_event *event, void *data); + +/* + pdf_open_document: Open a PDF document. + + Open a PDF document by reading its cross reference table, so + MuPDF can locate PDF objects inside the file. Upon an broken + cross reference table or other parse errors MuPDF will restart + parsing the file from the beginning to try to rebuild a + (hopefully correct) cross reference table to allow further + processing of the file. + + The returned pdf_document should be used when calling most + other PDF functions. Note that it wraps the context, so those + functions implicitly get access to the global state in + context. + + filename: a path to a file as it would be given to open(2). +*/ +pdf_document *pdf_open_document(fz_context *ctx, const char *filename); + +/* + pdf_open_document_with_stream: Opens a PDF document. + + Same as pdf_open_document, but takes a stream instead of a + filename to locate the PDF document to open. Increments the + reference count of the stream. See fz_open_file, + fz_open_file_w or fz_open_fd for opening a stream, and + fz_close for closing an open stream. +*/ +pdf_document *pdf_open_document_with_stream(fz_context *ctx, fz_stream *file); + +pdf_document *pdf_open_document_no_run(fz_context *ctx, const char *filename); +pdf_document *pdf_open_document_no_run_with_stream(fz_context *ctx, fz_stream *file); + +/* + pdf_close_document: Closes and frees an opened PDF document. + + The resource store in the context associated with pdf_document + is emptied. + + Does not throw exceptions. +*/ +void pdf_close_document(pdf_document *doc); + +/* + pdf_specific: down-cast an fz_document to a pdf_document. + Returns NULL if underlying document is not PDF +*/ +pdf_document *pdf_specifics(fz_document *doc); + +int pdf_needs_password(pdf_document *doc); +int pdf_authenticate_password(pdf_document *doc, const char *pw); + +enum +{ + PDF_PERM_PRINT = 1 << 2, + PDF_PERM_CHANGE = 1 << 3, + PDF_PERM_COPY = 1 << 4, + PDF_PERM_NOTES = 1 << 5, + PDF_PERM_FILL_FORM = 1 << 8, + PDF_PERM_ACCESSIBILITY = 1 << 9, + PDF_PERM_ASSEMBLE = 1 << 10, + PDF_PERM_HIGH_RES_PRINT = 1 << 11, + PDF_DEFAULT_PERM_FLAGS = 0xfffc +}; + +int pdf_has_permission(pdf_document *doc, int p); + +/* + Metadata interface. +*/ +int pdf_meta(pdf_document *doc, int key, void *ptr, int size); + +fz_outline *pdf_load_outline(pdf_document *doc); + +typedef struct pdf_ocg_entry_s pdf_ocg_entry; + +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; +}; + +/* + pdf_update_page: update a page for the sake of changes caused by a call + to pdf_pass_event. pdf_update_page regenerates any appearance streams that + are out of date, checks for cases where different appearance streams + should be selected because of state changes, and records internally + each annotation that has changed appearance. The list of changed annotations + is then available via pdf_poll_changed_annot. Note that a call to + pdf_pass_event for one page may lead to changes on any other, so an app + should call pdf_update_page for every page it currently displays. Also + it is important that the pdf_page object is the one used to last render + the page. If instead the app were to drop the page and reload it then + a call to pdf_update_page would not reliably be able to report all changed + areas. +*/ +void pdf_update_page(pdf_document *doc, pdf_page *page); + +/* + Determine whether changes have been made since the + document was opened or last saved. +*/ +int pdf_has_unsaved_changes(pdf_document *doc); + +struct pdf_document_s +{ + fz_document super; + + fz_context *ctx; + fz_stream *file; + + int version; + int startxref; + int file_size; + pdf_crypt *crypt; + pdf_ocg_descriptor *ocg; + pdf_hotspot hotspot; + + int num_xref_sections; + pdf_xref *xref_sections; + int xref_altered; + + int page_len; + int page_cap; + pdf_obj **page_objs; + pdf_obj **page_refs; + int resources_localised; + + pdf_lexbuf_large lexbuf; + + pdf_annot *focus; + pdf_obj *focus_obj; + + pdf_js *js; + int recalculating; + int dirty; + void (*update_appearance)(pdf_document *xref, pdf_obj *annot); + + pdf_doc_event_cb *event_cb; + void *event_cb_data; +}; + +#endif diff --git a/include/mupdf/pdf/event.h b/include/mupdf/pdf/event.h new file mode 100644 index 00000000..c2adf057 --- /dev/null +++ b/include/mupdf/pdf/event.h @@ -0,0 +1,216 @@ +#ifndef MUPDF_PDF_EVENT_H +#define MUPDF_PDF_EVENT_H + +enum +{ + HOTSPOT_POINTER_DOWN = 0x1, + HOTSPOT_POINTER_OVER = 0x2 +}; + +/* Types of UI event */ +enum +{ + PDF_EVENT_TYPE_POINTER, +}; + +/* Types of pointer event */ +enum +{ + PDF_POINTER_DOWN, + PDF_POINTER_UP, +}; + +/* + UI events that can be passed to an interactive document. +*/ +typedef struct pdf_ui_event_s +{ + int etype; + union + { + struct + { + int ptype; + fz_point pt; + } pointer; + } event; +} pdf_ui_event; + +/* + pdf_init_ui_pointer_event: Set up a pointer event +*/ +void pdf_init_ui_pointer_event(pdf_ui_event *event, int type, float x, float y); + +/* + Document events: the objects via which MuPDF informs the calling app + of occurrences emanating from the document, possibly from user interaction + or javascript execution. MuPDF informs the app of document events via a + callback. +*/ + +/* + pdf_pass_event: Pass a UI event to an interactive + document. + + Returns a boolean indication of whether the ui_event was + handled. Example of use for the return value: when considering + passing the events that make up a drag, if the down event isn't + accepted then don't send the move events or the up event. +*/ +int pdf_pass_event(pdf_document *doc, pdf_page *page, pdf_ui_event *ui_event); + +struct pdf_doc_event_s +{ + int type; +}; + +enum +{ + PDF_DOCUMENT_EVENT_ALERT, + PDF_DOCUMENT_EVENT_PRINT, + PDF_DOCUMENT_EVENT_LAUNCH_URL, + PDF_DOCUMENT_EVENT_MAIL_DOC, + PDF_DOCUMENT_EVENT_SUBMIT, + PDF_DOCUMENT_EVENT_EXEC_MENU_ITEM, + PDF_DOCUMENT_EVENT_EXEC_DIALOG +}; + +/* + pdf_set_doc_event_callback: set the function via which to receive + document events. +*/ +void pdf_set_doc_event_callback(pdf_document *doc, pdf_doc_event_cb *event_cb, void *data); + +/* + The various types of document events +*/ + +/* + pdf_alert_event: details of an alert event. In response the app should + display an alert dialog with the bittons specified by "button_type_group". + If "check_box_message" is non-NULL, a checkbox should be displayed in + the lower-left corned along with the messsage. + + "finally_checked" and "button_pressed" should be set by the app + before returning from the callback. "finally_checked" need be set + only if "check_box_message" is non-NULL. +*/ +typedef struct +{ + char *message; + int icon_type; + int button_group_type; + char *title; + char *check_box_message; + int initially_checked; + int finally_checked; + int button_pressed; +} pdf_alert_event; + +/* Possible values of icon_type */ +enum +{ + PDF_ALERT_ICON_ERROR, + PDF_ALERT_ICON_WARNING, + PDF_ALERT_ICON_QUESTION, + PDF_ALERT_ICON_STATUS +}; + +/* Possible values of button_group_type */ +enum +{ + PDF_ALERT_BUTTON_GROUP_OK, + PDF_ALERT_BUTTON_GROUP_OK_CANCEL, + PDF_ALERT_BUTTON_GROUP_YES_NO, + PDF_ALERT_BUTTON_GROUP_YES_NO_CANCEL +}; + +/* Possible values of button_pressed */ +enum +{ + PDF_ALERT_BUTTON_NONE, + PDF_ALERT_BUTTON_OK, + PDF_ALERT_BUTTON_CANCEL, + PDF_ALERT_BUTTON_NO, + PDF_ALERT_BUTTON_YES +}; + +/* + pdf_access_alert_event: access the details of an alert event + The returned pointer and all the data referred to by the + structire are owned by mupdf and need not be freed by the + caller. +*/ +pdf_alert_event *pdf_access_alert_event(pdf_doc_event *event); + +/* + pdf_access_exec_menu_item_event: access the details of am execMenuItem + event, which consists of just the name of the menu item +*/ +char *pdf_access_exec_menu_item_event(pdf_doc_event *event); + +/* + pdf_submit_event: details of a submit event. The app should submit + the specified data to the specified url. "get" determines whether + to use the GET or POST method. +*/ +typedef struct +{ + char *url; + char *data; + int data_len; + int get; +} pdf_submit_event; + +/* + pdf_access_submit_event: access the details of a submit event + The returned pointer and all data referred to by the structure are + owned by mupdf and need not be freed by the caller. +*/ +pdf_submit_event *pdf_access_submit_event(pdf_doc_event *event); + +/* + pdf_launch_url_event: details of a launch-url event. The app should + open the url, either in a new frame or in the current window. +*/ +typedef struct +{ + char *url; + int new_frame; +} pdf_launch_url_event; + +/* + pdf_access_launch_url_event: access the details of a launch-url + event. The returned pointer and all data referred to by the structure + are owned by mupdf and need not be freed by the caller. +*/ +pdf_launch_url_event *pdf_access_launch_url_event(pdf_doc_event *event); + +/* + pdf_mail_doc_event: details of a mail_doc event. The app should save + the current state of the document and email it using the specified + parameters. +*/ +typedef struct +{ + int ask_user; + char *to; + char *cc; + char *bcc; + char *subject; + char *message; +} pdf_mail_doc_event; + +/* + pdf_acccess_mail_doc_event: access the details of a mail-doc event. +*/ +pdf_mail_doc_event *pdf_access_mail_doc_event(pdf_doc_event *event); + +void pdf_event_issue_alert(pdf_document *doc, pdf_alert_event *event); +void pdf_event_issue_print(pdf_document *doc); +void pdf_event_issue_exec_menu_item(pdf_document *doc, char *item); +void pdf_event_issue_exec_dialog(pdf_document *doc); +void pdf_event_issue_launch_url(pdf_document *doc, char *url, int new_frame); +void pdf_event_issue_mail_doc(pdf_document *doc, pdf_mail_doc_event *event); + +#endif diff --git a/include/mupdf/pdf/field.h b/include/mupdf/pdf/field.h new file mode 100644 index 00000000..83a626f4 --- /dev/null +++ b/include/mupdf/pdf/field.h @@ -0,0 +1,37 @@ +#ifndef MUPDF_PDF_FIELD_H +#define MUPDF_PDF_FIELD_H + +/* Field flags */ +enum +{ + Ff_Multiline = 1 << (13-1), + Ff_Password = 1 << (14-1), + Ff_NoToggleToOff = 1 << (15-1), + Ff_Radio = 1 << (16-1), + Ff_Pushbutton = 1 << (17-1), + Ff_Combo = 1 << (18-1), + Ff_FileSelect = 1 << (21-1), + Ff_MultiSelect = 1 << (22-1), + Ff_DoNotSpellCheck = 1 << (23-1), + Ff_DoNotScroll = 1 << (24-1), + Ff_Comb = 1 << (25-1), + Ff_RadioInUnison = 1 << (26-1) +}; + +pdf_obj *pdf_get_inheritable(pdf_document *doc, pdf_obj *obj, char *key); +int pdf_get_field_flags(pdf_document *doc, pdf_obj *obj); +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); +char *pdf_field_name(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); + +#endif diff --git a/include/mupdf/pdf/font.h b/include/mupdf/pdf/font.h new file mode 100644 index 00000000..90b0fe01 --- /dev/null +++ b/include/mupdf/pdf/font.h @@ -0,0 +1,129 @@ +#ifndef MUPDF_PDF_FONT_H +#define MUPDF_PDF_FONT_H + +/* + * 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); +void pdf_load_type3_glyphs(pdf_document *doc, pdf_font_desc *fontdesc, int nestedDepth); +pdf_font_desc *pdf_load_font(pdf_document *doc, pdf_obj *rdb, pdf_obj *obj, int nestedDepth); + +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, fz_rect *rect); +float pdf_text_stride(fz_context *ctx, pdf_font_desc *fontdesc, float fontsize, unsigned char *buf, int len, float room, int *count); + +void pdf_run_glyph(pdf_document *doc, pdf_obj *resources, fz_buffer *contents, fz_device *dev, const fz_matrix *ctm, void *gstate, int nestedDepth); + +#endif diff --git a/include/mupdf/pdf/javascript.h b/include/mupdf/pdf/javascript.h new file mode 100644 index 00000000..a2a308a4 --- /dev/null +++ b/include/mupdf/pdf/javascript.h @@ -0,0 +1,70 @@ +#ifndef MUPDF_PDF_JAVASCRIPT_H +#define MUPDF_PDF_JAVASCRIPT_H + +typedef struct pdf_js_event_s +{ + pdf_obj *target; + char *value; + int rc; +} pdf_js_event; + +int pdf_js_supported(void); +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, + JS_TYPE_BOOLEAN +}; + +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); + +pdf_jsimp_obj *pdf_jsimp_property(pdf_jsimp *imp, pdf_jsimp_obj *obj, char *prop); + +void pdf_jsimp_execute(pdf_jsimp *imp, char *code); +void pdf_jsimp_execute_count(pdf_jsimp *imp, char *code, int count); + +#endif diff --git a/include/mupdf/pdf/object.h b/include/mupdf/pdf/object.h new file mode 100644 index 00000000..899bb0a7 --- /dev/null +++ b/include/mupdf/pdf/object.h @@ -0,0 +1,107 @@ +#ifndef MUPDF_PDF_OBJECT_H +#define MUPDF_PDF_OBJECT_H + +typedef struct pdf_document_s pdf_document; + +/* + * Dynamic objects. + * The same type of objects as found in PDF and PostScript. + * Used by the filters and the mupdf parser. + */ + +typedef struct pdf_obj_s pdf_obj; + +pdf_obj *pdf_new_null(fz_context *ctx); +pdf_obj *pdf_new_bool(fz_context *ctx, int b); +pdf_obj *pdf_new_int(fz_context *ctx, int i); +pdf_obj *pdf_new_real(fz_context *ctx, float f); +pdf_obj *pdf_new_name(fz_context *ctx, const char *str); +pdf_obj *pdf_new_string(fz_context *ctx, const char *str, int len); +pdf_obj *pdf_new_indirect(fz_context *ctx, int num, int gen, void *doc); +pdf_obj *pdf_new_array(fz_context *ctx, int initialcap); +pdf_obj *pdf_new_dict(fz_context *ctx, int initialcap); +pdf_obj *pdf_new_rect(fz_context *ctx, const fz_rect *rect); +pdf_obj *pdf_new_matrix(fz_context *ctx, const fz_matrix *mtx); +pdf_obj *pdf_copy_array(fz_context *ctx, pdf_obj *array); +pdf_obj *pdf_copy_dict(fz_context *ctx, pdf_obj *dict); + +pdf_obj *pdf_new_obj_from_str(fz_context *ctx, const char *src); + +pdf_obj *pdf_keep_obj(pdf_obj *obj); +void pdf_drop_obj(pdf_obj *obj); + +/* type queries */ +int pdf_is_null(pdf_obj *obj); +int pdf_is_bool(pdf_obj *obj); +int pdf_is_int(pdf_obj *obj); +int pdf_is_real(pdf_obj *obj); +int pdf_is_name(pdf_obj *obj); +int pdf_is_string(pdf_obj *obj); +int pdf_is_array(pdf_obj *obj); +int pdf_is_dict(pdf_obj *obj); +int pdf_is_indirect(pdf_obj *obj); +int pdf_is_stream(pdf_document *doc, int num, int gen); + +int pdf_objcmp(pdf_obj *a, pdf_obj *b); + +/* obj marking and unmarking functions - to avoid infinite recursions. */ +int pdf_obj_marked(pdf_obj *obj); +int pdf_obj_mark(pdf_obj *obj); +void pdf_obj_unmark(pdf_obj *obj); + +/* safe, silent failure, no error reporting on type mismatches */ +int pdf_to_bool(pdf_obj *obj); +int pdf_to_int(pdf_obj *obj); +float pdf_to_real(pdf_obj *obj); +char *pdf_to_name(pdf_obj *obj); +char *pdf_to_str_buf(pdf_obj *obj); +pdf_obj *pdf_to_dict(pdf_obj *obj); +int pdf_to_str_len(pdf_obj *obj); +int pdf_to_num(pdf_obj *obj); +int pdf_to_gen(pdf_obj *obj); + +int pdf_array_len(pdf_obj *array); +pdf_obj *pdf_array_get(pdf_obj *array, int i); +void pdf_array_put(pdf_obj *array, int i, pdf_obj *obj); +void pdf_array_push(pdf_obj *array, pdf_obj *obj); +void pdf_array_push_drop(pdf_obj *array, pdf_obj *obj); +void pdf_array_insert(pdf_obj *array, pdf_obj *obj); +int pdf_array_contains(pdf_obj *array, pdf_obj *obj); + +int pdf_dict_len(pdf_obj *dict); +pdf_obj *pdf_dict_get_key(pdf_obj *dict, int idx); +pdf_obj *pdf_dict_get_val(pdf_obj *dict, int idx); +pdf_obj *pdf_dict_get(pdf_obj *dict, pdf_obj *key); +pdf_obj *pdf_dict_gets(pdf_obj *dict, const char *key); +pdf_obj *pdf_dict_getp(pdf_obj *dict, const char *key); +pdf_obj *pdf_dict_getsa(pdf_obj *dict, const char *key, const char *abbrev); +void pdf_dict_put(pdf_obj *dict, pdf_obj *key, pdf_obj *val); +void pdf_dict_puts(pdf_obj *dict, const char *key, pdf_obj *val); +void pdf_dict_puts_drop(pdf_obj *dict, const char *key, pdf_obj *val); +void pdf_dict_putp(pdf_obj *dict, const char *key, pdf_obj *val); +void pdf_dict_putp_drop(pdf_obj *dict, const char *key, pdf_obj *val); +void pdf_dict_del(pdf_obj *dict, pdf_obj *key); +void pdf_dict_dels(pdf_obj *dict, const char *key); +void pdf_sort_dict(pdf_obj *dict); + +int pdf_fprint_obj(FILE *fp, pdf_obj *obj, int tight); + +#ifndef NDEBUG +void pdf_print_obj(pdf_obj *obj); +void pdf_print_ref(pdf_obj *obj); +#endif + +char *pdf_to_utf8(pdf_document *xref, pdf_obj *src); +unsigned short *pdf_to_ucs2(pdf_document *xref, pdf_obj *src); +pdf_obj *pdf_to_utf8_name(pdf_document *xref, pdf_obj *src); +char *pdf_from_ucs2(pdf_document *xref, unsigned short *str); +void pdf_to_ucs2_buf(unsigned short *buffer, pdf_obj *src); + +fz_rect *pdf_to_rect(fz_context *ctx, pdf_obj *array, fz_rect *rect); +fz_matrix *pdf_to_matrix(fz_context *ctx, pdf_obj *array, fz_matrix *mat); + +pdf_document *pdf_get_indirect_document(pdf_obj *obj); +void pdf_set_str_len(pdf_obj *obj, int newlen); +void pdf_set_int(pdf_obj *obj, int i); + +#endif diff --git a/include/mupdf/pdf/output-pdf.h b/include/mupdf/pdf/output-pdf.h new file mode 100644 index 00000000..0a5c7a46 --- /dev/null +++ b/include/mupdf/pdf/output-pdf.h @@ -0,0 +1,18 @@ +#ifndef MUPDF_PDF_OUTPUT_PDF_H +#define MUPDF_PDF_OUTPUT_PDF_H + +/* + pdf_new_pdf_device: Create a pdf device. Rendering to the device creates + new pdf content. WARNING: this device is work in progress. It doesn't + currently support all rendering cases. +*/ +fz_device *pdf_new_pdf_device(pdf_document *doc, pdf_obj *contents, pdf_obj *resources, const fz_matrix *ctm); + +/* + pdf_write_document: Write out the document to a file with all changes finalised. +*/ +void pdf_write_document(pdf_document *doc, char *filename, fz_write_options *opts); + +void pdf_localise_page_resources(pdf_document *xref); + +#endif diff --git a/include/mupdf/pdf/page.h b/include/mupdf/pdf/page.h new file mode 100644 index 00000000..f60a8836 --- /dev/null +++ b/include/mupdf/pdf/page.h @@ -0,0 +1,95 @@ +#ifndef MUPDF_PDF_PAGE_H +#define MUPDF_PDF_PAGE_H + +int pdf_lookup_page_number(pdf_document *doc, pdf_obj *pageobj); +int pdf_count_pages(pdf_document *doc); + +/* + pdf_load_page: Load a page and its resources. + + Locates the page in the PDF document and loads the page and its + resources. After pdf_load_page is it possible to retrieve the size + of the page using pdf_bound_page, or to render the page using + pdf_run_page_*. + + number: page number, where 0 is the first page of the document. +*/ +pdf_page *pdf_load_page(pdf_document *doc, int number); + +fz_link *pdf_load_links(pdf_document *doc, pdf_page *page); + +/* + pdf_bound_page: Determine the size of a page. + + Determine the page size in user space units, taking page rotation + into account. The page size is taken to be the crop box if it + exists (visible area after cropping), otherwise the media box will + be used (possibly including printing marks). + + Does not throw exceptions. +*/ +fz_rect *pdf_bound_page(pdf_document *doc, pdf_page *page, fz_rect *); + +/* + pdf_free_page: Frees a page and its resources. + + Does not throw exceptions. +*/ +void pdf_free_page(pdf_document *doc, pdf_page *page); + +/* + pdf_run_page: Interpret a loaded page and render it on a device. + + page: A page loaded by pdf_load_page. + + dev: Device used for rendering, obtained from fz_new_*_device. + + ctm: A transformation matrix applied to the objects on the page, + e.g. to scale or rotate the page contents as desired. +*/ +void pdf_run_page(pdf_document *doc, pdf_page *page, fz_device *dev, const fz_matrix *ctm, fz_cookie *cookie); + +void pdf_run_page_with_usage(pdf_document *doc, pdf_page *page, fz_device *dev, const fz_matrix *ctm, char *event, fz_cookie *cookie); + +/* + pdf_run_page_contents: Interpret a loaded page and render it on a device. + Just the main page contents without the annotations + + page: A page loaded by pdf_load_page. + + dev: Device used for rendering, obtained from fz_new_*_device. + + ctm: A transformation matrix applied to the objects on the page, + e.g. to scale or rotate the page contents as desired. +*/ +void pdf_run_page_contents(pdf_document *xref, pdf_page *page, fz_device *dev, const fz_matrix *ctm, fz_cookie *cookie); + +/* + Presentation interface. +*/ +fz_transition *pdf_page_presentation(pdf_document *doc, pdf_page *page, float *duration); + +/* + * 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; + pdf_annot *changed_annots; + pdf_annot *deleted_annots; + pdf_annot *tmp_annots; + pdf_obj *me; + float duration; + int transition_present; + fz_transition transition; +}; + +#endif diff --git a/include/mupdf/pdf/parse.h b/include/mupdf/pdf/parse.h new file mode 100644 index 00000000..0dc52a78 --- /dev/null +++ b/include/mupdf/pdf/parse.h @@ -0,0 +1,38 @@ +#ifndef MUPDF_PDF_PARSE_H +#define MUPDF_PDF_PARSE_H + +/* + * tokenizer and low-level object parser + */ + +typedef 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 +} pdf_token; + +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); + +pdf_token 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); + +#endif diff --git a/include/mupdf/pdf/resource.h b/include/mupdf/pdf/resource.h new file mode 100644 index 00000000..b52a1589 --- /dev/null +++ b/include/mupdf/pdf/resource.h @@ -0,0 +1,77 @@ +#ifndef MUPDF_PDF_RESOURCE_H +#define MUPDF_PDF_RESOURCE_H + +/* + * 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); + +/* + * Functions, Colorspaces, Shadings and Images + */ + +fz_function *pdf_load_function(pdf_document *doc, pdf_obj *ref, int in, int out); + +fz_colorspace *pdf_load_colorspace(pdf_document *doc, pdf_obj *obj); + +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); + +fz_image *pdf_load_image(pdf_document *doc, pdf_obj *obj); + +/* + * 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; + int iteration; +}; + +pdf_xobject *pdf_load_xobject(pdf_document *doc, pdf_obj *obj); +pdf_obj *pdf_new_xobject(pdf_document *doc, const fz_rect *bbox, const 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); + +#endif diff --git a/include/mupdf/pdf/widget.h b/include/mupdf/pdf/widget.h new file mode 100644 index 00000000..2c94c828 --- /dev/null +++ b/include/mupdf/pdf/widget.h @@ -0,0 +1,120 @@ +#ifndef MUPDF_PDF_WIDGET_H +#define MUPDF_PDF_WIDGET_H + +/* Types of widget */ +enum +{ + PDF_WIDGET_TYPE_NOT_WIDGET = -1, + PDF_WIDGET_TYPE_PUSHBUTTON, + PDF_WIDGET_TYPE_CHECKBOX, + PDF_WIDGET_TYPE_RADIOBUTTON, + PDF_WIDGET_TYPE_TEXT, + PDF_WIDGET_TYPE_LISTBOX, + PDF_WIDGET_TYPE_COMBOBOX, + PDF_WIDGET_TYPE_SIGNATURE +}; + +/* Types of text widget content */ +enum +{ + PDF_WIDGET_CONTENT_UNRESTRAINED, + PDF_WIDGET_CONTENT_NUMBER, + PDF_WIDGET_CONTENT_SPECIAL, + PDF_WIDGET_CONTENT_DATE, + PDF_WIDGET_CONTENT_TIME +}; + +/* + Widgets that may appear in PDF forms +*/ + +/* + pdf_focused_widget: returns the currently focussed widget + + Widgets can become focussed as a result of passing in ui events. + NULL is returned if there is no currently focussed widget. An + app may wish to create a native representative of the focussed + widget, e.g., to collect the text for a text widget, rather than + routing key strokes through pdf_pass_event. +*/ +pdf_widget *pdf_focused_widget(pdf_document *doc); + +/* + pdf_first_widget: get first widget when enumerating +*/ +pdf_widget *pdf_first_widget(pdf_document *doc, pdf_page *page); + +/* + pdf_next_widget: get next widget when enumerating +*/ +pdf_widget *pdf_next_widget(pdf_widget *previous); + +/* + pdf_widget_get_type: find out the type of a widget. + + The type determines what widget subclass the widget + can safely be cast to. +*/ +int pdf_widget_get_type(pdf_widget *widget); + +/* + pdf_bound_widget: get the bounding box of a widget. +*/ +fz_rect *pdf_bound_widget(pdf_widget *widget, fz_rect *); + +/* + pdf_text_widget_text: Get the text currently displayed in + a text widget. +*/ +char *pdf_text_widget_text(pdf_document *doc, pdf_widget *tw); + +/* + pdf_widget_text_max_len: get the maximum number of + characters permitted in a text widget +*/ +int pdf_text_widget_max_len(pdf_document *doc, pdf_widget *tw); + +/* + pdf_text_widget_content_type: get the type of content + required by a text widget +*/ +int pdf_text_widget_content_type(pdf_document *doc, pdf_widget *tw); + +/* + pdf_text_widget_set_text: Update the text of a text widget. + The text is first validated and accepted only if it passes. The + function returns whether validation passed. +*/ +int pdf_text_widget_set_text(pdf_document *doc, pdf_widget *tw, char *text); + +/* + pdf_choice_widget_options: get the list of options for a list + box or combo box. Returns the number of options and fills in their + names within the supplied array. Should first be called with a + NULL array to find out how big the array should be. +*/ +int pdf_choice_widget_options(pdf_document *doc, pdf_widget *tw, char *opts[]); + +/* + pdf_choice_widget_is_multiselect: returns whether a list box or + combo box supports selection of multiple options +*/ +int pdf_choice_widget_is_multiselect(pdf_document *doc, pdf_widget *tw); + +/* + pdf_choice_widget_value: get the value of a choice widget. + Returns the number of options curently selected and fills in + the supplied array with their strings. Should first be called + with NULL as the array to find out how big the array need to + be. The filled in elements should not be freed by the caller. +*/ +int pdf_choice_widget_value(pdf_document *doc, pdf_widget *tw, char *opts[]); + +/* + pdf_widget_set_value: set the value of a choice widget. The + caller should pass the number of options selected and an + array of their names +*/ +void pdf_choice_widget_set_value(pdf_document *doc, pdf_widget *tw, int n, char *opts[]); + +#endif diff --git a/include/mupdf/pdf/xref.h b/include/mupdf/pdf/xref.h new file mode 100644 index 00000000..d4317bad --- /dev/null +++ b/include/mupdf/pdf/xref.h @@ -0,0 +1,85 @@ +#ifndef MUPDF_PDF_XREF_H +#define MUPDF_PDF_XREF_H + +/* + pdf_create_object: Allocate a slot in the xref table and return a fresh unused object number. +*/ +int pdf_create_object(pdf_document *xref); + +/* + pdf_delete_object: Remove object from xref table, marking the slot as free. +*/ +void pdf_delete_object(pdf_document *xref, int num); + +/* + pdf_update_object: Replace object in xref table with the passed in object. +*/ +void pdf_update_object(pdf_document *xref, int num, pdf_obj *obj); + +/* + pdf_update_stream: Replace stream contents for object in xref table with the passed in buffer. + + The buffer contents must match the /Filter setting. + If storing uncompressed data, make sure to delete the /Filter key from + the stream dictionary. If storing deflated data, make sure to set the + /Filter value to /FlateDecode. +*/ +void pdf_update_stream(pdf_document *xref, int num, fz_buffer *buf); + +/* + * 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 */ +}; + +struct pdf_xref_s +{ + int len; + pdf_xref_entry *table; + pdf_obj *trailer; +}; + +void pdf_cache_object(pdf_document *doc, int num, int gen); + +int pdf_count_objects(pdf_document *doc); +pdf_obj *pdf_resolve_indirect(pdf_obj *ref); +pdf_obj *pdf_load_object(pdf_document *doc, int num, int gen); + +fz_buffer *pdf_load_raw_stream(pdf_document *doc, int num, int gen); +fz_buffer *pdf_load_stream(pdf_document *doc, int num, int gen); +fz_stream *pdf_open_raw_stream(pdf_document *doc, int num, int gen); +fz_stream *pdf_open_stream(pdf_document *doc, int num, int gen); + +fz_stream *pdf_open_inline_stream(pdf_document *doc, pdf_obj *stmobj, int length, fz_stream *chain, fz_compression_params *params); +fz_compressed_buffer *pdf_load_compressed_stream(pdf_document *doc, int num, int gen); +fz_stream *pdf_open_stream_with_offset(pdf_document *doc, int num, int gen, pdf_obj *dict, int stm_ofs); +fz_stream *pdf_open_compressed_stream(fz_context *ctx, fz_compressed_buffer *); +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, int *truncated); +fz_stream *pdf_open_raw_renumbered_stream(pdf_document *doc, int num, int gen, int orig_num, int orig_gen); + +pdf_obj *pdf_trailer(pdf_document *doc); +void pdf_set_populating_xref_trailer(pdf_document *doc, pdf_obj *trailer); +int pdf_xref_len(pdf_document *doc); +pdf_xref_entry *pdf_get_populating_xref_entry(pdf_document *doc, int i); +pdf_xref_entry *pdf_get_xref_entry(pdf_document *doc, int i); +void pdf_replace_xref(pdf_document *doc, pdf_xref_entry *entries, int n); + +void pdf_repair_xref(pdf_document *doc, pdf_lexbuf *buf); +void pdf_repair_obj_stms(pdf_document *doc); +pdf_obj *pdf_new_ref(pdf_document *doc, pdf_obj *obj); + +void pdf_print_xref(pdf_document *); + +#endif diff --git a/pdf/pdf_object.c b/pdf/pdf_object.c index ac1609cf..c07f4bef 100644 --- a/pdf/pdf_object.c +++ b/pdf/pdf_object.c @@ -49,7 +49,7 @@ struct pdf_obj_s struct { int num; int gen; - struct pdf_xref_s *xref; + pdf_document *xref; } r; } u; }; @@ -311,7 +311,7 @@ int pdf_to_gen(pdf_obj *obj) return obj->u.r.gen; } -void *pdf_get_indirect_document(pdf_obj *obj) +pdf_document *pdf_get_indirect_document(pdf_obj *obj) { if (!obj || obj->kind != PDF_INDIRECT) return NULL; |