Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download
7858 views
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/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"
11
12
/*
13
Document interface
14
*/
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;
19
20
typedef enum
21
{
22
FZ_PERMISSION_PRINT = 'p',
23
FZ_PERMISSION_COPY = 'c',
24
FZ_PERMISSION_EDIT = 'e',
25
FZ_PERMISSION_ANNOTATE = 'n',
26
}
27
fz_permission;
28
29
// TODO: move out of this interface (it's pdf specific)
30
typedef struct fz_write_options_s fz_write_options;
31
32
typedef void (fz_document_close_fn)(fz_context *ctx, fz_document *doc);
33
typedef int (fz_document_needs_password_fn)(fz_context *ctx, fz_document *doc);
34
typedef int (fz_document_authenticate_password_fn)(fz_context *ctx, fz_document *doc, const char *password);
35
typedef int (fz_document_has_permission_fn)(fz_context *ctx, fz_document *doc, fz_permission permission);
36
typedef fz_outline *(fz_document_load_outline_fn)(fz_context *ctx, fz_document *doc);
37
typedef void (fz_document_layout_fn)(fz_context *ctx, fz_document *doc, float w, float h, float em);
38
typedef int (fz_document_count_pages_fn)(fz_context *ctx, fz_document *doc);
39
typedef fz_page *(fz_document_load_page_fn)(fz_context *ctx, fz_document *doc, int number);
40
typedef int (fz_document_lookup_metadata_fn)(fz_context *ctx, fz_document *doc, const char *key, char *buf, int size);
41
typedef void (fz_document_write_fn)(fz_context *ctx, fz_document *doc, char *filename, fz_write_options *opts);
42
43
typedef fz_link *(fz_page_load_links_fn)(fz_context *ctx, fz_page *page);
44
typedef fz_rect *(fz_page_bound_page_fn)(fz_context *ctx, fz_page *page, fz_rect *);
45
typedef void (fz_page_run_page_contents_fn)(fz_context *ctx, fz_page *page, fz_device *dev, const fz_matrix *transform, fz_cookie *cookie);
46
typedef void (fz_page_drop_page_imp_fn)(fz_context *ctx, fz_page *page);
47
typedef fz_transition *(fz_page_page_presentation_fn)(fz_context *ctx, fz_page *page, float *duration);
48
49
typedef fz_annot *(fz_page_first_annot_fn)(fz_context *ctx, fz_page *page);
50
typedef fz_annot *(fz_page_next_annot_fn)(fz_context *ctx, fz_page *page, fz_annot *annot);
51
typedef fz_rect *(fz_page_bound_annot_fn)(fz_context *ctx, fz_page *page, fz_annot *annot, fz_rect *rect);
52
typedef 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);
53
54
struct fz_page_s
55
{
56
int refs;
57
fz_page_drop_page_imp_fn *drop_page_imp;
58
fz_page_bound_page_fn *bound_page;
59
fz_page_run_page_contents_fn *run_page_contents;
60
fz_page_load_links_fn *load_links;
61
fz_page_first_annot_fn *first_annot;
62
fz_page_next_annot_fn *next_annot;
63
fz_page_bound_annot_fn *bound_annot;
64
fz_page_run_annot_fn *run_annot;
65
fz_page_page_presentation_fn *page_presentation;
66
};
67
68
struct fz_document_s
69
{
70
int refs;
71
fz_document_close_fn *close;
72
fz_document_needs_password_fn *needs_password;
73
fz_document_authenticate_password_fn *authenticate_password;
74
fz_document_has_permission_fn *has_permission;
75
fz_document_load_outline_fn *load_outline;
76
fz_document_layout_fn *layout;
77
fz_document_count_pages_fn *count_pages;
78
fz_document_load_page_fn *load_page;
79
fz_document_lookup_metadata_fn *lookup_metadata;
80
fz_document_write_fn *write;
81
int did_layout;
82
};
83
84
typedef fz_document *(fz_document_open_fn)(fz_context *ctx, const char *filename);
85
typedef fz_document *(fz_document_open_with_stream_fn)(fz_context *ctx, fz_stream *stream);
86
typedef int (fz_document_recognize_fn)(fz_context *ctx, const char *magic);
87
88
struct fz_document_handler_s
89
{
90
fz_document_recognize_fn *recognize;
91
fz_document_open_fn *open;
92
fz_document_open_with_stream_fn *open_with_stream;
93
};
94
95
extern fz_document_handler pdf_document_handler;
96
extern fz_document_handler xps_document_handler;
97
extern fz_document_handler cbz_document_handler;
98
extern fz_document_handler img_document_handler;
99
extern fz_document_handler tiff_document_handler;
100
extern fz_document_handler html_document_handler;
101
extern fz_document_handler epub_document_handler;
102
103
void fz_register_document_handler(fz_context *ctx, const fz_document_handler *handler);
104
105
void fz_register_document_handlers(fz_context *ctx);
106
107
/*
108
fz_open_document: Open a PDF, XPS or CBZ document.
109
110
Open a document file and read its basic structure so pages and
111
objects can be located. MuPDF will try to repair broken
112
documents (without actually changing the file contents).
113
114
The returned fz_document is used when calling most other
115
document related functions. Note that it wraps the context, so
116
those functions implicitly can access the global state in
117
context.
118
119
filename: a path to a file as it would be given to open(2).
120
*/
121
fz_document *fz_open_document(fz_context *ctx, const char *filename);
122
123
/*
124
fz_open_document_with_stream: Open a PDF, XPS or CBZ document.
125
126
Open a document using the specified stream object rather than
127
opening a file on disk.
128
129
magic: a string used to detect document type; either a file name or mime-type.
130
*/
131
fz_document *fz_open_document_with_stream(fz_context *ctx, const char *magic, fz_stream *stream);
132
133
/*
134
fz_new_document: Create and initialize a document struct.
135
*/
136
void *fz_new_document(fz_context *ctx, int size);
137
138
/*
139
fz_drop_document: Release an open document.
140
141
The resource store in the context associated with fz_document
142
is emptied, and any allocations for the document are freed when
143
the last reference is dropped.
144
145
Does not throw exceptions.
146
*/
147
void fz_drop_document(fz_context *ctx, fz_document *doc);
148
149
fz_document *fz_keep_document(fz_context *ctx, fz_document *doc);
150
151
/*
152
fz_needs_password: Check if a document is encrypted with a
153
non-blank password.
154
155
Does not throw exceptions.
156
*/
157
int fz_needs_password(fz_context *ctx, fz_document *doc);
158
159
/*
160
fz_authenticate_password: Test if the given password can
161
decrypt the document.
162
163
password: The password string to be checked. Some document
164
specifications do not specify any particular text encoding, so
165
neither do we.
166
167
Does not throw exceptions.
168
*/
169
int fz_authenticate_password(fz_context *ctx, fz_document *doc, const char *password);
170
171
/*
172
fz_load_outline: Load the hierarchical document outline.
173
174
Should be freed by fz_drop_outline.
175
*/
176
fz_outline *fz_load_outline(fz_context *ctx, fz_document *doc);
177
178
/*
179
fz_layout_document: Layout reflowable document types.
180
181
w, h: Page size in points.
182
em: Default font size in points.
183
*/
184
void fz_layout_document(fz_context *ctx, fz_document *doc, float w, float h, float em);
185
186
/*
187
fz_count_pages: Return the number of pages in document
188
189
May return 0 for documents with no pages.
190
*/
191
int fz_count_pages(fz_context *ctx, fz_document *doc);
192
193
/*
194
fz_load_page: Load a page.
195
196
After fz_load_page is it possible to retrieve the size of the
197
page using fz_bound_page, or to render the page using
198
fz_run_page_*. Free the page by calling fz_drop_page.
199
200
number: page number, 0 is the first page of the document.
201
*/
202
fz_page *fz_load_page(fz_context *ctx, fz_document *doc, int number);
203
204
/*
205
fz_load_links: Load the list of links for a page.
206
207
Returns a linked list of all the links on the page, each with
208
its clickable region and link destination. Each link is
209
reference counted so drop and free the list of links by
210
calling fz_drop_link on the pointer return from fz_load_links.
211
212
page: Page obtained from fz_load_page.
213
*/
214
fz_link *fz_load_links(fz_context *ctx, fz_page *page);
215
216
/*
217
fz_new_page: Create and initialize a page struct.
218
*/
219
void *fz_new_page(fz_context *ctx, int size);
220
221
/*
222
fz_bound_page: Determine the size of a page at 72 dpi.
223
224
Does not throw exceptions.
225
*/
226
fz_rect *fz_bound_page(fz_context *ctx, fz_page *page, fz_rect *rect);
227
228
/*
229
fz_run_page: Run a page through a device.
230
231
page: Page obtained from fz_load_page.
232
233
dev: Device obtained from fz_new_*_device.
234
235
transform: Transform to apply to page. May include for example
236
scaling and rotation, see fz_scale, fz_rotate and fz_concat.
237
Set to fz_identity if no transformation is desired.
238
239
cookie: Communication mechanism between caller and library
240
rendering the page. Intended for multi-threaded applications,
241
while single-threaded applications set cookie to NULL. The
242
caller may abort an ongoing rendering of a page. Cookie also
243
communicates progress information back to the caller. The
244
fields inside cookie are continually updated while the page is
245
rendering.
246
*/
247
void fz_run_page(fz_context *ctx, fz_page *page, fz_device *dev, const fz_matrix *transform, fz_cookie *cookie);
248
249
/*
250
fz_run_page_contents: Run a page through a device. Just the main
251
page content, without the annotations, if any.
252
253
page: Page obtained from fz_load_page.
254
255
dev: Device obtained from fz_new_*_device.
256
257
transform: Transform to apply to page. May include for example
258
scaling and rotation, see fz_scale, fz_rotate and fz_concat.
259
Set to fz_identity if no transformation is desired.
260
261
cookie: Communication mechanism between caller and library
262
rendering the page. Intended for multi-threaded applications,
263
while single-threaded applications set cookie to NULL. The
264
caller may abort an ongoing rendering of a page. Cookie also
265
communicates progress information back to the caller. The
266
fields inside cookie are continually updated while the page is
267
rendering.
268
*/
269
void fz_run_page_contents(fz_context *ctx, fz_page *page, fz_device *dev, const fz_matrix *transform, fz_cookie *cookie);
270
271
/*
272
fz_run_annot: Run an annotation through a device.
273
274
page: Page obtained from fz_load_page.
275
276
annot: an annotation.
277
278
dev: Device obtained from fz_new_*_device.
279
280
transform: Transform to apply to page. May include for example
281
scaling and rotation, see fz_scale, fz_rotate and fz_concat.
282
Set to fz_identity if no transformation is desired.
283
284
cookie: Communication mechanism between caller and library
285
rendering the page. Intended for multi-threaded applications,
286
while single-threaded applications set cookie to NULL. The
287
caller may abort an ongoing rendering of a page. Cookie also
288
communicates progress information back to the caller. The
289
fields inside cookie are continually updated while the page is
290
rendering.
291
*/
292
void fz_run_annot(fz_context *ctx, fz_page *page, fz_annot *annot, fz_device *dev, const fz_matrix *transform, fz_cookie *cookie);
293
294
/*
295
fz_drop_page: Free a loaded page.
296
297
Does not throw exceptions.
298
*/
299
void fz_drop_page(fz_context *ctx, fz_page *page);
300
301
/*
302
fz_page_presentation: Get the presentation details for a given page.
303
304
duration: NULL, or a pointer to a place to set the page duration in
305
seconds. (Will be set to 0 if unspecified).
306
307
Returns: a pointer to a transition structure, or NULL if there isn't
308
one.
309
310
Does not throw exceptions.
311
*/
312
fz_transition *fz_page_presentation(fz_context *ctx, fz_page *page, float *duration);
313
314
/*
315
fz_has_permission: Check permission flags on document.
316
*/
317
int fz_has_permission(fz_context *ctx, fz_document *doc, fz_permission p);
318
319
/*
320
fz_lookup_metadata: Retrieve document meta data strings.
321
322
doc: The document to query.
323
324
key: Which meta data key to retrieve...
325
326
Basic information:
327
'format' -- Document format and version.
328
'encryption' -- Description of the encryption used.
329
330
From the document information dictionary:
331
'info:Title'
332
'info:Author'
333
'info:Subject'
334
'info:Keywords'
335
'info:Creator'
336
'info:Producer'
337
'info:CreationDate'
338
'info:ModDate'
339
340
buf: The buffer to hold the results (a nul-terminated UTF-8 string).
341
342
size: Size of 'buf'.
343
344
Returns the size of the output string (may be larger than 'size' if
345
the output was truncated), or -1 if the key is not recognized or found.
346
*/
347
int fz_lookup_metadata(fz_context *ctx, fz_document *doc, const char *key, char *buf, int size);
348
349
#define FZ_META_FORMAT "format"
350
#define FZ_META_ENCRYPTION "encryption"
351
352
#define FZ_META_INFO_AUTHOR "info:Author"
353
#define FZ_META_INFO_TITLE "info:Title"
354
355
#endif
356
357