1 #ifndef MUPDF_FITZ_DOCUMENT_H
2 #define MUPDF_FITZ_DOCUMENT_H
4 #include "mupdf/fitz/system.h"
5 #include "mupdf/fitz/context.h"
6 #include "mupdf/fitz/math.h"
7 #include "mupdf/fitz/device.h"
8 #include "mupdf/fitz/transition.h"
9 #include "mupdf/fitz/link.h"
10 #include "mupdf/fitz/outline.h"
15 typedef struct fz_document_s fz_document;
16 typedef struct fz_document_handler_s fz_document_handler;
17 typedef struct fz_page_s fz_page;
18 typedef struct fz_annot_s fz_annot;
20 // TODO: move out of this interface (it's pdf specific)
21 typedef struct fz_write_options_s fz_write_options;
23 typedef void (fz_document_close_fn)(fz_document *doc);
24 typedef int (fz_document_needs_password_fn)(fz_document *doc);
25 typedef int (fz_document_authenticate_password_fn)(fz_document *doc, const char *password);
26 typedef fz_outline *(fz_document_load_outline_fn)(fz_document *doc);
27 typedef void (fz_document_layout_fn)(fz_document *doc, float w, float h, float em);
28 typedef int (fz_document_count_pages_fn)(fz_document *doc);
29 typedef fz_page *(fz_document_load_page_fn)(fz_document *doc, int number);
30 typedef fz_link *(fz_document_load_links_fn)(fz_document *doc, fz_page *page);
31 typedef fz_rect *(fz_document_bound_page_fn)(fz_document *doc, fz_page *page, fz_rect *);
32 typedef void (fz_document_run_page_contents_fn)(fz_document *doc, fz_page *page, fz_device *dev, const fz_matrix *transform, fz_cookie *cookie);
33 typedef void (fz_document_run_annot_fn)(fz_document *doc, fz_page *page, fz_annot *annot, fz_device *dev, const fz_matrix *transform, fz_cookie *cookie);
34 typedef void (fz_document_free_page_fn)(fz_document *doc, fz_page *page);
35 typedef int (fz_document_meta_fn)(fz_document *doc, int key, void *ptr, int size);
36 typedef fz_transition *(fz_document_page_presentation_fn)(fz_document *doc, fz_page *page, float *duration);
37 typedef fz_annot *(fz_document_first_annot_fn)(fz_document *doc, fz_page *page);
38 typedef fz_annot *(fz_document_next_annot_fn)(fz_document *doc, fz_annot *annot);
39 typedef fz_rect *(fz_document_bound_annot_fn)(fz_document *doc, fz_annot *annot, fz_rect *rect);
40 typedef void (fz_document_write_fn)(fz_document *doc, char *filename, fz_write_options *opts);
41 typedef void (fz_document_rebind_fn)(fz_document *doc, fz_context *ctx);
45 fz_document_close_fn *close;
46 fz_document_needs_password_fn *needs_password;
47 fz_document_authenticate_password_fn *authenticate_password;
48 fz_document_load_outline_fn *load_outline;
49 fz_document_layout_fn *layout;
50 fz_document_count_pages_fn *count_pages;
51 fz_document_load_page_fn *load_page;
52 fz_document_load_links_fn *load_links;
53 fz_document_bound_page_fn *bound_page;
54 fz_document_run_page_contents_fn *run_page_contents;
55 fz_document_run_annot_fn *run_annot;
56 fz_document_free_page_fn *free_page;
57 fz_document_meta_fn *meta;
58 fz_document_page_presentation_fn *page_presentation;
59 fz_document_first_annot_fn *first_annot;
60 fz_document_next_annot_fn *next_annot;
61 fz_document_bound_annot_fn *bound_annot;
62 fz_document_write_fn *write;
63 fz_document_rebind_fn *rebind;
66 typedef fz_document *(fz_document_open_fn)(fz_context *ctx, const char *filename);
67 typedef fz_document *(fz_document_open_with_stream_fn)(fz_context *ctx, fz_stream *stream);
68 typedef int (fz_document_recognize_fn)(fz_context *ctx, const char *magic);
70 struct fz_document_handler_s
72 fz_document_recognize_fn *recognize;
73 fz_document_open_fn *open;
74 fz_document_open_with_stream_fn *open_with_stream;
77 extern fz_document_handler pdf_document_handler;
78 extern fz_document_handler pdf_no_run_document_handler;
79 extern fz_document_handler xps_document_handler;
80 extern fz_document_handler cbz_document_handler;
81 extern fz_document_handler img_document_handler;
82 extern fz_document_handler tiff_document_handler;
84 void fz_register_document_handler(fz_context *ctx, const fz_document_handler *handler);
86 void fz_register_document_handlers(fz_context *ctx);
87 void fz_register_no_run_document_handlers(fz_context *ctx);
90 fz_open_document: Open a PDF, XPS or CBZ document.
92 Open a document file and read its basic structure so pages and
93 objects can be located. MuPDF will try to repair broken
94 documents (without actually changing the file contents).
96 The returned fz_document is used when calling most other
97 document related functions. Note that it wraps the context, so
98 those functions implicitly can access the global state in
101 filename: a path to a file as it would be given to open(2).
103 fz_document *fz_open_document(fz_context *ctx, const char *filename);
106 fz_open_document_with_stream: Open a PDF, XPS or CBZ document.
108 Open a document using the specified stream object rather than
109 opening a file on disk.
111 magic: a string used to detect document type; either a file name or mime-type.
113 fz_document *fz_open_document_with_stream(fz_context *ctx, const char *magic, fz_stream *stream);
116 fz_close_document: Close and free an open document.
118 The resource store in the context associated with fz_document
119 is emptied, and any allocations for the document are freed.
121 Does not throw exceptions.
123 void fz_close_document(fz_document *doc);
126 fz_needs_password: Check if a document is encrypted with a
129 Does not throw exceptions.
131 int fz_needs_password(fz_document *doc);
134 fz_authenticate_password: Test if the given password can
135 decrypt the document.
137 password: The password string to be checked. Some document
138 specifications do not specify any particular text encoding, so
141 Does not throw exceptions.
143 int fz_authenticate_password(fz_document *doc, const char *password);
146 fz_load_outline: Load the hierarchical document outline.
148 Should be freed by fz_free_outline.
150 fz_outline *fz_load_outline(fz_document *doc);
153 fz_layout_document: Layout reflowable document types.
155 w, h: Page size in points.
156 em: Default font size in points.
158 void fz_layout_document(fz_document *doc, float w, float h, float em);
161 fz_count_pages: Return the number of pages in document
163 May return 0 for documents with no pages.
165 int fz_count_pages(fz_document *doc);
168 fz_load_page: Load a page.
170 After fz_load_page is it possible to retrieve the size of the
171 page using fz_bound_page, or to render the page using
172 fz_run_page_*. Free the page by calling fz_free_page.
174 number: page number, 0 is the first page of the document.
176 fz_page *fz_load_page(fz_document *doc, int number);
179 fz_load_links: Load the list of links for a page.
181 Returns a linked list of all the links on the page, each with
182 its clickable region and link destination. Each link is
183 reference counted so drop and free the list of links by
184 calling fz_drop_link on the pointer return from fz_load_links.
186 page: Page obtained from fz_load_page.
188 fz_link *fz_load_links(fz_document *doc, fz_page *page);
191 fz_bound_page: Determine the size of a page at 72 dpi.
193 Does not throw exceptions.
195 fz_rect *fz_bound_page(fz_document *doc, fz_page *page, fz_rect *rect);
198 fz_run_page: Run a page through a device.
200 page: Page obtained from fz_load_page.
202 dev: Device obtained from fz_new_*_device.
204 transform: Transform to apply to page. May include for example
205 scaling and rotation, see fz_scale, fz_rotate and fz_concat.
206 Set to fz_identity if no transformation is desired.
208 cookie: Communication mechanism between caller and library
209 rendering the page. Intended for multi-threaded applications,
210 while single-threaded applications set cookie to NULL. The
211 caller may abort an ongoing rendering of a page. Cookie also
212 communicates progress information back to the caller. The
213 fields inside cookie are continually updated while the page is
216 void fz_run_page(fz_document *doc, fz_page *page, fz_device *dev, const fz_matrix *transform, fz_cookie *cookie);
219 fz_run_page_contents: Run a page through a device. Just the main
220 page content, without the annotations, if any.
222 page: Page obtained from fz_load_page.
224 dev: Device obtained from fz_new_*_device.
226 transform: Transform to apply to page. May include for example
227 scaling and rotation, see fz_scale, fz_rotate and fz_concat.
228 Set to fz_identity if no transformation is desired.
230 cookie: Communication mechanism between caller and library
231 rendering the page. Intended for multi-threaded applications,
232 while single-threaded applications set cookie to NULL. The
233 caller may abort an ongoing rendering of a page. Cookie also
234 communicates progress information back to the caller. The
235 fields inside cookie are continually updated while the page is
238 void fz_run_page_contents(fz_document *doc, fz_page *page, fz_device *dev, const fz_matrix *transform, fz_cookie *cookie);
241 fz_run_annot: Run an annotation through a device.
243 page: Page obtained from fz_load_page.
245 annot: an annotation.
247 dev: Device obtained from fz_new_*_device.
249 transform: Transform to apply to page. May include for example
250 scaling and rotation, see fz_scale, fz_rotate and fz_concat.
251 Set to fz_identity if no transformation is desired.
253 cookie: Communication mechanism between caller and library
254 rendering the page. Intended for multi-threaded applications,
255 while single-threaded applications set cookie to NULL. The
256 caller may abort an ongoing rendering of a page. Cookie also
257 communicates progress information back to the caller. The
258 fields inside cookie are continually updated while the page is
261 void fz_run_annot(fz_document *doc, fz_page *page, fz_annot *annot, fz_device *dev, const fz_matrix *transform, fz_cookie *cookie);
264 fz_free_page: Free a loaded page.
266 Does not throw exceptions.
268 void fz_free_page(fz_document *doc, fz_page *page);
271 fz_page_presentation: Get the presentation details for a given page.
273 duration: NULL, or a pointer to a place to set the page duration in
274 seconds. (Will be set to 0 if unspecified).
276 Returns: a pointer to a transition structure, or NULL if there isn't
279 Does not throw exceptions.
281 fz_transition *fz_page_presentation(fz_document *doc, fz_page *page, float *duration);
283 void fz_rebind_document(fz_document *doc, fz_context *ctx);