@vaadin-component-factory/vcf-pdf-viewer 0.9.0 → 0.9.4
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 +33 -18
- package/{src/display → pdfjs/dist}/display_utils.js +344 -139
- package/{src/display → pdfjs/dist}/fetch_stream.js +115 -97
- package/pdfjs/dist/get.js +1857 -0
- package/pdfjs/dist/index.js +767 -0
- 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/typeof.js +100 -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 +77 -27
- package/theme/lumo/vcf-pdf-viewer-styles.js +1 -1
- 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
package/src/core/jpx_stream.js
DELETED
|
@@ -1,87 +0,0 @@
|
|
|
1
|
-
/* Copyright 2012 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 { DecodeStream } from "./decode_stream.js";
|
|
17
|
-
import { JpxImage } from "./jpx.js";
|
|
18
|
-
import { shadow } from "../shared/util.js";
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* For JPEG 2000's we use a library to decode these images and
|
|
22
|
-
* the stream behaves like all the other DecodeStreams.
|
|
23
|
-
*/
|
|
24
|
-
class JpxStream extends DecodeStream {
|
|
25
|
-
constructor(stream, maybeLength, params) {
|
|
26
|
-
super(maybeLength);
|
|
27
|
-
|
|
28
|
-
this.stream = stream;
|
|
29
|
-
this.dict = stream.dict;
|
|
30
|
-
this.maybeLength = maybeLength;
|
|
31
|
-
this.params = params;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
get bytes() {
|
|
35
|
-
// If `this.maybeLength` is null, we'll get the entire stream.
|
|
36
|
-
return shadow(this, "bytes", this.stream.getBytes(this.maybeLength));
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
ensureBuffer(requested) {
|
|
40
|
-
// No-op, since `this.readBlock` will always parse the entire image and
|
|
41
|
-
// directly insert all of its data into `this.buffer`.
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
readBlock() {
|
|
45
|
-
if (this.eof) {
|
|
46
|
-
return;
|
|
47
|
-
}
|
|
48
|
-
const jpxImage = new JpxImage();
|
|
49
|
-
jpxImage.parse(this.bytes);
|
|
50
|
-
|
|
51
|
-
const width = jpxImage.width;
|
|
52
|
-
const height = jpxImage.height;
|
|
53
|
-
const componentsCount = jpxImage.componentsCount;
|
|
54
|
-
const tileCount = jpxImage.tiles.length;
|
|
55
|
-
if (tileCount === 1) {
|
|
56
|
-
this.buffer = jpxImage.tiles[0].items;
|
|
57
|
-
} else {
|
|
58
|
-
const data = new Uint8ClampedArray(width * height * componentsCount);
|
|
59
|
-
|
|
60
|
-
for (let k = 0; k < tileCount; k++) {
|
|
61
|
-
const tileComponents = jpxImage.tiles[k];
|
|
62
|
-
const tileWidth = tileComponents.width;
|
|
63
|
-
const tileHeight = tileComponents.height;
|
|
64
|
-
const tileLeft = tileComponents.left;
|
|
65
|
-
const tileTop = tileComponents.top;
|
|
66
|
-
|
|
67
|
-
const src = tileComponents.items;
|
|
68
|
-
let srcPosition = 0;
|
|
69
|
-
let dataPosition = (width * tileTop + tileLeft) * componentsCount;
|
|
70
|
-
const imgRowSize = width * componentsCount;
|
|
71
|
-
const tileRowSize = tileWidth * componentsCount;
|
|
72
|
-
|
|
73
|
-
for (let j = 0; j < tileHeight; j++) {
|
|
74
|
-
const rowBytes = src.subarray(srcPosition, srcPosition + tileRowSize);
|
|
75
|
-
data.set(rowBytes, dataPosition);
|
|
76
|
-
srcPosition += tileRowSize;
|
|
77
|
-
dataPosition += imgRowSize;
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
this.buffer = data;
|
|
81
|
-
}
|
|
82
|
-
this.bufferLength = this.buffer.length;
|
|
83
|
-
this.eof = true;
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
export { JpxStream };
|
|
@@ -1,221 +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
|
-
// Widths of glyphs in LiberationSans-Bold.ttf.
|
|
17
|
-
const LiberationSansBoldWidths = [
|
|
18
|
-
365, 0, 722, 1000, 1000, 722, 722, 722, 722, 722, 722, 722, 722, 722, 722,
|
|
19
|
-
722, 722, 722, 722, 722, 722, 722, 722, 722, 722, 667, 722, 722, 722, 719,
|
|
20
|
-
667, 667, 667, 667, 667, 667, 667, 667, 667, 723, 667, 667, 853, 722, 906,
|
|
21
|
-
722, 556, 611, 778, 601, 778, 778, 778, 778, 722, 604, 354, 354, 604, 722,
|
|
22
|
-
722, 278, 785, 278, 278, 278, 278, 278, 278, 278, 278, 278, 278, 474, 278,
|
|
23
|
-
556, 556, 722, 722, 722, 611, 611, 667, 611, 611, 611, 611, 833, 833, 722,
|
|
24
|
-
722, 722, 722, 722, 722, 778, 1000, 778, 778, 778, 778, 778, 778, 778, 802,
|
|
25
|
-
838, 778, 825, 778, 778, 778, 667, 821, 722, 809, 778, 722, 722, 722, 722,
|
|
26
|
-
667, 667, 708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 625, 708, 708,
|
|
27
|
-
708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 708,
|
|
28
|
-
708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 667, 667, 667,
|
|
29
|
-
667, 667, 600, 611, 611, 611, 611, 611, 778, 667, 722, 722, 722, 722, 722,
|
|
30
|
-
722, 722, 722, 722, 667, 667, 927, 722, 722, 667, 944, 944, 944, 944, 944,
|
|
31
|
-
667, 644, 667, 667, 667, 667, 667, 611, 611, 611, 611, 611, 556, 556, 556,
|
|
32
|
-
556, 333, 333, 556, 889, 889, 1000, 722, 719, 722, 567, 712, 667, 669, 904,
|
|
33
|
-
626, 719, 719, 610, 702, 833, 722, 778, 719, 667, 722, 611, 622, 854, 667,
|
|
34
|
-
730, 703, 1005, 1019, 870, 979, 719, 711, 1031, 719, 487, 885, 567, 711, 667,
|
|
35
|
-
278, 276, 556, 1094, 1062, 875, 610, 622, 556, 618, 615, 417, 635, 556, 556,
|
|
36
|
-
709, 497, 615, 615, 500, 635, 740, 604, 611, 604, 611, 556, 490, 556, 875,
|
|
37
|
-
556, 615, 581, 833, 844, 729, 854, 615, 552, 854, 583, 447, 611, 417, 552,
|
|
38
|
-
556, 278, 281, 278, 969, 906, 611, 500, 556, 719, 778, 604, 611, 885, 489,
|
|
39
|
-
1115, 556, 615, 615, 556, 722, 333, 556, 549, 556, 556, 1000, 500, 1000, 1000,
|
|
40
|
-
500, 500, 500, 584, 584, 389, 975, 556, 611, 278, 280, 610, 708, 389, 389,
|
|
41
|
-
333, 333, 333, 333, 280, 350, 556, 556, 333, 333, 222, 556, 556, 556, 556,
|
|
42
|
-
333, 556, 576, 604, 333, 333, 656, 333, 278, 333, 222, 737, 556, 333, 611,
|
|
43
|
-
556, 556, 719, 611, 400, 606, 510, 333, 333, 465, 549, 729, 708, 556, 333,
|
|
44
|
-
278, 556, 556, 556, 556, 556, 556, 556, 556, 556, 333, 1000, 556, 1000, 556,
|
|
45
|
-
611, 556, 475, 451, 584, 583, 600, 611, 611, 611, 333, 604, 333, 333, 750,
|
|
46
|
-
604, 1000, 556, 834, 333, 556, 556, 333, 556, 611, 556, 611, 611, 611, 611,
|
|
47
|
-
611, 333, 333, 584, 549, 556, 556, 333, 333, 611, 611, 611, 594, 604, 333,
|
|
48
|
-
333, 278, 278, 278, 278, 278, 278, 556, 278, 713, 274, 604, 604, 722, 604,
|
|
49
|
-
604, 1052, 278, 278, 278, 278, 278, 278, 278, 278, 556, 558, 556, 556, 278,
|
|
50
|
-
278, 556, 385, 278, 479, 584, 549, 708, 556, 584, 278, 494, 278, 708, 889,
|
|
51
|
-
552, 750, 333, 584, 240, 612, 584, 500, 750, 611, 611, 708, 611, 611, 556,
|
|
52
|
-
333, 549, 611, 556, 556, 611, 611, 611, 611, 611, 944, 333, 611, 611, 611,
|
|
53
|
-
845, 845, 611, 611, 556, 834, 834, 834, 354, 370, 365, 979, 611, 611, 611,
|
|
54
|
-
611, 556, 333, 333, 494, 889, 278, 1000, 1094, 715, 766, 584, 549, 823, 753,
|
|
55
|
-
611, 611, 611, 474, 500, 500, 500, 278, 278, 278, 278, 238, 389, 389, 549,
|
|
56
|
-
389, 389, 737, 584, 619, 333, 708, 556, 556, 556, 556, 556, 556, 479, 556,
|
|
57
|
-
556, 834, 333, 708, 684, 520, 556, 278, 1021, 531, 556, 713, 917, 333, 446,
|
|
58
|
-
333, 479, 333, 541, 611, 556, 834, 834, 333, 333, 333, 1000, 990, 990, 990,
|
|
59
|
-
990, 556, 611, 611, 611, 611, 611, 611, 611, 611, 556, 552, 278, 333, 333,
|
|
60
|
-
333, 576, 333, 611, 333, 333, 333, 667, 722, 556, 615, 333, 333, 333, 396,
|
|
61
|
-
768, 612, 167, 278, 750, 333, 611, 611, 611, 708, 582, 582, 582, 582, 611,
|
|
62
|
-
611, 556, 778, 778, 778, 778, 778, 556, 445, 556, 556, 556, 556, 556, 556,
|
|
63
|
-
500, 500, 500, 500, 556, 460,
|
|
64
|
-
];
|
|
65
|
-
|
|
66
|
-
// Widths of glyphs in LiberationSans-BoldItalic.ttf.
|
|
67
|
-
const LiberationSansBoldItalicWidths = [
|
|
68
|
-
365, 0, 722, 1000, 1000, 722, 722, 722, 722, 722, 722, 722, 722, 722, 722,
|
|
69
|
-
722, 722, 722, 722, 722, 722, 722, 722, 722, 722, 667, 722, 722, 722, 671,
|
|
70
|
-
667, 667, 667, 667, 667, 667, 667, 667, 667, 723, 667, 667, 854, 722, 906,
|
|
71
|
-
722, 556, 611, 778, 610, 778, 778, 778, 778, 722, 604, 354, 354, 604, 722,
|
|
72
|
-
722, 278, 782, 278, 278, 278, 278, 278, 278, 278, 278, 278, 278, 473, 278,
|
|
73
|
-
556, 556, 722, 722, 722, 611, 611, 667, 611, 611, 611, 611, 833, 833, 722,
|
|
74
|
-
722, 722, 722, 722, 722, 778, 1000, 778, 778, 778, 778, 778, 778, 778, 781,
|
|
75
|
-
847, 778, 844, 778, 778, 778, 667, 822, 718, 829, 778, 722, 722, 722, 722,
|
|
76
|
-
667, 667, 708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 625, 708, 708,
|
|
77
|
-
708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 708,
|
|
78
|
-
708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 667, 667, 667,
|
|
79
|
-
667, 667, 590, 611, 611, 611, 611, 611, 778, 667, 722, 722, 722, 722, 722,
|
|
80
|
-
722, 722, 722, 722, 667, 667, 930, 722, 722, 667, 944, 944, 944, 944, 944,
|
|
81
|
-
667, 657, 667, 667, 667, 667, 667, 611, 611, 611, 611, 611, 556, 556, 556,
|
|
82
|
-
556, 333, 333, 556, 889, 889, 1000, 722, 708, 722, 614, 722, 667, 667, 927,
|
|
83
|
-
643, 719, 719, 615, 687, 833, 722, 778, 719, 667, 722, 611, 677, 781, 667,
|
|
84
|
-
729, 708, 979, 989, 854, 1000, 708, 719, 1042, 729, 575, 886, 614, 719, 667,
|
|
85
|
-
278, 278, 556, 1094, 1042, 854, 622, 677, 556, 619, 604, 534, 618, 556, 556,
|
|
86
|
-
736, 510, 611, 611, 507, 622, 740, 604, 611, 611, 611, 556, 889, 556, 885,
|
|
87
|
-
556, 646, 583, 889, 935, 707, 854, 594, 552, 865, 589, 467, 611, 469, 563,
|
|
88
|
-
556, 278, 278, 278, 969, 906, 611, 507, 556, 719, 778, 611, 611, 885, 516,
|
|
89
|
-
1146, 556, 620, 620, 556, 722, 333, 556, 549, 556, 556, 1000, 500, 999, 1000,
|
|
90
|
-
500, 500, 500, 584, 584, 389, 975, 556, 611, 278, 280, 621, 708, 389, 389,
|
|
91
|
-
333, 333, 333, 333, 280, 350, 556, 556, 333, 333, 222, 556, 556, 556, 556,
|
|
92
|
-
333, 556, 578, 604, 333, 333, 656, 333, 278, 333, 222, 737, 556, 333, 611,
|
|
93
|
-
556, 556, 740, 611, 400, 610, 510, 333, 333, 333, 549, 729, 708, 556, 333,
|
|
94
|
-
278, 556, 556, 556, 556, 556, 556, 556, 556, 556, 333, 1000, 556, 1000, 556,
|
|
95
|
-
611, 556, 479, 479, 584, 583, 600, 611, 611, 611, 333, 604, 333, 333, 750,
|
|
96
|
-
604, 1000, 556, 834, 333, 556, 556, 333, 556, 611, 556, 611, 611, 611, 611,
|
|
97
|
-
611, 333, 333, 584, 549, 556, 556, 333, 333, 611, 611, 611, 594, 604, 333,
|
|
98
|
-
333, 278, 278, 278, 278, 278, 278, 556, 278, 713, 274, 604, 604, 722, 604,
|
|
99
|
-
604, 1052, 278, 278, 278, 278, 278, 278, 278, 278, 556, 566, 556, 556, 278,
|
|
100
|
-
278, 556, 396, 278, 479, 584, 549, 708, 556, 584, 278, 494, 278, 708, 889,
|
|
101
|
-
552, 750, 333, 584, 240, 603, 584, 500, 750, 611, 611, 708, 611, 611, 556,
|
|
102
|
-
333, 549, 611, 556, 556, 611, 611, 611, 611, 611, 944, 333, 611, 611, 611,
|
|
103
|
-
834, 834, 611, 611, 556, 834, 834, 834, 354, 370, 365, 979, 611, 611, 611,
|
|
104
|
-
611, 556, 333, 333, 494, 889, 278, 1000, 1104, 704, 712, 584, 549, 823, 773,
|
|
105
|
-
611, 611, 611, 474, 500, 500, 500, 278, 278, 278, 278, 238, 389, 389, 549,
|
|
106
|
-
389, 389, 737, 584, 605, 333, 708, 556, 556, 556, 556, 556, 556, 479, 556,
|
|
107
|
-
556, 834, 333, 708, 664, 532, 556, 278, 1021, 531, 556, 713, 917, 333, 409,
|
|
108
|
-
333, 479, 333, 558, 611, 556, 834, 834, 333, 333, 333, 1000, 990, 990, 990,
|
|
109
|
-
990, 556, 611, 611, 611, 611, 611, 611, 611, 611, 556, 552, 278, 333, 333,
|
|
110
|
-
333, 576, 333, 611, 333, 333, 333, 667, 719, 556, 619, 333, 333, 333, 396,
|
|
111
|
-
768, 612, 167, 278, 750, 333, 611, 611, 611, 708, 591, 591, 591, 591, 611,
|
|
112
|
-
611, 556, 778, 778, 778, 778, 778, 556, 450, 556, 556, 556, 556, 556, 556,
|
|
113
|
-
500, 500, 500, 500, 556, 492,
|
|
114
|
-
];
|
|
115
|
-
|
|
116
|
-
// Widths of glyphs in LiberationSans-Italic.ttf.
|
|
117
|
-
const LiberationSansItalicWidths = [
|
|
118
|
-
365, 0, 667, 1000, 1000, 667, 667, 667, 667, 667, 667, 667, 667, 667, 667,
|
|
119
|
-
667, 667, 667, 667, 722, 722, 722, 722, 722, 722, 667, 722, 722, 722, 671,
|
|
120
|
-
667, 667, 667, 667, 667, 667, 667, 667, 667, 723, 667, 667, 789, 722, 846,
|
|
121
|
-
722, 556, 611, 778, 570, 778, 778, 778, 778, 722, 604, 354, 354, 604, 722,
|
|
122
|
-
722, 278, 733, 278, 278, 278, 278, 278, 278, 278, 278, 278, 278, 389, 278,
|
|
123
|
-
500, 500, 667, 667, 667, 556, 556, 667, 556, 556, 556, 556, 833, 833, 722,
|
|
124
|
-
722, 722, 722, 722, 722, 778, 1000, 778, 778, 778, 778, 778, 778, 778, 761,
|
|
125
|
-
775, 778, 794, 778, 778, 778, 667, 837, 725, 831, 778, 722, 722, 722, 722,
|
|
126
|
-
667, 667, 708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 625, 708, 708,
|
|
127
|
-
708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 708,
|
|
128
|
-
708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 667, 667, 667,
|
|
129
|
-
667, 667, 600, 611, 611, 611, 611, 611, 778, 667, 722, 722, 722, 722, 722,
|
|
130
|
-
722, 722, 722, 722, 667, 667, 865, 722, 722, 667, 944, 944, 944, 944, 944,
|
|
131
|
-
667, 648, 667, 667, 667, 667, 667, 611, 611, 611, 611, 611, 556, 556, 556,
|
|
132
|
-
556, 333, 294, 556, 889, 889, 1000, 667, 651, 667, 544, 704, 667, 667, 917,
|
|
133
|
-
614, 715, 715, 589, 686, 833, 722, 778, 725, 667, 722, 611, 639, 795, 667,
|
|
134
|
-
727, 673, 920, 923, 805, 886, 651, 694, 1022, 682, 492, 843, 544, 708, 667,
|
|
135
|
-
278, 278, 500, 1066, 982, 844, 589, 639, 556, 562, 522, 493, 553, 556, 556,
|
|
136
|
-
688, 465, 556, 556, 472, 564, 686, 550, 556, 556, 556, 500, 833, 500, 835,
|
|
137
|
-
500, 572, 518, 830, 851, 621, 736, 526, 492, 752, 534, 339, 556, 378, 496,
|
|
138
|
-
500, 222, 222, 222, 910, 828, 556, 472, 500, 724, 778, 556, 556, 885, 323,
|
|
139
|
-
1083, 556, 570, 570, 556, 667, 278, 556, 549, 556, 556, 1000, 500, 1000, 998,
|
|
140
|
-
500, 500, 500, 469, 584, 389, 1015, 556, 556, 278, 260, 571, 708, 334, 334,
|
|
141
|
-
278, 278, 333, 285, 260, 350, 500, 500, 333, 324, 222, 500, 500, 500, 500,
|
|
142
|
-
333, 556, 546, 604, 333, 324, 656, 278, 278, 333, 222, 737, 556, 333, 556,
|
|
143
|
-
556, 556, 625, 556, 400, 556, 510, 333, 316, 333, 549, 729, 708, 556, 333,
|
|
144
|
-
278, 556, 556, 556, 556, 556, 556, 556, 556, 556, 333, 1000, 556, 1000, 556,
|
|
145
|
-
556, 556, 439, 439, 584, 584, 600, 555, 555, 556, 278, 500, 333, 278, 750,
|
|
146
|
-
604, 1000, 556, 834, 333, 556, 556, 333, 556, 556, 500, 556, 556, 556, 556,
|
|
147
|
-
611, 333, 294, 584, 549, 556, 556, 333, 333, 556, 556, 556, 594, 604, 333,
|
|
148
|
-
398, 222, 278, 278, 278, 278, 278, 444, 278, 713, 274, 604, 604, 719, 604,
|
|
149
|
-
604, 1052, 222, 222, 222, 222, 222, 278, 222, 222, 500, 500, 500, 500, 222,
|
|
150
|
-
222, 492, 281, 222, 400, 584, 549, 708, 556, 584, 222, 494, 222, 708, 833,
|
|
151
|
-
552, 750, 333, 584, 188, 548, 584, 500, 750, 556, 556, 615, 556, 556, 556,
|
|
152
|
-
333, 549, 556, 500, 556, 556, 556, 556, 556, 556, 944, 333, 556, 556, 556,
|
|
153
|
-
779, 779, 556, 556, 556, 834, 834, 834, 354, 370, 365, 979, 611, 611, 556,
|
|
154
|
-
556, 537, 333, 333, 494, 889, 278, 1000, 1094, 652, 670, 584, 549, 823, 728,
|
|
155
|
-
556, 556, 611, 355, 333, 333, 333, 222, 222, 222, 222, 191, 333, 333, 549,
|
|
156
|
-
333, 333, 737, 584, 573, 333, 708, 500, 500, 500, 500, 500, 500, 354, 556,
|
|
157
|
-
556, 834, 333, 708, 603, 486, 556, 278, 1021, 531, 556, 713, 917, 278, 374,
|
|
158
|
-
278, 354, 278, 542, 556, 556, 834, 834, 333, 328, 333, 1000, 990, 990, 990,
|
|
159
|
-
990, 556, 556, 556, 556, 556, 556, 556, 556, 556, 556, 552, 278, 333, 333,
|
|
160
|
-
333, 576, 333, 611, 278, 333, 278, 667, 715, 556, 565, 333, 333, 333, 365,
|
|
161
|
-
768, 612, 167, 278, 750, 333, 500, 500, 556, 708, 550, 550, 550, 550, 556,
|
|
162
|
-
556, 500, 722, 722, 722, 722, 722, 500, 447, 500, 500, 500, 500, 556, 500,
|
|
163
|
-
500, 500, 500, 500, 556, 463,
|
|
164
|
-
];
|
|
165
|
-
|
|
166
|
-
// Widths of glyphs in LiberationSans-Regular.ttf.
|
|
167
|
-
const LiberationSansRegularWidths = [
|
|
168
|
-
365, 0, 667, 1000, 1000, 667, 667, 667, 667, 667, 667, 667, 667, 667, 667,
|
|
169
|
-
667, 667, 667, 667, 722, 722, 722, 722, 722, 722, 667, 722, 722, 722, 668,
|
|
170
|
-
667, 667, 667, 667, 667, 667, 667, 667, 667, 723, 667, 667, 784, 722, 838,
|
|
171
|
-
722, 556, 611, 778, 551, 778, 778, 778, 778, 722, 604, 354, 354, 604, 722,
|
|
172
|
-
722, 278, 735, 278, 278, 278, 278, 278, 278, 278, 278, 278, 278, 384, 278,
|
|
173
|
-
500, 500, 667, 667, 667, 556, 556, 668, 556, 556, 556, 556, 833, 833, 722,
|
|
174
|
-
722, 722, 722, 722, 722, 778, 1000, 778, 778, 778, 778, 778, 778, 778, 748,
|
|
175
|
-
752, 778, 774, 778, 778, 778, 667, 798, 722, 835, 778, 722, 722, 722, 722,
|
|
176
|
-
667, 667, 708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 625, 708, 708,
|
|
177
|
-
708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 708,
|
|
178
|
-
708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 667, 667, 667,
|
|
179
|
-
667, 667, 618, 611, 611, 611, 611, 611, 778, 667, 722, 722, 722, 722, 722,
|
|
180
|
-
722, 722, 722, 722, 667, 667, 855, 722, 722, 667, 944, 944, 944, 944, 944,
|
|
181
|
-
667, 650, 667, 667, 667, 667, 667, 611, 611, 611, 611, 611, 556, 556, 556,
|
|
182
|
-
556, 333, 556, 889, 889, 1000, 667, 656, 667, 542, 677, 667, 667, 923, 604,
|
|
183
|
-
719, 719, 583, 656, 833, 722, 778, 719, 667, 722, 611, 635, 760, 667, 740,
|
|
184
|
-
667, 917, 938, 792, 885, 656, 719, 1010, 722, 489, 865, 542, 719, 667, 278,
|
|
185
|
-
278, 500, 1057, 1010, 854, 583, 635, 556, 573, 531, 365, 583, 556, 556, 669,
|
|
186
|
-
458, 559, 559, 438, 583, 688, 552, 556, 542, 556, 500, 458, 500, 823, 500,
|
|
187
|
-
573, 521, 802, 823, 625, 719, 521, 510, 750, 542, 411, 556, 365, 510, 500,
|
|
188
|
-
222, 278, 222, 906, 812, 556, 438, 500, 719, 778, 552, 556, 885, 323, 1073,
|
|
189
|
-
556, 578, 578, 556, 667, 278, 556, 549, 556, 556, 1000, 500, 1000, 1000, 500,
|
|
190
|
-
500, 500, 469, 584, 389, 1015, 556, 556, 278, 260, 575, 708, 334, 334, 278,
|
|
191
|
-
278, 333, 260, 350, 500, 500, 333, 500, 500, 500, 500, 333, 556, 525, 604,
|
|
192
|
-
333, 656, 278, 278, 737, 556, 556, 556, 556, 615, 556, 400, 557, 510, 333,
|
|
193
|
-
333, 549, 729, 708, 556, 333, 278, 556, 556, 556, 556, 556, 556, 556, 556,
|
|
194
|
-
556, 1000, 556, 1000, 556, 556, 556, 446, 446, 584, 583, 600, 556, 556, 556,
|
|
195
|
-
278, 500, 333, 278, 750, 604, 1000, 556, 834, 556, 556, 556, 556, 500, 556,
|
|
196
|
-
556, 556, 556, 611, 333, 222, 222, 294, 294, 324, 324, 316, 328, 398, 285,
|
|
197
|
-
333, 584, 549, 556, 556, 333, 333, 556, 556, 556, 594, 604, 333, 222, 278,
|
|
198
|
-
278, 278, 278, 278, 444, 278, 713, 274, 604, 604, 719, 604, 604, 1052, 222,
|
|
199
|
-
222, 222, 222, 222, 278, 222, 222, 500, 500, 500, 500, 222, 222, 500, 292,
|
|
200
|
-
222, 334, 584, 549, 708, 556, 584, 222, 494, 222, 708, 833, 552, 750, 333,
|
|
201
|
-
584, 188, 576, 584, 500, 750, 556, 556, 604, 556, 556, 556, 333, 549, 556,
|
|
202
|
-
500, 556, 556, 556, 556, 556, 556, 944, 333, 556, 556, 556, 781, 781, 556,
|
|
203
|
-
556, 556, 834, 834, 834, 354, 370, 365, 979, 611, 611, 556, 556, 537, 333,
|
|
204
|
-
333, 494, 889, 278, 1000, 1094, 648, 690, 584, 549, 823, 713, 556, 556, 611,
|
|
205
|
-
355, 333, 333, 333, 222, 222, 222, 222, 191, 333, 333, 549, 333, 333, 737,
|
|
206
|
-
584, 569, 333, 708, 500, 500, 500, 500, 500, 500, 354, 556, 556, 834, 708,
|
|
207
|
-
617, 482, 556, 278, 1021, 531, 556, 713, 917, 278, 395, 278, 375, 278, 556,
|
|
208
|
-
556, 556, 834, 834, 333, 333, 1000, 990, 990, 990, 990, 556, 556, 556, 556,
|
|
209
|
-
556, 556, 556, 556, 556, 556, 552, 278, 333, 333, 333, 576, 333, 611, 278,
|
|
210
|
-
333, 278, 667, 722, 556, 559, 333, 333, 333, 333, 333, 333, 333, 365, 768,
|
|
211
|
-
612, 167, 278, 750, 333, 333, 500, 500, 556, 708, 547, 547, 547, 547, 556,
|
|
212
|
-
556, 500, 722, 722, 722, 722, 722, 500, 448, 500, 500, 500, 500, 556, 500,
|
|
213
|
-
500, 500, 500, 500, 556, 441,
|
|
214
|
-
];
|
|
215
|
-
|
|
216
|
-
export {
|
|
217
|
-
LiberationSansBoldItalicWidths,
|
|
218
|
-
LiberationSansBoldWidths,
|
|
219
|
-
LiberationSansItalicWidths,
|
|
220
|
-
LiberationSansRegularWidths,
|
|
221
|
-
};
|
package/src/core/lzw_stream.js
DELETED
|
@@ -1,150 +0,0 @@
|
|
|
1
|
-
/* Copyright 2012 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 { DecodeStream } from "./decode_stream.js";
|
|
17
|
-
|
|
18
|
-
class LZWStream extends DecodeStream {
|
|
19
|
-
constructor(str, maybeLength, earlyChange) {
|
|
20
|
-
super(maybeLength);
|
|
21
|
-
|
|
22
|
-
this.str = str;
|
|
23
|
-
this.dict = str.dict;
|
|
24
|
-
this.cachedData = 0;
|
|
25
|
-
this.bitsCached = 0;
|
|
26
|
-
|
|
27
|
-
const maxLzwDictionarySize = 4096;
|
|
28
|
-
const lzwState = {
|
|
29
|
-
earlyChange,
|
|
30
|
-
codeLength: 9,
|
|
31
|
-
nextCode: 258,
|
|
32
|
-
dictionaryValues: new Uint8Array(maxLzwDictionarySize),
|
|
33
|
-
dictionaryLengths: new Uint16Array(maxLzwDictionarySize),
|
|
34
|
-
dictionaryPrevCodes: new Uint16Array(maxLzwDictionarySize),
|
|
35
|
-
currentSequence: new Uint8Array(maxLzwDictionarySize),
|
|
36
|
-
currentSequenceLength: 0,
|
|
37
|
-
};
|
|
38
|
-
for (let i = 0; i < 256; ++i) {
|
|
39
|
-
lzwState.dictionaryValues[i] = i;
|
|
40
|
-
lzwState.dictionaryLengths[i] = 1;
|
|
41
|
-
}
|
|
42
|
-
this.lzwState = lzwState;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
readBits(n) {
|
|
46
|
-
let bitsCached = this.bitsCached;
|
|
47
|
-
let cachedData = this.cachedData;
|
|
48
|
-
while (bitsCached < n) {
|
|
49
|
-
const c = this.str.getByte();
|
|
50
|
-
if (c === -1) {
|
|
51
|
-
this.eof = true;
|
|
52
|
-
return null;
|
|
53
|
-
}
|
|
54
|
-
cachedData = (cachedData << 8) | c;
|
|
55
|
-
bitsCached += 8;
|
|
56
|
-
}
|
|
57
|
-
this.bitsCached = bitsCached -= n;
|
|
58
|
-
this.cachedData = cachedData;
|
|
59
|
-
this.lastCode = null;
|
|
60
|
-
return (cachedData >>> bitsCached) & ((1 << n) - 1);
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
readBlock() {
|
|
64
|
-
const blockSize = 512,
|
|
65
|
-
decodedSizeDelta = blockSize;
|
|
66
|
-
let estimatedDecodedSize = blockSize * 2;
|
|
67
|
-
let i, j, q;
|
|
68
|
-
|
|
69
|
-
const lzwState = this.lzwState;
|
|
70
|
-
if (!lzwState) {
|
|
71
|
-
return; // eof was found
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
const earlyChange = lzwState.earlyChange;
|
|
75
|
-
let nextCode = lzwState.nextCode;
|
|
76
|
-
const dictionaryValues = lzwState.dictionaryValues;
|
|
77
|
-
const dictionaryLengths = lzwState.dictionaryLengths;
|
|
78
|
-
const dictionaryPrevCodes = lzwState.dictionaryPrevCodes;
|
|
79
|
-
let codeLength = lzwState.codeLength;
|
|
80
|
-
let prevCode = lzwState.prevCode;
|
|
81
|
-
const currentSequence = lzwState.currentSequence;
|
|
82
|
-
let currentSequenceLength = lzwState.currentSequenceLength;
|
|
83
|
-
|
|
84
|
-
let decodedLength = 0;
|
|
85
|
-
let currentBufferLength = this.bufferLength;
|
|
86
|
-
let buffer = this.ensureBuffer(this.bufferLength + estimatedDecodedSize);
|
|
87
|
-
|
|
88
|
-
for (i = 0; i < blockSize; i++) {
|
|
89
|
-
const code = this.readBits(codeLength);
|
|
90
|
-
const hasPrev = currentSequenceLength > 0;
|
|
91
|
-
if (code < 256) {
|
|
92
|
-
currentSequence[0] = code;
|
|
93
|
-
currentSequenceLength = 1;
|
|
94
|
-
} else if (code >= 258) {
|
|
95
|
-
if (code < nextCode) {
|
|
96
|
-
currentSequenceLength = dictionaryLengths[code];
|
|
97
|
-
for (j = currentSequenceLength - 1, q = code; j >= 0; j--) {
|
|
98
|
-
currentSequence[j] = dictionaryValues[q];
|
|
99
|
-
q = dictionaryPrevCodes[q];
|
|
100
|
-
}
|
|
101
|
-
} else {
|
|
102
|
-
currentSequence[currentSequenceLength++] = currentSequence[0];
|
|
103
|
-
}
|
|
104
|
-
} else if (code === 256) {
|
|
105
|
-
codeLength = 9;
|
|
106
|
-
nextCode = 258;
|
|
107
|
-
currentSequenceLength = 0;
|
|
108
|
-
continue;
|
|
109
|
-
} else {
|
|
110
|
-
this.eof = true;
|
|
111
|
-
delete this.lzwState;
|
|
112
|
-
break;
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
if (hasPrev) {
|
|
116
|
-
dictionaryPrevCodes[nextCode] = prevCode;
|
|
117
|
-
dictionaryLengths[nextCode] = dictionaryLengths[prevCode] + 1;
|
|
118
|
-
dictionaryValues[nextCode] = currentSequence[0];
|
|
119
|
-
nextCode++;
|
|
120
|
-
codeLength =
|
|
121
|
-
(nextCode + earlyChange) & (nextCode + earlyChange - 1)
|
|
122
|
-
? codeLength
|
|
123
|
-
: Math.min(
|
|
124
|
-
Math.log(nextCode + earlyChange) / 0.6931471805599453 + 1,
|
|
125
|
-
12
|
|
126
|
-
) | 0;
|
|
127
|
-
}
|
|
128
|
-
prevCode = code;
|
|
129
|
-
|
|
130
|
-
decodedLength += currentSequenceLength;
|
|
131
|
-
if (estimatedDecodedSize < decodedLength) {
|
|
132
|
-
do {
|
|
133
|
-
estimatedDecodedSize += decodedSizeDelta;
|
|
134
|
-
} while (estimatedDecodedSize < decodedLength);
|
|
135
|
-
buffer = this.ensureBuffer(this.bufferLength + estimatedDecodedSize);
|
|
136
|
-
}
|
|
137
|
-
for (j = 0; j < currentSequenceLength; j++) {
|
|
138
|
-
buffer[currentBufferLength++] = currentSequence[j];
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
lzwState.nextCode = nextCode;
|
|
142
|
-
lzwState.codeLength = codeLength;
|
|
143
|
-
lzwState.prevCode = prevCode;
|
|
144
|
-
lzwState.currentSequenceLength = currentSequenceLength;
|
|
145
|
-
|
|
146
|
-
this.bufferLength = currentBufferLength;
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
export { LZWStream };
|
|
@@ -1,146 +0,0 @@
|
|
|
1
|
-
/* Copyright 2012 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 { SimpleXMLParser } from "./xml_parser.js";
|
|
17
|
-
|
|
18
|
-
class MetadataParser {
|
|
19
|
-
constructor(data) {
|
|
20
|
-
// Ghostscript may produce invalid metadata, so try to repair that first.
|
|
21
|
-
data = this._repair(data);
|
|
22
|
-
|
|
23
|
-
// Convert the string to an XML document.
|
|
24
|
-
const parser = new SimpleXMLParser({ lowerCaseName: true });
|
|
25
|
-
const xmlDocument = parser.parseFromString(data);
|
|
26
|
-
|
|
27
|
-
this._metadataMap = new Map();
|
|
28
|
-
this._data = data;
|
|
29
|
-
|
|
30
|
-
if (xmlDocument) {
|
|
31
|
-
this._parse(xmlDocument);
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
_repair(data) {
|
|
36
|
-
// Start by removing any "junk" before the first tag (see issue 10395).
|
|
37
|
-
return data
|
|
38
|
-
.replace(/^[^<]+/, "")
|
|
39
|
-
.replace(/>\\376\\377([^<]+)/g, function (all, codes) {
|
|
40
|
-
const bytes = codes
|
|
41
|
-
.replace(/\\([0-3])([0-7])([0-7])/g, function (code, d1, d2, d3) {
|
|
42
|
-
return String.fromCharCode(d1 * 64 + d2 * 8 + d3 * 1);
|
|
43
|
-
})
|
|
44
|
-
.replace(/&(amp|apos|gt|lt|quot);/g, function (str, name) {
|
|
45
|
-
switch (name) {
|
|
46
|
-
case "amp":
|
|
47
|
-
return "&";
|
|
48
|
-
case "apos":
|
|
49
|
-
return "'";
|
|
50
|
-
case "gt":
|
|
51
|
-
return ">";
|
|
52
|
-
case "lt":
|
|
53
|
-
return "<";
|
|
54
|
-
case "quot":
|
|
55
|
-
return '"';
|
|
56
|
-
}
|
|
57
|
-
throw new Error(`_repair: ${name} isn't defined.`);
|
|
58
|
-
});
|
|
59
|
-
|
|
60
|
-
const charBuf = [];
|
|
61
|
-
for (let i = 0, ii = bytes.length; i < ii; i += 2) {
|
|
62
|
-
const code = bytes.charCodeAt(i) * 256 + bytes.charCodeAt(i + 1);
|
|
63
|
-
if (
|
|
64
|
-
code >= /* Space = */ 32 &&
|
|
65
|
-
code < /* Delete = */ 127 &&
|
|
66
|
-
code !== /* '<' = */ 60 &&
|
|
67
|
-
code !== /* '>' = */ 62 &&
|
|
68
|
-
code !== /* '&' = */ 38
|
|
69
|
-
) {
|
|
70
|
-
charBuf.push(String.fromCharCode(code));
|
|
71
|
-
} else {
|
|
72
|
-
charBuf.push(
|
|
73
|
-
"&#x" + (0x10000 + code).toString(16).substring(1) + ";"
|
|
74
|
-
);
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
return ">" + charBuf.join("");
|
|
78
|
-
});
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
_getSequence(entry) {
|
|
82
|
-
const name = entry.nodeName;
|
|
83
|
-
if (name !== "rdf:bag" && name !== "rdf:seq" && name !== "rdf:alt") {
|
|
84
|
-
return null;
|
|
85
|
-
}
|
|
86
|
-
return entry.childNodes.filter(node => node.nodeName === "rdf:li");
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
_parseArray(entry) {
|
|
90
|
-
if (!entry.hasChildNodes()) {
|
|
91
|
-
return;
|
|
92
|
-
}
|
|
93
|
-
// Child must be a Bag (unordered array) or a Seq.
|
|
94
|
-
const [seqNode] = entry.childNodes;
|
|
95
|
-
const sequence = this._getSequence(seqNode) || [];
|
|
96
|
-
|
|
97
|
-
this._metadataMap.set(
|
|
98
|
-
entry.nodeName,
|
|
99
|
-
sequence.map(node => node.textContent.trim())
|
|
100
|
-
);
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
_parse(xmlDocument) {
|
|
104
|
-
let rdf = xmlDocument.documentElement;
|
|
105
|
-
|
|
106
|
-
if (rdf.nodeName !== "rdf:rdf") {
|
|
107
|
-
// Wrapped in <xmpmeta>
|
|
108
|
-
rdf = rdf.firstChild;
|
|
109
|
-
while (rdf && rdf.nodeName !== "rdf:rdf") {
|
|
110
|
-
rdf = rdf.nextSibling;
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
if (!rdf || rdf.nodeName !== "rdf:rdf" || !rdf.hasChildNodes()) {
|
|
115
|
-
return;
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
for (const desc of rdf.childNodes) {
|
|
119
|
-
if (desc.nodeName !== "rdf:description") {
|
|
120
|
-
continue;
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
for (const entry of desc.childNodes) {
|
|
124
|
-
const name = entry.nodeName;
|
|
125
|
-
switch (name) {
|
|
126
|
-
case "#text":
|
|
127
|
-
continue;
|
|
128
|
-
case "dc:creator":
|
|
129
|
-
case "dc:subject":
|
|
130
|
-
this._parseArray(entry);
|
|
131
|
-
continue;
|
|
132
|
-
}
|
|
133
|
-
this._metadataMap.set(name, entry.textContent.trim());
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
get serializable() {
|
|
139
|
-
return {
|
|
140
|
-
parsedData: this._metadataMap,
|
|
141
|
-
rawData: this._data,
|
|
142
|
-
};
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
export { MetadataParser };
|