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 
13 typedef struct fz_document fz_document;
14 typedef struct fz_document_handler fz_document_handler;
15 typedef struct fz_page fz_page;
16 typedef intptr_t fz_bookmark;
17 
18 /**
19 	Locations within the document are referred to in terms of
20 	chapter and page, rather than just a page number. For some
21 	documents (such as epub documents with large numbers of pages
22 	broken into many chapters) this can make navigation much faster
23 	as only the required chapter needs to be decoded at a time.
24 */
25 typedef struct
26 {
27 	int chapter;
28 	int page;
29 } fz_location;
30 
31 /**
32 	Simple constructor for fz_locations.
33 */
fz_make_location(int chapter,int page)34 static inline fz_location fz_make_location(int chapter, int page)
35 {
36 	fz_location loc = { chapter, page };
37 	return loc;
38 }
39 
40 enum
41 {
42 	/* 6in at 4:3 */
43 	FZ_LAYOUT_KINDLE_W = 260,
44 	FZ_LAYOUT_KINDLE_H = 346,
45 	FZ_LAYOUT_KINDLE_EM = 9,
46 
47 	/* 4.25 x 6.87 in */
48 	FZ_LAYOUT_US_POCKET_W = 306,
49 	FZ_LAYOUT_US_POCKET_H = 495,
50 	FZ_LAYOUT_US_POCKET_EM = 10,
51 
52 	/* 5.5 x 8.5 in */
53 	FZ_LAYOUT_US_TRADE_W = 396,
54 	FZ_LAYOUT_US_TRADE_H = 612,
55 	FZ_LAYOUT_US_TRADE_EM = 11,
56 
57 	/* 110 x 178 mm */
58 	FZ_LAYOUT_UK_A_FORMAT_W = 312,
59 	FZ_LAYOUT_UK_A_FORMAT_H = 504,
60 	FZ_LAYOUT_UK_A_FORMAT_EM = 10,
61 
62 	/* 129 x 198 mm */
63 	FZ_LAYOUT_UK_B_FORMAT_W = 366,
64 	FZ_LAYOUT_UK_B_FORMAT_H = 561,
65 	FZ_LAYOUT_UK_B_FORMAT_EM = 10,
66 
67 	/* 135 x 216 mm */
68 	FZ_LAYOUT_UK_C_FORMAT_W = 382,
69 	FZ_LAYOUT_UK_C_FORMAT_H = 612,
70 	FZ_LAYOUT_UK_C_FORMAT_EM = 11,
71 
72 	/* 148 x 210 mm */
73 	FZ_LAYOUT_A5_W = 420,
74 	FZ_LAYOUT_A5_H = 595,
75 	FZ_LAYOUT_A5_EM = 11,
76 
77 	/* Default to A5 */
78 	FZ_DEFAULT_LAYOUT_W = FZ_LAYOUT_A5_W,
79 	FZ_DEFAULT_LAYOUT_H = FZ_LAYOUT_A5_H,
80 	FZ_DEFAULT_LAYOUT_EM = FZ_LAYOUT_A5_EM,
81 };
82 
83 typedef enum
84 {
85 	FZ_PERMISSION_PRINT = 'p',
86 	FZ_PERMISSION_COPY = 'c',
87 	FZ_PERMISSION_EDIT = 'e',
88 	FZ_PERMISSION_ANNOTATE = 'n',
89 }
90 fz_permission;
91 
92 /**
93 	Type for a function to be called when
94 	the reference count for the fz_document drops to 0. The
95 	implementation should release any resources held by the
96 	document. The actual document pointer will be freed by the
97 	caller.
98 */
99 typedef void (fz_document_drop_fn)(fz_context *ctx, fz_document *doc);
100 
101 /**
102 	Type for a function to be
103 	called to enquire whether the document needs a password
104 	or not. See fz_needs_password for more information.
105 */
106 typedef int (fz_document_needs_password_fn)(fz_context *ctx, fz_document *doc);
107 
108 /**
109 	Type for a function to be
110 	called to attempt to authenticate a password. See
111 	fz_authenticate_password for more information.
112 */
113 typedef int (fz_document_authenticate_password_fn)(fz_context *ctx, fz_document *doc, const char *password);
114 
115 /**
116 	Type for a function to be
117 	called to see if a document grants a certain permission. See
118 	fz_document_has_permission for more information.
119 */
120 typedef int (fz_document_has_permission_fn)(fz_context *ctx, fz_document *doc, fz_permission permission);
121 
122 /**
123 	Type for a function to be called to
124 	load the outlines for a document. See fz_document_load_outline
125 	for more information.
126 */
127 typedef fz_outline *(fz_document_load_outline_fn)(fz_context *ctx, fz_document *doc);
128 
129 /**
130 	Type for a function to be called to lay
131 	out a document. See fz_layout_document for more information.
132 */
133 typedef void (fz_document_layout_fn)(fz_context *ctx, fz_document *doc, float w, float h, float em);
134 
135 /**
136 	Type for a function to be called to
137 	resolve an internal link to a location (chapter/page number
138 	tuple). See fz_resolve_link for more information.
139 */
140 typedef fz_location (fz_document_resolve_link_fn)(fz_context *ctx, fz_document *doc, const char *uri, float *xp, float *yp);
141 
142 /**
143 	Type for a function to be called to
144 	count the number of chapters in a document. See
145 	fz_count_chapters for more information.
146 */
147 typedef int (fz_document_count_chapters_fn)(fz_context *ctx, fz_document *doc);
148 
149 /**
150 	Type for a function to be called to
151 	count the number of pages in a document. See fz_count_pages for
152 	more information.
153 */
154 typedef int (fz_document_count_pages_fn)(fz_context *ctx, fz_document *doc, int chapter);
155 
156 /**
157 	Type for a function to load a given
158 	page from a document. See fz_load_page for more information.
159 */
160 typedef fz_page *(fz_document_load_page_fn)(fz_context *ctx, fz_document *doc, int chapter, int page);
161 
162 /**
163 	Type for a function to query
164 	a documents metadata. See fz_lookup_metadata for more
165 	information.
166 */
167 typedef int (fz_document_lookup_metadata_fn)(fz_context *ctx, fz_document *doc, const char *key, char *buf, int size);
168 
169 /**
170 	Return output intent color space if it exists
171 */
172 typedef fz_colorspace *(fz_document_output_intent_fn)(fz_context *ctx, fz_document *doc);
173 
174 /**
175 	Write document accelerator data
176 */
177 typedef void (fz_document_output_accelerator_fn)(fz_context *ctx, fz_document *doc, fz_output *out);
178 
179 /**
180 	Type for a function to make
181 	a bookmark. See fz_make_bookmark for more information.
182 */
183 typedef fz_bookmark (fz_document_make_bookmark_fn)(fz_context *ctx, fz_document *doc, fz_location loc);
184 
185 /**
186 	Type for a function to lookup a bookmark.
187 	See fz_lookup_bookmark for more information.
188 */
189 typedef fz_location (fz_document_lookup_bookmark_fn)(fz_context *ctx, fz_document *doc, fz_bookmark mark);
190 
191 /**
192 	Type for a function to release all the
193 	resources held by a page. Called automatically when the
194 	reference count for that page reaches zero.
195 */
196 typedef void (fz_page_drop_page_fn)(fz_context *ctx, fz_page *page);
197 
198 /**
199 	Type for a function to return the
200 	bounding box of a page. See fz_bound_page for more
201 	information.
202 */
203 typedef fz_rect (fz_page_bound_page_fn)(fz_context *ctx, fz_page *page);
204 
205 /**
206 	Type for a function to run the
207 	contents of a page. See fz_run_page_contents for more
208 	information.
209 */
210 typedef void (fz_page_run_page_fn)(fz_context *ctx, fz_page *page, fz_device *dev, fz_matrix transform, fz_cookie *cookie);
211 
212 /**
213 	Type for a function to load the links
214 	from a page. See fz_load_links for more information.
215 */
216 typedef fz_link *(fz_page_load_links_fn)(fz_context *ctx, fz_page *page);
217 
218 /**
219 	Type for a function to
220 	obtain the details of how this page should be presented when
221 	in presentation mode. See fz_page_presentation for more
222 	information.
223 */
224 typedef fz_transition *(fz_page_page_presentation_fn)(fz_context *ctx, fz_page *page, fz_transition *transition, float *duration);
225 
226 /**
227 	Type for a function to enable/
228 	disable separations on a page. See fz_control_separation for
229 	more information.
230 */
231 typedef void (fz_page_control_separation_fn)(fz_context *ctx, fz_page *page, int separation, int disable);
232 
233 /**
234 	Type for a function to detect
235 	whether a given separation is enabled or disabled on a page.
236 	See FZ_SEPARATION_DISABLED for more information.
237 */
238 typedef int (fz_page_separation_disabled_fn)(fz_context *ctx, fz_page *page, int separation);
239 
240 /**
241 	Type for a function to retrieve
242 	details of separations on a page. See fz_get_separations
243 	for more information.
244 */
245 typedef fz_separations *(fz_page_separations_fn)(fz_context *ctx, fz_page *page);
246 
247 /**
248 	Type for a function to retrieve
249 	whether or not a given page uses overprint.
250 */
251 typedef int (fz_page_uses_overprint_fn)(fz_context *ctx, fz_page *page);
252 
253 /**
254 	Function type to open a document from a file.
255 
256 	filename: file to open
257 
258 	Pointer to opened document. Throws exception in case of error.
259 */
260 typedef fz_document *(fz_document_open_fn)(fz_context *ctx, const char *filename);
261 
262 /**
263 	Function type to open a
264 	document from a file.
265 
266 	stream: fz_stream to read document data from. Must be
267 	seekable for formats that require it.
268 
269 	Pointer to opened document. Throws exception in case of error.
270 */
271 typedef fz_document *(fz_document_open_with_stream_fn)(fz_context *ctx, fz_stream *stream);
272 
273 /**
274 	Function type to open a document from a
275 	file, with accelerator data.
276 
277 	filename: file to open
278 
279 	accel: accelerator file
280 
281 	Pointer to opened document. Throws exception in case of error.
282 */
283 typedef fz_document *(fz_document_open_accel_fn)(fz_context *ctx, const char *filename, const char *accel);
284 
285 /**
286 	Function type to open a document from a file,
287 	with accelerator data.
288 
289 	stream: fz_stream to read document data from. Must be
290 	seekable for formats that require it.
291 
292 	accel: fz_stream to read accelerator data from. Must be
293 	seekable for formats that require it.
294 
295 	Pointer to opened document. Throws exception in case of error.
296 */
297 typedef fz_document *(fz_document_open_accel_with_stream_fn)(fz_context *ctx, fz_stream *stream, fz_stream *accel);
298 
299 /**
300 	Recognize a document type from
301 	a magic string.
302 
303 	magic: string to recognise - typically a filename or mime
304 	type.
305 
306 	Returns a number between 0 (not recognized) and 100
307 	(fully recognized) based on how certain the recognizer
308 	is that this is of the required type.
309 */
310 typedef int (fz_document_recognize_fn)(fz_context *ctx, const char *magic);
311 
312 /**
313 	Register a handler for a document type.
314 
315 	handler: The handler to register.
316 */
317 void fz_register_document_handler(fz_context *ctx, const fz_document_handler *handler);
318 
319 /**
320 	Register handlers
321 	for all the standard document types supported in
322 	this build.
323 */
324 void fz_register_document_handlers(fz_context *ctx);
325 
326 /**
327 	Given a magic find a document handler that can handle a
328 	document of this type.
329 
330 	magic: Can be a filename extension (including initial period) or
331 	a mimetype.
332 */
333 const fz_document_handler *fz_recognize_document(fz_context *ctx, const char *magic);
334 
335 /**
336 	Open a document file and read its basic structure so pages and
337 	objects can be located. MuPDF will try to repair broken
338 	documents (without actually changing the file contents).
339 
340 	The returned fz_document is used when calling most other
341 	document related functions.
342 
343 	filename: a path to a file as it would be given to open(2).
344 */
345 fz_document *fz_open_document(fz_context *ctx, const char *filename);
346 
347 /**
348 	Open a document file and read its basic structure so pages and
349 	objects can be located. MuPDF will try to repair broken
350 	documents (without actually changing the file contents).
351 
352 	The returned fz_document is used when calling most other
353 	document related functions.
354 
355 	filename: a path to a file as it would be given to open(2).
356 */
357 fz_document *fz_open_accelerated_document(fz_context *ctx, const char *filename, const char *accel);
358 
359 /**
360 	Open a document using the specified stream object rather than
361 	opening a file on disk.
362 
363 	magic: a string used to detect document type; either a file name
364 	or mime-type.
365 */
366 fz_document *fz_open_document_with_stream(fz_context *ctx, const char *magic, fz_stream *stream);
367 
368 /**
369 	Open a document using the specified stream object rather than
370 	opening a file on disk.
371 
372 	magic: a string used to detect document type; either a file name
373 	or mime-type.
374 */
375 fz_document *fz_open_accelerated_document_with_stream(fz_context *ctx, const char *magic, fz_stream *stream, fz_stream *accel);
376 
377 /**
378 	Query if the document supports the saving of accelerator data.
379 */
380 int fz_document_supports_accelerator(fz_context *ctx, fz_document *doc);
381 
382 /**
383 	Save accelerator data for the document to a given file.
384 */
385 void fz_save_accelerator(fz_context *ctx, fz_document *doc, const char *accel);
386 
387 /**
388 	Output accelerator data for the document to a given output
389 	stream.
390 */
391 void fz_output_accelerator(fz_context *ctx, fz_document *doc, fz_output *accel);
392 
393 /**
394 	New documents are typically created by calls like
395 	foo_new_document(fz_context *ctx, ...). These work by
396 	deriving a new document type from fz_document, for instance:
397 	typedef struct { fz_document base; ...extras... } foo_document;
398 	These are allocated by calling
399 	fz_new_derived_document(ctx, foo_document)
400 */
401 void *fz_new_document_of_size(fz_context *ctx, int size);
402 #define fz_new_derived_document(C,M) ((M*)Memento_label(fz_new_document_of_size(C, sizeof(M)), #M))
403 
404 /**
405 	Increment the document reference count. The same pointer is
406 	returned.
407 
408 	Never throws exceptions.
409 */
410 fz_document *fz_keep_document(fz_context *ctx, fz_document *doc);
411 
412 /**
413 	Decrement the document reference count. When the reference
414 	count reaches 0, the document and all it's references are
415 	freed.
416 
417 	Never throws exceptions.
418 */
419 void fz_drop_document(fz_context *ctx, fz_document *doc);
420 
421 /**
422 	Check if a document is encrypted with a
423 	non-blank password.
424 */
425 int fz_needs_password(fz_context *ctx, fz_document *doc);
426 
427 /**
428 	Test if the given password can decrypt the document.
429 
430 	password: The password string to be checked. Some document
431 	specifications do not specify any particular text encoding, so
432 	neither do we.
433 
434 	Returns 0 for failure to authenticate, non-zero for success.
435 
436 	For PDF documents, further information can be given by examining
437 	the bits in the return code.
438 
439 		Bit 0 => No password required
440 		Bit 1 => User password authenticated
441 		Bit 2 => Owner password authenticated
442 */
443 int fz_authenticate_password(fz_context *ctx, fz_document *doc, const char *password);
444 
445 /**
446 	Load the hierarchical document outline.
447 
448 	Should be freed by fz_drop_outline.
449 */
450 fz_outline *fz_load_outline(fz_context *ctx, fz_document *doc);
451 
452 /**
453 	Is the document reflowable.
454 
455 	Returns 1 to indicate reflowable documents, otherwise 0.
456 */
457 int fz_is_document_reflowable(fz_context *ctx, fz_document *doc);
458 
459 /**
460 	Layout reflowable document types.
461 
462 	w, h: Page size in points.
463 	em: Default font size in points.
464 */
465 void fz_layout_document(fz_context *ctx, fz_document *doc, float w, float h, float em);
466 
467 /**
468 	Create a bookmark for the given page, which can be used to find
469 	the same location after the document has been laid out with
470 	different parameters.
471 */
472 fz_bookmark fz_make_bookmark(fz_context *ctx, fz_document *doc, fz_location loc);
473 
474 /**
475 	Find a bookmark and return its page number.
476 */
477 fz_location fz_lookup_bookmark(fz_context *ctx, fz_document *doc, fz_bookmark mark);
478 
479 /**
480 	Return the number of pages in document
481 
482 	May return 0 for documents with no pages.
483 */
484 int fz_count_pages(fz_context *ctx, fz_document *doc);
485 
486 /**
487 	Resolve an internal link to a page number.
488 
489 	xp, yp: Pointer to store coordinate of destination on the page.
490 
491 	Returns (-1,-1) if the URI cannot be resolved.
492 */
493 fz_location fz_resolve_link(fz_context *ctx, fz_document *doc, const char *uri, float *xp, float *yp);
494 
495 /**
496 	Function to get the location for the last page in the document.
497 	Using this can be far more efficient in some cases than calling
498 	fz_count_pages and using the page number.
499 */
500 fz_location fz_last_page(fz_context *ctx, fz_document *doc);
501 
502 /**
503 	Function to get the location of the next page (allowing for the
504 	end of chapters etc). If at the end of the document, returns the
505 	current location.
506 */
507 fz_location fz_next_page(fz_context *ctx, fz_document *doc, fz_location loc);
508 
509 /**
510 	Function to get the location of the previous page (allowing for
511 	the end of chapters etc). If already at the start of the
512 	document, returns the current page.
513 */
514 fz_location fz_previous_page(fz_context *ctx, fz_document *doc, fz_location loc);
515 
516 /**
517 	Clamps a location into valid chapter/page range. (First clamps
518 	the chapter into range, then the page into range).
519 */
520 fz_location fz_clamp_location(fz_context *ctx, fz_document *doc, fz_location loc);
521 
522 /**
523 	Converts from page number to chapter+page. This may cause many
524 	chapters to be laid out in order to calculate the number of
525 	pages within those chapters.
526 */
527 fz_location fz_location_from_page_number(fz_context *ctx, fz_document *doc, int number);
528 
529 /**
530 	Converts from chapter+page to page number. This may cause many
531 	chapters to be laid out in order to calculate the number of
532 	pages within those chapters.
533 */
534 int fz_page_number_from_location(fz_context *ctx, fz_document *doc, fz_location loc);
535 
536 /**
537 	Load a given page number from a document. This may be much less
538 	efficient than loading by location (chapter+page) for some
539 	document types.
540 */
541 fz_page *fz_load_page(fz_context *ctx, fz_document *doc, int number);
542 
543 /**
544 	Return the number of chapters in the document.
545 	At least 1.
546 */
547 int fz_count_chapters(fz_context *ctx, fz_document *doc);
548 
549 /**
550 	Return the number of pages in a chapter.
551 	May return 0.
552 */
553 int fz_count_chapter_pages(fz_context *ctx, fz_document *doc, int chapter);
554 
555 /**
556 	Load a page.
557 
558 	After fz_load_page is it possible to retrieve the size of the
559 	page using fz_bound_page, or to render the page using
560 	fz_run_page_*. Free the page by calling fz_drop_page.
561 
562 	chapter: chapter number, 0 is the first chapter of the document.
563 	number: page number, 0 is the first page of the chapter.
564 */
565 fz_page *fz_load_chapter_page(fz_context *ctx, fz_document *doc, int chapter, int page);
566 
567 /**
568 	Load the list of links for a page.
569 
570 	Returns a linked list of all the links on the page, each with
571 	its clickable region and link destination. Each link is
572 	reference counted so drop and free the list of links by
573 	calling fz_drop_link on the pointer return from fz_load_links.
574 
575 	page: Page obtained from fz_load_page.
576 */
577 fz_link *fz_load_links(fz_context *ctx, fz_page *page);
578 
579 /**
580 	Different document types will be implemented by deriving from
581 	fz_page. This macro allocates such derived structures, and
582 	initialises the base sections.
583 */
584 fz_page *fz_new_page_of_size(fz_context *ctx, int size);
585 #define fz_new_derived_page(CTX,TYPE) \
586 	((TYPE *)Memento_label(fz_new_page_of_size(CTX,sizeof(TYPE)),#TYPE))
587 
588 /**
589 	Determine the size of a page at 72 dpi.
590 */
591 fz_rect fz_bound_page(fz_context *ctx, fz_page *page);
592 
593 /**
594 	Run a page through a device.
595 
596 	page: Page obtained from fz_load_page.
597 
598 	dev: Device obtained from fz_new_*_device.
599 
600 	transform: Transform to apply to page. May include for example
601 	scaling and rotation, see fz_scale, fz_rotate and fz_concat.
602 	Set to fz_identity if no transformation is desired.
603 
604 	cookie: Communication mechanism between caller and library
605 	rendering the page. Intended for multi-threaded applications,
606 	while single-threaded applications set cookie to NULL. The
607 	caller may abort an ongoing rendering of a page. Cookie also
608 	communicates progress information back to the caller. The
609 	fields inside cookie are continually updated while the page is
610 	rendering.
611 */
612 void fz_run_page(fz_context *ctx, fz_page *page, fz_device *dev, fz_matrix transform, fz_cookie *cookie);
613 
614 /**
615 	Run a page through a device. Just the main
616 	page content, without the annotations, if any.
617 
618 	page: Page obtained from fz_load_page.
619 
620 	dev: Device obtained from fz_new_*_device.
621 
622 	transform: Transform to apply to page. May include for example
623 	scaling and rotation, see fz_scale, fz_rotate and fz_concat.
624 	Set to fz_identity if no transformation is desired.
625 
626 	cookie: Communication mechanism between caller and library
627 	rendering the page. Intended for multi-threaded applications,
628 	while single-threaded applications set cookie to NULL. The
629 	caller may abort an ongoing rendering of a page. Cookie also
630 	communicates progress information back to the caller. The
631 	fields inside cookie are continually updated while the page is
632 	rendering.
633 */
634 void fz_run_page_contents(fz_context *ctx, fz_page *page, fz_device *dev, fz_matrix transform, fz_cookie *cookie);
635 
636 /**
637 	Run the annotations on a page through a device.
638 */
639 void fz_run_page_annots(fz_context *ctx, fz_page *page, fz_device *dev, fz_matrix transform, fz_cookie *cookie);
640 
641 /**
642 	Run the widgets on a page through a device.
643 */
644 void fz_run_page_widgets(fz_context *ctx, fz_page *page, fz_device *dev, fz_matrix transform, fz_cookie *cookie);
645 
646 /**
647 	Increment the reference count for the page. Returns the same
648 	pointer.
649 
650 	Never throws exceptions.
651 */
652 fz_page *fz_keep_page(fz_context *ctx, fz_page *page);
653 
654 /**
655 	Decrements the reference count for the page. When the reference
656 	count hits 0, the page and its references are freed.
657 
658 	Never throws exceptions.
659 */
660 void fz_drop_page(fz_context *ctx, fz_page *page);
661 
662 /**
663 	Get the presentation details for a given page.
664 
665 	transition: A pointer to a transition struct to fill out.
666 
667 	duration: A pointer to a place to set the page duration in
668 	seconds. Will be set to 0 if no transition is specified for the
669 	page.
670 
671 	Returns: a pointer to the transition structure, or NULL if there
672 	is no transition specified for the page.
673 */
674 fz_transition *fz_page_presentation(fz_context *ctx, fz_page *page, fz_transition *transition, float *duration);
675 
676 /**
677 	Check permission flags on document.
678 */
679 int fz_has_permission(fz_context *ctx, fz_document *doc, fz_permission p);
680 
681 /**
682 	Retrieve document meta data strings.
683 
684 	doc: The document to query.
685 
686 	key: Which meta data key to retrieve...
687 
688 	Basic information:
689 		'format'	-- Document format and version.
690 		'encryption'	-- Description of the encryption used.
691 
692 	From the document information dictionary:
693 		'info:Title'
694 		'info:Author'
695 		'info:Subject'
696 		'info:Keywords'
697 		'info:Creator'
698 		'info:Producer'
699 		'info:CreationDate'
700 		'info:ModDate'
701 
702 	buf: The buffer to hold the results (a nul-terminated UTF-8
703 	string).
704 
705 	size: Size of 'buf'.
706 
707 	Returns the number of bytes need to store the string plus terminator
708 	(will be larger than 'size' if the output was truncated), or -1 if the
709 	key is not recognized or found.
710 */
711 int fz_lookup_metadata(fz_context *ctx, fz_document *doc, const char *key, char *buf, int size);
712 
713 #define FZ_META_FORMAT "format"
714 #define FZ_META_ENCRYPTION "encryption"
715 
716 #define FZ_META_INFO_AUTHOR "info:Author"
717 #define FZ_META_INFO_TITLE "info:Title"
718 #define FZ_META_INFO_CREATOR "info:Creator"
719 #define FZ_META_INFO_PRODUCER "info:Producer"
720 
721 /**
722 	Find the output intent colorspace if the document has defined
723 	one.
724 
725 	Returns a borrowed reference that should not be dropped, unless
726 	it is kept first.
727 */
728 fz_colorspace *fz_document_output_intent(fz_context *ctx, fz_document *doc);
729 
730 /**
731 	Get the separations details for a page.
732 	This will be NULL, unless the format specifically supports
733 	separations (such as PDF files). May be NULL even
734 	so, if there are no separations on a page.
735 
736 	Returns a reference that must be dropped.
737 */
738 fz_separations *fz_page_separations(fz_context *ctx, fz_page *page);
739 
740 /**
741 	Query if a given page requires overprint.
742 */
743 int fz_page_uses_overprint(fz_context *ctx, fz_page *page);
744 
745 /* Implementation details: subject to change. */
746 
747 /**
748 	Structure definition is public so other classes can
749 	derive from it. Do not access the members directly.
750 */
751 struct fz_page
752 {
753 	int refs;
754 	int chapter; /* chapter number */
755 	int number; /* page number in chapter */
756 	int incomplete; /* incomplete from progressive loading; don't cache! */
757 	fz_page_drop_page_fn *drop_page;
758 	fz_page_bound_page_fn *bound_page;
759 	fz_page_run_page_fn *run_page_contents;
760 	fz_page_run_page_fn *run_page_annots;
761 	fz_page_run_page_fn *run_page_widgets;
762 	fz_page_load_links_fn *load_links;
763 	fz_page_page_presentation_fn *page_presentation;
764 	fz_page_control_separation_fn *control_separation;
765 	fz_page_separation_disabled_fn *separation_disabled;
766 	fz_page_separations_fn *separations;
767 	fz_page_uses_overprint_fn *overprint;
768 	fz_page **prev, *next; /* linked list of currently open pages */
769 };
770 
771 /**
772 	Structure definition is public so other classes can
773 	derive from it. Callers should not access the members
774 	directly, though implementations will need initialize
775 	functions directly.
776 */
777 struct fz_document
778 {
779 	int refs;
780 	fz_document_drop_fn *drop_document;
781 	fz_document_needs_password_fn *needs_password;
782 	fz_document_authenticate_password_fn *authenticate_password;
783 	fz_document_has_permission_fn *has_permission;
784 	fz_document_load_outline_fn *load_outline;
785 	fz_document_layout_fn *layout;
786 	fz_document_make_bookmark_fn *make_bookmark;
787 	fz_document_lookup_bookmark_fn *lookup_bookmark;
788 	fz_document_resolve_link_fn *resolve_link;
789 	fz_document_count_chapters_fn *count_chapters;
790 	fz_document_count_pages_fn *count_pages;
791 	fz_document_load_page_fn *load_page;
792 	fz_document_lookup_metadata_fn *lookup_metadata;
793 	fz_document_output_intent_fn *get_output_intent;
794 	fz_document_output_accelerator_fn *output_accelerator;
795 	int did_layout;
796 	int is_reflowable;
797 	fz_page *open; /* linked list of currently open pages */
798 };
799 
800 struct fz_document_handler
801 {
802 	fz_document_recognize_fn *recognize;
803 	fz_document_open_fn *open;
804 	fz_document_open_with_stream_fn *open_with_stream;
805 	const char **extensions;
806 	const char **mimetypes;
807 	fz_document_open_accel_fn *open_accel;
808 	fz_document_open_accel_with_stream_fn *open_accel_with_stream;
809 };
810 
811 
812 #endif
813