1#ifndef MUPDF_FITZ_DOCUMENT_H
2#define MUPDF_FITZ_DOCUMENT_H
3
4#include "mupdf/fitz/system.h"
5#include "mupdf/fitz/context.h"
6#include "mupdf/fitz/geometry.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"
11#include "mupdf/fitz/separation.h"
12
13typedef struct fz_document_s fz_document;
14typedef struct fz_document_handler_s fz_document_handler;
15typedef struct fz_page_s fz_page;
16typedef intptr_t fz_bookmark;
17
18enum
19{
20 /* 6in at 4:3 */
21 FZ_LAYOUT_KINDLE_W = 260,
22 FZ_LAYOUT_KINDLE_H = 346,
23 FZ_LAYOUT_KINDLE_EM = 9,
24
25 /* 4.25 x 6.87 in */
26 FZ_LAYOUT_US_POCKET_W = 306,
27 FZ_LAYOUT_US_POCKET_H = 495,
28 FZ_LAYOUT_US_POCKET_EM = 10,
29
30 /* 5.5 x 8.5 in */
31 FZ_LAYOUT_US_TRADE_W = 396,
32 FZ_LAYOUT_US_TRADE_H = 612,
33 FZ_LAYOUT_US_TRADE_EM = 11,
34
35 /* 110 x 178 mm */
36 FZ_LAYOUT_UK_A_FORMAT_W = 312,
37 FZ_LAYOUT_UK_A_FORMAT_H = 504,
38 FZ_LAYOUT_UK_A_FORMAT_EM = 10,
39
40 /* 129 x 198 mm */
41 FZ_LAYOUT_UK_B_FORMAT_W = 366,
42 FZ_LAYOUT_UK_B_FORMAT_H = 561,
43 FZ_LAYOUT_UK_B_FORMAT_EM = 10,
44
45 /* 135 x 216 mm */
46 FZ_LAYOUT_UK_C_FORMAT_W = 382,
47 FZ_LAYOUT_UK_C_FORMAT_H = 612,
48 FZ_LAYOUT_UK_C_FORMAT_EM = 11,
49
50 /* 148 x 210 mm */
51 FZ_LAYOUT_A5_W = 420,
52 FZ_LAYOUT_A5_H = 595,
53 FZ_LAYOUT_A5_EM = 11,
54
55 /* Default to A5 */
56 FZ_DEFAULT_LAYOUT_W = FZ_LAYOUT_A5_W,
57 FZ_DEFAULT_LAYOUT_H = FZ_LAYOUT_A5_H,
58 FZ_DEFAULT_LAYOUT_EM = FZ_LAYOUT_A5_EM,
59};
60
61typedef enum
62{
63 FZ_PERMISSION_PRINT = 'p',
64 FZ_PERMISSION_COPY = 'c',
65 FZ_PERMISSION_EDIT = 'e',
66 FZ_PERMISSION_ANNOTATE = 'n',
67}
68fz_permission;
69
70/*
71 Type for a function to be called when
72 the reference count for the fz_document drops to 0. The
73 implementation should release any resources held by the
74 document. The actual document pointer will be freed by the
75 caller.
76*/
77typedef void (fz_document_drop_fn)(fz_context *ctx, fz_document *doc);
78
79/*
80 Type for a function to be
81 called to enquire whether the document needs a password
82 or not. See fz_needs_password for more information.
83*/
84typedef int (fz_document_needs_password_fn)(fz_context *ctx, fz_document *doc);
85
86/*
87 Type for a function to be
88 called to attempt to authenticate a password. See
89 fz_authenticate_password for more information.
90*/
91typedef int (fz_document_authenticate_password_fn)(fz_context *ctx, fz_document *doc, const char *password);
92
93/*
94 Type for a function to be
95 called to see if a document grants a certain permission. See
96 fz_document_has_permission for more information.
97*/
98typedef int (fz_document_has_permission_fn)(fz_context *ctx, fz_document *doc, fz_permission permission);
99
100/*
101 Type for a function to be called to
102 load the outlines for a document. See fz_document_load_outline
103 for more information.
104*/
105typedef fz_outline *(fz_document_load_outline_fn)(fz_context *ctx, fz_document *doc);
106
107/*
108 Type for a function to be called to lay
109 out a document. See fz_layout_document for more information.
110*/
111typedef void (fz_document_layout_fn)(fz_context *ctx, fz_document *doc, float w, float h, float em);
112
113/*
114 Type for a function to be called to
115 resolve an internal link to a page number. See fz_resolve_link
116 for more information.
117*/
118typedef int (fz_document_resolve_link_fn)(fz_context *ctx, fz_document *doc, const char *uri, float *xp, float *yp);
119
120/*
121 Type for a function to be called to
122 count the number of pages in a document. See fz_count_pages for
123 more information.
124*/
125typedef int (fz_document_count_pages_fn)(fz_context *ctx, fz_document *doc);
126
127/*
128 Type for a function to load a given
129 page from a document. See fz_load_page for more information.
130*/
131typedef fz_page *(fz_document_load_page_fn)(fz_context *ctx, fz_document *doc, int number);
132
133/*
134 Type for a function to query
135 a documents metadata. See fz_lookup_metadata for more
136 information.
137*/
138typedef int (fz_document_lookup_metadata_fn)(fz_context *ctx, fz_document *doc, const char *key, char *buf, int size);
139
140/*
141 Return output intent color space if it exists
142*/
143typedef fz_colorspace* (fz_document_output_intent_fn)(fz_context *ctx, fz_document *doc);
144
145/*
146 Type for a function to make
147 a bookmark. See fz_make_bookmark for more information.
148*/
149typedef fz_bookmark (fz_document_make_bookmark_fn)(fz_context *ctx, fz_document *doc, int page);
150
151/*
152 Type for a function to lookup
153 a bookmark. See fz_lookup_bookmark for more information.
154*/
155typedef int (fz_document_lookup_bookmark_fn)(fz_context *ctx, fz_document *doc, fz_bookmark mark);
156
157/*
158 Type for a function to release all the
159 resources held by a page. Called automatically when the
160 reference count for that page reaches zero.
161*/
162typedef void (fz_page_drop_page_fn)(fz_context *ctx, fz_page *page);
163
164/*
165 Type for a function to return the
166 bounding box of a page. See fz_bound_page for more
167 information.
168*/
169typedef fz_rect (fz_page_bound_page_fn)(fz_context *ctx, fz_page *page);
170
171/*
172 Type for a function to run the
173 contents of a page. See fz_run_page_contents for more
174 information.
175*/
176typedef void (fz_page_run_page_fn)(fz_context *ctx, fz_page *page, fz_device *dev, fz_matrix transform, fz_cookie *cookie);
177
178/*
179 Type for a function to load the links
180 from a page. See fz_load_links for more information.
181*/
182typedef fz_link *(fz_page_load_links_fn)(fz_context *ctx, fz_page *page);
183
184/*
185 Type for a function to
186 obtain the details of how this page should be presented when
187 in presentation mode. See fz_page_presentation for more
188 information.
189*/
190typedef fz_transition *(fz_page_page_presentation_fn)(fz_context *ctx, fz_page *page, fz_transition *transition, float *duration);
191
192/*
193 Type for a function to enable/
194 disable separations on a page. See fz_control_separation for
195 more information.
196*/
197typedef void (fz_page_control_separation_fn)(fz_context *ctx, fz_page *page, int separation, int disable);
198
199/*
200 Type for a function to detect
201 whether a given separation is enabled or disabled on a page.
202 See FZ_SEPARATION_DISABLED for more information.
203*/
204typedef int (fz_page_separation_disabled_fn)(fz_context *ctx, fz_page *page, int separation);
205
206/*
207 Type for a function to retrieve
208 details of separations on a page. See fz_get_separations
209 for more information.
210*/
211typedef fz_separations *(fz_page_separations_fn)(fz_context *ctx, fz_page *page);
212
213/*
214 Type for a function to retrieve
215 whether or not a given page uses overprint.
216*/
217typedef int (fz_page_uses_overprint_fn)(fz_context *ctx, fz_page *page);
218
219/*
220 Structure definition is public so other classes can
221 derive from it. Do not access the members directly.
222*/
223struct fz_page_s
224{
225 int refs;
226 int number; /* page number */
227 int incomplete; /* incomplete from progressive loading; don't cache! */
228 fz_page_drop_page_fn *drop_page;
229 fz_page_bound_page_fn *bound_page;
230 fz_page_run_page_fn *run_page_contents;
231 fz_page_run_page_fn *run_page_annots;
232 fz_page_run_page_fn *run_page_widgets;
233 fz_page_load_links_fn *load_links;
234 fz_page_page_presentation_fn *page_presentation;
235 fz_page_control_separation_fn *control_separation;
236 fz_page_separation_disabled_fn *separation_disabled;
237 fz_page_separations_fn *separations;
238 fz_page_uses_overprint_fn *overprint;
239 fz_page **prev, *next; /* linked list of currently open pages */
240};
241
242/*
243 Structure definition is public so other classes can
244 derive from it. Callers shoud not access the members
245 directly, though implementations will need initialize
246 functions directly.
247*/
248struct fz_document_s
249{
250 int refs;
251 fz_document_drop_fn *drop_document;
252 fz_document_needs_password_fn *needs_password;
253 fz_document_authenticate_password_fn *authenticate_password;
254 fz_document_has_permission_fn *has_permission;
255 fz_document_load_outline_fn *load_outline;
256 fz_document_layout_fn *layout;
257 fz_document_make_bookmark_fn *make_bookmark;
258 fz_document_lookup_bookmark_fn *lookup_bookmark;
259 fz_document_resolve_link_fn *resolve_link;
260 fz_document_count_pages_fn *count_pages;
261 fz_document_load_page_fn *load_page;
262 fz_document_lookup_metadata_fn *lookup_metadata;
263 fz_document_output_intent_fn *get_output_intent;
264 int did_layout;
265 int is_reflowable;
266 fz_page *open; /* linked list of currently open pages */
267};
268
269/*
270 Function type to open a document from a
271 file.
272
273 filename: file to open
274
275 Pointer to opened document. Throws exception in case of error.
276*/
277typedef fz_document *(fz_document_open_fn)(fz_context *ctx, const char *filename);
278
279/*
280 Function type to open a
281 document from a file.
282
283 stream: fz_stream to read document data from. Must be
284 seekable for formats that require it.
285
286 Pointer to opened document. Throws exception in case of error.
287*/
288typedef fz_document *(fz_document_open_with_stream_fn)(fz_context *ctx, fz_stream *stream);
289
290/*
291 Recognize a document type from
292 a magic string.
293
294 magic: string to recognise - typically a filename or mime
295 type.
296
297 Returns a number between 0 (not recognized) and 100
298 (fully recognized) based on how certain the recognizer
299 is that this is of the required type.
300*/
301typedef int (fz_document_recognize_fn)(fz_context *ctx, const char *magic);
302
303struct fz_document_handler_s
304{
305 fz_document_recognize_fn *recognize;
306 fz_document_open_fn *open;
307 fz_document_open_with_stream_fn *open_with_stream;
308 const char **extensions;
309 const char **mimetypes;
310};
311
312void fz_register_document_handler(fz_context *ctx, const fz_document_handler *handler);
313
314void fz_register_document_handlers(fz_context *ctx);
315
316const fz_document_handler *fz_recognize_document(fz_context *ctx, const char *magic);
317
318fz_document *fz_open_document(fz_context *ctx, const char *filename);
319
320fz_document *fz_open_document_with_stream(fz_context *ctx, const char *magic, fz_stream *stream);
321
322void *fz_new_document_of_size(fz_context *ctx, int size);
323#define fz_new_derived_document(C,M) ((M*)Memento_label(fz_new_document_of_size(C, sizeof(M)), #M))
324
325fz_document *fz_keep_document(fz_context *ctx, fz_document *doc);
326void fz_drop_document(fz_context *ctx, fz_document *doc);
327
328int fz_needs_password(fz_context *ctx, fz_document *doc);
329
330int fz_authenticate_password(fz_context *ctx, fz_document *doc, const char *password);
331
332fz_outline *fz_load_outline(fz_context *ctx, fz_document *doc);
333
334int fz_is_document_reflowable(fz_context *ctx, fz_document *doc);
335
336void fz_layout_document(fz_context *ctx, fz_document *doc, float w, float h, float em);
337
338fz_bookmark fz_make_bookmark(fz_context *ctx, fz_document *doc, int page);
339
340int fz_lookup_bookmark(fz_context *ctx, fz_document *doc, fz_bookmark mark);
341
342int fz_count_pages(fz_context *ctx, fz_document *doc);
343
344int fz_resolve_link(fz_context *ctx, fz_document *doc, const char *uri, float *xp, float *yp);
345
346fz_page *fz_load_page(fz_context *ctx, fz_document *doc, int number);
347
348fz_link *fz_load_links(fz_context *ctx, fz_page *page);
349
350fz_page *fz_new_page_of_size(fz_context *ctx, int size);
351#define fz_new_derived_page(CTX,TYPE) \
352 ((TYPE *)Memento_label(fz_new_page_of_size(CTX,sizeof(TYPE)),#TYPE))
353
354fz_rect fz_bound_page(fz_context *ctx, fz_page *page);
355
356void fz_run_page(fz_context *ctx, fz_page *page, fz_device *dev, fz_matrix transform, fz_cookie *cookie);
357
358void fz_run_page_contents(fz_context *ctx, fz_page *page, fz_device *dev, fz_matrix transform, fz_cookie *cookie);
359void fz_run_page_annots(fz_context *ctx, fz_page *page, fz_device *dev, fz_matrix transform, fz_cookie *cookie);
360void fz_run_page_widgets(fz_context *ctx, fz_page *page, fz_device *dev, fz_matrix transform, fz_cookie *cookie);
361
362fz_page *fz_keep_page(fz_context *ctx, fz_page *page);
363void fz_drop_page(fz_context *ctx, fz_page *page);
364
365fz_transition *fz_page_presentation(fz_context *ctx, fz_page *page, fz_transition *transition, float *duration);
366
367int fz_has_permission(fz_context *ctx, fz_document *doc, fz_permission p);
368
369int fz_lookup_metadata(fz_context *ctx, fz_document *doc, const char *key, char *buf, int size);
370
371#define FZ_META_FORMAT "format"
372#define FZ_META_ENCRYPTION "encryption"
373
374#define FZ_META_INFO_AUTHOR "info:Author"
375#define FZ_META_INFO_TITLE "info:Title"
376
377fz_colorspace *fz_document_output_intent(fz_context *ctx, fz_document *doc);
378
379fz_separations *fz_page_separations(fz_context *ctx, fz_page *page);
380
381int fz_page_uses_overprint(fz_context *ctx, fz_page *page);
382
383#endif
384