comparison mupdf-source/include/mupdf/fitz/writer.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-2025 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_FITZ_WRITER_H
24 #define MUPDF_FITZ_WRITER_H
25
26 #include "mupdf/fitz/system.h"
27 #include "mupdf/fitz/context.h"
28 #include "mupdf/fitz/output.h"
29 #include "mupdf/fitz/document.h"
30 #include "mupdf/fitz/device.h"
31
32 typedef struct fz_document_writer fz_document_writer;
33
34 /**
35 Function type to start
36 the process of writing a page to a document.
37
38 mediabox: page size rectangle in points.
39
40 Returns a fz_device to write page contents to.
41 */
42 typedef fz_device *(fz_document_writer_begin_page_fn)(fz_context *ctx, fz_document_writer *wri, fz_rect mediabox);
43
44 /**
45 Function type to end the
46 process of writing a page to a document.
47
48 dev: The device created by the begin_page function.
49 */
50 typedef void (fz_document_writer_end_page_fn)(fz_context *ctx, fz_document_writer *wri, fz_device *dev);
51
52 /**
53 Function type to end
54 the process of writing pages to a document.
55
56 This writes any file level trailers required. After this
57 completes successfully the file is up to date and complete.
58 */
59 typedef void (fz_document_writer_close_writer_fn)(fz_context *ctx, fz_document_writer *wri);
60
61 /**
62 Function type to discard
63 an fz_document_writer. This may be called at any time during
64 the process to release all the resources owned by the writer.
65
66 Calling drop without having previously called close may leave
67 the file in an inconsistent state and the user of the
68 fz_document_writer would need to do any cleanup required.
69 */
70 typedef void (fz_document_writer_drop_writer_fn)(fz_context *ctx, fz_document_writer *wri);
71
72 #define fz_new_derived_document_writer(CTX,TYPE,BEGIN_PAGE,END_PAGE,CLOSE,DROP) \
73 ((TYPE *)Memento_label(fz_new_document_writer_of_size(CTX,sizeof(TYPE),BEGIN_PAGE,END_PAGE,CLOSE,DROP),#TYPE))
74
75 /**
76 Look for a given option (key) in the opts string. Return 1 if
77 it has it, and update *val to point to the value within opts.
78 */
79 int fz_has_option(fz_context *ctx, const char *opts, const char *key, const char **val);
80
81 /**
82 Check to see if an option, a, from a string matches a reference
83 option, b.
84
85 (i.e. a could be 'foo' or 'foo,bar...' etc, but b can only be
86 'foo'.)
87 */
88 int fz_option_eq(const char *a, const char *b);
89
90 /**
91 Copy an option (val) into a destination buffer (dest), of maxlen
92 bytes.
93
94 Returns the number of bytes (including terminator) that did not
95 fit. If val is maxlen or greater bytes in size, it will be left
96 unterminated.
97 */
98 size_t fz_copy_option(fz_context *ctx, const char *val, char *dest, size_t maxlen);
99
100 /**
101 Create a new fz_document_writer, for a
102 file of the given type.
103
104 path: The document name to write (or NULL for default)
105
106 format: Which format to write (currently cbz, html, pdf, pam,
107 pbm, pgm, pkm, png, ppm, pnm, svg, text, xhtml, docx, odt)
108
109 options: NULL, or pointer to comma separated string to control
110 file generation.
111 */
112 fz_document_writer *fz_new_document_writer(fz_context *ctx, const char *path, const char *format, const char *options);
113
114 /**
115 Like fz_new_document_writer but takes a fz_output for writing
116 the result. Only works for multi-page formats.
117 */
118 fz_document_writer *
119 fz_new_document_writer_with_output(fz_context *ctx, fz_output *out, const char *format, const char *options);
120
121 fz_document_writer *
122 fz_new_document_writer_with_buffer(fz_context *ctx, fz_buffer *buf, const char *format, const char *options);
123
124 /**
125 Document writers for various possible output formats.
126
127 All of the "_with_output" variants pass the ownership of out in
128 immediately upon calling. The writers are responsible for
129 dropping the fz_output when they are finished with it (even
130 if they throw an exception during creation).
131 */
132 fz_document_writer *fz_new_pdf_writer(fz_context *ctx, const char *path, const char *options);
133 fz_document_writer *fz_new_pdf_writer_with_output(fz_context *ctx, fz_output *out, const char *options);
134 fz_document_writer *fz_new_svg_writer(fz_context *ctx, const char *path, const char *options);
135 fz_document_writer *fz_new_svg_writer_with_output(fz_context *ctx, fz_output *out, const char *options);
136
137 fz_document_writer *fz_new_text_writer(fz_context *ctx, const char *format, const char *path, const char *options);
138 fz_document_writer *fz_new_text_writer_with_output(fz_context *ctx, const char *format, fz_output *out, const char *options);
139
140 fz_document_writer *fz_new_odt_writer(fz_context *ctx, const char *path, const char *options);
141 fz_document_writer *fz_new_odt_writer_with_output(fz_context *ctx, fz_output *out, const char *options);
142 fz_document_writer *fz_new_docx_writer(fz_context *ctx, const char *path, const char *options);
143 fz_document_writer *fz_new_docx_writer_with_output(fz_context *ctx, fz_output *out, const char *options);
144
145 fz_document_writer *fz_new_ps_writer(fz_context *ctx, const char *path, const char *options);
146 fz_document_writer *fz_new_ps_writer_with_output(fz_context *ctx, fz_output *out, const char *options);
147 fz_document_writer *fz_new_pcl_writer(fz_context *ctx, const char *path, const char *options);
148 fz_document_writer *fz_new_pcl_writer_with_output(fz_context *ctx, fz_output *out, const char *options);
149 fz_document_writer *fz_new_pclm_writer(fz_context *ctx, const char *path, const char *options);
150 fz_document_writer *fz_new_pclm_writer_with_output(fz_context *ctx, fz_output *out, const char *options);
151 fz_document_writer *fz_new_pwg_writer(fz_context *ctx, const char *path, const char *options);
152 fz_document_writer *fz_new_pwg_writer_with_output(fz_context *ctx, fz_output *out, const char *options);
153
154 fz_document_writer *fz_new_cbz_writer(fz_context *ctx, const char *path, const char *options);
155 fz_document_writer *fz_new_cbz_writer_with_output(fz_context *ctx, fz_output *out, const char *options);
156
157 fz_document_writer *fz_new_csv_writer(fz_context *ctx, const char *path, const char *options);
158 fz_document_writer *fz_new_csv_writer_with_output(fz_context *ctx, fz_output *out, const char *options);
159
160 /**
161 Used to report progress of the OCR operation.
162
163 page: Current page being processed.
164
165 percent: Progress of the OCR operation for the
166 current page in percent. Whether it reaches 100
167 once a page is finished, depends on the OCR engine.
168
169 Return 0 to continue progress, return 1 to cancel the
170 operation.
171 */
172 typedef int (fz_pdfocr_progress_fn)(fz_context *ctx, void *progress_arg, int page, int percent);
173
174 fz_document_writer *fz_new_pdfocr_writer(fz_context *ctx, const char *path, const char *options);
175 fz_document_writer *fz_new_pdfocr_writer_with_output(fz_context *ctx, fz_output *out, const char *options);
176 void fz_pdfocr_writer_set_progress(fz_context *ctx, fz_document_writer *writer, fz_pdfocr_progress_fn *progress, void *);
177
178 fz_document_writer *fz_new_jpeg_pixmap_writer(fz_context *ctx, const char *path, const char *options);
179 fz_document_writer *fz_new_png_pixmap_writer(fz_context *ctx, const char *path, const char *options);
180 fz_document_writer *fz_new_pam_pixmap_writer(fz_context *ctx, const char *path, const char *options);
181 fz_document_writer *fz_new_pnm_pixmap_writer(fz_context *ctx, const char *path, const char *options);
182 fz_document_writer *fz_new_pgm_pixmap_writer(fz_context *ctx, const char *path, const char *options);
183 fz_document_writer *fz_new_ppm_pixmap_writer(fz_context *ctx, const char *path, const char *options);
184 fz_document_writer *fz_new_pbm_pixmap_writer(fz_context *ctx, const char *path, const char *options);
185 fz_document_writer *fz_new_pkm_pixmap_writer(fz_context *ctx, const char *path, const char *options);
186
187 /**
188 Called to start the process of writing a page to
189 a document.
190
191 mediabox: page size rectangle in points.
192
193 Returns a borrowed fz_device to write page contents to. This
194 should be kept if required, and only dropped if it was kept.
195 */
196 fz_device *fz_begin_page(fz_context *ctx, fz_document_writer *wri, fz_rect mediabox);
197
198 /**
199 Called to end the process of writing a page to a
200 document.
201 */
202 void fz_end_page(fz_context *ctx, fz_document_writer *wri);
203
204 /**
205 Convenience function to feed all the pages of a document to
206 fz_begin_page/fz_run_page/fz_end_page.
207 */
208 void fz_write_document(fz_context *ctx, fz_document_writer *wri, fz_document *doc);
209
210 /**
211 Called to end the process of writing
212 pages to a document.
213
214 This writes any file level trailers required. After this
215 completes successfully the file is up to date and complete.
216 */
217 void fz_close_document_writer(fz_context *ctx, fz_document_writer *wri);
218
219 /**
220 Called to discard a fz_document_writer.
221 This may be called at any time during the process to release all
222 the resources owned by the writer.
223
224 Calling drop without having previously called close may leave
225 the file in an inconsistent state.
226 */
227 void fz_drop_document_writer(fz_context *ctx, fz_document_writer *wri);
228
229 fz_document_writer *fz_new_pixmap_writer(fz_context *ctx, const char *path, const char *options, const char *default_path, int n,
230 void (*save)(fz_context *ctx, fz_pixmap *pix, const char *filename));
231
232 FZ_DATA extern const char *fz_pdf_write_options_usage;
233 FZ_DATA extern const char *fz_svg_write_options_usage;
234
235 FZ_DATA extern const char *fz_pcl_write_options_usage;
236 FZ_DATA extern const char *fz_pclm_write_options_usage;
237 FZ_DATA extern const char *fz_pwg_write_options_usage;
238 FZ_DATA extern const char *fz_pdfocr_write_options_usage;
239
240 /* Implementation details: subject to change. */
241
242 /**
243 Structure is public to allow other structures to
244 be derived from it. Do not access members directly.
245 */
246 struct fz_document_writer
247 {
248 fz_document_writer_begin_page_fn *begin_page;
249 fz_document_writer_end_page_fn *end_page;
250 fz_document_writer_close_writer_fn *close_writer;
251 fz_document_writer_drop_writer_fn *drop_writer;
252 fz_device *dev;
253 };
254
255 /**
256 Internal function to allocate a
257 block for a derived document_writer structure, with the base
258 structure's function pointers populated correctly, and the extra
259 space zero initialised.
260 */
261 fz_document_writer *fz_new_document_writer_of_size(fz_context *ctx, size_t size,
262 fz_document_writer_begin_page_fn *begin_page,
263 fz_document_writer_end_page_fn *end_page,
264 fz_document_writer_close_writer_fn *close,
265 fz_document_writer_drop_writer_fn *drop);
266
267
268
269 #endif