#ifndef MUPDF_FITZ_DOCUMENT_H1#define MUPDF_FITZ_DOCUMENT_H23#include "mupdf/fitz/system.h"4#include "mupdf/fitz/context.h"5#include "mupdf/fitz/math.h"6#include "mupdf/fitz/device.h"7#include "mupdf/fitz/transition.h"8#include "mupdf/fitz/link.h"9#include "mupdf/fitz/outline.h"1011/*12Document interface13*/14typedef struct fz_document_s fz_document;15typedef struct fz_document_handler_s fz_document_handler;16typedef struct fz_page_s fz_page;17typedef struct fz_annot_s fz_annot;1819typedef enum20{21FZ_PERMISSION_PRINT = 'p',22FZ_PERMISSION_COPY = 'c',23FZ_PERMISSION_EDIT = 'e',24FZ_PERMISSION_ANNOTATE = 'n',25}26fz_permission;2728// TODO: move out of this interface (it's pdf specific)29typedef struct fz_write_options_s fz_write_options;3031typedef void (fz_document_close_fn)(fz_context *ctx, fz_document *doc);32typedef int (fz_document_needs_password_fn)(fz_context *ctx, fz_document *doc);33typedef int (fz_document_authenticate_password_fn)(fz_context *ctx, fz_document *doc, const char *password);34typedef int (fz_document_has_permission_fn)(fz_context *ctx, fz_document *doc, fz_permission permission);35typedef fz_outline *(fz_document_load_outline_fn)(fz_context *ctx, fz_document *doc);36typedef void (fz_document_layout_fn)(fz_context *ctx, fz_document *doc, float w, float h, float em);37typedef int (fz_document_count_pages_fn)(fz_context *ctx, fz_document *doc);38typedef fz_page *(fz_document_load_page_fn)(fz_context *ctx, fz_document *doc, int number);39typedef int (fz_document_lookup_metadata_fn)(fz_context *ctx, fz_document *doc, const char *key, char *buf, int size);40typedef void (fz_document_write_fn)(fz_context *ctx, fz_document *doc, char *filename, fz_write_options *opts);4142typedef fz_link *(fz_page_load_links_fn)(fz_context *ctx, fz_page *page);43typedef fz_rect *(fz_page_bound_page_fn)(fz_context *ctx, fz_page *page, fz_rect *);44typedef void (fz_page_run_page_contents_fn)(fz_context *ctx, fz_page *page, fz_device *dev, const fz_matrix *transform, fz_cookie *cookie);45typedef void (fz_page_drop_page_imp_fn)(fz_context *ctx, fz_page *page);46typedef fz_transition *(fz_page_page_presentation_fn)(fz_context *ctx, fz_page *page, float *duration);4748typedef fz_annot *(fz_page_first_annot_fn)(fz_context *ctx, fz_page *page);49typedef fz_annot *(fz_page_next_annot_fn)(fz_context *ctx, fz_page *page, fz_annot *annot);50typedef fz_rect *(fz_page_bound_annot_fn)(fz_context *ctx, fz_page *page, fz_annot *annot, fz_rect *rect);51typedef void (fz_page_run_annot_fn)(fz_context *ctx, fz_page *page, fz_annot *annot, fz_device *dev, const fz_matrix *transform, fz_cookie *cookie);5253struct fz_page_s54{55int refs;56fz_page_drop_page_imp_fn *drop_page_imp;57fz_page_bound_page_fn *bound_page;58fz_page_run_page_contents_fn *run_page_contents;59fz_page_load_links_fn *load_links;60fz_page_first_annot_fn *first_annot;61fz_page_next_annot_fn *next_annot;62fz_page_bound_annot_fn *bound_annot;63fz_page_run_annot_fn *run_annot;64fz_page_page_presentation_fn *page_presentation;65};6667struct fz_document_s68{69int refs;70fz_document_close_fn *close;71fz_document_needs_password_fn *needs_password;72fz_document_authenticate_password_fn *authenticate_password;73fz_document_has_permission_fn *has_permission;74fz_document_load_outline_fn *load_outline;75fz_document_layout_fn *layout;76fz_document_count_pages_fn *count_pages;77fz_document_load_page_fn *load_page;78fz_document_lookup_metadata_fn *lookup_metadata;79fz_document_write_fn *write;80int did_layout;81};8283typedef fz_document *(fz_document_open_fn)(fz_context *ctx, const char *filename);84typedef fz_document *(fz_document_open_with_stream_fn)(fz_context *ctx, fz_stream *stream);85typedef int (fz_document_recognize_fn)(fz_context *ctx, const char *magic);8687struct fz_document_handler_s88{89fz_document_recognize_fn *recognize;90fz_document_open_fn *open;91fz_document_open_with_stream_fn *open_with_stream;92};9394extern fz_document_handler pdf_document_handler;95extern fz_document_handler xps_document_handler;96extern fz_document_handler cbz_document_handler;97extern fz_document_handler img_document_handler;98extern fz_document_handler tiff_document_handler;99extern fz_document_handler html_document_handler;100extern fz_document_handler epub_document_handler;101102void fz_register_document_handler(fz_context *ctx, const fz_document_handler *handler);103104void fz_register_document_handlers(fz_context *ctx);105106/*107fz_open_document: Open a PDF, XPS or CBZ document.108109Open a document file and read its basic structure so pages and110objects can be located. MuPDF will try to repair broken111documents (without actually changing the file contents).112113The returned fz_document is used when calling most other114document related functions. Note that it wraps the context, so115those functions implicitly can access the global state in116context.117118filename: a path to a file as it would be given to open(2).119*/120fz_document *fz_open_document(fz_context *ctx, const char *filename);121122/*123fz_open_document_with_stream: Open a PDF, XPS or CBZ document.124125Open a document using the specified stream object rather than126opening a file on disk.127128magic: a string used to detect document type; either a file name or mime-type.129*/130fz_document *fz_open_document_with_stream(fz_context *ctx, const char *magic, fz_stream *stream);131132/*133fz_new_document: Create and initialize a document struct.134*/135void *fz_new_document(fz_context *ctx, int size);136137/*138fz_drop_document: Release an open document.139140The resource store in the context associated with fz_document141is emptied, and any allocations for the document are freed when142the last reference is dropped.143144Does not throw exceptions.145*/146void fz_drop_document(fz_context *ctx, fz_document *doc);147148fz_document *fz_keep_document(fz_context *ctx, fz_document *doc);149150/*151fz_needs_password: Check if a document is encrypted with a152non-blank password.153154Does not throw exceptions.155*/156int fz_needs_password(fz_context *ctx, fz_document *doc);157158/*159fz_authenticate_password: Test if the given password can160decrypt the document.161162password: The password string to be checked. Some document163specifications do not specify any particular text encoding, so164neither do we.165166Does not throw exceptions.167*/168int fz_authenticate_password(fz_context *ctx, fz_document *doc, const char *password);169170/*171fz_load_outline: Load the hierarchical document outline.172173Should be freed by fz_drop_outline.174*/175fz_outline *fz_load_outline(fz_context *ctx, fz_document *doc);176177/*178fz_layout_document: Layout reflowable document types.179180w, h: Page size in points.181em: Default font size in points.182*/183void fz_layout_document(fz_context *ctx, fz_document *doc, float w, float h, float em);184185/*186fz_count_pages: Return the number of pages in document187188May return 0 for documents with no pages.189*/190int fz_count_pages(fz_context *ctx, fz_document *doc);191192/*193fz_load_page: Load a page.194195After fz_load_page is it possible to retrieve the size of the196page using fz_bound_page, or to render the page using197fz_run_page_*. Free the page by calling fz_drop_page.198199number: page number, 0 is the first page of the document.200*/201fz_page *fz_load_page(fz_context *ctx, fz_document *doc, int number);202203/*204fz_load_links: Load the list of links for a page.205206Returns a linked list of all the links on the page, each with207its clickable region and link destination. Each link is208reference counted so drop and free the list of links by209calling fz_drop_link on the pointer return from fz_load_links.210211page: Page obtained from fz_load_page.212*/213fz_link *fz_load_links(fz_context *ctx, fz_page *page);214215/*216fz_new_page: Create and initialize a page struct.217*/218void *fz_new_page(fz_context *ctx, int size);219220/*221fz_bound_page: Determine the size of a page at 72 dpi.222223Does not throw exceptions.224*/225fz_rect *fz_bound_page(fz_context *ctx, fz_page *page, fz_rect *rect);226227/*228fz_run_page: Run a page through a device.229230page: Page obtained from fz_load_page.231232dev: Device obtained from fz_new_*_device.233234transform: Transform to apply to page. May include for example235scaling and rotation, see fz_scale, fz_rotate and fz_concat.236Set to fz_identity if no transformation is desired.237238cookie: Communication mechanism between caller and library239rendering the page. Intended for multi-threaded applications,240while single-threaded applications set cookie to NULL. The241caller may abort an ongoing rendering of a page. Cookie also242communicates progress information back to the caller. The243fields inside cookie are continually updated while the page is244rendering.245*/246void fz_run_page(fz_context *ctx, fz_page *page, fz_device *dev, const fz_matrix *transform, fz_cookie *cookie);247248/*249fz_run_page_contents: Run a page through a device. Just the main250page content, without the annotations, if any.251252page: Page obtained from fz_load_page.253254dev: Device obtained from fz_new_*_device.255256transform: Transform to apply to page. May include for example257scaling and rotation, see fz_scale, fz_rotate and fz_concat.258Set to fz_identity if no transformation is desired.259260cookie: Communication mechanism between caller and library261rendering the page. Intended for multi-threaded applications,262while single-threaded applications set cookie to NULL. The263caller may abort an ongoing rendering of a page. Cookie also264communicates progress information back to the caller. The265fields inside cookie are continually updated while the page is266rendering.267*/268void fz_run_page_contents(fz_context *ctx, fz_page *page, fz_device *dev, const fz_matrix *transform, fz_cookie *cookie);269270/*271fz_run_annot: Run an annotation through a device.272273page: Page obtained from fz_load_page.274275annot: an annotation.276277dev: Device obtained from fz_new_*_device.278279transform: Transform to apply to page. May include for example280scaling and rotation, see fz_scale, fz_rotate and fz_concat.281Set to fz_identity if no transformation is desired.282283cookie: Communication mechanism between caller and library284rendering the page. Intended for multi-threaded applications,285while single-threaded applications set cookie to NULL. The286caller may abort an ongoing rendering of a page. Cookie also287communicates progress information back to the caller. The288fields inside cookie are continually updated while the page is289rendering.290*/291void fz_run_annot(fz_context *ctx, fz_page *page, fz_annot *annot, fz_device *dev, const fz_matrix *transform, fz_cookie *cookie);292293/*294fz_drop_page: Free a loaded page.295296Does not throw exceptions.297*/298void fz_drop_page(fz_context *ctx, fz_page *page);299300/*301fz_page_presentation: Get the presentation details for a given page.302303duration: NULL, or a pointer to a place to set the page duration in304seconds. (Will be set to 0 if unspecified).305306Returns: a pointer to a transition structure, or NULL if there isn't307one.308309Does not throw exceptions.310*/311fz_transition *fz_page_presentation(fz_context *ctx, fz_page *page, float *duration);312313/*314fz_has_permission: Check permission flags on document.315*/316int fz_has_permission(fz_context *ctx, fz_document *doc, fz_permission p);317318/*319fz_lookup_metadata: Retrieve document meta data strings.320321doc: The document to query.322323key: Which meta data key to retrieve...324325Basic information:326'format' -- Document format and version.327'encryption' -- Description of the encryption used.328329From the document information dictionary:330'info:Title'331'info:Author'332'info:Subject'333'info:Keywords'334'info:Creator'335'info:Producer'336'info:CreationDate'337'info:ModDate'338339buf: The buffer to hold the results (a nul-terminated UTF-8 string).340341size: Size of 'buf'.342343Returns the size of the output string (may be larger than 'size' if344the output was truncated), or -1 if the key is not recognized or found.345*/346int fz_lookup_metadata(fz_context *ctx, fz_document *doc, const char *key, char *buf, int size);347348#define FZ_META_FORMAT "format"349#define FZ_META_ENCRYPTION "encryption"350351#define FZ_META_INFO_AUTHOR "info:Author"352#define FZ_META_INFO_TITLE "info:Title"353354#endif355356357