#ifndef MUPDF_PDF_DOCUMENT_H1#define MUPDF_PDF_DOCUMENT_H23typedef struct pdf_lexbuf_s pdf_lexbuf;4typedef struct pdf_lexbuf_large_s pdf_lexbuf_large;5typedef struct pdf_xref_s pdf_xref;6typedef struct pdf_crypt_s pdf_crypt;7typedef struct pdf_ocg_descriptor_s pdf_ocg_descriptor;89typedef struct pdf_page_s pdf_page;10typedef struct pdf_annot_s pdf_annot;11typedef struct pdf_widget_s pdf_widget;12typedef struct pdf_hotspot_s pdf_hotspot;13typedef struct pdf_js_s pdf_js;1415enum16{17PDF_LEXBUF_SMALL = 256,18PDF_LEXBUF_LARGE = 6553619};2021struct pdf_lexbuf_s22{23int size;24int base_size;25int len;26int i;27float f;28char *scratch;29char buffer[PDF_LEXBUF_SMALL];30};3132struct pdf_lexbuf_large_s33{34pdf_lexbuf base;35char buffer[PDF_LEXBUF_LARGE - PDF_LEXBUF_SMALL];36};3738struct pdf_hotspot_s39{40int num;41int gen;42int state;43};4445/*46Document event structures are mostly opaque to the app. Only the type47is visible to the app.48*/49typedef struct pdf_doc_event_s pdf_doc_event;5051/*52pdf_doc_event_cb: the type of function via which the app receives53document events.54*/55typedef void (pdf_doc_event_cb)(fz_context *ctx, pdf_document *doc, pdf_doc_event *event, void *data);5657/*58pdf_open_document: Open a PDF document.5960Open a PDF document by reading its cross reference table, so61MuPDF can locate PDF objects inside the file. Upon an broken62cross reference table or other parse errors MuPDF will restart63parsing the file from the beginning to try to rebuild a64(hopefully correct) cross reference table to allow further65processing of the file.6667The returned pdf_document should be used when calling most68other PDF functions. Note that it wraps the context, so those69functions implicitly get access to the global state in70context.7172filename: a path to a file as it would be given to open(2).73*/74pdf_document *pdf_open_document(fz_context *ctx, const char *filename);7576/*77pdf_open_document_with_stream: Opens a PDF document.7879Same as pdf_open_document, but takes a stream instead of a80filename to locate the PDF document to open. Increments the81reference count of the stream. See fz_open_file,82fz_open_file_w or fz_open_fd for opening a stream, and83fz_drop_stream for closing an open stream.84*/85pdf_document *pdf_open_document_with_stream(fz_context *ctx, fz_stream *file);8687/*88pdf_close_document: Closes and frees an opened PDF document.8990The resource store in the context associated with pdf_document91is emptied.9293Does not throw exceptions.94*/95void pdf_close_document(fz_context *ctx, pdf_document *doc);9697/*98pdf_specific: down-cast an fz_document to a pdf_document.99Returns NULL if underlying document is not PDF100*/101pdf_document *pdf_specifics(fz_context *ctx, fz_document *doc);102103int pdf_needs_password(fz_context *ctx, pdf_document *doc);104int pdf_authenticate_password(fz_context *ctx, pdf_document *doc, const char *pw);105106int pdf_has_permission(fz_context *ctx, pdf_document *doc, fz_permission p);107int pdf_lookup_metadata(fz_context *ctx, pdf_document *doc, const char *key, char *ptr, int size);108109fz_outline *pdf_load_outline(fz_context *ctx, pdf_document *doc);110111typedef struct pdf_ocg_entry_s pdf_ocg_entry;112113struct pdf_ocg_entry_s114{115int num;116int gen;117int state;118};119120struct pdf_ocg_descriptor_s121{122int len;123pdf_ocg_entry *ocgs;124pdf_obj *intent;125};126127/*128pdf_update_page: update a page for the sake of changes caused by a call129to pdf_pass_event. pdf_update_page regenerates any appearance streams that130are out of date, checks for cases where different appearance streams131should be selected because of state changes, and records internally132each annotation that has changed appearance. The list of changed annotations133is then available via pdf_poll_changed_annot. Note that a call to134pdf_pass_event for one page may lead to changes on any other, so an app135should call pdf_update_page for every page it currently displays. Also136it is important that the pdf_page object is the one used to last render137the page. If instead the app were to drop the page and reload it then138a call to pdf_update_page would not reliably be able to report all changed139areas.140*/141void pdf_update_page(fz_context *ctx, pdf_document *doc, pdf_page *page);142143/*144Determine whether changes have been made since the145document was opened or last saved.146*/147int pdf_has_unsaved_changes(fz_context *ctx, pdf_document *doc);148149typedef struct pdf_signer_s pdf_signer;150151/* Unsaved signature fields */152typedef struct pdf_unsaved_sig_s pdf_unsaved_sig;153154struct pdf_unsaved_sig_s155{156pdf_obj *field;157int byte_range_start;158int byte_range_end;159int contents_start;160int contents_end;161pdf_signer *signer;162pdf_unsaved_sig *next;163};164165struct pdf_document_s166{167fz_document super;168169fz_stream *file;170171int version;172int startxref;173int file_size;174pdf_crypt *crypt;175pdf_ocg_descriptor *ocg;176pdf_hotspot hotspot;177178int max_xref_len;179int num_xref_sections;180pdf_xref *xref_sections;181int *xref_index;182int xref_altered;183int freeze_updates;184int has_xref_streams;185186int page_count;187188int repair_attempted;189190/* State indicating which file parsing method we are using */191int file_reading_linearly;192int file_length;193194pdf_obj *linear_obj; /* Linearized object (if used) */195pdf_obj **linear_page_refs; /* Page objects for linear loading */196int linear_page1_obj_num;197198/* The state for the pdf_progressive_advance parser */199int linear_pos;200int linear_page_num;201202int hint_object_offset;203int hint_object_length;204int hints_loaded; /* Set to 1 after the hints loading has completed,205* whether successful or not! */206/* Page n references shared object references:207* hint_shared_ref[i]208* where209* i = s to e-1210* s = hint_page[n]->index211* e = hint_page[n+1]->index212* Shared object reference r accesses objects:213* rs to re-1214* where215* rs = hint_shared[r]->number216* re = hint_shared[r]->count + rs217* These are guaranteed to lie within the region starting at218* hint_shared[r]->offset of length hint_shared[r]->length219*/220struct221{222int number; /* Page object number */223int offset; /* Offset of page object */224int index; /* Index into shared hint_shared_ref */225} *hint_page;226int *hint_shared_ref;227struct228{229int number; /* Object number of first object */230int offset; /* Offset of first object */231} *hint_shared;232int hint_obj_offsets_max;233int *hint_obj_offsets;234235int resources_localised;236237pdf_lexbuf_large lexbuf;238239pdf_annot *focus;240pdf_obj *focus_obj;241242pdf_js *js;243void (*drop_js)(pdf_js *js);244int recalculating;245int dirty;246pdf_unsaved_sig *unsaved_sigs;247248void (*update_appearance)(fz_context *ctx, pdf_document *doc, pdf_annot *annot);249250pdf_doc_event_cb *event_cb;251void *event_cb_data;252253int num_type3_fonts;254int max_type3_fonts;255fz_font **type3_fonts;256};257258/*259PDF creation260*/261262/*263pdf_create_document: Create a blank PDF document264*/265pdf_document *pdf_create_document(fz_context *ctx);266267pdf_page *pdf_create_page(fz_context *ctx, pdf_document *doc, fz_rect rect, int res, int rotate);268269void pdf_insert_page(fz_context *ctx, pdf_document *doc, pdf_page *page, int at);270271void pdf_delete_page(fz_context *ctx, pdf_document *doc, int number);272273void pdf_delete_page_range(fz_context *ctx, pdf_document *doc, int start, int end);274275fz_device *pdf_page_write(fz_context *ctx, pdf_document *doc, pdf_page *page);276277void pdf_finish_edit(fz_context *ctx, pdf_document *doc);278279int pdf_recognize(fz_context *doc, const char *magic);280281#endif282283284