@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,985 +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
- FormatError,
19
- info,
20
- shadow,
21
- unreachable,
22
- UNSUPPORTED_FEATURES,
23
- Util,
24
- warn,
25
- } from "../shared/util.js";
26
- import { ColorSpace } from "./colorspace.js";
27
- import { isStream } from "./primitives.js";
28
- import { MissingDataException } from "./core_utils.js";
29
-
30
- const ShadingType = {
31
- FUNCTION_BASED: 1,
32
- AXIAL: 2,
33
- RADIAL: 3,
34
- FREE_FORM_MESH: 4,
35
- LATTICE_FORM_MESH: 5,
36
- COONS_PATCH_MESH: 6,
37
- TENSOR_PATCH_MESH: 7,
38
- };
39
-
40
- class Pattern {
41
- constructor() {
42
- unreachable("Cannot initialize Pattern.");
43
- }
44
-
45
- static parseShading(
46
- shading,
47
- matrix,
48
- xref,
49
- res,
50
- handler,
51
- pdfFunctionFactory,
52
- localColorSpaceCache
53
- ) {
54
- const dict = isStream(shading) ? shading.dict : shading;
55
- const type = dict.get("ShadingType");
56
-
57
- try {
58
- switch (type) {
59
- case ShadingType.AXIAL:
60
- case ShadingType.RADIAL:
61
- return new RadialAxialShading(
62
- dict,
63
- matrix,
64
- xref,
65
- res,
66
- pdfFunctionFactory,
67
- localColorSpaceCache
68
- );
69
- case ShadingType.FREE_FORM_MESH:
70
- case ShadingType.LATTICE_FORM_MESH:
71
- case ShadingType.COONS_PATCH_MESH:
72
- case ShadingType.TENSOR_PATCH_MESH:
73
- return new MeshShading(
74
- shading,
75
- matrix,
76
- xref,
77
- res,
78
- pdfFunctionFactory,
79
- localColorSpaceCache
80
- );
81
- default:
82
- throw new FormatError("Unsupported ShadingType: " + type);
83
- }
84
- } catch (ex) {
85
- if (ex instanceof MissingDataException) {
86
- throw ex;
87
- }
88
- handler.send("UnsupportedFeature", {
89
- featureId: UNSUPPORTED_FEATURES.shadingPattern,
90
- });
91
- warn(ex);
92
- return new DummyShading();
93
- }
94
- }
95
- }
96
-
97
- class BaseShading {
98
- // A small number to offset the first/last color stops so we can insert ones
99
- // to support extend. Number.MIN_VALUE is too small and breaks the extend.
100
- static get SMALL_NUMBER() {
101
- return shadow(this, "SMALL_NUMBER", 1e-6);
102
- }
103
-
104
- constructor() {
105
- if (this.constructor === BaseShading) {
106
- unreachable("Cannot initialize BaseShading.");
107
- }
108
- }
109
-
110
- getIR() {
111
- unreachable("Abstract method `getIR` called.");
112
- }
113
- }
114
-
115
- // Radial and axial shading have very similar implementations
116
- // If needed, the implementations can be broken into two classes.
117
- class RadialAxialShading extends BaseShading {
118
- constructor(
119
- dict,
120
- matrix,
121
- xref,
122
- resources,
123
- pdfFunctionFactory,
124
- localColorSpaceCache
125
- ) {
126
- super();
127
- this.matrix = matrix;
128
- this.coordsArr = dict.getArray("Coords");
129
- this.shadingType = dict.get("ShadingType");
130
- const cs = ColorSpace.parse({
131
- cs: dict.getRaw("ColorSpace") || dict.getRaw("CS"),
132
- xref,
133
- resources,
134
- pdfFunctionFactory,
135
- localColorSpaceCache,
136
- });
137
- const bbox = dict.getArray("BBox");
138
- if (Array.isArray(bbox) && bbox.length === 4) {
139
- this.bbox = Util.normalizeRect(bbox);
140
- } else {
141
- this.bbox = null;
142
- }
143
-
144
- let t0 = 0.0,
145
- t1 = 1.0;
146
- if (dict.has("Domain")) {
147
- const domainArr = dict.getArray("Domain");
148
- t0 = domainArr[0];
149
- t1 = domainArr[1];
150
- }
151
-
152
- let extendStart = false,
153
- extendEnd = false;
154
- if (dict.has("Extend")) {
155
- const extendArr = dict.getArray("Extend");
156
- extendStart = extendArr[0];
157
- extendEnd = extendArr[1];
158
- }
159
-
160
- if (
161
- this.shadingType === ShadingType.RADIAL &&
162
- (!extendStart || !extendEnd)
163
- ) {
164
- // Radial gradient only currently works if either circle is fully within
165
- // the other circle.
166
- const [x1, y1, r1, x2, y2, r2] = this.coordsArr;
167
- const distance = Math.hypot(x1 - x2, y1 - y2);
168
- if (r1 <= r2 + distance && r2 <= r1 + distance) {
169
- warn("Unsupported radial gradient.");
170
- }
171
- }
172
-
173
- this.extendStart = extendStart;
174
- this.extendEnd = extendEnd;
175
-
176
- const fnObj = dict.getRaw("Function");
177
- const fn = pdfFunctionFactory.createFromArray(fnObj);
178
-
179
- // 10 samples seems good enough for now, but probably won't work
180
- // if there are sharp color changes. Ideally, we would implement
181
- // the spec faithfully and add lossless optimizations.
182
- const NUMBER_OF_SAMPLES = 10;
183
- const step = (t1 - t0) / NUMBER_OF_SAMPLES;
184
-
185
- const colorStops = (this.colorStops = []);
186
-
187
- // Protect against bad domains.
188
- if (t0 >= t1 || step <= 0) {
189
- // Acrobat doesn't seem to handle these cases so we'll ignore for
190
- // now.
191
- info("Bad shading domain.");
192
- return;
193
- }
194
-
195
- const color = new Float32Array(cs.numComps),
196
- ratio = new Float32Array(1);
197
- let rgbColor;
198
- for (let i = 0; i <= NUMBER_OF_SAMPLES; i++) {
199
- ratio[0] = t0 + i * step;
200
- fn(ratio, 0, color, 0);
201
- rgbColor = cs.getRgb(color, 0);
202
- const cssColor = Util.makeHexColor(rgbColor[0], rgbColor[1], rgbColor[2]);
203
- colorStops.push([i / NUMBER_OF_SAMPLES, cssColor]);
204
- }
205
-
206
- let background = "transparent";
207
- if (dict.has("Background")) {
208
- rgbColor = cs.getRgb(dict.get("Background"), 0);
209
- background = Util.makeHexColor(rgbColor[0], rgbColor[1], rgbColor[2]);
210
- }
211
-
212
- if (!extendStart) {
213
- // Insert a color stop at the front and offset the first real color stop
214
- // so it doesn't conflict with the one we insert.
215
- colorStops.unshift([0, background]);
216
- colorStops[1][0] += BaseShading.SMALL_NUMBER;
217
- }
218
- if (!extendEnd) {
219
- // Same idea as above in extendStart but for the end.
220
- colorStops[colorStops.length - 1][0] -= BaseShading.SMALL_NUMBER;
221
- colorStops.push([1, background]);
222
- }
223
-
224
- this.colorStops = colorStops;
225
- }
226
-
227
- getIR() {
228
- const coordsArr = this.coordsArr;
229
- const shadingType = this.shadingType;
230
- let type, p0, p1, r0, r1;
231
- if (shadingType === ShadingType.AXIAL) {
232
- p0 = [coordsArr[0], coordsArr[1]];
233
- p1 = [coordsArr[2], coordsArr[3]];
234
- r0 = null;
235
- r1 = null;
236
- type = "axial";
237
- } else if (shadingType === ShadingType.RADIAL) {
238
- p0 = [coordsArr[0], coordsArr[1]];
239
- p1 = [coordsArr[3], coordsArr[4]];
240
- r0 = coordsArr[2];
241
- r1 = coordsArr[5];
242
- type = "radial";
243
- } else {
244
- unreachable(`getPattern type unknown: ${shadingType}`);
245
- }
246
-
247
- return [
248
- "RadialAxial",
249
- type,
250
- this.bbox,
251
- this.colorStops,
252
- p0,
253
- p1,
254
- r0,
255
- r1,
256
- this.matrix,
257
- ];
258
- }
259
- }
260
-
261
- // All mesh shadings. For now, they will be presented as set of the triangles
262
- // to be drawn on the canvas and rgb color for each vertex.
263
- class MeshStreamReader {
264
- constructor(stream, context) {
265
- this.stream = stream;
266
- this.context = context;
267
- this.buffer = 0;
268
- this.bufferLength = 0;
269
-
270
- const numComps = context.numComps;
271
- this.tmpCompsBuf = new Float32Array(numComps);
272
- const csNumComps = context.colorSpace.numComps;
273
- this.tmpCsCompsBuf = context.colorFn
274
- ? new Float32Array(csNumComps)
275
- : this.tmpCompsBuf;
276
- }
277
-
278
- get hasData() {
279
- if (this.stream.end) {
280
- return this.stream.pos < this.stream.end;
281
- }
282
- if (this.bufferLength > 0) {
283
- return true;
284
- }
285
- const nextByte = this.stream.getByte();
286
- if (nextByte < 0) {
287
- return false;
288
- }
289
- this.buffer = nextByte;
290
- this.bufferLength = 8;
291
- return true;
292
- }
293
-
294
- readBits(n) {
295
- let buffer = this.buffer;
296
- let bufferLength = this.bufferLength;
297
- if (n === 32) {
298
- if (bufferLength === 0) {
299
- return (
300
- ((this.stream.getByte() << 24) |
301
- (this.stream.getByte() << 16) |
302
- (this.stream.getByte() << 8) |
303
- this.stream.getByte()) >>>
304
- 0
305
- );
306
- }
307
- buffer =
308
- (buffer << 24) |
309
- (this.stream.getByte() << 16) |
310
- (this.stream.getByte() << 8) |
311
- this.stream.getByte();
312
- const nextByte = this.stream.getByte();
313
- this.buffer = nextByte & ((1 << bufferLength) - 1);
314
- return (
315
- ((buffer << (8 - bufferLength)) |
316
- ((nextByte & 0xff) >> bufferLength)) >>>
317
- 0
318
- );
319
- }
320
- if (n === 8 && bufferLength === 0) {
321
- return this.stream.getByte();
322
- }
323
- while (bufferLength < n) {
324
- buffer = (buffer << 8) | this.stream.getByte();
325
- bufferLength += 8;
326
- }
327
- bufferLength -= n;
328
- this.bufferLength = bufferLength;
329
- this.buffer = buffer & ((1 << bufferLength) - 1);
330
- return buffer >> bufferLength;
331
- }
332
-
333
- align() {
334
- this.buffer = 0;
335
- this.bufferLength = 0;
336
- }
337
-
338
- readFlag() {
339
- return this.readBits(this.context.bitsPerFlag);
340
- }
341
-
342
- readCoordinate() {
343
- const bitsPerCoordinate = this.context.bitsPerCoordinate;
344
- const xi = this.readBits(bitsPerCoordinate);
345
- const yi = this.readBits(bitsPerCoordinate);
346
- const decode = this.context.decode;
347
- const scale =
348
- bitsPerCoordinate < 32
349
- ? 1 / ((1 << bitsPerCoordinate) - 1)
350
- : 2.3283064365386963e-10; // 2 ^ -32
351
- return [
352
- xi * scale * (decode[1] - decode[0]) + decode[0],
353
- yi * scale * (decode[3] - decode[2]) + decode[2],
354
- ];
355
- }
356
-
357
- readComponents() {
358
- const numComps = this.context.numComps;
359
- const bitsPerComponent = this.context.bitsPerComponent;
360
- const scale =
361
- bitsPerComponent < 32
362
- ? 1 / ((1 << bitsPerComponent) - 1)
363
- : 2.3283064365386963e-10; // 2 ^ -32
364
- const decode = this.context.decode;
365
- const components = this.tmpCompsBuf;
366
- for (let i = 0, j = 4; i < numComps; i++, j += 2) {
367
- const ci = this.readBits(bitsPerComponent);
368
- components[i] = ci * scale * (decode[j + 1] - decode[j]) + decode[j];
369
- }
370
- const color = this.tmpCsCompsBuf;
371
- if (this.context.colorFn) {
372
- this.context.colorFn(components, 0, color, 0);
373
- }
374
- return this.context.colorSpace.getRgb(color, 0);
375
- }
376
- }
377
-
378
- const getB = (function getBClosure() {
379
- function buildB(count) {
380
- const lut = [];
381
- for (let i = 0; i <= count; i++) {
382
- const t = i / count,
383
- t_ = 1 - t;
384
- lut.push(
385
- new Float32Array([
386
- t_ * t_ * t_,
387
- 3 * t * t_ * t_,
388
- 3 * t * t * t_,
389
- t * t * t,
390
- ])
391
- );
392
- }
393
- return lut;
394
- }
395
- const cache = [];
396
-
397
- return function (count) {
398
- if (!cache[count]) {
399
- cache[count] = buildB(count);
400
- }
401
- return cache[count];
402
- };
403
- })();
404
-
405
- class MeshShading extends BaseShading {
406
- static get MIN_SPLIT_PATCH_CHUNKS_AMOUNT() {
407
- return shadow(this, "MIN_SPLIT_PATCH_CHUNKS_AMOUNT", 3);
408
- }
409
-
410
- static get MAX_SPLIT_PATCH_CHUNKS_AMOUNT() {
411
- return shadow(this, "MAX_SPLIT_PATCH_CHUNKS_AMOUNT", 20);
412
- }
413
-
414
- // Count of triangles per entire mesh bounds.
415
- static get TRIANGLE_DENSITY() {
416
- return shadow(this, "TRIANGLE_DENSITY", 20);
417
- }
418
-
419
- constructor(
420
- stream,
421
- matrix,
422
- xref,
423
- resources,
424
- pdfFunctionFactory,
425
- localColorSpaceCache
426
- ) {
427
- super();
428
- if (!isStream(stream)) {
429
- throw new FormatError("Mesh data is not a stream");
430
- }
431
- const dict = stream.dict;
432
- this.matrix = matrix;
433
- this.shadingType = dict.get("ShadingType");
434
- const bbox = dict.getArray("BBox");
435
- if (Array.isArray(bbox) && bbox.length === 4) {
436
- this.bbox = Util.normalizeRect(bbox);
437
- } else {
438
- this.bbox = null;
439
- }
440
- const cs = ColorSpace.parse({
441
- cs: dict.getRaw("ColorSpace") || dict.getRaw("CS"),
442
- xref,
443
- resources,
444
- pdfFunctionFactory,
445
- localColorSpaceCache,
446
- });
447
- this.background = dict.has("Background")
448
- ? cs.getRgb(dict.get("Background"), 0)
449
- : null;
450
-
451
- const fnObj = dict.getRaw("Function");
452
- const fn = fnObj ? pdfFunctionFactory.createFromArray(fnObj) : null;
453
-
454
- this.coords = [];
455
- this.colors = [];
456
- this.figures = [];
457
-
458
- const decodeContext = {
459
- bitsPerCoordinate: dict.get("BitsPerCoordinate"),
460
- bitsPerComponent: dict.get("BitsPerComponent"),
461
- bitsPerFlag: dict.get("BitsPerFlag"),
462
- decode: dict.getArray("Decode"),
463
- colorFn: fn,
464
- colorSpace: cs,
465
- numComps: fn ? 1 : cs.numComps,
466
- };
467
- const reader = new MeshStreamReader(stream, decodeContext);
468
-
469
- let patchMesh = false;
470
- switch (this.shadingType) {
471
- case ShadingType.FREE_FORM_MESH:
472
- this._decodeType4Shading(reader);
473
- break;
474
- case ShadingType.LATTICE_FORM_MESH:
475
- const verticesPerRow = dict.get("VerticesPerRow") | 0;
476
- if (verticesPerRow < 2) {
477
- throw new FormatError("Invalid VerticesPerRow");
478
- }
479
- this._decodeType5Shading(reader, verticesPerRow);
480
- break;
481
- case ShadingType.COONS_PATCH_MESH:
482
- this._decodeType6Shading(reader);
483
- patchMesh = true;
484
- break;
485
- case ShadingType.TENSOR_PATCH_MESH:
486
- this._decodeType7Shading(reader);
487
- patchMesh = true;
488
- break;
489
- default:
490
- unreachable("Unsupported mesh type.");
491
- break;
492
- }
493
-
494
- if (patchMesh) {
495
- // Dirty bounds calculation, to determine how dense the triangles will be.
496
- this._updateBounds();
497
- for (let i = 0, ii = this.figures.length; i < ii; i++) {
498
- this._buildFigureFromPatch(i);
499
- }
500
- }
501
- // Calculate bounds.
502
- this._updateBounds();
503
-
504
- this._packData();
505
- }
506
-
507
- _decodeType4Shading(reader) {
508
- const coords = this.coords;
509
- const colors = this.colors;
510
- const operators = [];
511
- const ps = []; // not maintaining cs since that will match ps
512
- let verticesLeft = 0; // assuming we have all data to start a new triangle
513
- while (reader.hasData) {
514
- const f = reader.readFlag();
515
- const coord = reader.readCoordinate();
516
- const color = reader.readComponents();
517
- if (verticesLeft === 0) {
518
- // ignoring flags if we started a triangle
519
- if (!(0 <= f && f <= 2)) {
520
- throw new FormatError("Unknown type4 flag");
521
- }
522
- switch (f) {
523
- case 0:
524
- verticesLeft = 3;
525
- break;
526
- case 1:
527
- ps.push(ps[ps.length - 2], ps[ps.length - 1]);
528
- verticesLeft = 1;
529
- break;
530
- case 2:
531
- ps.push(ps[ps.length - 3], ps[ps.length - 1]);
532
- verticesLeft = 1;
533
- break;
534
- }
535
- operators.push(f);
536
- }
537
- ps.push(coords.length);
538
- coords.push(coord);
539
- colors.push(color);
540
- verticesLeft--;
541
-
542
- reader.align();
543
- }
544
- this.figures.push({
545
- type: "triangles",
546
- coords: new Int32Array(ps),
547
- colors: new Int32Array(ps),
548
- });
549
- }
550
-
551
- _decodeType5Shading(reader, verticesPerRow) {
552
- const coords = this.coords;
553
- const colors = this.colors;
554
- const ps = []; // not maintaining cs since that will match ps
555
- while (reader.hasData) {
556
- const coord = reader.readCoordinate();
557
- const color = reader.readComponents();
558
- ps.push(coords.length);
559
- coords.push(coord);
560
- colors.push(color);
561
- }
562
- this.figures.push({
563
- type: "lattice",
564
- coords: new Int32Array(ps),
565
- colors: new Int32Array(ps),
566
- verticesPerRow,
567
- });
568
- }
569
-
570
- _decodeType6Shading(reader) {
571
- // A special case of Type 7. The p11, p12, p21, p22 automatically filled
572
- const coords = this.coords;
573
- const colors = this.colors;
574
- const ps = new Int32Array(16); // p00, p10, ..., p30, p01, ..., p33
575
- const cs = new Int32Array(4); // c00, c30, c03, c33
576
- while (reader.hasData) {
577
- const f = reader.readFlag();
578
- if (!(0 <= f && f <= 3)) {
579
- throw new FormatError("Unknown type6 flag");
580
- }
581
- const pi = coords.length;
582
- for (let i = 0, ii = f !== 0 ? 8 : 12; i < ii; i++) {
583
- coords.push(reader.readCoordinate());
584
- }
585
- const ci = colors.length;
586
- for (let i = 0, ii = f !== 0 ? 2 : 4; i < ii; i++) {
587
- colors.push(reader.readComponents());
588
- }
589
- let tmp1, tmp2, tmp3, tmp4;
590
- switch (f) {
591
- // prettier-ignore
592
- case 0:
593
- ps[12] = pi + 3; ps[13] = pi + 4; ps[14] = pi + 5; ps[15] = pi + 6;
594
- ps[ 8] = pi + 2; /* values for 5, 6, 9, 10 are */ ps[11] = pi + 7;
595
- ps[ 4] = pi + 1; /* calculated below */ ps[ 7] = pi + 8;
596
- ps[ 0] = pi; ps[ 1] = pi + 11; ps[ 2] = pi + 10; ps[ 3] = pi + 9;
597
- cs[2] = ci + 1; cs[3] = ci + 2;
598
- cs[0] = ci; cs[1] = ci + 3;
599
- break;
600
- // prettier-ignore
601
- case 1:
602
- tmp1 = ps[12]; tmp2 = ps[13]; tmp3 = ps[14]; tmp4 = ps[15];
603
- ps[12] = tmp4; ps[13] = pi + 0; ps[14] = pi + 1; ps[15] = pi + 2;
604
- ps[ 8] = tmp3; /* values for 5, 6, 9, 10 are */ ps[11] = pi + 3;
605
- ps[ 4] = tmp2; /* calculated below */ ps[ 7] = pi + 4;
606
- ps[ 0] = tmp1; ps[ 1] = pi + 7; ps[ 2] = pi + 6; ps[ 3] = pi + 5;
607
- tmp1 = cs[2]; tmp2 = cs[3];
608
- cs[2] = tmp2; cs[3] = ci;
609
- cs[0] = tmp1; cs[1] = ci + 1;
610
- break;
611
- // prettier-ignore
612
- case 2:
613
- tmp1 = ps[15];
614
- tmp2 = ps[11];
615
- ps[12] = ps[3]; ps[13] = pi + 0; ps[14] = pi + 1; ps[15] = pi + 2;
616
- ps[ 8] = ps[7]; /* values for 5, 6, 9, 10 are */ ps[11] = pi + 3;
617
- ps[ 4] = tmp2; /* calculated below */ ps[ 7] = pi + 4;
618
- ps[ 0] = tmp1; ps[ 1] = pi + 7; ps[ 2] = pi + 6; ps[ 3] = pi + 5;
619
- tmp1 = cs[3];
620
- cs[2] = cs[1]; cs[3] = ci;
621
- cs[0] = tmp1; cs[1] = ci + 1;
622
- break;
623
- // prettier-ignore
624
- case 3:
625
- ps[12] = ps[0]; ps[13] = pi + 0; ps[14] = pi + 1; ps[15] = pi + 2;
626
- ps[ 8] = ps[1]; /* values for 5, 6, 9, 10 are */ ps[11] = pi + 3;
627
- ps[ 4] = ps[2]; /* calculated below */ ps[ 7] = pi + 4;
628
- ps[ 0] = ps[3]; ps[ 1] = pi + 7; ps[ 2] = pi + 6; ps[ 3] = pi + 5;
629
- cs[2] = cs[0]; cs[3] = ci;
630
- cs[0] = cs[1]; cs[1] = ci + 1;
631
- break;
632
- }
633
- // set p11, p12, p21, p22
634
- ps[5] = coords.length;
635
- coords.push([
636
- (-4 * coords[ps[0]][0] -
637
- coords[ps[15]][0] +
638
- 6 * (coords[ps[4]][0] + coords[ps[1]][0]) -
639
- 2 * (coords[ps[12]][0] + coords[ps[3]][0]) +
640
- 3 * (coords[ps[13]][0] + coords[ps[7]][0])) /
641
- 9,
642
- (-4 * coords[ps[0]][1] -
643
- coords[ps[15]][1] +
644
- 6 * (coords[ps[4]][1] + coords[ps[1]][1]) -
645
- 2 * (coords[ps[12]][1] + coords[ps[3]][1]) +
646
- 3 * (coords[ps[13]][1] + coords[ps[7]][1])) /
647
- 9,
648
- ]);
649
- ps[6] = coords.length;
650
- coords.push([
651
- (-4 * coords[ps[3]][0] -
652
- coords[ps[12]][0] +
653
- 6 * (coords[ps[2]][0] + coords[ps[7]][0]) -
654
- 2 * (coords[ps[0]][0] + coords[ps[15]][0]) +
655
- 3 * (coords[ps[4]][0] + coords[ps[14]][0])) /
656
- 9,
657
- (-4 * coords[ps[3]][1] -
658
- coords[ps[12]][1] +
659
- 6 * (coords[ps[2]][1] + coords[ps[7]][1]) -
660
- 2 * (coords[ps[0]][1] + coords[ps[15]][1]) +
661
- 3 * (coords[ps[4]][1] + coords[ps[14]][1])) /
662
- 9,
663
- ]);
664
- ps[9] = coords.length;
665
- coords.push([
666
- (-4 * coords[ps[12]][0] -
667
- coords[ps[3]][0] +
668
- 6 * (coords[ps[8]][0] + coords[ps[13]][0]) -
669
- 2 * (coords[ps[0]][0] + coords[ps[15]][0]) +
670
- 3 * (coords[ps[11]][0] + coords[ps[1]][0])) /
671
- 9,
672
- (-4 * coords[ps[12]][1] -
673
- coords[ps[3]][1] +
674
- 6 * (coords[ps[8]][1] + coords[ps[13]][1]) -
675
- 2 * (coords[ps[0]][1] + coords[ps[15]][1]) +
676
- 3 * (coords[ps[11]][1] + coords[ps[1]][1])) /
677
- 9,
678
- ]);
679
- ps[10] = coords.length;
680
- coords.push([
681
- (-4 * coords[ps[15]][0] -
682
- coords[ps[0]][0] +
683
- 6 * (coords[ps[11]][0] + coords[ps[14]][0]) -
684
- 2 * (coords[ps[12]][0] + coords[ps[3]][0]) +
685
- 3 * (coords[ps[2]][0] + coords[ps[8]][0])) /
686
- 9,
687
- (-4 * coords[ps[15]][1] -
688
- coords[ps[0]][1] +
689
- 6 * (coords[ps[11]][1] + coords[ps[14]][1]) -
690
- 2 * (coords[ps[12]][1] + coords[ps[3]][1]) +
691
- 3 * (coords[ps[2]][1] + coords[ps[8]][1])) /
692
- 9,
693
- ]);
694
- this.figures.push({
695
- type: "patch",
696
- coords: new Int32Array(ps), // making copies of ps and cs
697
- colors: new Int32Array(cs),
698
- });
699
- }
700
- }
701
-
702
- _decodeType7Shading(reader) {
703
- const coords = this.coords;
704
- const colors = this.colors;
705
- const ps = new Int32Array(16); // p00, p10, ..., p30, p01, ..., p33
706
- const cs = new Int32Array(4); // c00, c30, c03, c33
707
- while (reader.hasData) {
708
- const f = reader.readFlag();
709
- if (!(0 <= f && f <= 3)) {
710
- throw new FormatError("Unknown type7 flag");
711
- }
712
- const pi = coords.length;
713
- for (let i = 0, ii = f !== 0 ? 12 : 16; i < ii; i++) {
714
- coords.push(reader.readCoordinate());
715
- }
716
- const ci = colors.length;
717
- for (let i = 0, ii = f !== 0 ? 2 : 4; i < ii; i++) {
718
- colors.push(reader.readComponents());
719
- }
720
- let tmp1, tmp2, tmp3, tmp4;
721
- switch (f) {
722
- // prettier-ignore
723
- case 0:
724
- ps[12] = pi + 3; ps[13] = pi + 4; ps[14] = pi + 5; ps[15] = pi + 6;
725
- ps[ 8] = pi + 2; ps[ 9] = pi + 13; ps[10] = pi + 14; ps[11] = pi + 7;
726
- ps[ 4] = pi + 1; ps[ 5] = pi + 12; ps[ 6] = pi + 15; ps[ 7] = pi + 8;
727
- ps[ 0] = pi; ps[ 1] = pi + 11; ps[ 2] = pi + 10; ps[ 3] = pi + 9;
728
- cs[2] = ci + 1; cs[3] = ci + 2;
729
- cs[0] = ci; cs[1] = ci + 3;
730
- break;
731
- // prettier-ignore
732
- case 1:
733
- tmp1 = ps[12]; tmp2 = ps[13]; tmp3 = ps[14]; tmp4 = ps[15];
734
- ps[12] = tmp4; ps[13] = pi + 0; ps[14] = pi + 1; ps[15] = pi + 2;
735
- ps[ 8] = tmp3; ps[ 9] = pi + 9; ps[10] = pi + 10; ps[11] = pi + 3;
736
- ps[ 4] = tmp2; ps[ 5] = pi + 8; ps[ 6] = pi + 11; ps[ 7] = pi + 4;
737
- ps[ 0] = tmp1; ps[ 1] = pi + 7; ps[ 2] = pi + 6; ps[ 3] = pi + 5;
738
- tmp1 = cs[2]; tmp2 = cs[3];
739
- cs[2] = tmp2; cs[3] = ci;
740
- cs[0] = tmp1; cs[1] = ci + 1;
741
- break;
742
- // prettier-ignore
743
- case 2:
744
- tmp1 = ps[15];
745
- tmp2 = ps[11];
746
- ps[12] = ps[3]; ps[13] = pi + 0; ps[14] = pi + 1; ps[15] = pi + 2;
747
- ps[ 8] = ps[7]; ps[ 9] = pi + 9; ps[10] = pi + 10; ps[11] = pi + 3;
748
- ps[ 4] = tmp2; ps[ 5] = pi + 8; ps[ 6] = pi + 11; ps[ 7] = pi + 4;
749
- ps[ 0] = tmp1; ps[ 1] = pi + 7; ps[ 2] = pi + 6; ps[ 3] = pi + 5;
750
- tmp1 = cs[3];
751
- cs[2] = cs[1]; cs[3] = ci;
752
- cs[0] = tmp1; cs[1] = ci + 1;
753
- break;
754
- // prettier-ignore
755
- case 3:
756
- ps[12] = ps[0]; ps[13] = pi + 0; ps[14] = pi + 1; ps[15] = pi + 2;
757
- ps[ 8] = ps[1]; ps[ 9] = pi + 9; ps[10] = pi + 10; ps[11] = pi + 3;
758
- ps[ 4] = ps[2]; ps[ 5] = pi + 8; ps[ 6] = pi + 11; ps[ 7] = pi + 4;
759
- ps[ 0] = ps[3]; ps[ 1] = pi + 7; ps[ 2] = pi + 6; ps[ 3] = pi + 5;
760
- cs[2] = cs[0]; cs[3] = ci;
761
- cs[0] = cs[1]; cs[1] = ci + 1;
762
- break;
763
- }
764
- this.figures.push({
765
- type: "patch",
766
- coords: new Int32Array(ps), // making copies of ps and cs
767
- colors: new Int32Array(cs),
768
- });
769
- }
770
- }
771
-
772
- _buildFigureFromPatch(index) {
773
- const figure = this.figures[index];
774
- assert(figure.type === "patch", "Unexpected patch mesh figure");
775
-
776
- const coords = this.coords,
777
- colors = this.colors;
778
- const pi = figure.coords;
779
- const ci = figure.colors;
780
-
781
- const figureMinX = Math.min(
782
- coords[pi[0]][0],
783
- coords[pi[3]][0],
784
- coords[pi[12]][0],
785
- coords[pi[15]][0]
786
- );
787
- const figureMinY = Math.min(
788
- coords[pi[0]][1],
789
- coords[pi[3]][1],
790
- coords[pi[12]][1],
791
- coords[pi[15]][1]
792
- );
793
- const figureMaxX = Math.max(
794
- coords[pi[0]][0],
795
- coords[pi[3]][0],
796
- coords[pi[12]][0],
797
- coords[pi[15]][0]
798
- );
799
- const figureMaxY = Math.max(
800
- coords[pi[0]][1],
801
- coords[pi[3]][1],
802
- coords[pi[12]][1],
803
- coords[pi[15]][1]
804
- );
805
- let splitXBy = Math.ceil(
806
- ((figureMaxX - figureMinX) * MeshShading.TRIANGLE_DENSITY) /
807
- (this.bounds[2] - this.bounds[0])
808
- );
809
- splitXBy = Math.max(
810
- MeshShading.MIN_SPLIT_PATCH_CHUNKS_AMOUNT,
811
- Math.min(MeshShading.MAX_SPLIT_PATCH_CHUNKS_AMOUNT, splitXBy)
812
- );
813
- let splitYBy = Math.ceil(
814
- ((figureMaxY - figureMinY) * MeshShading.TRIANGLE_DENSITY) /
815
- (this.bounds[3] - this.bounds[1])
816
- );
817
- splitYBy = Math.max(
818
- MeshShading.MIN_SPLIT_PATCH_CHUNKS_AMOUNT,
819
- Math.min(MeshShading.MAX_SPLIT_PATCH_CHUNKS_AMOUNT, splitYBy)
820
- );
821
-
822
- const verticesPerRow = splitXBy + 1;
823
- const figureCoords = new Int32Array((splitYBy + 1) * verticesPerRow);
824
- const figureColors = new Int32Array((splitYBy + 1) * verticesPerRow);
825
- let k = 0;
826
- const cl = new Uint8Array(3),
827
- cr = new Uint8Array(3);
828
- const c0 = colors[ci[0]],
829
- c1 = colors[ci[1]],
830
- c2 = colors[ci[2]],
831
- c3 = colors[ci[3]];
832
- const bRow = getB(splitYBy),
833
- bCol = getB(splitXBy);
834
- for (let row = 0; row <= splitYBy; row++) {
835
- cl[0] = ((c0[0] * (splitYBy - row) + c2[0] * row) / splitYBy) | 0;
836
- cl[1] = ((c0[1] * (splitYBy - row) + c2[1] * row) / splitYBy) | 0;
837
- cl[2] = ((c0[2] * (splitYBy - row) + c2[2] * row) / splitYBy) | 0;
838
-
839
- cr[0] = ((c1[0] * (splitYBy - row) + c3[0] * row) / splitYBy) | 0;
840
- cr[1] = ((c1[1] * (splitYBy - row) + c3[1] * row) / splitYBy) | 0;
841
- cr[2] = ((c1[2] * (splitYBy - row) + c3[2] * row) / splitYBy) | 0;
842
-
843
- for (let col = 0; col <= splitXBy; col++, k++) {
844
- if (
845
- (row === 0 || row === splitYBy) &&
846
- (col === 0 || col === splitXBy)
847
- ) {
848
- continue;
849
- }
850
- let x = 0,
851
- y = 0;
852
- let q = 0;
853
- for (let i = 0; i <= 3; i++) {
854
- for (let j = 0; j <= 3; j++, q++) {
855
- const m = bRow[row][i] * bCol[col][j];
856
- x += coords[pi[q]][0] * m;
857
- y += coords[pi[q]][1] * m;
858
- }
859
- }
860
- figureCoords[k] = coords.length;
861
- coords.push([x, y]);
862
- figureColors[k] = colors.length;
863
- const newColor = new Uint8Array(3);
864
- newColor[0] = ((cl[0] * (splitXBy - col) + cr[0] * col) / splitXBy) | 0;
865
- newColor[1] = ((cl[1] * (splitXBy - col) + cr[1] * col) / splitXBy) | 0;
866
- newColor[2] = ((cl[2] * (splitXBy - col) + cr[2] * col) / splitXBy) | 0;
867
- colors.push(newColor);
868
- }
869
- }
870
- figureCoords[0] = pi[0];
871
- figureColors[0] = ci[0];
872
- figureCoords[splitXBy] = pi[3];
873
- figureColors[splitXBy] = ci[1];
874
- figureCoords[verticesPerRow * splitYBy] = pi[12];
875
- figureColors[verticesPerRow * splitYBy] = ci[2];
876
- figureCoords[verticesPerRow * splitYBy + splitXBy] = pi[15];
877
- figureColors[verticesPerRow * splitYBy + splitXBy] = ci[3];
878
-
879
- this.figures[index] = {
880
- type: "lattice",
881
- coords: figureCoords,
882
- colors: figureColors,
883
- verticesPerRow,
884
- };
885
- }
886
-
887
- _updateBounds() {
888
- let minX = this.coords[0][0],
889
- minY = this.coords[0][1],
890
- maxX = minX,
891
- maxY = minY;
892
- for (let i = 1, ii = this.coords.length; i < ii; i++) {
893
- const x = this.coords[i][0],
894
- y = this.coords[i][1];
895
- minX = minX > x ? x : minX;
896
- minY = minY > y ? y : minY;
897
- maxX = maxX < x ? x : maxX;
898
- maxY = maxY < y ? y : maxY;
899
- }
900
- this.bounds = [minX, minY, maxX, maxY];
901
- }
902
-
903
- _packData() {
904
- let i, ii, j, jj;
905
-
906
- const coords = this.coords;
907
- const coordsPacked = new Float32Array(coords.length * 2);
908
- for (i = 0, j = 0, ii = coords.length; i < ii; i++) {
909
- const xy = coords[i];
910
- coordsPacked[j++] = xy[0];
911
- coordsPacked[j++] = xy[1];
912
- }
913
- this.coords = coordsPacked;
914
-
915
- const colors = this.colors;
916
- const colorsPacked = new Uint8Array(colors.length * 3);
917
- for (i = 0, j = 0, ii = colors.length; i < ii; i++) {
918
- const c = colors[i];
919
- colorsPacked[j++] = c[0];
920
- colorsPacked[j++] = c[1];
921
- colorsPacked[j++] = c[2];
922
- }
923
- this.colors = colorsPacked;
924
-
925
- const figures = this.figures;
926
- for (i = 0, ii = figures.length; i < ii; i++) {
927
- const figure = figures[i],
928
- ps = figure.coords,
929
- cs = figure.colors;
930
- for (j = 0, jj = ps.length; j < jj; j++) {
931
- ps[j] *= 2;
932
- cs[j] *= 3;
933
- }
934
- }
935
- }
936
-
937
- getIR() {
938
- return [
939
- "Mesh",
940
- this.shadingType,
941
- this.coords,
942
- this.colors,
943
- this.figures,
944
- this.bounds,
945
- this.matrix,
946
- this.bbox,
947
- this.background,
948
- ];
949
- }
950
- }
951
-
952
- class DummyShading extends BaseShading {
953
- getIR() {
954
- return ["Dummy"];
955
- }
956
- }
957
-
958
- function getTilingPatternIR(operatorList, dict, color) {
959
- const matrix = dict.getArray("Matrix");
960
- const bbox = Util.normalizeRect(dict.getArray("BBox"));
961
- const xstep = dict.get("XStep");
962
- const ystep = dict.get("YStep");
963
- const paintType = dict.get("PaintType");
964
- const tilingType = dict.get("TilingType");
965
-
966
- // Ensure that the pattern has a non-zero width and height, to prevent errors
967
- // in `pattern_helper.js` (fixes issue8330.pdf).
968
- if (bbox[2] - bbox[0] === 0 || bbox[3] - bbox[1] === 0) {
969
- throw new FormatError(`Invalid getTilingPatternIR /BBox array: [${bbox}].`);
970
- }
971
-
972
- return [
973
- "TilingPattern",
974
- color,
975
- operatorList,
976
- matrix,
977
- bbox,
978
- xstep,
979
- ystep,
980
- paintType,
981
- tilingType,
982
- ];
983
- }
984
-
985
- export { getTilingPatternIR, Pattern };