PyMuPDF 1.26.6__cp310-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.
- fitz/__init__.py +13 -0
- fitz/table.py +2 -0
- fitz/utils.py +2 -0
- pymupdf/__init__.py +25899 -0
- pymupdf/__main__.py +1140 -0
- pymupdf/_apply_pages.py +253 -0
- pymupdf/_build.py +8 -0
- pymupdf/_extra.pyd +0 -0
- pymupdf/_mupdf.pyd +0 -0
- pymupdf/_wxcolors.py +562 -0
- pymupdf/extra.py +220 -0
- pymupdf/mupdf-devel/include/mupdf/classes.h +19999 -0
- pymupdf/mupdf-devel/include/mupdf/classes2.h +12244 -0
- pymupdf/mupdf-devel/include/mupdf/exceptions.h +118 -0
- pymupdf/mupdf-devel/include/mupdf/extra.h +189 -0
- pymupdf/mupdf-devel/include/mupdf/fitz/archive.h +444 -0
- pymupdf/mupdf-devel/include/mupdf/fitz/band-writer.h +117 -0
- pymupdf/mupdf-devel/include/mupdf/fitz/barcode.h +138 -0
- pymupdf/mupdf-devel/include/mupdf/fitz/bidi.h +90 -0
- pymupdf/mupdf-devel/include/mupdf/fitz/bitmap.h +188 -0
- pymupdf/mupdf-devel/include/mupdf/fitz/buffer.h +250 -0
- pymupdf/mupdf-devel/include/mupdf/fitz/color.h +433 -0
- pymupdf/mupdf-devel/include/mupdf/fitz/compress.h +132 -0
- pymupdf/mupdf-devel/include/mupdf/fitz/compressed-buffer.h +194 -0
- pymupdf/mupdf-devel/include/mupdf/fitz/config.h +302 -0
- pymupdf/mupdf-devel/include/mupdf/fitz/context.h +1064 -0
- pymupdf/mupdf-devel/include/mupdf/fitz/crypt.h +270 -0
- pymupdf/mupdf-devel/include/mupdf/fitz/deskew.h +46 -0
- pymupdf/mupdf-devel/include/mupdf/fitz/device.h +652 -0
- pymupdf/mupdf-devel/include/mupdf/fitz/display-list.h +142 -0
- pymupdf/mupdf-devel/include/mupdf/fitz/document.h +1103 -0
- pymupdf/mupdf-devel/include/mupdf/fitz/export.h +52 -0
- pymupdf/mupdf-devel/include/mupdf/fitz/filter.h +269 -0
- pymupdf/mupdf-devel/include/mupdf/fitz/font.h +858 -0
- pymupdf/mupdf-devel/include/mupdf/fitz/geometry.h +885 -0
- pymupdf/mupdf-devel/include/mupdf/fitz/getopt.h +134 -0
- pymupdf/mupdf-devel/include/mupdf/fitz/glyph-cache.h +96 -0
- pymupdf/mupdf-devel/include/mupdf/fitz/glyph.h +81 -0
- pymupdf/mupdf-devel/include/mupdf/fitz/hash.h +126 -0
- pymupdf/mupdf-devel/include/mupdf/fitz/heap-imp.h +190 -0
- pymupdf/mupdf-devel/include/mupdf/fitz/heap.h +143 -0
- pymupdf/mupdf-devel/include/mupdf/fitz/image.h +451 -0
- pymupdf/mupdf-devel/include/mupdf/fitz/json.h +98 -0
- pymupdf/mupdf-devel/include/mupdf/fitz/link.h +130 -0
- pymupdf/mupdf-devel/include/mupdf/fitz/log.h +61 -0
- pymupdf/mupdf-devel/include/mupdf/fitz/outline.h +254 -0
- pymupdf/mupdf-devel/include/mupdf/fitz/output-svg.h +64 -0
- pymupdf/mupdf-devel/include/mupdf/fitz/output.h +448 -0
- pymupdf/mupdf-devel/include/mupdf/fitz/path.h +477 -0
- pymupdf/mupdf-devel/include/mupdf/fitz/pixmap.h +516 -0
- pymupdf/mupdf-devel/include/mupdf/fitz/pool.h +102 -0
- pymupdf/mupdf-devel/include/mupdf/fitz/separation.h +138 -0
- pymupdf/mupdf-devel/include/mupdf/fitz/shade.h +233 -0
- pymupdf/mupdf-devel/include/mupdf/fitz/store.h +465 -0
- pymupdf/mupdf-devel/include/mupdf/fitz/story-writer.h +209 -0
- pymupdf/mupdf-devel/include/mupdf/fitz/story.h +232 -0
- pymupdf/mupdf-devel/include/mupdf/fitz/stream.h +646 -0
- pymupdf/mupdf-devel/include/mupdf/fitz/string-util.h +335 -0
- pymupdf/mupdf-devel/include/mupdf/fitz/structured-text.h +924 -0
- pymupdf/mupdf-devel/include/mupdf/fitz/system.h +495 -0
- pymupdf/mupdf-devel/include/mupdf/fitz/text.h +210 -0
- pymupdf/mupdf-devel/include/mupdf/fitz/track-usage.h +57 -0
- pymupdf/mupdf-devel/include/mupdf/fitz/transition.h +76 -0
- pymupdf/mupdf-devel/include/mupdf/fitz/tree.h +62 -0
- pymupdf/mupdf-devel/include/mupdf/fitz/types.h +41 -0
- pymupdf/mupdf-devel/include/mupdf/fitz/util.h +159 -0
- pymupdf/mupdf-devel/include/mupdf/fitz/version.h +31 -0
- pymupdf/mupdf-devel/include/mupdf/fitz/write-pixmap.h +507 -0
- pymupdf/mupdf-devel/include/mupdf/fitz/writer.h +269 -0
- pymupdf/mupdf-devel/include/mupdf/fitz/xml.h +435 -0
- pymupdf/mupdf-devel/include/mupdf/fitz.h +101 -0
- pymupdf/mupdf-devel/include/mupdf/functions.h +13819 -0
- pymupdf/mupdf-devel/include/mupdf/helpers/mu-office-lib.h +666 -0
- pymupdf/mupdf-devel/include/mupdf/helpers/mu-threads.h +280 -0
- pymupdf/mupdf-devel/include/mupdf/helpers/pkcs7-openssl.h +48 -0
- pymupdf/mupdf-devel/include/mupdf/html.h +53 -0
- pymupdf/mupdf-devel/include/mupdf/internal.h +29 -0
- pymupdf/mupdf-devel/include/mupdf/memento.h +425 -0
- pymupdf/mupdf-devel/include/mupdf/pdf/annot.h +1015 -0
- pymupdf/mupdf-devel/include/mupdf/pdf/clean.h +68 -0
- pymupdf/mupdf-devel/include/mupdf/pdf/cmap.h +145 -0
- pymupdf/mupdf-devel/include/mupdf/pdf/crypt.h +108 -0
- pymupdf/mupdf-devel/include/mupdf/pdf/document.h +902 -0
- pymupdf/mupdf-devel/include/mupdf/pdf/event.h +167 -0
- pymupdf/mupdf-devel/include/mupdf/pdf/font.h +168 -0
- pymupdf/mupdf-devel/include/mupdf/pdf/form.h +381 -0
- pymupdf/mupdf-devel/include/mupdf/pdf/image-rewriter.h +78 -0
- pymupdf/mupdf-devel/include/mupdf/pdf/interpret.h +518 -0
- pymupdf/mupdf-devel/include/mupdf/pdf/javascript.h +43 -0
- pymupdf/mupdf-devel/include/mupdf/pdf/name-table.h +621 -0
- pymupdf/mupdf-devel/include/mupdf/pdf/object.h +445 -0
- pymupdf/mupdf-devel/include/mupdf/pdf/page.h +327 -0
- pymupdf/mupdf-devel/include/mupdf/pdf/parse.h +61 -0
- pymupdf/mupdf-devel/include/mupdf/pdf/recolor.h +49 -0
- pymupdf/mupdf-devel/include/mupdf/pdf/resource.h +144 -0
- pymupdf/mupdf-devel/include/mupdf/pdf/xref.h +300 -0
- pymupdf/mupdf-devel/include/mupdf/pdf/zugferd.h +49 -0
- pymupdf/mupdf-devel/include/mupdf/pdf.h +59 -0
- pymupdf/mupdf-devel/include/mupdf/ucdn.h +464 -0
- pymupdf/mupdf-devel/lib/libmuthreads.lib +0 -0
- pymupdf/mupdf-devel/lib/mupdfcpp64.lib +0 -0
- pymupdf/mupdf.py +63667 -0
- pymupdf/mupdfcpp64.dll +0 -0
- pymupdf/pymupdf.py +2 -0
- pymupdf/table.py +2697 -0
- pymupdf/utils.py +1169 -0
- pymupdf-1.26.6.dist-info/COPYING +1 -0
- pymupdf-1.26.6.dist-info/METADATA +83 -0
- pymupdf-1.26.6.dist-info/README.md +60 -0
- pymupdf-1.26.6.dist-info/RECORD +112 -0
- pymupdf-1.26.6.dist-info/WHEEL +4 -0
- pymupdf-1.26.6.dist-info/entry_points.txt +3 -0
|
@@ -0,0 +1,465 @@
|
|
|
1
|
+
// Copyright (C) 2004-2021 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_STORE_H
|
|
24
|
+
#define MUPDF_FITZ_STORE_H
|
|
25
|
+
|
|
26
|
+
#include "mupdf/fitz/system.h"
|
|
27
|
+
#include "mupdf/fitz/context.h"
|
|
28
|
+
#include "mupdf/fitz/output.h"
|
|
29
|
+
#include "mupdf/fitz/log.h"
|
|
30
|
+
#include "mupdf/fitz/types.h"
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
Resource store
|
|
34
|
+
|
|
35
|
+
MuPDF stores decoded "objects" into a store for potential reuse.
|
|
36
|
+
If the size of the store gets too big, objects stored within it
|
|
37
|
+
can be evicted and freed to recover space. When MuPDF comes to
|
|
38
|
+
decode such an object, it will check to see if a version of this
|
|
39
|
+
object is already in the store - if it is, it will simply reuse
|
|
40
|
+
it. If not, it will decode it and place it into the store.
|
|
41
|
+
|
|
42
|
+
All objects that can be placed into the store are derived from
|
|
43
|
+
the fz_storable type (i.e. this should be the first component of
|
|
44
|
+
the objects structure). This allows for consistent (thread safe)
|
|
45
|
+
reference counting, and includes a function that will be called
|
|
46
|
+
to free the object as soon as the reference count reaches zero.
|
|
47
|
+
|
|
48
|
+
Most objects offer fz_keep_XXXX/fz_drop_XXXX functions derived
|
|
49
|
+
from fz_keep_storable/fz_drop_storable. Creation of such objects
|
|
50
|
+
includes a call to FZ_INIT_STORABLE to set up the fz_storable
|
|
51
|
+
header.
|
|
52
|
+
*/
|
|
53
|
+
typedef struct fz_storable fz_storable;
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
Function type for a function to drop a storable object.
|
|
57
|
+
|
|
58
|
+
Objects within the store are identified by type by comparing
|
|
59
|
+
their drop_fn pointers.
|
|
60
|
+
*/
|
|
61
|
+
typedef void (fz_store_drop_fn)(fz_context *, fz_storable *);
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
Function type for a function to check whether a storable
|
|
65
|
+
object can be dropped at the moment.
|
|
66
|
+
|
|
67
|
+
Return 0 for 'cannot be dropped', 1 otherwise.
|
|
68
|
+
*/
|
|
69
|
+
typedef int (fz_store_droppable_fn)(fz_context *, fz_storable *);
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
Any storable object should include an fz_storable structure
|
|
73
|
+
at the start (by convention at least) of their structure.
|
|
74
|
+
(Unless it starts with an fz_key_storable, see below).
|
|
75
|
+
*/
|
|
76
|
+
struct fz_storable {
|
|
77
|
+
int refs;
|
|
78
|
+
fz_store_drop_fn *drop;
|
|
79
|
+
fz_store_droppable_fn *droppable;
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
Any storable object that can appear in the key of another
|
|
84
|
+
storable object should include an fz_key_storable structure
|
|
85
|
+
at the start (by convention at least) of their structure.
|
|
86
|
+
*/
|
|
87
|
+
typedef struct
|
|
88
|
+
{
|
|
89
|
+
fz_storable storable;
|
|
90
|
+
short store_key_refs;
|
|
91
|
+
} fz_key_storable;
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
Macros to initialise a storable object.
|
|
95
|
+
*/
|
|
96
|
+
#define FZ_INIT_STORABLE(S_,RC,DROP) \
|
|
97
|
+
do { fz_storable *S = &(S_)->storable; S->refs = (RC); \
|
|
98
|
+
S->drop = (DROP); S->droppable = NULL; \
|
|
99
|
+
} while (0)
|
|
100
|
+
|
|
101
|
+
#define FZ_INIT_AWKWARD_STORABLE(S_,RC,DROP,DROPPABLE) \
|
|
102
|
+
do { fz_storable *S = &(S_)->storable; S->refs = (RC); \
|
|
103
|
+
S->drop = (DROP); S->droppable = (DROPPABLE); \
|
|
104
|
+
} while (0)
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
Macro to initialise a key storable object.
|
|
108
|
+
*/
|
|
109
|
+
#define FZ_INIT_KEY_STORABLE(KS_,RC,DROP) \
|
|
110
|
+
do { fz_key_storable *KS = &(KS_)->key_storable; KS->store_key_refs = 0;\
|
|
111
|
+
FZ_INIT_STORABLE(KS,RC,DROP); \
|
|
112
|
+
} while (0)
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
Increment the reference count for a storable object.
|
|
116
|
+
Returns the same pointer.
|
|
117
|
+
|
|
118
|
+
Never throws exceptions.
|
|
119
|
+
*/
|
|
120
|
+
void *fz_keep_storable(fz_context *, const fz_storable *);
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
Decrement the reference count for a storable object. When the
|
|
124
|
+
reference count hits zero, the drop function for that object
|
|
125
|
+
is called to free the object.
|
|
126
|
+
|
|
127
|
+
Never throws exceptions.
|
|
128
|
+
*/
|
|
129
|
+
void fz_drop_storable(fz_context *, const fz_storable *);
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
Increment the (normal) reference count for a key storable
|
|
133
|
+
object. Returns the same pointer.
|
|
134
|
+
|
|
135
|
+
Never throws exceptions.
|
|
136
|
+
*/
|
|
137
|
+
void *fz_keep_key_storable(fz_context *, const fz_key_storable *);
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
Decrement the (normal) reference count for a storable object.
|
|
141
|
+
When the total reference count hits zero, the drop function for
|
|
142
|
+
that object is called to free the object.
|
|
143
|
+
|
|
144
|
+
Never throws exceptions.
|
|
145
|
+
*/
|
|
146
|
+
void fz_drop_key_storable(fz_context *, const fz_key_storable *);
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
Increment the (key) reference count for a key storable
|
|
150
|
+
object. Returns the same pointer.
|
|
151
|
+
|
|
152
|
+
Never throws exceptions.
|
|
153
|
+
*/
|
|
154
|
+
void *fz_keep_key_storable_key(fz_context *, const fz_key_storable *);
|
|
155
|
+
|
|
156
|
+
/**
|
|
157
|
+
Decrement the (key) reference count for a storable object.
|
|
158
|
+
When the total reference count hits zero, the drop function for
|
|
159
|
+
that object is called to free the object.
|
|
160
|
+
|
|
161
|
+
Never throws exceptions.
|
|
162
|
+
*/
|
|
163
|
+
void fz_drop_key_storable_key(fz_context *, const fz_key_storable *);
|
|
164
|
+
|
|
165
|
+
/**
|
|
166
|
+
The store can be seen as a dictionary that maps keys to
|
|
167
|
+
fz_storable values. In order to allow keys of different types to
|
|
168
|
+
be stored, we have a structure full of functions for each key
|
|
169
|
+
'type'; this fz_store_type pointer is stored with each key, and
|
|
170
|
+
tells the store how to perform certain operations (like taking/
|
|
171
|
+
dropping a reference, comparing two keys, outputting details for
|
|
172
|
+
debugging etc).
|
|
173
|
+
|
|
174
|
+
The store uses a hash table internally for speed where possible.
|
|
175
|
+
In order for this to work, we need a mechanism for turning a
|
|
176
|
+
generic 'key' into 'a hashable string'. For this purpose the
|
|
177
|
+
type structure contains a make_hash_key function pointer that
|
|
178
|
+
maps from a void * to a fz_store_hash structure. If
|
|
179
|
+
make_hash_key function returns 0, then the key is determined not
|
|
180
|
+
to be hashable, and the value is not stored in the hash table.
|
|
181
|
+
|
|
182
|
+
Some objects can be used both as values within the store, and as
|
|
183
|
+
a component of keys within the store. We refer to these objects
|
|
184
|
+
as "key storable" objects. In this case, we need to take
|
|
185
|
+
additional care to ensure that we do not end up keeping an item
|
|
186
|
+
within the store, purely because its value is referred to by
|
|
187
|
+
another key in the store.
|
|
188
|
+
|
|
189
|
+
An example of this are fz_images in PDF files. Each fz_image is
|
|
190
|
+
placed into the store to enable it to be easily reused. When the
|
|
191
|
+
image is rendered, a pixmap is generated from the image, and the
|
|
192
|
+
pixmap is placed into the store so it can be reused on
|
|
193
|
+
subsequent renders. The image forms part of the key for the
|
|
194
|
+
pixmap.
|
|
195
|
+
|
|
196
|
+
When we close the pdf document (and any associated pages/display
|
|
197
|
+
lists etc), we drop the images from the store. This may leave us
|
|
198
|
+
in the position of the images having non-zero reference counts
|
|
199
|
+
purely because they are used as part of the keys for the
|
|
200
|
+
pixmaps.
|
|
201
|
+
|
|
202
|
+
We therefore use special reference counting functions to keep
|
|
203
|
+
track of these "key storable" items, and hence store the number
|
|
204
|
+
of references to these items that are used in keys.
|
|
205
|
+
|
|
206
|
+
When the number of references to an object == the number of
|
|
207
|
+
references to an object from keys in the store, we know that we
|
|
208
|
+
can remove all the items which have that object as part of the
|
|
209
|
+
key. This is done by running a pass over the store, 'reaping'
|
|
210
|
+
those items.
|
|
211
|
+
|
|
212
|
+
Reap passes are slower than we would like as they touch every
|
|
213
|
+
item in the store. We therefore provide a way to 'batch' such
|
|
214
|
+
reap passes together, using fz_defer_reap_start/
|
|
215
|
+
fz_defer_reap_end to bracket a region in which many may be
|
|
216
|
+
triggered.
|
|
217
|
+
*/
|
|
218
|
+
typedef struct
|
|
219
|
+
{
|
|
220
|
+
fz_store_drop_fn *drop;
|
|
221
|
+
union
|
|
222
|
+
{
|
|
223
|
+
struct
|
|
224
|
+
{
|
|
225
|
+
const void *ptr;
|
|
226
|
+
int i;
|
|
227
|
+
} pi; /* 8 or 12 bytes */
|
|
228
|
+
struct
|
|
229
|
+
{
|
|
230
|
+
const void *ptr;
|
|
231
|
+
int i;
|
|
232
|
+
fz_irect r;
|
|
233
|
+
} pir; /* 24 or 28 bytes */
|
|
234
|
+
struct
|
|
235
|
+
{
|
|
236
|
+
int id;
|
|
237
|
+
char has_shape;
|
|
238
|
+
char has_group_alpha;
|
|
239
|
+
float m[4];
|
|
240
|
+
void *ptr;
|
|
241
|
+
int doc_id;
|
|
242
|
+
} im; /* 32 or 36 bytes */
|
|
243
|
+
struct
|
|
244
|
+
{
|
|
245
|
+
unsigned char src_md5[16];
|
|
246
|
+
unsigned char dst_md5[16];
|
|
247
|
+
unsigned int ri:2;
|
|
248
|
+
unsigned int bp:1;
|
|
249
|
+
unsigned int format:1;
|
|
250
|
+
unsigned int proof:1;
|
|
251
|
+
unsigned int src_extras:5;
|
|
252
|
+
unsigned int dst_extras:5;
|
|
253
|
+
unsigned int copy_spots:1;
|
|
254
|
+
unsigned int bgr:1;
|
|
255
|
+
} link; /* 36 bytes */
|
|
256
|
+
} u;
|
|
257
|
+
/* 0 or 4 bytes padding */
|
|
258
|
+
} fz_store_hash; /* 40 or 48 bytes */
|
|
259
|
+
|
|
260
|
+
/**
|
|
261
|
+
Every type of object to be placed into the store defines an
|
|
262
|
+
fz_store_type. This contains the pointers to functions to
|
|
263
|
+
make hashes, manipulate keys, and check for needing reaping.
|
|
264
|
+
*/
|
|
265
|
+
typedef struct
|
|
266
|
+
{
|
|
267
|
+
const char *name;
|
|
268
|
+
int (*make_hash_key)(fz_context *ctx, fz_store_hash *hash, void *key);
|
|
269
|
+
void *(*keep_key)(fz_context *ctx, void *key);
|
|
270
|
+
void (*drop_key)(fz_context *ctx, void *key);
|
|
271
|
+
int (*cmp_key)(fz_context *ctx, void *a, void *b);
|
|
272
|
+
void (*format_key)(fz_context *ctx, char *buf, size_t size, void *key);
|
|
273
|
+
int (*needs_reap)(fz_context *ctx, void *key);
|
|
274
|
+
} fz_store_type;
|
|
275
|
+
|
|
276
|
+
/**
|
|
277
|
+
Create a new store inside the context
|
|
278
|
+
|
|
279
|
+
max: The maximum size (in bytes) that the store is allowed to
|
|
280
|
+
grow to. FZ_STORE_UNLIMITED means no limit.
|
|
281
|
+
*/
|
|
282
|
+
void fz_new_store_context(fz_context *ctx, size_t max);
|
|
283
|
+
|
|
284
|
+
/**
|
|
285
|
+
Increment the reference count for the store context. Returns
|
|
286
|
+
the same pointer.
|
|
287
|
+
|
|
288
|
+
Never throws exceptions.
|
|
289
|
+
*/
|
|
290
|
+
fz_store *fz_keep_store_context(fz_context *ctx);
|
|
291
|
+
|
|
292
|
+
/**
|
|
293
|
+
Decrement the reference count for the store context. When the
|
|
294
|
+
reference count hits zero, the store context is freed.
|
|
295
|
+
|
|
296
|
+
Never throws exceptions.
|
|
297
|
+
*/
|
|
298
|
+
void fz_drop_store_context(fz_context *ctx);
|
|
299
|
+
|
|
300
|
+
/**
|
|
301
|
+
Add an item to the store.
|
|
302
|
+
|
|
303
|
+
Add an item into the store, returning NULL for success. If an
|
|
304
|
+
item with the same key is found in the store, then our item will
|
|
305
|
+
not be inserted, and the function will return a pointer to that
|
|
306
|
+
value instead. This function takes its own reference to val, as
|
|
307
|
+
required (i.e. the caller maintains ownership of its own
|
|
308
|
+
reference).
|
|
309
|
+
|
|
310
|
+
key: The key used to index the item.
|
|
311
|
+
|
|
312
|
+
val: The value to store.
|
|
313
|
+
|
|
314
|
+
itemsize: The size in bytes of the value (as counted towards the
|
|
315
|
+
store size).
|
|
316
|
+
|
|
317
|
+
type: Functions used to manipulate the key.
|
|
318
|
+
*/
|
|
319
|
+
void *fz_store_item(fz_context *ctx, void *key, void *val, size_t itemsize, const fz_store_type *type);
|
|
320
|
+
|
|
321
|
+
/**
|
|
322
|
+
Find an item within the store.
|
|
323
|
+
|
|
324
|
+
drop: The function used to free the value (to ensure we get a
|
|
325
|
+
value of the correct type).
|
|
326
|
+
|
|
327
|
+
key: The key used to index the item.
|
|
328
|
+
|
|
329
|
+
type: Functions used to manipulate the key.
|
|
330
|
+
|
|
331
|
+
Returns NULL for not found, otherwise returns a pointer to the
|
|
332
|
+
value indexed by key to which a reference has been taken.
|
|
333
|
+
*/
|
|
334
|
+
void *fz_find_item(fz_context *ctx, fz_store_drop_fn *drop, void *key, const fz_store_type *type);
|
|
335
|
+
|
|
336
|
+
/**
|
|
337
|
+
Remove an item from the store.
|
|
338
|
+
|
|
339
|
+
If an item indexed by the given key exists in the store, remove
|
|
340
|
+
it.
|
|
341
|
+
|
|
342
|
+
drop: The function used to free the value (to ensure we get a
|
|
343
|
+
value of the correct type).
|
|
344
|
+
|
|
345
|
+
key: The key used to find the item to remove.
|
|
346
|
+
|
|
347
|
+
type: Functions used to manipulate the key.
|
|
348
|
+
*/
|
|
349
|
+
void fz_remove_item(fz_context *ctx, fz_store_drop_fn *drop, void *key, const fz_store_type *type);
|
|
350
|
+
|
|
351
|
+
/**
|
|
352
|
+
Evict every item from the store.
|
|
353
|
+
*/
|
|
354
|
+
void fz_empty_store(fz_context *ctx);
|
|
355
|
+
|
|
356
|
+
/**
|
|
357
|
+
Internal function used as part of the scavenging
|
|
358
|
+
allocator; when we fail to allocate memory, before returning a
|
|
359
|
+
failure to the caller, we try to scavenge space within the store
|
|
360
|
+
by evicting at least 'size' bytes. The allocator then retries.
|
|
361
|
+
|
|
362
|
+
size: The number of bytes we are trying to have free.
|
|
363
|
+
|
|
364
|
+
phase: What phase of the scavenge we are in. Updated on exit.
|
|
365
|
+
|
|
366
|
+
Returns non zero if we managed to free any memory.
|
|
367
|
+
*/
|
|
368
|
+
int fz_store_scavenge(fz_context *ctx, size_t size, int *phase);
|
|
369
|
+
|
|
370
|
+
/**
|
|
371
|
+
External function for callers to use
|
|
372
|
+
to scavenge while trying allocations.
|
|
373
|
+
|
|
374
|
+
size: The number of bytes we are trying to have free.
|
|
375
|
+
|
|
376
|
+
phase: What phase of the scavenge we are in. Updated on exit.
|
|
377
|
+
|
|
378
|
+
Returns non zero if we managed to free any memory.
|
|
379
|
+
*/
|
|
380
|
+
int fz_store_scavenge_external(fz_context *ctx, size_t size, int *phase);
|
|
381
|
+
|
|
382
|
+
/**
|
|
383
|
+
Evict items from the store until the total size of
|
|
384
|
+
the objects in the store is reduced to a given percentage of its
|
|
385
|
+
current size.
|
|
386
|
+
|
|
387
|
+
percent: %age of current size to reduce the store to.
|
|
388
|
+
|
|
389
|
+
Returns non zero if we managed to free enough memory, zero
|
|
390
|
+
otherwise.
|
|
391
|
+
*/
|
|
392
|
+
int fz_shrink_store(fz_context *ctx, unsigned int percent);
|
|
393
|
+
|
|
394
|
+
/**
|
|
395
|
+
Callback function called by fz_filter_store on every item within
|
|
396
|
+
the store.
|
|
397
|
+
|
|
398
|
+
Return 1 to drop the item from the store, 0 to retain.
|
|
399
|
+
*/
|
|
400
|
+
typedef int (fz_store_filter_fn)(fz_context *ctx, void *arg, void *key);
|
|
401
|
+
|
|
402
|
+
/**
|
|
403
|
+
Filter every element in the store with a matching type with the
|
|
404
|
+
given function.
|
|
405
|
+
|
|
406
|
+
If the function returns 1 for an element, drop the element.
|
|
407
|
+
*/
|
|
408
|
+
void fz_filter_store(fz_context *ctx, fz_store_filter_fn *fn, void *arg, const fz_store_type *type);
|
|
409
|
+
|
|
410
|
+
/**
|
|
411
|
+
Filter the store and throw away any stored tiles drawn for a
|
|
412
|
+
given document.
|
|
413
|
+
*/
|
|
414
|
+
void fz_drop_drawn_tiles_for_document(fz_context *ctx, fz_document *doc);
|
|
415
|
+
|
|
416
|
+
/**
|
|
417
|
+
Output debugging information for the current state of the store
|
|
418
|
+
to the given output channel.
|
|
419
|
+
*/
|
|
420
|
+
void fz_debug_store(fz_context *ctx, fz_output *out);
|
|
421
|
+
|
|
422
|
+
/**
|
|
423
|
+
Increment the defer reap count.
|
|
424
|
+
|
|
425
|
+
No reap operations will take place (except for those
|
|
426
|
+
triggered by an immediate failed malloc) until the
|
|
427
|
+
defer reap count returns to 0.
|
|
428
|
+
|
|
429
|
+
Call this at the start of a process during which you
|
|
430
|
+
potentially might drop many reapable objects.
|
|
431
|
+
|
|
432
|
+
It is vital that every fz_defer_reap_start is matched
|
|
433
|
+
by a fz_defer_reap_end call.
|
|
434
|
+
*/
|
|
435
|
+
void fz_defer_reap_start(fz_context *ctx);
|
|
436
|
+
|
|
437
|
+
/**
|
|
438
|
+
Decrement the defer reap count.
|
|
439
|
+
|
|
440
|
+
If the defer reap count returns to 0, and the store
|
|
441
|
+
has reapable objects in, a reap pass will begin.
|
|
442
|
+
|
|
443
|
+
Call this at the end of a process during which you
|
|
444
|
+
potentially might drop many reapable objects.
|
|
445
|
+
|
|
446
|
+
It is vital that every fz_defer_reap_start is matched
|
|
447
|
+
by a fz_defer_reap_end call.
|
|
448
|
+
*/
|
|
449
|
+
void fz_defer_reap_end(fz_context *ctx);
|
|
450
|
+
|
|
451
|
+
#ifdef ENABLE_STORE_LOGGING
|
|
452
|
+
|
|
453
|
+
void fz_log_dump_store(fz_context *ctx, const char *fmt, ...);
|
|
454
|
+
|
|
455
|
+
#define FZ_LOG_STORE(CTX, ...) fz_log_module(CTX, "STORE", __VA_ARGS__)
|
|
456
|
+
#define FZ_LOG_DUMP_STORE(...) fz_log_dump_store(__VA_ARGS__)
|
|
457
|
+
|
|
458
|
+
#else
|
|
459
|
+
|
|
460
|
+
#define FZ_LOG_STORE(...) do {} while (0)
|
|
461
|
+
#define FZ_LOG_DUMP_STORE(...) do {} while (0)
|
|
462
|
+
|
|
463
|
+
#endif
|
|
464
|
+
|
|
465
|
+
#endif
|
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
// Copyright (C) 2022-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_FITZ_STORY_WRITER_H
|
|
24
|
+
#define MUPDF_FITZ_STORY_WRITER_H
|
|
25
|
+
|
|
26
|
+
#include "mupdf/fitz/story.h"
|
|
27
|
+
#include "mupdf/fitz/writer.h"
|
|
28
|
+
|
|
29
|
+
/*
|
|
30
|
+
* A fz_story_element_position plus page number information; used with
|
|
31
|
+
* fz_write_story() and fz_write_stabilized_story().
|
|
32
|
+
*/
|
|
33
|
+
typedef struct
|
|
34
|
+
{
|
|
35
|
+
fz_story_element_position element;
|
|
36
|
+
int page_num;
|
|
37
|
+
} fz_write_story_position;
|
|
38
|
+
|
|
39
|
+
/*
|
|
40
|
+
* A set of fz_write_story_position items; used with
|
|
41
|
+
* fz_write_stabilized_story().
|
|
42
|
+
*/
|
|
43
|
+
typedef struct
|
|
44
|
+
{
|
|
45
|
+
fz_write_story_position *positions;
|
|
46
|
+
int num;
|
|
47
|
+
} fz_write_story_positions;
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
/*
|
|
51
|
+
* Callback type used by fz_write_story() and fz_write_stabilized_story().
|
|
52
|
+
*
|
|
53
|
+
* Should set *rect to rect number <num>. If this is on a new page should also
|
|
54
|
+
* set *mediabox and return 1, otherwise return 0.
|
|
55
|
+
*
|
|
56
|
+
* ref:
|
|
57
|
+
* As passed to fz_write_story() or fz_write_stabilized_story().
|
|
58
|
+
* num:
|
|
59
|
+
* The rect number. Will typically increment by one each time, being reset
|
|
60
|
+
* to zero when fz_write_stabilized_story() starts a new iteration.
|
|
61
|
+
* filled:
|
|
62
|
+
* From earlier internal call to fz_place_story().
|
|
63
|
+
* rect:
|
|
64
|
+
* Out param.
|
|
65
|
+
* ctm:
|
|
66
|
+
* Out param, defaults to fz_identity.
|
|
67
|
+
* mediabox:
|
|
68
|
+
* Out param, only used if we return 1.
|
|
69
|
+
*/
|
|
70
|
+
typedef int (fz_write_story_rectfn)(fz_context *ctx, void *ref, int num, fz_rect filled, fz_rect *rect, fz_matrix *ctm, fz_rect *mediabox);
|
|
71
|
+
|
|
72
|
+
/*
|
|
73
|
+
* Callback used by fz_write_story() to report information about element
|
|
74
|
+
* positions. Slightly different from fz_story_position_callback() because
|
|
75
|
+
* <position> also includes the page number.
|
|
76
|
+
*
|
|
77
|
+
* ref:
|
|
78
|
+
* As passed to fz_write_story() or fz_write_stabilized_story().
|
|
79
|
+
* position:
|
|
80
|
+
* Called via internal call to fz_story_position_callback().
|
|
81
|
+
*/
|
|
82
|
+
typedef void (fz_write_story_positionfn)(fz_context *ctx, void *ref, const fz_write_story_position *position);
|
|
83
|
+
|
|
84
|
+
/*
|
|
85
|
+
* Callback for fz_write_story(), called twice for each page, before (after=0)
|
|
86
|
+
* and after (after=1) the story is written.
|
|
87
|
+
*
|
|
88
|
+
* ref:
|
|
89
|
+
* As passed to fz_write_story() or fz_write_stabilized_story().
|
|
90
|
+
* page_num:
|
|
91
|
+
* Page number, starting from 1.
|
|
92
|
+
* mediabox:
|
|
93
|
+
* As returned from fz_write_story_rectfn().
|
|
94
|
+
* dev:
|
|
95
|
+
* Created from the fz_writer passed to fz_write_story() or
|
|
96
|
+
* fz_write_stabilized_story().
|
|
97
|
+
* after:
|
|
98
|
+
* 0 - before writing the story.
|
|
99
|
+
* 1 - after writing the story.
|
|
100
|
+
*/
|
|
101
|
+
typedef void (fz_write_story_pagefn)(fz_context *ctx, void *ref, int page_num, fz_rect mediabox, fz_device *dev, int after);
|
|
102
|
+
|
|
103
|
+
/*
|
|
104
|
+
* Callback type for fz_write_stabilized_story().
|
|
105
|
+
*
|
|
106
|
+
* Should populate the supplied buffer with html content for use with internal
|
|
107
|
+
* calls to fz_new_story(). This may include extra content derived from
|
|
108
|
+
* information in <positions>, for example a table of contents.
|
|
109
|
+
*
|
|
110
|
+
* ref:
|
|
111
|
+
* As passed to fz_write_stabilized_story().
|
|
112
|
+
* positions:
|
|
113
|
+
* Information from previous iteration.
|
|
114
|
+
* buffer:
|
|
115
|
+
* Where to write the new content. Will be initially empty.
|
|
116
|
+
*/
|
|
117
|
+
typedef void (fz_write_story_contentfn)(fz_context *ctx, void *ref, const fz_write_story_positions *positions, fz_buffer *buffer);
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
/*
|
|
121
|
+
* Places and writes a story to a fz_document_writer. Avoids the need
|
|
122
|
+
* for calling code to implement a loop that calls fz_place_story()
|
|
123
|
+
* and fz_draw_story() etc, at the expense of having to provide a
|
|
124
|
+
* fz_write_story_rectfn() callback.
|
|
125
|
+
*
|
|
126
|
+
* story:
|
|
127
|
+
* The story to place and write.
|
|
128
|
+
* writer:
|
|
129
|
+
* Where to write the story; can be NULL.
|
|
130
|
+
* rectfn:
|
|
131
|
+
* Should return information about the rect to be used in the next
|
|
132
|
+
* internal call to fz_place_story().
|
|
133
|
+
* rectfn_ref:
|
|
134
|
+
* Passed to rectfn().
|
|
135
|
+
* positionfn:
|
|
136
|
+
* If not NULL, is called via internal calls to fz_story_positions().
|
|
137
|
+
* positionfn_ref:
|
|
138
|
+
* Passed to positionfn().
|
|
139
|
+
* pagefn:
|
|
140
|
+
* If not NULL, called at start and end of each page (before and after all
|
|
141
|
+
* story content has been written to the device).
|
|
142
|
+
* pagefn_ref:
|
|
143
|
+
* Passed to pagefn().
|
|
144
|
+
*/
|
|
145
|
+
void fz_write_story(
|
|
146
|
+
fz_context *ctx,
|
|
147
|
+
fz_document_writer *writer,
|
|
148
|
+
fz_story *story,
|
|
149
|
+
fz_write_story_rectfn rectfn,
|
|
150
|
+
void *rectfn_ref,
|
|
151
|
+
fz_write_story_positionfn positionfn,
|
|
152
|
+
void *positionfn_ref,
|
|
153
|
+
fz_write_story_pagefn pagefn,
|
|
154
|
+
void *pagefn_ref
|
|
155
|
+
);
|
|
156
|
+
|
|
157
|
+
|
|
158
|
+
/*
|
|
159
|
+
* Does iterative layout of html content to a fz_document_writer. For example
|
|
160
|
+
* this allows one to add a table of contents section while ensuring that page
|
|
161
|
+
* numbers are patched up until stable.
|
|
162
|
+
*
|
|
163
|
+
* Repeatedly creates new story from (contentfn(), contentfn_ref, user_css, em)
|
|
164
|
+
* and lays it out with internal call to fz_write_story(); uses a NULL writer
|
|
165
|
+
* and populates a fz_write_story_positions which is passed to the next call of
|
|
166
|
+
* contentfn().
|
|
167
|
+
*
|
|
168
|
+
* When the html from contentfn() becomes unchanged, we do a final iteration
|
|
169
|
+
* using <writer>.
|
|
170
|
+
*
|
|
171
|
+
* writer:
|
|
172
|
+
* Where to write in the final iteration.
|
|
173
|
+
* user_css:
|
|
174
|
+
* Used in internal calls to fz_new_story().
|
|
175
|
+
* em:
|
|
176
|
+
* Used in internal calls to fz_new_story().
|
|
177
|
+
* contentfn:
|
|
178
|
+
* Should return html content for use with fz_new_story(), possibly
|
|
179
|
+
* including extra content such as a table-of-contents.
|
|
180
|
+
* contentfn_ref:
|
|
181
|
+
* Passed to contentfn().
|
|
182
|
+
* rectfn:
|
|
183
|
+
* Should return information about the rect to be used in the next
|
|
184
|
+
* internal call to fz_place_story().
|
|
185
|
+
* rectfn_ref:
|
|
186
|
+
* Passed to rectfn().
|
|
187
|
+
* fz_write_story_pagefn:
|
|
188
|
+
* If not NULL, called at start and end of each page (before and after all
|
|
189
|
+
* story content has been written to the device).
|
|
190
|
+
* pagefn_ref:
|
|
191
|
+
* Passed to pagefn().
|
|
192
|
+
* dir:
|
|
193
|
+
* NULL, or a directory context to load images etc from.
|
|
194
|
+
*/
|
|
195
|
+
void fz_write_stabilized_story(
|
|
196
|
+
fz_context *ctx,
|
|
197
|
+
fz_document_writer *writer,
|
|
198
|
+
const char *user_css,
|
|
199
|
+
float em,
|
|
200
|
+
fz_write_story_contentfn contentfn,
|
|
201
|
+
void *contentfn_ref,
|
|
202
|
+
fz_write_story_rectfn rectfn,
|
|
203
|
+
void *rectfn_ref,
|
|
204
|
+
fz_write_story_pagefn pagefn,
|
|
205
|
+
void *pagefn_ref,
|
|
206
|
+
fz_archive *dir
|
|
207
|
+
);
|
|
208
|
+
|
|
209
|
+
#endif
|