@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.
Files changed (174) hide show
  1. package/README.md +1 -1
  2. package/package.json +33 -18
  3. package/{src/display → pdfjs/dist}/display_utils.js +344 -139
  4. package/{src/display → pdfjs/dist}/fetch_stream.js +115 -97
  5. package/pdfjs/dist/get.js +1857 -0
  6. package/pdfjs/dist/index.js +767 -0
  7. package/pdfjs/dist/l10n_utils.js +140 -0
  8. package/{src/shared → pdfjs/dist}/message_handler.js +243 -259
  9. package/{src/display → pdfjs/dist}/network.js +149 -87
  10. package/{src/display/content_disposition.js → pdfjs/dist/network_utils.js} +167 -55
  11. package/{src/display → pdfjs/dist}/node_stream.js +133 -98
  12. package/pdfjs/dist/pdf.js +12778 -0
  13. package/pdfjs/dist/pdf_link_service.js +638 -0
  14. package/pdfjs/dist/pdf_rendering_queue.js +199 -0
  15. package/pdfjs/dist/pdf_thumbnail_viewer.js +819 -0
  16. package/pdfjs/dist/pdf_viewer.js +3598 -0
  17. package/pdfjs/dist/typeof.js +100 -0
  18. package/pdfjs/dist/ui_utils.js +1033 -0
  19. package/{src/shared → pdfjs/dist}/util.js +301 -287
  20. package/pdfjs/dist/worker.js +62813 -0
  21. package/src/vcf-pdf-viewer.js +77 -27
  22. package/theme/lumo/vcf-pdf-viewer-styles.js +1 -1
  23. package/theme/material/vcf-pdf-viewer.js +2 -2
  24. package/src/core/.eslintrc +0 -13
  25. package/src/core/annotation.js +0 -2948
  26. package/src/core/arithmetic_decoder.js +0 -182
  27. package/src/core/ascii_85_stream.js +0 -98
  28. package/src/core/ascii_hex_stream.js +0 -79
  29. package/src/core/base_stream.js +0 -110
  30. package/src/core/bidi.js +0 -438
  31. package/src/core/calibri_factors.js +0 -308
  32. package/src/core/catalog.js +0 -1459
  33. package/src/core/ccitt.js +0 -1062
  34. package/src/core/ccitt_stream.js +0 -60
  35. package/src/core/cff_font.js +0 -116
  36. package/src/core/cff_parser.js +0 -1949
  37. package/src/core/charsets.js +0 -119
  38. package/src/core/chunked_stream.js +0 -557
  39. package/src/core/cmap.js +0 -1039
  40. package/src/core/colorspace.js +0 -1533
  41. package/src/core/core_utils.js +0 -464
  42. package/src/core/crypto.js +0 -1900
  43. package/src/core/decode_stream.js +0 -170
  44. package/src/core/decrypt_stream.js +0 -59
  45. package/src/core/default_appearance.js +0 -99
  46. package/src/core/document.js +0 -1456
  47. package/src/core/encodings.js +0 -301
  48. package/src/core/evaluator.js +0 -4601
  49. package/src/core/file_spec.js +0 -108
  50. package/src/core/flate_stream.js +0 -402
  51. package/src/core/font_renderer.js +0 -882
  52. package/src/core/fonts.js +0 -3260
  53. package/src/core/fonts_utils.js +0 -221
  54. package/src/core/function.js +0 -1257
  55. package/src/core/glyf.js +0 -706
  56. package/src/core/glyphlist.js +0 -4558
  57. package/src/core/helvetica_factors.js +0 -353
  58. package/src/core/image.js +0 -802
  59. package/src/core/image_utils.js +0 -291
  60. package/src/core/jbig2.js +0 -2572
  61. package/src/core/jbig2_stream.js +0 -73
  62. package/src/core/jpeg_stream.js +0 -105
  63. package/src/core/jpg.js +0 -1416
  64. package/src/core/jpx.js +0 -2343
  65. package/src/core/jpx_stream.js +0 -87
  66. package/src/core/liberationsans_widths.js +0 -221
  67. package/src/core/lzw_stream.js +0 -150
  68. package/src/core/metadata_parser.js +0 -146
  69. package/src/core/metrics.js +0 -2970
  70. package/src/core/murmurhash3.js +0 -139
  71. package/src/core/myriadpro_factors.js +0 -290
  72. package/src/core/name_number_tree.js +0 -153
  73. package/src/core/object_loader.js +0 -149
  74. package/src/core/opentype_file_builder.js +0 -154
  75. package/src/core/operator_list.js +0 -734
  76. package/src/core/parser.js +0 -1416
  77. package/src/core/pattern.js +0 -985
  78. package/src/core/pdf_manager.js +0 -217
  79. package/src/core/predictor_stream.js +0 -238
  80. package/src/core/primitives.js +0 -402
  81. package/src/core/ps_parser.js +0 -272
  82. package/src/core/run_length_stream.js +0 -61
  83. package/src/core/segoeui_factors.js +0 -308
  84. package/src/core/standard_fonts.js +0 -817
  85. package/src/core/stream.js +0 -103
  86. package/src/core/struct_tree.js +0 -335
  87. package/src/core/to_unicode_map.js +0 -103
  88. package/src/core/type1_font.js +0 -421
  89. package/src/core/type1_parser.js +0 -776
  90. package/src/core/unicode.js +0 -1649
  91. package/src/core/worker.js +0 -848
  92. package/src/core/worker_stream.js +0 -135
  93. package/src/core/writer.js +0 -278
  94. package/src/core/xfa/bind.js +0 -652
  95. package/src/core/xfa/builder.js +0 -207
  96. package/src/core/xfa/config.js +0 -1926
  97. package/src/core/xfa/connection_set.js +0 -202
  98. package/src/core/xfa/data.js +0 -82
  99. package/src/core/xfa/datasets.js +0 -76
  100. package/src/core/xfa/factory.js +0 -111
  101. package/src/core/xfa/fonts.js +0 -181
  102. package/src/core/xfa/formcalc_lexer.js +0 -385
  103. package/src/core/xfa/formcalc_parser.js +0 -1340
  104. package/src/core/xfa/html_utils.js +0 -639
  105. package/src/core/xfa/layout.js +0 -383
  106. package/src/core/xfa/locale_set.js +0 -345
  107. package/src/core/xfa/namespaces.js +0 -81
  108. package/src/core/xfa/parser.js +0 -184
  109. package/src/core/xfa/setup.js +0 -38
  110. package/src/core/xfa/signature.js +0 -40
  111. package/src/core/xfa/som.js +0 -338
  112. package/src/core/xfa/stylesheet.js +0 -40
  113. package/src/core/xfa/template.js +0 -6260
  114. package/src/core/xfa/text.js +0 -290
  115. package/src/core/xfa/unknown.js +0 -29
  116. package/src/core/xfa/utils.js +0 -217
  117. package/src/core/xfa/xdp.js +0 -59
  118. package/src/core/xfa/xfa_object.js +0 -1130
  119. package/src/core/xfa/xhtml.js +0 -543
  120. package/src/core/xfa_fonts.js +0 -208
  121. package/src/core/xml_parser.js +0 -507
  122. package/src/core/xref.js +0 -899
  123. package/src/display/annotation_layer.js +0 -2107
  124. package/src/display/annotation_storage.js +0 -113
  125. package/src/display/api.js +0 -3292
  126. package/src/display/base_factory.js +0 -180
  127. package/src/display/canvas.js +0 -2828
  128. package/src/display/font_loader.js +0 -484
  129. package/src/display/metadata.js +0 -41
  130. package/src/display/network_utils.js +0 -100
  131. package/src/display/node_utils.js +0 -83
  132. package/src/display/optional_content_config.js +0 -189
  133. package/src/display/pattern_helper.js +0 -659
  134. package/src/display/svg.js +0 -1709
  135. package/src/display/text_layer.js +0 -847
  136. package/src/display/transport_stream.js +0 -303
  137. package/src/display/worker_options.js +0 -40
  138. package/src/display/xfa_layer.js +0 -204
  139. package/src/doc_helper.js +0 -25
  140. package/src/images/logo.svg +0 -41
  141. package/src/interfaces.js +0 -169
  142. package/src/license_header.js +0 -14
  143. package/src/license_header_libre.js +0 -21
  144. package/src/pdf.image_decoders.js +0 -46
  145. package/src/pdf.js +0 -146
  146. package/src/pdf.sandbox.external.js +0 -181
  147. package/src/pdf.sandbox.js +0 -151
  148. package/src/pdf.scripting.js +0 -25
  149. package/src/pdf.worker.entry.js +0 -19
  150. package/src/pdf.worker.js +0 -23
  151. package/src/scripting_api/aform.js +0 -608
  152. package/src/scripting_api/app.js +0 -621
  153. package/src/scripting_api/color.js +0 -129
  154. package/src/scripting_api/common.js +0 -58
  155. package/src/scripting_api/console.js +0 -38
  156. package/src/scripting_api/constants.js +0 -208
  157. package/src/scripting_api/doc.js +0 -1195
  158. package/src/scripting_api/error.js +0 -23
  159. package/src/scripting_api/event.js +0 -232
  160. package/src/scripting_api/field.js +0 -620
  161. package/src/scripting_api/fullscreen.js +0 -145
  162. package/src/scripting_api/initialization.js +0 -223
  163. package/src/scripting_api/pdf_object.js +0 -24
  164. package/src/scripting_api/print_params.js +0 -146
  165. package/src/scripting_api/proxy.js +0 -139
  166. package/src/scripting_api/thermometer.js +0 -69
  167. package/src/scripting_api/util.js +0 -581
  168. package/src/shared/.eslintrc +0 -13
  169. package/src/shared/cffStandardStrings.js +0 -311
  170. package/src/shared/compatibility.js +0 -114
  171. package/src/shared/fonts_utils.js +0 -429
  172. package/src/shared/is_node.js +0 -27
  173. package/src/shared/scripting_utils.js +0 -85
  174. package/src/worker_loader.js +0 -32
package/src/core/cmap.js DELETED
@@ -1,1039 +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 {
17
- CMapCompressionType,
18
- FormatError,
19
- isString,
20
- unreachable,
21
- warn,
22
- } from "../shared/util.js";
23
- import { isCmd, isEOF, isName, isStream } from "./primitives.js";
24
- import { Lexer } from "./parser.js";
25
- import { MissingDataException } from "./core_utils.js";
26
- import { Stream } from "./stream.js";
27
-
28
- const BUILT_IN_CMAPS = [
29
- // << Start unicode maps.
30
- "Adobe-GB1-UCS2",
31
- "Adobe-CNS1-UCS2",
32
- "Adobe-Japan1-UCS2",
33
- "Adobe-Korea1-UCS2",
34
- // >> End unicode maps.
35
- "78-EUC-H",
36
- "78-EUC-V",
37
- "78-H",
38
- "78-RKSJ-H",
39
- "78-RKSJ-V",
40
- "78-V",
41
- "78ms-RKSJ-H",
42
- "78ms-RKSJ-V",
43
- "83pv-RKSJ-H",
44
- "90ms-RKSJ-H",
45
- "90ms-RKSJ-V",
46
- "90msp-RKSJ-H",
47
- "90msp-RKSJ-V",
48
- "90pv-RKSJ-H",
49
- "90pv-RKSJ-V",
50
- "Add-H",
51
- "Add-RKSJ-H",
52
- "Add-RKSJ-V",
53
- "Add-V",
54
- "Adobe-CNS1-0",
55
- "Adobe-CNS1-1",
56
- "Adobe-CNS1-2",
57
- "Adobe-CNS1-3",
58
- "Adobe-CNS1-4",
59
- "Adobe-CNS1-5",
60
- "Adobe-CNS1-6",
61
- "Adobe-GB1-0",
62
- "Adobe-GB1-1",
63
- "Adobe-GB1-2",
64
- "Adobe-GB1-3",
65
- "Adobe-GB1-4",
66
- "Adobe-GB1-5",
67
- "Adobe-Japan1-0",
68
- "Adobe-Japan1-1",
69
- "Adobe-Japan1-2",
70
- "Adobe-Japan1-3",
71
- "Adobe-Japan1-4",
72
- "Adobe-Japan1-5",
73
- "Adobe-Japan1-6",
74
- "Adobe-Korea1-0",
75
- "Adobe-Korea1-1",
76
- "Adobe-Korea1-2",
77
- "B5-H",
78
- "B5-V",
79
- "B5pc-H",
80
- "B5pc-V",
81
- "CNS-EUC-H",
82
- "CNS-EUC-V",
83
- "CNS1-H",
84
- "CNS1-V",
85
- "CNS2-H",
86
- "CNS2-V",
87
- "ETHK-B5-H",
88
- "ETHK-B5-V",
89
- "ETen-B5-H",
90
- "ETen-B5-V",
91
- "ETenms-B5-H",
92
- "ETenms-B5-V",
93
- "EUC-H",
94
- "EUC-V",
95
- "Ext-H",
96
- "Ext-RKSJ-H",
97
- "Ext-RKSJ-V",
98
- "Ext-V",
99
- "GB-EUC-H",
100
- "GB-EUC-V",
101
- "GB-H",
102
- "GB-V",
103
- "GBK-EUC-H",
104
- "GBK-EUC-V",
105
- "GBK2K-H",
106
- "GBK2K-V",
107
- "GBKp-EUC-H",
108
- "GBKp-EUC-V",
109
- "GBT-EUC-H",
110
- "GBT-EUC-V",
111
- "GBT-H",
112
- "GBT-V",
113
- "GBTpc-EUC-H",
114
- "GBTpc-EUC-V",
115
- "GBpc-EUC-H",
116
- "GBpc-EUC-V",
117
- "H",
118
- "HKdla-B5-H",
119
- "HKdla-B5-V",
120
- "HKdlb-B5-H",
121
- "HKdlb-B5-V",
122
- "HKgccs-B5-H",
123
- "HKgccs-B5-V",
124
- "HKm314-B5-H",
125
- "HKm314-B5-V",
126
- "HKm471-B5-H",
127
- "HKm471-B5-V",
128
- "HKscs-B5-H",
129
- "HKscs-B5-V",
130
- "Hankaku",
131
- "Hiragana",
132
- "KSC-EUC-H",
133
- "KSC-EUC-V",
134
- "KSC-H",
135
- "KSC-Johab-H",
136
- "KSC-Johab-V",
137
- "KSC-V",
138
- "KSCms-UHC-H",
139
- "KSCms-UHC-HW-H",
140
- "KSCms-UHC-HW-V",
141
- "KSCms-UHC-V",
142
- "KSCpc-EUC-H",
143
- "KSCpc-EUC-V",
144
- "Katakana",
145
- "NWP-H",
146
- "NWP-V",
147
- "RKSJ-H",
148
- "RKSJ-V",
149
- "Roman",
150
- "UniCNS-UCS2-H",
151
- "UniCNS-UCS2-V",
152
- "UniCNS-UTF16-H",
153
- "UniCNS-UTF16-V",
154
- "UniCNS-UTF32-H",
155
- "UniCNS-UTF32-V",
156
- "UniCNS-UTF8-H",
157
- "UniCNS-UTF8-V",
158
- "UniGB-UCS2-H",
159
- "UniGB-UCS2-V",
160
- "UniGB-UTF16-H",
161
- "UniGB-UTF16-V",
162
- "UniGB-UTF32-H",
163
- "UniGB-UTF32-V",
164
- "UniGB-UTF8-H",
165
- "UniGB-UTF8-V",
166
- "UniJIS-UCS2-H",
167
- "UniJIS-UCS2-HW-H",
168
- "UniJIS-UCS2-HW-V",
169
- "UniJIS-UCS2-V",
170
- "UniJIS-UTF16-H",
171
- "UniJIS-UTF16-V",
172
- "UniJIS-UTF32-H",
173
- "UniJIS-UTF32-V",
174
- "UniJIS-UTF8-H",
175
- "UniJIS-UTF8-V",
176
- "UniJIS2004-UTF16-H",
177
- "UniJIS2004-UTF16-V",
178
- "UniJIS2004-UTF32-H",
179
- "UniJIS2004-UTF32-V",
180
- "UniJIS2004-UTF8-H",
181
- "UniJIS2004-UTF8-V",
182
- "UniJISPro-UCS2-HW-V",
183
- "UniJISPro-UCS2-V",
184
- "UniJISPro-UTF8-V",
185
- "UniJISX0213-UTF32-H",
186
- "UniJISX0213-UTF32-V",
187
- "UniJISX02132004-UTF32-H",
188
- "UniJISX02132004-UTF32-V",
189
- "UniKS-UCS2-H",
190
- "UniKS-UCS2-V",
191
- "UniKS-UTF16-H",
192
- "UniKS-UTF16-V",
193
- "UniKS-UTF32-H",
194
- "UniKS-UTF32-V",
195
- "UniKS-UTF8-H",
196
- "UniKS-UTF8-V",
197
- "V",
198
- "WP-Symbol",
199
- ];
200
-
201
- // Heuristic to avoid hanging the worker-thread for CMap data with ridiculously
202
- // large ranges, such as e.g. 0xFFFFFFFF (fixes issue11922_reduced.pdf).
203
- const MAX_MAP_RANGE = 2 ** 24 - 1; // = 0xFFFFFF
204
-
205
- // CMap, not to be confused with TrueType's cmap.
206
- class CMap {
207
- constructor(builtInCMap = false) {
208
- // Codespace ranges are stored as follows:
209
- // [[1BytePairs], [2BytePairs], [3BytePairs], [4BytePairs]]
210
- // where nBytePairs are ranges e.g. [low1, high1, low2, high2, ...]
211
- this.codespaceRanges = [[], [], [], []];
212
- this.numCodespaceRanges = 0;
213
- // Map entries have one of two forms.
214
- // - cid chars are 16-bit unsigned integers, stored as integers.
215
- // - bf chars are variable-length byte sequences, stored as strings, with
216
- // one byte per character.
217
- this._map = [];
218
- this.name = "";
219
- this.vertical = false;
220
- this.useCMap = null;
221
- this.builtInCMap = builtInCMap;
222
- }
223
-
224
- addCodespaceRange(n, low, high) {
225
- this.codespaceRanges[n - 1].push(low, high);
226
- this.numCodespaceRanges++;
227
- }
228
-
229
- mapCidRange(low, high, dstLow) {
230
- if (high - low > MAX_MAP_RANGE) {
231
- throw new Error("mapCidRange - ignoring data above MAX_MAP_RANGE.");
232
- }
233
- while (low <= high) {
234
- this._map[low++] = dstLow++;
235
- }
236
- }
237
-
238
- mapBfRange(low, high, dstLow) {
239
- if (high - low > MAX_MAP_RANGE) {
240
- throw new Error("mapBfRange - ignoring data above MAX_MAP_RANGE.");
241
- }
242
- const lastByte = dstLow.length - 1;
243
- while (low <= high) {
244
- this._map[low++] = dstLow;
245
- // Only the last byte has to be incremented.
246
- dstLow =
247
- dstLow.substring(0, lastByte) +
248
- String.fromCharCode(dstLow.charCodeAt(lastByte) + 1);
249
- }
250
- }
251
-
252
- mapBfRangeToArray(low, high, array) {
253
- if (high - low > MAX_MAP_RANGE) {
254
- throw new Error("mapBfRangeToArray - ignoring data above MAX_MAP_RANGE.");
255
- }
256
- const ii = array.length;
257
- let i = 0;
258
- while (low <= high && i < ii) {
259
- this._map[low] = array[i++];
260
- ++low;
261
- }
262
- }
263
-
264
- // This is used for both bf and cid chars.
265
- mapOne(src, dst) {
266
- this._map[src] = dst;
267
- }
268
-
269
- lookup(code) {
270
- return this._map[code];
271
- }
272
-
273
- contains(code) {
274
- return this._map[code] !== undefined;
275
- }
276
-
277
- forEach(callback) {
278
- // Most maps have fewer than 65536 entries, and for those we use normal
279
- // array iteration. But really sparse tables are possible -- e.g. with
280
- // indices in the *billions*. For such tables we use for..in, which isn't
281
- // ideal because it stringifies the indices for all present elements, but
282
- // it does avoid iterating over every undefined entry.
283
- const map = this._map;
284
- const length = map.length;
285
- if (length <= 0x10000) {
286
- for (let i = 0; i < length; i++) {
287
- if (map[i] !== undefined) {
288
- callback(i, map[i]);
289
- }
290
- }
291
- } else {
292
- for (const i in map) {
293
- callback(i, map[i]);
294
- }
295
- }
296
- }
297
-
298
- charCodeOf(value) {
299
- // `Array.prototype.indexOf` is *extremely* inefficient for arrays which
300
- // are both very sparse and very large (see issue8372.pdf).
301
- const map = this._map;
302
- if (map.length <= 0x10000) {
303
- return map.indexOf(value);
304
- }
305
- for (const charCode in map) {
306
- if (map[charCode] === value) {
307
- return charCode | 0;
308
- }
309
- }
310
- return -1;
311
- }
312
-
313
- getMap() {
314
- return this._map;
315
- }
316
-
317
- readCharCode(str, offset, out) {
318
- let c = 0;
319
- const codespaceRanges = this.codespaceRanges;
320
- // 9.7.6.2 CMap Mapping
321
- // The code length is at most 4.
322
- for (let n = 0, nn = codespaceRanges.length; n < nn; n++) {
323
- c = ((c << 8) | str.charCodeAt(offset + n)) >>> 0;
324
- // Check each codespace range to see if it falls within.
325
- const codespaceRange = codespaceRanges[n];
326
- for (let k = 0, kk = codespaceRange.length; k < kk; ) {
327
- const low = codespaceRange[k++];
328
- const high = codespaceRange[k++];
329
- if (c >= low && c <= high) {
330
- out.charcode = c;
331
- out.length = n + 1;
332
- return;
333
- }
334
- }
335
- }
336
- out.charcode = 0;
337
- out.length = 1;
338
- }
339
-
340
- getCharCodeLength(charCode) {
341
- const codespaceRanges = this.codespaceRanges;
342
- for (let n = 0, nn = codespaceRanges.length; n < nn; n++) {
343
- // Check each codespace range to see if it falls within.
344
- const codespaceRange = codespaceRanges[n];
345
- for (let k = 0, kk = codespaceRange.length; k < kk; ) {
346
- const low = codespaceRange[k++];
347
- const high = codespaceRange[k++];
348
- if (charCode >= low && charCode <= high) {
349
- return n + 1;
350
- }
351
- }
352
- }
353
- return 1;
354
- }
355
-
356
- get length() {
357
- return this._map.length;
358
- }
359
-
360
- get isIdentityCMap() {
361
- if (!(this.name === "Identity-H" || this.name === "Identity-V")) {
362
- return false;
363
- }
364
- if (this._map.length !== 0x10000) {
365
- return false;
366
- }
367
- for (let i = 0; i < 0x10000; i++) {
368
- if (this._map[i] !== i) {
369
- return false;
370
- }
371
- }
372
- return true;
373
- }
374
- }
375
-
376
- // A special case of CMap, where the _map array implicitly has a length of
377
- // 65536 and each element is equal to its index.
378
- class IdentityCMap extends CMap {
379
- constructor(vertical, n) {
380
- super();
381
-
382
- this.vertical = vertical;
383
- this.addCodespaceRange(n, 0, 0xffff);
384
- }
385
-
386
- mapCidRange(low, high, dstLow) {
387
- unreachable("should not call mapCidRange");
388
- }
389
-
390
- mapBfRange(low, high, dstLow) {
391
- unreachable("should not call mapBfRange");
392
- }
393
-
394
- mapBfRangeToArray(low, high, array) {
395
- unreachable("should not call mapBfRangeToArray");
396
- }
397
-
398
- mapOne(src, dst) {
399
- unreachable("should not call mapCidOne");
400
- }
401
-
402
- lookup(code) {
403
- return Number.isInteger(code) && code <= 0xffff ? code : undefined;
404
- }
405
-
406
- contains(code) {
407
- return Number.isInteger(code) && code <= 0xffff;
408
- }
409
-
410
- forEach(callback) {
411
- for (let i = 0; i <= 0xffff; i++) {
412
- callback(i, i);
413
- }
414
- }
415
-
416
- charCodeOf(value) {
417
- return Number.isInteger(value) && value <= 0xffff ? value : -1;
418
- }
419
-
420
- getMap() {
421
- // Sometimes identity maps must be instantiated, but it's rare.
422
- const map = new Array(0x10000);
423
- for (let i = 0; i <= 0xffff; i++) {
424
- map[i] = i;
425
- }
426
- return map;
427
- }
428
-
429
- get length() {
430
- return 0x10000;
431
- }
432
-
433
- // eslint-disable-next-line getter-return
434
- get isIdentityCMap() {
435
- unreachable("should not access .isIdentityCMap");
436
- }
437
- }
438
-
439
- const BinaryCMapReader = (function BinaryCMapReaderClosure() {
440
- function hexToInt(a, size) {
441
- let n = 0;
442
- for (let i = 0; i <= size; i++) {
443
- n = (n << 8) | a[i];
444
- }
445
- return n >>> 0;
446
- }
447
-
448
- function hexToStr(a, size) {
449
- // This code is hot. Special-case some common values to avoid creating an
450
- // object with subarray().
451
- if (size === 1) {
452
- return String.fromCharCode(a[0], a[1]);
453
- }
454
- if (size === 3) {
455
- return String.fromCharCode(a[0], a[1], a[2], a[3]);
456
- }
457
- return String.fromCharCode.apply(null, a.subarray(0, size + 1));
458
- }
459
-
460
- function addHex(a, b, size) {
461
- let c = 0;
462
- for (let i = size; i >= 0; i--) {
463
- c += a[i] + b[i];
464
- a[i] = c & 255;
465
- c >>= 8;
466
- }
467
- }
468
-
469
- function incHex(a, size) {
470
- let c = 1;
471
- for (let i = size; i >= 0 && c > 0; i--) {
472
- c += a[i];
473
- a[i] = c & 255;
474
- c >>= 8;
475
- }
476
- }
477
-
478
- const MAX_NUM_SIZE = 16;
479
- const MAX_ENCODED_NUM_SIZE = 19; // ceil(MAX_NUM_SIZE * 7 / 8)
480
-
481
- class BinaryCMapStream {
482
- constructor(data) {
483
- this.buffer = data;
484
- this.pos = 0;
485
- this.end = data.length;
486
- this.tmpBuf = new Uint8Array(MAX_ENCODED_NUM_SIZE);
487
- }
488
-
489
- readByte() {
490
- if (this.pos >= this.end) {
491
- return -1;
492
- }
493
- return this.buffer[this.pos++];
494
- }
495
-
496
- readNumber() {
497
- let n = 0;
498
- let last;
499
- do {
500
- const b = this.readByte();
501
- if (b < 0) {
502
- throw new FormatError("unexpected EOF in bcmap");
503
- }
504
- last = !(b & 0x80);
505
- n = (n << 7) | (b & 0x7f);
506
- } while (!last);
507
- return n;
508
- }
509
-
510
- readSigned() {
511
- const n = this.readNumber();
512
- return n & 1 ? ~(n >>> 1) : n >>> 1;
513
- }
514
-
515
- readHex(num, size) {
516
- num.set(this.buffer.subarray(this.pos, this.pos + size + 1));
517
- this.pos += size + 1;
518
- }
519
-
520
- readHexNumber(num, size) {
521
- let last;
522
- const stack = this.tmpBuf;
523
- let sp = 0;
524
- do {
525
- const b = this.readByte();
526
- if (b < 0) {
527
- throw new FormatError("unexpected EOF in bcmap");
528
- }
529
- last = !(b & 0x80);
530
- stack[sp++] = b & 0x7f;
531
- } while (!last);
532
- let i = size,
533
- buffer = 0,
534
- bufferSize = 0;
535
- while (i >= 0) {
536
- while (bufferSize < 8 && stack.length > 0) {
537
- buffer |= stack[--sp] << bufferSize;
538
- bufferSize += 7;
539
- }
540
- num[i] = buffer & 255;
541
- i--;
542
- buffer >>= 8;
543
- bufferSize -= 8;
544
- }
545
- }
546
-
547
- readHexSigned(num, size) {
548
- this.readHexNumber(num, size);
549
- const sign = num[size] & 1 ? 255 : 0;
550
- let c = 0;
551
- for (let i = 0; i <= size; i++) {
552
- c = ((c & 1) << 8) | num[i];
553
- num[i] = (c >> 1) ^ sign;
554
- }
555
- }
556
-
557
- readString() {
558
- const len = this.readNumber();
559
- let s = "";
560
- for (let i = 0; i < len; i++) {
561
- s += String.fromCharCode(this.readNumber());
562
- }
563
- return s;
564
- }
565
- }
566
-
567
- // eslint-disable-next-line no-shadow
568
- class BinaryCMapReader {
569
- async process(data, cMap, extend) {
570
- const stream = new BinaryCMapStream(data);
571
- const header = stream.readByte();
572
- cMap.vertical = !!(header & 1);
573
-
574
- let useCMap = null;
575
- const start = new Uint8Array(MAX_NUM_SIZE);
576
- const end = new Uint8Array(MAX_NUM_SIZE);
577
- const char = new Uint8Array(MAX_NUM_SIZE);
578
- const charCode = new Uint8Array(MAX_NUM_SIZE);
579
- const tmp = new Uint8Array(MAX_NUM_SIZE);
580
- let code;
581
-
582
- let b;
583
- while ((b = stream.readByte()) >= 0) {
584
- const type = b >> 5;
585
- if (type === 7) {
586
- // metadata, e.g. comment or usecmap
587
- switch (b & 0x1f) {
588
- case 0:
589
- stream.readString(); // skipping comment
590
- break;
591
- case 1:
592
- useCMap = stream.readString();
593
- break;
594
- }
595
- continue;
596
- }
597
- const sequence = !!(b & 0x10);
598
- const dataSize = b & 15;
599
-
600
- if (dataSize + 1 > MAX_NUM_SIZE) {
601
- throw new Error("BinaryCMapReader.process: Invalid dataSize.");
602
- }
603
-
604
- const ucs2DataSize = 1;
605
- const subitemsCount = stream.readNumber();
606
- switch (type) {
607
- case 0: // codespacerange
608
- stream.readHex(start, dataSize);
609
- stream.readHexNumber(end, dataSize);
610
- addHex(end, start, dataSize);
611
- cMap.addCodespaceRange(
612
- dataSize + 1,
613
- hexToInt(start, dataSize),
614
- hexToInt(end, dataSize)
615
- );
616
- for (let i = 1; i < subitemsCount; i++) {
617
- incHex(end, dataSize);
618
- stream.readHexNumber(start, dataSize);
619
- addHex(start, end, dataSize);
620
- stream.readHexNumber(end, dataSize);
621
- addHex(end, start, dataSize);
622
- cMap.addCodespaceRange(
623
- dataSize + 1,
624
- hexToInt(start, dataSize),
625
- hexToInt(end, dataSize)
626
- );
627
- }
628
- break;
629
- case 1: // notdefrange
630
- stream.readHex(start, dataSize);
631
- stream.readHexNumber(end, dataSize);
632
- addHex(end, start, dataSize);
633
- stream.readNumber(); // code
634
- // undefined range, skipping
635
- for (let i = 1; i < subitemsCount; i++) {
636
- incHex(end, dataSize);
637
- stream.readHexNumber(start, dataSize);
638
- addHex(start, end, dataSize);
639
- stream.readHexNumber(end, dataSize);
640
- addHex(end, start, dataSize);
641
- stream.readNumber(); // code
642
- // nop
643
- }
644
- break;
645
- case 2: // cidchar
646
- stream.readHex(char, dataSize);
647
- code = stream.readNumber();
648
- cMap.mapOne(hexToInt(char, dataSize), code);
649
- for (let i = 1; i < subitemsCount; i++) {
650
- incHex(char, dataSize);
651
- if (!sequence) {
652
- stream.readHexNumber(tmp, dataSize);
653
- addHex(char, tmp, dataSize);
654
- }
655
- code = stream.readSigned() + (code + 1);
656
- cMap.mapOne(hexToInt(char, dataSize), code);
657
- }
658
- break;
659
- case 3: // cidrange
660
- stream.readHex(start, dataSize);
661
- stream.readHexNumber(end, dataSize);
662
- addHex(end, start, dataSize);
663
- code = stream.readNumber();
664
- cMap.mapCidRange(
665
- hexToInt(start, dataSize),
666
- hexToInt(end, dataSize),
667
- code
668
- );
669
- for (let i = 1; i < subitemsCount; i++) {
670
- incHex(end, dataSize);
671
- if (!sequence) {
672
- stream.readHexNumber(start, dataSize);
673
- addHex(start, end, dataSize);
674
- } else {
675
- start.set(end);
676
- }
677
- stream.readHexNumber(end, dataSize);
678
- addHex(end, start, dataSize);
679
- code = stream.readNumber();
680
- cMap.mapCidRange(
681
- hexToInt(start, dataSize),
682
- hexToInt(end, dataSize),
683
- code
684
- );
685
- }
686
- break;
687
- case 4: // bfchar
688
- stream.readHex(char, ucs2DataSize);
689
- stream.readHex(charCode, dataSize);
690
- cMap.mapOne(
691
- hexToInt(char, ucs2DataSize),
692
- hexToStr(charCode, dataSize)
693
- );
694
- for (let i = 1; i < subitemsCount; i++) {
695
- incHex(char, ucs2DataSize);
696
- if (!sequence) {
697
- stream.readHexNumber(tmp, ucs2DataSize);
698
- addHex(char, tmp, ucs2DataSize);
699
- }
700
- incHex(charCode, dataSize);
701
- stream.readHexSigned(tmp, dataSize);
702
- addHex(charCode, tmp, dataSize);
703
- cMap.mapOne(
704
- hexToInt(char, ucs2DataSize),
705
- hexToStr(charCode, dataSize)
706
- );
707
- }
708
- break;
709
- case 5: // bfrange
710
- stream.readHex(start, ucs2DataSize);
711
- stream.readHexNumber(end, ucs2DataSize);
712
- addHex(end, start, ucs2DataSize);
713
- stream.readHex(charCode, dataSize);
714
- cMap.mapBfRange(
715
- hexToInt(start, ucs2DataSize),
716
- hexToInt(end, ucs2DataSize),
717
- hexToStr(charCode, dataSize)
718
- );
719
- for (let i = 1; i < subitemsCount; i++) {
720
- incHex(end, ucs2DataSize);
721
- if (!sequence) {
722
- stream.readHexNumber(start, ucs2DataSize);
723
- addHex(start, end, ucs2DataSize);
724
- } else {
725
- start.set(end);
726
- }
727
- stream.readHexNumber(end, ucs2DataSize);
728
- addHex(end, start, ucs2DataSize);
729
- stream.readHex(charCode, dataSize);
730
- cMap.mapBfRange(
731
- hexToInt(start, ucs2DataSize),
732
- hexToInt(end, ucs2DataSize),
733
- hexToStr(charCode, dataSize)
734
- );
735
- }
736
- break;
737
- default:
738
- throw new Error(`BinaryCMapReader.process - unknown type: ${type}`);
739
- }
740
- }
741
-
742
- if (useCMap) {
743
- return extend(useCMap);
744
- }
745
- return cMap;
746
- }
747
- }
748
-
749
- return BinaryCMapReader;
750
- })();
751
-
752
- const CMapFactory = (function CMapFactoryClosure() {
753
- function strToInt(str) {
754
- let a = 0;
755
- for (let i = 0; i < str.length; i++) {
756
- a = (a << 8) | str.charCodeAt(i);
757
- }
758
- return a >>> 0;
759
- }
760
-
761
- function expectString(obj) {
762
- if (!isString(obj)) {
763
- throw new FormatError("Malformed CMap: expected string.");
764
- }
765
- }
766
-
767
- function expectInt(obj) {
768
- if (!Number.isInteger(obj)) {
769
- throw new FormatError("Malformed CMap: expected int.");
770
- }
771
- }
772
-
773
- function parseBfChar(cMap, lexer) {
774
- while (true) {
775
- let obj = lexer.getObj();
776
- if (isEOF(obj)) {
777
- break;
778
- }
779
- if (isCmd(obj, "endbfchar")) {
780
- return;
781
- }
782
- expectString(obj);
783
- const src = strToInt(obj);
784
- obj = lexer.getObj();
785
- // TODO are /dstName used?
786
- expectString(obj);
787
- const dst = obj;
788
- cMap.mapOne(src, dst);
789
- }
790
- }
791
-
792
- function parseBfRange(cMap, lexer) {
793
- while (true) {
794
- let obj = lexer.getObj();
795
- if (isEOF(obj)) {
796
- break;
797
- }
798
- if (isCmd(obj, "endbfrange")) {
799
- return;
800
- }
801
- expectString(obj);
802
- const low = strToInt(obj);
803
- obj = lexer.getObj();
804
- expectString(obj);
805
- const high = strToInt(obj);
806
- obj = lexer.getObj();
807
- if (Number.isInteger(obj) || isString(obj)) {
808
- const dstLow = Number.isInteger(obj) ? String.fromCharCode(obj) : obj;
809
- cMap.mapBfRange(low, high, dstLow);
810
- } else if (isCmd(obj, "[")) {
811
- obj = lexer.getObj();
812
- const array = [];
813
- while (!isCmd(obj, "]") && !isEOF(obj)) {
814
- array.push(obj);
815
- obj = lexer.getObj();
816
- }
817
- cMap.mapBfRangeToArray(low, high, array);
818
- } else {
819
- break;
820
- }
821
- }
822
- throw new FormatError("Invalid bf range.");
823
- }
824
-
825
- function parseCidChar(cMap, lexer) {
826
- while (true) {
827
- let obj = lexer.getObj();
828
- if (isEOF(obj)) {
829
- break;
830
- }
831
- if (isCmd(obj, "endcidchar")) {
832
- return;
833
- }
834
- expectString(obj);
835
- const src = strToInt(obj);
836
- obj = lexer.getObj();
837
- expectInt(obj);
838
- const dst = obj;
839
- cMap.mapOne(src, dst);
840
- }
841
- }
842
-
843
- function parseCidRange(cMap, lexer) {
844
- while (true) {
845
- let obj = lexer.getObj();
846
- if (isEOF(obj)) {
847
- break;
848
- }
849
- if (isCmd(obj, "endcidrange")) {
850
- return;
851
- }
852
- expectString(obj);
853
- const low = strToInt(obj);
854
- obj = lexer.getObj();
855
- expectString(obj);
856
- const high = strToInt(obj);
857
- obj = lexer.getObj();
858
- expectInt(obj);
859
- const dstLow = obj;
860
- cMap.mapCidRange(low, high, dstLow);
861
- }
862
- }
863
-
864
- function parseCodespaceRange(cMap, lexer) {
865
- while (true) {
866
- let obj = lexer.getObj();
867
- if (isEOF(obj)) {
868
- break;
869
- }
870
- if (isCmd(obj, "endcodespacerange")) {
871
- return;
872
- }
873
- if (!isString(obj)) {
874
- break;
875
- }
876
- const low = strToInt(obj);
877
- obj = lexer.getObj();
878
- if (!isString(obj)) {
879
- break;
880
- }
881
- const high = strToInt(obj);
882
- cMap.addCodespaceRange(obj.length, low, high);
883
- }
884
- throw new FormatError("Invalid codespace range.");
885
- }
886
-
887
- function parseWMode(cMap, lexer) {
888
- const obj = lexer.getObj();
889
- if (Number.isInteger(obj)) {
890
- cMap.vertical = !!obj;
891
- }
892
- }
893
-
894
- function parseCMapName(cMap, lexer) {
895
- const obj = lexer.getObj();
896
- if (isName(obj) && isString(obj.name)) {
897
- cMap.name = obj.name;
898
- }
899
- }
900
-
901
- async function parseCMap(cMap, lexer, fetchBuiltInCMap, useCMap) {
902
- let previous, embeddedUseCMap;
903
- objLoop: while (true) {
904
- try {
905
- const obj = lexer.getObj();
906
- if (isEOF(obj)) {
907
- break;
908
- } else if (isName(obj)) {
909
- if (obj.name === "WMode") {
910
- parseWMode(cMap, lexer);
911
- } else if (obj.name === "CMapName") {
912
- parseCMapName(cMap, lexer);
913
- }
914
- previous = obj;
915
- } else if (isCmd(obj)) {
916
- switch (obj.cmd) {
917
- case "endcmap":
918
- break objLoop;
919
- case "usecmap":
920
- if (isName(previous)) {
921
- embeddedUseCMap = previous.name;
922
- }
923
- break;
924
- case "begincodespacerange":
925
- parseCodespaceRange(cMap, lexer);
926
- break;
927
- case "beginbfchar":
928
- parseBfChar(cMap, lexer);
929
- break;
930
- case "begincidchar":
931
- parseCidChar(cMap, lexer);
932
- break;
933
- case "beginbfrange":
934
- parseBfRange(cMap, lexer);
935
- break;
936
- case "begincidrange":
937
- parseCidRange(cMap, lexer);
938
- break;
939
- }
940
- }
941
- } catch (ex) {
942
- if (ex instanceof MissingDataException) {
943
- throw ex;
944
- }
945
- warn("Invalid cMap data: " + ex);
946
- continue;
947
- }
948
- }
949
-
950
- if (!useCMap && embeddedUseCMap) {
951
- // Load the useCMap definition from the file only if there wasn't one
952
- // specified.
953
- useCMap = embeddedUseCMap;
954
- }
955
- if (useCMap) {
956
- return extendCMap(cMap, fetchBuiltInCMap, useCMap);
957
- }
958
- return cMap;
959
- }
960
-
961
- async function extendCMap(cMap, fetchBuiltInCMap, useCMap) {
962
- cMap.useCMap = await createBuiltInCMap(useCMap, fetchBuiltInCMap);
963
- // If there aren't any code space ranges defined clone all the parent ones
964
- // into this cMap.
965
- if (cMap.numCodespaceRanges === 0) {
966
- const useCodespaceRanges = cMap.useCMap.codespaceRanges;
967
- for (let i = 0; i < useCodespaceRanges.length; i++) {
968
- cMap.codespaceRanges[i] = useCodespaceRanges[i].slice();
969
- }
970
- cMap.numCodespaceRanges = cMap.useCMap.numCodespaceRanges;
971
- }
972
- // Merge the map into the current one, making sure not to override
973
- // any previously defined entries.
974
- cMap.useCMap.forEach(function (key, value) {
975
- if (!cMap.contains(key)) {
976
- cMap.mapOne(key, cMap.useCMap.lookup(key));
977
- }
978
- });
979
-
980
- return cMap;
981
- }
982
-
983
- async function createBuiltInCMap(name, fetchBuiltInCMap) {
984
- if (name === "Identity-H") {
985
- return new IdentityCMap(false, 2);
986
- } else if (name === "Identity-V") {
987
- return new IdentityCMap(true, 2);
988
- }
989
- if (!BUILT_IN_CMAPS.includes(name)) {
990
- throw new Error("Unknown CMap name: " + name);
991
- }
992
- if (!fetchBuiltInCMap) {
993
- throw new Error("Built-in CMap parameters are not provided.");
994
- }
995
-
996
- const { cMapData, compressionType } = await fetchBuiltInCMap(name);
997
- const cMap = new CMap(true);
998
-
999
- if (compressionType === CMapCompressionType.BINARY) {
1000
- return new BinaryCMapReader().process(cMapData, cMap, useCMap => {
1001
- return extendCMap(cMap, fetchBuiltInCMap, useCMap);
1002
- });
1003
- }
1004
- if (compressionType === CMapCompressionType.NONE) {
1005
- const lexer = new Lexer(new Stream(cMapData));
1006
- return parseCMap(cMap, lexer, fetchBuiltInCMap, null);
1007
- }
1008
- throw new Error(
1009
- "TODO: Only BINARY/NONE CMap compression is currently supported."
1010
- );
1011
- }
1012
-
1013
- return {
1014
- async create(params) {
1015
- const encoding = params.encoding;
1016
- const fetchBuiltInCMap = params.fetchBuiltInCMap;
1017
- const useCMap = params.useCMap;
1018
-
1019
- if (isName(encoding)) {
1020
- return createBuiltInCMap(encoding.name, fetchBuiltInCMap);
1021
- } else if (isStream(encoding)) {
1022
- const parsedCMap = await parseCMap(
1023
- /* cMap = */ new CMap(),
1024
- /* lexer = */ new Lexer(encoding),
1025
- fetchBuiltInCMap,
1026
- useCMap
1027
- );
1028
-
1029
- if (parsedCMap.isIdentityCMap) {
1030
- return createBuiltInCMap(parsedCMap.name, fetchBuiltInCMap);
1031
- }
1032
- return parsedCMap;
1033
- }
1034
- throw new Error("Encoding required.");
1035
- },
1036
- };
1037
- })();
1038
-
1039
- export { CMap, CMapFactory, IdentityCMap };