quickwin 2026.5.2-3.145209
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.
- package/README.md +6 -0
- package/examples/pdf_preview.js +440 -0
- package/examples/pdf_preview.ts +470 -0
- package/examples/preact_demo.js +35 -0
- package/examples/preact_demo.tsx +49 -0
- package/examples/tray_demo.js +75 -0
- package/examples/tray_demo.tsx +79 -0
- package/lib/fetch.js +746 -0
- package/lib/fetch.ts +811 -0
- package/lib/polyfill.js +500 -0
- package/lib/polyfill.ts +454 -0
- package/lib/preact/hooks.js +287 -0
- package/lib/preact/hooks.ts +330 -0
- package/lib/preact/jsx-runtime.js +1 -0
- package/lib/preact/jsx-runtime.ts +2 -0
- package/lib/preact/jsx.d.ts +36 -0
- package/lib/preact/layout.js +153 -0
- package/lib/preact/layout.ts +183 -0
- package/lib/preact/preact.js +54 -0
- package/lib/preact/preact.ts +133 -0
- package/lib/preact/props.js +99 -0
- package/lib/preact/props.ts +119 -0
- package/lib/preact/render.js +320 -0
- package/lib/preact/render.ts +353 -0
- package/lib/websocket.js +540 -0
- package/lib/websocket.ts +574 -0
- package/package.json +32 -0
- package/quickwin.d.ts +657 -0
- package/test/add.wasm +0 -0
- package/test/complex.wasm +0 -0
- package/test/complex_imports.wasm +0 -0
- package/test/global_imports.wasm +0 -0
- package/test/import_func.wasm +0 -0
- package/test/imports.wasm +0 -0
- package/test/run.js +86 -0
- package/test/run.ts +90 -0
- package/test/sjlj.wasm +0 -0
- package/test/test_basic.js +7 -0
- package/test/test_basic.ts +9 -0
- package/test/test_brotli.js +48 -0
- package/test/test_brotli.ts +52 -0
- package/test/test_fetch_cache.js +131 -0
- package/test/test_fetch_cache.ts +141 -0
- package/test/test_ffi.js +157 -0
- package/test/test_ffi.ts +174 -0
- package/test/test_frame_encoding.js +128 -0
- package/test/test_frame_encoding.ts +132 -0
- package/test/test_helper.js +84 -0
- package/test/test_helper.ts +80 -0
- package/test/test_http_import.js +78 -0
- package/test/test_http_import.ts +74 -0
- package/test/test_mupdf_render.js +69 -0
- package/test/test_mupdf_render.ts +74 -0
- package/test/test_mupdf_twice.js +77 -0
- package/test/test_mupdf_twice.ts +81 -0
- package/test/test_mupdf_wasm.js +33 -0
- package/test/test_mupdf_wasm.ts +30 -0
- package/test/test_net_event.js +63 -0
- package/test/test_net_event.ts +59 -0
- package/test/test_net_fetch.js +153 -0
- package/test/test_net_fetch.ts +131 -0
- package/test/test_net_websocket.js +158 -0
- package/test/test_net_websocket.ts +144 -0
- package/test/test_polyfill.js +58 -0
- package/test/test_polyfill.ts +60 -0
- package/test/test_url.js +173 -0
- package/test/test_url.ts +183 -0
- package/test/test_wasm_basic.js +82 -0
- package/test/test_wasm_basic.ts +70 -0
- package/test/test_wasm_import_global.js +41 -0
- package/test/test_wasm_import_global.ts +39 -0
- package/test/test_wasm_sjlj.js +153 -0
- package/test/test_wasm_sjlj.ts +134 -0
- package/test/test_wasm_types.js +96 -0
- package/test/test_wasm_types.ts +108 -0
- package/test/types.wasm +0 -0
- package/tsconfig.json +18 -0
- package/vendor/mupdf-wasm/mupdf-wasm.d.ts +571 -0
- package/vendor/mupdf-wasm/mupdf-wasm.js +2749 -0
- package/vendor/mupdf-wasm/mupdf-wasm.wasm +0 -0
- package/vendor/mupdf-wasm/mupdf.d.ts +939 -0
- package/vendor/mupdf-wasm/mupdf.js +3317 -0
- package/win-mingw64.exe +0 -0
|
@@ -0,0 +1,3317 @@
|
|
|
1
|
+
// Copyright (C) 2004-2026 Artifex Software, Inc.
|
|
2
|
+
//
|
|
3
|
+
// This file is part of MuPDF WASM Library.
|
|
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
|
+
"use strict";
|
|
23
|
+
import libmupdf_wasm from "./mupdf-wasm.js";
|
|
24
|
+
var node_fs = null;
|
|
25
|
+
if (typeof process !== "undefined" && process.versions && process.versions.node)
|
|
26
|
+
node_fs = await import("node:fs");
|
|
27
|
+
const libmupdf = await libmupdf_wasm(globalThis["$libmupdf_wasm_Module"]);
|
|
28
|
+
libmupdf._wasm_init_context();
|
|
29
|
+
function Malloc(size) {
|
|
30
|
+
return libmupdf._wasm_malloc(size);
|
|
31
|
+
}
|
|
32
|
+
function Free(ptr) {
|
|
33
|
+
libmupdf._wasm_free(ptr);
|
|
34
|
+
}
|
|
35
|
+
export const memento = {
|
|
36
|
+
listBlocks() {
|
|
37
|
+
libmupdf._wasm_Memento_listBlocks();
|
|
38
|
+
},
|
|
39
|
+
checkAllMemory() {
|
|
40
|
+
libmupdf._wasm_Memento_checkAllMemory();
|
|
41
|
+
},
|
|
42
|
+
};
|
|
43
|
+
export const Matrix = {
|
|
44
|
+
identity: [1, 0, 0, 1, 0, 0],
|
|
45
|
+
scale(sx, sy) {
|
|
46
|
+
return [sx, 0, 0, sy, 0, 0];
|
|
47
|
+
},
|
|
48
|
+
translate(tx, ty) {
|
|
49
|
+
return [1, 0, 0, 1, tx, ty];
|
|
50
|
+
},
|
|
51
|
+
rotate(d) {
|
|
52
|
+
while (d < 0)
|
|
53
|
+
d += 360;
|
|
54
|
+
while (d >= 360)
|
|
55
|
+
d -= 360;
|
|
56
|
+
let s = Math.sin((d * Math.PI) / 180);
|
|
57
|
+
let c = Math.cos((d * Math.PI) / 180);
|
|
58
|
+
return [c, s, -s, c, 0, 0];
|
|
59
|
+
},
|
|
60
|
+
invert(m) {
|
|
61
|
+
checkMatrix(m);
|
|
62
|
+
let det = m[0] * m[3] - m[1] * m[2];
|
|
63
|
+
if (det > -1e-23 && det < 1e-23)
|
|
64
|
+
return m;
|
|
65
|
+
let rdet = 1 / det;
|
|
66
|
+
let inva = m[3] * rdet;
|
|
67
|
+
let invb = -m[1] * rdet;
|
|
68
|
+
let invc = -m[2] * rdet;
|
|
69
|
+
let invd = m[0] * rdet;
|
|
70
|
+
let inve = -m[4] * inva - m[5] * invc;
|
|
71
|
+
let invf = -m[4] * invb - m[5] * invd;
|
|
72
|
+
return [inva, invb, invc, invd, inve, invf];
|
|
73
|
+
},
|
|
74
|
+
concat(one, two) {
|
|
75
|
+
checkMatrix(one);
|
|
76
|
+
checkMatrix(two);
|
|
77
|
+
return [
|
|
78
|
+
one[0] * two[0] + one[1] * two[2],
|
|
79
|
+
one[0] * two[1] + one[1] * two[3],
|
|
80
|
+
one[2] * two[0] + one[3] * two[2],
|
|
81
|
+
one[2] * two[1] + one[3] * two[3],
|
|
82
|
+
one[4] * two[0] + one[5] * two[2] + two[4],
|
|
83
|
+
one[4] * two[1] + one[5] * two[3] + two[5],
|
|
84
|
+
];
|
|
85
|
+
},
|
|
86
|
+
};
|
|
87
|
+
export const Rect = {
|
|
88
|
+
MIN_INF_RECT: 0x80000000,
|
|
89
|
+
MAX_INF_RECT: 0x7fffff80,
|
|
90
|
+
empty: [0x80000000, 0x80000000, 0x7fffff80, 0x7fffff80],
|
|
91
|
+
invalid: [0, 0, -1, -1],
|
|
92
|
+
infinite: [0x7fffff80, 0x7fffff80, 0x80000000, 0x80000000],
|
|
93
|
+
isEmpty: function (rect) {
|
|
94
|
+
checkRect(rect);
|
|
95
|
+
return rect[0] >= rect[2] || rect[1] >= rect[3];
|
|
96
|
+
},
|
|
97
|
+
isValid: function (rect) {
|
|
98
|
+
checkRect(rect);
|
|
99
|
+
return rect[0] <= rect[2] && rect[1] <= rect[3];
|
|
100
|
+
},
|
|
101
|
+
isInfinite: function (rect) {
|
|
102
|
+
checkRect(rect);
|
|
103
|
+
return (rect[0] === Rect.MAX_INF_RECT &&
|
|
104
|
+
rect[1] === Rect.MAX_INF_RECT &&
|
|
105
|
+
rect[2] === Rect.MIN_INF_RECT &&
|
|
106
|
+
rect[3] === Rect.MIN_INF_RECT);
|
|
107
|
+
},
|
|
108
|
+
transform: function (rect, matrix) {
|
|
109
|
+
checkRect(rect);
|
|
110
|
+
checkMatrix(matrix);
|
|
111
|
+
var t;
|
|
112
|
+
if (Rect.isInfinite(rect))
|
|
113
|
+
return rect;
|
|
114
|
+
if (!Rect.isValid(rect))
|
|
115
|
+
return rect;
|
|
116
|
+
var ax0 = rect[0] * matrix[0];
|
|
117
|
+
var ax1 = rect[2] * matrix[0];
|
|
118
|
+
if (ax0 > ax1)
|
|
119
|
+
t = ax0, ax0 = ax1, ax1 = t;
|
|
120
|
+
var cy0 = rect[1] * matrix[2];
|
|
121
|
+
var cy1 = rect[3] * matrix[2];
|
|
122
|
+
if (cy0 > cy1)
|
|
123
|
+
t = cy0, cy0 = cy1, cy1 = t;
|
|
124
|
+
ax0 += cy0 + matrix[4];
|
|
125
|
+
ax1 += cy1 + matrix[4];
|
|
126
|
+
var bx0 = rect[0] * matrix[1];
|
|
127
|
+
var bx1 = rect[2] * matrix[1];
|
|
128
|
+
if (bx0 > bx1)
|
|
129
|
+
t = bx0, bx0 = bx1, bx1 = t;
|
|
130
|
+
var dy0 = rect[1] * matrix[3];
|
|
131
|
+
var dy1 = rect[3] * matrix[3];
|
|
132
|
+
if (dy0 > dy1)
|
|
133
|
+
t = dy0, dy0 = dy1, dy1 = t;
|
|
134
|
+
bx0 += dy0 + matrix[5];
|
|
135
|
+
bx1 += dy1 + matrix[5];
|
|
136
|
+
return [ax0, bx0, ax1, bx1];
|
|
137
|
+
},
|
|
138
|
+
};
|
|
139
|
+
export function enableICC() {
|
|
140
|
+
libmupdf._wasm_enable_icc();
|
|
141
|
+
}
|
|
142
|
+
export function disableICC() {
|
|
143
|
+
libmupdf._wasm_disable_icc();
|
|
144
|
+
}
|
|
145
|
+
export function setUserCSS(text) {
|
|
146
|
+
libmupdf._wasm_set_user_css(STRING(text));
|
|
147
|
+
}
|
|
148
|
+
export function emptyStore() {
|
|
149
|
+
libmupdf._wasm_empty_store();
|
|
150
|
+
}
|
|
151
|
+
export function shrinkStore(percent) {
|
|
152
|
+
return libmupdf._wasm_shrink_store(percent);
|
|
153
|
+
}
|
|
154
|
+
export function installLoadFontFunction(f) {
|
|
155
|
+
$libmupdf_load_font_file_js = f;
|
|
156
|
+
}
|
|
157
|
+
var $libmupdf_log = null;
|
|
158
|
+
globalThis.$libmupdf_log_error = function (message) {
|
|
159
|
+
$libmupdf_log?.error?.(fromString(message));
|
|
160
|
+
};
|
|
161
|
+
globalThis.$libmupdf_log_warning = function (message) {
|
|
162
|
+
$libmupdf_log?.warning?.(fromString(message));
|
|
163
|
+
};
|
|
164
|
+
export function setLog(log) {
|
|
165
|
+
if (typeof log === "function") {
|
|
166
|
+
$libmupdf_log = { error: log, warning: log };
|
|
167
|
+
}
|
|
168
|
+
else {
|
|
169
|
+
$libmupdf_log = log;
|
|
170
|
+
}
|
|
171
|
+
libmupdf._wasm_enable_log_callback(log !== null);
|
|
172
|
+
}
|
|
173
|
+
/* -------------------------------------------------------------------------- */
|
|
174
|
+
// To pass Rect and Matrix as pointer arguments
|
|
175
|
+
const _wasm_int = Malloc(4);
|
|
176
|
+
const _wasm_point = Malloc(4 * 6) >> 2;
|
|
177
|
+
const _wasm_rect = Malloc(4 * 8) >> 2;
|
|
178
|
+
const _wasm_matrix = Malloc(4 * 6) >> 2;
|
|
179
|
+
const _wasm_color = Malloc(4 * 4) >> 2;
|
|
180
|
+
const _wasm_quad = Malloc(4 * 8) >> 2;
|
|
181
|
+
const _wasm_string = [0, 0];
|
|
182
|
+
function checkType(value, type) {
|
|
183
|
+
if (typeof type === "string" && typeof value !== type)
|
|
184
|
+
throw new TypeError("expected " + type);
|
|
185
|
+
if (typeof type === "function" && !(value instanceof type))
|
|
186
|
+
throw new TypeError("expected " + type.name);
|
|
187
|
+
}
|
|
188
|
+
function checkPoint(value) {
|
|
189
|
+
if (!Array.isArray(value) || value.length !== 2)
|
|
190
|
+
throw new TypeError("expected point");
|
|
191
|
+
}
|
|
192
|
+
function checkRect(value) {
|
|
193
|
+
if (!Array.isArray(value) || value.length !== 4)
|
|
194
|
+
throw new TypeError("expected rectangle");
|
|
195
|
+
}
|
|
196
|
+
function checkMatrix(value) {
|
|
197
|
+
if (!Array.isArray(value) || value.length !== 6)
|
|
198
|
+
throw new TypeError("expected matrix");
|
|
199
|
+
}
|
|
200
|
+
function checkQuad(value) {
|
|
201
|
+
if (!Array.isArray(value) || value.length !== 8)
|
|
202
|
+
throw new TypeError("expected quad");
|
|
203
|
+
}
|
|
204
|
+
function checkColor(value) {
|
|
205
|
+
if (!Array.isArray(value) || (value.length !== 1 && value.length !== 3 && value.length !== 4))
|
|
206
|
+
throw new TypeError("expected color array");
|
|
207
|
+
}
|
|
208
|
+
function checkAnnotColor(value) {
|
|
209
|
+
if (!Array.isArray(value) || (value.length !== 0 && value.length !== 1 && value.length !== 3 && value.length !== 4))
|
|
210
|
+
throw new TypeError("expected color array");
|
|
211
|
+
}
|
|
212
|
+
function BUFFER(input) {
|
|
213
|
+
if (input instanceof Buffer)
|
|
214
|
+
return input.pointer;
|
|
215
|
+
if (input instanceof ArrayBuffer || input instanceof Uint8Array)
|
|
216
|
+
return new Buffer(input).pointer;
|
|
217
|
+
if (typeof input === "string")
|
|
218
|
+
return new Buffer(input).pointer;
|
|
219
|
+
throw new TypeError("expected buffer");
|
|
220
|
+
}
|
|
221
|
+
function ENUM(value, list) {
|
|
222
|
+
if (typeof value === "number") {
|
|
223
|
+
if (value >= 0 && value < list.length)
|
|
224
|
+
return value;
|
|
225
|
+
}
|
|
226
|
+
if (typeof value === "string") {
|
|
227
|
+
let idx = list.indexOf(value);
|
|
228
|
+
if (idx >= 0)
|
|
229
|
+
return idx;
|
|
230
|
+
}
|
|
231
|
+
throw new TypeError(`invalid enum value ("${value}"; expected ${list.join(", ")})`);
|
|
232
|
+
}
|
|
233
|
+
function allocateUTF8(str) {
|
|
234
|
+
var size = libmupdf.lengthBytesUTF8(str) + 1;
|
|
235
|
+
var pointer = Malloc(size);
|
|
236
|
+
libmupdf.stringToUTF8(str, pointer, size);
|
|
237
|
+
return pointer;
|
|
238
|
+
}
|
|
239
|
+
function STRING_N(s, i) {
|
|
240
|
+
if (_wasm_string[i]) {
|
|
241
|
+
Free(_wasm_string[i]);
|
|
242
|
+
_wasm_string[i] = 0;
|
|
243
|
+
}
|
|
244
|
+
return _wasm_string[i] = allocateUTF8(s);
|
|
245
|
+
}
|
|
246
|
+
function STRING(s) {
|
|
247
|
+
return STRING_N(s, 0);
|
|
248
|
+
}
|
|
249
|
+
function STRING2(s) {
|
|
250
|
+
return STRING_N(s, 1);
|
|
251
|
+
}
|
|
252
|
+
function STRING_OPT(s) {
|
|
253
|
+
return typeof s === "string" ? STRING_N(s, 0) : 0;
|
|
254
|
+
}
|
|
255
|
+
function STRING2_OPT(s) {
|
|
256
|
+
return typeof s === "string" ? STRING_N(s, 1) : 0;
|
|
257
|
+
}
|
|
258
|
+
function POINT(p) {
|
|
259
|
+
libmupdf.HEAPF32[_wasm_point + 0] = p[0];
|
|
260
|
+
libmupdf.HEAPF32[_wasm_point + 1] = p[1];
|
|
261
|
+
return _wasm_point << 2;
|
|
262
|
+
}
|
|
263
|
+
function POINT2(p) {
|
|
264
|
+
libmupdf.HEAPF32[_wasm_point + 2] = p[0];
|
|
265
|
+
libmupdf.HEAPF32[_wasm_point + 3] = p[1];
|
|
266
|
+
return (_wasm_point + 2) << 2;
|
|
267
|
+
}
|
|
268
|
+
function POINT3(p) {
|
|
269
|
+
libmupdf.HEAPF32[_wasm_point + 4] = p[0];
|
|
270
|
+
libmupdf.HEAPF32[_wasm_point + 5] = p[1];
|
|
271
|
+
return (_wasm_point + 4) << 2;
|
|
272
|
+
}
|
|
273
|
+
function RECT(r) {
|
|
274
|
+
libmupdf.HEAPF32[_wasm_rect + 0] = r[0];
|
|
275
|
+
libmupdf.HEAPF32[_wasm_rect + 1] = r[1];
|
|
276
|
+
libmupdf.HEAPF32[_wasm_rect + 2] = r[2];
|
|
277
|
+
libmupdf.HEAPF32[_wasm_rect + 3] = r[3];
|
|
278
|
+
return _wasm_rect << 2;
|
|
279
|
+
}
|
|
280
|
+
function RECT2(r) {
|
|
281
|
+
libmupdf.HEAPF32[_wasm_rect + 4] = r[0];
|
|
282
|
+
libmupdf.HEAPF32[_wasm_rect + 5] = r[1];
|
|
283
|
+
libmupdf.HEAPF32[_wasm_rect + 6] = r[2];
|
|
284
|
+
libmupdf.HEAPF32[_wasm_rect + 7] = r[3];
|
|
285
|
+
return (_wasm_rect + 4) << 2;
|
|
286
|
+
}
|
|
287
|
+
function MATRIX(m) {
|
|
288
|
+
libmupdf.HEAPF32[_wasm_matrix + 0] = m[0];
|
|
289
|
+
libmupdf.HEAPF32[_wasm_matrix + 1] = m[1];
|
|
290
|
+
libmupdf.HEAPF32[_wasm_matrix + 2] = m[2];
|
|
291
|
+
libmupdf.HEAPF32[_wasm_matrix + 3] = m[3];
|
|
292
|
+
libmupdf.HEAPF32[_wasm_matrix + 4] = m[4];
|
|
293
|
+
libmupdf.HEAPF32[_wasm_matrix + 5] = m[5];
|
|
294
|
+
return _wasm_matrix << 2;
|
|
295
|
+
}
|
|
296
|
+
function QUAD(q) {
|
|
297
|
+
libmupdf.HEAPF32[_wasm_quad + 0] = q[0];
|
|
298
|
+
libmupdf.HEAPF32[_wasm_quad + 1] = q[1];
|
|
299
|
+
libmupdf.HEAPF32[_wasm_quad + 2] = q[2];
|
|
300
|
+
libmupdf.HEAPF32[_wasm_quad + 3] = q[3];
|
|
301
|
+
libmupdf.HEAPF32[_wasm_quad + 4] = q[4];
|
|
302
|
+
libmupdf.HEAPF32[_wasm_quad + 5] = q[5];
|
|
303
|
+
libmupdf.HEAPF32[_wasm_quad + 6] = q[6];
|
|
304
|
+
libmupdf.HEAPF32[_wasm_quad + 7] = q[7];
|
|
305
|
+
return _wasm_quad << 2;
|
|
306
|
+
}
|
|
307
|
+
function COLOR(c) {
|
|
308
|
+
if (typeof c !== "undefined") {
|
|
309
|
+
switch (c.length) {
|
|
310
|
+
case 0:
|
|
311
|
+
break;
|
|
312
|
+
case 1:
|
|
313
|
+
libmupdf.HEAPF32[_wasm_color + 0] = c[0];
|
|
314
|
+
break;
|
|
315
|
+
case 3:
|
|
316
|
+
libmupdf.HEAPF32[_wasm_color + 0] = c[0];
|
|
317
|
+
libmupdf.HEAPF32[_wasm_color + 1] = c[1];
|
|
318
|
+
libmupdf.HEAPF32[_wasm_color + 2] = c[2];
|
|
319
|
+
break;
|
|
320
|
+
case 4:
|
|
321
|
+
libmupdf.HEAPF32[_wasm_color + 0] = c[0];
|
|
322
|
+
libmupdf.HEAPF32[_wasm_color + 1] = c[1];
|
|
323
|
+
libmupdf.HEAPF32[_wasm_color + 2] = c[2];
|
|
324
|
+
libmupdf.HEAPF32[_wasm_color + 3] = c[3];
|
|
325
|
+
break;
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
return _wasm_color << 2;
|
|
329
|
+
}
|
|
330
|
+
/* -------------------------------------------------------------------------- */
|
|
331
|
+
function fromColor(n) {
|
|
332
|
+
if (n === 1)
|
|
333
|
+
return [
|
|
334
|
+
libmupdf.HEAPF32[_wasm_color]
|
|
335
|
+
];
|
|
336
|
+
if (n === 3)
|
|
337
|
+
return [
|
|
338
|
+
libmupdf.HEAPF32[_wasm_color + 0],
|
|
339
|
+
libmupdf.HEAPF32[_wasm_color + 1],
|
|
340
|
+
libmupdf.HEAPF32[_wasm_color + 2],
|
|
341
|
+
];
|
|
342
|
+
if (n === 4)
|
|
343
|
+
return [
|
|
344
|
+
libmupdf.HEAPF32[_wasm_color + 0],
|
|
345
|
+
libmupdf.HEAPF32[_wasm_color + 1],
|
|
346
|
+
libmupdf.HEAPF32[_wasm_color + 2],
|
|
347
|
+
libmupdf.HEAPF32[_wasm_color + 3],
|
|
348
|
+
];
|
|
349
|
+
throw new TypeError("invalid number of components for Color: " + n);
|
|
350
|
+
}
|
|
351
|
+
function fromAnnotColor(n) {
|
|
352
|
+
if (n === 0)
|
|
353
|
+
return [];
|
|
354
|
+
return fromColor(n);
|
|
355
|
+
}
|
|
356
|
+
function fromColorArray(n, ptr) {
|
|
357
|
+
let addr = ptr >> 2;
|
|
358
|
+
let color = [];
|
|
359
|
+
for (let i = 0; i < n; ++i)
|
|
360
|
+
color.push(libmupdf.HEAPF32[addr + i]);
|
|
361
|
+
return color;
|
|
362
|
+
}
|
|
363
|
+
function fromStringOrNull(ptr) {
|
|
364
|
+
if (ptr === 0)
|
|
365
|
+
return null;
|
|
366
|
+
return libmupdf.UTF8ToString(ptr);
|
|
367
|
+
}
|
|
368
|
+
function fromString(ptr) {
|
|
369
|
+
return libmupdf.UTF8ToString(ptr);
|
|
370
|
+
}
|
|
371
|
+
function fromStringFree(ptr) {
|
|
372
|
+
let str = libmupdf.UTF8ToString(ptr);
|
|
373
|
+
Free(ptr);
|
|
374
|
+
return str;
|
|
375
|
+
}
|
|
376
|
+
function fromPoint(ptr) {
|
|
377
|
+
let addr = ptr >> 2;
|
|
378
|
+
return [
|
|
379
|
+
libmupdf.HEAPF32[addr + 0],
|
|
380
|
+
libmupdf.HEAPF32[addr + 1],
|
|
381
|
+
];
|
|
382
|
+
}
|
|
383
|
+
function fromRect(ptr) {
|
|
384
|
+
let addr = ptr >> 2;
|
|
385
|
+
return [
|
|
386
|
+
libmupdf.HEAPF32[addr + 0],
|
|
387
|
+
libmupdf.HEAPF32[addr + 1],
|
|
388
|
+
libmupdf.HEAPF32[addr + 2],
|
|
389
|
+
libmupdf.HEAPF32[addr + 3],
|
|
390
|
+
];
|
|
391
|
+
}
|
|
392
|
+
function fromMatrix(ptr) {
|
|
393
|
+
let addr = ptr >> 2;
|
|
394
|
+
return [
|
|
395
|
+
libmupdf.HEAPF32[addr + 0],
|
|
396
|
+
libmupdf.HEAPF32[addr + 1],
|
|
397
|
+
libmupdf.HEAPF32[addr + 2],
|
|
398
|
+
libmupdf.HEAPF32[addr + 3],
|
|
399
|
+
libmupdf.HEAPF32[addr + 4],
|
|
400
|
+
libmupdf.HEAPF32[addr + 5],
|
|
401
|
+
];
|
|
402
|
+
}
|
|
403
|
+
function fromQuad(ptr) {
|
|
404
|
+
let addr = ptr >> 2;
|
|
405
|
+
return [
|
|
406
|
+
libmupdf.HEAPF32[addr + 0],
|
|
407
|
+
libmupdf.HEAPF32[addr + 1],
|
|
408
|
+
libmupdf.HEAPF32[addr + 2],
|
|
409
|
+
libmupdf.HEAPF32[addr + 3],
|
|
410
|
+
libmupdf.HEAPF32[addr + 4],
|
|
411
|
+
libmupdf.HEAPF32[addr + 5],
|
|
412
|
+
libmupdf.HEAPF32[addr + 6],
|
|
413
|
+
libmupdf.HEAPF32[addr + 7],
|
|
414
|
+
];
|
|
415
|
+
}
|
|
416
|
+
function fromBuffer(ptr) {
|
|
417
|
+
let data = libmupdf._wasm_buffer_get_data(ptr);
|
|
418
|
+
let size = libmupdf._wasm_buffer_get_len(ptr);
|
|
419
|
+
return libmupdf.HEAPU8.slice(data, data + size);
|
|
420
|
+
}
|
|
421
|
+
function fromLayerConfigUIInfo(ptr) {
|
|
422
|
+
return {
|
|
423
|
+
text: libmupdf._wasm_pdf_layer_config_ui_get_text(ptr),
|
|
424
|
+
depth: libmupdf._wasm_pdf_layer_config_ui_get_depth(ptr),
|
|
425
|
+
type: libmupdf._wasm_pdf_layer_config_ui_get_type(ptr),
|
|
426
|
+
selected: libmupdf._wasm_pdf_layer_config_ui_get_selected(ptr),
|
|
427
|
+
locked: libmupdf._wasm_pdf_layer_config_ui_get_locked(ptr),
|
|
428
|
+
};
|
|
429
|
+
}
|
|
430
|
+
/* unused for now
|
|
431
|
+
function rgbFromColor(c?: Color): [number, number, number] {
|
|
432
|
+
var r = 0, g = 0, b = 0
|
|
433
|
+
if (typeof c !== "undefined") {
|
|
434
|
+
switch (c.length) {
|
|
435
|
+
case 1:
|
|
436
|
+
r = g = b = c[0]
|
|
437
|
+
break
|
|
438
|
+
case 3:
|
|
439
|
+
r = c[0]
|
|
440
|
+
g = c[1]
|
|
441
|
+
b = c[2]
|
|
442
|
+
break
|
|
443
|
+
case 4:
|
|
444
|
+
r = 1 - Math.min(1, c[0] + c[3])
|
|
445
|
+
g = 1 - Math.min(1, c[1] + c[3])
|
|
446
|
+
b = 1 - Math.min(1, c[2] + c[3])
|
|
447
|
+
break
|
|
448
|
+
}
|
|
449
|
+
}
|
|
450
|
+
return [ r, g, b ]
|
|
451
|
+
}
|
|
452
|
+
|
|
453
|
+
function numberFromColor(c?: Color): number {
|
|
454
|
+
var [ r, g, b ] = rgbFromColor(c)
|
|
455
|
+
return (255 << 24) | (r << 16) | (g << 8) | b
|
|
456
|
+
}
|
|
457
|
+
*/
|
|
458
|
+
function colorFromNumber(argb) {
|
|
459
|
+
var r = (argb >> 16) & 255;
|
|
460
|
+
var g = (argb >> 8) & 255;
|
|
461
|
+
var b = (argb) & 255;
|
|
462
|
+
return [r / 255, g / 255, b / 255];
|
|
463
|
+
}
|
|
464
|
+
function runSearch(searchFun, searchThis, needle, max_hits = 500) {
|
|
465
|
+
checkType(needle, "string");
|
|
466
|
+
let hits = 0;
|
|
467
|
+
let marks = 0;
|
|
468
|
+
try {
|
|
469
|
+
hits = Malloc(32 * max_hits);
|
|
470
|
+
marks = Malloc(4 * max_hits);
|
|
471
|
+
let n = searchFun(searchThis, STRING(needle), marks, hits, max_hits);
|
|
472
|
+
let outer = [];
|
|
473
|
+
if (n > 0) {
|
|
474
|
+
let inner = [];
|
|
475
|
+
for (let i = 0; i < n; ++i) {
|
|
476
|
+
let mark = libmupdf.HEAP32[(marks >> 2) + i];
|
|
477
|
+
let quad = fromQuad(hits + i * 32);
|
|
478
|
+
if (i > 0 && mark) {
|
|
479
|
+
outer.push(inner);
|
|
480
|
+
inner = [];
|
|
481
|
+
}
|
|
482
|
+
inner.push(quad);
|
|
483
|
+
}
|
|
484
|
+
outer.push(inner);
|
|
485
|
+
}
|
|
486
|
+
return outer;
|
|
487
|
+
}
|
|
488
|
+
finally {
|
|
489
|
+
Free(marks);
|
|
490
|
+
Free(hits);
|
|
491
|
+
}
|
|
492
|
+
}
|
|
493
|
+
/* -------------------------------------------------------------------------- */
|
|
494
|
+
class Userdata {
|
|
495
|
+
constructor(pointer) {
|
|
496
|
+
if (typeof pointer !== "number")
|
|
497
|
+
throw new Error("invalid pointer: " + typeof pointer);
|
|
498
|
+
if (pointer !== 0) {
|
|
499
|
+
let ctor = this.constructor;
|
|
500
|
+
if (!ctor._finalizer)
|
|
501
|
+
ctor._finalizer = new FinalizationRegistry(ctor._drop);
|
|
502
|
+
ctor._finalizer.register(this, pointer, this);
|
|
503
|
+
}
|
|
504
|
+
this.pointer = pointer;
|
|
505
|
+
}
|
|
506
|
+
destroy() {
|
|
507
|
+
if (this.pointer !== 0) {
|
|
508
|
+
let ctor = this.constructor;
|
|
509
|
+
ctor._finalizer.unregister(this);
|
|
510
|
+
ctor._drop(this.pointer);
|
|
511
|
+
}
|
|
512
|
+
this.pointer = 0;
|
|
513
|
+
}
|
|
514
|
+
// Custom "console.log" formatting for Node
|
|
515
|
+
[Symbol.for("nodejs.util.inspect.custom")]() {
|
|
516
|
+
return this.toString();
|
|
517
|
+
}
|
|
518
|
+
toString() {
|
|
519
|
+
return `[${this.constructor.name} ${this.pointer}]`;
|
|
520
|
+
}
|
|
521
|
+
valueOf() {
|
|
522
|
+
throw new Error("cannot convert Userdata to Javascript value");
|
|
523
|
+
}
|
|
524
|
+
}
|
|
525
|
+
export class Buffer extends Userdata {
|
|
526
|
+
constructor(arg) {
|
|
527
|
+
if (typeof arg === "undefined")
|
|
528
|
+
super(libmupdf._wasm_new_buffer(1024));
|
|
529
|
+
else if (typeof arg === "number")
|
|
530
|
+
super(arg);
|
|
531
|
+
else if (typeof arg === "string") {
|
|
532
|
+
let data_len = libmupdf.lengthBytesUTF8(arg);
|
|
533
|
+
let data_ptr = Malloc(data_len + 1);
|
|
534
|
+
libmupdf.stringToUTF8(arg, data_ptr, data_len + 1);
|
|
535
|
+
super(libmupdf._wasm_new_buffer_from_data(data_ptr, data_len));
|
|
536
|
+
}
|
|
537
|
+
else if (arg instanceof ArrayBuffer || arg instanceof Uint8Array) {
|
|
538
|
+
let data_len = arg.byteLength;
|
|
539
|
+
let data_ptr = Malloc(data_len);
|
|
540
|
+
libmupdf.HEAPU8.set(new Uint8Array(arg), data_ptr);
|
|
541
|
+
super(libmupdf._wasm_new_buffer_from_data(data_ptr, data_len));
|
|
542
|
+
}
|
|
543
|
+
}
|
|
544
|
+
get length() {
|
|
545
|
+
return this.getLength();
|
|
546
|
+
}
|
|
547
|
+
set length(_) {
|
|
548
|
+
throw new TypeError("buffer length is read-only");
|
|
549
|
+
}
|
|
550
|
+
getLength() {
|
|
551
|
+
return libmupdf._wasm_buffer_get_len(this.pointer);
|
|
552
|
+
}
|
|
553
|
+
readByte(at) {
|
|
554
|
+
let data = libmupdf._wasm_buffer_get_data(this.pointer);
|
|
555
|
+
return libmupdf.HEAPU8[data + at];
|
|
556
|
+
}
|
|
557
|
+
write(s) {
|
|
558
|
+
libmupdf._wasm_append_string(this.pointer, STRING(s));
|
|
559
|
+
}
|
|
560
|
+
writeByte(b) {
|
|
561
|
+
libmupdf._wasm_append_byte(this.pointer, b);
|
|
562
|
+
}
|
|
563
|
+
writeLine(s) {
|
|
564
|
+
this.write(s);
|
|
565
|
+
this.writeByte(10);
|
|
566
|
+
}
|
|
567
|
+
writeBuffer(other) {
|
|
568
|
+
libmupdf._wasm_append_buffer(this.pointer, BUFFER(other));
|
|
569
|
+
}
|
|
570
|
+
asUint8Array() {
|
|
571
|
+
let data = libmupdf._wasm_buffer_get_data(this.pointer);
|
|
572
|
+
let size = libmupdf._wasm_buffer_get_len(this.pointer);
|
|
573
|
+
return libmupdf.HEAPU8.subarray(data, data + size);
|
|
574
|
+
}
|
|
575
|
+
slice(start, end) {
|
|
576
|
+
if (typeof end === "undefined")
|
|
577
|
+
end = this.getLength();
|
|
578
|
+
return new Buffer(libmupdf._wasm_slice_buffer(this.pointer, start, end));
|
|
579
|
+
}
|
|
580
|
+
asString() {
|
|
581
|
+
return fromString(libmupdf._wasm_string_from_buffer(this.pointer));
|
|
582
|
+
}
|
|
583
|
+
save(filename) {
|
|
584
|
+
if (node_fs)
|
|
585
|
+
node_fs.writeFileSync(filename, this.asUint8Array());
|
|
586
|
+
else
|
|
587
|
+
throw new Error("missing 'fs' module");
|
|
588
|
+
}
|
|
589
|
+
}
|
|
590
|
+
Buffer._drop = libmupdf._wasm_drop_buffer;
|
|
591
|
+
export class ColorSpace extends Userdata {
|
|
592
|
+
constructor(from, name) {
|
|
593
|
+
if (typeof from === "number") {
|
|
594
|
+
super(from);
|
|
595
|
+
}
|
|
596
|
+
else {
|
|
597
|
+
if (typeof from === "string") {
|
|
598
|
+
if (node_fs)
|
|
599
|
+
from = node_fs.readFileSync(from);
|
|
600
|
+
else
|
|
601
|
+
throw new Error("missing 'fs' module");
|
|
602
|
+
}
|
|
603
|
+
super(libmupdf._wasm_new_icc_colorspace(STRING_OPT(name), BUFFER(from)));
|
|
604
|
+
}
|
|
605
|
+
}
|
|
606
|
+
getName() {
|
|
607
|
+
return fromString(libmupdf._wasm_colorspace_get_name(this.pointer));
|
|
608
|
+
}
|
|
609
|
+
getType() {
|
|
610
|
+
return ColorSpace.COLORSPACE_TYPES[libmupdf._wasm_colorspace_get_type(this.pointer)] || "None";
|
|
611
|
+
}
|
|
612
|
+
getNumberOfComponents() {
|
|
613
|
+
return libmupdf._wasm_colorspace_get_n(this.pointer);
|
|
614
|
+
}
|
|
615
|
+
isGray() { return this.getType() === "Gray"; }
|
|
616
|
+
isRGB() { return this.getType() === "RGB"; }
|
|
617
|
+
isCMYK() { return this.getType() === "CMYK"; }
|
|
618
|
+
isIndexed() { return this.getType() === "Indexed"; }
|
|
619
|
+
isLab() { return this.getType() === "Lab"; }
|
|
620
|
+
isDeviceN() { return this.getType() === "Separation"; }
|
|
621
|
+
isSubtractive() { return this.getType() === "CMYK" || this.getType() === "Separation"; }
|
|
622
|
+
toString() {
|
|
623
|
+
return "[ColorSpace " + this.getName() + "]";
|
|
624
|
+
}
|
|
625
|
+
}
|
|
626
|
+
ColorSpace._drop = libmupdf._wasm_drop_colorspace;
|
|
627
|
+
ColorSpace.COLORSPACE_TYPES = [
|
|
628
|
+
"None",
|
|
629
|
+
"Gray",
|
|
630
|
+
"RGB",
|
|
631
|
+
"BGR",
|
|
632
|
+
"CMYK",
|
|
633
|
+
"Lab",
|
|
634
|
+
"Indexed",
|
|
635
|
+
"Separation"
|
|
636
|
+
];
|
|
637
|
+
ColorSpace.DeviceGray = new ColorSpace(libmupdf._wasm_device_gray());
|
|
638
|
+
ColorSpace.DeviceRGB = new ColorSpace(libmupdf._wasm_device_rgb());
|
|
639
|
+
ColorSpace.DeviceBGR = new ColorSpace(libmupdf._wasm_device_bgr());
|
|
640
|
+
ColorSpace.DeviceCMYK = new ColorSpace(libmupdf._wasm_device_cmyk());
|
|
641
|
+
ColorSpace.Lab = new ColorSpace(libmupdf._wasm_device_lab());
|
|
642
|
+
export class Font extends Userdata {
|
|
643
|
+
constructor(name_or_pointer, data, subfont = 0) {
|
|
644
|
+
let pointer = 0;
|
|
645
|
+
if (typeof name_or_pointer === "number") {
|
|
646
|
+
pointer = libmupdf._wasm_keep_font(name_or_pointer);
|
|
647
|
+
}
|
|
648
|
+
else {
|
|
649
|
+
if (typeof data === "string") {
|
|
650
|
+
if (node_fs)
|
|
651
|
+
data = node_fs.readFileSync(data);
|
|
652
|
+
else
|
|
653
|
+
throw new Error("missing 'fs' module");
|
|
654
|
+
}
|
|
655
|
+
if (data)
|
|
656
|
+
pointer = libmupdf._wasm_new_font_from_buffer(STRING(name_or_pointer), BUFFER(data), subfont);
|
|
657
|
+
else if (name_or_pointer === "zh-Hant")
|
|
658
|
+
pointer = libmupdf._wasm_new_cjk_font(Font.ADOBE_CNS);
|
|
659
|
+
else if (name_or_pointer === "zh-Hans")
|
|
660
|
+
pointer = libmupdf._wasm_new_cjk_font(Font.ADOBE_GB);
|
|
661
|
+
else if (name_or_pointer === "ja")
|
|
662
|
+
pointer = libmupdf._wasm_new_cjk_font(Font.ADOBE_JAPAN);
|
|
663
|
+
else if (name_or_pointer === "ko")
|
|
664
|
+
pointer = libmupdf._wasm_new_cjk_font(Font.ADOBE_KOREA);
|
|
665
|
+
else
|
|
666
|
+
pointer = libmupdf._wasm_new_base14_font(STRING(name_or_pointer));
|
|
667
|
+
}
|
|
668
|
+
super(pointer);
|
|
669
|
+
}
|
|
670
|
+
getName() {
|
|
671
|
+
return fromString(libmupdf._wasm_font_get_name(this.pointer));
|
|
672
|
+
}
|
|
673
|
+
encodeCharacter(uni) {
|
|
674
|
+
if (typeof uni === "string")
|
|
675
|
+
uni = uni.charCodeAt(0);
|
|
676
|
+
return libmupdf._wasm_encode_character(this.pointer, uni);
|
|
677
|
+
}
|
|
678
|
+
advanceGlyph(gid, wmode = 0) {
|
|
679
|
+
return libmupdf._wasm_advance_glyph(this.pointer, gid, wmode);
|
|
680
|
+
}
|
|
681
|
+
isMono() {
|
|
682
|
+
return !!libmupdf._wasm_font_is_monospaced(this.pointer);
|
|
683
|
+
}
|
|
684
|
+
isSerif() {
|
|
685
|
+
return !!libmupdf._wasm_font_is_serif(this.pointer);
|
|
686
|
+
}
|
|
687
|
+
isBold() {
|
|
688
|
+
return !!libmupdf._wasm_font_is_bold(this.pointer);
|
|
689
|
+
}
|
|
690
|
+
isItalic() {
|
|
691
|
+
return !!libmupdf._wasm_font_is_italic(this.pointer);
|
|
692
|
+
}
|
|
693
|
+
}
|
|
694
|
+
Font._drop = libmupdf._wasm_drop_font;
|
|
695
|
+
Font.SIMPLE_ENCODING = [
|
|
696
|
+
"Latin",
|
|
697
|
+
"Greek",
|
|
698
|
+
"Cyrillic"
|
|
699
|
+
];
|
|
700
|
+
Font.SIMPLE_ENCODING_LATIN = "Latin";
|
|
701
|
+
Font.SIMPLE_ENCODING_GREEK = "Greek";
|
|
702
|
+
Font.SIMPLE_ENCODING_CYRILLIC = "Cyrillic";
|
|
703
|
+
Font.ADOBE_CNS = 0;
|
|
704
|
+
Font.ADOBE_GB = 1;
|
|
705
|
+
Font.ADOBE_JAPAN = 2;
|
|
706
|
+
Font.ADOBE_KOREA = 3;
|
|
707
|
+
Font.CJK_ORDERING_BY_LANG = {
|
|
708
|
+
"Adobe-CNS1": 0,
|
|
709
|
+
"Adobe-GB1": 1,
|
|
710
|
+
"Adobe-Japan1": 2,
|
|
711
|
+
"Adobe-Korea1": 3,
|
|
712
|
+
"zh-Hant": 0,
|
|
713
|
+
"zh-TW": 0,
|
|
714
|
+
"zh-HK": 0,
|
|
715
|
+
"zh-Hans": 1,
|
|
716
|
+
"zh-CN": 1,
|
|
717
|
+
"ja": 2,
|
|
718
|
+
"ko": 3,
|
|
719
|
+
};
|
|
720
|
+
export class Image extends Userdata {
|
|
721
|
+
constructor(data, mask) {
|
|
722
|
+
let pointer = 0;
|
|
723
|
+
if (typeof data === "number") {
|
|
724
|
+
pointer = libmupdf._wasm_keep_image(data);
|
|
725
|
+
}
|
|
726
|
+
else if (data instanceof Pixmap) {
|
|
727
|
+
pointer = libmupdf._wasm_new_image_from_pixmap(data.pointer, mask ? mask.pointer : 0);
|
|
728
|
+
}
|
|
729
|
+
else {
|
|
730
|
+
if (typeof data === "string") {
|
|
731
|
+
if (node_fs)
|
|
732
|
+
data = node_fs.readFileSync(data);
|
|
733
|
+
else
|
|
734
|
+
throw new Error("missing 'fs' module");
|
|
735
|
+
}
|
|
736
|
+
pointer = libmupdf._wasm_new_image_from_buffer(BUFFER(data));
|
|
737
|
+
}
|
|
738
|
+
super(pointer);
|
|
739
|
+
}
|
|
740
|
+
getWidth() {
|
|
741
|
+
return libmupdf._wasm_image_get_w(this.pointer);
|
|
742
|
+
}
|
|
743
|
+
getHeight() {
|
|
744
|
+
return libmupdf._wasm_image_get_h(this.pointer);
|
|
745
|
+
}
|
|
746
|
+
getNumberOfComponents() {
|
|
747
|
+
return libmupdf._wasm_image_get_n(this.pointer);
|
|
748
|
+
}
|
|
749
|
+
getBitsPerComponent() {
|
|
750
|
+
return libmupdf._wasm_image_get_bpc(this.pointer);
|
|
751
|
+
}
|
|
752
|
+
getXResolution() {
|
|
753
|
+
return libmupdf._wasm_image_get_xres(this.pointer);
|
|
754
|
+
}
|
|
755
|
+
getYResolution() {
|
|
756
|
+
return libmupdf._wasm_image_get_yres(this.pointer);
|
|
757
|
+
}
|
|
758
|
+
getImageMask() {
|
|
759
|
+
return !!libmupdf._wasm_image_get_imagemask(this.pointer);
|
|
760
|
+
}
|
|
761
|
+
getColorSpace() {
|
|
762
|
+
let cs = libmupdf._wasm_image_get_colorspace(this.pointer);
|
|
763
|
+
if (cs)
|
|
764
|
+
return new ColorSpace(libmupdf._wasm_keep_colorspace(cs));
|
|
765
|
+
return null;
|
|
766
|
+
}
|
|
767
|
+
getMask() {
|
|
768
|
+
let mask = libmupdf._wasm_image_get_mask(this.pointer);
|
|
769
|
+
if (mask)
|
|
770
|
+
return new Image(libmupdf._wasm_keep_image(mask));
|
|
771
|
+
return null;
|
|
772
|
+
}
|
|
773
|
+
toPixmap() {
|
|
774
|
+
return new Pixmap(libmupdf._wasm_get_pixmap_from_image(this.pointer));
|
|
775
|
+
}
|
|
776
|
+
}
|
|
777
|
+
Image._drop = libmupdf._wasm_drop_image;
|
|
778
|
+
export class StrokeState extends Userdata {
|
|
779
|
+
constructor(data) {
|
|
780
|
+
if (typeof data === "number") {
|
|
781
|
+
super(data);
|
|
782
|
+
return this;
|
|
783
|
+
}
|
|
784
|
+
super(libmupdf._wasm_new_stroke_state(data?.dashes?.length ?? 0));
|
|
785
|
+
let lineCap = ENUM(data.lineCap, StrokeState.LINE_CAP);
|
|
786
|
+
let lineJoin = ENUM(data.lineJoin, StrokeState.LINE_JOIN);
|
|
787
|
+
libmupdf._wasm_stroke_state_set_start_cap(this.pointer, lineCap);
|
|
788
|
+
libmupdf._wasm_stroke_state_set_dash_cap(this.pointer, lineCap);
|
|
789
|
+
libmupdf._wasm_stroke_state_set_end_cap(this.pointer, lineCap);
|
|
790
|
+
libmupdf._wasm_stroke_state_set_linejoin(this.pointer, lineJoin);
|
|
791
|
+
libmupdf._wasm_stroke_state_set_linewidth(this.pointer, data.lineWidth);
|
|
792
|
+
libmupdf._wasm_stroke_state_set_miterlimit(this.pointer, data.miterLimit);
|
|
793
|
+
libmupdf._wasm_stroke_state_set_dash_phase(this.pointer, data.dashPhase ?? 0);
|
|
794
|
+
if (data.dashes) {
|
|
795
|
+
for (let i = 0; i < data.dashes.length; ++i)
|
|
796
|
+
libmupdf._wasm_stroke_state_set_dash_item(this.pointer, i, data.dashes[i] ?? 0);
|
|
797
|
+
}
|
|
798
|
+
}
|
|
799
|
+
getLineCap() {
|
|
800
|
+
return libmupdf._wasm_stroke_state_get_start_cap(this.pointer);
|
|
801
|
+
}
|
|
802
|
+
getLineJoin() {
|
|
803
|
+
return libmupdf._wasm_stroke_state_get_linejoin(this.pointer);
|
|
804
|
+
}
|
|
805
|
+
getLineWidth() {
|
|
806
|
+
return libmupdf._wasm_stroke_state_get_linewidth(this.pointer);
|
|
807
|
+
}
|
|
808
|
+
getMiterLimit() {
|
|
809
|
+
return libmupdf._wasm_stroke_state_get_miterlimit(this.pointer);
|
|
810
|
+
}
|
|
811
|
+
getDashPhase() {
|
|
812
|
+
return libmupdf._wasm_stroke_state_get_dash_phase(this.pointer);
|
|
813
|
+
}
|
|
814
|
+
getDashes() {
|
|
815
|
+
var n = libmupdf._wasm_stroke_state_get_dash_len(this.pointer);
|
|
816
|
+
if (n > 0) {
|
|
817
|
+
var out = [];
|
|
818
|
+
for (let i = 0; i < n; ++i)
|
|
819
|
+
out[i] = libmupdf._wasm_stroke_state_get_dash_item(this.pointer, i);
|
|
820
|
+
return out;
|
|
821
|
+
}
|
|
822
|
+
return null;
|
|
823
|
+
}
|
|
824
|
+
}
|
|
825
|
+
StrokeState._drop = libmupdf._wasm_drop_stroke_state;
|
|
826
|
+
StrokeState.LINE_CAP = [
|
|
827
|
+
"Butt",
|
|
828
|
+
"Round",
|
|
829
|
+
"Square",
|
|
830
|
+
"Triangle"
|
|
831
|
+
];
|
|
832
|
+
StrokeState.LINE_JOIN = [
|
|
833
|
+
"Miter",
|
|
834
|
+
"Round",
|
|
835
|
+
"Bevel",
|
|
836
|
+
"MiterXPS"
|
|
837
|
+
];
|
|
838
|
+
export class Path extends Userdata {
|
|
839
|
+
constructor(pointer) {
|
|
840
|
+
if (typeof pointer === "number")
|
|
841
|
+
super(pointer);
|
|
842
|
+
else
|
|
843
|
+
super(libmupdf._wasm_new_path());
|
|
844
|
+
}
|
|
845
|
+
getBounds(strokeState, transform) {
|
|
846
|
+
if (strokeState !== null)
|
|
847
|
+
checkType(strokeState, StrokeState);
|
|
848
|
+
checkMatrix(transform);
|
|
849
|
+
return fromRect(libmupdf._wasm_bound_path(this.pointer, strokeState?.pointer, MATRIX(transform)));
|
|
850
|
+
}
|
|
851
|
+
moveTo(x, y) {
|
|
852
|
+
checkType(x, "number");
|
|
853
|
+
checkType(y, "number");
|
|
854
|
+
libmupdf._wasm_moveto(this.pointer, x, y);
|
|
855
|
+
}
|
|
856
|
+
lineTo(x, y) {
|
|
857
|
+
checkType(x, "number");
|
|
858
|
+
checkType(y, "number");
|
|
859
|
+
libmupdf._wasm_lineto(this.pointer, x, y);
|
|
860
|
+
}
|
|
861
|
+
curveTo(x1, y1, x2, y2, x3, y3) {
|
|
862
|
+
checkType(x1, "number");
|
|
863
|
+
checkType(y1, "number");
|
|
864
|
+
checkType(x2, "number");
|
|
865
|
+
checkType(y2, "number");
|
|
866
|
+
checkType(x3, "number");
|
|
867
|
+
checkType(y3, "number");
|
|
868
|
+
libmupdf._wasm_curveto(this.pointer, x1, y1, x2, y2, x3, y3);
|
|
869
|
+
}
|
|
870
|
+
curveToV(cx, cy, ex, ey) {
|
|
871
|
+
checkType(cx, "number");
|
|
872
|
+
checkType(cy, "number");
|
|
873
|
+
checkType(ex, "number");
|
|
874
|
+
checkType(ey, "number");
|
|
875
|
+
libmupdf._wasm_curvetov(this.pointer, cx, cy, ex, ey);
|
|
876
|
+
}
|
|
877
|
+
curveToY(cx, cy, ex, ey) {
|
|
878
|
+
checkType(cx, "number");
|
|
879
|
+
checkType(cy, "number");
|
|
880
|
+
checkType(ex, "number");
|
|
881
|
+
checkType(ey, "number");
|
|
882
|
+
libmupdf._wasm_curvetoy(this.pointer, cx, cy, ex, ey);
|
|
883
|
+
}
|
|
884
|
+
closePath() {
|
|
885
|
+
libmupdf._wasm_closepath(this.pointer);
|
|
886
|
+
}
|
|
887
|
+
rect(x1, y1, x2, y2) {
|
|
888
|
+
checkType(x1, "number");
|
|
889
|
+
checkType(y1, "number");
|
|
890
|
+
checkType(x2, "number");
|
|
891
|
+
checkType(y2, "number");
|
|
892
|
+
libmupdf._wasm_rectto(this.pointer, x1, y1, x2, y2);
|
|
893
|
+
}
|
|
894
|
+
transform(matrix) {
|
|
895
|
+
checkMatrix(matrix);
|
|
896
|
+
libmupdf._wasm_transform_path(this.pointer, MATRIX(matrix));
|
|
897
|
+
}
|
|
898
|
+
walk(walker) {
|
|
899
|
+
let id = $libmupdf_path_id++;
|
|
900
|
+
$libmupdf_path_table.set(id, walker);
|
|
901
|
+
libmupdf._wasm_walk_path(this.pointer, id);
|
|
902
|
+
$libmupdf_path_table.delete(id);
|
|
903
|
+
}
|
|
904
|
+
}
|
|
905
|
+
Path._drop = libmupdf._wasm_drop_path;
|
|
906
|
+
export class Text extends Userdata {
|
|
907
|
+
constructor(pointer) {
|
|
908
|
+
if (typeof pointer === "number")
|
|
909
|
+
super(pointer);
|
|
910
|
+
else
|
|
911
|
+
super(libmupdf._wasm_new_text());
|
|
912
|
+
}
|
|
913
|
+
getBounds(strokeState, transform) {
|
|
914
|
+
if (strokeState !== null)
|
|
915
|
+
checkType(strokeState, StrokeState);
|
|
916
|
+
checkMatrix(transform);
|
|
917
|
+
return fromRect(libmupdf._wasm_bound_text(this.pointer, strokeState?.pointer, MATRIX(transform)));
|
|
918
|
+
}
|
|
919
|
+
showGlyph(font, trm, gid, uni, wmode = 0) {
|
|
920
|
+
checkType(font, Font);
|
|
921
|
+
checkMatrix(trm);
|
|
922
|
+
checkType(gid, "number");
|
|
923
|
+
checkType(uni, "number");
|
|
924
|
+
libmupdf._wasm_show_glyph(this.pointer, font.pointer, MATRIX(trm), gid, uni, wmode);
|
|
925
|
+
}
|
|
926
|
+
showString(font, trm, str, wmode = 0) {
|
|
927
|
+
checkType(font, Font);
|
|
928
|
+
checkMatrix(trm);
|
|
929
|
+
checkType(str, "string");
|
|
930
|
+
return fromMatrix(libmupdf._wasm_show_string(this.pointer, font.pointer, MATRIX(trm), STRING(str), wmode));
|
|
931
|
+
}
|
|
932
|
+
walk(walker) {
|
|
933
|
+
let id = $libmupdf_text_id++;
|
|
934
|
+
$libmupdf_text_table.set(id, walker);
|
|
935
|
+
libmupdf._wasm_walk_text(this.pointer, id);
|
|
936
|
+
$libmupdf_text_table.delete(id);
|
|
937
|
+
}
|
|
938
|
+
}
|
|
939
|
+
Text._drop = libmupdf._wasm_drop_text;
|
|
940
|
+
export class DisplayList extends Userdata {
|
|
941
|
+
constructor(arg1) {
|
|
942
|
+
let pointer = 0;
|
|
943
|
+
if (typeof arg1 === "number") {
|
|
944
|
+
pointer = arg1;
|
|
945
|
+
}
|
|
946
|
+
else {
|
|
947
|
+
checkRect(arg1);
|
|
948
|
+
pointer = libmupdf._wasm_new_display_list(RECT(arg1));
|
|
949
|
+
}
|
|
950
|
+
super(pointer);
|
|
951
|
+
}
|
|
952
|
+
getBounds() {
|
|
953
|
+
return fromRect(libmupdf._wasm_bound_display_list(this.pointer));
|
|
954
|
+
}
|
|
955
|
+
toPixmap(matrix, colorspace, alpha = false) {
|
|
956
|
+
checkMatrix(matrix);
|
|
957
|
+
checkType(colorspace, ColorSpace);
|
|
958
|
+
return new Pixmap(libmupdf._wasm_new_pixmap_from_display_list(this.pointer, MATRIX(matrix), colorspace.pointer, alpha));
|
|
959
|
+
}
|
|
960
|
+
toStructuredText(options = "") {
|
|
961
|
+
checkType(options, "string");
|
|
962
|
+
return new StructuredText(libmupdf._wasm_new_stext_page_from_display_list(this.pointer, STRING(options)));
|
|
963
|
+
}
|
|
964
|
+
run(device, matrix) {
|
|
965
|
+
checkType(device, Device);
|
|
966
|
+
checkMatrix(matrix);
|
|
967
|
+
libmupdf._wasm_run_display_list(this.pointer, device.pointer, MATRIX(matrix));
|
|
968
|
+
}
|
|
969
|
+
search(needle, max_hits = 500) {
|
|
970
|
+
return runSearch(libmupdf._wasm_search_display_list, this.pointer, needle, max_hits);
|
|
971
|
+
}
|
|
972
|
+
}
|
|
973
|
+
DisplayList._drop = libmupdf._wasm_drop_display_list;
|
|
974
|
+
export class Pixmap extends Userdata {
|
|
975
|
+
constructor(arg1, bbox, alpha = false) {
|
|
976
|
+
if (typeof arg1 === "number") {
|
|
977
|
+
super(arg1);
|
|
978
|
+
}
|
|
979
|
+
if (arg1 instanceof ColorSpace) {
|
|
980
|
+
checkRect(bbox);
|
|
981
|
+
super(libmupdf._wasm_new_pixmap_with_bbox(arg1.pointer, RECT(bbox), alpha));
|
|
982
|
+
}
|
|
983
|
+
if (arg1 === null) {
|
|
984
|
+
checkRect(bbox);
|
|
985
|
+
super(libmupdf._wasm_new_pixmap_with_bbox(0, RECT(bbox), alpha));
|
|
986
|
+
}
|
|
987
|
+
}
|
|
988
|
+
getBounds() {
|
|
989
|
+
let x = libmupdf._wasm_pixmap_get_x(this.pointer);
|
|
990
|
+
let y = libmupdf._wasm_pixmap_get_y(this.pointer);
|
|
991
|
+
let w = libmupdf._wasm_pixmap_get_w(this.pointer);
|
|
992
|
+
let h = libmupdf._wasm_pixmap_get_h(this.pointer);
|
|
993
|
+
return [x, y, x + w, y + h];
|
|
994
|
+
}
|
|
995
|
+
clear(value) {
|
|
996
|
+
if (typeof value === "undefined")
|
|
997
|
+
libmupdf._wasm_clear_pixmap(this.pointer);
|
|
998
|
+
else
|
|
999
|
+
libmupdf._wasm_clear_pixmap_with_value(this.pointer, value);
|
|
1000
|
+
}
|
|
1001
|
+
getWidth() {
|
|
1002
|
+
return libmupdf._wasm_pixmap_get_w(this.pointer);
|
|
1003
|
+
}
|
|
1004
|
+
getHeight() {
|
|
1005
|
+
return libmupdf._wasm_pixmap_get_h(this.pointer);
|
|
1006
|
+
}
|
|
1007
|
+
getX() {
|
|
1008
|
+
return libmupdf._wasm_pixmap_get_x(this.pointer);
|
|
1009
|
+
}
|
|
1010
|
+
getY() {
|
|
1011
|
+
return libmupdf._wasm_pixmap_get_y(this.pointer);
|
|
1012
|
+
}
|
|
1013
|
+
getStride() {
|
|
1014
|
+
return libmupdf._wasm_pixmap_get_stride(this.pointer);
|
|
1015
|
+
}
|
|
1016
|
+
getNumberOfComponents() {
|
|
1017
|
+
return libmupdf._wasm_pixmap_get_n(this.pointer);
|
|
1018
|
+
}
|
|
1019
|
+
getAlpha() {
|
|
1020
|
+
return libmupdf._wasm_pixmap_get_alpha(this.pointer);
|
|
1021
|
+
}
|
|
1022
|
+
getXResolution() {
|
|
1023
|
+
return libmupdf._wasm_pixmap_get_xres(this.pointer);
|
|
1024
|
+
}
|
|
1025
|
+
getYResolution() {
|
|
1026
|
+
return libmupdf._wasm_pixmap_get_yres(this.pointer);
|
|
1027
|
+
}
|
|
1028
|
+
setResolution(x, y) {
|
|
1029
|
+
libmupdf._wasm_pixmap_set_xres(this.pointer, x);
|
|
1030
|
+
libmupdf._wasm_pixmap_set_yres(this.pointer, y);
|
|
1031
|
+
}
|
|
1032
|
+
getColorSpace() {
|
|
1033
|
+
let cs = libmupdf._wasm_pixmap_get_colorspace(this.pointer);
|
|
1034
|
+
if (cs)
|
|
1035
|
+
return new ColorSpace(libmupdf._wasm_keep_colorspace(cs));
|
|
1036
|
+
return null;
|
|
1037
|
+
}
|
|
1038
|
+
getPixels() {
|
|
1039
|
+
let s = libmupdf._wasm_pixmap_get_stride(this.pointer);
|
|
1040
|
+
let h = libmupdf._wasm_pixmap_get_h(this.pointer);
|
|
1041
|
+
let p = libmupdf._wasm_pixmap_get_samples(this.pointer);
|
|
1042
|
+
return new Uint8ClampedArray(libmupdf.HEAPU8.buffer, p, s * h);
|
|
1043
|
+
}
|
|
1044
|
+
asPNG() {
|
|
1045
|
+
let buf = libmupdf._wasm_new_buffer_from_pixmap_as_png(this.pointer);
|
|
1046
|
+
try {
|
|
1047
|
+
return fromBuffer(buf);
|
|
1048
|
+
}
|
|
1049
|
+
finally {
|
|
1050
|
+
libmupdf._wasm_drop_buffer(buf);
|
|
1051
|
+
}
|
|
1052
|
+
}
|
|
1053
|
+
asPSD() {
|
|
1054
|
+
let buf = libmupdf._wasm_new_buffer_from_pixmap_as_psd(this.pointer);
|
|
1055
|
+
try {
|
|
1056
|
+
return fromBuffer(buf);
|
|
1057
|
+
}
|
|
1058
|
+
finally {
|
|
1059
|
+
libmupdf._wasm_drop_buffer(buf);
|
|
1060
|
+
}
|
|
1061
|
+
}
|
|
1062
|
+
asPAM() {
|
|
1063
|
+
let buf = libmupdf._wasm_new_buffer_from_pixmap_as_pam(this.pointer);
|
|
1064
|
+
try {
|
|
1065
|
+
return fromBuffer(buf);
|
|
1066
|
+
}
|
|
1067
|
+
finally {
|
|
1068
|
+
libmupdf._wasm_drop_buffer(buf);
|
|
1069
|
+
}
|
|
1070
|
+
}
|
|
1071
|
+
asJPEG(quality, invert_cmyk = false) {
|
|
1072
|
+
let buf = libmupdf._wasm_new_buffer_from_pixmap_as_jpeg(this.pointer, quality, invert_cmyk);
|
|
1073
|
+
try {
|
|
1074
|
+
return fromBuffer(buf);
|
|
1075
|
+
}
|
|
1076
|
+
finally {
|
|
1077
|
+
libmupdf._wasm_drop_buffer(buf);
|
|
1078
|
+
}
|
|
1079
|
+
}
|
|
1080
|
+
invert() {
|
|
1081
|
+
libmupdf._wasm_invert_pixmap(this.pointer);
|
|
1082
|
+
}
|
|
1083
|
+
invertLuminance() {
|
|
1084
|
+
libmupdf._wasm_invert_pixmap_luminance(this.pointer);
|
|
1085
|
+
}
|
|
1086
|
+
gamma(p) {
|
|
1087
|
+
libmupdf._wasm_gamma_pixmap(this.pointer, p);
|
|
1088
|
+
}
|
|
1089
|
+
tint(black, white) {
|
|
1090
|
+
let black_hex = 0x000000;
|
|
1091
|
+
let white_hex = 0xffffff;
|
|
1092
|
+
if (typeof black === "number")
|
|
1093
|
+
black_hex = black;
|
|
1094
|
+
else if (black instanceof Array && black.length === 3)
|
|
1095
|
+
black_hex = (((black[0] * 255) << 16) | ((black[1] * 255) << 8) | ((black[2] * 255)));
|
|
1096
|
+
if (typeof white === "number")
|
|
1097
|
+
white_hex = white;
|
|
1098
|
+
else if (white instanceof Array && white.length === 3)
|
|
1099
|
+
white = (((white[0] * 255) << 16) | ((white[1] * 255) << 8) | ((white[2] * 255)));
|
|
1100
|
+
libmupdf._wasm_tint_pixmap(this.pointer, black_hex, white_hex);
|
|
1101
|
+
}
|
|
1102
|
+
convertToColorSpace(colorspace, keepAlpha = false) {
|
|
1103
|
+
checkType(colorspace, ColorSpace);
|
|
1104
|
+
checkType(keepAlpha, "boolean");
|
|
1105
|
+
return new Pixmap(libmupdf._wasm_convert_pixmap(this.pointer, colorspace.pointer, keepAlpha));
|
|
1106
|
+
}
|
|
1107
|
+
warp(points, width, height) {
|
|
1108
|
+
let quad = points.flat();
|
|
1109
|
+
checkQuad(quad);
|
|
1110
|
+
checkType(width, "number");
|
|
1111
|
+
checkType(height, "number");
|
|
1112
|
+
return new Pixmap(libmupdf._wasm_warp_pixmap(this.pointer, QUAD(quad), width, height));
|
|
1113
|
+
}
|
|
1114
|
+
}
|
|
1115
|
+
Pixmap._drop = libmupdf._wasm_drop_pixmap;
|
|
1116
|
+
export class Shade extends Userdata {
|
|
1117
|
+
getBounds() {
|
|
1118
|
+
return fromRect(libmupdf._wasm_bound_shade(this.pointer));
|
|
1119
|
+
}
|
|
1120
|
+
}
|
|
1121
|
+
Shade._drop = libmupdf._wasm_drop_shade;
|
|
1122
|
+
export class StructuredText extends Userdata {
|
|
1123
|
+
walk(walker) {
|
|
1124
|
+
let block = libmupdf._wasm_stext_page_get_first_block(this.pointer);
|
|
1125
|
+
while (block) {
|
|
1126
|
+
let block_type = libmupdf._wasm_stext_block_get_type(block);
|
|
1127
|
+
let block_bbox = fromRect(libmupdf._wasm_stext_block_get_bbox(block));
|
|
1128
|
+
if (block_type === 0) {
|
|
1129
|
+
if (walker.beginTextBlock)
|
|
1130
|
+
walker.beginTextBlock(block_bbox);
|
|
1131
|
+
let line = libmupdf._wasm_stext_block_get_first_line(block);
|
|
1132
|
+
while (line) {
|
|
1133
|
+
let line_bbox = fromRect(libmupdf._wasm_stext_line_get_bbox(line));
|
|
1134
|
+
let line_wmode = libmupdf._wasm_stext_line_get_wmode(line);
|
|
1135
|
+
let line_dir = fromPoint(libmupdf._wasm_stext_line_get_dir(line));
|
|
1136
|
+
if (walker.beginLine)
|
|
1137
|
+
walker.beginLine(line_bbox, line_wmode, line_dir);
|
|
1138
|
+
if (walker.onChar) {
|
|
1139
|
+
let ch = libmupdf._wasm_stext_line_get_first_char(line);
|
|
1140
|
+
while (ch) {
|
|
1141
|
+
let ch_rune = String.fromCharCode(libmupdf._wasm_stext_char_get_c(ch));
|
|
1142
|
+
let ch_origin = fromPoint(libmupdf._wasm_stext_char_get_origin(ch));
|
|
1143
|
+
let ch_font = new Font(libmupdf._wasm_stext_char_get_font(ch));
|
|
1144
|
+
let ch_size = libmupdf._wasm_stext_char_get_size(ch);
|
|
1145
|
+
let ch_quad = fromQuad(libmupdf._wasm_stext_char_get_quad(ch));
|
|
1146
|
+
let ch_color = colorFromNumber(libmupdf._wasm_stext_char_get_argb(ch));
|
|
1147
|
+
let ch_bidi = libmupdf._wasm_stext_char_get_bidi(ch);
|
|
1148
|
+
walker.onChar(ch_rune, ch_origin, ch_font, ch_size, ch_quad, ch_color, ch_bidi);
|
|
1149
|
+
ch = libmupdf._wasm_stext_char_get_next(ch);
|
|
1150
|
+
}
|
|
1151
|
+
}
|
|
1152
|
+
if (walker.endLine)
|
|
1153
|
+
walker.endLine();
|
|
1154
|
+
line = libmupdf._wasm_stext_line_get_next(line);
|
|
1155
|
+
}
|
|
1156
|
+
if (walker.endTextBlock)
|
|
1157
|
+
walker.endTextBlock();
|
|
1158
|
+
}
|
|
1159
|
+
else if (block_type === 1) {
|
|
1160
|
+
/* image */
|
|
1161
|
+
if (walker.onImageBlock) {
|
|
1162
|
+
let matrix = fromMatrix(libmupdf._wasm_stext_block_get_transform(block));
|
|
1163
|
+
let image = new Image(libmupdf._wasm_stext_block_get_image(block));
|
|
1164
|
+
walker.onImageBlock(block_bbox, matrix, image);
|
|
1165
|
+
}
|
|
1166
|
+
}
|
|
1167
|
+
else if (block_type === 2) {
|
|
1168
|
+
/* struct */
|
|
1169
|
+
}
|
|
1170
|
+
else if (block_type === 3) {
|
|
1171
|
+
/* vector */
|
|
1172
|
+
if (walker.onVector) {
|
|
1173
|
+
let v_flags_word = libmupdf._wasm_stext_block_get_v_flags(block);
|
|
1174
|
+
let v_flags = {
|
|
1175
|
+
isStroked: !!(v_flags_word & 1),
|
|
1176
|
+
isRectangle: !!(v_flags_word & 2),
|
|
1177
|
+
};
|
|
1178
|
+
let v_color = colorFromNumber(libmupdf._wasm_stext_block_get_v_argb(block));
|
|
1179
|
+
walker.onVector(block_bbox, v_flags, v_color);
|
|
1180
|
+
}
|
|
1181
|
+
}
|
|
1182
|
+
else if (block_type === 4) {
|
|
1183
|
+
/* grid */
|
|
1184
|
+
}
|
|
1185
|
+
block = libmupdf._wasm_stext_block_get_next(block);
|
|
1186
|
+
}
|
|
1187
|
+
}
|
|
1188
|
+
asJSON(scale = 1) {
|
|
1189
|
+
return fromStringFree(libmupdf._wasm_print_stext_page_as_json(this.pointer, scale));
|
|
1190
|
+
}
|
|
1191
|
+
asHTML(id) {
|
|
1192
|
+
return fromStringFree(libmupdf._wasm_print_stext_page_as_html(this.pointer, id));
|
|
1193
|
+
}
|
|
1194
|
+
asText() {
|
|
1195
|
+
return fromStringFree(libmupdf._wasm_print_stext_page_as_text(this.pointer));
|
|
1196
|
+
}
|
|
1197
|
+
snap(p, q, mode) {
|
|
1198
|
+
let mm = ENUM(mode, StructuredText.SELECT_MODE);
|
|
1199
|
+
return fromQuad(libmupdf._wasm_snap_selection(this.pointer, POINT(p), POINT2(q), mm));
|
|
1200
|
+
}
|
|
1201
|
+
copy(p, q) {
|
|
1202
|
+
return fromStringFree(libmupdf._wasm_copy_selection(this.pointer, POINT(p), POINT2(q)));
|
|
1203
|
+
}
|
|
1204
|
+
highlight(p, q, max_hits = 100) {
|
|
1205
|
+
let hits = 0;
|
|
1206
|
+
let result = [];
|
|
1207
|
+
try {
|
|
1208
|
+
hits = Malloc(32 * max_hits);
|
|
1209
|
+
let n = libmupdf._wasm_highlight_selection(this.pointer, POINT(p), POINT2(q), hits, max_hits);
|
|
1210
|
+
for (let i = 0; i < n; ++i)
|
|
1211
|
+
result.push(fromQuad(hits + i * 32));
|
|
1212
|
+
}
|
|
1213
|
+
finally {
|
|
1214
|
+
Free(hits);
|
|
1215
|
+
}
|
|
1216
|
+
return result;
|
|
1217
|
+
}
|
|
1218
|
+
search(needle, max_hits = 500) {
|
|
1219
|
+
return runSearch(libmupdf._wasm_search_stext_page, this.pointer, needle, max_hits);
|
|
1220
|
+
}
|
|
1221
|
+
}
|
|
1222
|
+
StructuredText._drop = libmupdf._wasm_drop_stext_page;
|
|
1223
|
+
StructuredText.SELECT_MODE = [
|
|
1224
|
+
"chars",
|
|
1225
|
+
"words",
|
|
1226
|
+
"lines"
|
|
1227
|
+
];
|
|
1228
|
+
StructuredText.SELECT_CHARS = "chars";
|
|
1229
|
+
StructuredText.SELECT_WORDS = "words";
|
|
1230
|
+
StructuredText.SELECT_LINES = "lines";
|
|
1231
|
+
export class Device extends Userdata {
|
|
1232
|
+
constructor(pointer_or_callbacks) {
|
|
1233
|
+
if (typeof pointer_or_callbacks === "number")
|
|
1234
|
+
super(pointer_or_callbacks);
|
|
1235
|
+
else {
|
|
1236
|
+
let id = $libmupdf_device_id++;
|
|
1237
|
+
$libmupdf_device_table.set(id, pointer_or_callbacks);
|
|
1238
|
+
super(libmupdf._wasm_new_js_device(id));
|
|
1239
|
+
}
|
|
1240
|
+
}
|
|
1241
|
+
fillPath(path, evenOdd, ctm, colorspace, color, alpha) {
|
|
1242
|
+
checkType(path, Path);
|
|
1243
|
+
checkMatrix(ctm);
|
|
1244
|
+
checkType(colorspace, ColorSpace);
|
|
1245
|
+
checkColor(color);
|
|
1246
|
+
libmupdf._wasm_fill_path(this.pointer, path.pointer, evenOdd, MATRIX(ctm), colorspace.pointer, COLOR(color), alpha);
|
|
1247
|
+
}
|
|
1248
|
+
strokePath(path, stroke, ctm, colorspace, color, alpha) {
|
|
1249
|
+
checkType(path, Path);
|
|
1250
|
+
checkType(stroke, StrokeState);
|
|
1251
|
+
checkMatrix(ctm);
|
|
1252
|
+
checkType(colorspace, ColorSpace);
|
|
1253
|
+
checkColor(color);
|
|
1254
|
+
libmupdf._wasm_stroke_path(this.pointer, path.pointer, stroke.pointer, MATRIX(ctm), colorspace.pointer, COLOR(color), alpha);
|
|
1255
|
+
}
|
|
1256
|
+
clipPath(path, evenOdd, ctm) {
|
|
1257
|
+
checkType(path, Path);
|
|
1258
|
+
checkMatrix(ctm);
|
|
1259
|
+
libmupdf._wasm_clip_path(this.pointer, path.pointer, evenOdd, MATRIX(ctm));
|
|
1260
|
+
}
|
|
1261
|
+
clipStrokePath(path, stroke, ctm) {
|
|
1262
|
+
checkType(path, Path);
|
|
1263
|
+
checkType(stroke, StrokeState);
|
|
1264
|
+
checkMatrix(ctm);
|
|
1265
|
+
libmupdf._wasm_clip_stroke_path(this.pointer, path.pointer, stroke.pointer, MATRIX(ctm));
|
|
1266
|
+
}
|
|
1267
|
+
fillText(text, ctm, colorspace, color, alpha) {
|
|
1268
|
+
checkType(text, Text);
|
|
1269
|
+
checkMatrix(ctm);
|
|
1270
|
+
checkType(colorspace, ColorSpace);
|
|
1271
|
+
checkColor(color);
|
|
1272
|
+
libmupdf._wasm_fill_text(this.pointer, text.pointer, MATRIX(ctm), colorspace.pointer, COLOR(color), alpha);
|
|
1273
|
+
}
|
|
1274
|
+
strokeText(text, stroke, ctm, colorspace, color, alpha) {
|
|
1275
|
+
checkType(text, Text);
|
|
1276
|
+
checkType(stroke, StrokeState);
|
|
1277
|
+
checkMatrix(ctm);
|
|
1278
|
+
checkType(colorspace, ColorSpace);
|
|
1279
|
+
checkColor(color);
|
|
1280
|
+
libmupdf._wasm_stroke_text(this.pointer, text.pointer, stroke.pointer, MATRIX(ctm), colorspace.pointer, COLOR(color), alpha);
|
|
1281
|
+
}
|
|
1282
|
+
clipText(text, ctm) {
|
|
1283
|
+
checkType(text, Text);
|
|
1284
|
+
checkMatrix(ctm);
|
|
1285
|
+
libmupdf._wasm_clip_text(this.pointer, text.pointer, MATRIX(ctm));
|
|
1286
|
+
}
|
|
1287
|
+
clipStrokeText(text, stroke, ctm) {
|
|
1288
|
+
checkType(text, Text);
|
|
1289
|
+
checkType(stroke, StrokeState);
|
|
1290
|
+
checkMatrix(ctm);
|
|
1291
|
+
libmupdf._wasm_clip_stroke_text(this.pointer, text.pointer, stroke.pointer, MATRIX(ctm));
|
|
1292
|
+
}
|
|
1293
|
+
ignoreText(text, ctm) {
|
|
1294
|
+
checkType(text, Text);
|
|
1295
|
+
checkMatrix(ctm);
|
|
1296
|
+
libmupdf._wasm_ignore_text(this.pointer, text.pointer, MATRIX(ctm));
|
|
1297
|
+
}
|
|
1298
|
+
fillShade(shade, ctm, alpha) {
|
|
1299
|
+
checkType(shade, Shade);
|
|
1300
|
+
checkMatrix(ctm);
|
|
1301
|
+
libmupdf._wasm_fill_shade(this.pointer, shade.pointer, MATRIX(ctm), alpha);
|
|
1302
|
+
}
|
|
1303
|
+
fillImage(image, ctm, alpha) {
|
|
1304
|
+
checkType(image, Image);
|
|
1305
|
+
checkMatrix(ctm);
|
|
1306
|
+
libmupdf._wasm_fill_image(this.pointer, image.pointer, MATRIX(ctm), alpha);
|
|
1307
|
+
}
|
|
1308
|
+
fillImageMask(image, ctm, colorspace, color, alpha) {
|
|
1309
|
+
checkType(image, Image);
|
|
1310
|
+
checkMatrix(ctm);
|
|
1311
|
+
checkType(colorspace, ColorSpace);
|
|
1312
|
+
checkColor(color);
|
|
1313
|
+
libmupdf._wasm_fill_image_mask(this.pointer, image.pointer, MATRIX(ctm), colorspace.pointer, COLOR(color), alpha);
|
|
1314
|
+
}
|
|
1315
|
+
clipImageMask(image, ctm) {
|
|
1316
|
+
checkType(image, Image);
|
|
1317
|
+
checkMatrix(ctm);
|
|
1318
|
+
libmupdf._wasm_clip_image_mask(this.pointer, image.pointer, MATRIX(ctm));
|
|
1319
|
+
}
|
|
1320
|
+
popClip() {
|
|
1321
|
+
libmupdf._wasm_pop_clip(this.pointer);
|
|
1322
|
+
}
|
|
1323
|
+
beginMask(area, luminosity, colorspace, color) {
|
|
1324
|
+
checkRect(area);
|
|
1325
|
+
checkType(colorspace, ColorSpace);
|
|
1326
|
+
checkColor(color);
|
|
1327
|
+
libmupdf._wasm_begin_mask(this.pointer, RECT(area), luminosity, colorspace.pointer, COLOR(color));
|
|
1328
|
+
}
|
|
1329
|
+
endMask() {
|
|
1330
|
+
libmupdf._wasm_end_mask(this.pointer);
|
|
1331
|
+
}
|
|
1332
|
+
beginGroup(area, colorspace, isolated, knockout, blendmode, alpha) {
|
|
1333
|
+
checkRect(area);
|
|
1334
|
+
checkType(colorspace, ColorSpace);
|
|
1335
|
+
let blendmode_ix = ENUM(blendmode, Device.BLEND_MODES);
|
|
1336
|
+
libmupdf._wasm_begin_group(this.pointer, RECT(area), colorspace.pointer, isolated, knockout, blendmode_ix, alpha);
|
|
1337
|
+
}
|
|
1338
|
+
endGroup() {
|
|
1339
|
+
libmupdf._wasm_end_group(this.pointer);
|
|
1340
|
+
}
|
|
1341
|
+
beginTile(area, view, xstep, ystep, ctm, id, doc_id) {
|
|
1342
|
+
checkRect(area);
|
|
1343
|
+
checkRect(view);
|
|
1344
|
+
checkMatrix(ctm);
|
|
1345
|
+
return libmupdf._wasm_begin_tile(this.pointer, RECT(area), RECT2(view), xstep, ystep, MATRIX(ctm), id, doc_id);
|
|
1346
|
+
}
|
|
1347
|
+
endTile() {
|
|
1348
|
+
libmupdf._wasm_end_tile(this.pointer);
|
|
1349
|
+
}
|
|
1350
|
+
beginLayer(name) {
|
|
1351
|
+
libmupdf._wasm_begin_layer(this.pointer, STRING(name));
|
|
1352
|
+
}
|
|
1353
|
+
endLayer() {
|
|
1354
|
+
libmupdf._wasm_end_layer(this.pointer);
|
|
1355
|
+
}
|
|
1356
|
+
close() {
|
|
1357
|
+
libmupdf._wasm_close_device(this.pointer);
|
|
1358
|
+
}
|
|
1359
|
+
}
|
|
1360
|
+
Device._drop = libmupdf._wasm_drop_device;
|
|
1361
|
+
Device.BLEND_MODES = [
|
|
1362
|
+
"Normal",
|
|
1363
|
+
"Multiply",
|
|
1364
|
+
"Screen",
|
|
1365
|
+
"Overlay",
|
|
1366
|
+
"Darken",
|
|
1367
|
+
"Lighten",
|
|
1368
|
+
"ColorDodge",
|
|
1369
|
+
"ColorBurn",
|
|
1370
|
+
"HardLight",
|
|
1371
|
+
"SoftLight",
|
|
1372
|
+
"Difference",
|
|
1373
|
+
"Exclusion",
|
|
1374
|
+
"Hue",
|
|
1375
|
+
"Saturation",
|
|
1376
|
+
"Color",
|
|
1377
|
+
"Luminosity",
|
|
1378
|
+
];
|
|
1379
|
+
Device.BLEND_NORMAL = "Normal";
|
|
1380
|
+
Device.BLEND_MULTIPLY = "Multiply";
|
|
1381
|
+
Device.BLEND_SCREEN = "Screen";
|
|
1382
|
+
Device.BLEND_OVERLAY = "Overlay";
|
|
1383
|
+
Device.BLEND_DARKEN = "Darken";
|
|
1384
|
+
Device.BLEND_LIGHTEN = "Lighten";
|
|
1385
|
+
Device.BLEND_COLOR_DODGE = "ColorDodge";
|
|
1386
|
+
Device.BLEND_COLOR_BURN = "ColorBurn";
|
|
1387
|
+
Device.BLEND_HARD_LIGHT = "HardLight";
|
|
1388
|
+
Device.BLEND_SOFT_LIGHT = "SoftLight";
|
|
1389
|
+
Device.BLEND_DIFFERENCE = "Difference";
|
|
1390
|
+
Device.BLEND_EXCLUSION = "Exclusion";
|
|
1391
|
+
Device.BLEND_HUE = "Hue";
|
|
1392
|
+
Device.BLEND_SATURATION = "Saturation";
|
|
1393
|
+
Device.BLEND_COLOR = "Color";
|
|
1394
|
+
Device.BLEND_LUMINOSITY = "Luminosity";
|
|
1395
|
+
export class DrawDevice extends Device {
|
|
1396
|
+
constructor(matrix, pixmap) {
|
|
1397
|
+
checkMatrix(matrix);
|
|
1398
|
+
checkType(pixmap, Pixmap);
|
|
1399
|
+
super(libmupdf._wasm_new_draw_device(MATRIX(matrix), pixmap.pointer));
|
|
1400
|
+
}
|
|
1401
|
+
}
|
|
1402
|
+
export class DisplayListDevice extends Device {
|
|
1403
|
+
constructor(displayList) {
|
|
1404
|
+
checkType(displayList, DisplayList);
|
|
1405
|
+
super(libmupdf._wasm_new_display_list_device(displayList.pointer));
|
|
1406
|
+
}
|
|
1407
|
+
}
|
|
1408
|
+
export class DocumentWriter extends Userdata {
|
|
1409
|
+
constructor(buffer, format, options) {
|
|
1410
|
+
super(libmupdf._wasm_new_document_writer_with_buffer(BUFFER(buffer), STRING(format), STRING2(options)));
|
|
1411
|
+
}
|
|
1412
|
+
beginPage(mediabox) {
|
|
1413
|
+
checkRect(mediabox);
|
|
1414
|
+
return new Device(libmupdf._wasm_keep_device(libmupdf._wasm_begin_page(this.pointer, RECT(mediabox))));
|
|
1415
|
+
}
|
|
1416
|
+
endPage() {
|
|
1417
|
+
libmupdf._wasm_end_page(this.pointer);
|
|
1418
|
+
}
|
|
1419
|
+
close() {
|
|
1420
|
+
libmupdf._wasm_close_document_writer(this.pointer);
|
|
1421
|
+
}
|
|
1422
|
+
}
|
|
1423
|
+
DocumentWriter._drop = libmupdf._wasm_drop_document_writer;
|
|
1424
|
+
export class LinkDestination {
|
|
1425
|
+
constructor(chapter = 0, page = 0, type = "Fit", x = NaN, y = NaN, width = NaN, height = NaN, zoom = NaN) {
|
|
1426
|
+
this.chapter = chapter;
|
|
1427
|
+
this.page = page;
|
|
1428
|
+
this.type = type;
|
|
1429
|
+
this.x = x;
|
|
1430
|
+
this.y = y;
|
|
1431
|
+
this.width = width;
|
|
1432
|
+
this.height = height;
|
|
1433
|
+
this.zoom = zoom;
|
|
1434
|
+
}
|
|
1435
|
+
}
|
|
1436
|
+
LinkDestination.LINK_DEST = [
|
|
1437
|
+
"Fit",
|
|
1438
|
+
"FitB",
|
|
1439
|
+
"FitH",
|
|
1440
|
+
"FitBH",
|
|
1441
|
+
"FitV",
|
|
1442
|
+
"FitBV",
|
|
1443
|
+
"FitR",
|
|
1444
|
+
"XYZ",
|
|
1445
|
+
];
|
|
1446
|
+
LinkDestination.FIT = "Fit";
|
|
1447
|
+
LinkDestination.FIT_B = "FitB";
|
|
1448
|
+
LinkDestination.FIT_H = "FitH";
|
|
1449
|
+
LinkDestination.FIT_BH = "FitBH";
|
|
1450
|
+
LinkDestination.FIT_V = "FitV";
|
|
1451
|
+
LinkDestination.FIT_BV = "FitBV";
|
|
1452
|
+
LinkDestination.FIT_R = "FitR";
|
|
1453
|
+
LinkDestination.XYZ = "XYZ";
|
|
1454
|
+
export class Document extends Userdata {
|
|
1455
|
+
static openDocument(from, magic) {
|
|
1456
|
+
let pointer = 0;
|
|
1457
|
+
let free_from = false;
|
|
1458
|
+
if (typeof from === "string") {
|
|
1459
|
+
magic = from;
|
|
1460
|
+
if (node_fs)
|
|
1461
|
+
from = node_fs.readFileSync(from);
|
|
1462
|
+
else
|
|
1463
|
+
throw new Error("missing 'fs' module");
|
|
1464
|
+
}
|
|
1465
|
+
else {
|
|
1466
|
+
if (typeof magic === "undefined")
|
|
1467
|
+
magic = "application/pdf";
|
|
1468
|
+
}
|
|
1469
|
+
checkType(magic, "string");
|
|
1470
|
+
if (from instanceof ArrayBuffer || from instanceof Uint8Array) {
|
|
1471
|
+
from = new Buffer(from);
|
|
1472
|
+
free_from = true;
|
|
1473
|
+
}
|
|
1474
|
+
if (from instanceof Buffer)
|
|
1475
|
+
pointer = libmupdf._wasm_open_document_with_buffer(STRING(magic), from.pointer);
|
|
1476
|
+
else if (from instanceof Stream)
|
|
1477
|
+
pointer = libmupdf._wasm_open_document_with_stream(STRING(magic), from.pointer);
|
|
1478
|
+
else
|
|
1479
|
+
throw new Error("not a Buffer or Stream");
|
|
1480
|
+
if (free_from) {
|
|
1481
|
+
// Destroy any implicit Buffer instances immediately!
|
|
1482
|
+
// This may help the GC and FinalizationRegistry out when
|
|
1483
|
+
// processing many documents without a pause.
|
|
1484
|
+
from.destroy();
|
|
1485
|
+
}
|
|
1486
|
+
let pdf = libmupdf._wasm_pdf_document_from_fz_document(pointer);
|
|
1487
|
+
if (pdf)
|
|
1488
|
+
return new PDFDocument(pdf);
|
|
1489
|
+
return new Document(pointer);
|
|
1490
|
+
}
|
|
1491
|
+
formatLinkURI(dest) {
|
|
1492
|
+
return fromStringFree(libmupdf._wasm_format_link_uri(this.pointer, dest.chapter | 0, dest.page | 0, ENUM(dest.type, LinkDestination.LINK_DEST), +dest.x, +dest.y, +dest.width, +dest.height, +dest.zoom));
|
|
1493
|
+
}
|
|
1494
|
+
asPDF() {
|
|
1495
|
+
if (this instanceof PDFDocument)
|
|
1496
|
+
return this;
|
|
1497
|
+
return null;
|
|
1498
|
+
}
|
|
1499
|
+
isPDF() {
|
|
1500
|
+
return this instanceof PDFDocument;
|
|
1501
|
+
}
|
|
1502
|
+
needsPassword() {
|
|
1503
|
+
return !!libmupdf._wasm_needs_password(this.pointer);
|
|
1504
|
+
}
|
|
1505
|
+
authenticatePassword(password) {
|
|
1506
|
+
return libmupdf._wasm_authenticate_password(this.pointer, STRING(password));
|
|
1507
|
+
}
|
|
1508
|
+
hasPermission(perm) {
|
|
1509
|
+
let perm_ix = (typeof perm === "number") ? perm : Document.PERMISSION[perm];
|
|
1510
|
+
return !!libmupdf._wasm_has_permission(this.pointer, perm_ix);
|
|
1511
|
+
}
|
|
1512
|
+
getMetaData(key) {
|
|
1513
|
+
let value = libmupdf._wasm_lookup_metadata(this.pointer, STRING(key));
|
|
1514
|
+
if (value)
|
|
1515
|
+
return fromString(value);
|
|
1516
|
+
return undefined;
|
|
1517
|
+
}
|
|
1518
|
+
setMetaData(key, value) {
|
|
1519
|
+
libmupdf._wasm_set_metadata(this.pointer, STRING(key), STRING2(value));
|
|
1520
|
+
}
|
|
1521
|
+
countPages() {
|
|
1522
|
+
return libmupdf._wasm_count_pages(this.pointer);
|
|
1523
|
+
}
|
|
1524
|
+
isReflowable() {
|
|
1525
|
+
libmupdf._wasm_is_document_reflowable(this.pointer);
|
|
1526
|
+
}
|
|
1527
|
+
layout(w, h, em) {
|
|
1528
|
+
libmupdf._wasm_layout_document(this.pointer, w, h, em);
|
|
1529
|
+
}
|
|
1530
|
+
loadPage(index) {
|
|
1531
|
+
let fz_ptr = libmupdf._wasm_load_page(this.pointer, index);
|
|
1532
|
+
if (this instanceof PDFDocument) {
|
|
1533
|
+
let pdf_ptr = libmupdf._wasm_pdf_page_from_fz_page(fz_ptr);
|
|
1534
|
+
if (pdf_ptr)
|
|
1535
|
+
return new PDFPage(this, pdf_ptr);
|
|
1536
|
+
}
|
|
1537
|
+
return new Page(fz_ptr);
|
|
1538
|
+
}
|
|
1539
|
+
loadOutline() {
|
|
1540
|
+
let doc = this.pointer;
|
|
1541
|
+
function to_outline(outline) {
|
|
1542
|
+
let result = [];
|
|
1543
|
+
while (outline) {
|
|
1544
|
+
let title = libmupdf._wasm_outline_get_title(outline);
|
|
1545
|
+
let uri = libmupdf._wasm_outline_get_uri(outline);
|
|
1546
|
+
let open = libmupdf._wasm_outline_get_is_open(outline);
|
|
1547
|
+
let item = {
|
|
1548
|
+
title: title ? fromString(title) : undefined,
|
|
1549
|
+
uri: uri ? fromString(uri) : undefined,
|
|
1550
|
+
open: !!open,
|
|
1551
|
+
};
|
|
1552
|
+
let page = libmupdf._wasm_outline_get_page(doc, outline);
|
|
1553
|
+
if (page >= 0)
|
|
1554
|
+
item.page = page;
|
|
1555
|
+
let down = libmupdf._wasm_outline_get_down(outline);
|
|
1556
|
+
if (down)
|
|
1557
|
+
item.down = to_outline(down);
|
|
1558
|
+
result.push(item);
|
|
1559
|
+
outline = libmupdf._wasm_outline_get_next(outline);
|
|
1560
|
+
}
|
|
1561
|
+
return result;
|
|
1562
|
+
}
|
|
1563
|
+
let root = libmupdf._wasm_load_outline(doc);
|
|
1564
|
+
if (root)
|
|
1565
|
+
return to_outline(root);
|
|
1566
|
+
return null;
|
|
1567
|
+
}
|
|
1568
|
+
resolveLink(link) {
|
|
1569
|
+
if (link instanceof Link)
|
|
1570
|
+
return libmupdf._wasm_resolve_link(this.pointer, libmupdf._wasm_link_get_uri(link.pointer));
|
|
1571
|
+
return libmupdf._wasm_resolve_link(this.pointer, STRING(link));
|
|
1572
|
+
}
|
|
1573
|
+
resolveLinkDestination(link) {
|
|
1574
|
+
let dest;
|
|
1575
|
+
if (link instanceof Link)
|
|
1576
|
+
dest = libmupdf._wasm_resolve_link_dest(this.pointer, libmupdf._wasm_link_get_uri(link.pointer));
|
|
1577
|
+
else
|
|
1578
|
+
dest = libmupdf._wasm_resolve_link_dest(this.pointer, STRING(link));
|
|
1579
|
+
return {
|
|
1580
|
+
type: LinkDestination.LINK_DEST[libmupdf._wasm_link_dest_get_type(dest)],
|
|
1581
|
+
chapter: libmupdf._wasm_link_dest_get_chapter(dest),
|
|
1582
|
+
page: libmupdf._wasm_link_dest_get_page(dest),
|
|
1583
|
+
x: libmupdf._wasm_link_dest_get_x(dest),
|
|
1584
|
+
y: libmupdf._wasm_link_dest_get_y(dest),
|
|
1585
|
+
width: libmupdf._wasm_link_dest_get_w(dest),
|
|
1586
|
+
height: libmupdf._wasm_link_dest_get_h(dest),
|
|
1587
|
+
zoom: libmupdf._wasm_link_dest_get_zoom(dest),
|
|
1588
|
+
};
|
|
1589
|
+
}
|
|
1590
|
+
outlineIterator() {
|
|
1591
|
+
return new OutlineIterator(libmupdf._wasm_new_outline_iterator(this.pointer));
|
|
1592
|
+
}
|
|
1593
|
+
}
|
|
1594
|
+
Document._drop = libmupdf._wasm_drop_document;
|
|
1595
|
+
Document.META_FORMAT = "format";
|
|
1596
|
+
Document.META_ENCRYPTION = "encryption";
|
|
1597
|
+
Document.META_INFO_AUTHOR = "info:Author";
|
|
1598
|
+
Document.META_INFO_TITLE = "info:Title";
|
|
1599
|
+
Document.META_INFO_SUBJECT = "info:Subject";
|
|
1600
|
+
Document.META_INFO_KEYWORDS = "info:Keywords";
|
|
1601
|
+
Document.META_INFO_CREATOR = "info:Creator";
|
|
1602
|
+
Document.META_INFO_PRODUCER = "info:Producer";
|
|
1603
|
+
Document.META_INFO_CREATIONDATE = "info:CreationDate";
|
|
1604
|
+
Document.META_INFO_MODIFICATIONDATE = "info:ModDate";
|
|
1605
|
+
Document.PERMISSION_PRINT = "print";
|
|
1606
|
+
Document.PERMISSION_COPY = "copy";
|
|
1607
|
+
Document.PERMISSION_EDIT = "eedit";
|
|
1608
|
+
Document.PERMISSION_ANNOTATE = "annotate";
|
|
1609
|
+
Document.PERMISSION_FORM = "form";
|
|
1610
|
+
Document.PERMISSION_ACCESSIBILITY = "accessibility";
|
|
1611
|
+
Document.PERMISSION_ASSEMBLE = "assemble";
|
|
1612
|
+
Document.PERMISSION_PRINT_HQ = "print-hq";
|
|
1613
|
+
Document.PERMISSION = {
|
|
1614
|
+
"print": "p".charCodeAt(0),
|
|
1615
|
+
"copy": "c".charCodeAt(0),
|
|
1616
|
+
"edit": "e".charCodeAt(0),
|
|
1617
|
+
"annotate": "n".charCodeAt(0),
|
|
1618
|
+
"form": "f".charCodeAt(0),
|
|
1619
|
+
"accessibility": "y".charCodeAt(0),
|
|
1620
|
+
"assemble": "a".charCodeAt(0),
|
|
1621
|
+
"print-hq": "h".charCodeAt(0),
|
|
1622
|
+
};
|
|
1623
|
+
export class OutlineIterator extends Userdata {
|
|
1624
|
+
item() {
|
|
1625
|
+
let item = libmupdf._wasm_outline_iterator_item(this.pointer);
|
|
1626
|
+
if (item) {
|
|
1627
|
+
let title_ptr = libmupdf._wasm_outline_item_get_title(item);
|
|
1628
|
+
let uri_ptr = libmupdf._wasm_outline_item_get_uri(item);
|
|
1629
|
+
let is_open = libmupdf._wasm_outline_item_get_is_open(item);
|
|
1630
|
+
return {
|
|
1631
|
+
title: title_ptr ? fromString(title_ptr) : undefined,
|
|
1632
|
+
uri: uri_ptr ? fromString(uri_ptr) : undefined,
|
|
1633
|
+
open: !!is_open,
|
|
1634
|
+
};
|
|
1635
|
+
}
|
|
1636
|
+
return null;
|
|
1637
|
+
}
|
|
1638
|
+
next() {
|
|
1639
|
+
return libmupdf._wasm_outline_iterator_next(this.pointer);
|
|
1640
|
+
}
|
|
1641
|
+
prev() {
|
|
1642
|
+
return libmupdf._wasm_outline_iterator_prev(this.pointer);
|
|
1643
|
+
}
|
|
1644
|
+
up() {
|
|
1645
|
+
return libmupdf._wasm_outline_iterator_up(this.pointer);
|
|
1646
|
+
}
|
|
1647
|
+
down() {
|
|
1648
|
+
return libmupdf._wasm_outline_iterator_down(this.pointer);
|
|
1649
|
+
}
|
|
1650
|
+
delete() {
|
|
1651
|
+
return libmupdf._wasm_outline_iterator_delete(this.pointer);
|
|
1652
|
+
}
|
|
1653
|
+
insert(item) {
|
|
1654
|
+
return libmupdf._wasm_outline_iterator_insert(this.pointer, STRING_OPT(item.title), STRING2_OPT(item.uri), item.open);
|
|
1655
|
+
}
|
|
1656
|
+
update(item) {
|
|
1657
|
+
libmupdf._wasm_outline_iterator_update(this.pointer, STRING_OPT(item.title), STRING2_OPT(item.uri), item.open);
|
|
1658
|
+
}
|
|
1659
|
+
}
|
|
1660
|
+
OutlineIterator._drop = libmupdf._wasm_drop_outline_iterator;
|
|
1661
|
+
OutlineIterator.ITERATOR_DID_NOT_MOVE = -1;
|
|
1662
|
+
OutlineIterator.ITERATOR_AT_ITEM = 0;
|
|
1663
|
+
OutlineIterator.ITERATOR_AT_EMPTY = 1;
|
|
1664
|
+
OutlineIterator.FLAG_BOLD = 1;
|
|
1665
|
+
OutlineIterator.FLAG_ITALIC = 2;
|
|
1666
|
+
export class Link extends Userdata {
|
|
1667
|
+
getBounds() {
|
|
1668
|
+
return fromRect(libmupdf._wasm_link_get_rect(this.pointer));
|
|
1669
|
+
}
|
|
1670
|
+
setBounds(rect) {
|
|
1671
|
+
checkRect(rect);
|
|
1672
|
+
libmupdf._wasm_link_set_rect(this.pointer, RECT(rect));
|
|
1673
|
+
}
|
|
1674
|
+
getURI() {
|
|
1675
|
+
return fromString(libmupdf._wasm_link_get_uri(this.pointer));
|
|
1676
|
+
}
|
|
1677
|
+
setURI(uri) {
|
|
1678
|
+
checkType(uri, "string");
|
|
1679
|
+
libmupdf._wasm_link_set_uri(this.pointer, STRING(uri));
|
|
1680
|
+
}
|
|
1681
|
+
isExternal() {
|
|
1682
|
+
return /^\w[\w+-.]*:/.test(this.getURI());
|
|
1683
|
+
}
|
|
1684
|
+
}
|
|
1685
|
+
Link._drop = libmupdf._wasm_drop_link;
|
|
1686
|
+
export class Page extends Userdata {
|
|
1687
|
+
isPDF() {
|
|
1688
|
+
return this instanceof PDFPage;
|
|
1689
|
+
}
|
|
1690
|
+
getBounds(box = "CropBox") {
|
|
1691
|
+
let box_ix = ENUM(box, Page.BOXES);
|
|
1692
|
+
return fromRect(libmupdf._wasm_bound_page(this.pointer, box_ix));
|
|
1693
|
+
}
|
|
1694
|
+
getLabel() {
|
|
1695
|
+
return fromString(libmupdf._wasm_page_label(this.pointer));
|
|
1696
|
+
}
|
|
1697
|
+
run(device, matrix) {
|
|
1698
|
+
checkType(device, Device);
|
|
1699
|
+
checkMatrix(matrix);
|
|
1700
|
+
libmupdf._wasm_run_page(this.pointer, device.pointer, MATRIX(matrix));
|
|
1701
|
+
}
|
|
1702
|
+
runPageContents(device, matrix) {
|
|
1703
|
+
checkType(device, Device);
|
|
1704
|
+
checkMatrix(matrix);
|
|
1705
|
+
libmupdf._wasm_run_page_contents(this.pointer, device.pointer, MATRIX(matrix));
|
|
1706
|
+
}
|
|
1707
|
+
runPageAnnots(device, matrix) {
|
|
1708
|
+
checkType(device, Device);
|
|
1709
|
+
checkMatrix(matrix);
|
|
1710
|
+
libmupdf._wasm_run_page_annots(this.pointer, device.pointer, MATRIX(matrix));
|
|
1711
|
+
}
|
|
1712
|
+
runPageWidgets(device, matrix) {
|
|
1713
|
+
checkType(device, Device);
|
|
1714
|
+
checkMatrix(matrix);
|
|
1715
|
+
libmupdf._wasm_run_page_widgets(this.pointer, device.pointer, MATRIX(matrix));
|
|
1716
|
+
}
|
|
1717
|
+
toPixmap(matrix, colorspace, alpha = false, showExtras = true) {
|
|
1718
|
+
checkType(colorspace, ColorSpace);
|
|
1719
|
+
checkMatrix(matrix);
|
|
1720
|
+
let result;
|
|
1721
|
+
if (showExtras)
|
|
1722
|
+
result = libmupdf._wasm_new_pixmap_from_page(this.pointer, MATRIX(matrix), colorspace.pointer, alpha);
|
|
1723
|
+
else
|
|
1724
|
+
result = libmupdf._wasm_new_pixmap_from_page_contents(this.pointer, MATRIX(matrix), colorspace.pointer, alpha);
|
|
1725
|
+
return new Pixmap(result);
|
|
1726
|
+
}
|
|
1727
|
+
toDisplayList(showExtras = true) {
|
|
1728
|
+
let result;
|
|
1729
|
+
if (showExtras)
|
|
1730
|
+
result = libmupdf._wasm_new_display_list_from_page(this.pointer);
|
|
1731
|
+
else
|
|
1732
|
+
result = libmupdf._wasm_new_display_list_from_page_contents(this.pointer);
|
|
1733
|
+
return new DisplayList(result);
|
|
1734
|
+
}
|
|
1735
|
+
toStructuredText(options = "") {
|
|
1736
|
+
checkType(options, "string");
|
|
1737
|
+
return new StructuredText(libmupdf._wasm_new_stext_page_from_page(this.pointer, STRING(options)));
|
|
1738
|
+
}
|
|
1739
|
+
getLinks() {
|
|
1740
|
+
let links = [];
|
|
1741
|
+
let link = libmupdf._wasm_load_links(this.pointer);
|
|
1742
|
+
while (link) {
|
|
1743
|
+
links.push(new Link(libmupdf._wasm_keep_link(link)));
|
|
1744
|
+
link = libmupdf._wasm_link_get_next(link);
|
|
1745
|
+
}
|
|
1746
|
+
return links;
|
|
1747
|
+
}
|
|
1748
|
+
createLink(bbox, uri) {
|
|
1749
|
+
checkRect(bbox);
|
|
1750
|
+
return new Link(libmupdf._wasm_create_link(this.pointer, RECT(bbox), STRING(uri)));
|
|
1751
|
+
}
|
|
1752
|
+
deleteLink(link) {
|
|
1753
|
+
checkType(link, Link);
|
|
1754
|
+
libmupdf._wasm_delete_link(this.pointer, link.pointer);
|
|
1755
|
+
}
|
|
1756
|
+
search(needle, max_hits = 500) {
|
|
1757
|
+
return runSearch(libmupdf._wasm_search_page, this.pointer, needle, max_hits);
|
|
1758
|
+
}
|
|
1759
|
+
}
|
|
1760
|
+
Page._drop = libmupdf._wasm_drop_page;
|
|
1761
|
+
Page.BOXES = [
|
|
1762
|
+
"MediaBox",
|
|
1763
|
+
"CropBox",
|
|
1764
|
+
"BleedBox",
|
|
1765
|
+
"TrimBox",
|
|
1766
|
+
"ArtBox"
|
|
1767
|
+
];
|
|
1768
|
+
Page.MEDIA_BOX = "MediaBox";
|
|
1769
|
+
Page.CROP_BOX = "CropBox";
|
|
1770
|
+
Page.BLEED_BOX = "BleedBox";
|
|
1771
|
+
Page.TRIM_BOX = "TrimBox";
|
|
1772
|
+
Page.ART_BOX = "ArtBox";
|
|
1773
|
+
/* -------------------------------------------------------------------------- */
|
|
1774
|
+
export class PDFDocument extends Document {
|
|
1775
|
+
constructor(arg1) {
|
|
1776
|
+
if (typeof arg1 === "undefined")
|
|
1777
|
+
super(libmupdf._wasm_pdf_create_document());
|
|
1778
|
+
else if (typeof arg1 === "number")
|
|
1779
|
+
super(arg1);
|
|
1780
|
+
else if (arg1 instanceof PDFDocument) {
|
|
1781
|
+
super(arg1.pointer);
|
|
1782
|
+
libmupdf._wasm_keep_document(this.pointer);
|
|
1783
|
+
}
|
|
1784
|
+
else {
|
|
1785
|
+
let doc = Document.openDocument(arg1, "application/pdf");
|
|
1786
|
+
if (doc instanceof PDFDocument)
|
|
1787
|
+
return doc;
|
|
1788
|
+
throw new Error("not a PDF document");
|
|
1789
|
+
}
|
|
1790
|
+
}
|
|
1791
|
+
loadPage(index) {
|
|
1792
|
+
return super.loadPage(index);
|
|
1793
|
+
}
|
|
1794
|
+
// PDFObject instances are always bound to a document, so the WASM/JS value interface lives here.
|
|
1795
|
+
// Wrap a pdf_obj in a Userdata object. The pointer must be newly created or we already own it.
|
|
1796
|
+
_fromPDFObjectNew(ptr) {
|
|
1797
|
+
if (ptr === 0)
|
|
1798
|
+
return PDFObject.Null;
|
|
1799
|
+
return new PDFObject(this, ptr);
|
|
1800
|
+
}
|
|
1801
|
+
// Wrap a pdf_obj in a Userdata object. The pointer must be a borrowed pointer, so we have to take ownership.
|
|
1802
|
+
_fromPDFObjectKeep(ptr) {
|
|
1803
|
+
if (ptr === 0)
|
|
1804
|
+
return PDFObject.Null;
|
|
1805
|
+
return new PDFObject(this, libmupdf._wasm_pdf_keep_obj(ptr));
|
|
1806
|
+
}
|
|
1807
|
+
_toPDFObject(obj) {
|
|
1808
|
+
if (obj instanceof PDFObject)
|
|
1809
|
+
return obj;
|
|
1810
|
+
if (obj === null || obj === undefined)
|
|
1811
|
+
return this.newNull();
|
|
1812
|
+
if (typeof obj === "string") {
|
|
1813
|
+
// if a JS string is surrounded by parens, convert it to a PDF string
|
|
1814
|
+
if (obj.startsWith("(") && obj.endsWith(")"))
|
|
1815
|
+
return this.newString(obj.slice(1, -1));
|
|
1816
|
+
// otherwise treat it as a name
|
|
1817
|
+
return this.newName(obj);
|
|
1818
|
+
}
|
|
1819
|
+
if (typeof obj === "number") {
|
|
1820
|
+
if (obj === (obj | 0))
|
|
1821
|
+
return this.newInteger(obj);
|
|
1822
|
+
return this.newReal(obj);
|
|
1823
|
+
}
|
|
1824
|
+
if (typeof obj === "boolean")
|
|
1825
|
+
return this.newBoolean(obj);
|
|
1826
|
+
if (obj instanceof Array) {
|
|
1827
|
+
let result = this.newArray();
|
|
1828
|
+
for (let item of obj)
|
|
1829
|
+
result.push(item);
|
|
1830
|
+
return result;
|
|
1831
|
+
}
|
|
1832
|
+
if (obj instanceof Object) {
|
|
1833
|
+
let result = this.newDictionary();
|
|
1834
|
+
for (let key in obj)
|
|
1835
|
+
result.put(key, obj[key]);
|
|
1836
|
+
return result;
|
|
1837
|
+
}
|
|
1838
|
+
throw new TypeError("cannot convert value to PDFObject");
|
|
1839
|
+
}
|
|
1840
|
+
_PDFOBJ(obj) {
|
|
1841
|
+
// Note: We have to create a PDFObject instance for garbage collection.
|
|
1842
|
+
return this._toPDFObject(obj).pointer;
|
|
1843
|
+
}
|
|
1844
|
+
getVersion() {
|
|
1845
|
+
return libmupdf._wasm_pdf_version(this.pointer);
|
|
1846
|
+
}
|
|
1847
|
+
getLanguage() {
|
|
1848
|
+
return fromStringOrNull(libmupdf._wasm_pdf_document_language(this.pointer));
|
|
1849
|
+
}
|
|
1850
|
+
setLanguage(lang) {
|
|
1851
|
+
libmupdf._wasm_pdf_set_document_language(this.pointer, STRING(lang));
|
|
1852
|
+
}
|
|
1853
|
+
countObjects() {
|
|
1854
|
+
return libmupdf._wasm_pdf_xref_len(this.pointer);
|
|
1855
|
+
}
|
|
1856
|
+
getTrailer() {
|
|
1857
|
+
return new PDFObject(this, libmupdf._wasm_pdf_trailer(this.pointer));
|
|
1858
|
+
}
|
|
1859
|
+
createObject() {
|
|
1860
|
+
let num = libmupdf._wasm_pdf_create_object(this.pointer);
|
|
1861
|
+
return this._fromPDFObjectNew(libmupdf._wasm_pdf_new_indirect(this.pointer, num));
|
|
1862
|
+
}
|
|
1863
|
+
newNull() { return PDFObject.Null; }
|
|
1864
|
+
newBoolean(v) { return this._fromPDFObjectNew(libmupdf._wasm_pdf_new_bool(v)); }
|
|
1865
|
+
newInteger(v) { return this._fromPDFObjectNew(libmupdf._wasm_pdf_new_int(v)); }
|
|
1866
|
+
newReal(v) { return this._fromPDFObjectNew(libmupdf._wasm_pdf_new_real(v)); }
|
|
1867
|
+
newName(v) { return this._fromPDFObjectNew(libmupdf._wasm_pdf_new_name(STRING(v))); }
|
|
1868
|
+
newString(v) { return this._fromPDFObjectNew(libmupdf._wasm_pdf_new_text_string(STRING(v))); }
|
|
1869
|
+
newByteString(v) {
|
|
1870
|
+
if (v instanceof Array)
|
|
1871
|
+
v = Uint8Array.from(v);
|
|
1872
|
+
checkType(v, Uint8Array);
|
|
1873
|
+
let len = v.byteLength;
|
|
1874
|
+
let ptr = Malloc(len);
|
|
1875
|
+
libmupdf.HEAPU8.set(v, ptr);
|
|
1876
|
+
try {
|
|
1877
|
+
return this._fromPDFObjectNew(libmupdf._wasm_pdf_new_string(ptr, len));
|
|
1878
|
+
}
|
|
1879
|
+
finally {
|
|
1880
|
+
Free(ptr);
|
|
1881
|
+
}
|
|
1882
|
+
}
|
|
1883
|
+
newIndirect(v) { return this._fromPDFObjectNew(libmupdf._wasm_pdf_new_indirect(this.pointer, v)); }
|
|
1884
|
+
newArray() { return this._fromPDFObjectNew(libmupdf._wasm_pdf_new_array(this.pointer)); }
|
|
1885
|
+
newDictionary() { return this._fromPDFObjectNew(libmupdf._wasm_pdf_new_dict(this.pointer)); }
|
|
1886
|
+
deleteObject(num) {
|
|
1887
|
+
if (num instanceof PDFObject)
|
|
1888
|
+
num = num.asIndirect();
|
|
1889
|
+
else
|
|
1890
|
+
checkType(num, "number");
|
|
1891
|
+
libmupdf._wasm_pdf_delete_object(this.pointer, num);
|
|
1892
|
+
}
|
|
1893
|
+
addObject(obj) {
|
|
1894
|
+
return this._fromPDFObjectNew(libmupdf._wasm_pdf_add_object(this.pointer, this._PDFOBJ(obj)));
|
|
1895
|
+
}
|
|
1896
|
+
addStream(buf, obj) {
|
|
1897
|
+
return this._fromPDFObjectNew(libmupdf._wasm_pdf_add_stream(this.pointer, BUFFER(buf), this._PDFOBJ(obj), 0));
|
|
1898
|
+
}
|
|
1899
|
+
addRawStream(buf, obj) {
|
|
1900
|
+
return this._fromPDFObjectNew(libmupdf._wasm_pdf_add_stream(this.pointer, BUFFER(buf), this._PDFOBJ(obj), 1));
|
|
1901
|
+
}
|
|
1902
|
+
newGraftMap() {
|
|
1903
|
+
return new PDFGraftMap(this, libmupdf._wasm_pdf_new_graft_map(this.pointer));
|
|
1904
|
+
}
|
|
1905
|
+
graftObject(obj) {
|
|
1906
|
+
checkType(obj, PDFObject);
|
|
1907
|
+
return this._fromPDFObjectNew(libmupdf._wasm_pdf_graft_object(this.pointer, obj.pointer));
|
|
1908
|
+
}
|
|
1909
|
+
graftPage(to, srcDoc, srcPage) {
|
|
1910
|
+
checkType(to, "number");
|
|
1911
|
+
checkType(srcDoc, PDFDocument);
|
|
1912
|
+
checkType(srcPage, "number");
|
|
1913
|
+
libmupdf._wasm_pdf_graft_page(this.pointer, to, srcDoc.pointer, srcPage);
|
|
1914
|
+
}
|
|
1915
|
+
addSimpleFont(font, encoding = "Latin") {
|
|
1916
|
+
checkType(font, Font);
|
|
1917
|
+
var encoding_ix = ENUM(encoding, Font.SIMPLE_ENCODING);
|
|
1918
|
+
return this._fromPDFObjectNew(libmupdf._wasm_pdf_add_simple_font(this.pointer, font.pointer, encoding_ix));
|
|
1919
|
+
}
|
|
1920
|
+
addCJKFont(font, lang, wmode = 0, serif = true) {
|
|
1921
|
+
checkType(font, Font);
|
|
1922
|
+
if (typeof lang === "string")
|
|
1923
|
+
lang = Font.CJK_ORDERING_BY_LANG[lang];
|
|
1924
|
+
return this._fromPDFObjectNew(libmupdf._wasm_pdf_add_cjk_font(this.pointer, font.pointer, lang, wmode, serif));
|
|
1925
|
+
}
|
|
1926
|
+
addFont(font) {
|
|
1927
|
+
checkType(font, Font);
|
|
1928
|
+
return this._fromPDFObjectNew(libmupdf._wasm_pdf_add_cid_font(this.pointer, font.pointer));
|
|
1929
|
+
}
|
|
1930
|
+
addImage(image) {
|
|
1931
|
+
checkType(image, Image);
|
|
1932
|
+
return this._fromPDFObjectNew(libmupdf._wasm_pdf_add_image(this.pointer, image.pointer));
|
|
1933
|
+
}
|
|
1934
|
+
loadImage(ref) {
|
|
1935
|
+
checkType(ref, PDFObject);
|
|
1936
|
+
return new Image(libmupdf._wasm_pdf_load_image(this.pointer, ref.pointer));
|
|
1937
|
+
}
|
|
1938
|
+
findPage(index) {
|
|
1939
|
+
checkType(index, "number");
|
|
1940
|
+
return this._fromPDFObjectKeep(libmupdf._wasm_pdf_lookup_page_obj(this.pointer, index));
|
|
1941
|
+
}
|
|
1942
|
+
setPageTreeCache(enabled) {
|
|
1943
|
+
checkType(enabled, "boolean");
|
|
1944
|
+
libmupdf._wasm_pdf_set_page_tree_cache(this.pointer, enabled);
|
|
1945
|
+
}
|
|
1946
|
+
addPage(mediabox, rotate, resources, contents) {
|
|
1947
|
+
checkRect(mediabox);
|
|
1948
|
+
checkType(rotate, "number");
|
|
1949
|
+
return this._fromPDFObjectNew(libmupdf._wasm_pdf_add_page(this.pointer, RECT(mediabox), rotate, this._PDFOBJ(resources), BUFFER(contents)));
|
|
1950
|
+
}
|
|
1951
|
+
insertPage(at, obj) {
|
|
1952
|
+
checkType(at, "number");
|
|
1953
|
+
libmupdf._wasm_pdf_insert_page(this.pointer, at, this._PDFOBJ(obj));
|
|
1954
|
+
}
|
|
1955
|
+
deletePage(at) {
|
|
1956
|
+
checkType(at, "number");
|
|
1957
|
+
libmupdf._wasm_pdf_delete_page(this.pointer, at);
|
|
1958
|
+
}
|
|
1959
|
+
isEmbeddedFile(ref) {
|
|
1960
|
+
checkType(ref, PDFObject);
|
|
1961
|
+
return !!libmupdf._wasm_pdf_is_embedded_file(ref.pointer);
|
|
1962
|
+
}
|
|
1963
|
+
addEmbeddedFile(filename, mimetype, contents, created, modified, checksum = false) {
|
|
1964
|
+
checkType(filename, "string");
|
|
1965
|
+
checkType(mimetype, "string");
|
|
1966
|
+
checkType(created, Date);
|
|
1967
|
+
checkType(modified, Date);
|
|
1968
|
+
checkType(checksum, "boolean");
|
|
1969
|
+
return this._fromPDFObjectNew(libmupdf._wasm_pdf_add_embedded_file(this.pointer, STRING(filename), STRING2(mimetype), BUFFER(contents), created.getTime() / 1000 | 0, modified.getTime() / 1000 | 0, checksum));
|
|
1970
|
+
}
|
|
1971
|
+
getFilespecParams(ref) {
|
|
1972
|
+
checkType(ref, PDFObject);
|
|
1973
|
+
let ptr = libmupdf._wasm_pdf_get_filespec_params(ref.pointer);
|
|
1974
|
+
return {
|
|
1975
|
+
filename: fromString(libmupdf._wasm_pdf_filespec_params_get_filename(ptr)),
|
|
1976
|
+
mimetype: fromString(libmupdf._wasm_pdf_filespec_params_get_mimetype(ptr)),
|
|
1977
|
+
size: libmupdf._wasm_pdf_filespec_params_get_filename(ptr),
|
|
1978
|
+
creationDate: new Date(libmupdf._wasm_pdf_filespec_params_get_created(ptr) * 1000),
|
|
1979
|
+
modificationDate: new Date(libmupdf._wasm_pdf_filespec_params_get_modified(ptr) * 1000),
|
|
1980
|
+
};
|
|
1981
|
+
}
|
|
1982
|
+
getEmbeddedFileContents(ref) {
|
|
1983
|
+
checkType(ref, PDFObject);
|
|
1984
|
+
let contents = libmupdf._wasm_pdf_load_embedded_file_contents(ref.pointer);
|
|
1985
|
+
if (contents)
|
|
1986
|
+
return new Buffer(contents);
|
|
1987
|
+
return null;
|
|
1988
|
+
}
|
|
1989
|
+
getEmbeddedFiles() {
|
|
1990
|
+
function _getEmbeddedFilesRec(result, N) {
|
|
1991
|
+
var i, n;
|
|
1992
|
+
if (N.isDictionary()) {
|
|
1993
|
+
var NN = N.get("Names");
|
|
1994
|
+
if (NN)
|
|
1995
|
+
for (i = 0, n = NN.length; i < n; i += 2)
|
|
1996
|
+
result[NN.get(i + 0).asString()] = NN.get(i + 1);
|
|
1997
|
+
var NK = N.get("Kids");
|
|
1998
|
+
if (NK)
|
|
1999
|
+
for (i = 0, n = NK.length; i < n; i += 1)
|
|
2000
|
+
_getEmbeddedFilesRec(result, NK.get(i));
|
|
2001
|
+
}
|
|
2002
|
+
return result;
|
|
2003
|
+
}
|
|
2004
|
+
return _getEmbeddedFilesRec({}, this.getTrailer().get("Root", "Names", "EmbeddedFiles"));
|
|
2005
|
+
}
|
|
2006
|
+
loadNameTree(treeName) {
|
|
2007
|
+
function _loadNameTreeRec(dict, node) {
|
|
2008
|
+
var kids = node.get("Kids");
|
|
2009
|
+
if (kids && kids.isArray())
|
|
2010
|
+
for (var i = 0; i < kids.length; i += 1)
|
|
2011
|
+
_loadNameTreeRec(dict, kids.get(i));
|
|
2012
|
+
var names = node.get("Names");
|
|
2013
|
+
if (names && names.isArray())
|
|
2014
|
+
for (var i = 0; i < names.length; i += 2)
|
|
2015
|
+
dict[names.get(i).asString()] = names.get(i + 1);
|
|
2016
|
+
}
|
|
2017
|
+
var node = this.getTrailer().get("Root").get("Names").get(treeName);
|
|
2018
|
+
var dict = {};
|
|
2019
|
+
if (node.isDictionary())
|
|
2020
|
+
_loadNameTreeRec(dict, node);
|
|
2021
|
+
return dict;
|
|
2022
|
+
}
|
|
2023
|
+
insertEmbeddedFile(filename, filespec) {
|
|
2024
|
+
var efs = this.getEmbeddedFiles();
|
|
2025
|
+
efs[filename] = filespec;
|
|
2026
|
+
this._rewriteEmbeddedFiles(efs);
|
|
2027
|
+
}
|
|
2028
|
+
deleteEmbeddedFile(filename) {
|
|
2029
|
+
var efs = this.getEmbeddedFiles();
|
|
2030
|
+
delete efs[filename];
|
|
2031
|
+
this._rewriteEmbeddedFiles(efs);
|
|
2032
|
+
}
|
|
2033
|
+
_rewriteEmbeddedFiles(efs) {
|
|
2034
|
+
var efs_keys = Object.keys(efs);
|
|
2035
|
+
efs_keys.sort();
|
|
2036
|
+
var root = this.getTrailer().get("Root");
|
|
2037
|
+
var root_names = root.get("Names");
|
|
2038
|
+
if (!root_names.isDictionary())
|
|
2039
|
+
root_names = root.put("Names", this.newDictionary());
|
|
2040
|
+
var root_names_efs = root_names.put("EmbeddedFiles", this.newDictionary());
|
|
2041
|
+
var root_names_efs_names = root_names_efs.put("Names", this.newArray());
|
|
2042
|
+
for (var key of efs_keys) {
|
|
2043
|
+
root_names_efs_names.push(this.newString(key));
|
|
2044
|
+
root_names_efs_names.push(efs[key]);
|
|
2045
|
+
}
|
|
2046
|
+
}
|
|
2047
|
+
saveToBuffer(options = "") {
|
|
2048
|
+
var options_string;
|
|
2049
|
+
if (typeof options === "object") {
|
|
2050
|
+
options_string = Object.entries(options).map(kv => {
|
|
2051
|
+
var k = kv[0];
|
|
2052
|
+
var v = kv[1];
|
|
2053
|
+
if (v === true)
|
|
2054
|
+
return k + "=" + "yes";
|
|
2055
|
+
else if (v === false)
|
|
2056
|
+
return k + "=" + "no";
|
|
2057
|
+
else
|
|
2058
|
+
return k + "=" + String(v).replaceAll(",", ":");
|
|
2059
|
+
}).join(",");
|
|
2060
|
+
}
|
|
2061
|
+
else {
|
|
2062
|
+
options_string = options;
|
|
2063
|
+
}
|
|
2064
|
+
return new Buffer(libmupdf._wasm_pdf_write_document_buffer(this.pointer, STRING(options_string)));
|
|
2065
|
+
}
|
|
2066
|
+
save(filename, options = "") {
|
|
2067
|
+
if (node_fs)
|
|
2068
|
+
node_fs.writeFileSync(filename, this.saveToBuffer(options).asUint8Array());
|
|
2069
|
+
else
|
|
2070
|
+
throw new Error("missing 'fs' module");
|
|
2071
|
+
}
|
|
2072
|
+
setPageLabels(index, style = "D", prefix = "", start = 1) {
|
|
2073
|
+
libmupdf._wasm_pdf_set_page_labels(this.pointer, index, style.charCodeAt(0), STRING(prefix), start);
|
|
2074
|
+
}
|
|
2075
|
+
deletePageLabels(index) {
|
|
2076
|
+
libmupdf._wasm_pdf_delete_page_labels(this.pointer, index);
|
|
2077
|
+
}
|
|
2078
|
+
wasRepaired() {
|
|
2079
|
+
return !!libmupdf._wasm_pdf_was_repaired(this.pointer);
|
|
2080
|
+
}
|
|
2081
|
+
hasUnsavedChanges() {
|
|
2082
|
+
return !!libmupdf._wasm_pdf_has_unsaved_changes(this.pointer);
|
|
2083
|
+
}
|
|
2084
|
+
countVersions() {
|
|
2085
|
+
return libmupdf._wasm_pdf_count_versions(this.pointer);
|
|
2086
|
+
}
|
|
2087
|
+
countUnsavedVersions() {
|
|
2088
|
+
return libmupdf._wasm_pdf_count_unsaved_versions(this.pointer);
|
|
2089
|
+
}
|
|
2090
|
+
validateChangeHistory() {
|
|
2091
|
+
return libmupdf._wasm_pdf_validate_change_history(this.pointer);
|
|
2092
|
+
}
|
|
2093
|
+
canBeSavedIncrementally() {
|
|
2094
|
+
return !!libmupdf._wasm_pdf_can_be_saved_incrementally(this.pointer);
|
|
2095
|
+
}
|
|
2096
|
+
enableJournal() {
|
|
2097
|
+
libmupdf._wasm_pdf_enable_journal(this.pointer);
|
|
2098
|
+
}
|
|
2099
|
+
getJournal() {
|
|
2100
|
+
let position = libmupdf._wasm_pdf_undoredo_state_position(this.pointer);
|
|
2101
|
+
let n = libmupdf._wasm_pdf_undoredo_state_count(this.pointer);
|
|
2102
|
+
let steps = [];
|
|
2103
|
+
for (let i = 0; i < n; ++i)
|
|
2104
|
+
steps.push(fromString(libmupdf._wasm_pdf_undoredo_step(this.pointer, i)));
|
|
2105
|
+
return { position, steps };
|
|
2106
|
+
}
|
|
2107
|
+
beginOperation(op) {
|
|
2108
|
+
libmupdf._wasm_pdf_begin_operation(this.pointer, STRING(op));
|
|
2109
|
+
}
|
|
2110
|
+
beginImplicitOperation() {
|
|
2111
|
+
libmupdf._wasm_pdf_begin_implicit_operation(this.pointer);
|
|
2112
|
+
}
|
|
2113
|
+
endOperation() {
|
|
2114
|
+
libmupdf._wasm_pdf_end_operation(this.pointer);
|
|
2115
|
+
}
|
|
2116
|
+
abandonOperation() {
|
|
2117
|
+
libmupdf._wasm_pdf_abandon_operation(this.pointer);
|
|
2118
|
+
}
|
|
2119
|
+
canUndo() {
|
|
2120
|
+
return !!libmupdf._wasm_pdf_can_undo(this.pointer);
|
|
2121
|
+
}
|
|
2122
|
+
canRedo() {
|
|
2123
|
+
return !!libmupdf._wasm_pdf_can_redo(this.pointer);
|
|
2124
|
+
}
|
|
2125
|
+
undo() {
|
|
2126
|
+
libmupdf._wasm_pdf_undo(this.pointer);
|
|
2127
|
+
}
|
|
2128
|
+
redo() {
|
|
2129
|
+
libmupdf._wasm_pdf_redo(this.pointer);
|
|
2130
|
+
}
|
|
2131
|
+
isJSSupported() {
|
|
2132
|
+
return !!libmupdf._wasm_pdf_js_supported(this.pointer);
|
|
2133
|
+
}
|
|
2134
|
+
enableJS() {
|
|
2135
|
+
libmupdf._wasm_pdf_enable_js(this.pointer);
|
|
2136
|
+
}
|
|
2137
|
+
disableJS() {
|
|
2138
|
+
libmupdf._wasm_pdf_disable_js(this.pointer);
|
|
2139
|
+
}
|
|
2140
|
+
setJSEventListener(_listener) {
|
|
2141
|
+
throw "TODO";
|
|
2142
|
+
}
|
|
2143
|
+
rearrangePages(pages) {
|
|
2144
|
+
let n = pages.length;
|
|
2145
|
+
let ptr = Malloc(n << 2);
|
|
2146
|
+
for (let i = 0; i < n; ++i)
|
|
2147
|
+
libmupdf.HEAPU32[(ptr >> 2) + i] = pages[i] || 0;
|
|
2148
|
+
try {
|
|
2149
|
+
libmupdf._wasm_pdf_rearrange_pages(this.pointer, n, ptr);
|
|
2150
|
+
}
|
|
2151
|
+
finally {
|
|
2152
|
+
Free(ptr);
|
|
2153
|
+
}
|
|
2154
|
+
}
|
|
2155
|
+
subsetFonts() {
|
|
2156
|
+
libmupdf._wasm_pdf_subset_fonts(this.pointer);
|
|
2157
|
+
}
|
|
2158
|
+
bake(bakeAnnots = true, bakeWidgets = true) {
|
|
2159
|
+
libmupdf._wasm_pdf_bake_document(this.pointer, bakeAnnots, bakeWidgets);
|
|
2160
|
+
}
|
|
2161
|
+
countLayerConfigs() {
|
|
2162
|
+
return libmupdf._wasm_pdf_count_layer_configs(this.pointer);
|
|
2163
|
+
}
|
|
2164
|
+
getLayerConfigCreator(config) {
|
|
2165
|
+
return fromString(libmupdf._wasm_pdf_layer_config_creator(this.pointer, config));
|
|
2166
|
+
}
|
|
2167
|
+
getLayerConfigName(config) {
|
|
2168
|
+
return fromString(libmupdf._wasm_pdf_layer_config_name(this.pointer, config));
|
|
2169
|
+
}
|
|
2170
|
+
selectLayerConfig(config) {
|
|
2171
|
+
libmupdf._wasm_pdf_select_layer_config(this.pointer, config);
|
|
2172
|
+
}
|
|
2173
|
+
countLayerConfigUIs() {
|
|
2174
|
+
return libmupdf._wasm_pdf_count_layer_config_uis(this.pointer);
|
|
2175
|
+
}
|
|
2176
|
+
getLayerConfigUIInfo(configui) {
|
|
2177
|
+
return fromLayerConfigUIInfo(libmupdf._wasm_pdf_layer_config_ui_info(this.pointer, configui));
|
|
2178
|
+
}
|
|
2179
|
+
countLayers() {
|
|
2180
|
+
return libmupdf._wasm_pdf_count_layers(this.pointer);
|
|
2181
|
+
}
|
|
2182
|
+
isLayerVisible(layer) {
|
|
2183
|
+
return !!libmupdf._wasm_pdf_layer_is_enabled(this.pointer, layer);
|
|
2184
|
+
}
|
|
2185
|
+
setLayerVisible(layer, visible) {
|
|
2186
|
+
libmupdf._wasm_pdf_enable_layer(this.pointer, layer, Number(visible));
|
|
2187
|
+
}
|
|
2188
|
+
getLayerName(layer) {
|
|
2189
|
+
return fromString(libmupdf._wasm_pdf_layer_name(this.pointer, layer));
|
|
2190
|
+
}
|
|
2191
|
+
resetForm(fields, exclude) {
|
|
2192
|
+
libmupdf._wasm_pdf_reset_form(this.pointer, this._PDFOBJ(fields), Number(exclude));
|
|
2193
|
+
}
|
|
2194
|
+
}
|
|
2195
|
+
PDFDocument.PAGE_LABEL_NONE = "\0";
|
|
2196
|
+
PDFDocument.PAGE_LABEL_DECIMAL = "D";
|
|
2197
|
+
PDFDocument.PAGE_LABEL_ROMAN_UC = "R";
|
|
2198
|
+
PDFDocument.PAGE_LABEL_ROMAN_LC = "r";
|
|
2199
|
+
PDFDocument.PAGE_LABEL_ALPHA_UC = "A";
|
|
2200
|
+
PDFDocument.PAGE_LABEL_ALPHA_LC = "a";
|
|
2201
|
+
export class PDFPage extends Page {
|
|
2202
|
+
// PRIVATE
|
|
2203
|
+
constructor(doc, pointer) {
|
|
2204
|
+
super(pointer);
|
|
2205
|
+
this._doc = doc;
|
|
2206
|
+
this._annots = null;
|
|
2207
|
+
this._widgets = null;
|
|
2208
|
+
}
|
|
2209
|
+
getObject() {
|
|
2210
|
+
return this._doc._fromPDFObjectKeep(libmupdf._wasm_pdf_page_get_obj(this.pointer));
|
|
2211
|
+
}
|
|
2212
|
+
getTransform() {
|
|
2213
|
+
return fromMatrix(libmupdf._wasm_pdf_page_transform(this.pointer));
|
|
2214
|
+
}
|
|
2215
|
+
setPageBox(box, rect) {
|
|
2216
|
+
let box_ix = ENUM(box, Page.BOXES);
|
|
2217
|
+
checkRect(rect);
|
|
2218
|
+
libmupdf._wasm_pdf_set_page_box(this.pointer, box_ix, RECT(rect));
|
|
2219
|
+
}
|
|
2220
|
+
toPixmap(matrix, colorspace, alpha = false, showExtras = true, usage = "View", box = "CropBox") {
|
|
2221
|
+
checkMatrix(matrix);
|
|
2222
|
+
checkType(colorspace, ColorSpace);
|
|
2223
|
+
let box_ix = ENUM(box, Page.BOXES);
|
|
2224
|
+
let result;
|
|
2225
|
+
if (showExtras)
|
|
2226
|
+
result = libmupdf._wasm_pdf_new_pixmap_from_page_with_usage(this.pointer, MATRIX(matrix), colorspace.pointer, alpha, STRING(usage), box_ix);
|
|
2227
|
+
else
|
|
2228
|
+
result = libmupdf._wasm_pdf_new_pixmap_from_page_contents_with_usage(this.pointer, MATRIX(matrix), colorspace.pointer, alpha, STRING(usage), box_ix);
|
|
2229
|
+
return new Pixmap(result);
|
|
2230
|
+
}
|
|
2231
|
+
getWidgets() {
|
|
2232
|
+
if (!this._widgets) {
|
|
2233
|
+
this._widgets = [];
|
|
2234
|
+
let widget = libmupdf._wasm_pdf_first_widget(this.pointer);
|
|
2235
|
+
while (widget) {
|
|
2236
|
+
this._widgets.push(new PDFWidget(this._doc, libmupdf._wasm_pdf_keep_annot(widget)));
|
|
2237
|
+
widget = libmupdf._wasm_pdf_next_widget(widget);
|
|
2238
|
+
}
|
|
2239
|
+
}
|
|
2240
|
+
return this._widgets;
|
|
2241
|
+
}
|
|
2242
|
+
getAnnotations() {
|
|
2243
|
+
if (!this._annots) {
|
|
2244
|
+
this._annots = [];
|
|
2245
|
+
let annot = libmupdf._wasm_pdf_first_annot(this.pointer);
|
|
2246
|
+
while (annot) {
|
|
2247
|
+
this._annots.push(new PDFAnnotation(this._doc, libmupdf._wasm_pdf_keep_annot(annot)));
|
|
2248
|
+
annot = libmupdf._wasm_pdf_next_annot(annot);
|
|
2249
|
+
}
|
|
2250
|
+
}
|
|
2251
|
+
return this._annots;
|
|
2252
|
+
}
|
|
2253
|
+
createAnnotation(type) {
|
|
2254
|
+
let type_ix = ENUM(type, PDFAnnotation.ANNOT_TYPES);
|
|
2255
|
+
let annot = new PDFAnnotation(this._doc, libmupdf._wasm_pdf_create_annot(this.pointer, type_ix));
|
|
2256
|
+
if (this._annots)
|
|
2257
|
+
this._annots.push(annot);
|
|
2258
|
+
return annot;
|
|
2259
|
+
}
|
|
2260
|
+
deleteAnnotation(annot) {
|
|
2261
|
+
checkType(annot, PDFAnnotation);
|
|
2262
|
+
libmupdf._wasm_pdf_delete_annot(this.pointer, annot.pointer);
|
|
2263
|
+
if (this._annots) {
|
|
2264
|
+
let ix = this._annots.indexOf(annot);
|
|
2265
|
+
if (ix >= 0)
|
|
2266
|
+
this._annots.splice(ix, 1);
|
|
2267
|
+
}
|
|
2268
|
+
}
|
|
2269
|
+
applyRedactions(black_boxes = true, image_method = 2, line_art_method = 1, text_method = 0) {
|
|
2270
|
+
libmupdf._wasm_pdf_redact_page(this.pointer, Number(black_boxes), image_method, line_art_method, text_method);
|
|
2271
|
+
}
|
|
2272
|
+
update() {
|
|
2273
|
+
return !!libmupdf._wasm_pdf_update_page(this.pointer);
|
|
2274
|
+
}
|
|
2275
|
+
}
|
|
2276
|
+
PDFPage.REDACT_IMAGE_NONE = 0;
|
|
2277
|
+
PDFPage.REDACT_IMAGE_REMOVE = 1;
|
|
2278
|
+
PDFPage.REDACT_IMAGE_PIXELS = 2;
|
|
2279
|
+
PDFPage.REDACT_IMAGE_UNLESS_INVISIBLE = 3;
|
|
2280
|
+
PDFPage.REDACT_LINE_ART_NONE = 0;
|
|
2281
|
+
PDFPage.REDACT_LINE_ART_REMOVE_IF_COVERED = 1;
|
|
2282
|
+
PDFPage.REDACT_LINE_ART_REMOVE_IF_TOUCHED = 2;
|
|
2283
|
+
PDFPage.REDACT_TEXT_REMOVE = 0;
|
|
2284
|
+
PDFPage.REDACT_TEXT_NONE = 1;
|
|
2285
|
+
export class PDFObject extends Userdata {
|
|
2286
|
+
// PRIVATE
|
|
2287
|
+
constructor(doc, pointer) {
|
|
2288
|
+
super(libmupdf._wasm_pdf_keep_obj(pointer));
|
|
2289
|
+
this._doc = doc;
|
|
2290
|
+
}
|
|
2291
|
+
isNull() { return this === PDFObject.Null; }
|
|
2292
|
+
isIndirect() { return !!libmupdf._wasm_pdf_is_indirect(this.pointer); }
|
|
2293
|
+
isBoolean() { return !!libmupdf._wasm_pdf_is_bool(this.pointer); }
|
|
2294
|
+
isInteger() { return !!libmupdf._wasm_pdf_is_int(this.pointer); }
|
|
2295
|
+
isReal() { return !!libmupdf._wasm_pdf_is_real(this.pointer); }
|
|
2296
|
+
isNumber() { return !!libmupdf._wasm_pdf_is_number(this.pointer); }
|
|
2297
|
+
isName() { return !!libmupdf._wasm_pdf_is_name(this.pointer); }
|
|
2298
|
+
isString() { return !!libmupdf._wasm_pdf_is_string(this.pointer); }
|
|
2299
|
+
isArray() { return !!libmupdf._wasm_pdf_is_array(this.pointer); }
|
|
2300
|
+
isDictionary() { return !!libmupdf._wasm_pdf_is_dict(this.pointer); }
|
|
2301
|
+
isStream() { return !!libmupdf._wasm_pdf_is_stream(this.pointer); }
|
|
2302
|
+
asIndirect() { return libmupdf._wasm_pdf_to_num(this.pointer); }
|
|
2303
|
+
asBoolean() { return !!libmupdf._wasm_pdf_to_bool(this.pointer); }
|
|
2304
|
+
asNumber() { return libmupdf._wasm_pdf_to_real(this.pointer); }
|
|
2305
|
+
asName() { return fromString(libmupdf._wasm_pdf_to_name(this.pointer)); }
|
|
2306
|
+
asString() { return fromString(libmupdf._wasm_pdf_to_text_string(this.pointer)); }
|
|
2307
|
+
asByteString() {
|
|
2308
|
+
let ptr = libmupdf._wasm_pdf_to_string(this.pointer, _wasm_int);
|
|
2309
|
+
let len = libmupdf.HEAPU32[_wasm_int >> 2];
|
|
2310
|
+
return libmupdf.HEAPU8.slice(ptr, ptr + len);
|
|
2311
|
+
}
|
|
2312
|
+
readStream() { return new Buffer(libmupdf._wasm_pdf_load_stream(this.pointer)); }
|
|
2313
|
+
readRawStream() { return new Buffer(libmupdf._wasm_pdf_load_raw_stream(this.pointer)); }
|
|
2314
|
+
writeObject(obj) {
|
|
2315
|
+
if (!this.isIndirect())
|
|
2316
|
+
throw new TypeError("can only call PDFObject.writeObject on an indirect reference");
|
|
2317
|
+
libmupdf._wasm_pdf_update_object(this._doc.pointer, this.asIndirect(), this._doc._PDFOBJ(obj));
|
|
2318
|
+
}
|
|
2319
|
+
writeStream(buf) {
|
|
2320
|
+
if (!this.isIndirect())
|
|
2321
|
+
throw new TypeError("can only call PDFObject.writeStream on an indirect reference");
|
|
2322
|
+
libmupdf._wasm_pdf_update_stream(this._doc.pointer, this.pointer, BUFFER(buf), 0);
|
|
2323
|
+
}
|
|
2324
|
+
writeRawStream(buf) {
|
|
2325
|
+
if (!this.isIndirect())
|
|
2326
|
+
throw new TypeError("can only call PDFObject.writeRawStream on an indirect reference");
|
|
2327
|
+
libmupdf._wasm_pdf_update_stream(this._doc.pointer, this.pointer, BUFFER(buf), 1);
|
|
2328
|
+
}
|
|
2329
|
+
resolve() {
|
|
2330
|
+
return this._doc._fromPDFObjectKeep(libmupdf._wasm_pdf_resolve_indirect(this.pointer));
|
|
2331
|
+
}
|
|
2332
|
+
get length() {
|
|
2333
|
+
return libmupdf._wasm_pdf_array_len(this.pointer);
|
|
2334
|
+
}
|
|
2335
|
+
set length(_) {
|
|
2336
|
+
throw new TypeError("object length is read-only");
|
|
2337
|
+
}
|
|
2338
|
+
_get(path) {
|
|
2339
|
+
let obj = this.pointer;
|
|
2340
|
+
for (let key of path) {
|
|
2341
|
+
if (typeof key === "number")
|
|
2342
|
+
obj = libmupdf._wasm_pdf_array_get(obj, key);
|
|
2343
|
+
else if (key instanceof PDFObject)
|
|
2344
|
+
obj = libmupdf._wasm_pdf_dict_get(obj, key.pointer);
|
|
2345
|
+
else
|
|
2346
|
+
obj = libmupdf._wasm_pdf_dict_gets(obj, STRING(key));
|
|
2347
|
+
if (obj === 0)
|
|
2348
|
+
break;
|
|
2349
|
+
}
|
|
2350
|
+
return obj;
|
|
2351
|
+
}
|
|
2352
|
+
get(...path) {
|
|
2353
|
+
return this._doc._fromPDFObjectKeep(this._get(path));
|
|
2354
|
+
}
|
|
2355
|
+
getInheritable(key) {
|
|
2356
|
+
if (key instanceof PDFObject)
|
|
2357
|
+
return this._doc._fromPDFObjectKeep(libmupdf._wasm_pdf_dict_get_inheritable(this.pointer, key.pointer));
|
|
2358
|
+
return this._doc._fromPDFObjectKeep(libmupdf._wasm_pdf_dict_gets_inheritable(this.pointer, STRING(key)));
|
|
2359
|
+
}
|
|
2360
|
+
put(key, value) {
|
|
2361
|
+
value = this._doc._toPDFObject(value);
|
|
2362
|
+
if (typeof key === "number")
|
|
2363
|
+
libmupdf._wasm_pdf_array_put(this.pointer, key, value.pointer);
|
|
2364
|
+
else if (key instanceof PDFObject)
|
|
2365
|
+
libmupdf._wasm_pdf_dict_put(this.pointer, key.pointer, value.pointer);
|
|
2366
|
+
else
|
|
2367
|
+
libmupdf._wasm_pdf_dict_puts(this.pointer, STRING(key), value.pointer);
|
|
2368
|
+
return value;
|
|
2369
|
+
}
|
|
2370
|
+
push(value) {
|
|
2371
|
+
value = this._doc._toPDFObject(value);
|
|
2372
|
+
libmupdf._wasm_pdf_array_push(this.pointer, value.pointer);
|
|
2373
|
+
return value;
|
|
2374
|
+
}
|
|
2375
|
+
delete(key) {
|
|
2376
|
+
if (typeof key === "number")
|
|
2377
|
+
libmupdf._wasm_pdf_array_delete(this.pointer, key);
|
|
2378
|
+
else if (key instanceof PDFObject)
|
|
2379
|
+
libmupdf._wasm_pdf_dict_del(this.pointer, key.pointer);
|
|
2380
|
+
else
|
|
2381
|
+
libmupdf._wasm_pdf_dict_dels(this.pointer, STRING(key));
|
|
2382
|
+
}
|
|
2383
|
+
valueOf() {
|
|
2384
|
+
if (this.isNull())
|
|
2385
|
+
return null;
|
|
2386
|
+
if (this.isBoolean())
|
|
2387
|
+
return this.asBoolean();
|
|
2388
|
+
if (this.isNumber())
|
|
2389
|
+
return this.asNumber();
|
|
2390
|
+
if (this.isName())
|
|
2391
|
+
return this.asName();
|
|
2392
|
+
if (this.isString())
|
|
2393
|
+
return this.asString();
|
|
2394
|
+
if (this.isIndirect())
|
|
2395
|
+
return `${this.asIndirect()} 0 R`;
|
|
2396
|
+
return this;
|
|
2397
|
+
}
|
|
2398
|
+
toString(tight = true, ascii = true) {
|
|
2399
|
+
return fromStringFree(libmupdf._wasm_pdf_sprint_obj(this.pointer, tight, ascii));
|
|
2400
|
+
}
|
|
2401
|
+
forEach(fn) {
|
|
2402
|
+
if (this.isArray()) {
|
|
2403
|
+
let n = this.length;
|
|
2404
|
+
for (let i = 0; i < n; ++i)
|
|
2405
|
+
fn(this.get(i), i, this);
|
|
2406
|
+
}
|
|
2407
|
+
else if (this.isDictionary()) {
|
|
2408
|
+
let n = libmupdf._wasm_pdf_dict_len(this.pointer);
|
|
2409
|
+
for (let i = 0; i < n; ++i) {
|
|
2410
|
+
let key = this._doc._fromPDFObjectKeep(libmupdf._wasm_pdf_dict_get_key(this.pointer, i));
|
|
2411
|
+
let val = this._doc._fromPDFObjectKeep(libmupdf._wasm_pdf_dict_get_val(this.pointer, i));
|
|
2412
|
+
fn(val, key.asName(), this);
|
|
2413
|
+
}
|
|
2414
|
+
}
|
|
2415
|
+
}
|
|
2416
|
+
// Convert to plain Javascript values, objects, and arrays.
|
|
2417
|
+
// If you want to resolve indirect references, pass an empty object or array as the first argument.
|
|
2418
|
+
// On exit, this object will contain all indirect objects encountered indexed by object number.
|
|
2419
|
+
// Note: This function will omit cyclic references.
|
|
2420
|
+
asJS(seen) {
|
|
2421
|
+
if (this.isIndirect()) {
|
|
2422
|
+
let ref = this.asIndirect();
|
|
2423
|
+
if (!seen)
|
|
2424
|
+
return `${ref} 0 R`;
|
|
2425
|
+
if (ref in seen)
|
|
2426
|
+
return seen[ref];
|
|
2427
|
+
seen[ref] = PDFObject.Null; // stop recursion!
|
|
2428
|
+
return seen[ref] = this.resolve().asJS(seen);
|
|
2429
|
+
}
|
|
2430
|
+
if (this.isArray()) {
|
|
2431
|
+
let result = [];
|
|
2432
|
+
this.forEach(val => {
|
|
2433
|
+
result.push(val.asJS(seen));
|
|
2434
|
+
});
|
|
2435
|
+
return result;
|
|
2436
|
+
}
|
|
2437
|
+
if (this.isDictionary()) {
|
|
2438
|
+
let result = {};
|
|
2439
|
+
this.forEach((val, key) => {
|
|
2440
|
+
result[key] = val.asJS(seen);
|
|
2441
|
+
});
|
|
2442
|
+
return result;
|
|
2443
|
+
}
|
|
2444
|
+
return this.valueOf();
|
|
2445
|
+
}
|
|
2446
|
+
}
|
|
2447
|
+
PDFObject._drop = libmupdf._wasm_pdf_drop_obj;
|
|
2448
|
+
PDFObject.Null = new PDFObject(null, 0);
|
|
2449
|
+
export class PDFGraftMap extends Userdata {
|
|
2450
|
+
// PRIVATE
|
|
2451
|
+
constructor(doc, pointer) {
|
|
2452
|
+
super(pointer);
|
|
2453
|
+
this._doc = doc;
|
|
2454
|
+
}
|
|
2455
|
+
graftObject(obj) {
|
|
2456
|
+
checkType(obj, PDFObject);
|
|
2457
|
+
return this._doc._fromPDFObjectNew(libmupdf._wasm_pdf_graft_mapped_object(this.pointer, obj.pointer));
|
|
2458
|
+
}
|
|
2459
|
+
graftPage(to, srcDoc, srcPage) {
|
|
2460
|
+
checkType(to, "number");
|
|
2461
|
+
checkType(srcDoc, PDFDocument);
|
|
2462
|
+
checkType(srcPage, "number");
|
|
2463
|
+
libmupdf._wasm_pdf_graft_mapped_page(this.pointer, to, srcDoc.pointer, srcPage);
|
|
2464
|
+
}
|
|
2465
|
+
}
|
|
2466
|
+
PDFGraftMap._drop = libmupdf._wasm_pdf_drop_graft_map;
|
|
2467
|
+
export class PDFAnnotation extends Userdata {
|
|
2468
|
+
// PRIVATE
|
|
2469
|
+
constructor(doc, pointer) {
|
|
2470
|
+
super(pointer);
|
|
2471
|
+
this._doc = doc;
|
|
2472
|
+
}
|
|
2473
|
+
getObject() {
|
|
2474
|
+
return this._doc._fromPDFObjectKeep(libmupdf._wasm_pdf_annot_obj(this.pointer));
|
|
2475
|
+
}
|
|
2476
|
+
getBounds() {
|
|
2477
|
+
return fromRect(libmupdf._wasm_pdf_bound_annot(this.pointer));
|
|
2478
|
+
}
|
|
2479
|
+
run(device, matrix) {
|
|
2480
|
+
checkType(device, Device);
|
|
2481
|
+
checkMatrix(matrix);
|
|
2482
|
+
libmupdf._wasm_pdf_run_annot(this.pointer, device.pointer, MATRIX(matrix));
|
|
2483
|
+
}
|
|
2484
|
+
toPixmap(matrix, colorspace, alpha = false) {
|
|
2485
|
+
checkMatrix(matrix);
|
|
2486
|
+
checkType(colorspace, ColorSpace);
|
|
2487
|
+
return new Pixmap(libmupdf._wasm_pdf_new_pixmap_from_annot(this.pointer, MATRIX(matrix), colorspace.pointer, alpha));
|
|
2488
|
+
}
|
|
2489
|
+
toDisplayList() {
|
|
2490
|
+
return new DisplayList(libmupdf._wasm_pdf_new_display_list_from_annot(this.pointer));
|
|
2491
|
+
}
|
|
2492
|
+
update() {
|
|
2493
|
+
return !!libmupdf._wasm_pdf_update_annot(this.pointer);
|
|
2494
|
+
}
|
|
2495
|
+
getType() {
|
|
2496
|
+
let type = libmupdf._wasm_pdf_annot_type(this.pointer);
|
|
2497
|
+
return PDFAnnotation.ANNOT_TYPES[type] || "Text";
|
|
2498
|
+
}
|
|
2499
|
+
getLanguage() {
|
|
2500
|
+
return fromStringOrNull(libmupdf._wasm_pdf_annot_language(this.pointer));
|
|
2501
|
+
}
|
|
2502
|
+
setLanguage(lang) {
|
|
2503
|
+
libmupdf._wasm_pdf_set_annot_language(this.pointer, STRING(lang));
|
|
2504
|
+
}
|
|
2505
|
+
getFlags() {
|
|
2506
|
+
return libmupdf._wasm_pdf_annot_flags(this.pointer);
|
|
2507
|
+
}
|
|
2508
|
+
setFlags(flags) {
|
|
2509
|
+
return libmupdf._wasm_pdf_set_annot_flags(this.pointer, flags);
|
|
2510
|
+
}
|
|
2511
|
+
getContents() {
|
|
2512
|
+
return fromString(libmupdf._wasm_pdf_annot_contents(this.pointer));
|
|
2513
|
+
}
|
|
2514
|
+
setContents(text) {
|
|
2515
|
+
libmupdf._wasm_pdf_set_annot_contents(this.pointer, STRING(text));
|
|
2516
|
+
}
|
|
2517
|
+
getName() {
|
|
2518
|
+
return fromString(libmupdf._wasm_pdf_annot_name(this.pointer));
|
|
2519
|
+
}
|
|
2520
|
+
setName(text) {
|
|
2521
|
+
libmupdf._wasm_pdf_set_annot_name(this.pointer, STRING(text));
|
|
2522
|
+
}
|
|
2523
|
+
getAuthor() {
|
|
2524
|
+
return fromString(libmupdf._wasm_pdf_annot_author(this.pointer));
|
|
2525
|
+
}
|
|
2526
|
+
setAuthor(text) {
|
|
2527
|
+
libmupdf._wasm_pdf_set_annot_author(this.pointer, STRING(text));
|
|
2528
|
+
}
|
|
2529
|
+
getSubject() {
|
|
2530
|
+
return fromString(libmupdf._wasm_pdf_annot_subject(this.pointer));
|
|
2531
|
+
}
|
|
2532
|
+
setSubject(text) {
|
|
2533
|
+
libmupdf._wasm_pdf_set_annot_subject(this.pointer, STRING(text));
|
|
2534
|
+
}
|
|
2535
|
+
getCreationDate() {
|
|
2536
|
+
return new Date(libmupdf._wasm_pdf_annot_creation_date(this.pointer) * 1000);
|
|
2537
|
+
}
|
|
2538
|
+
setCreationDate(date) {
|
|
2539
|
+
checkType(date, Date);
|
|
2540
|
+
libmupdf._wasm_pdf_set_annot_creation_date(this.pointer, date.getTime() / 1000);
|
|
2541
|
+
}
|
|
2542
|
+
getModificationDate() {
|
|
2543
|
+
return new Date(libmupdf._wasm_pdf_annot_modification_date(this.pointer) * 1000);
|
|
2544
|
+
}
|
|
2545
|
+
setModificationDate(date) {
|
|
2546
|
+
checkType(date, Date);
|
|
2547
|
+
libmupdf._wasm_pdf_set_annot_modification_date(this.pointer, date.getTime() / 1000);
|
|
2548
|
+
}
|
|
2549
|
+
hasRect() {
|
|
2550
|
+
return !!libmupdf._wasm_pdf_annot_has_rect(this.pointer);
|
|
2551
|
+
}
|
|
2552
|
+
hasInkList() {
|
|
2553
|
+
return !!libmupdf._wasm_pdf_annot_has_ink_list(this.pointer);
|
|
2554
|
+
}
|
|
2555
|
+
hasQuadPoints() {
|
|
2556
|
+
return !!libmupdf._wasm_pdf_annot_has_quad_points(this.pointer);
|
|
2557
|
+
}
|
|
2558
|
+
hasVertices() {
|
|
2559
|
+
return !!libmupdf._wasm_pdf_annot_has_vertices(this.pointer);
|
|
2560
|
+
}
|
|
2561
|
+
hasLine() {
|
|
2562
|
+
return !!libmupdf._wasm_pdf_annot_has_line(this.pointer);
|
|
2563
|
+
}
|
|
2564
|
+
hasInteriorColor() {
|
|
2565
|
+
return !!libmupdf._wasm_pdf_annot_has_interior_color(this.pointer);
|
|
2566
|
+
}
|
|
2567
|
+
hasLineEndingStyles() {
|
|
2568
|
+
return !!libmupdf._wasm_pdf_annot_has_line_ending_styles(this.pointer);
|
|
2569
|
+
}
|
|
2570
|
+
hasBorder() {
|
|
2571
|
+
return !!libmupdf._wasm_pdf_annot_has_border(this.pointer);
|
|
2572
|
+
}
|
|
2573
|
+
hasBorderEffect() {
|
|
2574
|
+
return !!libmupdf._wasm_pdf_annot_has_border_effect(this.pointer);
|
|
2575
|
+
}
|
|
2576
|
+
hasIcon() {
|
|
2577
|
+
return !!libmupdf._wasm_pdf_annot_has_icon_name(this.pointer);
|
|
2578
|
+
}
|
|
2579
|
+
hasOpen() {
|
|
2580
|
+
return !!libmupdf._wasm_pdf_annot_has_open(this.pointer);
|
|
2581
|
+
}
|
|
2582
|
+
hasAuthor() {
|
|
2583
|
+
return !!libmupdf._wasm_pdf_annot_has_author(this.pointer);
|
|
2584
|
+
}
|
|
2585
|
+
hasSubject() {
|
|
2586
|
+
return !!libmupdf._wasm_pdf_annot_has_subject(this.pointer);
|
|
2587
|
+
}
|
|
2588
|
+
hasFilespec() {
|
|
2589
|
+
return !!libmupdf._wasm_pdf_annot_has_filespec(this.pointer);
|
|
2590
|
+
}
|
|
2591
|
+
hasCallout() {
|
|
2592
|
+
return !!libmupdf._wasm_pdf_annot_has_callout(this.pointer);
|
|
2593
|
+
}
|
|
2594
|
+
hasRichContents() {
|
|
2595
|
+
return !!libmupdf._wasm_pdf_annot_has_rich_contents(this.pointer);
|
|
2596
|
+
}
|
|
2597
|
+
getRect() {
|
|
2598
|
+
return fromRect(libmupdf._wasm_pdf_annot_rect(this.pointer));
|
|
2599
|
+
}
|
|
2600
|
+
setRect(rect) {
|
|
2601
|
+
checkRect(rect);
|
|
2602
|
+
libmupdf._wasm_pdf_set_annot_rect(this.pointer, RECT(rect));
|
|
2603
|
+
}
|
|
2604
|
+
getPopup() {
|
|
2605
|
+
return fromRect(libmupdf._wasm_pdf_annot_popup(this.pointer));
|
|
2606
|
+
}
|
|
2607
|
+
setPopup(rect) {
|
|
2608
|
+
checkRect(rect);
|
|
2609
|
+
libmupdf._wasm_pdf_set_annot_popup(this.pointer, RECT(rect));
|
|
2610
|
+
}
|
|
2611
|
+
getIsOpen() {
|
|
2612
|
+
return !!libmupdf._wasm_pdf_annot_is_open(this.pointer);
|
|
2613
|
+
}
|
|
2614
|
+
setIsOpen(isOpen) {
|
|
2615
|
+
checkType(isOpen, "boolean");
|
|
2616
|
+
libmupdf._wasm_pdf_set_annot_is_open(this.pointer, isOpen);
|
|
2617
|
+
}
|
|
2618
|
+
getHiddenForEditing() {
|
|
2619
|
+
return !!libmupdf._wasm_pdf_annot_hidden_for_editing(this.pointer);
|
|
2620
|
+
}
|
|
2621
|
+
setHiddenForEditing(isHidden) {
|
|
2622
|
+
checkType(isHidden, "boolean");
|
|
2623
|
+
libmupdf._wasm_pdf_set_annot_hidden_for_editing(this.pointer, isHidden);
|
|
2624
|
+
}
|
|
2625
|
+
getIcon() {
|
|
2626
|
+
return fromString(libmupdf._wasm_pdf_annot_icon_name(this.pointer));
|
|
2627
|
+
}
|
|
2628
|
+
setIcon(text) {
|
|
2629
|
+
checkType(text, "string");
|
|
2630
|
+
libmupdf._wasm_pdf_set_annot_icon_name(this.pointer, STRING(text));
|
|
2631
|
+
}
|
|
2632
|
+
getOpacity() {
|
|
2633
|
+
return libmupdf._wasm_pdf_annot_opacity(this.pointer);
|
|
2634
|
+
}
|
|
2635
|
+
setOpacity(opacity) {
|
|
2636
|
+
checkType(opacity, "number");
|
|
2637
|
+
libmupdf._wasm_pdf_set_annot_opacity(this.pointer, opacity);
|
|
2638
|
+
}
|
|
2639
|
+
getQuadding() {
|
|
2640
|
+
return libmupdf._wasm_pdf_annot_quadding(this.pointer);
|
|
2641
|
+
}
|
|
2642
|
+
setQuadding(quadding) {
|
|
2643
|
+
checkType(quadding, "number");
|
|
2644
|
+
libmupdf._wasm_pdf_set_annot_quadding(this.pointer, quadding);
|
|
2645
|
+
}
|
|
2646
|
+
getLine() {
|
|
2647
|
+
let a = fromPoint(libmupdf._wasm_pdf_annot_line_1(this.pointer));
|
|
2648
|
+
let b = fromPoint(libmupdf._wasm_pdf_annot_line_2(this.pointer));
|
|
2649
|
+
return [a, b];
|
|
2650
|
+
}
|
|
2651
|
+
setLine(a, b) {
|
|
2652
|
+
checkPoint(a);
|
|
2653
|
+
checkPoint(b);
|
|
2654
|
+
libmupdf._wasm_pdf_set_annot_line(this.pointer, POINT(a), POINT2(b));
|
|
2655
|
+
}
|
|
2656
|
+
getLineEndingStyles() {
|
|
2657
|
+
let a = libmupdf._wasm_pdf_annot_line_ending_styles_start(this.pointer);
|
|
2658
|
+
let b = libmupdf._wasm_pdf_annot_line_ending_styles_end(this.pointer);
|
|
2659
|
+
return {
|
|
2660
|
+
start: PDFAnnotation.LINE_ENDING[a] || "None",
|
|
2661
|
+
end: PDFAnnotation.LINE_ENDING[b] || "None",
|
|
2662
|
+
};
|
|
2663
|
+
}
|
|
2664
|
+
setLineEndingStyles(start, end) {
|
|
2665
|
+
let start_ix = ENUM(start, PDFAnnotation.LINE_ENDING);
|
|
2666
|
+
let end_ix = ENUM(end, PDFAnnotation.LINE_ENDING);
|
|
2667
|
+
libmupdf._wasm_pdf_set_annot_line_ending_styles(this.pointer, start_ix, end_ix);
|
|
2668
|
+
}
|
|
2669
|
+
getLineCaption() {
|
|
2670
|
+
return libmupdf._wasm_pdf_annot_line_caption(this.pointer);
|
|
2671
|
+
}
|
|
2672
|
+
setLineCaption(on) {
|
|
2673
|
+
return libmupdf._wasm_pdf_set_annot_line_caption(this.pointer, on);
|
|
2674
|
+
}
|
|
2675
|
+
getLineCaptionOffset() {
|
|
2676
|
+
return fromPoint(libmupdf._wasm_pdf_annot_line_caption_offset(this.pointer));
|
|
2677
|
+
}
|
|
2678
|
+
setLineCaptionOffset(p) {
|
|
2679
|
+
return libmupdf._wasm_pdf_set_annot_line_caption_offset(this.pointer, POINT(p));
|
|
2680
|
+
}
|
|
2681
|
+
getLineLeader() {
|
|
2682
|
+
return libmupdf._wasm_pdf_annot_line_leader(this.pointer);
|
|
2683
|
+
}
|
|
2684
|
+
getLineLeaderExtension() {
|
|
2685
|
+
return libmupdf._wasm_pdf_annot_line_leader_extension(this.pointer);
|
|
2686
|
+
}
|
|
2687
|
+
getLineLeaderOffset() {
|
|
2688
|
+
return libmupdf._wasm_pdf_annot_line_leader_offset(this.pointer);
|
|
2689
|
+
}
|
|
2690
|
+
setLineLeader(v) {
|
|
2691
|
+
return libmupdf._wasm_pdf_set_annot_line_leader(this.pointer, v);
|
|
2692
|
+
}
|
|
2693
|
+
setLineLeaderExtension(v) {
|
|
2694
|
+
return libmupdf._wasm_pdf_set_annot_line_leader_extension(this.pointer, v);
|
|
2695
|
+
}
|
|
2696
|
+
setLineLeaderOffset(v) {
|
|
2697
|
+
return libmupdf._wasm_pdf_set_annot_line_leader_offset(this.pointer, v);
|
|
2698
|
+
}
|
|
2699
|
+
getCalloutStyle() {
|
|
2700
|
+
let style = libmupdf._wasm_pdf_annot_callout_style(this.pointer);
|
|
2701
|
+
return PDFAnnotation.LINE_ENDING[style] || "None";
|
|
2702
|
+
}
|
|
2703
|
+
setCalloutStyle(style) {
|
|
2704
|
+
let style_ix = ENUM(style, PDFAnnotation.LINE_ENDING);
|
|
2705
|
+
libmupdf._wasm_pdf_set_annot_callout_style(this.pointer, style_ix);
|
|
2706
|
+
}
|
|
2707
|
+
getCalloutLine() {
|
|
2708
|
+
let n = libmupdf._wasm_pdf_annot_callout_line(this.pointer, (_wasm_point << 2));
|
|
2709
|
+
if (n == 3)
|
|
2710
|
+
return [
|
|
2711
|
+
fromPoint((_wasm_point + 0) << 2),
|
|
2712
|
+
fromPoint((_wasm_point + 1) << 2),
|
|
2713
|
+
fromPoint((_wasm_point + 2) << 2)
|
|
2714
|
+
];
|
|
2715
|
+
if (n == 2)
|
|
2716
|
+
return [
|
|
2717
|
+
fromPoint((_wasm_point + 0) << 2),
|
|
2718
|
+
fromPoint((_wasm_point + 1) << 2)
|
|
2719
|
+
];
|
|
2720
|
+
return null;
|
|
2721
|
+
}
|
|
2722
|
+
setCalloutLine(line) {
|
|
2723
|
+
let a = line[0] || [0, 0];
|
|
2724
|
+
let b = line[1] || [0, 0];
|
|
2725
|
+
let c = line[2] || [0, 0];
|
|
2726
|
+
libmupdf._wasm_pdf_set_annot_callout_line(this.pointer, line.length, POINT(a), POINT2(b), POINT3(c));
|
|
2727
|
+
}
|
|
2728
|
+
getCalloutPoint() {
|
|
2729
|
+
let line = this.getCalloutLine();
|
|
2730
|
+
if (line)
|
|
2731
|
+
return line[0];
|
|
2732
|
+
return undefined;
|
|
2733
|
+
}
|
|
2734
|
+
setCalloutPoint(p) {
|
|
2735
|
+
libmupdf._wasm_pdf_set_annot_callout_point(this.pointer, POINT(p));
|
|
2736
|
+
}
|
|
2737
|
+
getColor() {
|
|
2738
|
+
return fromAnnotColor(libmupdf._wasm_pdf_annot_color(this.pointer, COLOR()));
|
|
2739
|
+
}
|
|
2740
|
+
getInteriorColor() {
|
|
2741
|
+
return fromAnnotColor(libmupdf._wasm_pdf_annot_interior_color(this.pointer, COLOR()));
|
|
2742
|
+
}
|
|
2743
|
+
setColor(color) {
|
|
2744
|
+
checkAnnotColor(color);
|
|
2745
|
+
libmupdf._wasm_pdf_set_annot_color(this.pointer, color.length, COLOR(color));
|
|
2746
|
+
}
|
|
2747
|
+
setInteriorColor(color) {
|
|
2748
|
+
checkAnnotColor(color);
|
|
2749
|
+
libmupdf._wasm_pdf_set_annot_interior_color(this.pointer, color.length, COLOR(color));
|
|
2750
|
+
}
|
|
2751
|
+
getBorderWidth() {
|
|
2752
|
+
return libmupdf._wasm_pdf_annot_border_width(this.pointer);
|
|
2753
|
+
}
|
|
2754
|
+
setBorderWidth(value) {
|
|
2755
|
+
checkType(value, "number");
|
|
2756
|
+
return libmupdf._wasm_pdf_set_annot_border_width(this.pointer, value);
|
|
2757
|
+
}
|
|
2758
|
+
getBorderStyle() {
|
|
2759
|
+
return PDFAnnotation.BORDER_STYLE[libmupdf._wasm_pdf_annot_border_style(this.pointer)] || "Solid";
|
|
2760
|
+
}
|
|
2761
|
+
setBorderStyle(value) {
|
|
2762
|
+
let value_ix = ENUM(value, PDFAnnotation.BORDER_STYLE);
|
|
2763
|
+
return libmupdf._wasm_pdf_set_annot_border_style(this.pointer, value_ix);
|
|
2764
|
+
}
|
|
2765
|
+
getBorderEffect() {
|
|
2766
|
+
return PDFAnnotation.BORDER_EFFECT[libmupdf._wasm_pdf_annot_border_effect(this.pointer)] || "None";
|
|
2767
|
+
}
|
|
2768
|
+
setBorderEffect(value) {
|
|
2769
|
+
let value_ix = ENUM(value, PDFAnnotation.BORDER_EFFECT);
|
|
2770
|
+
return libmupdf._wasm_pdf_set_annot_border_effect(this.pointer, value_ix);
|
|
2771
|
+
}
|
|
2772
|
+
getBorderEffectIntensity() {
|
|
2773
|
+
return libmupdf._wasm_pdf_annot_border_effect_intensity(this.pointer);
|
|
2774
|
+
}
|
|
2775
|
+
setBorderEffectIntensity(value) {
|
|
2776
|
+
checkType(value, "number");
|
|
2777
|
+
return libmupdf._wasm_pdf_set_annot_border_effect_intensity(this.pointer, value);
|
|
2778
|
+
}
|
|
2779
|
+
getBorderDashCount() {
|
|
2780
|
+
return libmupdf._wasm_pdf_annot_border_dash_count(this.pointer);
|
|
2781
|
+
}
|
|
2782
|
+
getBorderDashItem(idx) {
|
|
2783
|
+
return libmupdf._wasm_pdf_annot_border_dash_item(this.pointer, idx);
|
|
2784
|
+
}
|
|
2785
|
+
clearBorderDash() {
|
|
2786
|
+
libmupdf._wasm_pdf_clear_annot_border_dash(this.pointer);
|
|
2787
|
+
}
|
|
2788
|
+
addBorderDashItem(v) {
|
|
2789
|
+
checkType(v, "number");
|
|
2790
|
+
return libmupdf._wasm_pdf_add_annot_border_dash_item(this.pointer, v);
|
|
2791
|
+
}
|
|
2792
|
+
getBorderDashPattern() {
|
|
2793
|
+
let n = this.getBorderDashCount();
|
|
2794
|
+
let result = new Array(n);
|
|
2795
|
+
for (let i = 0; i < n; ++i)
|
|
2796
|
+
result[i] = this.getBorderDashItem(i);
|
|
2797
|
+
return result;
|
|
2798
|
+
}
|
|
2799
|
+
setBorderDashPattern(list) {
|
|
2800
|
+
this.clearBorderDash();
|
|
2801
|
+
for (let v of list)
|
|
2802
|
+
this.addBorderDashItem(v);
|
|
2803
|
+
}
|
|
2804
|
+
getIntent() {
|
|
2805
|
+
return PDFAnnotation.INTENT[libmupdf._wasm_pdf_annot_intent(this.pointer)] || null;
|
|
2806
|
+
}
|
|
2807
|
+
setIntent(value) {
|
|
2808
|
+
let value_ix = ENUM(value, PDFAnnotation.INTENT);
|
|
2809
|
+
return libmupdf._wasm_pdf_set_annot_intent(this.pointer, value_ix);
|
|
2810
|
+
}
|
|
2811
|
+
setDefaultAppearance(fontName, size, color) {
|
|
2812
|
+
checkType(fontName, "string");
|
|
2813
|
+
checkType(size, "number");
|
|
2814
|
+
checkAnnotColor(color);
|
|
2815
|
+
libmupdf._wasm_pdf_set_annot_default_appearance(this.pointer, STRING(fontName), size, color.length, COLOR(color));
|
|
2816
|
+
}
|
|
2817
|
+
getDefaultAppearance() {
|
|
2818
|
+
let font = fromString(libmupdf._wasm_pdf_annot_default_appearance_font(this.pointer));
|
|
2819
|
+
let size = libmupdf._wasm_pdf_annot_default_appearance_size(this.pointer);
|
|
2820
|
+
let color = fromAnnotColor(libmupdf._wasm_pdf_annot_default_appearance_color(this.pointer, COLOR()));
|
|
2821
|
+
return { font, size, color };
|
|
2822
|
+
}
|
|
2823
|
+
getFileSpec() {
|
|
2824
|
+
return this._doc._fromPDFObjectKeep(libmupdf._wasm_pdf_annot_filespec(this.pointer));
|
|
2825
|
+
}
|
|
2826
|
+
setFileSpec(fs) {
|
|
2827
|
+
return libmupdf._wasm_pdf_set_annot_filespec(this.pointer, this._doc._PDFOBJ(fs));
|
|
2828
|
+
}
|
|
2829
|
+
getQuadPoints() {
|
|
2830
|
+
let n = libmupdf._wasm_pdf_annot_quad_point_count(this.pointer);
|
|
2831
|
+
let result = [];
|
|
2832
|
+
for (let i = 0; i < n; ++i)
|
|
2833
|
+
result.push(fromQuad(libmupdf._wasm_pdf_annot_quad_point(this.pointer, i)));
|
|
2834
|
+
return result;
|
|
2835
|
+
}
|
|
2836
|
+
clearQuadPoints() {
|
|
2837
|
+
libmupdf._wasm_pdf_clear_annot_quad_points(this.pointer);
|
|
2838
|
+
}
|
|
2839
|
+
addQuadPoint(quad) {
|
|
2840
|
+
checkQuad(quad);
|
|
2841
|
+
libmupdf._wasm_pdf_add_annot_quad_point(this.pointer, QUAD(quad));
|
|
2842
|
+
}
|
|
2843
|
+
setQuadPoints(quadlist) {
|
|
2844
|
+
this.clearQuadPoints();
|
|
2845
|
+
for (let quad of quadlist)
|
|
2846
|
+
this.addQuadPoint(quad);
|
|
2847
|
+
}
|
|
2848
|
+
getVertices() {
|
|
2849
|
+
let n = libmupdf._wasm_pdf_annot_vertex_count(this.pointer);
|
|
2850
|
+
let result = new Array(n);
|
|
2851
|
+
for (let i = 0; i < n; ++i)
|
|
2852
|
+
result[i] = fromPoint(libmupdf._wasm_pdf_annot_vertex(this.pointer, i));
|
|
2853
|
+
return result;
|
|
2854
|
+
}
|
|
2855
|
+
clearVertices() {
|
|
2856
|
+
libmupdf._wasm_pdf_clear_annot_vertices(this.pointer);
|
|
2857
|
+
}
|
|
2858
|
+
addVertex(vertex) {
|
|
2859
|
+
checkPoint(vertex);
|
|
2860
|
+
libmupdf._wasm_pdf_add_annot_vertex(this.pointer, POINT(vertex));
|
|
2861
|
+
}
|
|
2862
|
+
setVertices(vertexlist) {
|
|
2863
|
+
this.clearVertices();
|
|
2864
|
+
for (let vertex of vertexlist)
|
|
2865
|
+
this.addVertex(vertex);
|
|
2866
|
+
}
|
|
2867
|
+
getInkList() {
|
|
2868
|
+
let n = libmupdf._wasm_pdf_annot_ink_list_count(this.pointer);
|
|
2869
|
+
let outer = [];
|
|
2870
|
+
for (let i = 0; i < n; ++i) {
|
|
2871
|
+
let m = libmupdf._wasm_pdf_annot_ink_list_stroke_count(this.pointer, i);
|
|
2872
|
+
let inner = new Array(m);
|
|
2873
|
+
for (let k = 0; k < m; ++k)
|
|
2874
|
+
inner[k] = fromPoint(libmupdf._wasm_pdf_annot_ink_list_stroke_vertex(this.pointer, i, k));
|
|
2875
|
+
outer.push(inner);
|
|
2876
|
+
}
|
|
2877
|
+
return outer;
|
|
2878
|
+
}
|
|
2879
|
+
clearInkList() {
|
|
2880
|
+
libmupdf._wasm_pdf_clear_annot_ink_list(this.pointer);
|
|
2881
|
+
}
|
|
2882
|
+
addInkListStroke() {
|
|
2883
|
+
libmupdf._wasm_pdf_add_annot_ink_list_stroke(this.pointer);
|
|
2884
|
+
}
|
|
2885
|
+
addInkListStrokeVertex(v) {
|
|
2886
|
+
checkPoint(v);
|
|
2887
|
+
libmupdf._wasm_pdf_add_annot_ink_list_stroke_vertex(this.pointer, POINT(v));
|
|
2888
|
+
}
|
|
2889
|
+
setInkList(inklist) {
|
|
2890
|
+
this.clearInkList();
|
|
2891
|
+
for (let stroke of inklist) {
|
|
2892
|
+
this.addInkListStroke();
|
|
2893
|
+
for (let vertex of stroke)
|
|
2894
|
+
this.addInkListStrokeVertex(vertex);
|
|
2895
|
+
}
|
|
2896
|
+
}
|
|
2897
|
+
getRichContents() {
|
|
2898
|
+
return fromString(libmupdf._wasm_pdf_annot_rich_contents(this.pointer));
|
|
2899
|
+
}
|
|
2900
|
+
setRichContents(plain, html) {
|
|
2901
|
+
checkType(plain, "string");
|
|
2902
|
+
checkType(html, "string");
|
|
2903
|
+
libmupdf._wasm_pdf_set_annot_rich_contents(this.pointer, STRING(plain), STRING2(html));
|
|
2904
|
+
}
|
|
2905
|
+
getRichDefaults() {
|
|
2906
|
+
return fromString(libmupdf._wasm_pdf_annot_rich_defaults(this.pointer));
|
|
2907
|
+
}
|
|
2908
|
+
setRichDefaults(style) {
|
|
2909
|
+
checkType(style, "string");
|
|
2910
|
+
libmupdf._wasm_pdf_set_annot_rich_defaults(this.pointer, STRING(style));
|
|
2911
|
+
}
|
|
2912
|
+
setStampImage(image) {
|
|
2913
|
+
libmupdf._wasm_pdf_set_annot_stamp_image(this.pointer, image.pointer);
|
|
2914
|
+
}
|
|
2915
|
+
setAppearanceFromDisplayList(appearance, state, transform, list) {
|
|
2916
|
+
checkMatrix(transform);
|
|
2917
|
+
checkType(list, DisplayList);
|
|
2918
|
+
libmupdf._wasm_pdf_set_annot_appearance_from_display_list(this.pointer, STRING_OPT(appearance), STRING2_OPT(state), MATRIX(transform), list.pointer);
|
|
2919
|
+
}
|
|
2920
|
+
setAppearance(appearance, state, transform, bbox, resources, contents) {
|
|
2921
|
+
checkMatrix(transform);
|
|
2922
|
+
checkRect(bbox);
|
|
2923
|
+
libmupdf._wasm_pdf_set_annot_appearance(this.pointer, STRING_OPT(appearance), STRING2_OPT(state), MATRIX(transform), RECT(bbox), this._doc._PDFOBJ(resources), BUFFER(contents));
|
|
2924
|
+
}
|
|
2925
|
+
applyRedaction(black_boxes = 1, image_method = 2, line_art_method = 1, text_method = 0) {
|
|
2926
|
+
libmupdf._wasm_pdf_apply_redaction(this.pointer, black_boxes, image_method, line_art_method, text_method);
|
|
2927
|
+
}
|
|
2928
|
+
}
|
|
2929
|
+
PDFAnnotation._drop = libmupdf._wasm_pdf_drop_annot;
|
|
2930
|
+
/* IMPORTANT: Keep in sync with mupdf/pdf/annot.h and PDFAnnotation.java */
|
|
2931
|
+
PDFAnnotation.ANNOT_TYPES = [
|
|
2932
|
+
"Text",
|
|
2933
|
+
"Link",
|
|
2934
|
+
"FreeText",
|
|
2935
|
+
"Line",
|
|
2936
|
+
"Square",
|
|
2937
|
+
"Circle",
|
|
2938
|
+
"Polygon",
|
|
2939
|
+
"PolyLine",
|
|
2940
|
+
"Highlight",
|
|
2941
|
+
"Underline",
|
|
2942
|
+
"Squiggly",
|
|
2943
|
+
"StrikeOut",
|
|
2944
|
+
"Redact",
|
|
2945
|
+
"Stamp",
|
|
2946
|
+
"Caret",
|
|
2947
|
+
"Ink",
|
|
2948
|
+
"Popup",
|
|
2949
|
+
"FileAttachment",
|
|
2950
|
+
"Sound",
|
|
2951
|
+
"Movie",
|
|
2952
|
+
"RichMedia",
|
|
2953
|
+
"Widget",
|
|
2954
|
+
"Screen",
|
|
2955
|
+
"PrinterMark",
|
|
2956
|
+
"TrapNet",
|
|
2957
|
+
"Watermark",
|
|
2958
|
+
"3D",
|
|
2959
|
+
"Projection",
|
|
2960
|
+
];
|
|
2961
|
+
PDFAnnotation.LINE_ENDING = [
|
|
2962
|
+
"None",
|
|
2963
|
+
"Square",
|
|
2964
|
+
"Circle",
|
|
2965
|
+
"Diamond",
|
|
2966
|
+
"OpenArrow",
|
|
2967
|
+
"ClosedArrow",
|
|
2968
|
+
"Butt",
|
|
2969
|
+
"ROpenArrow",
|
|
2970
|
+
"RClosedArrow",
|
|
2971
|
+
"Slash",
|
|
2972
|
+
];
|
|
2973
|
+
PDFAnnotation.BORDER_STYLE = ["Solid", "Dashed", "Beveled", "Inset", "Underline"];
|
|
2974
|
+
PDFAnnotation.BORDER_EFFECT = ["None", "Cloudy"];
|
|
2975
|
+
PDFAnnotation.INTENT = [
|
|
2976
|
+
null,
|
|
2977
|
+
"FreeTextCallout",
|
|
2978
|
+
"FreeTextTypeWriter",
|
|
2979
|
+
"LineArrow",
|
|
2980
|
+
"LineDimension",
|
|
2981
|
+
"PloyLine",
|
|
2982
|
+
"PolygonCloud",
|
|
2983
|
+
"PolygonDimension",
|
|
2984
|
+
"StampImage",
|
|
2985
|
+
"StampSnapshot"
|
|
2986
|
+
];
|
|
2987
|
+
// Bit masks for getFlags and setFlags
|
|
2988
|
+
PDFAnnotation.IS_INVISIBLE = 1 << (1 - 1);
|
|
2989
|
+
PDFAnnotation.IS_HIDDEN = 1 << (2 - 1);
|
|
2990
|
+
PDFAnnotation.IS_PRINT = 1 << (3 - 1);
|
|
2991
|
+
PDFAnnotation.IS_NO_ZOOM = 1 << (4 - 1);
|
|
2992
|
+
PDFAnnotation.IS_NO_ROTATE = 1 << (5 - 1);
|
|
2993
|
+
PDFAnnotation.IS_NO_VIEW = 1 << (6 - 1);
|
|
2994
|
+
PDFAnnotation.IS_READ_ONLY = 1 << (7 - 1);
|
|
2995
|
+
PDFAnnotation.IS_LOCKED = 1 << (8 - 1);
|
|
2996
|
+
PDFAnnotation.IS_TOGGLE_NO_VIEW = 1 << (9 - 1);
|
|
2997
|
+
PDFAnnotation.IS_LOCKED_CONTENTS = 1 << (10 - 1);
|
|
2998
|
+
export class PDFWidget extends PDFAnnotation {
|
|
2999
|
+
getFieldType() {
|
|
3000
|
+
return PDFWidget.WIDGET_TYPES[libmupdf._wasm_pdf_annot_field_type(this.pointer)] || "button";
|
|
3001
|
+
}
|
|
3002
|
+
isButton() {
|
|
3003
|
+
let type = this.getFieldType();
|
|
3004
|
+
return type === "button" || type === "checkbox" || type === "radiobutton";
|
|
3005
|
+
}
|
|
3006
|
+
isPushButton() {
|
|
3007
|
+
return this.getFieldType() === "button";
|
|
3008
|
+
}
|
|
3009
|
+
isCheckbox() {
|
|
3010
|
+
return this.getFieldType() === "checkbox";
|
|
3011
|
+
}
|
|
3012
|
+
isRadioButton() {
|
|
3013
|
+
return this.getFieldType() === "radiobutton";
|
|
3014
|
+
}
|
|
3015
|
+
isText() {
|
|
3016
|
+
return this.getFieldType() === "text";
|
|
3017
|
+
}
|
|
3018
|
+
isChoice() {
|
|
3019
|
+
let type = this.getFieldType();
|
|
3020
|
+
return type === "combobox" || type === "listbox";
|
|
3021
|
+
}
|
|
3022
|
+
isListBox() {
|
|
3023
|
+
return this.getFieldType() === "listbox";
|
|
3024
|
+
}
|
|
3025
|
+
isComboBox() {
|
|
3026
|
+
return this.getFieldType() === "combobox";
|
|
3027
|
+
}
|
|
3028
|
+
getFieldFlags() {
|
|
3029
|
+
return libmupdf._wasm_pdf_annot_field_flags(this.pointer);
|
|
3030
|
+
}
|
|
3031
|
+
isMultiline() {
|
|
3032
|
+
return (this.getFieldFlags() & PDFWidget.TX_FIELD_IS_MULTILINE) !== 0;
|
|
3033
|
+
}
|
|
3034
|
+
isPassword() {
|
|
3035
|
+
return (this.getFieldFlags() & PDFWidget.TX_FIELD_IS_PASSWORD) !== 0;
|
|
3036
|
+
}
|
|
3037
|
+
isComb() {
|
|
3038
|
+
return (this.getFieldFlags() & PDFWidget.TX_FIELD_IS_COMB) !== 0;
|
|
3039
|
+
}
|
|
3040
|
+
isReadOnly() {
|
|
3041
|
+
return (this.getFieldFlags() & PDFWidget.FIELD_IS_READ_ONLY) !== 0;
|
|
3042
|
+
}
|
|
3043
|
+
getLabel() {
|
|
3044
|
+
return fromString(libmupdf._wasm_pdf_annot_field_label(this.pointer));
|
|
3045
|
+
}
|
|
3046
|
+
getName() {
|
|
3047
|
+
return fromStringFree(libmupdf._wasm_pdf_load_field_name(this.pointer));
|
|
3048
|
+
}
|
|
3049
|
+
setName() {
|
|
3050
|
+
throw new Error("widget field name is read-only");
|
|
3051
|
+
}
|
|
3052
|
+
getValue() {
|
|
3053
|
+
return fromString(libmupdf._wasm_pdf_annot_field_value(this.pointer));
|
|
3054
|
+
}
|
|
3055
|
+
setTextValue(value) {
|
|
3056
|
+
return libmupdf._wasm_pdf_set_annot_text_field_value(this.pointer, STRING(value));
|
|
3057
|
+
}
|
|
3058
|
+
getMaxLen() {
|
|
3059
|
+
return libmupdf._wasm_pdf_annot_text_widget_max_len(this.pointer);
|
|
3060
|
+
}
|
|
3061
|
+
setChoiceValue(value) {
|
|
3062
|
+
return libmupdf._wasm_pdf_set_annot_choice_field_value(this.pointer, STRING(value));
|
|
3063
|
+
}
|
|
3064
|
+
getOptions(isExport = false) {
|
|
3065
|
+
let result = [];
|
|
3066
|
+
let n = libmupdf._wasm_pdf_annot_choice_field_option_count(this.pointer);
|
|
3067
|
+
for (let i = 0; i < n; ++i) {
|
|
3068
|
+
result.push(fromString(libmupdf._wasm_pdf_annot_choice_field_option(this.pointer, isExport, i)));
|
|
3069
|
+
}
|
|
3070
|
+
return result;
|
|
3071
|
+
}
|
|
3072
|
+
toggle() {
|
|
3073
|
+
return libmupdf._wasm_pdf_toggle_widget(this.pointer);
|
|
3074
|
+
}
|
|
3075
|
+
}
|
|
3076
|
+
/* IMPORTANT: Keep in sync with mupdf/pdf/widget.h and PDFWidget.java */
|
|
3077
|
+
PDFWidget.WIDGET_TYPES = [
|
|
3078
|
+
"widget", // unknown
|
|
3079
|
+
"button",
|
|
3080
|
+
"checkbox",
|
|
3081
|
+
"combobox",
|
|
3082
|
+
"listbox",
|
|
3083
|
+
"radiobutton",
|
|
3084
|
+
"signature",
|
|
3085
|
+
"text",
|
|
3086
|
+
];
|
|
3087
|
+
/* Field flags */
|
|
3088
|
+
PDFWidget.FIELD_IS_READ_ONLY = 1;
|
|
3089
|
+
PDFWidget.FIELD_IS_REQUIRED = 1 << 1;
|
|
3090
|
+
PDFWidget.FIELD_IS_NO_EXPORT = 1 << 2;
|
|
3091
|
+
/* Text fields */
|
|
3092
|
+
PDFWidget.TX_FIELD_IS_MULTILINE = 1 << 12;
|
|
3093
|
+
PDFWidget.TX_FIELD_IS_PASSWORD = 1 << 13;
|
|
3094
|
+
PDFWidget.TX_FIELD_IS_FILE_SELECT = 1 << 20;
|
|
3095
|
+
PDFWidget.TX_FIELD_IS_DO_NOT_SPELL_CHECK = 1 << 22;
|
|
3096
|
+
PDFWidget.TX_FIELD_IS_DO_NOT_SCROLL = 1 << 23;
|
|
3097
|
+
PDFWidget.TX_FIELD_IS_COMB = 1 << 24;
|
|
3098
|
+
PDFWidget.TX_FIELD_IS_RICH_TEXT = 1 << 25;
|
|
3099
|
+
/* Button fields */
|
|
3100
|
+
PDFWidget.BTN_FIELD_IS_NO_TOGGLE_TO_OFF = 1 << 14;
|
|
3101
|
+
PDFWidget.BTN_FIELD_IS_RADIO = 1 << 15;
|
|
3102
|
+
PDFWidget.BTN_FIELD_IS_PUSHBUTTON = 1 << 16;
|
|
3103
|
+
PDFWidget.BTN_FIELD_IS_RADIOS_IN_UNISON = 1 << 25;
|
|
3104
|
+
/* Choice fields */
|
|
3105
|
+
PDFWidget.CH_FIELD_IS_COMBO = 1 << 17;
|
|
3106
|
+
PDFWidget.CH_FIELD_IS_EDIT = 1 << 18;
|
|
3107
|
+
PDFWidget.CH_FIELD_IS_SORT = 1 << 19;
|
|
3108
|
+
PDFWidget.CH_FIELD_IS_MULTI_SELECT = 1 << 21;
|
|
3109
|
+
PDFWidget.CH_FIELD_IS_DO_NOT_SPELL_CHECK = 1 << 22;
|
|
3110
|
+
PDFWidget.CH_FIELD_IS_COMMIT_ON_SEL_CHANGE = 1 << 25;
|
|
3111
|
+
var $libmupdf_stm_id = 0;
|
|
3112
|
+
var $libmupdf_stm_table = new Map();
|
|
3113
|
+
globalThis.$libmupdf_stm_close = function (id) {
|
|
3114
|
+
let handle = $libmupdf_stm_table.get(id);
|
|
3115
|
+
if (handle) {
|
|
3116
|
+
handle.close();
|
|
3117
|
+
$libmupdf_stm_table.delete(id);
|
|
3118
|
+
return;
|
|
3119
|
+
}
|
|
3120
|
+
throw new Error("invalid file handle");
|
|
3121
|
+
};
|
|
3122
|
+
globalThis.$libmupdf_stm_seek = function (id, pos, offset, whence) {
|
|
3123
|
+
let handle = $libmupdf_stm_table.get(id);
|
|
3124
|
+
if (handle) {
|
|
3125
|
+
if (whence === 0)
|
|
3126
|
+
return offset;
|
|
3127
|
+
if (whence === 1)
|
|
3128
|
+
return pos + offset;
|
|
3129
|
+
if (whence === 2) {
|
|
3130
|
+
let size = handle.fileSize();
|
|
3131
|
+
if (size < 0)
|
|
3132
|
+
return -1;
|
|
3133
|
+
return size + offset;
|
|
3134
|
+
}
|
|
3135
|
+
throw new Error("invalid whence argument");
|
|
3136
|
+
}
|
|
3137
|
+
throw new Error("invalid file handle");
|
|
3138
|
+
};
|
|
3139
|
+
globalThis.$libmupdf_stm_read = function (id, pos, addr, size) {
|
|
3140
|
+
let handle = $libmupdf_stm_table.get(id);
|
|
3141
|
+
if (handle) {
|
|
3142
|
+
return handle.read(libmupdf.HEAPU8, addr, size, pos);
|
|
3143
|
+
}
|
|
3144
|
+
throw new Error("invalid file handle");
|
|
3145
|
+
};
|
|
3146
|
+
export class Stream extends Userdata {
|
|
3147
|
+
constructor(handle) {
|
|
3148
|
+
let id = $libmupdf_stm_id++;
|
|
3149
|
+
$libmupdf_stm_table.set(id, handle);
|
|
3150
|
+
super(libmupdf._wasm_new_stream(id));
|
|
3151
|
+
}
|
|
3152
|
+
}
|
|
3153
|
+
Stream._drop = libmupdf._wasm_drop_stream;
|
|
3154
|
+
/* -------------------------------------------------------------------------- */
|
|
3155
|
+
var $libmupdf_load_font_file_js;
|
|
3156
|
+
globalThis.$libmupdf_load_font_file = function (name, script, bold, italic) {
|
|
3157
|
+
if ($libmupdf_load_font_file_js) {
|
|
3158
|
+
var font = $libmupdf_load_font_file_js(fromString(name), fromString(script), bold, italic);
|
|
3159
|
+
if (font) {
|
|
3160
|
+
checkType(font, Font);
|
|
3161
|
+
return font.pointer;
|
|
3162
|
+
}
|
|
3163
|
+
}
|
|
3164
|
+
return 0;
|
|
3165
|
+
};
|
|
3166
|
+
var $libmupdf_device_id = 0;
|
|
3167
|
+
var $libmupdf_device_table = new Map();
|
|
3168
|
+
var $libmupdf_path_id = 0;
|
|
3169
|
+
var $libmupdf_path_table = new Map();
|
|
3170
|
+
var $libmupdf_text_id = 0;
|
|
3171
|
+
var $libmupdf_text_table = new Map();
|
|
3172
|
+
globalThis.$libmupdf_path_walk = {
|
|
3173
|
+
moveto(id, x, y) {
|
|
3174
|
+
$libmupdf_path_table.get(id)?.moveTo?.(x, y);
|
|
3175
|
+
},
|
|
3176
|
+
lineto(id, x, y) {
|
|
3177
|
+
$libmupdf_path_table.get(id)?.lineTo?.(x, y);
|
|
3178
|
+
},
|
|
3179
|
+
curveto(id, x1, y1, x2, y2, x3, y3) {
|
|
3180
|
+
$libmupdf_path_table.get(id)?.curveTo?.(x1, y1, x2, y2, x3, y3);
|
|
3181
|
+
},
|
|
3182
|
+
closepath(id) {
|
|
3183
|
+
$libmupdf_path_table.get(id)?.closePath?.();
|
|
3184
|
+
},
|
|
3185
|
+
};
|
|
3186
|
+
var $libmupdf_text_font = null;
|
|
3187
|
+
globalThis.$libmupdf_text_walk = {
|
|
3188
|
+
begin_span(id, font, trm, wmode, bidi, dir, lang) {
|
|
3189
|
+
if (font !== $libmupdf_text_font?.pointer)
|
|
3190
|
+
$libmupdf_text_font = new Font(font);
|
|
3191
|
+
$libmupdf_text_table.get(id)?.beginSpan?.($libmupdf_text_font, fromMatrix(trm), wmode, bidi, dir, fromString(lang));
|
|
3192
|
+
},
|
|
3193
|
+
end_span(id) {
|
|
3194
|
+
$libmupdf_text_table.get(id)?.endSpan?.();
|
|
3195
|
+
},
|
|
3196
|
+
show_glyph(id, font, trm, glyph, unicode, wmode, bidi) {
|
|
3197
|
+
if (font !== $libmupdf_text_font?.pointer)
|
|
3198
|
+
$libmupdf_text_font = new Font(font);
|
|
3199
|
+
$libmupdf_text_table.get(id)?.showGlyph?.($libmupdf_text_font, fromMatrix(trm), glyph, unicode, wmode, bidi);
|
|
3200
|
+
},
|
|
3201
|
+
};
|
|
3202
|
+
globalThis.$libmupdf_device = {
|
|
3203
|
+
drop_device(id) {
|
|
3204
|
+
$libmupdf_device_table.get(id)?.drop?.();
|
|
3205
|
+
$libmupdf_device_table.delete(id);
|
|
3206
|
+
},
|
|
3207
|
+
close_device(id) {
|
|
3208
|
+
$libmupdf_device_table.get(id)?.close?.();
|
|
3209
|
+
},
|
|
3210
|
+
fill_path(id, path, even_odd, ctm, colorspace, color_n, color_arr, alpha) {
|
|
3211
|
+
$libmupdf_device_table.get(id)?.fillPath?.(new Path(libmupdf._wasm_keep_path(path)), !!even_odd, fromMatrix(ctm), new ColorSpace(libmupdf._wasm_keep_colorspace(colorspace)), fromColorArray(color_n, color_arr), alpha);
|
|
3212
|
+
},
|
|
3213
|
+
clip_path(id, path, even_odd, ctm) {
|
|
3214
|
+
$libmupdf_device_table.get(id)?.clipPath?.(new Path(libmupdf._wasm_keep_path(path)), !!even_odd, fromMatrix(ctm));
|
|
3215
|
+
},
|
|
3216
|
+
stroke_path(id, path, stroke, ctm, colorspace, color_n, color_arr, alpha) {
|
|
3217
|
+
$libmupdf_device_table.get(id)?.strokePath?.(new Path(libmupdf._wasm_keep_path(path)), new StrokeState(libmupdf._wasm_keep_stroke_state(stroke)), fromMatrix(ctm), new ColorSpace(libmupdf._wasm_keep_colorspace(colorspace)), fromColorArray(color_n, color_arr), alpha);
|
|
3218
|
+
},
|
|
3219
|
+
clip_stroke_path(id, path, stroke, ctm) {
|
|
3220
|
+
$libmupdf_device_table.get(id)?.clipStrokePath?.(new Path(libmupdf._wasm_keep_path(path)), new StrokeState(libmupdf._wasm_keep_stroke_state(stroke)), fromMatrix(ctm));
|
|
3221
|
+
},
|
|
3222
|
+
fill_text(id, text, ctm, colorspace, color_n, color_arr, alpha) {
|
|
3223
|
+
$libmupdf_device_table.get(id)?.fillText?.(new Text(libmupdf._wasm_keep_text(text)), fromMatrix(ctm), new ColorSpace(libmupdf._wasm_keep_colorspace(colorspace)), fromColorArray(color_n, color_arr), alpha);
|
|
3224
|
+
},
|
|
3225
|
+
stroke_text(id, text, stroke, ctm, colorspace, color_n, color_arr, alpha) {
|
|
3226
|
+
$libmupdf_device_table.get(id)?.strokeText?.(new Text(libmupdf._wasm_keep_text(text)), new StrokeState(libmupdf._wasm_keep_stroke_state(stroke)), fromMatrix(ctm), new ColorSpace(libmupdf._wasm_keep_colorspace(colorspace)), fromColorArray(color_n, color_arr), alpha);
|
|
3227
|
+
},
|
|
3228
|
+
clip_text(id, text, ctm) {
|
|
3229
|
+
$libmupdf_device_table.get(id)?.clipText?.(new Text(libmupdf._wasm_keep_text(text)), fromMatrix(ctm));
|
|
3230
|
+
},
|
|
3231
|
+
clip_stroke_text(id, text, stroke, ctm) {
|
|
3232
|
+
$libmupdf_device_table.get(id)?.clipStrokeText?.(new Text(libmupdf._wasm_keep_text(text)), new StrokeState(libmupdf._wasm_keep_stroke_state(stroke)), fromMatrix(ctm));
|
|
3233
|
+
},
|
|
3234
|
+
ignore_text(id, text, ctm) {
|
|
3235
|
+
$libmupdf_device_table.get(id)?.ignoreText?.(new Text(libmupdf._wasm_keep_text(text)), fromMatrix(ctm));
|
|
3236
|
+
},
|
|
3237
|
+
fill_shade(id, shade, ctm, alpha) {
|
|
3238
|
+
$libmupdf_device_table.get(id)?.fillShade?.(new Shade(shade), fromMatrix(ctm), alpha);
|
|
3239
|
+
},
|
|
3240
|
+
fill_image(id, image, ctm, alpha) {
|
|
3241
|
+
$libmupdf_device_table.get(id)?.fillImage?.(new Image(image), fromMatrix(ctm), alpha);
|
|
3242
|
+
},
|
|
3243
|
+
fill_image_mask(id, image, ctm, colorspace, color_n, color_arr, alpha) {
|
|
3244
|
+
$libmupdf_device_table.get(id)?.fillImageMask?.(new Image(image), fromMatrix(ctm), new ColorSpace(libmupdf._wasm_keep_colorspace(colorspace)), fromColorArray(color_n, color_arr), alpha);
|
|
3245
|
+
},
|
|
3246
|
+
clip_image_mask(id, image, ctm) {
|
|
3247
|
+
$libmupdf_device_table.get(id)?.clipImageMask?.(new Image(image), fromMatrix(ctm));
|
|
3248
|
+
},
|
|
3249
|
+
pop_clip(id) {
|
|
3250
|
+
$libmupdf_device_table.get(id)?.popClip?.();
|
|
3251
|
+
},
|
|
3252
|
+
begin_mask(id, bbox, luminosity, colorspace, color_n, color_arr) {
|
|
3253
|
+
$libmupdf_device_table.get(id)?.beginMask?.(fromRect(bbox), !!luminosity, new ColorSpace(libmupdf._wasm_keep_colorspace(colorspace)), fromColorArray(color_n, color_arr));
|
|
3254
|
+
},
|
|
3255
|
+
begin_group(id, bbox, colorspace, isolated, knockout, blendmode, alpha) {
|
|
3256
|
+
$libmupdf_device_table.get(id)?.beginGroup?.(fromRect(bbox), new ColorSpace(libmupdf._wasm_keep_colorspace(colorspace)), !!isolated, !!knockout, Device.BLEND_MODES[blendmode], alpha);
|
|
3257
|
+
},
|
|
3258
|
+
begin_tile(id, area, view, xstep, ystep, ctm, tile_id, doc_id) {
|
|
3259
|
+
return $libmupdf_device_table.get(id)?.beginTile?.(fromRect(area), fromRect(view), xstep, ystep, fromMatrix(ctm), tile_id, doc_id) || 0;
|
|
3260
|
+
},
|
|
3261
|
+
begin_layer(id, name) {
|
|
3262
|
+
$libmupdf_device_table.get(id)?.beginLayer?.(fromString(name));
|
|
3263
|
+
},
|
|
3264
|
+
end_mask(id) {
|
|
3265
|
+
$libmupdf_device_table.get(id)?.endMask?.();
|
|
3266
|
+
},
|
|
3267
|
+
end_group(id) {
|
|
3268
|
+
$libmupdf_device_table.get(id)?.endGroup?.();
|
|
3269
|
+
},
|
|
3270
|
+
end_tile(id) {
|
|
3271
|
+
$libmupdf_device_table.get(id)?.endTile?.();
|
|
3272
|
+
},
|
|
3273
|
+
end_layer(id) {
|
|
3274
|
+
$libmupdf_device_table.get(id)?.endLayer?.();
|
|
3275
|
+
},
|
|
3276
|
+
};
|
|
3277
|
+
/* default exports */
|
|
3278
|
+
export default {
|
|
3279
|
+
// const
|
|
3280
|
+
Matrix,
|
|
3281
|
+
Rect,
|
|
3282
|
+
// function
|
|
3283
|
+
enableICC,
|
|
3284
|
+
disableICC,
|
|
3285
|
+
setUserCSS,
|
|
3286
|
+
installLoadFontFunction,
|
|
3287
|
+
setLog,
|
|
3288
|
+
// class
|
|
3289
|
+
Buffer,
|
|
3290
|
+
ColorSpace,
|
|
3291
|
+
Font,
|
|
3292
|
+
Image,
|
|
3293
|
+
StrokeState,
|
|
3294
|
+
Path,
|
|
3295
|
+
Text,
|
|
3296
|
+
DisplayList,
|
|
3297
|
+
Pixmap,
|
|
3298
|
+
Shade,
|
|
3299
|
+
StructuredText,
|
|
3300
|
+
Device,
|
|
3301
|
+
DrawDevice,
|
|
3302
|
+
DisplayListDevice,
|
|
3303
|
+
DocumentWriter,
|
|
3304
|
+
Document,
|
|
3305
|
+
OutlineIterator,
|
|
3306
|
+
Link,
|
|
3307
|
+
Page,
|
|
3308
|
+
PDFDocument,
|
|
3309
|
+
PDFPage,
|
|
3310
|
+
PDFObject,
|
|
3311
|
+
PDFGraftMap,
|
|
3312
|
+
PDFAnnotation,
|
|
3313
|
+
PDFWidget,
|
|
3314
|
+
Stream,
|
|
3315
|
+
// debugging
|
|
3316
|
+
memento
|
|
3317
|
+
};
|