pdfjs-dist 2.0.489 → 2.2.228
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.
Potentially problematic release.
This version of pdfjs-dist might be problematic. Click here for more details.
- package/CODE_OF_CONDUCT.md +15 -0
- package/bower.json +1 -1
- package/build/pdf.js +18515 -11402
- package/build/pdf.js.map +1 -1
- package/build/pdf.min.js +1 -1
- package/build/pdf.worker.js +48266 -37137
- package/build/pdf.worker.js.map +1 -1
- package/build/pdf.worker.min.js +1 -1
- package/external/url/url-lib.js +627 -0
- package/image_decoders/pdf.image_decoders.js +11350 -0
- package/image_decoders/pdf.image_decoders.js.map +1 -0
- package/image_decoders/pdf.image_decoders.min.js +1 -0
- package/lib/core/annotation.js +587 -242
- package/lib/core/arithmetic_decoder.js +275 -245
- package/lib/core/bidi.js +65 -6
- package/lib/core/ccitt.js +173 -18
- package/lib/core/ccitt_stream.js +15 -6
- package/lib/core/cff_parser.js +433 -61
- package/lib/core/charsets.js +5 -4
- package/lib/core/chunked_stream.js +400 -152
- package/lib/core/cmap.js +326 -87
- package/lib/core/colorspace.js +874 -594
- package/lib/core/core_utils.js +147 -0
- package/lib/core/crypto.js +290 -45
- package/lib/core/document.js +560 -268
- package/lib/core/encodings.js +19 -10
- package/lib/core/evaluator.js +1005 -360
- package/lib/core/font_renderer.js +331 -97
- package/lib/core/fonts.js +812 -195
- package/lib/core/function.js +284 -71
- package/lib/core/glyphlist.js +4 -3
- package/lib/core/image.js +169 -62
- package/lib/core/image_utils.js +111 -0
- package/lib/core/jbig2.js +479 -66
- package/lib/core/jbig2_stream.js +19 -8
- package/lib/core/jpeg_stream.js +38 -13
- package/lib/core/jpg.js +253 -29
- package/lib/core/jpx.js +396 -6
- package/lib/core/jpx_stream.js +18 -6
- package/lib/core/metrics.js +15 -15
- package/lib/core/murmurhash3.js +56 -34
- package/lib/core/obj.js +1354 -488
- package/lib/core/operator_list.js +144 -31
- package/lib/core/parser.js +539 -191
- package/lib/core/pattern.js +148 -14
- package/lib/core/pdf_manager.js +323 -133
- package/lib/core/primitives.js +111 -24
- package/lib/core/ps_parser.js +134 -45
- package/lib/core/standard_fonts.js +17 -17
- package/lib/core/stream.js +313 -34
- package/lib/core/type1_parser.js +143 -13
- package/lib/core/unicode.js +32 -5
- package/lib/core/worker.js +217 -190
- package/lib/core/worker_stream.js +277 -0
- package/lib/display/annotation_layer.js +450 -133
- package/lib/display/api.js +1597 -784
- package/lib/display/api_compatibility.js +11 -13
- package/lib/display/canvas.js +360 -44
- package/lib/display/content_disposition.js +83 -32
- package/lib/display/display_utils.js +747 -0
- package/lib/display/fetch_stream.js +221 -90
- package/lib/display/font_loader.js +468 -236
- package/lib/display/metadata.js +38 -16
- package/lib/display/network.js +635 -428
- package/lib/display/network_utils.js +32 -19
- package/lib/display/node_stream.js +367 -175
- package/lib/display/pattern_helper.js +81 -31
- package/lib/display/svg.js +1235 -519
- package/lib/display/text_layer.js +153 -29
- package/lib/display/transport_stream.js +345 -94
- package/lib/display/webgl.js +64 -18
- package/lib/display/worker_options.js +5 -4
- package/lib/display/xml_parser.js +166 -53
- package/lib/examples/node/domstubs.js +60 -4
- package/lib/pdf.js +36 -14
- package/lib/pdf.worker.js +5 -3
- package/lib/shared/compatibility.js +158 -564
- package/lib/shared/global_scope.js +2 -2
- package/lib/shared/is_node.js +4 -4
- package/lib/shared/message_handler.js +521 -0
- package/lib/shared/streams_polyfill.js +21 -17
- package/lib/shared/url_polyfill.js +56 -0
- package/lib/shared/util.js +243 -710
- package/lib/test/unit/annotation_spec.js +870 -401
- package/lib/test/unit/api_spec.js +657 -345
- package/lib/test/unit/bidi_spec.js +7 -7
- package/lib/test/unit/cff_parser_spec.js +54 -11
- package/lib/test/unit/clitests_helper.js +10 -8
- package/lib/test/unit/cmap_spec.js +95 -41
- package/lib/test/unit/colorspace_spec.js +115 -63
- package/lib/test/unit/core_utils_spec.js +191 -0
- package/lib/test/unit/crypto_spec.js +17 -5
- package/lib/test/unit/custom_spec.js +43 -55
- package/lib/test/unit/display_svg_spec.js +34 -18
- package/lib/test/unit/display_utils_spec.js +273 -0
- package/lib/test/unit/document_spec.js +8 -13
- package/lib/test/unit/encodings_spec.js +25 -45
- package/lib/test/unit/evaluator_spec.js +38 -15
- package/lib/test/unit/fetch_stream_spec.js +109 -0
- package/lib/test/unit/function_spec.js +17 -5
- package/lib/test/unit/jasmine-boot.js +33 -20
- package/lib/test/unit/{util_stream_spec.js → message_handler_spec.js} +41 -69
- package/lib/test/unit/metadata_spec.js +71 -11
- package/lib/test/unit/murmurhash3_spec.js +3 -3
- package/lib/test/unit/network_spec.js +19 -54
- package/lib/test/unit/network_utils_spec.js +91 -14
- package/lib/test/unit/node_stream_spec.js +56 -32
- package/lib/test/unit/parser_spec.js +162 -71
- package/lib/test/unit/pdf_find_controller_spec.js +230 -0
- package/lib/test/unit/pdf_find_utils_spec.js +63 -0
- package/lib/test/unit/pdf_history_spec.js +21 -9
- package/lib/test/unit/primitives_spec.js +53 -20
- package/lib/test/unit/stream_spec.js +12 -4
- package/lib/test/unit/test_utils.js +273 -56
- package/lib/test/unit/testreporter.js +21 -3
- package/lib/test/unit/type1_parser_spec.js +8 -6
- package/lib/test/unit/ui_utils_spec.js +454 -16
- package/lib/test/unit/unicode_spec.js +18 -15
- package/lib/test/unit/util_spec.js +87 -128
- package/lib/web/annotation_layer_builder.js +39 -22
- package/lib/web/app.js +1290 -588
- package/lib/web/app_options.js +100 -62
- package/lib/web/base_viewer.js +511 -182
- package/lib/web/chromecom.js +261 -117
- package/lib/web/debugger.js +166 -22
- package/lib/web/download_manager.js +32 -13
- package/lib/web/firefox_print_service.js +20 -10
- package/lib/web/firefoxcom.js +315 -80
- package/lib/web/genericcom.js +89 -30
- package/lib/web/genericl10n.js +142 -30
- package/lib/web/grab_to_pan.js +28 -4
- package/lib/web/interfaces.js +170 -47
- package/lib/web/overlay_manager.js +235 -85
- package/lib/web/password_prompt.js +22 -14
- package/lib/web/pdf_attachment_viewer.js +38 -18
- package/lib/web/pdf_cursor_tools.js +39 -16
- package/lib/web/pdf_document_properties.js +255 -136
- package/lib/web/pdf_find_bar.js +84 -40
- package/lib/web/pdf_find_controller.js +495 -184
- package/lib/web/pdf_find_utils.js +111 -0
- package/lib/web/pdf_history.js +190 -53
- package/lib/web/pdf_link_service.js +138 -77
- package/lib/web/pdf_outline_viewer.js +122 -46
- package/lib/web/pdf_page_view.js +191 -67
- package/lib/web/pdf_presentation_mode.js +99 -34
- package/lib/web/pdf_print_service.js +61 -13
- package/lib/web/pdf_rendering_queue.js +28 -9
- package/lib/web/pdf_sidebar.js +141 -81
- package/lib/web/pdf_sidebar_resizer.js +42 -16
- package/lib/web/pdf_single_page_viewer.js +74 -66
- package/lib/web/pdf_thumbnail_view.js +104 -33
- package/lib/web/pdf_thumbnail_viewer.js +66 -26
- package/lib/web/pdf_viewer.component.js +112 -32
- package/lib/web/pdf_viewer.js +91 -52
- package/lib/web/preferences.js +284 -89
- package/lib/web/secondary_toolbar.js +165 -40
- package/lib/web/text_layer_builder.js +134 -59
- package/lib/web/toolbar.js +78 -43
- package/lib/web/ui_utils.js +462 -136
- package/lib/web/view_history.js +215 -67
- package/lib/web/viewer_compatibility.js +4 -13
- package/package.json +5 -4
- package/web/pdf_viewer.css +79 -11
- package/web/pdf_viewer.js +6107 -3748
- package/web/pdf_viewer.js.map +1 -1
- package/lib/display/dom_utils.js +0 -309
- package/lib/test/unit/dom_utils_spec.js +0 -89
- package/lib/test/unit/fonts_spec.js +0 -81
- package/lib/web/dom_events.js +0 -137
package/lib/core/pattern.js
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
* @licstart The following is the entire license notice for the
|
3
3
|
* Javascript code in this page
|
4
4
|
*
|
5
|
-
* Copyright
|
5
|
+
* Copyright 2019 Mozilla Foundation
|
6
6
|
*
|
7
7
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
8
8
|
* you may not use this file except in compliance with the License.
|
@@ -19,18 +19,21 @@
|
|
19
19
|
* @licend The above is the entire license notice for the
|
20
20
|
* Javascript code in this page
|
21
21
|
*/
|
22
|
-
|
22
|
+
"use strict";
|
23
23
|
|
24
24
|
Object.defineProperty(exports, "__esModule", {
|
25
25
|
value: true
|
26
26
|
});
|
27
|
-
exports.getTilingPatternIR =
|
27
|
+
exports.getTilingPatternIR = getTilingPatternIR;
|
28
|
+
exports.Pattern = void 0;
|
28
29
|
|
29
|
-
var _util = require(
|
30
|
+
var _util = require("../shared/util");
|
30
31
|
|
31
|
-
var _colorspace = require(
|
32
|
+
var _colorspace = require("./colorspace");
|
32
33
|
|
33
|
-
var _primitives = require(
|
34
|
+
var _primitives = require("./primitives");
|
35
|
+
|
36
|
+
var _core_utils = require("./core_utils");
|
34
37
|
|
35
38
|
var ShadingType = {
|
36
39
|
FUNCTION_BASED: 1,
|
@@ -41,44 +44,57 @@ var ShadingType = {
|
|
41
44
|
COONS_PATCH_MESH: 6,
|
42
45
|
TENSOR_PATCH_MESH: 7
|
43
46
|
};
|
47
|
+
|
44
48
|
var Pattern = function PatternClosure() {
|
45
49
|
function Pattern() {
|
46
50
|
(0, _util.unreachable)('should not call Pattern constructor');
|
47
51
|
}
|
52
|
+
|
48
53
|
Pattern.prototype = {
|
49
54
|
getPattern: function Pattern_getPattern(ctx) {
|
50
|
-
(0, _util.unreachable)(
|
55
|
+
(0, _util.unreachable)("Should not call Pattern.getStyle: ".concat(ctx));
|
51
56
|
}
|
52
57
|
};
|
58
|
+
|
53
59
|
Pattern.parseShading = function (shading, matrix, xref, res, handler, pdfFunctionFactory) {
|
54
60
|
var dict = (0, _primitives.isStream)(shading) ? shading.dict : shading;
|
55
61
|
var type = dict.get('ShadingType');
|
62
|
+
|
56
63
|
try {
|
57
64
|
switch (type) {
|
58
65
|
case ShadingType.AXIAL:
|
59
66
|
case ShadingType.RADIAL:
|
60
67
|
return new Shadings.RadialAxial(dict, matrix, xref, res, pdfFunctionFactory);
|
68
|
+
|
61
69
|
case ShadingType.FREE_FORM_MESH:
|
62
70
|
case ShadingType.LATTICE_FORM_MESH:
|
63
71
|
case ShadingType.COONS_PATCH_MESH:
|
64
72
|
case ShadingType.TENSOR_PATCH_MESH:
|
65
73
|
return new Shadings.Mesh(shading, matrix, xref, res, pdfFunctionFactory);
|
74
|
+
|
66
75
|
default:
|
67
76
|
throw new _util.FormatError('Unsupported ShadingType: ' + type);
|
68
77
|
}
|
69
78
|
} catch (ex) {
|
70
|
-
if (ex instanceof
|
79
|
+
if (ex instanceof _core_utils.MissingDataException) {
|
71
80
|
throw ex;
|
72
81
|
}
|
73
|
-
|
82
|
+
|
83
|
+
handler.send('UnsupportedFeature', {
|
84
|
+
featureId: _util.UNSUPPORTED_FEATURES.shadingPattern
|
85
|
+
});
|
74
86
|
(0, _util.warn)(ex);
|
75
87
|
return new Shadings.Dummy();
|
76
88
|
}
|
77
89
|
};
|
90
|
+
|
78
91
|
return Pattern;
|
79
92
|
}();
|
93
|
+
|
94
|
+
exports.Pattern = Pattern;
|
80
95
|
var Shadings = {};
|
81
96
|
Shadings.SMALL_NUMBER = 1e-6;
|
97
|
+
|
82
98
|
Shadings.RadialAxial = function RadialAxialClosure() {
|
83
99
|
function RadialAxial(dict, matrix, xref, res, pdfFunctionFactory) {
|
84
100
|
this.matrix = matrix;
|
@@ -90,18 +106,22 @@ Shadings.RadialAxial = function RadialAxialClosure() {
|
|
90
106
|
this.cs = cs;
|
91
107
|
var t0 = 0.0,
|
92
108
|
t1 = 1.0;
|
109
|
+
|
93
110
|
if (dict.has('Domain')) {
|
94
111
|
var domainArr = dict.getArray('Domain');
|
95
112
|
t0 = domainArr[0];
|
96
113
|
t1 = domainArr[1];
|
97
114
|
}
|
115
|
+
|
98
116
|
var extendStart = false,
|
99
117
|
extendEnd = false;
|
118
|
+
|
100
119
|
if (dict.has('Extend')) {
|
101
120
|
var extendArr = dict.getArray('Extend');
|
102
121
|
extendStart = extendArr[0];
|
103
122
|
extendEnd = extendArr[1];
|
104
123
|
}
|
124
|
+
|
105
125
|
if (this.shadingType === ShadingType.RADIAL && (!extendStart || !extendEnd)) {
|
106
126
|
var x1 = this.coordsArr[0];
|
107
127
|
var y1 = this.coordsArr[1];
|
@@ -110,10 +130,12 @@ Shadings.RadialAxial = function RadialAxialClosure() {
|
|
110
130
|
var y2 = this.coordsArr[4];
|
111
131
|
var r2 = this.coordsArr[5];
|
112
132
|
var distance = Math.sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
|
133
|
+
|
113
134
|
if (r1 <= r2 + distance && r2 <= r1 + distance) {
|
114
135
|
(0, _util.warn)('Unsupported radial gradient.');
|
115
136
|
}
|
116
137
|
}
|
138
|
+
|
117
139
|
this.extendStart = extendStart;
|
118
140
|
this.extendEnd = extendEnd;
|
119
141
|
var fnObj = dict.get('Function');
|
@@ -121,40 +143,52 @@ Shadings.RadialAxial = function RadialAxialClosure() {
|
|
121
143
|
var diff = t1 - t0;
|
122
144
|
var step = diff / 10;
|
123
145
|
var colorStops = this.colorStops = [];
|
146
|
+
|
124
147
|
if (t0 >= t1 || step <= 0) {
|
125
148
|
(0, _util.info)('Bad shading domain.');
|
126
149
|
return;
|
127
150
|
}
|
151
|
+
|
128
152
|
var color = new Float32Array(cs.numComps),
|
129
153
|
ratio = new Float32Array(1);
|
130
154
|
var rgbColor;
|
155
|
+
|
131
156
|
for (var i = t0; i <= t1; i += step) {
|
132
157
|
ratio[0] = i;
|
133
158
|
fn(ratio, 0, color, 0);
|
134
159
|
rgbColor = cs.getRgb(color, 0);
|
160
|
+
|
135
161
|
var cssColor = _util.Util.makeCssRgb(rgbColor[0], rgbColor[1], rgbColor[2]);
|
162
|
+
|
136
163
|
colorStops.push([(i - t0) / diff, cssColor]);
|
137
164
|
}
|
165
|
+
|
138
166
|
var background = 'transparent';
|
167
|
+
|
139
168
|
if (dict.has('Background')) {
|
140
169
|
rgbColor = cs.getRgb(dict.get('Background'), 0);
|
141
170
|
background = _util.Util.makeCssRgb(rgbColor[0], rgbColor[1], rgbColor[2]);
|
142
171
|
}
|
172
|
+
|
143
173
|
if (!extendStart) {
|
144
174
|
colorStops.unshift([0, background]);
|
145
175
|
colorStops[1][0] += Shadings.SMALL_NUMBER;
|
146
176
|
}
|
177
|
+
|
147
178
|
if (!extendEnd) {
|
148
179
|
colorStops[colorStops.length - 1][0] -= Shadings.SMALL_NUMBER;
|
149
180
|
colorStops.push([1, background]);
|
150
181
|
}
|
182
|
+
|
151
183
|
this.colorStops = colorStops;
|
152
184
|
}
|
185
|
+
|
153
186
|
RadialAxial.prototype = {
|
154
187
|
getIR: function RadialAxial_getIR() {
|
155
188
|
var coordsArr = this.coordsArr;
|
156
189
|
var shadingType = this.shadingType;
|
157
190
|
var type, p0, p1, r0, r1;
|
191
|
+
|
158
192
|
if (shadingType === ShadingType.AXIAL) {
|
159
193
|
p0 = [coordsArr[0], coordsArr[1]];
|
160
194
|
p1 = [coordsArr[2], coordsArr[3]];
|
@@ -168,23 +202,29 @@ Shadings.RadialAxial = function RadialAxialClosure() {
|
|
168
202
|
r1 = coordsArr[5];
|
169
203
|
type = 'radial';
|
170
204
|
} else {
|
171
|
-
(0, _util.unreachable)(
|
205
|
+
(0, _util.unreachable)("getPattern type unknown: ".concat(shadingType));
|
172
206
|
}
|
207
|
+
|
173
208
|
var matrix = this.matrix;
|
209
|
+
|
174
210
|
if (matrix) {
|
175
211
|
p0 = _util.Util.applyTransform(p0, matrix);
|
176
212
|
p1 = _util.Util.applyTransform(p1, matrix);
|
213
|
+
|
177
214
|
if (shadingType === ShadingType.RADIAL) {
|
178
215
|
var scale = _util.Util.singularValueDecompose2dScale(matrix);
|
216
|
+
|
179
217
|
r0 *= scale[0];
|
180
218
|
r1 *= scale[1];
|
181
219
|
}
|
182
220
|
}
|
221
|
+
|
183
222
|
return ['RadialAxial', type, this.colorStops, p0, p1, r0, r1];
|
184
223
|
}
|
185
224
|
};
|
186
225
|
return RadialAxial;
|
187
226
|
}();
|
227
|
+
|
188
228
|
Shadings.Mesh = function MeshClosure() {
|
189
229
|
function MeshStreamReader(stream, context) {
|
190
230
|
this.stream = stream;
|
@@ -196,41 +236,52 @@ Shadings.Mesh = function MeshClosure() {
|
|
196
236
|
var csNumComps = context.colorSpace.numComps;
|
197
237
|
this.tmpCsCompsBuf = context.colorFn ? new Float32Array(csNumComps) : this.tmpCompsBuf;
|
198
238
|
}
|
239
|
+
|
199
240
|
MeshStreamReader.prototype = {
|
200
241
|
get hasData() {
|
201
242
|
if (this.stream.end) {
|
202
243
|
return this.stream.pos < this.stream.end;
|
203
244
|
}
|
245
|
+
|
204
246
|
if (this.bufferLength > 0) {
|
205
247
|
return true;
|
206
248
|
}
|
249
|
+
|
207
250
|
var nextByte = this.stream.getByte();
|
251
|
+
|
208
252
|
if (nextByte < 0) {
|
209
253
|
return false;
|
210
254
|
}
|
255
|
+
|
211
256
|
this.buffer = nextByte;
|
212
257
|
this.bufferLength = 8;
|
213
258
|
return true;
|
214
259
|
},
|
260
|
+
|
215
261
|
readBits: function MeshStreamReader_readBits(n) {
|
216
262
|
var buffer = this.buffer;
|
217
263
|
var bufferLength = this.bufferLength;
|
264
|
+
|
218
265
|
if (n === 32) {
|
219
266
|
if (bufferLength === 0) {
|
220
267
|
return (this.stream.getByte() << 24 | this.stream.getByte() << 16 | this.stream.getByte() << 8 | this.stream.getByte()) >>> 0;
|
221
268
|
}
|
269
|
+
|
222
270
|
buffer = buffer << 24 | this.stream.getByte() << 16 | this.stream.getByte() << 8 | this.stream.getByte();
|
223
271
|
var nextByte = this.stream.getByte();
|
224
272
|
this.buffer = nextByte & (1 << bufferLength) - 1;
|
225
273
|
return (buffer << 8 - bufferLength | (nextByte & 0xFF) >> bufferLength) >>> 0;
|
226
274
|
}
|
275
|
+
|
227
276
|
if (n === 8 && bufferLength === 0) {
|
228
277
|
return this.stream.getByte();
|
229
278
|
}
|
279
|
+
|
230
280
|
while (bufferLength < n) {
|
231
281
|
buffer = buffer << 8 | this.stream.getByte();
|
232
282
|
bufferLength += 8;
|
233
283
|
}
|
284
|
+
|
234
285
|
bufferLength -= n;
|
235
286
|
this.bufferLength = bufferLength;
|
236
287
|
this.buffer = buffer & (1 << bufferLength) - 1;
|
@@ -257,62 +308,77 @@ Shadings.Mesh = function MeshClosure() {
|
|
257
308
|
var scale = bitsPerComponent < 32 ? 1 / ((1 << bitsPerComponent) - 1) : 2.3283064365386963e-10;
|
258
309
|
var decode = this.context.decode;
|
259
310
|
var components = this.tmpCompsBuf;
|
311
|
+
|
260
312
|
for (var i = 0, j = 4; i < numComps; i++, j += 2) {
|
261
313
|
var ci = this.readBits(bitsPerComponent);
|
262
314
|
components[i] = ci * scale * (decode[j + 1] - decode[j]) + decode[j];
|
263
315
|
}
|
316
|
+
|
264
317
|
var color = this.tmpCsCompsBuf;
|
318
|
+
|
265
319
|
if (this.context.colorFn) {
|
266
320
|
this.context.colorFn(components, 0, color, 0);
|
267
321
|
}
|
322
|
+
|
268
323
|
return this.context.colorSpace.getRgb(color, 0);
|
269
324
|
}
|
270
325
|
};
|
326
|
+
|
271
327
|
function decodeType4Shading(mesh, reader) {
|
272
328
|
var coords = mesh.coords;
|
273
329
|
var colors = mesh.colors;
|
274
330
|
var operators = [];
|
275
331
|
var ps = [];
|
276
332
|
var verticesLeft = 0;
|
333
|
+
|
277
334
|
while (reader.hasData) {
|
278
335
|
var f = reader.readFlag();
|
279
336
|
var coord = reader.readCoordinate();
|
280
337
|
var color = reader.readComponents();
|
338
|
+
|
281
339
|
if (verticesLeft === 0) {
|
282
340
|
if (!(0 <= f && f <= 2)) {
|
283
341
|
throw new _util.FormatError('Unknown type4 flag');
|
284
342
|
}
|
343
|
+
|
285
344
|
switch (f) {
|
286
345
|
case 0:
|
287
346
|
verticesLeft = 3;
|
288
347
|
break;
|
348
|
+
|
289
349
|
case 1:
|
290
350
|
ps.push(ps[ps.length - 2], ps[ps.length - 1]);
|
291
351
|
verticesLeft = 1;
|
292
352
|
break;
|
353
|
+
|
293
354
|
case 2:
|
294
355
|
ps.push(ps[ps.length - 3], ps[ps.length - 1]);
|
295
356
|
verticesLeft = 1;
|
296
357
|
break;
|
297
358
|
}
|
359
|
+
|
298
360
|
operators.push(f);
|
299
361
|
}
|
362
|
+
|
300
363
|
ps.push(coords.length);
|
301
364
|
coords.push(coord);
|
302
365
|
colors.push(color);
|
303
366
|
verticesLeft--;
|
304
367
|
reader.align();
|
305
368
|
}
|
369
|
+
|
306
370
|
mesh.figures.push({
|
307
371
|
type: 'triangles',
|
308
372
|
coords: new Int32Array(ps),
|
309
373
|
colors: new Int32Array(ps)
|
310
374
|
});
|
311
375
|
}
|
376
|
+
|
312
377
|
function decodeType5Shading(mesh, reader, verticesPerRow) {
|
313
378
|
var coords = mesh.coords;
|
314
379
|
var colors = mesh.colors;
|
315
380
|
var ps = [];
|
381
|
+
|
316
382
|
while (reader.hasData) {
|
317
383
|
var coord = reader.readCoordinate();
|
318
384
|
var color = reader.readComponents();
|
@@ -320,6 +386,7 @@ Shadings.Mesh = function MeshClosure() {
|
|
320
386
|
coords.push(coord);
|
321
387
|
colors.push(color);
|
322
388
|
}
|
389
|
+
|
323
390
|
mesh.figures.push({
|
324
391
|
type: 'lattice',
|
325
392
|
coords: new Int32Array(ps),
|
@@ -327,27 +394,34 @@ Shadings.Mesh = function MeshClosure() {
|
|
327
394
|
verticesPerRow: verticesPerRow
|
328
395
|
});
|
329
396
|
}
|
397
|
+
|
330
398
|
var MIN_SPLIT_PATCH_CHUNKS_AMOUNT = 3;
|
331
399
|
var MAX_SPLIT_PATCH_CHUNKS_AMOUNT = 20;
|
332
400
|
var TRIANGLE_DENSITY = 20;
|
401
|
+
|
333
402
|
var getB = function getBClosure() {
|
334
403
|
function buildB(count) {
|
335
404
|
var lut = [];
|
405
|
+
|
336
406
|
for (var i = 0; i <= count; i++) {
|
337
407
|
var t = i / count,
|
338
408
|
t_ = 1 - t;
|
339
409
|
lut.push(new Float32Array([t_ * t_ * t_, 3 * t * t_ * t_, 3 * t * t * t_, t * t * t]));
|
340
410
|
}
|
411
|
+
|
341
412
|
return lut;
|
342
413
|
}
|
414
|
+
|
343
415
|
var cache = [];
|
344
416
|
return function getB(count) {
|
345
417
|
if (!cache[count]) {
|
346
418
|
cache[count] = buildB(count);
|
347
419
|
}
|
420
|
+
|
348
421
|
return cache[count];
|
349
422
|
};
|
350
423
|
}();
|
424
|
+
|
351
425
|
function buildFigureFromPatch(mesh, index) {
|
352
426
|
var figure = mesh.figures[index];
|
353
427
|
(0, _util.assert)(figure.type === 'patch', 'Unexpected patch mesh figure');
|
@@ -375,6 +449,7 @@ Shadings.Mesh = function MeshClosure() {
|
|
375
449
|
c3 = colors[ci[3]];
|
376
450
|
var bRow = getB(splitYBy),
|
377
451
|
bCol = getB(splitXBy);
|
452
|
+
|
378
453
|
for (var row = 0; row <= splitYBy; row++) {
|
379
454
|
cl[0] = (c0[0] * (splitYBy - row) + c2[0] * row) / splitYBy | 0;
|
380
455
|
cl[1] = (c0[1] * (splitYBy - row) + c2[1] * row) / splitYBy | 0;
|
@@ -382,13 +457,16 @@ Shadings.Mesh = function MeshClosure() {
|
|
382
457
|
cr[0] = (c1[0] * (splitYBy - row) + c3[0] * row) / splitYBy | 0;
|
383
458
|
cr[1] = (c1[1] * (splitYBy - row) + c3[1] * row) / splitYBy | 0;
|
384
459
|
cr[2] = (c1[2] * (splitYBy - row) + c3[2] * row) / splitYBy | 0;
|
460
|
+
|
385
461
|
for (var col = 0; col <= splitXBy; col++, k++) {
|
386
462
|
if ((row === 0 || row === splitYBy) && (col === 0 || col === splitXBy)) {
|
387
463
|
continue;
|
388
464
|
}
|
465
|
+
|
389
466
|
var x = 0,
|
390
467
|
y = 0;
|
391
468
|
var q = 0;
|
469
|
+
|
392
470
|
for (var i = 0; i <= 3; i++) {
|
393
471
|
for (var j = 0; j <= 3; j++, q++) {
|
394
472
|
var m = bRow[row][i] * bCol[col][j];
|
@@ -396,6 +474,7 @@ Shadings.Mesh = function MeshClosure() {
|
|
396
474
|
y += coords[pi[q]][1] * m;
|
397
475
|
}
|
398
476
|
}
|
477
|
+
|
399
478
|
figureCoords[k] = coords.length;
|
400
479
|
coords.push([x, y]);
|
401
480
|
figureColors[k] = colors.length;
|
@@ -406,6 +485,7 @@ Shadings.Mesh = function MeshClosure() {
|
|
406
485
|
colors.push(newColor);
|
407
486
|
}
|
408
487
|
}
|
488
|
+
|
409
489
|
figureCoords[0] = pi[0];
|
410
490
|
figureColors[0] = ci[0];
|
411
491
|
figureCoords[splitXBy] = pi[3];
|
@@ -421,26 +501,35 @@ Shadings.Mesh = function MeshClosure() {
|
|
421
501
|
verticesPerRow: verticesPerRow
|
422
502
|
};
|
423
503
|
}
|
504
|
+
|
424
505
|
function decodeType6Shading(mesh, reader) {
|
425
506
|
var coords = mesh.coords;
|
426
507
|
var colors = mesh.colors;
|
427
508
|
var ps = new Int32Array(16);
|
428
509
|
var cs = new Int32Array(4);
|
510
|
+
|
429
511
|
while (reader.hasData) {
|
430
512
|
var f = reader.readFlag();
|
513
|
+
|
431
514
|
if (!(0 <= f && f <= 3)) {
|
432
515
|
throw new _util.FormatError('Unknown type6 flag');
|
433
516
|
}
|
517
|
+
|
434
518
|
var i, ii;
|
435
519
|
var pi = coords.length;
|
520
|
+
|
436
521
|
for (i = 0, ii = f !== 0 ? 8 : 12; i < ii; i++) {
|
437
522
|
coords.push(reader.readCoordinate());
|
438
523
|
}
|
524
|
+
|
439
525
|
var ci = colors.length;
|
526
|
+
|
440
527
|
for (i = 0, ii = f !== 0 ? 2 : 4; i < ii; i++) {
|
441
528
|
colors.push(reader.readComponents());
|
442
529
|
}
|
530
|
+
|
443
531
|
var tmp1, tmp2, tmp3, tmp4;
|
532
|
+
|
444
533
|
switch (f) {
|
445
534
|
case 0:
|
446
535
|
ps[12] = pi + 3;
|
@@ -460,6 +549,7 @@ Shadings.Mesh = function MeshClosure() {
|
|
460
549
|
cs[0] = ci;
|
461
550
|
cs[1] = ci + 3;
|
462
551
|
break;
|
552
|
+
|
463
553
|
case 1:
|
464
554
|
tmp1 = ps[12];
|
465
555
|
tmp2 = ps[13];
|
@@ -484,6 +574,7 @@ Shadings.Mesh = function MeshClosure() {
|
|
484
574
|
cs[0] = tmp1;
|
485
575
|
cs[1] = ci + 1;
|
486
576
|
break;
|
577
|
+
|
487
578
|
case 2:
|
488
579
|
tmp1 = ps[15];
|
489
580
|
tmp2 = ps[11];
|
@@ -505,6 +596,7 @@ Shadings.Mesh = function MeshClosure() {
|
|
505
596
|
cs[0] = tmp1;
|
506
597
|
cs[1] = ci + 1;
|
507
598
|
break;
|
599
|
+
|
508
600
|
case 3:
|
509
601
|
ps[12] = ps[0];
|
510
602
|
ps[13] = pi + 0;
|
@@ -524,6 +616,7 @@ Shadings.Mesh = function MeshClosure() {
|
|
524
616
|
cs[1] = ci + 1;
|
525
617
|
break;
|
526
618
|
}
|
619
|
+
|
527
620
|
ps[5] = coords.length;
|
528
621
|
coords.push([(-4 * coords[ps[0]][0] - coords[ps[15]][0] + 6 * (coords[ps[4]][0] + coords[ps[1]][0]) - 2 * (coords[ps[12]][0] + coords[ps[3]][0]) + 3 * (coords[ps[13]][0] + coords[ps[7]][0])) / 9, (-4 * coords[ps[0]][1] - coords[ps[15]][1] + 6 * (coords[ps[4]][1] + coords[ps[1]][1]) - 2 * (coords[ps[12]][1] + coords[ps[3]][1]) + 3 * (coords[ps[13]][1] + coords[ps[7]][1])) / 9]);
|
529
622
|
ps[6] = coords.length;
|
@@ -539,26 +632,35 @@ Shadings.Mesh = function MeshClosure() {
|
|
539
632
|
});
|
540
633
|
}
|
541
634
|
}
|
635
|
+
|
542
636
|
function decodeType7Shading(mesh, reader) {
|
543
637
|
var coords = mesh.coords;
|
544
638
|
var colors = mesh.colors;
|
545
639
|
var ps = new Int32Array(16);
|
546
640
|
var cs = new Int32Array(4);
|
641
|
+
|
547
642
|
while (reader.hasData) {
|
548
643
|
var f = reader.readFlag();
|
644
|
+
|
549
645
|
if (!(0 <= f && f <= 3)) {
|
550
646
|
throw new _util.FormatError('Unknown type7 flag');
|
551
647
|
}
|
648
|
+
|
552
649
|
var i, ii;
|
553
650
|
var pi = coords.length;
|
651
|
+
|
554
652
|
for (i = 0, ii = f !== 0 ? 12 : 16; i < ii; i++) {
|
555
653
|
coords.push(reader.readCoordinate());
|
556
654
|
}
|
655
|
+
|
557
656
|
var ci = colors.length;
|
657
|
+
|
558
658
|
for (i = 0, ii = f !== 0 ? 2 : 4; i < ii; i++) {
|
559
659
|
colors.push(reader.readComponents());
|
560
660
|
}
|
661
|
+
|
561
662
|
var tmp1, tmp2, tmp3, tmp4;
|
663
|
+
|
562
664
|
switch (f) {
|
563
665
|
case 0:
|
564
666
|
ps[12] = pi + 3;
|
@@ -582,6 +684,7 @@ Shadings.Mesh = function MeshClosure() {
|
|
582
684
|
cs[0] = ci;
|
583
685
|
cs[1] = ci + 3;
|
584
686
|
break;
|
687
|
+
|
585
688
|
case 1:
|
586
689
|
tmp1 = ps[12];
|
587
690
|
tmp2 = ps[13];
|
@@ -610,6 +713,7 @@ Shadings.Mesh = function MeshClosure() {
|
|
610
713
|
cs[0] = tmp1;
|
611
714
|
cs[1] = ci + 1;
|
612
715
|
break;
|
716
|
+
|
613
717
|
case 2:
|
614
718
|
tmp1 = ps[15];
|
615
719
|
tmp2 = ps[11];
|
@@ -635,6 +739,7 @@ Shadings.Mesh = function MeshClosure() {
|
|
635
739
|
cs[0] = tmp1;
|
636
740
|
cs[1] = ci + 1;
|
637
741
|
break;
|
742
|
+
|
638
743
|
case 3:
|
639
744
|
ps[12] = ps[0];
|
640
745
|
ps[13] = pi + 0;
|
@@ -658,6 +763,7 @@ Shadings.Mesh = function MeshClosure() {
|
|
658
763
|
cs[1] = ci + 1;
|
659
764
|
break;
|
660
765
|
}
|
766
|
+
|
661
767
|
mesh.figures.push({
|
662
768
|
type: 'patch',
|
663
769
|
coords: new Int32Array(ps),
|
@@ -665,11 +771,13 @@ Shadings.Mesh = function MeshClosure() {
|
|
665
771
|
});
|
666
772
|
}
|
667
773
|
}
|
774
|
+
|
668
775
|
function updateBounds(mesh) {
|
669
776
|
var minX = mesh.coords[0][0],
|
670
777
|
minY = mesh.coords[0][1],
|
671
778
|
maxX = minX,
|
672
779
|
maxY = minY;
|
780
|
+
|
673
781
|
for (var i = 1, ii = mesh.coords.length; i < ii; i++) {
|
674
782
|
var x = mesh.coords[i][0],
|
675
783
|
y = mesh.coords[i][1];
|
@@ -678,42 +786,52 @@ Shadings.Mesh = function MeshClosure() {
|
|
678
786
|
maxX = maxX < x ? x : maxX;
|
679
787
|
maxY = maxY < y ? y : maxY;
|
680
788
|
}
|
789
|
+
|
681
790
|
mesh.bounds = [minX, minY, maxX, maxY];
|
682
791
|
}
|
792
|
+
|
683
793
|
function packData(mesh) {
|
684
794
|
var i, ii, j, jj;
|
685
795
|
var coords = mesh.coords;
|
686
796
|
var coordsPacked = new Float32Array(coords.length * 2);
|
797
|
+
|
687
798
|
for (i = 0, j = 0, ii = coords.length; i < ii; i++) {
|
688
799
|
var xy = coords[i];
|
689
800
|
coordsPacked[j++] = xy[0];
|
690
801
|
coordsPacked[j++] = xy[1];
|
691
802
|
}
|
803
|
+
|
692
804
|
mesh.coords = coordsPacked;
|
693
805
|
var colors = mesh.colors;
|
694
806
|
var colorsPacked = new Uint8Array(colors.length * 3);
|
807
|
+
|
695
808
|
for (i = 0, j = 0, ii = colors.length; i < ii; i++) {
|
696
809
|
var c = colors[i];
|
697
810
|
colorsPacked[j++] = c[0];
|
698
811
|
colorsPacked[j++] = c[1];
|
699
812
|
colorsPacked[j++] = c[2];
|
700
813
|
}
|
814
|
+
|
701
815
|
mesh.colors = colorsPacked;
|
702
816
|
var figures = mesh.figures;
|
817
|
+
|
703
818
|
for (i = 0, ii = figures.length; i < ii; i++) {
|
704
819
|
var figure = figures[i],
|
705
820
|
ps = figure.coords,
|
706
821
|
cs = figure.colors;
|
822
|
+
|
707
823
|
for (j = 0, jj = ps.length; j < jj; j++) {
|
708
824
|
ps[j] *= 2;
|
709
825
|
cs[j] *= 3;
|
710
826
|
}
|
711
827
|
}
|
712
828
|
}
|
829
|
+
|
713
830
|
function Mesh(stream, matrix, xref, res, pdfFunctionFactory) {
|
714
831
|
if (!(0, _primitives.isStream)(stream)) {
|
715
832
|
throw new _util.FormatError('Mesh data is not a stream');
|
716
833
|
}
|
834
|
+
|
717
835
|
var dict = stream.dict;
|
718
836
|
this.matrix = matrix;
|
719
837
|
this.shadingType = dict.get('ShadingType');
|
@@ -739,38 +857,49 @@ Shadings.Mesh = function MeshClosure() {
|
|
739
857
|
};
|
740
858
|
var reader = new MeshStreamReader(stream, decodeContext);
|
741
859
|
var patchMesh = false;
|
860
|
+
|
742
861
|
switch (this.shadingType) {
|
743
862
|
case ShadingType.FREE_FORM_MESH:
|
744
863
|
decodeType4Shading(this, reader);
|
745
864
|
break;
|
865
|
+
|
746
866
|
case ShadingType.LATTICE_FORM_MESH:
|
747
867
|
var verticesPerRow = dict.get('VerticesPerRow') | 0;
|
868
|
+
|
748
869
|
if (verticesPerRow < 2) {
|
749
870
|
throw new _util.FormatError('Invalid VerticesPerRow');
|
750
871
|
}
|
872
|
+
|
751
873
|
decodeType5Shading(this, reader, verticesPerRow);
|
752
874
|
break;
|
875
|
+
|
753
876
|
case ShadingType.COONS_PATCH_MESH:
|
754
877
|
decodeType6Shading(this, reader);
|
755
878
|
patchMesh = true;
|
756
879
|
break;
|
880
|
+
|
757
881
|
case ShadingType.TENSOR_PATCH_MESH:
|
758
882
|
decodeType7Shading(this, reader);
|
759
883
|
patchMesh = true;
|
760
884
|
break;
|
885
|
+
|
761
886
|
default:
|
762
887
|
(0, _util.unreachable)('Unsupported mesh type.');
|
763
888
|
break;
|
764
889
|
}
|
890
|
+
|
765
891
|
if (patchMesh) {
|
766
892
|
updateBounds(this);
|
893
|
+
|
767
894
|
for (var i = 0, ii = this.figures.length; i < ii; i++) {
|
768
895
|
buildFigureFromPatch(this, i);
|
769
896
|
}
|
770
897
|
}
|
898
|
+
|
771
899
|
updateBounds(this);
|
772
900
|
packData(this);
|
773
901
|
}
|
902
|
+
|
774
903
|
Mesh.prototype = {
|
775
904
|
getIR: function Mesh_getIR() {
|
776
905
|
return ['Mesh', this.shadingType, this.coords, this.colors, this.figures, this.bounds, this.matrix, this.bbox, this.background];
|
@@ -778,10 +907,12 @@ Shadings.Mesh = function MeshClosure() {
|
|
778
907
|
};
|
779
908
|
return Mesh;
|
780
909
|
}();
|
910
|
+
|
781
911
|
Shadings.Dummy = function DummyClosure() {
|
782
912
|
function Dummy() {
|
783
913
|
this.type = 'Pattern';
|
784
914
|
}
|
915
|
+
|
785
916
|
Dummy.prototype = {
|
786
917
|
getIR: function Dummy_getIR() {
|
787
918
|
return ['Dummy'];
|
@@ -789,17 +920,20 @@ Shadings.Dummy = function DummyClosure() {
|
|
789
920
|
};
|
790
921
|
return Dummy;
|
791
922
|
}();
|
923
|
+
|
792
924
|
function getTilingPatternIR(operatorList, dict, args) {
|
793
925
|
var matrix = dict.getArray('Matrix');
|
926
|
+
|
794
927
|
var bbox = _util.Util.normalizeRect(dict.getArray('BBox'));
|
928
|
+
|
795
929
|
var xstep = dict.get('XStep');
|
796
930
|
var ystep = dict.get('YStep');
|
797
931
|
var paintType = dict.get('PaintType');
|
798
932
|
var tilingType = dict.get('TilingType');
|
933
|
+
|
799
934
|
if (bbox[2] - bbox[0] === 0 || bbox[3] - bbox[1] === 0) {
|
800
|
-
throw new _util.FormatError(
|
935
|
+
throw new _util.FormatError("Invalid getTilingPatternIR /BBox array: [".concat(bbox, "]."));
|
801
936
|
}
|
937
|
+
|
802
938
|
return ['TilingPattern', args, operatorList, matrix, bbox, xstep, ystep, paintType, tilingType];
|
803
|
-
}
|
804
|
-
exports.Pattern = Pattern;
|
805
|
-
exports.getTilingPatternIR = getTilingPatternIR;
|
939
|
+
}
|