PyMuPDF 1.24.11__cp38-abi3-win_amd64.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (99) hide show
  1. PyMuPDF-1.24.11.dist-info/COPYING +1 -0
  2. PyMuPDF-1.24.11.dist-info/METADATA +83 -0
  3. PyMuPDF-1.24.11.dist-info/README.md +60 -0
  4. PyMuPDF-1.24.11.dist-info/RECORD +99 -0
  5. PyMuPDF-1.24.11.dist-info/WHEEL +4 -0
  6. PyMuPDF-1.24.11.dist-info/entry_points.txt +3 -0
  7. fitz/__init__.py +11 -0
  8. fitz/table.py +2 -0
  9. fitz/utils.py +2 -0
  10. pymupdf/__init__.py +22122 -0
  11. pymupdf/__main__.py +1146 -0
  12. pymupdf/_apply_pages.py +253 -0
  13. pymupdf/_build.py +1 -0
  14. pymupdf/_extra.pyd +0 -0
  15. pymupdf/_mupdf.pyd +0 -0
  16. pymupdf/extra.py +214 -0
  17. pymupdf/mupdf-devel/include/mupdf/fitz/archive.h +444 -0
  18. pymupdf/mupdf-devel/include/mupdf/fitz/band-writer.h +117 -0
  19. pymupdf/mupdf-devel/include/mupdf/fitz/bidi.h +90 -0
  20. pymupdf/mupdf-devel/include/mupdf/fitz/bitmap.h +175 -0
  21. pymupdf/mupdf-devel/include/mupdf/fitz/buffer.h +250 -0
  22. pymupdf/mupdf-devel/include/mupdf/fitz/color.h +427 -0
  23. pymupdf/mupdf-devel/include/mupdf/fitz/compress.h +88 -0
  24. pymupdf/mupdf-devel/include/mupdf/fitz/compressed-buffer.h +185 -0
  25. pymupdf/mupdf-devel/include/mupdf/fitz/config.h +223 -0
  26. pymupdf/mupdf-devel/include/mupdf/fitz/context.h +1006 -0
  27. pymupdf/mupdf-devel/include/mupdf/fitz/crypt.h +270 -0
  28. pymupdf/mupdf-devel/include/mupdf/fitz/device.h +654 -0
  29. pymupdf/mupdf-devel/include/mupdf/fitz/display-list.h +142 -0
  30. pymupdf/mupdf-devel/include/mupdf/fitz/document.h +1108 -0
  31. pymupdf/mupdf-devel/include/mupdf/fitz/export.h +52 -0
  32. pymupdf/mupdf-devel/include/mupdf/fitz/filter.h +263 -0
  33. pymupdf/mupdf-devel/include/mupdf/fitz/font.h +815 -0
  34. pymupdf/mupdf-devel/include/mupdf/fitz/geometry.h +818 -0
  35. pymupdf/mupdf-devel/include/mupdf/fitz/getopt.h +128 -0
  36. pymupdf/mupdf-devel/include/mupdf/fitz/glyph-cache.h +96 -0
  37. pymupdf/mupdf-devel/include/mupdf/fitz/glyph.h +81 -0
  38. pymupdf/mupdf-devel/include/mupdf/fitz/hash.h +126 -0
  39. pymupdf/mupdf-devel/include/mupdf/fitz/heap-imp.h +163 -0
  40. pymupdf/mupdf-devel/include/mupdf/fitz/heap.h +140 -0
  41. pymupdf/mupdf-devel/include/mupdf/fitz/image.h +443 -0
  42. pymupdf/mupdf-devel/include/mupdf/fitz/link.h +130 -0
  43. pymupdf/mupdf-devel/include/mupdf/fitz/log.h +61 -0
  44. pymupdf/mupdf-devel/include/mupdf/fitz/outline.h +228 -0
  45. pymupdf/mupdf-devel/include/mupdf/fitz/output-svg.h +64 -0
  46. pymupdf/mupdf-devel/include/mupdf/fitz/output.h +415 -0
  47. pymupdf/mupdf-devel/include/mupdf/fitz/path.h +447 -0
  48. pymupdf/mupdf-devel/include/mupdf/fitz/pixmap.h +501 -0
  49. pymupdf/mupdf-devel/include/mupdf/fitz/pool.h +68 -0
  50. pymupdf/mupdf-devel/include/mupdf/fitz/separation.h +138 -0
  51. pymupdf/mupdf-devel/include/mupdf/fitz/shade.h +233 -0
  52. pymupdf/mupdf-devel/include/mupdf/fitz/store.h +456 -0
  53. pymupdf/mupdf-devel/include/mupdf/fitz/story-writer.h +209 -0
  54. pymupdf/mupdf-devel/include/mupdf/fitz/story.h +232 -0
  55. pymupdf/mupdf-devel/include/mupdf/fitz/stream.h +646 -0
  56. pymupdf/mupdf-devel/include/mupdf/fitz/string-util.h +286 -0
  57. pymupdf/mupdf-devel/include/mupdf/fitz/structured-text.h +365 -0
  58. pymupdf/mupdf-devel/include/mupdf/fitz/system.h +459 -0
  59. pymupdf/mupdf-devel/include/mupdf/fitz/text.h +209 -0
  60. pymupdf/mupdf-devel/include/mupdf/fitz/track-usage.h +57 -0
  61. pymupdf/mupdf-devel/include/mupdf/fitz/transition.h +76 -0
  62. pymupdf/mupdf-devel/include/mupdf/fitz/tree.h +62 -0
  63. pymupdf/mupdf-devel/include/mupdf/fitz/types.h +41 -0
  64. pymupdf/mupdf-devel/include/mupdf/fitz/util.h +151 -0
  65. pymupdf/mupdf-devel/include/mupdf/fitz/version.h +31 -0
  66. pymupdf/mupdf-devel/include/mupdf/fitz/write-pixmap.h +499 -0
  67. pymupdf/mupdf-devel/include/mupdf/fitz/writer.h +266 -0
  68. pymupdf/mupdf-devel/include/mupdf/fitz/xml.h +397 -0
  69. pymupdf/mupdf-devel/include/mupdf/fitz.h +97 -0
  70. pymupdf/mupdf-devel/include/mupdf/helpers/mu-office-lib.h +666 -0
  71. pymupdf/mupdf-devel/include/mupdf/helpers/mu-threads.h +280 -0
  72. pymupdf/mupdf-devel/include/mupdf/helpers/pkcs7-openssl.h +48 -0
  73. pymupdf/mupdf-devel/include/mupdf/html.h +53 -0
  74. pymupdf/mupdf-devel/include/mupdf/memento.h +423 -0
  75. pymupdf/mupdf-devel/include/mupdf/pdf/annot.h +965 -0
  76. pymupdf/mupdf-devel/include/mupdf/pdf/clean.h +48 -0
  77. pymupdf/mupdf-devel/include/mupdf/pdf/cmap.h +145 -0
  78. pymupdf/mupdf-devel/include/mupdf/pdf/crypt.h +107 -0
  79. pymupdf/mupdf-devel/include/mupdf/pdf/document.h +842 -0
  80. pymupdf/mupdf-devel/include/mupdf/pdf/event.h +167 -0
  81. pymupdf/mupdf-devel/include/mupdf/pdf/font.h +168 -0
  82. pymupdf/mupdf-devel/include/mupdf/pdf/form.h +380 -0
  83. pymupdf/mupdf-devel/include/mupdf/pdf/image-rewriter.h +78 -0
  84. pymupdf/mupdf-devel/include/mupdf/pdf/interpret.h +492 -0
  85. pymupdf/mupdf-devel/include/mupdf/pdf/javascript.h +43 -0
  86. pymupdf/mupdf-devel/include/mupdf/pdf/name-table.h +596 -0
  87. pymupdf/mupdf-devel/include/mupdf/pdf/object.h +435 -0
  88. pymupdf/mupdf-devel/include/mupdf/pdf/page.h +316 -0
  89. pymupdf/mupdf-devel/include/mupdf/pdf/parse.h +61 -0
  90. pymupdf/mupdf-devel/include/mupdf/pdf/resource.h +133 -0
  91. pymupdf/mupdf-devel/include/mupdf/pdf/xref.h +300 -0
  92. pymupdf/mupdf-devel/include/mupdf/pdf.h +57 -0
  93. pymupdf/mupdf-devel/include/mupdf/ucdn.h +452 -0
  94. pymupdf/mupdf-devel/lib/mupdfcpp64.lib +0 -0
  95. pymupdf/mupdf.py +58506 -0
  96. pymupdf/mupdfcpp64.dll +0 -0
  97. pymupdf/pymupdf.py +2 -0
  98. pymupdf/table.py +2355 -0
  99. pymupdf/utils.py +5880 -0
@@ -0,0 +1,492 @@
1
+ // Copyright (C) 2004-2023 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 PDF_INTERPRET_H
24
+ #define PDF_INTERPRET_H
25
+
26
+ #include "mupdf/pdf/font.h"
27
+ #include "mupdf/pdf/resource.h"
28
+ #include "mupdf/pdf/document.h"
29
+
30
+ typedef struct pdf_gstate pdf_gstate;
31
+ typedef struct pdf_processor pdf_processor;
32
+
33
+ void *pdf_new_processor(fz_context *ctx, int size);
34
+ pdf_processor *pdf_keep_processor(fz_context *ctx, pdf_processor *proc);
35
+ void pdf_close_processor(fz_context *ctx, pdf_processor *proc);
36
+ void pdf_drop_processor(fz_context *ctx, pdf_processor *proc);
37
+
38
+ typedef enum
39
+ {
40
+ PDF_PROCESSOR_REQUIRES_DECODED_IMAGES = 1
41
+ } pdf_processor_requirements;
42
+
43
+ struct pdf_processor
44
+ {
45
+ int refs;
46
+
47
+ int closed;
48
+
49
+ /* close the processor. Also closes any chained processors. */
50
+ void (*close_processor)(fz_context *ctx, pdf_processor *proc);
51
+ void (*drop_processor)(fz_context *ctx, pdf_processor *proc);
52
+ void (*reset_processor)(fz_context *ctx, pdf_processor *proc);
53
+
54
+ /* At any stage, we can have one set of resources in place.
55
+ * This function gives us a set of resources to use. We remember
56
+ * any previous set on a stack, so we can pop back to it later.
57
+ * Our responsibility (as well as remembering it for our own use)
58
+ * is to pass either it, or a filtered version of it onto any
59
+ * chained processor. */
60
+ void (*push_resources)(fz_context *ctx, pdf_processor *proc, pdf_obj *res);
61
+ /* Pop the resources stack. This must be passed on to any chained
62
+ * processors. This returns a pointer to the resource dict just
63
+ * popped by the deepest filter. The caller inherits this reference. */
64
+ pdf_obj *(*pop_resources)(fz_context *ctx, pdf_processor *proc);
65
+
66
+ /* general graphics state */
67
+ void (*op_w)(fz_context *ctx, pdf_processor *proc, float linewidth);
68
+ void (*op_j)(fz_context *ctx, pdf_processor *proc, int linejoin);
69
+ void (*op_J)(fz_context *ctx, pdf_processor *proc, int linecap);
70
+ void (*op_M)(fz_context *ctx, pdf_processor *proc, float miterlimit);
71
+ void (*op_d)(fz_context *ctx, pdf_processor *proc, pdf_obj *array, float phase);
72
+ void (*op_ri)(fz_context *ctx, pdf_processor *proc, const char *intent);
73
+ void (*op_i)(fz_context *ctx, pdf_processor *proc, float flatness);
74
+
75
+ void (*op_gs_begin)(fz_context *ctx, pdf_processor *proc, const char *name, pdf_obj *extgstate);
76
+ void (*op_gs_BM)(fz_context *ctx, pdf_processor *proc, const char *blendmode);
77
+ void (*op_gs_ca)(fz_context *ctx, pdf_processor *proc, float alpha);
78
+ void (*op_gs_CA)(fz_context *ctx, pdf_processor *proc, float alpha);
79
+ void (*op_gs_SMask)(fz_context *ctx, pdf_processor *proc, pdf_obj *smask, float *bc, int luminosity, pdf_obj *tr);
80
+ void (*op_gs_end)(fz_context *ctx, pdf_processor *proc);
81
+
82
+ /* special graphics state */
83
+ void (*op_q)(fz_context *ctx, pdf_processor *proc);
84
+ void (*op_Q)(fz_context *ctx, pdf_processor *proc);
85
+ void (*op_cm)(fz_context *ctx, pdf_processor *proc, float a, float b, float c, float d, float e, float f);
86
+
87
+ /* path construction */
88
+ void (*op_m)(fz_context *ctx, pdf_processor *proc, float x, float y);
89
+ void (*op_l)(fz_context *ctx, pdf_processor *proc, float x, float y);
90
+ void (*op_c)(fz_context *ctx, pdf_processor *proc, float x1, float y1, float x2, float y2, float x3, float y3);
91
+ void (*op_v)(fz_context *ctx, pdf_processor *proc, float x2, float y2, float x3, float y3);
92
+ void (*op_y)(fz_context *ctx, pdf_processor *proc, float x1, float y1, float x3, float y3);
93
+ void (*op_h)(fz_context *ctx, pdf_processor *proc);
94
+ void (*op_re)(fz_context *ctx, pdf_processor *proc, float x, float y, float w, float h);
95
+
96
+ /* path painting */
97
+ void (*op_S)(fz_context *ctx, pdf_processor *proc);
98
+ void (*op_s)(fz_context *ctx, pdf_processor *proc);
99
+ void (*op_F)(fz_context *ctx, pdf_processor *proc);
100
+ void (*op_f)(fz_context *ctx, pdf_processor *proc);
101
+ void (*op_fstar)(fz_context *ctx, pdf_processor *proc);
102
+ void (*op_B)(fz_context *ctx, pdf_processor *proc);
103
+ void (*op_Bstar)(fz_context *ctx, pdf_processor *proc);
104
+ void (*op_b)(fz_context *ctx, pdf_processor *proc);
105
+ void (*op_bstar)(fz_context *ctx, pdf_processor *proc);
106
+ void (*op_n)(fz_context *ctx, pdf_processor *proc);
107
+
108
+ /* clipping paths */
109
+ void (*op_W)(fz_context *ctx, pdf_processor *proc);
110
+ void (*op_Wstar)(fz_context *ctx, pdf_processor *proc);
111
+
112
+ /* text objects */
113
+ void (*op_BT)(fz_context *ctx, pdf_processor *proc);
114
+ void (*op_ET)(fz_context *ctx, pdf_processor *proc);
115
+
116
+ /* text state */
117
+ void (*op_Tc)(fz_context *ctx, pdf_processor *proc, float charspace);
118
+ void (*op_Tw)(fz_context *ctx, pdf_processor *proc, float wordspace);
119
+ void (*op_Tz)(fz_context *ctx, pdf_processor *proc, float scale);
120
+ void (*op_TL)(fz_context *ctx, pdf_processor *proc, float leading);
121
+ void (*op_Tf)(fz_context *ctx, pdf_processor *proc, const char *name, pdf_font_desc *font, float size);
122
+ void (*op_Tr)(fz_context *ctx, pdf_processor *proc, int render);
123
+ void (*op_Ts)(fz_context *ctx, pdf_processor *proc, float rise);
124
+
125
+ /* text positioning */
126
+ void (*op_Td)(fz_context *ctx, pdf_processor *proc, float tx, float ty);
127
+ void (*op_TD)(fz_context *ctx, pdf_processor *proc, float tx, float ty);
128
+ void (*op_Tm)(fz_context *ctx, pdf_processor *proc, float a, float b, float c, float d, float e, float f);
129
+ void (*op_Tstar)(fz_context *ctx, pdf_processor *proc);
130
+
131
+ /* text showing */
132
+ void (*op_TJ)(fz_context *ctx, pdf_processor *proc, pdf_obj *array);
133
+ void (*op_Tj)(fz_context *ctx, pdf_processor *proc, char *str, size_t len);
134
+ void (*op_squote)(fz_context *ctx, pdf_processor *proc, char *str, size_t len);
135
+ void (*op_dquote)(fz_context *ctx, pdf_processor *proc, float aw, float ac, char *str, size_t len);
136
+
137
+ /* type 3 fonts */
138
+ void (*op_d0)(fz_context *ctx, pdf_processor *proc, float wx, float wy);
139
+ void (*op_d1)(fz_context *ctx, pdf_processor *proc, float wx, float wy, float llx, float lly, float urx, float ury);
140
+
141
+ /* color */
142
+ void (*op_CS)(fz_context *ctx, pdf_processor *proc, const char *name, fz_colorspace *cs);
143
+ void (*op_cs)(fz_context *ctx, pdf_processor *proc, const char *name, fz_colorspace *cs);
144
+ void (*op_SC_pattern)(fz_context *ctx, pdf_processor *proc, const char *name, pdf_pattern *pat, int n, float *color);
145
+ void (*op_sc_pattern)(fz_context *ctx, pdf_processor *proc, const char *name, pdf_pattern *pat, int n, float *color);
146
+ void (*op_SC_shade)(fz_context *ctx, pdf_processor *proc, const char *name, fz_shade *shade);
147
+ void (*op_sc_shade)(fz_context *ctx, pdf_processor *proc, const char *name, fz_shade *shade);
148
+ void (*op_SC_color)(fz_context *ctx, pdf_processor *proc, int n, float *color);
149
+ void (*op_sc_color)(fz_context *ctx, pdf_processor *proc, int n, float *color);
150
+
151
+ void (*op_G)(fz_context *ctx, pdf_processor *proc, float g);
152
+ void (*op_g)(fz_context *ctx, pdf_processor *proc, float g);
153
+ void (*op_RG)(fz_context *ctx, pdf_processor *proc, float r, float g, float b);
154
+ void (*op_rg)(fz_context *ctx, pdf_processor *proc, float r, float g, float b);
155
+ void (*op_K)(fz_context *ctx, pdf_processor *proc, float c, float m, float y, float k);
156
+ void (*op_k)(fz_context *ctx, pdf_processor *proc, float c, float m, float y, float k);
157
+
158
+ /* shadings, images, xobjects */
159
+ void (*op_BI)(fz_context *ctx, pdf_processor *proc, fz_image *image, const char *colorspace_name);
160
+ void (*op_sh)(fz_context *ctx, pdf_processor *proc, const char *name, fz_shade *shade);
161
+ void (*op_Do_image)(fz_context *ctx, pdf_processor *proc, const char *name, fz_image *image);
162
+ void (*op_Do_form)(fz_context *ctx, pdf_processor *proc, const char *name, pdf_obj *form);
163
+
164
+ /* marked content */
165
+ void (*op_MP)(fz_context *ctx, pdf_processor *proc, const char *tag);
166
+ void (*op_DP)(fz_context *ctx, pdf_processor *proc, const char *tag, pdf_obj *raw, pdf_obj *cooked);
167
+ void (*op_BMC)(fz_context *ctx, pdf_processor *proc, const char *tag);
168
+ void (*op_BDC)(fz_context *ctx, pdf_processor *proc, const char *tag, pdf_obj *raw, pdf_obj *cooked);
169
+ void (*op_EMC)(fz_context *ctx, pdf_processor *proc);
170
+
171
+ /* compatibility */
172
+ void (*op_BX)(fz_context *ctx, pdf_processor *proc);
173
+ void (*op_EX)(fz_context *ctx, pdf_processor *proc);
174
+
175
+ /* Virtual ops for ExtGState entries */
176
+ void (*op_gs_OP)(fz_context *ctx, pdf_processor *proc, int b);
177
+ void (*op_gs_op)(fz_context *ctx, pdf_processor *proc, int b);
178
+ void (*op_gs_OPM)(fz_context *ctx, pdf_processor *proc, int i);
179
+ void (*op_gs_UseBlackPtComp)(fz_context *ctx, pdf_processor *proc, pdf_obj *name);
180
+
181
+ /* END is used to signify end of stream (finalise and close down) */
182
+ void (*op_END)(fz_context *ctx, pdf_processor *proc);
183
+
184
+ /* interpreter state that persists across content streams */
185
+ const char *usage;
186
+ int hidden;
187
+
188
+ pdf_processor_requirements requirements;
189
+ };
190
+
191
+ typedef struct
192
+ {
193
+ /* input */
194
+ pdf_document *doc;
195
+ pdf_obj *rdb;
196
+ pdf_lexbuf *buf;
197
+ fz_cookie *cookie;
198
+
199
+ /* state */
200
+ int gstate;
201
+ int xbalance;
202
+ int in_text;
203
+ fz_rect d1_rect;
204
+
205
+ /* stack */
206
+ pdf_obj *obj;
207
+ char name[256];
208
+ char string[256];
209
+ size_t string_len;
210
+ int top;
211
+ float stack[32];
212
+ } pdf_csi;
213
+
214
+ void pdf_count_q_balance(fz_context *ctx, pdf_document *doc, pdf_obj *res, pdf_obj *stm, int *prepend, int *append);
215
+
216
+ /* Functions to set up pdf_process structures */
217
+
218
+ pdf_processor *pdf_new_run_processor(fz_context *ctx, pdf_document *doc, fz_device *dev, fz_matrix ctm, int struct_parent, const char *usage, pdf_gstate *gstate, fz_default_colorspaces *default_cs, fz_cookie *cookie);
219
+
220
+ /*
221
+ Create a buffer processor.
222
+
223
+ This collects the incoming PDF operator stream into an fz_buffer.
224
+
225
+ buffer: The (possibly empty) buffer to which operators will be
226
+ appended.
227
+
228
+ ahxencode: If 0, then image streams will be send as binary,
229
+ otherwise they will be asciihexencoded.
230
+
231
+ newlines: If 0, then minimal spacing will be sent. If 1
232
+ then newlines will be sent after every operator.
233
+ */
234
+ pdf_processor *pdf_new_buffer_processor(fz_context *ctx, fz_buffer *buffer, int ahxencode, int newlines);
235
+
236
+ /*
237
+ Reopen a closed processor to be used again.
238
+
239
+ This brings a processor back to life after a close.
240
+ Not all processors may support this, so this may throw
241
+ an exception.
242
+ */
243
+ void pdf_reset_processor(fz_context *ctx, pdf_processor *proc);
244
+
245
+
246
+ /*
247
+ Create an output processor. This
248
+ sends the incoming PDF operator stream to an fz_output stream.
249
+
250
+ out: The output stream to which operators will be sent.
251
+
252
+ ahxencode: If 0, then image streams will be send as binary,
253
+ otherwise they will be asciihexencoded.
254
+
255
+ newlines: If 0, then minimal spacing will be sent. If 1
256
+ then newlines will be sent after every operator.
257
+ */
258
+ pdf_processor *pdf_new_output_processor(fz_context *ctx, fz_output *out, int ahxencode, int newlines);
259
+
260
+ typedef struct pdf_filter_options pdf_filter_options;
261
+
262
+ /*
263
+ Create a filter processor. This filters the PDF operators
264
+ it is fed, and passes them down (with some changes) to the
265
+ child filter.
266
+
267
+ chain: The child processor to which the filtered operators
268
+ will be fed.
269
+
270
+ The options field contains a pointer to a structure with
271
+ filter specific options in.
272
+ */
273
+ typedef pdf_processor *(pdf_filter_factory_fn)(fz_context *ctx, pdf_document *doc, pdf_processor *chain, int struct_parents, fz_matrix transform, pdf_filter_options *options, void *factory_options);
274
+
275
+ /*
276
+ A pdf_filter_factory is a pdf_filter_factory_fn, plus the options
277
+ needed to instantiate it.
278
+ */
279
+ typedef struct
280
+ {
281
+ pdf_filter_factory_fn *filter;
282
+ void *options;
283
+ } pdf_filter_factory;
284
+
285
+ /*
286
+ recurse: Filter resources recursively.
287
+
288
+ instance_forms: Always recurse on XObject Form resources, but will
289
+ create a new instance of each XObject Form that is used, filtered
290
+ individually.
291
+
292
+ ascii: If true, escape all binary data in the output.
293
+
294
+ no_update: If true, do not update the document at the end.
295
+
296
+ opaque: Opaque value that is passed to the complete function.
297
+
298
+ complete: A function called at the end of processing.
299
+ This allows the caller to insert some extra content after
300
+ all other content.
301
+
302
+ filters: Pointer to an array of filter factory/options.
303
+ The array is terminated by an entry with a NULL factory pointer.
304
+ Operators will be fed into the filter generated from the first
305
+ factory function in the list, and from there go to the filter
306
+ generated from the second factory in the list etc.
307
+
308
+ newlines: If 0, then minimal whitespace will be produced. If 1,
309
+ then a newline will be sent after every operator.
310
+ */
311
+ struct pdf_filter_options
312
+ {
313
+ int recurse;
314
+ int instance_forms;
315
+ int ascii;
316
+ int no_update;
317
+
318
+ void *opaque;
319
+ void (*complete)(fz_context *ctx, fz_buffer *buffer, void *opaque);
320
+
321
+ pdf_filter_factory *filters;
322
+ int newlines;
323
+ };
324
+
325
+ typedef enum
326
+ {
327
+ FZ_CULL_PATH_FILL,
328
+ FZ_CULL_PATH_STROKE,
329
+ FZ_CULL_PATH_FILL_STROKE,
330
+ FZ_CULL_CLIP_PATH,
331
+ FZ_CULL_GLYPH,
332
+ FZ_CULL_IMAGE,
333
+ FZ_CULL_SHADING
334
+ } fz_cull_type;
335
+
336
+ /*
337
+ image_filter: A function called to assess whether a given
338
+ image should be removed or not.
339
+
340
+ text_filter: A function called to assess whether a given
341
+ character should be removed or not.
342
+
343
+ after_text_object: A function called after each text object.
344
+ This allows the caller to insert some extra content if
345
+ desired.
346
+
347
+ culler: A function called to see whether each object should
348
+ be culled or not.
349
+ */
350
+ typedef struct
351
+ {
352
+ void *opaque;
353
+ fz_image *(*image_filter)(fz_context *ctx, void *opaque, fz_matrix ctm, const char *name, fz_image *image, fz_rect scissor);
354
+ int (*text_filter)(fz_context *ctx, void *opaque, int *ucsbuf, int ucslen, fz_matrix trm, fz_matrix ctm, fz_rect bbox);
355
+ void (*after_text_object)(fz_context *ctx, void *opaque, pdf_document *doc, pdf_processor *chain, fz_matrix ctm);
356
+ int (*culler)(fz_context *ctx, void *opaque, fz_rect bbox, fz_cull_type type);
357
+ }
358
+ pdf_sanitize_filter_options;
359
+
360
+ /*
361
+ A sanitize filter factory.
362
+
363
+ sopts = pointer to pdf_sanitize_filter_options.
364
+
365
+ The changes made by a filter generated from this are:
366
+
367
+ * No operations are allowed to change the top level gstate.
368
+ Additional q/Q operators are inserted to prevent this.
369
+
370
+ * Repeated/unnecessary colour operators are removed (so,
371
+ for example, "0 0 0 rg 0 1 rg 0.5 g" would be sanitised to
372
+ "0.5 g")
373
+
374
+ The intention of these changes is to provide a simpler,
375
+ but equivalent stream, repairing problems with mismatched
376
+ operators, maintaining structure (such as BMC, EMC calls)
377
+ and leaving the graphics state in an known (default) state
378
+ so that subsequent operations (such as synthesising new
379
+ operators to be appended to the stream) are easier.
380
+
381
+ The net graphical effect of the filtered operator stream
382
+ should be identical to the incoming operator stream.
383
+ */
384
+ pdf_processor *pdf_new_sanitize_filter(fz_context *ctx, pdf_document *doc, pdf_processor *chain, int struct_parents, fz_matrix transform, pdf_filter_options *options, void *sopts);
385
+
386
+ pdf_obj *pdf_filter_xobject_instance(fz_context *ctx, pdf_obj *old_xobj, pdf_obj *page_res, fz_matrix ctm, pdf_filter_options *options, pdf_cycle_list *cycle_up);
387
+
388
+ void pdf_processor_push_resources(fz_context *ctx, pdf_processor *proc, pdf_obj *res);
389
+
390
+ pdf_obj *pdf_processor_pop_resources(fz_context *ctx, pdf_processor *proc);
391
+
392
+ /*
393
+ opaque: Opaque value that is passed to all the filter functions.
394
+
395
+ color_rewrite: function pointer called to rewrite a color
396
+ On entry:
397
+ *cs = reference to a pdf object representing the colorspace.
398
+
399
+ *n = number of color components
400
+
401
+ color = *n color values.
402
+
403
+ On exit:
404
+ *cs either the same (for no change in colorspace) or
405
+ updated to be a new one. Reference must be dropped, and
406
+ a new kept reference returned!
407
+
408
+ *n = number of color components (maybe updated)
409
+
410
+ color = *n color values (maybe updated)
411
+
412
+ image_rewrite: function pointer called to rewrite an image
413
+ On entry:
414
+ *image = reference to an fz_image.
415
+
416
+ On exit:
417
+ *image either the same (for no change) or updated
418
+ to be a new one. Reference must be dropped, and a
419
+ new kept reference returned.
420
+
421
+ share_rewrite: function pointer called to rewrite a shade
422
+
423
+ repeated_image_rewrite: If 0, then each image is rewritten only once.
424
+ Otherwise, it is called for every instance (useful if gathering
425
+ information about the ctm).
426
+ */
427
+ typedef struct
428
+ {
429
+ void *opaque;
430
+ void (*color_rewrite)(fz_context *ctx, void *opaque, pdf_obj **cs, int *n, float color[FZ_MAX_COLORS]);
431
+ void (*image_rewrite)(fz_context *ctx, void *opaque, fz_image **image, fz_matrix ctm, pdf_obj *obj);
432
+ pdf_shade_recolorer *shade_rewrite;
433
+ int repeated_image_rewrite;
434
+ } pdf_color_filter_options;
435
+
436
+ pdf_processor *
437
+ pdf_new_color_filter(fz_context *ctx, pdf_document *doc, pdf_processor *chain, int struct_parents, fz_matrix transform, pdf_filter_options *options, void *copts);
438
+
439
+ /*
440
+ Functions to actually process annotations, glyphs and general stream objects.
441
+ */
442
+ void pdf_process_contents(fz_context *ctx, pdf_processor *proc, pdf_document *doc, pdf_obj *res, pdf_obj *stm, fz_cookie *cookie, pdf_obj **out_res);
443
+ void pdf_process_annot(fz_context *ctx, pdf_processor *proc, pdf_annot *annot, fz_cookie *cookie);
444
+ void pdf_process_glyph(fz_context *ctx, pdf_processor *proc, pdf_document *doc, pdf_obj *resources, fz_buffer *contents);
445
+
446
+ /*
447
+ Function to process a contents stream without handling the resources.
448
+ The caller is responsible for pushing/popping the resources.
449
+ */
450
+ void pdf_process_raw_contents(fz_context *ctx, pdf_processor *proc, pdf_document *doc, pdf_obj *rdb, pdf_obj *stmobj, fz_cookie *cookie);
451
+
452
+ /* Text handling helper functions */
453
+ typedef struct
454
+ {
455
+ float char_space;
456
+ float word_space;
457
+ float scale;
458
+ float leading;
459
+ pdf_font_desc *font;
460
+ fz_string *fontname;
461
+ float size;
462
+ int render;
463
+ float rise;
464
+ } pdf_text_state;
465
+
466
+ typedef struct
467
+ {
468
+ fz_text *text;
469
+ fz_rect text_bbox;
470
+ fz_matrix tlm;
471
+ fz_matrix tm;
472
+ int text_mode;
473
+
474
+ int cid;
475
+ int gid;
476
+ fz_rect char_bbox;
477
+ pdf_font_desc *fontdesc;
478
+ float char_tx;
479
+ float char_ty;
480
+ } pdf_text_object_state;
481
+
482
+ void pdf_tos_save(fz_context *ctx, pdf_text_object_state *tos, fz_matrix save[2]);
483
+ void pdf_tos_restore(fz_context *ctx, pdf_text_object_state *tos, fz_matrix save[2]);
484
+ fz_text *pdf_tos_get_text(fz_context *ctx, pdf_text_object_state *tos);
485
+ void pdf_tos_reset(fz_context *ctx, pdf_text_object_state *tos, int render);
486
+ int pdf_tos_make_trm(fz_context *ctx, pdf_text_object_state *tos, pdf_text_state *text, pdf_font_desc *fontdesc, int cid, fz_matrix *trm);
487
+ void pdf_tos_move_after_char(fz_context *ctx, pdf_text_object_state *tos);
488
+ void pdf_tos_translate(pdf_text_object_state *tos, float tx, float ty);
489
+ void pdf_tos_set_matrix(pdf_text_object_state *tos, float a, float b, float c, float d, float e, float f);
490
+ void pdf_tos_newline(pdf_text_object_state *tos, float leading);
491
+
492
+ #endif
@@ -0,0 +1,43 @@
1
+ // Copyright (C) 2004-2022 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_JAVASCRIPT_H
24
+ #define MUPDF_PDF_JAVASCRIPT_H
25
+
26
+ #include "mupdf/pdf/document.h"
27
+ #include "mupdf/pdf/form.h"
28
+
29
+ void pdf_enable_js(fz_context *ctx, pdf_document *doc);
30
+ void pdf_disable_js(fz_context *ctx, pdf_document *doc);
31
+ int pdf_js_supported(fz_context *ctx, pdf_document *doc);
32
+ void pdf_drop_js(fz_context *ctx, pdf_js *js);
33
+
34
+ void pdf_js_event_init(pdf_js *js, pdf_obj *target, const char *value, int willCommit);
35
+ int pdf_js_event_result(pdf_js *js);
36
+ int pdf_js_event_result_validate(pdf_js *js, char **newvalue);
37
+ char *pdf_js_event_value(pdf_js *js);
38
+ void pdf_js_event_init_keystroke(pdf_js *js, pdf_obj *target, pdf_keystroke_event *evt);
39
+ int pdf_js_event_result_keystroke(pdf_js *js, pdf_keystroke_event *evt);
40
+
41
+ void pdf_js_execute(pdf_js *js, const char *name, const char *code, char **result);
42
+
43
+ #endif