comparison mupdf-source/include/mupdf/pdf/page.h @ 2:b50eed0cc0ef upstream

ADD: MuPDF v1.26.7: the MuPDF source as downloaded by a default build of PyMuPDF 1.26.4. The directory name has changed: no version number in the expanded directory now.
author Franz Glasner <fzglas.hg@dom66.de>
date Mon, 15 Sep 2025 11:43:07 +0200
parents
children
comparison
equal deleted inserted replaced
1:1d09e1dec1d9 2:b50eed0cc0ef
1 // Copyright (C) 2004-2024 Artifex Software, Inc.
2 //
3 // This file is part of MuPDF.
4 //
5 // MuPDF is free software: you can redistribute it and/or modify it under the
6 // terms of the GNU Affero General Public License as published by the Free
7 // Software Foundation, either version 3 of the License, or (at your option)
8 // any later version.
9 //
10 // MuPDF is distributed in the hope that it will be useful, but WITHOUT ANY
11 // WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12 // FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
13 // details.
14 //
15 // You should have received a copy of the GNU Affero General Public License
16 // along with MuPDF. If not, see <https://www.gnu.org/licenses/agpl-3.0.en.html>
17 //
18 // Alternative licensing terms are available from the licensor.
19 // For commercial licensing, see <https://www.artifex.com/> or contact
20 // Artifex Software, Inc., 39 Mesa Street, Suite 108A, San Francisco,
21 // CA 94129, USA, for further information.
22
23 #ifndef MUPDF_PDF_PAGE_H
24 #define MUPDF_PDF_PAGE_H
25
26 #include "mupdf/pdf/interpret.h"
27
28 pdf_page *pdf_keep_page(fz_context *ctx, pdf_page *page);
29 void pdf_drop_page(fz_context *ctx, pdf_page *page);
30
31 int pdf_lookup_page_number(fz_context *ctx, pdf_document *doc, pdf_obj *pageobj);
32 int pdf_count_pages(fz_context *ctx, pdf_document *doc);
33 int pdf_count_pages_imp(fz_context *ctx, fz_document *doc, int chapter);
34 pdf_obj *pdf_lookup_page_obj(fz_context *ctx, pdf_document *doc, int needle);
35 pdf_obj *pdf_lookup_page_loc(fz_context *ctx, pdf_document *doc, int needle, pdf_obj **parentp, int *indexp);
36
37 /*
38 Cache the page tree for fast forward/reverse page lookups.
39
40 No longer required. This is a No Op, now as page tree
41 maps are loaded automatically 'just in time'.
42 */
43 void pdf_load_page_tree(fz_context *ctx, pdf_document *doc);
44
45 /*
46 Discard the page tree maps.
47
48 No longer required. This is a No Op, now as page tree
49 maps are discarded automatically 'just in time'.
50 */
51 void pdf_drop_page_tree(fz_context *ctx, pdf_document *doc);
52
53 /*
54 Internal function used to drop the page tree.
55
56 Library users should not call this directly.
57 */
58 void pdf_drop_page_tree_internal(fz_context *ctx, pdf_document *doc);
59
60 /*
61 Make page self sufficient.
62
63 Copy any inheritable page keys into the actual page object, removing
64 any dependencies on the page tree parents.
65 */
66 void pdf_flatten_inheritable_page_items(fz_context *ctx, pdf_obj *page);
67
68 /*
69 Load a page and its resources.
70
71 Locates the page in the PDF document and loads the page and its
72 resources. After pdf_load_page is it possible to retrieve the size
73 of the page using pdf_bound_page, or to render the page using
74 pdf_run_page_*.
75
76 number: page number, where 0 is the first page of the document.
77 */
78 pdf_page *pdf_load_page(fz_context *ctx, pdf_document *doc, int number);
79
80 /*
81 Internal function to perform pdf_load_page.
82
83 Do not call this directly.
84 */
85 fz_page *pdf_load_page_imp(fz_context *ctx, fz_document *doc, int chapter, int number);
86
87 /*
88 Enquire as to whether a given page uses transparency or not.
89 */
90 int pdf_page_has_transparency(fz_context *ctx, pdf_page *page);
91
92 /*
93 Fetch the given box for a page, together with a transform that converts
94 from fitz coords to PDF coords.
95
96 pageobj: The object that represents the page.
97
98 outbox: If non-NULL, this will be filled in with the requested box
99 in fitz coordinates.
100
101 outctm: A transform to map from fitz page space to PDF page space.
102
103 box: Which box to return.
104 */
105 void pdf_page_obj_transform_box(fz_context *ctx, pdf_obj *pageobj, fz_rect *outbox, fz_matrix *out, fz_box_type box);
106
107 /*
108 As for pdf_page_obj_transform_box, always requesting the
109 cropbox.
110 */
111 void pdf_page_obj_transform(fz_context *ctx, pdf_obj *pageobj, fz_rect *outbox, fz_matrix *outctm);
112
113 /*
114 As for pdf_page_obj_transform_box, but working from a pdf_page
115 object rather than the pdf_obj representing the page.
116 */
117 void pdf_page_transform_box(fz_context *ctx, pdf_page *page, fz_rect *mediabox, fz_matrix *ctm, fz_box_type box);
118
119 /*
120 As for pdf_page_transform_box, always requesting the
121 cropbox.
122 */
123 void pdf_page_transform(fz_context *ctx, pdf_page *page, fz_rect *mediabox, fz_matrix *ctm);
124
125 /*
126 Find the pdf object that represents the resources dictionary
127 for a page.
128
129 This is a borrowed pointer that the caller should pdf_keep_obj
130 if. This may be NULL.
131 */
132 pdf_obj *pdf_page_resources(fz_context *ctx, pdf_page *page);
133
134 /*
135 Find the pdf object that represents the page contents
136 for a page.
137
138 This is a borrowed pointer that the caller should pdf_keep_obj
139 if. This may be NULL.
140 */
141 pdf_obj *pdf_page_contents(fz_context *ctx, pdf_page *page);
142
143 /*
144 Find the pdf object that represents the transparency group
145 for a page.
146
147 This is a borrowed pointer that the caller should pdf_keep_obj
148 if. This may be NULL.
149 */
150 pdf_obj *pdf_page_group(fz_context *ctx, pdf_page *page);
151
152 /*
153 Modify the page boxes (using fitz space coordinates).
154
155 Note that changing the CropBox will change the fitz coordinate space mapping,
156 invalidating all bounding boxes previously acquired.
157 */
158 void pdf_set_page_box(fz_context *ctx, pdf_page *page, fz_box_type box, fz_rect rect);
159
160 /*
161 Get the separation details for a page.
162 */
163 fz_separations *pdf_page_separations(fz_context *ctx, pdf_page *page);
164
165 pdf_ocg_descriptor *pdf_read_ocg(fz_context *ctx, pdf_document *doc);
166 void pdf_drop_ocg(fz_context *ctx, pdf_document *doc);
167 int pdf_is_ocg_hidden(fz_context *ctx, pdf_document *doc, pdf_obj *rdb, const char *usage, pdf_obj *ocg);
168
169 fz_link *pdf_load_links(fz_context *ctx, pdf_page *page);
170
171 /*
172 Determine the size of a page.
173
174 Determine the page size in points, taking page rotation
175 into account. The page size is taken to be the crop box if it
176 exists (visible area after cropping), otherwise the media box will
177 be used (possibly including printing marks).
178 */
179 fz_rect pdf_bound_page(fz_context *ctx, pdf_page *page, fz_box_type box);
180
181 /*
182 Interpret a loaded page and render it on a device.
183
184 page: A page loaded by pdf_load_page.
185
186 dev: Device used for rendering, obtained from fz_new_*_device.
187
188 ctm: A transformation matrix applied to the objects on the page,
189 e.g. to scale or rotate the page contents as desired.
190 */
191 void pdf_run_page(fz_context *ctx, pdf_page *page, fz_device *dev, fz_matrix ctm, fz_cookie *cookie);
192
193 /*
194 Interpret a loaded page and render it on a device.
195
196 page: A page loaded by pdf_load_page.
197
198 dev: Device used for rendering, obtained from fz_new_*_device.
199
200 ctm: A transformation matrix applied to the objects on the page,
201 e.g. to scale or rotate the page contents as desired.
202
203 usage: The 'usage' for displaying the file (typically
204 'View', 'Print' or 'Export'). NULL means 'View'.
205
206 cookie: A pointer to an optional fz_cookie structure that can be used
207 to track progress, collect errors etc.
208 */
209 void pdf_run_page_with_usage(fz_context *ctx, pdf_page *page, fz_device *dev, fz_matrix ctm, const char *usage, fz_cookie *cookie);
210
211 /*
212 Interpret a loaded page and render it on a device.
213 Just the main page contents without the annotations
214
215 page: A page loaded by pdf_load_page.
216
217 dev: Device used for rendering, obtained from fz_new_*_device.
218
219 ctm: A transformation matrix applied to the objects on the page,
220 e.g. to scale or rotate the page contents as desired.
221 */
222 void pdf_run_page_contents(fz_context *ctx, pdf_page *page, fz_device *dev, fz_matrix ctm, fz_cookie *cookie);
223 void pdf_run_page_annots(fz_context *ctx, pdf_page *page, fz_device *dev, fz_matrix ctm, fz_cookie *cookie);
224 void pdf_run_page_widgets(fz_context *ctx, pdf_page *page, fz_device *dev, fz_matrix ctm, fz_cookie *cookie);
225 void pdf_run_page_contents_with_usage(fz_context *ctx, pdf_page *page, fz_device *dev, fz_matrix ctm, const char *usage, fz_cookie *cookie);
226 void pdf_run_page_annots_with_usage(fz_context *ctx, pdf_page *page, fz_device *dev, fz_matrix ctm, const char *usage, fz_cookie *cookie);
227 void pdf_run_page_widgets_with_usage(fz_context *ctx, pdf_page *page, fz_device *dev, fz_matrix ctm, const char *usage, fz_cookie *cookie);
228
229 void pdf_filter_page_contents(fz_context *ctx, pdf_document *doc, pdf_page *page, pdf_filter_options *options);
230 void pdf_filter_annot_contents(fz_context *ctx, pdf_document *doc, pdf_annot *annot, pdf_filter_options *options);
231
232 fz_pixmap *pdf_new_pixmap_from_page_contents_with_usage(fz_context *ctx, pdf_page *page, fz_matrix ctm, fz_colorspace *cs, int alpha, const char *usage, fz_box_type box);
233 fz_pixmap *pdf_new_pixmap_from_page_with_usage(fz_context *ctx, pdf_page *page, fz_matrix ctm, fz_colorspace *cs, int alpha, const char *usage, fz_box_type box);
234 fz_pixmap *pdf_new_pixmap_from_page_contents_with_separations_and_usage(fz_context *ctx, pdf_page *page, fz_matrix ctm, fz_colorspace *cs, fz_separations *seps, int alpha, const char *usage, fz_box_type box);
235 fz_pixmap *pdf_new_pixmap_from_page_with_separations_and_usage(fz_context *ctx, pdf_page *page, fz_matrix ctm, fz_colorspace *cs, fz_separations *seps, int alpha, const char *usage, fz_box_type box);
236
237 enum {
238 /* Do not change images at all */
239 PDF_REDACT_IMAGE_NONE,
240
241 /* If the image intrudes across the redaction region (even if clipped),
242 * remove it. */
243 PDF_REDACT_IMAGE_REMOVE,
244
245 /* If the image intrudes across the redaction region (even if clipped),
246 * replace the bit that intrudes with black pixels. */
247 PDF_REDACT_IMAGE_PIXELS,
248
249 /* If the image, when clipped, intrudes across the redaction
250 * region, remove it completely. Note: clipped is a rough estimate
251 * based on the bbox of clipping paths.
252 *
253 * Essentially this says "remove any image that has visible parts
254 * that extend into the redaction region".
255 *
256 * This method can effectively 'leak' invisible information during
257 * the redaction phase, so should be used with caution.
258 */
259 PDF_REDACT_IMAGE_REMOVE_UNLESS_INVISIBLE
260 };
261
262 enum {
263 PDF_REDACT_LINE_ART_NONE,
264 PDF_REDACT_LINE_ART_REMOVE_IF_COVERED,
265 PDF_REDACT_LINE_ART_REMOVE_IF_TOUCHED
266 };
267
268 enum {
269 /* Remove any text that overlaps with the redaction region,
270 * however slightly. This is the default option, and is the
271 * correct option for secure behaviour. */
272 PDF_REDACT_TEXT_REMOVE,
273 /* Do not remove any text at all as part of this redaction
274 * operation. Using this option is INSECURE! Use at your own
275 * risk. */
276 PDF_REDACT_TEXT_NONE
277 };
278
279 typedef struct
280 {
281 int black_boxes;
282 int image_method;
283 int line_art;
284 int text;
285 } pdf_redact_options;
286
287 int pdf_redact_page(fz_context *ctx, pdf_document *doc, pdf_page *page, pdf_redact_options *opts);
288
289 fz_transition *pdf_page_presentation(fz_context *ctx, pdf_page *page, fz_transition *transition, float *duration);
290
291 fz_default_colorspaces *pdf_load_default_colorspaces(fz_context *ctx, pdf_document *doc, pdf_page *page);
292
293 void pdf_clip_page(fz_context *ctx, pdf_page *page, fz_rect *clip);
294
295 /*
296 Update default colorspaces for an xobject.
297 */
298 fz_default_colorspaces *pdf_update_default_colorspaces(fz_context *ctx, fz_default_colorspaces *old_cs, pdf_obj *res);
299
300 /*
301 * Page tree, pages and related objects
302 */
303
304 struct pdf_page
305 {
306 fz_page super;
307 pdf_document *doc; /* type alias for super.doc */
308 pdf_obj *obj;
309
310 int transparency;
311 int overprint;
312
313 fz_link *links;
314 pdf_annot *annots, **annot_tailp;
315 pdf_annot *widgets, **widget_tailp;
316 };
317
318 /* Keep pdf_page, pdf_annot, and pdf_link structs in sync with underlying pdf objects. */
319 void pdf_sync_open_pages(fz_context *ctx, pdf_document *doc);
320 void pdf_sync_page(fz_context *ctx, pdf_page *page);
321 void pdf_sync_links(fz_context *ctx, pdf_page *page);
322 void pdf_sync_annots(fz_context *ctx, pdf_page *page);
323 void pdf_nuke_page(fz_context *ctx, pdf_page *page);
324 void pdf_nuke_links(fz_context *ctx, pdf_page *page);
325 void pdf_nuke_annots(fz_context *ctx, pdf_page *page);
326
327 #endif