@vaadin-component-factory/vcf-pdf-viewer 0.9.0 → 1.0.0
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 +1 -1
- package/package.json +42 -26
- package/{src/display → pdfjs/dist}/display_utils.js +344 -139
- package/{src/display → pdfjs/dist}/fetch_stream.js +115 -97
- package/pdfjs/dist/l10n_utils.js +140 -0
- package/{src/shared → pdfjs/dist}/message_handler.js +243 -259
- package/{src/display → pdfjs/dist}/network.js +149 -87
- package/{src/display/content_disposition.js → pdfjs/dist/network_utils.js} +167 -55
- package/{src/display → pdfjs/dist}/node_stream.js +133 -98
- package/pdfjs/dist/pdf.js +12778 -0
- package/pdfjs/dist/pdf_link_service.js +638 -0
- package/pdfjs/dist/pdf_rendering_queue.js +199 -0
- package/pdfjs/dist/pdf_thumbnail_viewer.js +819 -0
- package/pdfjs/dist/pdf_viewer.js +3598 -0
- package/pdfjs/dist/ui_utils.js +1033 -0
- package/{src/shared → pdfjs/dist}/util.js +301 -287
- package/pdfjs/dist/worker.js +62813 -0
- package/src/vcf-pdf-viewer.js +98 -46
- package/theme/lumo/vcf-pdf-viewer-styles.js +4 -4
- package/theme/material/vcf-pdf-viewer-styles.js +4 -4
- package/theme/material/vcf-pdf-viewer.js +2 -2
- package/src/core/.eslintrc +0 -13
- package/src/core/annotation.js +0 -2948
- package/src/core/arithmetic_decoder.js +0 -182
- package/src/core/ascii_85_stream.js +0 -98
- package/src/core/ascii_hex_stream.js +0 -79
- package/src/core/base_stream.js +0 -110
- package/src/core/bidi.js +0 -438
- package/src/core/calibri_factors.js +0 -308
- package/src/core/catalog.js +0 -1459
- package/src/core/ccitt.js +0 -1062
- package/src/core/ccitt_stream.js +0 -60
- package/src/core/cff_font.js +0 -116
- package/src/core/cff_parser.js +0 -1949
- package/src/core/charsets.js +0 -119
- package/src/core/chunked_stream.js +0 -557
- package/src/core/cmap.js +0 -1039
- package/src/core/colorspace.js +0 -1533
- package/src/core/core_utils.js +0 -464
- package/src/core/crypto.js +0 -1900
- package/src/core/decode_stream.js +0 -170
- package/src/core/decrypt_stream.js +0 -59
- package/src/core/default_appearance.js +0 -99
- package/src/core/document.js +0 -1456
- package/src/core/encodings.js +0 -301
- package/src/core/evaluator.js +0 -4601
- package/src/core/file_spec.js +0 -108
- package/src/core/flate_stream.js +0 -402
- package/src/core/font_renderer.js +0 -882
- package/src/core/fonts.js +0 -3260
- package/src/core/fonts_utils.js +0 -221
- package/src/core/function.js +0 -1257
- package/src/core/glyf.js +0 -706
- package/src/core/glyphlist.js +0 -4558
- package/src/core/helvetica_factors.js +0 -353
- package/src/core/image.js +0 -802
- package/src/core/image_utils.js +0 -291
- package/src/core/jbig2.js +0 -2572
- package/src/core/jbig2_stream.js +0 -73
- package/src/core/jpeg_stream.js +0 -105
- package/src/core/jpg.js +0 -1416
- package/src/core/jpx.js +0 -2343
- package/src/core/jpx_stream.js +0 -87
- package/src/core/liberationsans_widths.js +0 -221
- package/src/core/lzw_stream.js +0 -150
- package/src/core/metadata_parser.js +0 -146
- package/src/core/metrics.js +0 -2970
- package/src/core/murmurhash3.js +0 -139
- package/src/core/myriadpro_factors.js +0 -290
- package/src/core/name_number_tree.js +0 -153
- package/src/core/object_loader.js +0 -149
- package/src/core/opentype_file_builder.js +0 -154
- package/src/core/operator_list.js +0 -734
- package/src/core/parser.js +0 -1416
- package/src/core/pattern.js +0 -985
- package/src/core/pdf_manager.js +0 -217
- package/src/core/predictor_stream.js +0 -238
- package/src/core/primitives.js +0 -402
- package/src/core/ps_parser.js +0 -272
- package/src/core/run_length_stream.js +0 -61
- package/src/core/segoeui_factors.js +0 -308
- package/src/core/standard_fonts.js +0 -817
- package/src/core/stream.js +0 -103
- package/src/core/struct_tree.js +0 -335
- package/src/core/to_unicode_map.js +0 -103
- package/src/core/type1_font.js +0 -421
- package/src/core/type1_parser.js +0 -776
- package/src/core/unicode.js +0 -1649
- package/src/core/worker.js +0 -848
- package/src/core/worker_stream.js +0 -135
- package/src/core/writer.js +0 -278
- package/src/core/xfa/bind.js +0 -652
- package/src/core/xfa/builder.js +0 -207
- package/src/core/xfa/config.js +0 -1926
- package/src/core/xfa/connection_set.js +0 -202
- package/src/core/xfa/data.js +0 -82
- package/src/core/xfa/datasets.js +0 -76
- package/src/core/xfa/factory.js +0 -111
- package/src/core/xfa/fonts.js +0 -181
- package/src/core/xfa/formcalc_lexer.js +0 -385
- package/src/core/xfa/formcalc_parser.js +0 -1340
- package/src/core/xfa/html_utils.js +0 -639
- package/src/core/xfa/layout.js +0 -383
- package/src/core/xfa/locale_set.js +0 -345
- package/src/core/xfa/namespaces.js +0 -81
- package/src/core/xfa/parser.js +0 -184
- package/src/core/xfa/setup.js +0 -38
- package/src/core/xfa/signature.js +0 -40
- package/src/core/xfa/som.js +0 -338
- package/src/core/xfa/stylesheet.js +0 -40
- package/src/core/xfa/template.js +0 -6260
- package/src/core/xfa/text.js +0 -290
- package/src/core/xfa/unknown.js +0 -29
- package/src/core/xfa/utils.js +0 -217
- package/src/core/xfa/xdp.js +0 -59
- package/src/core/xfa/xfa_object.js +0 -1130
- package/src/core/xfa/xhtml.js +0 -543
- package/src/core/xfa_fonts.js +0 -208
- package/src/core/xml_parser.js +0 -507
- package/src/core/xref.js +0 -899
- package/src/display/annotation_layer.js +0 -2107
- package/src/display/annotation_storage.js +0 -113
- package/src/display/api.js +0 -3292
- package/src/display/base_factory.js +0 -180
- package/src/display/canvas.js +0 -2828
- package/src/display/font_loader.js +0 -484
- package/src/display/metadata.js +0 -41
- package/src/display/network_utils.js +0 -100
- package/src/display/node_utils.js +0 -83
- package/src/display/optional_content_config.js +0 -189
- package/src/display/pattern_helper.js +0 -659
- package/src/display/svg.js +0 -1709
- package/src/display/text_layer.js +0 -847
- package/src/display/transport_stream.js +0 -303
- package/src/display/worker_options.js +0 -40
- package/src/display/xfa_layer.js +0 -204
- package/src/doc_helper.js +0 -25
- package/src/images/logo.svg +0 -41
- package/src/interfaces.js +0 -169
- package/src/license_header.js +0 -14
- package/src/license_header_libre.js +0 -21
- package/src/pdf.image_decoders.js +0 -46
- package/src/pdf.js +0 -146
- package/src/pdf.sandbox.external.js +0 -181
- package/src/pdf.sandbox.js +0 -151
- package/src/pdf.scripting.js +0 -25
- package/src/pdf.worker.entry.js +0 -19
- package/src/pdf.worker.js +0 -23
- package/src/scripting_api/aform.js +0 -608
- package/src/scripting_api/app.js +0 -621
- package/src/scripting_api/color.js +0 -129
- package/src/scripting_api/common.js +0 -58
- package/src/scripting_api/console.js +0 -38
- package/src/scripting_api/constants.js +0 -208
- package/src/scripting_api/doc.js +0 -1195
- package/src/scripting_api/error.js +0 -23
- package/src/scripting_api/event.js +0 -232
- package/src/scripting_api/field.js +0 -620
- package/src/scripting_api/fullscreen.js +0 -145
- package/src/scripting_api/initialization.js +0 -223
- package/src/scripting_api/pdf_object.js +0 -24
- package/src/scripting_api/print_params.js +0 -146
- package/src/scripting_api/proxy.js +0 -139
- package/src/scripting_api/thermometer.js +0 -69
- package/src/scripting_api/util.js +0 -581
- package/src/shared/.eslintrc +0 -13
- package/src/shared/cffStandardStrings.js +0 -311
- package/src/shared/compatibility.js +0 -114
- package/src/shared/fonts_utils.js +0 -429
- package/src/shared/is_node.js +0 -27
- package/src/shared/scripting_utils.js +0 -85
- package/src/worker_loader.js +0 -32
|
@@ -1,639 +0,0 @@
|
|
|
1
|
-
/* Copyright 2021 Mozilla Foundation
|
|
2
|
-
*
|
|
3
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
-
* you may not use this file except in compliance with the License.
|
|
5
|
-
* You may obtain a copy of the License at
|
|
6
|
-
*
|
|
7
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
-
*
|
|
9
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
10
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
-
* See the License for the specific language governing permissions and
|
|
13
|
-
* limitations under the License.
|
|
14
|
-
*/
|
|
15
|
-
|
|
16
|
-
import {
|
|
17
|
-
$content,
|
|
18
|
-
$extra,
|
|
19
|
-
$getParent,
|
|
20
|
-
$getSubformParent,
|
|
21
|
-
$getTemplateRoot,
|
|
22
|
-
$globalData,
|
|
23
|
-
$nodeName,
|
|
24
|
-
$pushGlyphs,
|
|
25
|
-
$text,
|
|
26
|
-
$toStyle,
|
|
27
|
-
XFAObject,
|
|
28
|
-
} from "./xfa_object.js";
|
|
29
|
-
import { getMeasurement, stripQuotes } from "./utils.js";
|
|
30
|
-
import { selectFont } from "./fonts.js";
|
|
31
|
-
import { TextMeasure } from "./text.js";
|
|
32
|
-
import { warn } from "../../shared/util.js";
|
|
33
|
-
|
|
34
|
-
function measureToString(m) {
|
|
35
|
-
if (typeof m === "string") {
|
|
36
|
-
return "0px";
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
return Number.isInteger(m) ? `${m}px` : `${m.toFixed(2)}px`;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
const converters = {
|
|
43
|
-
anchorType(node, style) {
|
|
44
|
-
const parent = node[$getSubformParent]();
|
|
45
|
-
if (!parent || (parent.layout && parent.layout !== "position")) {
|
|
46
|
-
// anchorType is only used in a positioned layout.
|
|
47
|
-
return;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
if (!("transform" in style)) {
|
|
51
|
-
style.transform = "";
|
|
52
|
-
}
|
|
53
|
-
switch (node.anchorType) {
|
|
54
|
-
case "bottomCenter":
|
|
55
|
-
style.transform += "translate(-50%, -100%)";
|
|
56
|
-
break;
|
|
57
|
-
case "bottomLeft":
|
|
58
|
-
style.transform += "translate(0,-100%)";
|
|
59
|
-
break;
|
|
60
|
-
case "bottomRight":
|
|
61
|
-
style.transform += "translate(-100%,-100%)";
|
|
62
|
-
break;
|
|
63
|
-
case "middleCenter":
|
|
64
|
-
style.transform += "translate(-50%,-50%)";
|
|
65
|
-
break;
|
|
66
|
-
case "middleLeft":
|
|
67
|
-
style.transform += "translate(0,-50%)";
|
|
68
|
-
break;
|
|
69
|
-
case "middleRight":
|
|
70
|
-
style.transform += "translate(-100%,-50%)";
|
|
71
|
-
break;
|
|
72
|
-
case "topCenter":
|
|
73
|
-
style.transform += "translate(-50%,0)";
|
|
74
|
-
break;
|
|
75
|
-
case "topRight":
|
|
76
|
-
style.transform += "translate(-100%,0)";
|
|
77
|
-
break;
|
|
78
|
-
}
|
|
79
|
-
},
|
|
80
|
-
dimensions(node, style) {
|
|
81
|
-
const parent = node[$getSubformParent]();
|
|
82
|
-
let width = node.w;
|
|
83
|
-
const height = node.h;
|
|
84
|
-
if (parent.layout && parent.layout.includes("row")) {
|
|
85
|
-
const extra = parent[$extra];
|
|
86
|
-
const colSpan = node.colSpan;
|
|
87
|
-
let w;
|
|
88
|
-
if (colSpan === -1) {
|
|
89
|
-
w = extra.columnWidths
|
|
90
|
-
.slice(extra.currentColumn)
|
|
91
|
-
.reduce((a, x) => a + x, 0);
|
|
92
|
-
extra.currentColumn = 0;
|
|
93
|
-
} else {
|
|
94
|
-
w = extra.columnWidths
|
|
95
|
-
.slice(extra.currentColumn, extra.currentColumn + colSpan)
|
|
96
|
-
.reduce((a, x) => a + x, 0);
|
|
97
|
-
extra.currentColumn =
|
|
98
|
-
(extra.currentColumn + node.colSpan) % extra.columnWidths.length;
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
if (!isNaN(w)) {
|
|
102
|
-
width = node.w = w;
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
if (width !== "") {
|
|
107
|
-
style.width = measureToString(width);
|
|
108
|
-
} else {
|
|
109
|
-
style.width = "auto";
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
if (height !== "") {
|
|
113
|
-
style.height = measureToString(height);
|
|
114
|
-
} else {
|
|
115
|
-
style.height = "auto";
|
|
116
|
-
}
|
|
117
|
-
},
|
|
118
|
-
position(node, style) {
|
|
119
|
-
const parent = node[$getSubformParent]();
|
|
120
|
-
if (parent && parent.layout && parent.layout !== "position") {
|
|
121
|
-
// IRL, we've some x/y in tb layout.
|
|
122
|
-
// Specs say x/y is only used in positioned layout.
|
|
123
|
-
return;
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
style.position = "absolute";
|
|
127
|
-
style.left = measureToString(node.x);
|
|
128
|
-
style.top = measureToString(node.y);
|
|
129
|
-
},
|
|
130
|
-
rotate(node, style) {
|
|
131
|
-
if (node.rotate) {
|
|
132
|
-
if (!("transform" in style)) {
|
|
133
|
-
style.transform = "";
|
|
134
|
-
}
|
|
135
|
-
style.transform += `rotate(-${node.rotate}deg)`;
|
|
136
|
-
style.transformOrigin = "top left";
|
|
137
|
-
}
|
|
138
|
-
},
|
|
139
|
-
presence(node, style) {
|
|
140
|
-
switch (node.presence) {
|
|
141
|
-
case "invisible":
|
|
142
|
-
style.visibility = "hidden";
|
|
143
|
-
break;
|
|
144
|
-
case "hidden":
|
|
145
|
-
case "inactive":
|
|
146
|
-
style.display = "none";
|
|
147
|
-
break;
|
|
148
|
-
}
|
|
149
|
-
},
|
|
150
|
-
hAlign(node, style) {
|
|
151
|
-
if (node[$nodeName] === "para") {
|
|
152
|
-
switch (node.hAlign) {
|
|
153
|
-
case "justifyAll":
|
|
154
|
-
style.textAlign = "justify-all";
|
|
155
|
-
break;
|
|
156
|
-
case "radix":
|
|
157
|
-
// TODO: implement this correctly !
|
|
158
|
-
style.textAlign = "left";
|
|
159
|
-
break;
|
|
160
|
-
default:
|
|
161
|
-
style.textAlign = node.hAlign;
|
|
162
|
-
}
|
|
163
|
-
} else {
|
|
164
|
-
switch (node.hAlign) {
|
|
165
|
-
case "left":
|
|
166
|
-
style.alignSelf = "start";
|
|
167
|
-
break;
|
|
168
|
-
case "center":
|
|
169
|
-
style.alignSelf = "center";
|
|
170
|
-
break;
|
|
171
|
-
case "right":
|
|
172
|
-
style.alignSelf = "end";
|
|
173
|
-
break;
|
|
174
|
-
}
|
|
175
|
-
}
|
|
176
|
-
},
|
|
177
|
-
margin(node, style) {
|
|
178
|
-
if (node.margin) {
|
|
179
|
-
style.margin = node.margin[$toStyle]().margin;
|
|
180
|
-
}
|
|
181
|
-
},
|
|
182
|
-
};
|
|
183
|
-
|
|
184
|
-
function setMinMaxDimensions(node, style) {
|
|
185
|
-
const parent = node[$getSubformParent]();
|
|
186
|
-
if (parent.layout === "position") {
|
|
187
|
-
if (node.minW > 0) {
|
|
188
|
-
style.minWidth = measureToString(node.minW);
|
|
189
|
-
}
|
|
190
|
-
if (node.maxW > 0) {
|
|
191
|
-
style.maxWidth = measureToString(node.maxW);
|
|
192
|
-
}
|
|
193
|
-
if (node.minH > 0) {
|
|
194
|
-
style.minHeight = measureToString(node.minH);
|
|
195
|
-
}
|
|
196
|
-
if (node.maxH > 0) {
|
|
197
|
-
style.maxHeight = measureToString(node.maxH);
|
|
198
|
-
}
|
|
199
|
-
}
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
function layoutText(text, xfaFont, margin, lineHeight, fontFinder, width) {
|
|
203
|
-
const measure = new TextMeasure(xfaFont, margin, lineHeight, fontFinder);
|
|
204
|
-
if (typeof text === "string") {
|
|
205
|
-
measure.addString(text);
|
|
206
|
-
} else {
|
|
207
|
-
text[$pushGlyphs](measure);
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
return measure.compute(width);
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
function layoutNode(node, availableSpace) {
|
|
214
|
-
let height = null;
|
|
215
|
-
let width = null;
|
|
216
|
-
let isBroken = false;
|
|
217
|
-
|
|
218
|
-
if ((!node.w || !node.h) && node.value) {
|
|
219
|
-
let marginH = 0;
|
|
220
|
-
let marginV = 0;
|
|
221
|
-
if (node.margin) {
|
|
222
|
-
marginH = node.margin.leftInset + node.margin.rightInset;
|
|
223
|
-
marginV = node.margin.topInset + node.margin.bottomInset;
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
let lineHeight = null;
|
|
227
|
-
let margin = null;
|
|
228
|
-
if (node.para) {
|
|
229
|
-
margin = Object.create(null);
|
|
230
|
-
lineHeight = node.para.lineHeight === "" ? null : node.para.lineHeight;
|
|
231
|
-
margin.top = node.para.spaceAbove === "" ? 0 : node.para.spaceAbove;
|
|
232
|
-
margin.bottom = node.para.spaceBelow === "" ? 0 : node.para.spaceBelow;
|
|
233
|
-
margin.left = node.para.marginLeft === "" ? 0 : node.para.marginLeft;
|
|
234
|
-
margin.right = node.para.marginRight === "" ? 0 : node.para.marginRight;
|
|
235
|
-
}
|
|
236
|
-
|
|
237
|
-
let font = node.font;
|
|
238
|
-
if (!font) {
|
|
239
|
-
const root = node[$getTemplateRoot]();
|
|
240
|
-
let parent = node[$getParent]();
|
|
241
|
-
while (parent !== root) {
|
|
242
|
-
if (parent.font) {
|
|
243
|
-
font = parent.font;
|
|
244
|
-
break;
|
|
245
|
-
}
|
|
246
|
-
parent = parent[$getParent]();
|
|
247
|
-
}
|
|
248
|
-
}
|
|
249
|
-
|
|
250
|
-
const maxWidth = !node.w ? availableSpace.width : node.w;
|
|
251
|
-
const fontFinder = node[$globalData].fontFinder;
|
|
252
|
-
if (
|
|
253
|
-
node.value.exData &&
|
|
254
|
-
node.value.exData[$content] &&
|
|
255
|
-
node.value.exData.contentType === "text/html"
|
|
256
|
-
) {
|
|
257
|
-
const res = layoutText(
|
|
258
|
-
node.value.exData[$content],
|
|
259
|
-
font,
|
|
260
|
-
margin,
|
|
261
|
-
lineHeight,
|
|
262
|
-
fontFinder,
|
|
263
|
-
maxWidth
|
|
264
|
-
);
|
|
265
|
-
width = res.width;
|
|
266
|
-
height = res.height;
|
|
267
|
-
isBroken = res.isBroken;
|
|
268
|
-
} else {
|
|
269
|
-
const text = node.value[$text]();
|
|
270
|
-
if (text) {
|
|
271
|
-
const res = layoutText(
|
|
272
|
-
text,
|
|
273
|
-
font,
|
|
274
|
-
margin,
|
|
275
|
-
lineHeight,
|
|
276
|
-
fontFinder,
|
|
277
|
-
maxWidth
|
|
278
|
-
);
|
|
279
|
-
width = res.width;
|
|
280
|
-
height = res.height;
|
|
281
|
-
isBroken = res.isBroken;
|
|
282
|
-
}
|
|
283
|
-
}
|
|
284
|
-
|
|
285
|
-
if (width !== null && !node.w) {
|
|
286
|
-
width += marginH;
|
|
287
|
-
}
|
|
288
|
-
|
|
289
|
-
if (height !== null && !node.h) {
|
|
290
|
-
height += marginV;
|
|
291
|
-
}
|
|
292
|
-
}
|
|
293
|
-
return { w: width, h: height, isBroken };
|
|
294
|
-
}
|
|
295
|
-
|
|
296
|
-
function computeBbox(node, html, availableSpace) {
|
|
297
|
-
let bbox;
|
|
298
|
-
if (node.w !== "" && node.h !== "") {
|
|
299
|
-
bbox = [node.x, node.y, node.w, node.h];
|
|
300
|
-
} else {
|
|
301
|
-
if (!availableSpace) {
|
|
302
|
-
return null;
|
|
303
|
-
}
|
|
304
|
-
let width = node.w;
|
|
305
|
-
if (width === "") {
|
|
306
|
-
if (node.maxW === 0) {
|
|
307
|
-
const parent = node[$getSubformParent]();
|
|
308
|
-
if (parent.layout === "position" && parent.w !== "") {
|
|
309
|
-
width = 0;
|
|
310
|
-
} else {
|
|
311
|
-
width = node.minW;
|
|
312
|
-
}
|
|
313
|
-
} else {
|
|
314
|
-
width = Math.min(node.maxW, availableSpace.width);
|
|
315
|
-
}
|
|
316
|
-
html.attributes.style.width = measureToString(width);
|
|
317
|
-
}
|
|
318
|
-
|
|
319
|
-
let height = node.h;
|
|
320
|
-
if (height === "") {
|
|
321
|
-
if (node.maxH === 0) {
|
|
322
|
-
const parent = node[$getSubformParent]();
|
|
323
|
-
if (parent.layout === "position" && parent.h !== "") {
|
|
324
|
-
height = 0;
|
|
325
|
-
} else {
|
|
326
|
-
height = node.minH;
|
|
327
|
-
}
|
|
328
|
-
} else {
|
|
329
|
-
height = Math.min(node.maxH, availableSpace.height);
|
|
330
|
-
}
|
|
331
|
-
html.attributes.style.height = measureToString(height);
|
|
332
|
-
}
|
|
333
|
-
|
|
334
|
-
bbox = [node.x, node.y, width, height];
|
|
335
|
-
}
|
|
336
|
-
return bbox;
|
|
337
|
-
}
|
|
338
|
-
|
|
339
|
-
function fixDimensions(node) {
|
|
340
|
-
const parent = node[$getSubformParent]();
|
|
341
|
-
if (parent.layout && parent.layout.includes("row")) {
|
|
342
|
-
const extra = parent[$extra];
|
|
343
|
-
const colSpan = node.colSpan;
|
|
344
|
-
let width;
|
|
345
|
-
if (colSpan === -1) {
|
|
346
|
-
width = extra.columnWidths
|
|
347
|
-
.slice(extra.currentColumn)
|
|
348
|
-
.reduce((a, w) => a + w, 0);
|
|
349
|
-
} else {
|
|
350
|
-
width = extra.columnWidths
|
|
351
|
-
.slice(extra.currentColumn, extra.currentColumn + colSpan)
|
|
352
|
-
.reduce((a, w) => a + w, 0);
|
|
353
|
-
}
|
|
354
|
-
if (!isNaN(width)) {
|
|
355
|
-
node.w = width;
|
|
356
|
-
}
|
|
357
|
-
}
|
|
358
|
-
|
|
359
|
-
if (parent.layout && parent.layout !== "position") {
|
|
360
|
-
// Useless in this context.
|
|
361
|
-
node.x = node.y = 0;
|
|
362
|
-
}
|
|
363
|
-
|
|
364
|
-
if (node.layout === "table") {
|
|
365
|
-
if (node.w === "" && Array.isArray(node.columnWidths)) {
|
|
366
|
-
node.w = node.columnWidths.reduce((a, x) => a + x, 0);
|
|
367
|
-
}
|
|
368
|
-
}
|
|
369
|
-
}
|
|
370
|
-
|
|
371
|
-
function layoutClass(node) {
|
|
372
|
-
switch (node.layout) {
|
|
373
|
-
case "position":
|
|
374
|
-
return "xfaPosition";
|
|
375
|
-
case "lr-tb":
|
|
376
|
-
return "xfaLrTb";
|
|
377
|
-
case "rl-row":
|
|
378
|
-
return "xfaRlRow";
|
|
379
|
-
case "rl-tb":
|
|
380
|
-
return "xfaRlTb";
|
|
381
|
-
case "row":
|
|
382
|
-
return "xfaRow";
|
|
383
|
-
case "table":
|
|
384
|
-
return "xfaTable";
|
|
385
|
-
case "tb":
|
|
386
|
-
return "xfaTb";
|
|
387
|
-
default:
|
|
388
|
-
return "xfaPosition";
|
|
389
|
-
}
|
|
390
|
-
}
|
|
391
|
-
|
|
392
|
-
function toStyle(node, ...names) {
|
|
393
|
-
const style = Object.create(null);
|
|
394
|
-
for (const name of names) {
|
|
395
|
-
const value = node[name];
|
|
396
|
-
if (value === null) {
|
|
397
|
-
continue;
|
|
398
|
-
}
|
|
399
|
-
if (converters.hasOwnProperty(name)) {
|
|
400
|
-
converters[name](node, style);
|
|
401
|
-
continue;
|
|
402
|
-
}
|
|
403
|
-
|
|
404
|
-
if (value instanceof XFAObject) {
|
|
405
|
-
const newStyle = value[$toStyle]();
|
|
406
|
-
if (newStyle) {
|
|
407
|
-
Object.assign(style, newStyle);
|
|
408
|
-
} else {
|
|
409
|
-
warn(`(DEBUG) - XFA - style for ${name} not implemented yet`);
|
|
410
|
-
}
|
|
411
|
-
}
|
|
412
|
-
}
|
|
413
|
-
return style;
|
|
414
|
-
}
|
|
415
|
-
|
|
416
|
-
function createWrapper(node, html) {
|
|
417
|
-
const { attributes } = html;
|
|
418
|
-
const { style } = attributes;
|
|
419
|
-
|
|
420
|
-
const wrapper = {
|
|
421
|
-
name: "div",
|
|
422
|
-
attributes: {
|
|
423
|
-
class: ["xfaWrapper"],
|
|
424
|
-
style: Object.create(null),
|
|
425
|
-
},
|
|
426
|
-
children: [],
|
|
427
|
-
};
|
|
428
|
-
|
|
429
|
-
attributes.class.push("xfaWrapped");
|
|
430
|
-
|
|
431
|
-
if (node.border) {
|
|
432
|
-
const { widths, insets } = node.border[$extra];
|
|
433
|
-
let width, height;
|
|
434
|
-
let top = insets[0];
|
|
435
|
-
let left = insets[3];
|
|
436
|
-
const insetsH = insets[0] + insets[2];
|
|
437
|
-
const insetsW = insets[1] + insets[3];
|
|
438
|
-
switch (node.border.hand) {
|
|
439
|
-
case "even":
|
|
440
|
-
top -= widths[0] / 2;
|
|
441
|
-
left -= widths[3] / 2;
|
|
442
|
-
width = `calc(100% + ${(widths[1] + widths[3]) / 2 - insetsW}px)`;
|
|
443
|
-
height = `calc(100% + ${(widths[0] + widths[2]) / 2 - insetsH}px)`;
|
|
444
|
-
break;
|
|
445
|
-
case "left":
|
|
446
|
-
top -= widths[0];
|
|
447
|
-
left -= widths[3];
|
|
448
|
-
width = `calc(100% + ${widths[1] + widths[3] - insetsW}px)`;
|
|
449
|
-
height = `calc(100% + ${widths[0] + widths[2] - insetsH}px)`;
|
|
450
|
-
break;
|
|
451
|
-
case "right":
|
|
452
|
-
width = insetsW ? `calc(100% - ${insetsW}px)` : "100%";
|
|
453
|
-
height = insetsH ? `calc(100% - ${insetsH}px)` : "100%";
|
|
454
|
-
break;
|
|
455
|
-
}
|
|
456
|
-
const classNames = ["xfaBorder"];
|
|
457
|
-
if (isPrintOnly(node.border)) {
|
|
458
|
-
classNames.push("xfaPrintOnly");
|
|
459
|
-
}
|
|
460
|
-
|
|
461
|
-
const border = {
|
|
462
|
-
name: "div",
|
|
463
|
-
attributes: {
|
|
464
|
-
class: classNames,
|
|
465
|
-
style: {
|
|
466
|
-
top: `${top}px`,
|
|
467
|
-
left: `${left}px`,
|
|
468
|
-
width,
|
|
469
|
-
height,
|
|
470
|
-
},
|
|
471
|
-
},
|
|
472
|
-
children: [],
|
|
473
|
-
};
|
|
474
|
-
|
|
475
|
-
for (const key of [
|
|
476
|
-
"border",
|
|
477
|
-
"borderWidth",
|
|
478
|
-
"borderColor",
|
|
479
|
-
"borderRadius",
|
|
480
|
-
"borderStyle",
|
|
481
|
-
]) {
|
|
482
|
-
if (style[key] !== undefined) {
|
|
483
|
-
border.attributes.style[key] = style[key];
|
|
484
|
-
delete style[key];
|
|
485
|
-
}
|
|
486
|
-
}
|
|
487
|
-
wrapper.children.push(border, html);
|
|
488
|
-
} else {
|
|
489
|
-
wrapper.children.push(html);
|
|
490
|
-
}
|
|
491
|
-
|
|
492
|
-
for (const key of [
|
|
493
|
-
"background",
|
|
494
|
-
"backgroundClip",
|
|
495
|
-
"top",
|
|
496
|
-
"left",
|
|
497
|
-
"width",
|
|
498
|
-
"height",
|
|
499
|
-
"minWidth",
|
|
500
|
-
"minHeight",
|
|
501
|
-
"maxWidth",
|
|
502
|
-
"maxHeight",
|
|
503
|
-
"transform",
|
|
504
|
-
"transformOrigin",
|
|
505
|
-
"visibility",
|
|
506
|
-
]) {
|
|
507
|
-
if (style[key] !== undefined) {
|
|
508
|
-
wrapper.attributes.style[key] = style[key];
|
|
509
|
-
delete style[key];
|
|
510
|
-
}
|
|
511
|
-
}
|
|
512
|
-
|
|
513
|
-
if (style.position === "absolute") {
|
|
514
|
-
wrapper.attributes.style.position = "absolute";
|
|
515
|
-
} else {
|
|
516
|
-
wrapper.attributes.style.position = "relative";
|
|
517
|
-
}
|
|
518
|
-
delete style.position;
|
|
519
|
-
|
|
520
|
-
if (style.alignSelf) {
|
|
521
|
-
wrapper.attributes.style.alignSelf = style.alignSelf;
|
|
522
|
-
delete style.alignSelf;
|
|
523
|
-
}
|
|
524
|
-
|
|
525
|
-
return wrapper;
|
|
526
|
-
}
|
|
527
|
-
|
|
528
|
-
function fixTextIndent(styles) {
|
|
529
|
-
const indent = getMeasurement(styles.textIndent, "0px");
|
|
530
|
-
if (indent >= 0) {
|
|
531
|
-
return;
|
|
532
|
-
}
|
|
533
|
-
|
|
534
|
-
// If indent is negative then it's a hanging indent.
|
|
535
|
-
const align = styles.textAlign === "right" ? "right" : "left";
|
|
536
|
-
const name = "padding" + (align === "left" ? "Left" : "Right");
|
|
537
|
-
const padding = getMeasurement(styles[name], "0px");
|
|
538
|
-
styles[name] = `${padding - indent}px`;
|
|
539
|
-
}
|
|
540
|
-
|
|
541
|
-
function setAccess(node, classNames) {
|
|
542
|
-
switch (node.access) {
|
|
543
|
-
case "nonInteractive":
|
|
544
|
-
classNames.push("xfaNonInteractive");
|
|
545
|
-
break;
|
|
546
|
-
case "readOnly":
|
|
547
|
-
classNames.push("xfaReadOnly");
|
|
548
|
-
break;
|
|
549
|
-
case "protected":
|
|
550
|
-
classNames.push("xfaDisabled");
|
|
551
|
-
break;
|
|
552
|
-
}
|
|
553
|
-
}
|
|
554
|
-
|
|
555
|
-
function isPrintOnly(node) {
|
|
556
|
-
return (
|
|
557
|
-
node.relevant.length > 0 &&
|
|
558
|
-
!node.relevant[0].excluded &&
|
|
559
|
-
node.relevant[0].viewname === "print"
|
|
560
|
-
);
|
|
561
|
-
}
|
|
562
|
-
|
|
563
|
-
function setPara(node, nodeStyle, value) {
|
|
564
|
-
if (value.attributes.class && value.attributes.class.includes("xfaRich")) {
|
|
565
|
-
if (nodeStyle) {
|
|
566
|
-
if (node.h === "") {
|
|
567
|
-
nodeStyle.height = "auto";
|
|
568
|
-
}
|
|
569
|
-
if (node.w === "") {
|
|
570
|
-
nodeStyle.width = "auto";
|
|
571
|
-
}
|
|
572
|
-
}
|
|
573
|
-
if (node.para) {
|
|
574
|
-
// By definition exData are external data so para
|
|
575
|
-
// has no effect on it.
|
|
576
|
-
const valueStyle = value.attributes.style;
|
|
577
|
-
valueStyle.display = "flex";
|
|
578
|
-
valueStyle.flexDirection = "column";
|
|
579
|
-
switch (node.para.vAlign) {
|
|
580
|
-
case "top":
|
|
581
|
-
valueStyle.justifyContent = "start";
|
|
582
|
-
break;
|
|
583
|
-
case "bottom":
|
|
584
|
-
valueStyle.justifyContent = "end";
|
|
585
|
-
break;
|
|
586
|
-
case "middle":
|
|
587
|
-
valueStyle.justifyContent = "center";
|
|
588
|
-
break;
|
|
589
|
-
}
|
|
590
|
-
|
|
591
|
-
const paraStyle = node.para[$toStyle]();
|
|
592
|
-
for (const [key, val] of Object.entries(paraStyle)) {
|
|
593
|
-
if (!(key in valueStyle)) {
|
|
594
|
-
valueStyle[key] = val;
|
|
595
|
-
}
|
|
596
|
-
}
|
|
597
|
-
}
|
|
598
|
-
}
|
|
599
|
-
}
|
|
600
|
-
|
|
601
|
-
function setFontFamily(xfaFont, fontFinder, style) {
|
|
602
|
-
const name = stripQuotes(xfaFont.typeface);
|
|
603
|
-
const typeface = fontFinder.find(name);
|
|
604
|
-
|
|
605
|
-
style.fontFamily = `"${name}"`;
|
|
606
|
-
if (typeface) {
|
|
607
|
-
const { fontFamily } = typeface.regular.cssFontInfo;
|
|
608
|
-
if (fontFamily !== name) {
|
|
609
|
-
style.fontFamily = `"${fontFamily}"`;
|
|
610
|
-
}
|
|
611
|
-
if (style.lineHeight) {
|
|
612
|
-
// Already something so don't overwrite.
|
|
613
|
-
return;
|
|
614
|
-
}
|
|
615
|
-
|
|
616
|
-
const pdfFont = selectFont(xfaFont, typeface);
|
|
617
|
-
if (pdfFont && pdfFont.lineHeight > 0) {
|
|
618
|
-
style.lineHeight = Math.max(1.2, pdfFont.lineHeight);
|
|
619
|
-
} else {
|
|
620
|
-
style.lineHeight = 1.2;
|
|
621
|
-
}
|
|
622
|
-
}
|
|
623
|
-
}
|
|
624
|
-
|
|
625
|
-
export {
|
|
626
|
-
computeBbox,
|
|
627
|
-
createWrapper,
|
|
628
|
-
fixDimensions,
|
|
629
|
-
fixTextIndent,
|
|
630
|
-
isPrintOnly,
|
|
631
|
-
layoutClass,
|
|
632
|
-
layoutNode,
|
|
633
|
-
measureToString,
|
|
634
|
-
setAccess,
|
|
635
|
-
setFontFamily,
|
|
636
|
-
setMinMaxDimensions,
|
|
637
|
-
setPara,
|
|
638
|
-
toStyle,
|
|
639
|
-
};
|