@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.
Files changed (172) hide show
  1. package/README.md +1 -1
  2. package/package.json +42 -26
  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/l10n_utils.js +140 -0
  6. package/{src/shared → pdfjs/dist}/message_handler.js +243 -259
  7. package/{src/display → pdfjs/dist}/network.js +149 -87
  8. package/{src/display/content_disposition.js → pdfjs/dist/network_utils.js} +167 -55
  9. package/{src/display → pdfjs/dist}/node_stream.js +133 -98
  10. package/pdfjs/dist/pdf.js +12778 -0
  11. package/pdfjs/dist/pdf_link_service.js +638 -0
  12. package/pdfjs/dist/pdf_rendering_queue.js +199 -0
  13. package/pdfjs/dist/pdf_thumbnail_viewer.js +819 -0
  14. package/pdfjs/dist/pdf_viewer.js +3598 -0
  15. package/pdfjs/dist/ui_utils.js +1033 -0
  16. package/{src/shared → pdfjs/dist}/util.js +301 -287
  17. package/pdfjs/dist/worker.js +62813 -0
  18. package/src/vcf-pdf-viewer.js +98 -46
  19. package/theme/lumo/vcf-pdf-viewer-styles.js +4 -4
  20. package/theme/material/vcf-pdf-viewer-styles.js +4 -4
  21. package/theme/material/vcf-pdf-viewer.js +2 -2
  22. package/src/core/.eslintrc +0 -13
  23. package/src/core/annotation.js +0 -2948
  24. package/src/core/arithmetic_decoder.js +0 -182
  25. package/src/core/ascii_85_stream.js +0 -98
  26. package/src/core/ascii_hex_stream.js +0 -79
  27. package/src/core/base_stream.js +0 -110
  28. package/src/core/bidi.js +0 -438
  29. package/src/core/calibri_factors.js +0 -308
  30. package/src/core/catalog.js +0 -1459
  31. package/src/core/ccitt.js +0 -1062
  32. package/src/core/ccitt_stream.js +0 -60
  33. package/src/core/cff_font.js +0 -116
  34. package/src/core/cff_parser.js +0 -1949
  35. package/src/core/charsets.js +0 -119
  36. package/src/core/chunked_stream.js +0 -557
  37. package/src/core/cmap.js +0 -1039
  38. package/src/core/colorspace.js +0 -1533
  39. package/src/core/core_utils.js +0 -464
  40. package/src/core/crypto.js +0 -1900
  41. package/src/core/decode_stream.js +0 -170
  42. package/src/core/decrypt_stream.js +0 -59
  43. package/src/core/default_appearance.js +0 -99
  44. package/src/core/document.js +0 -1456
  45. package/src/core/encodings.js +0 -301
  46. package/src/core/evaluator.js +0 -4601
  47. package/src/core/file_spec.js +0 -108
  48. package/src/core/flate_stream.js +0 -402
  49. package/src/core/font_renderer.js +0 -882
  50. package/src/core/fonts.js +0 -3260
  51. package/src/core/fonts_utils.js +0 -221
  52. package/src/core/function.js +0 -1257
  53. package/src/core/glyf.js +0 -706
  54. package/src/core/glyphlist.js +0 -4558
  55. package/src/core/helvetica_factors.js +0 -353
  56. package/src/core/image.js +0 -802
  57. package/src/core/image_utils.js +0 -291
  58. package/src/core/jbig2.js +0 -2572
  59. package/src/core/jbig2_stream.js +0 -73
  60. package/src/core/jpeg_stream.js +0 -105
  61. package/src/core/jpg.js +0 -1416
  62. package/src/core/jpx.js +0 -2343
  63. package/src/core/jpx_stream.js +0 -87
  64. package/src/core/liberationsans_widths.js +0 -221
  65. package/src/core/lzw_stream.js +0 -150
  66. package/src/core/metadata_parser.js +0 -146
  67. package/src/core/metrics.js +0 -2970
  68. package/src/core/murmurhash3.js +0 -139
  69. package/src/core/myriadpro_factors.js +0 -290
  70. package/src/core/name_number_tree.js +0 -153
  71. package/src/core/object_loader.js +0 -149
  72. package/src/core/opentype_file_builder.js +0 -154
  73. package/src/core/operator_list.js +0 -734
  74. package/src/core/parser.js +0 -1416
  75. package/src/core/pattern.js +0 -985
  76. package/src/core/pdf_manager.js +0 -217
  77. package/src/core/predictor_stream.js +0 -238
  78. package/src/core/primitives.js +0 -402
  79. package/src/core/ps_parser.js +0 -272
  80. package/src/core/run_length_stream.js +0 -61
  81. package/src/core/segoeui_factors.js +0 -308
  82. package/src/core/standard_fonts.js +0 -817
  83. package/src/core/stream.js +0 -103
  84. package/src/core/struct_tree.js +0 -335
  85. package/src/core/to_unicode_map.js +0 -103
  86. package/src/core/type1_font.js +0 -421
  87. package/src/core/type1_parser.js +0 -776
  88. package/src/core/unicode.js +0 -1649
  89. package/src/core/worker.js +0 -848
  90. package/src/core/worker_stream.js +0 -135
  91. package/src/core/writer.js +0 -278
  92. package/src/core/xfa/bind.js +0 -652
  93. package/src/core/xfa/builder.js +0 -207
  94. package/src/core/xfa/config.js +0 -1926
  95. package/src/core/xfa/connection_set.js +0 -202
  96. package/src/core/xfa/data.js +0 -82
  97. package/src/core/xfa/datasets.js +0 -76
  98. package/src/core/xfa/factory.js +0 -111
  99. package/src/core/xfa/fonts.js +0 -181
  100. package/src/core/xfa/formcalc_lexer.js +0 -385
  101. package/src/core/xfa/formcalc_parser.js +0 -1340
  102. package/src/core/xfa/html_utils.js +0 -639
  103. package/src/core/xfa/layout.js +0 -383
  104. package/src/core/xfa/locale_set.js +0 -345
  105. package/src/core/xfa/namespaces.js +0 -81
  106. package/src/core/xfa/parser.js +0 -184
  107. package/src/core/xfa/setup.js +0 -38
  108. package/src/core/xfa/signature.js +0 -40
  109. package/src/core/xfa/som.js +0 -338
  110. package/src/core/xfa/stylesheet.js +0 -40
  111. package/src/core/xfa/template.js +0 -6260
  112. package/src/core/xfa/text.js +0 -290
  113. package/src/core/xfa/unknown.js +0 -29
  114. package/src/core/xfa/utils.js +0 -217
  115. package/src/core/xfa/xdp.js +0 -59
  116. package/src/core/xfa/xfa_object.js +0 -1130
  117. package/src/core/xfa/xhtml.js +0 -543
  118. package/src/core/xfa_fonts.js +0 -208
  119. package/src/core/xml_parser.js +0 -507
  120. package/src/core/xref.js +0 -899
  121. package/src/display/annotation_layer.js +0 -2107
  122. package/src/display/annotation_storage.js +0 -113
  123. package/src/display/api.js +0 -3292
  124. package/src/display/base_factory.js +0 -180
  125. package/src/display/canvas.js +0 -2828
  126. package/src/display/font_loader.js +0 -484
  127. package/src/display/metadata.js +0 -41
  128. package/src/display/network_utils.js +0 -100
  129. package/src/display/node_utils.js +0 -83
  130. package/src/display/optional_content_config.js +0 -189
  131. package/src/display/pattern_helper.js +0 -659
  132. package/src/display/svg.js +0 -1709
  133. package/src/display/text_layer.js +0 -847
  134. package/src/display/transport_stream.js +0 -303
  135. package/src/display/worker_options.js +0 -40
  136. package/src/display/xfa_layer.js +0 -204
  137. package/src/doc_helper.js +0 -25
  138. package/src/images/logo.svg +0 -41
  139. package/src/interfaces.js +0 -169
  140. package/src/license_header.js +0 -14
  141. package/src/license_header_libre.js +0 -21
  142. package/src/pdf.image_decoders.js +0 -46
  143. package/src/pdf.js +0 -146
  144. package/src/pdf.sandbox.external.js +0 -181
  145. package/src/pdf.sandbox.js +0 -151
  146. package/src/pdf.scripting.js +0 -25
  147. package/src/pdf.worker.entry.js +0 -19
  148. package/src/pdf.worker.js +0 -23
  149. package/src/scripting_api/aform.js +0 -608
  150. package/src/scripting_api/app.js +0 -621
  151. package/src/scripting_api/color.js +0 -129
  152. package/src/scripting_api/common.js +0 -58
  153. package/src/scripting_api/console.js +0 -38
  154. package/src/scripting_api/constants.js +0 -208
  155. package/src/scripting_api/doc.js +0 -1195
  156. package/src/scripting_api/error.js +0 -23
  157. package/src/scripting_api/event.js +0 -232
  158. package/src/scripting_api/field.js +0 -620
  159. package/src/scripting_api/fullscreen.js +0 -145
  160. package/src/scripting_api/initialization.js +0 -223
  161. package/src/scripting_api/pdf_object.js +0 -24
  162. package/src/scripting_api/print_params.js +0 -146
  163. package/src/scripting_api/proxy.js +0 -139
  164. package/src/scripting_api/thermometer.js +0 -69
  165. package/src/scripting_api/util.js +0 -581
  166. package/src/shared/.eslintrc +0 -13
  167. package/src/shared/cffStandardStrings.js +0 -311
  168. package/src/shared/compatibility.js +0 -114
  169. package/src/shared/fonts_utils.js +0 -429
  170. package/src/shared/is_node.js +0 -27
  171. package/src/shared/scripting_utils.js +0 -85
  172. package/src/worker_loader.js +0 -32
@@ -1,484 +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
- assert,
18
- bytesToString,
19
- IsEvalSupportedCached,
20
- shadow,
21
- string32,
22
- unreachable,
23
- UNSUPPORTED_FEATURES,
24
- warn,
25
- } from "../shared/util.js";
26
-
27
- class BaseFontLoader {
28
- constructor({
29
- docId,
30
- onUnsupportedFeature,
31
- ownerDocument = globalThis.document,
32
- // For testing only.
33
- styleElement = null,
34
- }) {
35
- if (this.constructor === BaseFontLoader) {
36
- unreachable("Cannot initialize BaseFontLoader.");
37
- }
38
- this.docId = docId;
39
- this._onUnsupportedFeature = onUnsupportedFeature;
40
- this._document = ownerDocument;
41
-
42
- this.nativeFontFaces = [];
43
- this.styleElement =
44
- typeof PDFJSDev === "undefined" || PDFJSDev.test("!PRODUCTION || TESTING")
45
- ? styleElement
46
- : null;
47
- }
48
-
49
- addNativeFontFace(nativeFontFace) {
50
- this.nativeFontFaces.push(nativeFontFace);
51
- this._document.fonts.add(nativeFontFace);
52
- }
53
-
54
- insertRule(rule) {
55
- let styleElement = this.styleElement;
56
- if (!styleElement) {
57
- styleElement = this.styleElement = this._document.createElement("style");
58
- styleElement.id = `PDFJS_FONT_STYLE_TAG_${this.docId}`;
59
- this._document.documentElement
60
- .getElementsByTagName("head")[0]
61
- .appendChild(styleElement);
62
- }
63
- const styleSheet = styleElement.sheet;
64
- styleSheet.insertRule(rule, styleSheet.cssRules.length);
65
- }
66
-
67
- clear() {
68
- for (const nativeFontFace of this.nativeFontFaces) {
69
- this._document.fonts.delete(nativeFontFace);
70
- }
71
- this.nativeFontFaces.length = 0;
72
-
73
- if (this.styleElement) {
74
- // Note: ChildNode.remove doesn't throw if the parentNode is undefined.
75
- this.styleElement.remove();
76
- this.styleElement = null;
77
- }
78
- }
79
-
80
- async bind(font) {
81
- // Add the font to the DOM only once; skip if the font is already loaded.
82
- if (font.attached || font.missingFile) {
83
- return;
84
- }
85
- font.attached = true;
86
-
87
- if (this.isFontLoadingAPISupported) {
88
- const nativeFontFace = font.createNativeFontFace();
89
- if (nativeFontFace) {
90
- this.addNativeFontFace(nativeFontFace);
91
- try {
92
- await nativeFontFace.loaded;
93
- } catch (ex) {
94
- this._onUnsupportedFeature({
95
- featureId: UNSUPPORTED_FEATURES.errorFontLoadNative,
96
- });
97
- warn(`Failed to load font '${nativeFontFace.family}': '${ex}'.`);
98
-
99
- // When font loading failed, fall back to the built-in font renderer.
100
- font.disableFontFace = true;
101
- throw ex;
102
- }
103
- }
104
- return; // The font was, asynchronously, loaded.
105
- }
106
-
107
- // !this.isFontLoadingAPISupported
108
- const rule = font.createFontFaceRule();
109
- if (rule) {
110
- this.insertRule(rule);
111
-
112
- if (this.isSyncFontLoadingSupported) {
113
- return; // The font was, synchronously, loaded.
114
- }
115
- await new Promise(resolve => {
116
- const request = this._queueLoadingCallback(resolve);
117
- this._prepareFontLoadEvent([rule], [font], request);
118
- });
119
- // The font was, asynchronously, loaded.
120
- }
121
- }
122
-
123
- _queueLoadingCallback(callback) {
124
- unreachable("Abstract method `_queueLoadingCallback`.");
125
- }
126
-
127
- get isFontLoadingAPISupported() {
128
- const hasFonts = !!this._document?.fonts;
129
- if (
130
- typeof PDFJSDev === "undefined" ||
131
- PDFJSDev.test("!PRODUCTION || TESTING")
132
- ) {
133
- return shadow(
134
- this,
135
- "isFontLoadingAPISupported",
136
- hasFonts && !this.styleElement
137
- );
138
- }
139
- return shadow(this, "isFontLoadingAPISupported", hasFonts);
140
- }
141
-
142
- // eslint-disable-next-line getter-return
143
- get isSyncFontLoadingSupported() {
144
- unreachable("Abstract method `isSyncFontLoadingSupported`.");
145
- }
146
-
147
- // eslint-disable-next-line getter-return
148
- get _loadTestFont() {
149
- unreachable("Abstract method `_loadTestFont`.");
150
- }
151
-
152
- _prepareFontLoadEvent(rules, fontsToLoad, request) {
153
- unreachable("Abstract method `_prepareFontLoadEvent`.");
154
- }
155
- }
156
-
157
- let FontLoader;
158
- if (typeof PDFJSDev !== "undefined" && PDFJSDev.test("MOZCENTRAL")) {
159
- FontLoader = class MozcentralFontLoader extends BaseFontLoader {
160
- get isSyncFontLoadingSupported() {
161
- return shadow(this, "isSyncFontLoadingSupported", true);
162
- }
163
- };
164
- } else {
165
- // PDFJSDev.test('CHROME || GENERIC')
166
-
167
- FontLoader = class GenericFontLoader extends BaseFontLoader {
168
- constructor(params) {
169
- super(params);
170
- this.loadingContext = {
171
- requests: [],
172
- nextRequestId: 0,
173
- };
174
- this.loadTestFontId = 0;
175
- }
176
-
177
- get isSyncFontLoadingSupported() {
178
- let supported = false;
179
- if (typeof PDFJSDev === "undefined" || !PDFJSDev.test("CHROME")) {
180
- if (typeof navigator === "undefined") {
181
- // Node.js - we can pretend that sync font loading is supported.
182
- supported = true;
183
- } else {
184
- // User agent string sniffing is bad, but there is no reliable way to
185
- // tell if the font is fully loaded and ready to be used with canvas.
186
- const m = /Mozilla\/5.0.*?rv:(\d+).*? Gecko/.exec(
187
- navigator.userAgent
188
- );
189
- if (m?.[1] >= 14) {
190
- supported = true;
191
- }
192
- // TODO - other browsers...
193
- }
194
- }
195
- return shadow(this, "isSyncFontLoadingSupported", supported);
196
- }
197
-
198
- _queueLoadingCallback(callback) {
199
- function completeRequest() {
200
- assert(!request.done, "completeRequest() cannot be called twice.");
201
- request.done = true;
202
-
203
- // Sending all completed requests in order of how they were queued.
204
- while (context.requests.length > 0 && context.requests[0].done) {
205
- const otherRequest = context.requests.shift();
206
- setTimeout(otherRequest.callback, 0);
207
- }
208
- }
209
-
210
- const context = this.loadingContext;
211
- const request = {
212
- id: `pdfjs-font-loading-${context.nextRequestId++}`,
213
- done: false,
214
- complete: completeRequest,
215
- callback,
216
- };
217
- context.requests.push(request);
218
- return request;
219
- }
220
-
221
- get _loadTestFont() {
222
- const getLoadTestFont = function () {
223
- // This is a CFF font with 1 glyph for '.' that fills its entire width
224
- // and height.
225
- return atob(
226
- "T1RUTwALAIAAAwAwQ0ZGIDHtZg4AAAOYAAAAgUZGVE1lkzZwAAAEHAAAABxHREVGABQA" +
227
- "FQAABDgAAAAeT1MvMlYNYwkAAAEgAAAAYGNtYXABDQLUAAACNAAAAUJoZWFk/xVFDQAA" +
228
- "ALwAAAA2aGhlYQdkA+oAAAD0AAAAJGhtdHgD6AAAAAAEWAAAAAZtYXhwAAJQAAAAARgA" +
229
- "AAAGbmFtZVjmdH4AAAGAAAAAsXBvc3T/hgAzAAADeAAAACAAAQAAAAEAALZRFsRfDzz1" +
230
- "AAsD6AAAAADOBOTLAAAAAM4KHDwAAAAAA+gDIQAAAAgAAgAAAAAAAAABAAADIQAAAFoD" +
231
- "6AAAAAAD6AABAAAAAAAAAAAAAAAAAAAAAQAAUAAAAgAAAAQD6AH0AAUAAAKKArwAAACM" +
232
- "AooCvAAAAeAAMQECAAACAAYJAAAAAAAAAAAAAQAAAAAAAAAAAAAAAFBmRWQAwAAuAC4D" +
233
- "IP84AFoDIQAAAAAAAQAAAAAAAAAAACAAIAABAAAADgCuAAEAAAAAAAAAAQAAAAEAAAAA" +
234
- "AAEAAQAAAAEAAAAAAAIAAQAAAAEAAAAAAAMAAQAAAAEAAAAAAAQAAQAAAAEAAAAAAAUA" +
235
- "AQAAAAEAAAAAAAYAAQAAAAMAAQQJAAAAAgABAAMAAQQJAAEAAgABAAMAAQQJAAIAAgAB" +
236
- "AAMAAQQJAAMAAgABAAMAAQQJAAQAAgABAAMAAQQJAAUAAgABAAMAAQQJAAYAAgABWABY" +
237
- "AAAAAAAAAwAAAAMAAAAcAAEAAAAAADwAAwABAAAAHAAEACAAAAAEAAQAAQAAAC7//wAA" +
238
- "AC7////TAAEAAAAAAAABBgAAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" +
239
- "AAAAAAAAAAAAAAAAAAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" +
240
- "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" +
241
- "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" +
242
- "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" +
243
- "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAMAAAAAAAD/gwAyAAAAAQAAAAAAAAAAAAAAAAAA" +
244
- "AAABAAQEAAEBAQJYAAEBASH4DwD4GwHEAvgcA/gXBIwMAYuL+nz5tQXkD5j3CBLnEQAC" +
245
- "AQEBIVhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYAAABAQAADwACAQEEE/t3" +
246
- "Dov6fAH6fAT+fPp8+nwHDosMCvm1Cvm1DAz6fBQAAAAAAAABAAAAAMmJbzEAAAAAzgTj" +
247
- "FQAAAADOBOQpAAEAAAAAAAAADAAUAAQAAAABAAAAAgABAAAAAAAAAAAD6AAAAAAAAA=="
248
- );
249
- };
250
- return shadow(this, "_loadTestFont", getLoadTestFont());
251
- }
252
-
253
- _prepareFontLoadEvent(rules, fonts, request) {
254
- /** Hack begin */
255
- // There's currently no event when a font has finished downloading so the
256
- // following code is a dirty hack to 'guess' when a font is ready.
257
- // It's assumed fonts are loaded in order, so add a known test font after
258
- // the desired fonts and then test for the loading of that test font.
259
-
260
- function int32(data, offset) {
261
- return (
262
- (data.charCodeAt(offset) << 24) |
263
- (data.charCodeAt(offset + 1) << 16) |
264
- (data.charCodeAt(offset + 2) << 8) |
265
- (data.charCodeAt(offset + 3) & 0xff)
266
- );
267
- }
268
- function spliceString(s, offset, remove, insert) {
269
- const chunk1 = s.substring(0, offset);
270
- const chunk2 = s.substring(offset + remove);
271
- return chunk1 + insert + chunk2;
272
- }
273
- let i, ii;
274
-
275
- // The temporary canvas is used to determine if fonts are loaded.
276
- const canvas = this._document.createElement("canvas");
277
- canvas.width = 1;
278
- canvas.height = 1;
279
- const ctx = canvas.getContext("2d");
280
-
281
- let called = 0;
282
- function isFontReady(name, callback) {
283
- called++;
284
- // With setTimeout clamping this gives the font ~100ms to load.
285
- if (called > 30) {
286
- warn("Load test font never loaded.");
287
- callback();
288
- return;
289
- }
290
- ctx.font = "30px " + name;
291
- ctx.fillText(".", 0, 20);
292
- const imageData = ctx.getImageData(0, 0, 1, 1);
293
- if (imageData.data[3] > 0) {
294
- callback();
295
- return;
296
- }
297
- setTimeout(isFontReady.bind(null, name, callback));
298
- }
299
-
300
- const loadTestFontId = `lt${Date.now()}${this.loadTestFontId++}`;
301
- // Chromium seems to cache fonts based on a hash of the actual font data,
302
- // so the font must be modified for each load test else it will appear to
303
- // be loaded already.
304
- // TODO: This could maybe be made faster by avoiding the btoa of the full
305
- // font by splitting it in chunks before hand and padding the font id.
306
- let data = this._loadTestFont;
307
- const COMMENT_OFFSET = 976; // has to be on 4 byte boundary (for checksum)
308
- data = spliceString(
309
- data,
310
- COMMENT_OFFSET,
311
- loadTestFontId.length,
312
- loadTestFontId
313
- );
314
- // CFF checksum is important for IE, adjusting it
315
- const CFF_CHECKSUM_OFFSET = 16;
316
- const XXXX_VALUE = 0x58585858; // the "comment" filled with 'X'
317
- let checksum = int32(data, CFF_CHECKSUM_OFFSET);
318
- for (i = 0, ii = loadTestFontId.length - 3; i < ii; i += 4) {
319
- checksum = (checksum - XXXX_VALUE + int32(loadTestFontId, i)) | 0;
320
- }
321
- if (i < loadTestFontId.length) {
322
- // align to 4 bytes boundary
323
- checksum =
324
- (checksum - XXXX_VALUE + int32(loadTestFontId + "XXX", i)) | 0;
325
- }
326
- data = spliceString(data, CFF_CHECKSUM_OFFSET, 4, string32(checksum));
327
-
328
- const url = `url(data:font/opentype;base64,${btoa(data)});`;
329
- const rule = `@font-face {font-family:"${loadTestFontId}";src:${url}}`;
330
- this.insertRule(rule);
331
-
332
- const names = [];
333
- for (const font of fonts) {
334
- names.push(font.loadedName);
335
- }
336
- names.push(loadTestFontId);
337
-
338
- const div = this._document.createElement("div");
339
- div.style.visibility = "hidden";
340
- div.style.width = div.style.height = "10px";
341
- div.style.position = "absolute";
342
- div.style.top = div.style.left = "0px";
343
-
344
- for (const name of names) {
345
- const span = this._document.createElement("span");
346
- span.textContent = "Hi";
347
- span.style.fontFamily = name;
348
- div.appendChild(span);
349
- }
350
- this._document.body.appendChild(div);
351
-
352
- isFontReady(loadTestFontId, () => {
353
- this._document.body.removeChild(div);
354
- request.complete();
355
- });
356
- /** Hack end */
357
- }
358
- };
359
- } // End of PDFJSDev.test('CHROME || GENERIC')
360
-
361
- class FontFaceObject {
362
- constructor(
363
- translatedData,
364
- {
365
- isEvalSupported = true,
366
- disableFontFace = false,
367
- ignoreErrors = false,
368
- onUnsupportedFeature,
369
- fontRegistry = null,
370
- }
371
- ) {
372
- this.compiledGlyphs = Object.create(null);
373
- // importing translated data
374
- for (const i in translatedData) {
375
- this[i] = translatedData[i];
376
- }
377
- this.isEvalSupported = isEvalSupported !== false;
378
- this.disableFontFace = disableFontFace === true;
379
- this.ignoreErrors = ignoreErrors === true;
380
- this._onUnsupportedFeature = onUnsupportedFeature;
381
- this.fontRegistry = fontRegistry;
382
- }
383
-
384
- createNativeFontFace() {
385
- if (!this.data || this.disableFontFace) {
386
- return null;
387
- }
388
- let nativeFontFace;
389
- if (!this.cssFontInfo) {
390
- nativeFontFace = new FontFace(this.loadedName, this.data, {});
391
- } else {
392
- const css = {
393
- weight: this.cssFontInfo.fontWeight,
394
- };
395
- if (this.cssFontInfo.italicAngle) {
396
- css.style = `oblique ${this.cssFontInfo.italicAngle}deg`;
397
- }
398
- nativeFontFace = new FontFace(
399
- this.cssFontInfo.fontFamily,
400
- this.data,
401
- css
402
- );
403
- }
404
-
405
- if (this.fontRegistry) {
406
- this.fontRegistry.registerFont(this);
407
- }
408
- return nativeFontFace;
409
- }
410
-
411
- createFontFaceRule() {
412
- if (!this.data || this.disableFontFace) {
413
- return null;
414
- }
415
- const data = bytesToString(this.data);
416
- // Add the @font-face rule to the document.
417
- const url = `url(data:${this.mimetype};base64,${btoa(data)});`;
418
- let rule;
419
- if (!this.cssFontInfo) {
420
- rule = `@font-face {font-family:"${this.loadedName}";src:${url}}`;
421
- } else {
422
- let css = `font-weight: ${this.cssFontInfo.fontWeight};`;
423
- if (this.cssFontInfo.italicAngle) {
424
- css += `font-style: oblique ${this.cssFontInfo.italicAngle}deg;`;
425
- }
426
- rule = `@font-face {font-family:"${this.cssFontInfo.fontFamily}";${css}src:${url}}`;
427
- }
428
-
429
- if (this.fontRegistry) {
430
- this.fontRegistry.registerFont(this, url);
431
- }
432
- return rule;
433
- }
434
-
435
- getPathGenerator(objs, character) {
436
- if (this.compiledGlyphs[character] !== undefined) {
437
- return this.compiledGlyphs[character];
438
- }
439
-
440
- let cmds;
441
- try {
442
- cmds = objs.get(this.loadedName + "_path_" + character);
443
- } catch (ex) {
444
- if (!this.ignoreErrors) {
445
- throw ex;
446
- }
447
- this._onUnsupportedFeature({
448
- featureId: UNSUPPORTED_FEATURES.errorFontGetPath,
449
- });
450
- warn(`getPathGenerator - ignoring character: "${ex}".`);
451
-
452
- return (this.compiledGlyphs[character] = function (c, size) {
453
- // No-op function, to allow rendering to continue.
454
- });
455
- }
456
-
457
- // If we can, compile cmds into JS for MAXIMUM SPEED...
458
- if (this.isEvalSupported && IsEvalSupportedCached.value) {
459
- const jsBuf = [];
460
- for (const current of cmds) {
461
- const args = current.args !== undefined ? current.args.join(",") : "";
462
- jsBuf.push("c.", current.cmd, "(", args, ");\n");
463
- }
464
- // eslint-disable-next-line no-new-func
465
- return (this.compiledGlyphs[character] = new Function(
466
- "c",
467
- "size",
468
- jsBuf.join("")
469
- ));
470
- }
471
- // ... but fall back on using Function.prototype.apply() if we're
472
- // blocked from using eval() for whatever reason (like CSP policies).
473
- return (this.compiledGlyphs[character] = function (c, size) {
474
- for (const current of cmds) {
475
- if (current.cmd === "scale") {
476
- current.args = [size, -size];
477
- }
478
- c[current.cmd].apply(c, current.args);
479
- }
480
- });
481
- }
482
- }
483
-
484
- export { FontFaceObject, FontLoader };
@@ -1,41 +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 { objectFromMap } from "../shared/util.js";
17
-
18
- class Metadata {
19
- constructor({ parsedData, rawData }) {
20
- this._metadataMap = parsedData;
21
- this._data = rawData;
22
- }
23
-
24
- getRaw() {
25
- return this._data;
26
- }
27
-
28
- get(name) {
29
- return this._metadataMap.get(name) ?? null;
30
- }
31
-
32
- getAll() {
33
- return objectFromMap(this._metadataMap);
34
- }
35
-
36
- has(name) {
37
- return this._metadataMap.has(name);
38
- }
39
- }
40
-
41
- export { Metadata };
@@ -1,100 +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
- assert,
18
- MissingPDFException,
19
- UnexpectedResponseException,
20
- } from "../shared/util.js";
21
- import { getFilenameFromContentDispositionHeader } from "./content_disposition.js";
22
- import { isPdfFile } from "./display_utils.js";
23
-
24
- function validateRangeRequestCapabilities({
25
- getResponseHeader,
26
- isHttp,
27
- rangeChunkSize,
28
- disableRange,
29
- }) {
30
- assert(rangeChunkSize > 0, "Range chunk size must be larger than zero");
31
- const returnValues = {
32
- allowRangeRequests: false,
33
- suggestedLength: undefined,
34
- };
35
-
36
- const length = parseInt(getResponseHeader("Content-Length"), 10);
37
- if (!Number.isInteger(length)) {
38
- return returnValues;
39
- }
40
-
41
- returnValues.suggestedLength = length;
42
-
43
- if (length <= 2 * rangeChunkSize) {
44
- // The file size is smaller than the size of two chunks, so it does not
45
- // make any sense to abort the request and retry with a range request.
46
- return returnValues;
47
- }
48
-
49
- if (disableRange || !isHttp) {
50
- return returnValues;
51
- }
52
- if (getResponseHeader("Accept-Ranges") !== "bytes") {
53
- return returnValues;
54
- }
55
-
56
- const contentEncoding = getResponseHeader("Content-Encoding") || "identity";
57
- if (contentEncoding !== "identity") {
58
- return returnValues;
59
- }
60
-
61
- returnValues.allowRangeRequests = true;
62
- return returnValues;
63
- }
64
-
65
- function extractFilenameFromHeader(getResponseHeader) {
66
- const contentDisposition = getResponseHeader("Content-Disposition");
67
- if (contentDisposition) {
68
- let filename = getFilenameFromContentDispositionHeader(contentDisposition);
69
- if (filename.includes("%")) {
70
- try {
71
- filename = decodeURIComponent(filename);
72
- } catch (ex) {}
73
- }
74
- if (isPdfFile(filename)) {
75
- return filename;
76
- }
77
- }
78
- return null;
79
- }
80
-
81
- function createResponseStatusError(status, url) {
82
- if (status === 404 || (status === 0 && url.startsWith("file:"))) {
83
- return new MissingPDFException('Missing PDF "' + url + '".');
84
- }
85
- return new UnexpectedResponseException(
86
- `Unexpected server response (${status}) while retrieving PDF "${url}".`,
87
- status
88
- );
89
- }
90
-
91
- function validateResponseStatus(status) {
92
- return status === 200 || status === 206;
93
- }
94
-
95
- export {
96
- createResponseStatusError,
97
- extractFilenameFromHeader,
98
- validateRangeRequestCapabilities,
99
- validateResponseStatus,
100
- };
@@ -1,83 +0,0 @@
1
- /* Copyright 2020 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
- /* globals __non_webpack_require__ */
16
-
17
- import {
18
- BaseCanvasFactory,
19
- BaseCMapReaderFactory,
20
- BaseStandardFontDataFactory,
21
- } from "./base_factory.js";
22
- import { isNodeJS } from "../shared/is_node.js";
23
- import { unreachable } from "../shared/util.js";
24
-
25
- let NodeCanvasFactory = class {
26
- constructor() {
27
- unreachable("Not implemented: NodeCanvasFactory");
28
- }
29
- };
30
-
31
- let NodeCMapReaderFactory = class {
32
- constructor() {
33
- unreachable("Not implemented: NodeCMapReaderFactory");
34
- }
35
- };
36
-
37
- let NodeStandardFontDataFactory = class {
38
- constructor() {
39
- unreachable("Not implemented: NodeStandardFontDataFactory");
40
- }
41
- };
42
-
43
- if ((typeof PDFJSDev === "undefined" || PDFJSDev.test("GENERIC")) && isNodeJS) {
44
- const fetchData = function (url) {
45
- return new Promise((resolve, reject) => {
46
- const fs = __non_webpack_require__("fs");
47
- fs.readFile(url, (error, data) => {
48
- if (error || !data) {
49
- reject(new Error(error));
50
- return;
51
- }
52
- resolve(new Uint8Array(data));
53
- });
54
- });
55
- };
56
-
57
- NodeCanvasFactory = class extends BaseCanvasFactory {
58
- _createCanvas(width, height) {
59
- const Canvas = __non_webpack_require__("canvas");
60
- return Canvas.createCanvas(width, height);
61
- }
62
- };
63
-
64
- NodeCMapReaderFactory = class extends BaseCMapReaderFactory {
65
- _fetchData(url, compressionType) {
66
- return fetchData(url).then(data => {
67
- return { cMapData: data, compressionType };
68
- });
69
- }
70
- };
71
-
72
- NodeStandardFontDataFactory = class extends BaseStandardFontDataFactory {
73
- _fetchData(url) {
74
- return fetchData(url);
75
- }
76
- };
77
- }
78
-
79
- export {
80
- NodeCanvasFactory,
81
- NodeCMapReaderFactory,
82
- NodeStandardFontDataFactory,
83
- };