@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
@@ -1,659 +0,0 @@
1
- /* Copyright 2014 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
- FormatError,
18
- info,
19
- shadow,
20
- unreachable,
21
- Util,
22
- warn,
23
- } from "../shared/util.js";
24
-
25
- function applyBoundingBox(ctx, bbox) {
26
- if (!bbox || typeof Path2D === "undefined") {
27
- return;
28
- }
29
- const width = bbox[2] - bbox[0];
30
- const height = bbox[3] - bbox[1];
31
- const region = new Path2D();
32
- region.rect(bbox[0], bbox[1], width, height);
33
- ctx.clip(region);
34
- }
35
-
36
- class BaseShadingPattern {
37
- constructor() {
38
- if (this.constructor === BaseShadingPattern) {
39
- unreachable("Cannot initialize BaseShadingPattern.");
40
- }
41
- }
42
-
43
- getPattern() {
44
- unreachable("Abstract method `getPattern` called.");
45
- }
46
- }
47
-
48
- class RadialAxialShadingPattern extends BaseShadingPattern {
49
- constructor(IR) {
50
- super();
51
- this._type = IR[1];
52
- this._bbox = IR[2];
53
- this._colorStops = IR[3];
54
- this._p0 = IR[4];
55
- this._p1 = IR[5];
56
- this._r0 = IR[6];
57
- this._r1 = IR[7];
58
- this._matrix = IR[8];
59
- this._patternCache = null;
60
- }
61
-
62
- _createGradient(ctx) {
63
- let grad;
64
- if (this._type === "axial") {
65
- grad = ctx.createLinearGradient(
66
- this._p0[0],
67
- this._p0[1],
68
- this._p1[0],
69
- this._p1[1]
70
- );
71
- } else if (this._type === "radial") {
72
- grad = ctx.createRadialGradient(
73
- this._p0[0],
74
- this._p0[1],
75
- this._r0,
76
- this._p1[0],
77
- this._p1[1],
78
- this._r1
79
- );
80
- }
81
-
82
- for (const colorStop of this._colorStops) {
83
- grad.addColorStop(colorStop[0], colorStop[1]);
84
- }
85
- return grad;
86
- }
87
-
88
- getPattern(ctx, owner, inverse, shadingFill = false) {
89
- let pattern;
90
- if (this._patternCache) {
91
- pattern = this._patternCache;
92
- } else {
93
- if (!shadingFill) {
94
- const tmpCanvas = owner.cachedCanvases.getCanvas(
95
- "pattern",
96
- owner.ctx.canvas.width,
97
- owner.ctx.canvas.height,
98
- true
99
- );
100
-
101
- const tmpCtx = tmpCanvas.context;
102
- tmpCtx.clearRect(0, 0, tmpCtx.canvas.width, tmpCtx.canvas.height);
103
- tmpCtx.beginPath();
104
- tmpCtx.rect(0, 0, tmpCtx.canvas.width, tmpCtx.canvas.height);
105
-
106
- tmpCtx.setTransform.apply(tmpCtx, owner.baseTransform);
107
- if (this._matrix) {
108
- tmpCtx.transform.apply(tmpCtx, this._matrix);
109
- }
110
- applyBoundingBox(tmpCtx, this._bbox);
111
-
112
- tmpCtx.fillStyle = this._createGradient(tmpCtx);
113
- tmpCtx.fill();
114
-
115
- pattern = ctx.createPattern(tmpCanvas.canvas, "repeat");
116
- } else {
117
- applyBoundingBox(ctx, this._bbox);
118
- pattern = this._createGradient(ctx);
119
- }
120
- this._patternCache = pattern;
121
- }
122
- if (!shadingFill) {
123
- const domMatrix = new DOMMatrix(inverse);
124
- try {
125
- pattern.setTransform(domMatrix);
126
- } catch (ex) {
127
- // Avoid rendering breaking completely in Firefox 78 ESR,
128
- // and in Node.js (see issue 13724).
129
- warn(`RadialAxialShadingPattern.getPattern: "${ex?.message}".`);
130
- }
131
- }
132
- return pattern;
133
- }
134
- }
135
-
136
- function drawTriangle(data, context, p1, p2, p3, c1, c2, c3) {
137
- // Very basic Gouraud-shaded triangle rasterization algorithm.
138
- const coords = context.coords,
139
- colors = context.colors;
140
- const bytes = data.data,
141
- rowSize = data.width * 4;
142
- let tmp;
143
- if (coords[p1 + 1] > coords[p2 + 1]) {
144
- tmp = p1;
145
- p1 = p2;
146
- p2 = tmp;
147
- tmp = c1;
148
- c1 = c2;
149
- c2 = tmp;
150
- }
151
- if (coords[p2 + 1] > coords[p3 + 1]) {
152
- tmp = p2;
153
- p2 = p3;
154
- p3 = tmp;
155
- tmp = c2;
156
- c2 = c3;
157
- c3 = tmp;
158
- }
159
- if (coords[p1 + 1] > coords[p2 + 1]) {
160
- tmp = p1;
161
- p1 = p2;
162
- p2 = tmp;
163
- tmp = c1;
164
- c1 = c2;
165
- c2 = tmp;
166
- }
167
- const x1 = (coords[p1] + context.offsetX) * context.scaleX;
168
- const y1 = (coords[p1 + 1] + context.offsetY) * context.scaleY;
169
- const x2 = (coords[p2] + context.offsetX) * context.scaleX;
170
- const y2 = (coords[p2 + 1] + context.offsetY) * context.scaleY;
171
- const x3 = (coords[p3] + context.offsetX) * context.scaleX;
172
- const y3 = (coords[p3 + 1] + context.offsetY) * context.scaleY;
173
- if (y1 >= y3) {
174
- return;
175
- }
176
- const c1r = colors[c1],
177
- c1g = colors[c1 + 1],
178
- c1b = colors[c1 + 2];
179
- const c2r = colors[c2],
180
- c2g = colors[c2 + 1],
181
- c2b = colors[c2 + 2];
182
- const c3r = colors[c3],
183
- c3g = colors[c3 + 1],
184
- c3b = colors[c3 + 2];
185
-
186
- const minY = Math.round(y1),
187
- maxY = Math.round(y3);
188
- let xa, car, cag, cab;
189
- let xb, cbr, cbg, cbb;
190
- for (let y = minY; y <= maxY; y++) {
191
- if (y < y2) {
192
- let k;
193
- if (y < y1) {
194
- k = 0;
195
- } else {
196
- k = (y1 - y) / (y1 - y2);
197
- }
198
- xa = x1 - (x1 - x2) * k;
199
- car = c1r - (c1r - c2r) * k;
200
- cag = c1g - (c1g - c2g) * k;
201
- cab = c1b - (c1b - c2b) * k;
202
- } else {
203
- let k;
204
- if (y > y3) {
205
- k = 1;
206
- } else if (y2 === y3) {
207
- k = 0;
208
- } else {
209
- k = (y2 - y) / (y2 - y3);
210
- }
211
- xa = x2 - (x2 - x3) * k;
212
- car = c2r - (c2r - c3r) * k;
213
- cag = c2g - (c2g - c3g) * k;
214
- cab = c2b - (c2b - c3b) * k;
215
- }
216
-
217
- let k;
218
- if (y < y1) {
219
- k = 0;
220
- } else if (y > y3) {
221
- k = 1;
222
- } else {
223
- k = (y1 - y) / (y1 - y3);
224
- }
225
- xb = x1 - (x1 - x3) * k;
226
- cbr = c1r - (c1r - c3r) * k;
227
- cbg = c1g - (c1g - c3g) * k;
228
- cbb = c1b - (c1b - c3b) * k;
229
- const x1_ = Math.round(Math.min(xa, xb));
230
- const x2_ = Math.round(Math.max(xa, xb));
231
- let j = rowSize * y + x1_ * 4;
232
- for (let x = x1_; x <= x2_; x++) {
233
- k = (xa - x) / (xa - xb);
234
- if (k < 0) {
235
- k = 0;
236
- } else if (k > 1) {
237
- k = 1;
238
- }
239
- bytes[j++] = (car - (car - cbr) * k) | 0;
240
- bytes[j++] = (cag - (cag - cbg) * k) | 0;
241
- bytes[j++] = (cab - (cab - cbb) * k) | 0;
242
- bytes[j++] = 255;
243
- }
244
- }
245
- }
246
-
247
- function drawFigure(data, figure, context) {
248
- const ps = figure.coords;
249
- const cs = figure.colors;
250
- let i, ii;
251
- switch (figure.type) {
252
- case "lattice":
253
- const verticesPerRow = figure.verticesPerRow;
254
- const rows = Math.floor(ps.length / verticesPerRow) - 1;
255
- const cols = verticesPerRow - 1;
256
- for (i = 0; i < rows; i++) {
257
- let q = i * verticesPerRow;
258
- for (let j = 0; j < cols; j++, q++) {
259
- drawTriangle(
260
- data,
261
- context,
262
- ps[q],
263
- ps[q + 1],
264
- ps[q + verticesPerRow],
265
- cs[q],
266
- cs[q + 1],
267
- cs[q + verticesPerRow]
268
- );
269
- drawTriangle(
270
- data,
271
- context,
272
- ps[q + verticesPerRow + 1],
273
- ps[q + 1],
274
- ps[q + verticesPerRow],
275
- cs[q + verticesPerRow + 1],
276
- cs[q + 1],
277
- cs[q + verticesPerRow]
278
- );
279
- }
280
- }
281
- break;
282
- case "triangles":
283
- for (i = 0, ii = ps.length; i < ii; i += 3) {
284
- drawTriangle(
285
- data,
286
- context,
287
- ps[i],
288
- ps[i + 1],
289
- ps[i + 2],
290
- cs[i],
291
- cs[i + 1],
292
- cs[i + 2]
293
- );
294
- }
295
- break;
296
- default:
297
- throw new Error("illegal figure");
298
- }
299
- }
300
-
301
- class MeshShadingPattern extends BaseShadingPattern {
302
- constructor(IR) {
303
- super();
304
- this._coords = IR[2];
305
- this._colors = IR[3];
306
- this._figures = IR[4];
307
- this._bounds = IR[5];
308
- this._matrix = IR[6];
309
- this._bbox = IR[7];
310
- this._background = IR[8];
311
- }
312
-
313
- _createMeshCanvas(combinedScale, backgroundColor, cachedCanvases) {
314
- // we will increase scale on some weird factor to let antialiasing take
315
- // care of "rough" edges
316
- const EXPECTED_SCALE = 1.1;
317
- // MAX_PATTERN_SIZE is used to avoid OOM situation.
318
- const MAX_PATTERN_SIZE = 3000; // 10in @ 300dpi shall be enough
319
- // We need to keep transparent border around our pattern for fill():
320
- // createPattern with 'no-repeat' will bleed edges across entire area.
321
- const BORDER_SIZE = 2;
322
-
323
- const offsetX = Math.floor(this._bounds[0]);
324
- const offsetY = Math.floor(this._bounds[1]);
325
- const boundsWidth = Math.ceil(this._bounds[2]) - offsetX;
326
- const boundsHeight = Math.ceil(this._bounds[3]) - offsetY;
327
-
328
- const width = Math.min(
329
- Math.ceil(Math.abs(boundsWidth * combinedScale[0] * EXPECTED_SCALE)),
330
- MAX_PATTERN_SIZE
331
- );
332
- const height = Math.min(
333
- Math.ceil(Math.abs(boundsHeight * combinedScale[1] * EXPECTED_SCALE)),
334
- MAX_PATTERN_SIZE
335
- );
336
- const scaleX = boundsWidth / width;
337
- const scaleY = boundsHeight / height;
338
-
339
- const context = {
340
- coords: this._coords,
341
- colors: this._colors,
342
- offsetX: -offsetX,
343
- offsetY: -offsetY,
344
- scaleX: 1 / scaleX,
345
- scaleY: 1 / scaleY,
346
- };
347
-
348
- const paddedWidth = width + BORDER_SIZE * 2;
349
- const paddedHeight = height + BORDER_SIZE * 2;
350
-
351
- const tmpCanvas = cachedCanvases.getCanvas(
352
- "mesh",
353
- paddedWidth,
354
- paddedHeight,
355
- false
356
- );
357
- const tmpCtx = tmpCanvas.context;
358
-
359
- const data = tmpCtx.createImageData(width, height);
360
- if (backgroundColor) {
361
- const bytes = data.data;
362
- for (let i = 0, ii = bytes.length; i < ii; i += 4) {
363
- bytes[i] = backgroundColor[0];
364
- bytes[i + 1] = backgroundColor[1];
365
- bytes[i + 2] = backgroundColor[2];
366
- bytes[i + 3] = 255;
367
- }
368
- }
369
- for (const figure of this._figures) {
370
- drawFigure(data, figure, context);
371
- }
372
- tmpCtx.putImageData(data, BORDER_SIZE, BORDER_SIZE);
373
- const canvas = tmpCanvas.canvas;
374
-
375
- return {
376
- canvas,
377
- offsetX: offsetX - BORDER_SIZE * scaleX,
378
- offsetY: offsetY - BORDER_SIZE * scaleY,
379
- scaleX,
380
- scaleY,
381
- };
382
- }
383
-
384
- getPattern(ctx, owner, inverse, shadingFill = false) {
385
- applyBoundingBox(ctx, this._bbox);
386
- let scale;
387
- if (shadingFill) {
388
- scale = Util.singularValueDecompose2dScale(ctx.mozCurrentTransform);
389
- } else {
390
- // Obtain scale from matrix and current transformation matrix.
391
- scale = Util.singularValueDecompose2dScale(owner.baseTransform);
392
- if (this._matrix) {
393
- const matrixScale = Util.singularValueDecompose2dScale(this._matrix);
394
- scale = [scale[0] * matrixScale[0], scale[1] * matrixScale[1]];
395
- }
396
- }
397
-
398
- // Rasterizing on the main thread since sending/queue large canvases
399
- // might cause OOM.
400
- const temporaryPatternCanvas = this._createMeshCanvas(
401
- scale,
402
- shadingFill ? null : this._background,
403
- owner.cachedCanvases
404
- );
405
-
406
- if (!shadingFill) {
407
- ctx.setTransform.apply(ctx, owner.baseTransform);
408
- if (this._matrix) {
409
- ctx.transform.apply(ctx, this._matrix);
410
- }
411
- }
412
-
413
- ctx.translate(
414
- temporaryPatternCanvas.offsetX,
415
- temporaryPatternCanvas.offsetY
416
- );
417
- ctx.scale(temporaryPatternCanvas.scaleX, temporaryPatternCanvas.scaleY);
418
-
419
- return ctx.createPattern(temporaryPatternCanvas.canvas, "no-repeat");
420
- }
421
- }
422
-
423
- class DummyShadingPattern extends BaseShadingPattern {
424
- getPattern() {
425
- return "hotpink";
426
- }
427
- }
428
-
429
- function getShadingPattern(IR) {
430
- switch (IR[0]) {
431
- case "RadialAxial":
432
- return new RadialAxialShadingPattern(IR);
433
- case "Mesh":
434
- return new MeshShadingPattern(IR);
435
- case "Dummy":
436
- return new DummyShadingPattern();
437
- }
438
- throw new Error(`Unknown IR type: ${IR[0]}`);
439
- }
440
-
441
- const PaintType = {
442
- COLORED: 1,
443
- UNCOLORED: 2,
444
- };
445
-
446
- class TilingPattern {
447
- // 10in @ 300dpi shall be enough.
448
- static get MAX_PATTERN_SIZE() {
449
- return shadow(this, "MAX_PATTERN_SIZE", 3000);
450
- }
451
-
452
- constructor(IR, color, ctx, canvasGraphicsFactory, baseTransform) {
453
- this.operatorList = IR[2];
454
- this.matrix = IR[3] || [1, 0, 0, 1, 0, 0];
455
- this.bbox = IR[4];
456
- this.xstep = IR[5];
457
- this.ystep = IR[6];
458
- this.paintType = IR[7];
459
- this.tilingType = IR[8];
460
- this.color = color;
461
- this.ctx = ctx;
462
- this.canvasGraphicsFactory = canvasGraphicsFactory;
463
- this.baseTransform = baseTransform;
464
- }
465
-
466
- createPatternCanvas(owner) {
467
- const operatorList = this.operatorList;
468
- const bbox = this.bbox;
469
- const xstep = this.xstep;
470
- const ystep = this.ystep;
471
- const paintType = this.paintType;
472
- const tilingType = this.tilingType;
473
- const color = this.color;
474
- const canvasGraphicsFactory = this.canvasGraphicsFactory;
475
-
476
- info("TilingType: " + tilingType);
477
-
478
- // A tiling pattern as defined by PDF spec 8.7.2 is a cell whose size is
479
- // described by bbox, and may repeat regularly by shifting the cell by
480
- // xstep and ystep.
481
- // Because the HTML5 canvas API does not support pattern repetition with
482
- // gaps in between, we use the xstep/ystep instead of the bbox's size.
483
- //
484
- // This has the following consequences (similarly for ystep):
485
- //
486
- // - If xstep is the same as bbox, then there is no observable difference.
487
- //
488
- // - If xstep is larger than bbox, then the pattern canvas is partially
489
- // empty: the area bounded by bbox is painted, the outside area is void.
490
- //
491
- // - If xstep is smaller than bbox, then the pixels between xstep and the
492
- // bbox boundary will be missing. This is INCORRECT behavior.
493
- // "Figures on adjacent tiles should not overlap" (PDF spec 8.7.3.1),
494
- // but overlapping cells without common pixels are still valid.
495
- // TODO: Fix the implementation, to allow this scenario to be painted
496
- // correctly.
497
-
498
- const x0 = bbox[0],
499
- y0 = bbox[1],
500
- x1 = bbox[2],
501
- y1 = bbox[3];
502
-
503
- // Obtain scale from matrix and current transformation matrix.
504
- const matrixScale = Util.singularValueDecompose2dScale(this.matrix);
505
- const curMatrixScale = Util.singularValueDecompose2dScale(
506
- this.baseTransform
507
- );
508
- const combinedScale = [
509
- matrixScale[0] * curMatrixScale[0],
510
- matrixScale[1] * curMatrixScale[1],
511
- ];
512
-
513
- // Use width and height values that are as close as possible to the end
514
- // result when the pattern is used. Too low value makes the pattern look
515
- // blurry. Too large value makes it look too crispy.
516
- const dimx = this.getSizeAndScale(
517
- xstep,
518
- this.ctx.canvas.width,
519
- combinedScale[0]
520
- );
521
- const dimy = this.getSizeAndScale(
522
- ystep,
523
- this.ctx.canvas.height,
524
- combinedScale[1]
525
- );
526
-
527
- const tmpCanvas = owner.cachedCanvases.getCanvas(
528
- "pattern",
529
- dimx.size,
530
- dimy.size,
531
- true
532
- );
533
- const tmpCtx = tmpCanvas.context;
534
- const graphics = canvasGraphicsFactory.createCanvasGraphics(tmpCtx);
535
- graphics.groupLevel = owner.groupLevel;
536
-
537
- this.setFillAndStrokeStyleToContext(graphics, paintType, color);
538
-
539
- let adjustedX0 = x0;
540
- let adjustedY0 = y0;
541
- let adjustedX1 = x1;
542
- let adjustedY1 = y1;
543
- // Some bounding boxes have negative x0/y0 cordinates which will cause the
544
- // some of the drawing to be off of the canvas. To avoid this shift the
545
- // bounding box over.
546
- if (x0 < 0) {
547
- adjustedX0 = 0;
548
- adjustedX1 += Math.abs(x0);
549
- }
550
- if (y0 < 0) {
551
- adjustedY0 = 0;
552
- adjustedY1 += Math.abs(y0);
553
- }
554
- tmpCtx.translate(-(dimx.scale * adjustedX0), -(dimy.scale * adjustedY0));
555
- graphics.transform(dimx.scale, 0, 0, dimy.scale, 0, 0);
556
-
557
- this.clipBbox(graphics, adjustedX0, adjustedY0, adjustedX1, adjustedY1);
558
-
559
- graphics.baseTransform = graphics.ctx.mozCurrentTransform.slice();
560
-
561
- graphics.executeOperatorList(operatorList);
562
-
563
- graphics.endDrawing();
564
-
565
- return {
566
- canvas: tmpCanvas.canvas,
567
- scaleX: dimx.scale,
568
- scaleY: dimy.scale,
569
- offsetX: adjustedX0,
570
- offsetY: adjustedY0,
571
- };
572
- }
573
-
574
- getSizeAndScale(step, realOutputSize, scale) {
575
- // xstep / ystep may be negative -- normalize.
576
- step = Math.abs(step);
577
- // MAX_PATTERN_SIZE is used to avoid OOM situation.
578
- // Use the destination canvas's size if it is bigger than the hard-coded
579
- // limit of MAX_PATTERN_SIZE to avoid clipping patterns that cover the
580
- // whole canvas.
581
- const maxSize = Math.max(TilingPattern.MAX_PATTERN_SIZE, realOutputSize);
582
- let size = Math.ceil(step * scale);
583
- if (size >= maxSize) {
584
- size = maxSize;
585
- } else {
586
- scale = size / step;
587
- }
588
- return { scale, size };
589
- }
590
-
591
- clipBbox(graphics, x0, y0, x1, y1) {
592
- const bboxWidth = x1 - x0;
593
- const bboxHeight = y1 - y0;
594
- graphics.ctx.rect(x0, y0, bboxWidth, bboxHeight);
595
- graphics.clip();
596
- graphics.endPath();
597
- }
598
-
599
- setFillAndStrokeStyleToContext(graphics, paintType, color) {
600
- const context = graphics.ctx,
601
- current = graphics.current;
602
- switch (paintType) {
603
- case PaintType.COLORED:
604
- const ctx = this.ctx;
605
- context.fillStyle = ctx.fillStyle;
606
- context.strokeStyle = ctx.strokeStyle;
607
- current.fillColor = ctx.fillStyle;
608
- current.strokeColor = ctx.strokeStyle;
609
- break;
610
- case PaintType.UNCOLORED:
611
- const cssColor = Util.makeHexColor(color[0], color[1], color[2]);
612
- context.fillStyle = cssColor;
613
- context.strokeStyle = cssColor;
614
- // Set color needed by image masks (fixes issues 3226 and 8741).
615
- current.fillColor = cssColor;
616
- current.strokeColor = cssColor;
617
- break;
618
- default:
619
- throw new FormatError(`Unsupported paint type: ${paintType}`);
620
- }
621
- }
622
-
623
- getPattern(ctx, owner, inverse, shadingFill = false) {
624
- // PDF spec 8.7.2 NOTE 1: pattern's matrix is relative to initial matrix.
625
- let matrix = inverse;
626
- if (!shadingFill) {
627
- matrix = Util.transform(matrix, owner.baseTransform);
628
- if (this.matrix) {
629
- matrix = Util.transform(matrix, this.matrix);
630
- }
631
- }
632
-
633
- const temporaryPatternCanvas = this.createPatternCanvas(owner);
634
-
635
- let domMatrix = new DOMMatrix(matrix);
636
- // Rescale and so that the ctx.createPattern call generates a pattern with
637
- // the desired size.
638
- domMatrix = domMatrix.translate(
639
- temporaryPatternCanvas.offsetX,
640
- temporaryPatternCanvas.offsetY
641
- );
642
- domMatrix = domMatrix.scale(
643
- 1 / temporaryPatternCanvas.scaleX,
644
- 1 / temporaryPatternCanvas.scaleY
645
- );
646
-
647
- const pattern = ctx.createPattern(temporaryPatternCanvas.canvas, "repeat");
648
- try {
649
- pattern.setTransform(domMatrix);
650
- } catch (ex) {
651
- // Avoid rendering breaking completely in Firefox 78 ESR,
652
- // and in Node.js (see issue 13724).
653
- warn(`TilingPattern.getPattern: "${ex?.message}".`);
654
- }
655
- return pattern;
656
- }
657
- }
658
-
659
- export { getShadingPattern, TilingPattern };