pdfjs-dist 2.0.487 → 2.1.266
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/bower.json +1 -1
- package/build/pdf.js +15564 -9476
- package/build/pdf.js.map +1 -1
- package/build/pdf.min.js +1 -1
- package/build/pdf.worker.js +46644 -36309
- 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 +11430 -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 +406 -131
- 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 +376 -53
- package/lib/core/charsets.js +5 -4
- package/lib/core/chunked_stream.js +387 -149
- package/lib/core/cmap.js +310 -75
- package/lib/core/colorspace.js +874 -594
- package/lib/core/crypto.js +290 -45
- package/lib/core/document.js +545 -260
- package/lib/core/encodings.js +19 -10
- package/lib/core/evaluator.js +725 -147
- package/lib/core/font_renderer.js +360 -91
- package/lib/core/fonts.js +791 -186
- package/lib/core/function.js +284 -71
- package/lib/core/glyphlist.js +3 -2
- package/lib/core/image.js +168 -61
- 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 +252 -29
- package/lib/core/jpx.js +396 -6
- package/lib/core/jpx_stream.js +18 -6
- package/lib/core/metrics.js +4 -4
- package/lib/core/murmurhash3.js +24 -6
- package/lib/core/obj.js +1137 -475
- package/lib/core/operator_list.js +108 -6
- package/lib/core/parser.js +321 -68
- package/lib/core/pattern.js +145 -13
- package/lib/core/pdf_manager.js +321 -133
- package/lib/core/primitives.js +75 -22
- package/lib/core/ps_parser.js +134 -45
- package/lib/core/standard_fonts.js +10 -10
- package/lib/core/stream.js +313 -34
- package/lib/core/type1_parser.js +143 -13
- package/lib/core/unicode.js +31 -4
- package/lib/core/worker.js +210 -66
- package/lib/display/annotation_layer.js +361 -123
- package/lib/display/api.js +1454 -729
- package/lib/display/api_compatibility.js +11 -13
- package/lib/display/canvas.js +324 -29
- package/lib/display/content_disposition.js +83 -32
- package/lib/display/dom_utils.js +226 -41
- package/lib/display/fetch_stream.js +208 -84
- package/lib/display/font_loader.js +465 -236
- package/lib/display/metadata.js +38 -16
- package/lib/display/network.js +216 -51
- package/lib/display/network_utils.js +32 -19
- package/lib/display/node_stream.js +352 -169
- package/lib/display/pattern_helper.js +58 -7
- package/lib/display/svg.js +242 -29
- package/lib/display/text_layer.js +132 -18
- package/lib/display/transport_stream.js +171 -42
- 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 +57 -4
- package/lib/pdf.js +21 -4
- 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 +295 -650
- package/lib/test/unit/annotation_spec.js +629 -345
- package/lib/test/unit/api_spec.js +555 -253
- package/lib/test/unit/bidi_spec.js +7 -7
- package/lib/test/unit/cff_parser_spec.js +40 -11
- package/lib/test/unit/clitests_helper.js +9 -7
- package/lib/test/unit/cmap_spec.js +80 -26
- package/lib/test/unit/colorspace_spec.js +99 -52
- package/lib/test/unit/crypto_spec.js +17 -5
- package/lib/test/unit/custom_spec.js +41 -53
- package/lib/test/unit/display_svg_spec.js +33 -17
- package/lib/test/unit/document_spec.js +3 -3
- package/lib/test/unit/dom_utils_spec.js +9 -9
- package/lib/test/unit/encodings_spec.js +25 -45
- package/lib/test/unit/evaluator_spec.js +34 -9
- package/lib/test/unit/function_spec.js +17 -5
- package/lib/test/unit/jasmine-boot.js +31 -18
- 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 +20 -5
- package/lib/test/unit/network_utils_spec.js +41 -14
- package/lib/test/unit/node_stream_spec.js +51 -27
- package/lib/test/unit/parser_spec.js +35 -8
- 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 +24 -4
- package/lib/test/unit/stream_spec.js +12 -4
- package/lib/test/unit/test_utils.js +90 -27
- 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 +452 -14
- package/lib/test/unit/unicode_spec.js +14 -11
- package/lib/test/unit/util_spec.js +131 -9
- package/lib/web/annotation_layer_builder.js +39 -22
- package/lib/web/app.js +1240 -582
- package/lib/web/app_options.js +71 -41
- package/lib/web/base_viewer.js +508 -179
- package/lib/web/chromecom.js +261 -117
- package/lib/web/debugger.js +166 -22
- package/lib/web/download_manager.js +31 -13
- package/lib/web/firefox_print_service.js +17 -9
- package/lib/web/firefoxcom.js +283 -79
- package/lib/web/genericcom.js +89 -30
- package/lib/web/genericl10n.js +142 -30
- package/lib/web/grab_to_pan.js +26 -4
- package/lib/web/interfaces.js +170 -47
- package/lib/web/overlay_manager.js +235 -85
- package/lib/web/password_prompt.js +21 -13
- 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 +80 -30
- 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 +137 -76
- package/lib/web/pdf_outline_viewer.js +73 -22
- package/lib/web/pdf_page_view.js +196 -63
- package/lib/web/pdf_presentation_mode.js +99 -34
- package/lib/web/pdf_print_service.js +57 -11
- package/lib/web/pdf_rendering_queue.js +27 -5
- package/lib/web/pdf_sidebar.js +120 -67
- 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 +103 -32
- package/lib/web/pdf_thumbnail_viewer.js +64 -24
- package/lib/web/pdf_viewer.component.js +112 -32
- package/lib/web/pdf_viewer.js +91 -52
- package/lib/web/preferences.js +275 -80
- package/lib/web/secondary_toolbar.js +165 -40
- package/lib/web/text_layer_builder.js +162 -65
- 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 +58 -1
- package/web/pdf_viewer.js +6346 -3919
- package/web/pdf_viewer.js.map +1 -1
- package/lib/test/unit/fonts_spec.js +0 -81
- package/lib/web/dom_events.js +0 -137
package/lib/core/evaluator.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 2018 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,50 +19,58 @@
|
|
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.PartialEvaluator =
|
27
|
+
exports.PartialEvaluator = void 0;
|
28
28
|
|
29
|
-
var
|
29
|
+
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
|
30
30
|
|
31
|
-
var
|
31
|
+
var _util = require("../shared/util");
|
32
32
|
|
33
|
-
var
|
33
|
+
var _cmap = require("./cmap");
|
34
34
|
|
35
|
-
var
|
35
|
+
var _stream = require("./stream");
|
36
36
|
|
37
|
-
var
|
37
|
+
var _primitives = require("./primitives");
|
38
38
|
|
39
|
-
var
|
39
|
+
var _fonts = require("./fonts");
|
40
40
|
|
41
|
-
var
|
41
|
+
var _encodings = require("./encodings");
|
42
42
|
|
43
|
-
var
|
43
|
+
var _unicode = require("./unicode");
|
44
44
|
|
45
|
-
var
|
45
|
+
var _standard_fonts = require("./standard_fonts");
|
46
46
|
|
47
|
-
var
|
47
|
+
var _pattern = require("./pattern");
|
48
48
|
|
49
|
-
var
|
49
|
+
var _parser = require("./parser");
|
50
50
|
|
51
|
-
var
|
51
|
+
var _bidi = require("./bidi");
|
52
52
|
|
53
|
-
var
|
53
|
+
var _colorspace = require("./colorspace");
|
54
54
|
|
55
|
-
var
|
55
|
+
var _glyphlist = require("./glyphlist");
|
56
56
|
|
57
|
-
var
|
57
|
+
var _metrics = require("./metrics");
|
58
58
|
|
59
|
-
var
|
59
|
+
var _function = require("./function");
|
60
60
|
|
61
|
-
var
|
61
|
+
var _jpeg_stream = require("./jpeg_stream");
|
62
62
|
|
63
|
-
var
|
63
|
+
var _murmurhash = require("./murmurhash3");
|
64
64
|
|
65
|
-
var
|
65
|
+
var _operator_list = require("./operator_list");
|
66
|
+
|
67
|
+
var _image = require("./image");
|
68
|
+
|
69
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
70
|
+
|
71
|
+
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
|
72
|
+
|
73
|
+
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
|
66
74
|
|
67
75
|
var PartialEvaluator = function PartialEvaluatorClosure() {
|
68
76
|
var DefaultPartialEvaluatorOptions = {
|
@@ -73,20 +81,21 @@ var PartialEvaluator = function PartialEvaluatorClosure() {
|
|
73
81
|
ignoreErrors: false,
|
74
82
|
isEvalSupported: true
|
75
83
|
};
|
84
|
+
|
76
85
|
function NativeImageDecoder(_ref) {
|
77
86
|
var xref = _ref.xref,
|
78
87
|
resources = _ref.resources,
|
79
88
|
handler = _ref.handler,
|
80
89
|
_ref$forceDataSchema = _ref.forceDataSchema,
|
81
|
-
forceDataSchema = _ref$forceDataSchema ===
|
90
|
+
forceDataSchema = _ref$forceDataSchema === void 0 ? false : _ref$forceDataSchema,
|
82
91
|
pdfFunctionFactory = _ref.pdfFunctionFactory;
|
83
|
-
|
84
92
|
this.xref = xref;
|
85
93
|
this.resources = resources;
|
86
94
|
this.handler = handler;
|
87
95
|
this.forceDataSchema = forceDataSchema;
|
88
96
|
this.pdfFunctionFactory = pdfFunctionFactory;
|
89
97
|
}
|
98
|
+
|
90
99
|
NativeImageDecoder.prototype = {
|
91
100
|
canDecode: function canDecode(image) {
|
92
101
|
return image instanceof _jpeg_stream.JpegStream && NativeImageDecoder.isDecodable(image, this.xref, this.resources, this.pdfFunctionFactory);
|
@@ -99,27 +108,36 @@ var PartialEvaluator = function PartialEvaluatorClosure() {
|
|
99
108
|
var data = _ref2.data,
|
100
109
|
width = _ref2.width,
|
101
110
|
height = _ref2.height;
|
102
|
-
|
103
111
|
return new _stream.Stream(data, 0, data.length, image.dict);
|
104
112
|
});
|
105
113
|
}
|
106
114
|
};
|
115
|
+
|
107
116
|
NativeImageDecoder.isSupported = function (image, xref, res, pdfFunctionFactory) {
|
108
117
|
var dict = image.dict;
|
118
|
+
|
109
119
|
if (dict.has('DecodeParms') || dict.has('DP')) {
|
110
120
|
return false;
|
111
121
|
}
|
122
|
+
|
112
123
|
var cs = _colorspace.ColorSpace.parse(dict.get('ColorSpace', 'CS'), xref, res, pdfFunctionFactory);
|
124
|
+
|
113
125
|
return (cs.name === 'DeviceGray' || cs.name === 'DeviceRGB') && cs.isDefaultDecode(dict.getArray('Decode', 'D'));
|
114
126
|
};
|
127
|
+
|
115
128
|
NativeImageDecoder.isDecodable = function (image, xref, res, pdfFunctionFactory) {
|
116
129
|
var dict = image.dict;
|
130
|
+
|
117
131
|
if (dict.has('DecodeParms') || dict.has('DP')) {
|
118
132
|
return false;
|
119
133
|
}
|
134
|
+
|
120
135
|
var cs = _colorspace.ColorSpace.parse(dict.get('ColorSpace', 'CS'), xref, res, pdfFunctionFactory);
|
121
|
-
|
136
|
+
|
137
|
+
var bpc = dict.get('BitsPerComponent', 'BPC') || 1;
|
138
|
+
return (cs.numComps === 1 || cs.numComps === 3) && cs.isDefaultDecode(dict.getArray('Decode', 'D'), bpc);
|
122
139
|
};
|
140
|
+
|
123
141
|
function PartialEvaluator(_ref3) {
|
124
142
|
var _this = this;
|
125
143
|
|
@@ -131,9 +149,8 @@ var PartialEvaluator = function PartialEvaluatorClosure() {
|
|
131
149
|
fontCache = _ref3.fontCache,
|
132
150
|
builtInCMapCache = _ref3.builtInCMapCache,
|
133
151
|
_ref3$options = _ref3.options,
|
134
|
-
options = _ref3$options ===
|
152
|
+
options = _ref3$options === void 0 ? null : _ref3$options,
|
135
153
|
pdfFunctionFactory = _ref3.pdfFunctionFactory;
|
136
|
-
|
137
154
|
this.pdfManager = pdfManager;
|
138
155
|
this.xref = xref;
|
139
156
|
this.handler = handler;
|
@@ -143,29 +160,67 @@ var PartialEvaluator = function PartialEvaluatorClosure() {
|
|
143
160
|
this.builtInCMapCache = builtInCMapCache;
|
144
161
|
this.options = options || DefaultPartialEvaluatorOptions;
|
145
162
|
this.pdfFunctionFactory = pdfFunctionFactory;
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
163
|
+
|
164
|
+
this.fetchBuiltInCMap =
|
165
|
+
/*#__PURE__*/
|
166
|
+
function () {
|
167
|
+
var _ref4 = _asyncToGenerator(
|
168
|
+
/*#__PURE__*/
|
169
|
+
_regenerator.default.mark(function _callee(name) {
|
170
|
+
var data;
|
171
|
+
return _regenerator.default.wrap(function _callee$(_context) {
|
172
|
+
while (1) {
|
173
|
+
switch (_context.prev = _context.next) {
|
174
|
+
case 0:
|
175
|
+
if (!_this.builtInCMapCache.has(name)) {
|
176
|
+
_context.next = 2;
|
177
|
+
break;
|
178
|
+
}
|
179
|
+
|
180
|
+
return _context.abrupt("return", _this.builtInCMapCache.get(name));
|
181
|
+
|
182
|
+
case 2:
|
183
|
+
_context.next = 4;
|
184
|
+
return _this.handler.sendWithPromise('FetchBuiltInCMap', {
|
185
|
+
name: name
|
186
|
+
});
|
187
|
+
|
188
|
+
case 4:
|
189
|
+
data = _context.sent;
|
190
|
+
|
191
|
+
if (data.compressionType !== _util.CMapCompressionType.NONE) {
|
192
|
+
_this.builtInCMapCache.set(name, data);
|
193
|
+
}
|
194
|
+
|
195
|
+
return _context.abrupt("return", data);
|
196
|
+
|
197
|
+
case 7:
|
198
|
+
case "end":
|
199
|
+
return _context.stop();
|
200
|
+
}
|
201
|
+
}
|
202
|
+
}, _callee, this);
|
203
|
+
}));
|
204
|
+
|
205
|
+
return function (_x) {
|
206
|
+
return _ref4.apply(this, arguments);
|
207
|
+
};
|
208
|
+
}();
|
158
209
|
}
|
210
|
+
|
159
211
|
var TIME_SLOT_DURATION_MS = 20;
|
160
212
|
var CHECK_TIME_EVERY = 100;
|
213
|
+
|
161
214
|
function TimeSlotManager() {
|
162
215
|
this.reset();
|
163
216
|
}
|
217
|
+
|
164
218
|
TimeSlotManager.prototype = {
|
165
219
|
check: function TimeSlotManager_check() {
|
166
220
|
if (++this.checked < CHECK_TIME_EVERY) {
|
167
221
|
return false;
|
168
222
|
}
|
223
|
+
|
169
224
|
this.checked = 0;
|
170
225
|
return this.endTime <= Date.now();
|
171
226
|
},
|
@@ -174,124 +229,169 @@ var PartialEvaluator = function PartialEvaluatorClosure() {
|
|
174
229
|
this.checked = 0;
|
175
230
|
}
|
176
231
|
};
|
232
|
+
|
177
233
|
function normalizeBlendMode(value) {
|
178
234
|
if (!(0, _primitives.isName)(value)) {
|
179
235
|
return 'source-over';
|
180
236
|
}
|
237
|
+
|
181
238
|
switch (value.name) {
|
182
239
|
case 'Normal':
|
183
240
|
case 'Compatible':
|
184
241
|
return 'source-over';
|
242
|
+
|
185
243
|
case 'Multiply':
|
186
244
|
return 'multiply';
|
245
|
+
|
187
246
|
case 'Screen':
|
188
247
|
return 'screen';
|
248
|
+
|
189
249
|
case 'Overlay':
|
190
250
|
return 'overlay';
|
251
|
+
|
191
252
|
case 'Darken':
|
192
253
|
return 'darken';
|
254
|
+
|
193
255
|
case 'Lighten':
|
194
256
|
return 'lighten';
|
257
|
+
|
195
258
|
case 'ColorDodge':
|
196
259
|
return 'color-dodge';
|
260
|
+
|
197
261
|
case 'ColorBurn':
|
198
262
|
return 'color-burn';
|
263
|
+
|
199
264
|
case 'HardLight':
|
200
265
|
return 'hard-light';
|
266
|
+
|
201
267
|
case 'SoftLight':
|
202
268
|
return 'soft-light';
|
269
|
+
|
203
270
|
case 'Difference':
|
204
271
|
return 'difference';
|
272
|
+
|
205
273
|
case 'Exclusion':
|
206
274
|
return 'exclusion';
|
275
|
+
|
207
276
|
case 'Hue':
|
208
277
|
return 'hue';
|
278
|
+
|
209
279
|
case 'Saturation':
|
210
280
|
return 'saturation';
|
281
|
+
|
211
282
|
case 'Color':
|
212
283
|
return 'color';
|
284
|
+
|
213
285
|
case 'Luminosity':
|
214
286
|
return 'luminosity';
|
215
287
|
}
|
288
|
+
|
216
289
|
(0, _util.warn)('Unsupported blend mode: ' + value.name);
|
217
290
|
return 'source-over';
|
218
291
|
}
|
292
|
+
|
219
293
|
var deferred = Promise.resolve();
|
220
294
|
var TILING_PATTERN = 1,
|
221
295
|
SHADING_PATTERN = 2;
|
222
296
|
PartialEvaluator.prototype = {
|
223
297
|
clone: function clone() {
|
224
298
|
var newOptions = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : DefaultPartialEvaluatorOptions;
|
225
|
-
|
226
299
|
var newEvaluator = Object.create(this);
|
227
300
|
newEvaluator.options = newOptions;
|
228
301
|
return newEvaluator;
|
229
302
|
},
|
230
|
-
|
231
303
|
hasBlendModes: function PartialEvaluator_hasBlendModes(resources) {
|
232
304
|
if (!(0, _primitives.isDict)(resources)) {
|
233
305
|
return false;
|
234
306
|
}
|
307
|
+
|
235
308
|
var processed = Object.create(null);
|
309
|
+
|
236
310
|
if (resources.objId) {
|
237
311
|
processed[resources.objId] = true;
|
238
312
|
}
|
313
|
+
|
239
314
|
var nodes = [resources],
|
240
315
|
xref = this.xref;
|
316
|
+
|
241
317
|
while (nodes.length) {
|
242
318
|
var key, i, ii;
|
243
319
|
var node = nodes.shift();
|
244
320
|
var graphicStates = node.get('ExtGState');
|
321
|
+
|
245
322
|
if ((0, _primitives.isDict)(graphicStates)) {
|
246
323
|
var graphicStatesKeys = graphicStates.getKeys();
|
324
|
+
|
247
325
|
for (i = 0, ii = graphicStatesKeys.length; i < ii; i++) {
|
248
326
|
key = graphicStatesKeys[i];
|
249
327
|
var graphicState = graphicStates.get(key);
|
250
328
|
var bm = graphicState.get('BM');
|
329
|
+
|
251
330
|
if ((0, _primitives.isName)(bm) && bm.name !== 'Normal') {
|
252
331
|
return true;
|
253
332
|
}
|
254
333
|
}
|
255
334
|
}
|
335
|
+
|
256
336
|
var xObjects = node.get('XObject');
|
337
|
+
|
257
338
|
if (!(0, _primitives.isDict)(xObjects)) {
|
258
339
|
continue;
|
259
340
|
}
|
341
|
+
|
260
342
|
var xObjectsKeys = xObjects.getKeys();
|
343
|
+
|
261
344
|
for (i = 0, ii = xObjectsKeys.length; i < ii; i++) {
|
262
345
|
key = xObjectsKeys[i];
|
263
346
|
var xObject = xObjects.getRaw(key);
|
347
|
+
|
264
348
|
if ((0, _primitives.isRef)(xObject)) {
|
265
349
|
if (processed[xObject.toString()]) {
|
266
350
|
continue;
|
267
351
|
}
|
352
|
+
|
268
353
|
xObject = xref.fetch(xObject);
|
269
354
|
}
|
355
|
+
|
270
356
|
if (!(0, _primitives.isStream)(xObject)) {
|
271
357
|
continue;
|
272
358
|
}
|
359
|
+
|
273
360
|
if (xObject.dict.objId) {
|
274
361
|
if (processed[xObject.dict.objId]) {
|
275
362
|
continue;
|
276
363
|
}
|
364
|
+
|
277
365
|
processed[xObject.dict.objId] = true;
|
278
366
|
}
|
367
|
+
|
279
368
|
var xResources = xObject.dict.get('Resources');
|
369
|
+
|
280
370
|
if ((0, _primitives.isDict)(xResources) && (!xResources.objId || !processed[xResources.objId])) {
|
281
371
|
nodes.push(xResources);
|
372
|
+
|
282
373
|
if (xResources.objId) {
|
283
374
|
processed[xResources.objId] = true;
|
284
375
|
}
|
285
376
|
}
|
286
377
|
}
|
287
378
|
}
|
379
|
+
|
288
380
|
return false;
|
289
381
|
},
|
290
382
|
buildFormXObject: function PartialEvaluator_buildFormXObject(resources, xobj, smask, operatorList, task, initialState) {
|
291
383
|
var dict = xobj.dict;
|
292
384
|
var matrix = dict.getArray('Matrix');
|
293
385
|
var bbox = dict.getArray('BBox');
|
386
|
+
|
387
|
+
if (Array.isArray(bbox) && bbox.length === 4) {
|
388
|
+
bbox = _util.Util.normalizeRect(bbox);
|
389
|
+
} else {
|
390
|
+
bbox = null;
|
391
|
+
}
|
392
|
+
|
294
393
|
var group = dict.get('Group');
|
394
|
+
|
295
395
|
if (group) {
|
296
396
|
var groupOptions = {
|
297
397
|
matrix: matrix,
|
@@ -302,19 +402,24 @@ var PartialEvaluator = function PartialEvaluatorClosure() {
|
|
302
402
|
};
|
303
403
|
var groupSubtype = group.get('S');
|
304
404
|
var colorSpace = null;
|
405
|
+
|
305
406
|
if ((0, _primitives.isName)(groupSubtype, 'Transparency')) {
|
306
407
|
groupOptions.isolated = group.get('I') || false;
|
307
408
|
groupOptions.knockout = group.get('K') || false;
|
409
|
+
|
308
410
|
if (group.has('CS')) {
|
309
411
|
colorSpace = _colorspace.ColorSpace.parse(group.get('CS'), this.xref, resources, this.pdfFunctionFactory);
|
310
412
|
}
|
311
413
|
}
|
414
|
+
|
312
415
|
if (smask && smask.backdrop) {
|
313
416
|
colorSpace = colorSpace || _colorspace.ColorSpace.singletons.rgb;
|
314
417
|
smask.backdrop = colorSpace.getRgb(smask.backdrop, 0);
|
315
418
|
}
|
419
|
+
|
316
420
|
operatorList.addOp(_util.OPS.beginGroup, [groupOptions]);
|
317
421
|
}
|
422
|
+
|
318
423
|
operatorList.addOp(_util.OPS.paintFormXObjectBegin, [matrix, bbox]);
|
319
424
|
return this.getOperatorList({
|
320
425
|
stream: xobj,
|
@@ -324,43 +429,48 @@ var PartialEvaluator = function PartialEvaluatorClosure() {
|
|
324
429
|
initialState: initialState
|
325
430
|
}).then(function () {
|
326
431
|
operatorList.addOp(_util.OPS.paintFormXObjectEnd, []);
|
432
|
+
|
327
433
|
if (group) {
|
328
434
|
operatorList.addOp(_util.OPS.endGroup, [groupOptions]);
|
329
435
|
}
|
330
436
|
});
|
331
437
|
},
|
332
|
-
buildPaintImageXObject: function buildPaintImageXObject(
|
438
|
+
buildPaintImageXObject: function buildPaintImageXObject(_ref5) {
|
333
439
|
var _this2 = this;
|
334
440
|
|
335
|
-
var resources =
|
336
|
-
image =
|
337
|
-
|
338
|
-
isInline =
|
339
|
-
operatorList =
|
340
|
-
cacheKey =
|
341
|
-
imageCache =
|
342
|
-
|
343
|
-
forceDisableNativeImageDecoder =
|
344
|
-
|
441
|
+
var resources = _ref5.resources,
|
442
|
+
image = _ref5.image,
|
443
|
+
_ref5$isInline = _ref5.isInline,
|
444
|
+
isInline = _ref5$isInline === void 0 ? false : _ref5$isInline,
|
445
|
+
operatorList = _ref5.operatorList,
|
446
|
+
cacheKey = _ref5.cacheKey,
|
447
|
+
imageCache = _ref5.imageCache,
|
448
|
+
_ref5$forceDisableNat = _ref5.forceDisableNativeImageDecoder,
|
449
|
+
forceDisableNativeImageDecoder = _ref5$forceDisableNat === void 0 ? false : _ref5$forceDisableNat;
|
345
450
|
var dict = image.dict;
|
346
451
|
var w = dict.get('Width', 'W');
|
347
452
|
var h = dict.get('Height', 'H');
|
453
|
+
|
348
454
|
if (!(w && (0, _util.isNum)(w)) || !(h && (0, _util.isNum)(h))) {
|
349
455
|
(0, _util.warn)('Image dimensions are missing, or not numbers.');
|
350
456
|
return Promise.resolve();
|
351
457
|
}
|
458
|
+
|
352
459
|
var maxImageSize = this.options.maxImageSize;
|
460
|
+
|
353
461
|
if (maxImageSize !== -1 && w * h > maxImageSize) {
|
354
462
|
(0, _util.warn)('Image exceeded maximum allowed size and was removed.');
|
355
463
|
return Promise.resolve();
|
356
464
|
}
|
465
|
+
|
357
466
|
var imageMask = dict.get('ImageMask', 'IM') || false;
|
358
467
|
var imgData, args;
|
468
|
+
|
359
469
|
if (imageMask) {
|
360
470
|
var width = dict.get('Width', 'W');
|
361
471
|
var height = dict.get('Height', 'H');
|
362
472
|
var bitStrideLength = width + 7 >> 3;
|
363
|
-
var imgArray = image.getBytes(bitStrideLength * height);
|
473
|
+
var imgArray = image.getBytes(bitStrideLength * height, true);
|
364
474
|
var decode = dict.getArray('Decode', 'D');
|
365
475
|
imgData = _image.PDFImage.createMask({
|
366
476
|
imgArray: imgArray,
|
@@ -372,17 +482,21 @@ var PartialEvaluator = function PartialEvaluatorClosure() {
|
|
372
482
|
imgData.cached = true;
|
373
483
|
args = [imgData];
|
374
484
|
operatorList.addOp(_util.OPS.paintImageMaskXObject, args);
|
485
|
+
|
375
486
|
if (cacheKey) {
|
376
487
|
imageCache[cacheKey] = {
|
377
488
|
fn: _util.OPS.paintImageMaskXObject,
|
378
489
|
args: args
|
379
490
|
};
|
380
491
|
}
|
492
|
+
|
381
493
|
return Promise.resolve();
|
382
494
|
}
|
495
|
+
|
383
496
|
var softMask = dict.get('SMask', 'SM') || false;
|
384
497
|
var mask = dict.get('Mask') || false;
|
385
498
|
var SMALL_IMAGE_DIMENSIONS = 200;
|
499
|
+
|
386
500
|
if (isInline && !softMask && !mask && !(image instanceof _jpeg_stream.JpegStream) && w + h < SMALL_IMAGE_DIMENSIONS) {
|
387
501
|
var imageObj = new _image.PDFImage({
|
388
502
|
xref: this.xref,
|
@@ -395,13 +509,16 @@ var PartialEvaluator = function PartialEvaluatorClosure() {
|
|
395
509
|
operatorList.addOp(_util.OPS.paintInlineImageXObject, [imgData]);
|
396
510
|
return Promise.resolve();
|
397
511
|
}
|
512
|
+
|
398
513
|
var nativeImageDecoderSupport = forceDisableNativeImageDecoder ? _util.NativeImageDecoding.NONE : this.options.nativeImageDecoderSupport;
|
399
514
|
var objId = 'img_' + this.idFactory.createObjId();
|
515
|
+
|
400
516
|
if (nativeImageDecoderSupport !== _util.NativeImageDecoding.NONE && !softMask && !mask && image instanceof _jpeg_stream.JpegStream && NativeImageDecoder.isSupported(image, this.xref, resources, this.pdfFunctionFactory)) {
|
401
517
|
return this.handler.sendWithPromise('obj', [objId, this.pageIndex, 'JpegStream', image.getIR(this.options.forceDataSchema)]).then(function () {
|
402
518
|
operatorList.addDependency(objId);
|
403
519
|
args = [objId, w, h];
|
404
520
|
operatorList.addOp(_util.OPS.paintJpegXObject, args);
|
521
|
+
|
405
522
|
if (cacheKey) {
|
406
523
|
imageCache[cacheKey] = {
|
407
524
|
fn: _util.OPS.paintJpegXObject,
|
@@ -421,7 +538,9 @@ var PartialEvaluator = function PartialEvaluatorClosure() {
|
|
421
538
|
});
|
422
539
|
});
|
423
540
|
}
|
541
|
+
|
424
542
|
var nativeImageDecoder = null;
|
543
|
+
|
425
544
|
if (nativeImageDecoderSupport === _util.NativeImageDecoding.DECODE && (image instanceof _jpeg_stream.JpegStream || mask instanceof _jpeg_stream.JpegStream || softMask instanceof _jpeg_stream.JpegStream)) {
|
426
545
|
nativeImageDecoder = new NativeImageDecoder({
|
427
546
|
xref: this.xref,
|
@@ -431,8 +550,10 @@ var PartialEvaluator = function PartialEvaluatorClosure() {
|
|
431
550
|
pdfFunctionFactory: this.pdfFunctionFactory
|
432
551
|
});
|
433
552
|
}
|
553
|
+
|
434
554
|
operatorList.addDependency(objId);
|
435
555
|
args = [objId, w, h];
|
556
|
+
|
436
557
|
_image.PDFImage.buildImage({
|
437
558
|
handler: this.handler,
|
438
559
|
xref: this.xref,
|
@@ -443,21 +564,25 @@ var PartialEvaluator = function PartialEvaluatorClosure() {
|
|
443
564
|
pdfFunctionFactory: this.pdfFunctionFactory
|
444
565
|
}).then(function (imageObj) {
|
445
566
|
var imgData = imageObj.createImageData(false);
|
567
|
+
|
446
568
|
_this2.handler.send('obj', [objId, _this2.pageIndex, 'Image', imgData], [imgData.data.buffer]);
|
447
569
|
}).catch(function (reason) {
|
448
570
|
(0, _util.warn)('Unable to decode image: ' + reason);
|
571
|
+
|
449
572
|
_this2.handler.send('obj', [objId, _this2.pageIndex, 'Image', null]);
|
450
573
|
});
|
574
|
+
|
451
575
|
operatorList.addOp(_util.OPS.paintImageXObject, args);
|
576
|
+
|
452
577
|
if (cacheKey) {
|
453
578
|
imageCache[cacheKey] = {
|
454
579
|
fn: _util.OPS.paintImageXObject,
|
455
580
|
args: args
|
456
581
|
};
|
457
582
|
}
|
583
|
+
|
458
584
|
return Promise.resolve();
|
459
585
|
},
|
460
|
-
|
461
586
|
handleSMask: function PartialEvaluator_handleSmask(smask, resources, operatorList, task, stateManager) {
|
462
587
|
var smaskContent = smask.get('G');
|
463
588
|
var smaskOptions = {
|
@@ -465,17 +590,21 @@ var PartialEvaluator = function PartialEvaluatorClosure() {
|
|
465
590
|
backdrop: smask.get('BC')
|
466
591
|
};
|
467
592
|
var transferObj = smask.get('TR');
|
593
|
+
|
468
594
|
if ((0, _function.isPDFFunction)(transferObj)) {
|
469
595
|
var transferFn = this.pdfFunctionFactory.create(transferObj);
|
470
596
|
var transferMap = new Uint8Array(256);
|
471
597
|
var tmp = new Float32Array(1);
|
598
|
+
|
472
599
|
for (var i = 0; i < 256; i++) {
|
473
600
|
tmp[0] = i / 255;
|
474
601
|
transferFn(tmp, 0, tmp, 0);
|
475
602
|
transferMap[i] = tmp[0] * 255 | 0;
|
476
603
|
}
|
604
|
+
|
477
605
|
smaskOptions.transferMap = transferMap;
|
478
606
|
}
|
607
|
+
|
479
608
|
return this.buildFormXObject(resources, smaskContent, smaskOptions, operatorList, task, stateManager.state.clone());
|
480
609
|
},
|
481
610
|
handleTilingType: function handleTilingType(fn, args, resources, pattern, patternDict, operatorList, task) {
|
@@ -483,7 +612,9 @@ var PartialEvaluator = function PartialEvaluatorClosure() {
|
|
483
612
|
|
484
613
|
var tilingOpList = new _operator_list.OperatorList();
|
485
614
|
var resourcesArray = [patternDict.get('Resources'), resources];
|
615
|
+
|
486
616
|
var patternResources = _primitives.Dict.merge(this.xref, resourcesArray);
|
617
|
+
|
487
618
|
return this.getOperatorList({
|
488
619
|
stream: pattern,
|
489
620
|
task: task,
|
@@ -499,30 +630,39 @@ var PartialEvaluator = function PartialEvaluatorClosure() {
|
|
499
630
|
operatorList.addOp(fn, tilingPatternIR);
|
500
631
|
}, function (reason) {
|
501
632
|
if (_this3.options.ignoreErrors) {
|
502
|
-
_this3.handler.send('UnsupportedFeature', {
|
503
|
-
|
633
|
+
_this3.handler.send('UnsupportedFeature', {
|
634
|
+
featureId: _util.UNSUPPORTED_FEATURES.unknown
|
635
|
+
});
|
636
|
+
|
637
|
+
(0, _util.warn)("handleTilingType - ignoring pattern: \"".concat(reason, "\"."));
|
504
638
|
return;
|
505
639
|
}
|
640
|
+
|
506
641
|
throw reason;
|
507
642
|
});
|
508
643
|
},
|
509
|
-
|
510
644
|
handleSetFont: function PartialEvaluator_handleSetFont(resources, fontArgs, fontRef, operatorList, task, state) {
|
511
645
|
var _this4 = this;
|
512
646
|
|
513
647
|
var fontName;
|
648
|
+
|
514
649
|
if (fontArgs) {
|
515
650
|
fontArgs = fontArgs.slice();
|
516
651
|
fontName = fontArgs[0].name;
|
517
652
|
}
|
653
|
+
|
518
654
|
return this.loadFont(fontName, fontRef, resources).then(function (translated) {
|
519
655
|
if (!translated.font.isType3Font) {
|
520
656
|
return translated;
|
521
657
|
}
|
658
|
+
|
522
659
|
return translated.loadType3Data(_this4, resources, operatorList, task).then(function () {
|
523
660
|
return translated;
|
524
661
|
}).catch(function (reason) {
|
525
|
-
_this4.handler.send('UnsupportedFeature', {
|
662
|
+
_this4.handler.send('UnsupportedFeature', {
|
663
|
+
featureId: _util.UNSUPPORTED_FEATURES.font
|
664
|
+
});
|
665
|
+
|
526
666
|
return new TranslatedFont('g_font_error', new _fonts.ErrorFont('Type3 font load error: ' + reason), translated.font);
|
527
667
|
});
|
528
668
|
}).then(function (translated) {
|
@@ -531,32 +671,22 @@ var PartialEvaluator = function PartialEvaluatorClosure() {
|
|
531
671
|
return translated.loadedName;
|
532
672
|
});
|
533
673
|
},
|
534
|
-
handleText: function
|
535
|
-
var _this5 = this;
|
536
|
-
|
674
|
+
handleText: function handleText(chars, state) {
|
537
675
|
var font = state.font;
|
538
676
|
var glyphs = font.charsToGlyphs(chars);
|
539
|
-
|
540
|
-
if (font.data
|
541
|
-
var
|
542
|
-
|
543
|
-
|
544
|
-
|
545
|
-
}
|
546
|
-
};
|
547
|
-
for (var i = 0, ii = glyphs.length; i < ii; i++) {
|
548
|
-
var glyph = glyphs[i];
|
549
|
-
buildPath(glyph.fontChar);
|
550
|
-
var accent = glyph.accent;
|
551
|
-
if (accent && accent.fontChar) {
|
552
|
-
buildPath(accent.fontChar);
|
553
|
-
}
|
677
|
+
|
678
|
+
if (font.data) {
|
679
|
+
var isAddToPathSet = !!(state.textRenderingMode & _util.TextRenderingMode.ADD_TO_PATH_FLAG);
|
680
|
+
|
681
|
+
if (isAddToPathSet || state.fillColorSpace.name === 'Pattern' || font.disableFontFace || this.options.disableFontFace) {
|
682
|
+
PartialEvaluator.buildFontPaths(font, glyphs, this.handler);
|
554
683
|
}
|
555
684
|
}
|
685
|
+
|
556
686
|
return glyphs;
|
557
687
|
},
|
558
688
|
setGState: function PartialEvaluator_setGState(resources, gState, operatorList, task, stateManager) {
|
559
|
-
var
|
689
|
+
var _this5 = this;
|
560
690
|
|
561
691
|
var gStateObj = [];
|
562
692
|
var gStateKeys = gState.getKeys();
|
@@ -565,9 +695,11 @@ var PartialEvaluator = function PartialEvaluatorClosure() {
|
|
565
695
|
var _loop = function _loop() {
|
566
696
|
var key = gStateKeys[i];
|
567
697
|
var value = gState.get(key);
|
698
|
+
|
568
699
|
switch (key) {
|
569
700
|
case 'Type':
|
570
701
|
break;
|
702
|
+
|
571
703
|
case 'LW':
|
572
704
|
case 'LC':
|
573
705
|
case 'LJ':
|
@@ -579,31 +711,37 @@ var PartialEvaluator = function PartialEvaluatorClosure() {
|
|
579
711
|
case 'ca':
|
580
712
|
gStateObj.push([key, value]);
|
581
713
|
break;
|
714
|
+
|
582
715
|
case 'Font':
|
583
716
|
promise = promise.then(function () {
|
584
|
-
return
|
717
|
+
return _this5.handleSetFont(resources, null, value[0], operatorList, task, stateManager.state).then(function (loadedName) {
|
585
718
|
operatorList.addDependency(loadedName);
|
586
719
|
gStateObj.push([key, [loadedName, value[1]]]);
|
587
720
|
});
|
588
721
|
});
|
589
722
|
break;
|
723
|
+
|
590
724
|
case 'BM':
|
591
725
|
gStateObj.push([key, normalizeBlendMode(value)]);
|
592
726
|
break;
|
727
|
+
|
593
728
|
case 'SMask':
|
594
729
|
if ((0, _primitives.isName)(value, 'None')) {
|
595
730
|
gStateObj.push([key, false]);
|
596
731
|
break;
|
597
732
|
}
|
733
|
+
|
598
734
|
if ((0, _primitives.isDict)(value)) {
|
599
735
|
promise = promise.then(function () {
|
600
|
-
return
|
736
|
+
return _this5.handleSMask(value, resources, operatorList, task, stateManager);
|
601
737
|
});
|
602
738
|
gStateObj.push([key, true]);
|
603
739
|
} else {
|
604
740
|
(0, _util.warn)('Unsupported SMask type');
|
605
741
|
}
|
742
|
+
|
606
743
|
break;
|
744
|
+
|
607
745
|
case 'OP':
|
608
746
|
case 'op':
|
609
747
|
case 'OPM':
|
@@ -620,6 +758,7 @@ var PartialEvaluator = function PartialEvaluatorClosure() {
|
|
620
758
|
case 'TK':
|
621
759
|
(0, _util.info)('graphic state operator ' + key);
|
622
760
|
break;
|
761
|
+
|
623
762
|
default:
|
624
763
|
(0, _util.info)('Unknown graphic state operator ' + key);
|
625
764
|
break;
|
@@ -629,6 +768,7 @@ var PartialEvaluator = function PartialEvaluatorClosure() {
|
|
629
768
|
for (var i = 0, ii = gStateKeys.length; i < ii; i++) {
|
630
769
|
_loop();
|
631
770
|
}
|
771
|
+
|
632
772
|
return promise.then(function () {
|
633
773
|
if (gStateObj.length > 0) {
|
634
774
|
operatorList.addOp(_util.OPS.setGState, [gStateObj]);
|
@@ -636,20 +776,24 @@ var PartialEvaluator = function PartialEvaluatorClosure() {
|
|
636
776
|
});
|
637
777
|
},
|
638
778
|
loadFont: function PartialEvaluator_loadFont(fontName, font, resources) {
|
639
|
-
var
|
779
|
+
var _this6 = this;
|
640
780
|
|
641
781
|
function errorFont() {
|
642
782
|
return Promise.resolve(new TranslatedFont('g_font_error', new _fonts.ErrorFont('Font ' + fontName + ' is not available'), font));
|
643
783
|
}
|
784
|
+
|
644
785
|
var fontRef,
|
645
786
|
xref = this.xref;
|
787
|
+
|
646
788
|
if (font) {
|
647
789
|
if (!(0, _primitives.isRef)(font)) {
|
648
790
|
throw new Error('The "font" object should be a reference.');
|
649
791
|
}
|
792
|
+
|
650
793
|
fontRef = font;
|
651
794
|
} else {
|
652
795
|
var fontRes = resources.get('Font');
|
796
|
+
|
653
797
|
if (fontRes) {
|
654
798
|
fontRef = fontRes.getRaw(fontName);
|
655
799
|
} else {
|
@@ -657,73 +801,97 @@ var PartialEvaluator = function PartialEvaluatorClosure() {
|
|
657
801
|
return errorFont();
|
658
802
|
}
|
659
803
|
}
|
804
|
+
|
660
805
|
if (!fontRef) {
|
661
806
|
(0, _util.warn)('fontRef not available');
|
662
807
|
return errorFont();
|
663
808
|
}
|
809
|
+
|
664
810
|
if (this.fontCache.has(fontRef)) {
|
665
811
|
return this.fontCache.get(fontRef);
|
666
812
|
}
|
813
|
+
|
667
814
|
font = xref.fetchIfRef(fontRef);
|
815
|
+
|
668
816
|
if (!(0, _primitives.isDict)(font)) {
|
669
817
|
return errorFont();
|
670
818
|
}
|
819
|
+
|
671
820
|
if (font.translated) {
|
672
821
|
return font.translated;
|
673
822
|
}
|
823
|
+
|
674
824
|
var fontCapability = (0, _util.createPromiseCapability)();
|
675
825
|
var preEvaluatedFont = this.preEvaluateFont(font);
|
676
826
|
var descriptor = preEvaluatedFont.descriptor;
|
677
827
|
var fontRefIsRef = (0, _primitives.isRef)(fontRef),
|
678
828
|
fontID;
|
829
|
+
|
679
830
|
if (fontRefIsRef) {
|
680
831
|
fontID = fontRef.toString();
|
681
832
|
}
|
833
|
+
|
682
834
|
if ((0, _primitives.isDict)(descriptor)) {
|
683
835
|
if (!descriptor.fontAliases) {
|
684
836
|
descriptor.fontAliases = Object.create(null);
|
685
837
|
}
|
838
|
+
|
686
839
|
var fontAliases = descriptor.fontAliases;
|
687
840
|
var hash = preEvaluatedFont.hash;
|
841
|
+
|
688
842
|
if (fontAliases[hash]) {
|
689
843
|
var aliasFontRef = fontAliases[hash].aliasRef;
|
844
|
+
|
690
845
|
if (fontRefIsRef && aliasFontRef && this.fontCache.has(aliasFontRef)) {
|
691
846
|
this.fontCache.putAlias(fontRef, aliasFontRef);
|
692
847
|
return this.fontCache.get(fontRef);
|
693
848
|
}
|
694
849
|
} else {
|
695
|
-
fontAliases[hash] = {
|
850
|
+
fontAliases[hash] = {
|
851
|
+
fontID: _fonts.Font.getFontID()
|
852
|
+
};
|
696
853
|
}
|
854
|
+
|
697
855
|
if (fontRefIsRef) {
|
698
856
|
fontAliases[hash].aliasRef = fontRef;
|
699
857
|
}
|
858
|
+
|
700
859
|
fontID = fontAliases[hash].fontID;
|
701
860
|
}
|
861
|
+
|
702
862
|
if (fontRefIsRef) {
|
703
863
|
this.fontCache.put(fontRef, fontCapability.promise);
|
704
864
|
} else {
|
705
865
|
if (!fontID) {
|
706
866
|
fontID = this.idFactory.createObjId();
|
707
867
|
}
|
868
|
+
|
708
869
|
this.fontCache.put('id_' + fontID, fontCapability.promise);
|
709
870
|
}
|
871
|
+
|
710
872
|
(0, _util.assert)(fontID, 'The "fontID" must be defined.');
|
711
873
|
font.loadedName = 'g_' + this.pdfManager.docId + '_f' + fontID;
|
712
874
|
font.translated = fontCapability.promise;
|
713
875
|
var translatedPromise;
|
876
|
+
|
714
877
|
try {
|
715
878
|
translatedPromise = this.translateFont(preEvaluatedFont);
|
716
879
|
} catch (e) {
|
717
880
|
translatedPromise = Promise.reject(e);
|
718
881
|
}
|
882
|
+
|
719
883
|
translatedPromise.then(function (translatedFont) {
|
720
884
|
if (translatedFont.fontType !== undefined) {
|
721
885
|
var xrefFontStats = xref.stats.fontTypes;
|
722
886
|
xrefFontStats[translatedFont.fontType] = true;
|
723
887
|
}
|
888
|
+
|
724
889
|
fontCapability.resolve(new TranslatedFont(font.loadedName, translatedFont, font));
|
725
890
|
}).catch(function (reason) {
|
726
|
-
|
891
|
+
_this6.handler.send('UnsupportedFeature', {
|
892
|
+
featureId: _util.UNSUPPORTED_FEATURES.font
|
893
|
+
});
|
894
|
+
|
727
895
|
try {
|
728
896
|
var descriptor = preEvaluatedFont.descriptor;
|
729
897
|
var fontFile3 = descriptor && descriptor.get('FontFile3');
|
@@ -732,15 +900,18 @@ var PartialEvaluator = function PartialEvaluatorClosure() {
|
|
732
900
|
var xrefFontStats = xref.stats.fontTypes;
|
733
901
|
xrefFontStats[fontType] = true;
|
734
902
|
} catch (ex) {}
|
903
|
+
|
735
904
|
fontCapability.resolve(new TranslatedFont(font.loadedName, new _fonts.ErrorFont(reason instanceof Error ? reason.message : reason), font));
|
736
905
|
});
|
737
906
|
return fontCapability.promise;
|
738
907
|
},
|
739
908
|
buildPath: function PartialEvaluator_buildPath(operatorList, fn, args) {
|
740
909
|
var lastIndex = operatorList.length - 1;
|
910
|
+
|
741
911
|
if (!args) {
|
742
912
|
args = [];
|
743
913
|
}
|
914
|
+
|
744
915
|
if (lastIndex < 0 || operatorList.fnArray[lastIndex] !== _util.OPS.constructPath) {
|
745
916
|
operatorList.addOp(_util.OPS.constructPath, [[fn], args]);
|
746
917
|
} else {
|
@@ -752,9 +923,11 @@ var PartialEvaluator = function PartialEvaluatorClosure() {
|
|
752
923
|
handleColorN: function PartialEvaluator_handleColorN(operatorList, fn, args, cs, patterns, resources, task) {
|
753
924
|
var patternName = args[args.length - 1];
|
754
925
|
var pattern;
|
926
|
+
|
755
927
|
if ((0, _primitives.isName)(patternName) && (pattern = patterns.get(patternName.name))) {
|
756
928
|
var dict = (0, _primitives.isStream)(pattern) ? pattern.dict : pattern;
|
757
929
|
var typeNum = dict.get('PatternType');
|
930
|
+
|
758
931
|
if (typeNum === TILING_PATTERN) {
|
759
932
|
var color = cs.base ? cs.base.getRgb(args, 0) : null;
|
760
933
|
return this.handleTilingType(fn, color, resources, pattern, dict, operatorList, task);
|
@@ -765,39 +938,47 @@ var PartialEvaluator = function PartialEvaluatorClosure() {
|
|
765
938
|
operatorList.addOp(fn, pattern.getIR());
|
766
939
|
return Promise.resolve();
|
767
940
|
}
|
941
|
+
|
768
942
|
return Promise.reject(new Error('Unknown PatternType: ' + typeNum));
|
769
943
|
}
|
944
|
+
|
770
945
|
operatorList.addOp(fn, args);
|
771
946
|
return Promise.resolve();
|
772
947
|
},
|
773
|
-
getOperatorList: function getOperatorList(
|
774
|
-
var
|
775
|
-
|
776
|
-
var stream = _ref5.stream,
|
777
|
-
task = _ref5.task,
|
778
|
-
resources = _ref5.resources,
|
779
|
-
operatorList = _ref5.operatorList,
|
780
|
-
_ref5$initialState = _ref5.initialState,
|
781
|
-
initialState = _ref5$initialState === undefined ? null : _ref5$initialState;
|
948
|
+
getOperatorList: function getOperatorList(_ref6) {
|
949
|
+
var _this7 = this;
|
782
950
|
|
951
|
+
var stream = _ref6.stream,
|
952
|
+
task = _ref6.task,
|
953
|
+
resources = _ref6.resources,
|
954
|
+
operatorList = _ref6.operatorList,
|
955
|
+
_ref6$initialState = _ref6.initialState,
|
956
|
+
initialState = _ref6$initialState === void 0 ? null : _ref6$initialState;
|
783
957
|
resources = resources || _primitives.Dict.empty;
|
784
958
|
initialState = initialState || new EvalState();
|
959
|
+
|
785
960
|
if (!operatorList) {
|
786
961
|
throw new Error('getOperatorList: missing "operatorList" parameter');
|
787
962
|
}
|
963
|
+
|
788
964
|
var self = this;
|
789
965
|
var xref = this.xref;
|
790
966
|
var imageCache = Object.create(null);
|
967
|
+
|
791
968
|
var xobjs = resources.get('XObject') || _primitives.Dict.empty;
|
969
|
+
|
792
970
|
var patterns = resources.get('Pattern') || _primitives.Dict.empty;
|
971
|
+
|
793
972
|
var stateManager = new StateManager(initialState);
|
794
973
|
var preprocessor = new EvaluatorPreprocessor(stream, xref, stateManager);
|
795
974
|
var timeSlotManager = new TimeSlotManager();
|
975
|
+
|
796
976
|
function closePendingRestoreOPS(argument) {
|
797
977
|
for (var i = 0, ii = preprocessor.savedStatesDepth; i < ii; i++) {
|
798
978
|
operatorList.addOp(_util.OPS.restore, []);
|
799
979
|
}
|
800
980
|
}
|
981
|
+
|
801
982
|
return new Promise(function promiseBody(resolve, reject) {
|
802
983
|
var next = function next(promise) {
|
803
984
|
promise.then(function () {
|
@@ -808,6 +989,7 @@ var PartialEvaluator = function PartialEvaluatorClosure() {
|
|
808
989
|
}
|
809
990
|
}, reject);
|
810
991
|
};
|
992
|
+
|
811
993
|
task.ensureNotTerminated();
|
812
994
|
timeSlotManager.reset();
|
813
995
|
var stop,
|
@@ -815,38 +997,50 @@ var PartialEvaluator = function PartialEvaluatorClosure() {
|
|
815
997
|
i,
|
816
998
|
ii,
|
817
999
|
cs;
|
1000
|
+
|
818
1001
|
while (!(stop = timeSlotManager.check())) {
|
819
1002
|
operation.args = null;
|
1003
|
+
|
820
1004
|
if (!preprocessor.read(operation)) {
|
821
1005
|
break;
|
822
1006
|
}
|
1007
|
+
|
823
1008
|
var args = operation.args;
|
824
1009
|
var fn = operation.fn;
|
1010
|
+
|
825
1011
|
switch (fn | 0) {
|
826
1012
|
case _util.OPS.paintXObject:
|
827
1013
|
var name = args[0].name;
|
1014
|
+
|
828
1015
|
if (name && imageCache[name] !== undefined) {
|
829
1016
|
operatorList.addOp(imageCache[name].fn, imageCache[name].args);
|
830
1017
|
args = null;
|
831
1018
|
continue;
|
832
1019
|
}
|
1020
|
+
|
833
1021
|
next(new Promise(function (resolveXObject, rejectXObject) {
|
834
1022
|
if (!name) {
|
835
1023
|
throw new _util.FormatError('XObject must be referred to by name.');
|
836
1024
|
}
|
1025
|
+
|
837
1026
|
var xobj = xobjs.get(name);
|
1027
|
+
|
838
1028
|
if (!xobj) {
|
839
1029
|
operatorList.addOp(fn, args);
|
840
1030
|
resolveXObject();
|
841
1031
|
return;
|
842
1032
|
}
|
1033
|
+
|
843
1034
|
if (!(0, _primitives.isStream)(xobj)) {
|
844
1035
|
throw new _util.FormatError('XObject should be a stream');
|
845
1036
|
}
|
1037
|
+
|
846
1038
|
var type = xobj.dict.get('Subtype');
|
1039
|
+
|
847
1040
|
if (!(0, _primitives.isName)(type)) {
|
848
1041
|
throw new _util.FormatError('XObject should have a Name subtype');
|
849
1042
|
}
|
1043
|
+
|
850
1044
|
if (type.name === 'Form') {
|
851
1045
|
stateManager.save();
|
852
1046
|
self.buildFormXObject(resources, xobj, null, operatorList, task, stateManager.state.clone()).then(function () {
|
@@ -866,18 +1060,23 @@ var PartialEvaluator = function PartialEvaluatorClosure() {
|
|
866
1060
|
} else if (type.name === 'PS') {
|
867
1061
|
(0, _util.info)('Ignored XObject subtype PS');
|
868
1062
|
} else {
|
869
|
-
throw new _util.FormatError(
|
1063
|
+
throw new _util.FormatError("Unhandled XObject subtype ".concat(type.name));
|
870
1064
|
}
|
1065
|
+
|
871
1066
|
resolveXObject();
|
872
1067
|
}).catch(function (reason) {
|
873
1068
|
if (self.options.ignoreErrors) {
|
874
|
-
self.handler.send('UnsupportedFeature', {
|
875
|
-
|
1069
|
+
self.handler.send('UnsupportedFeature', {
|
1070
|
+
featureId: _util.UNSUPPORTED_FEATURES.unknown
|
1071
|
+
});
|
1072
|
+
(0, _util.warn)("getOperatorList - ignoring XObject: \"".concat(reason, "\"."));
|
876
1073
|
return;
|
877
1074
|
}
|
1075
|
+
|
878
1076
|
throw reason;
|
879
1077
|
}));
|
880
1078
|
return;
|
1079
|
+
|
881
1080
|
case _util.OPS.setFont:
|
882
1081
|
var fontSize = args[1];
|
883
1082
|
next(self.handleSetFont(resources, args, null, operatorList, task, stateManager.state).then(function (loadedName) {
|
@@ -885,16 +1084,20 @@ var PartialEvaluator = function PartialEvaluatorClosure() {
|
|
885
1084
|
operatorList.addOp(_util.OPS.setFont, [loadedName, fontSize]);
|
886
1085
|
}));
|
887
1086
|
return;
|
1087
|
+
|
888
1088
|
case _util.OPS.endInlineImage:
|
889
1089
|
var cacheKey = args[0].cacheKey;
|
1090
|
+
|
890
1091
|
if (cacheKey) {
|
891
1092
|
var cacheEntry = imageCache[cacheKey];
|
1093
|
+
|
892
1094
|
if (cacheEntry !== undefined) {
|
893
1095
|
operatorList.addOp(cacheEntry.fn, cacheEntry.args);
|
894
1096
|
args = null;
|
895
1097
|
continue;
|
896
1098
|
}
|
897
1099
|
}
|
1100
|
+
|
898
1101
|
next(self.buildPaintImageXObject({
|
899
1102
|
resources: resources,
|
900
1103
|
image: args[0],
|
@@ -904,30 +1107,37 @@ var PartialEvaluator = function PartialEvaluatorClosure() {
|
|
904
1107
|
imageCache: imageCache
|
905
1108
|
}));
|
906
1109
|
return;
|
1110
|
+
|
907
1111
|
case _util.OPS.showText:
|
908
1112
|
args[0] = self.handleText(args[0], stateManager.state);
|
909
1113
|
break;
|
1114
|
+
|
910
1115
|
case _util.OPS.showSpacedText:
|
911
1116
|
var arr = args[0];
|
912
1117
|
var combinedGlyphs = [];
|
913
1118
|
var arrLength = arr.length;
|
914
1119
|
var state = stateManager.state;
|
1120
|
+
|
915
1121
|
for (i = 0; i < arrLength; ++i) {
|
916
1122
|
var arrItem = arr[i];
|
1123
|
+
|
917
1124
|
if ((0, _util.isString)(arrItem)) {
|
918
1125
|
Array.prototype.push.apply(combinedGlyphs, self.handleText(arrItem, state));
|
919
1126
|
} else if ((0, _util.isNum)(arrItem)) {
|
920
1127
|
combinedGlyphs.push(arrItem);
|
921
1128
|
}
|
922
1129
|
}
|
1130
|
+
|
923
1131
|
args[0] = combinedGlyphs;
|
924
1132
|
fn = _util.OPS.showText;
|
925
1133
|
break;
|
1134
|
+
|
926
1135
|
case _util.OPS.nextLineShowText:
|
927
1136
|
operatorList.addOp(_util.OPS.nextLine);
|
928
1137
|
args[0] = self.handleText(args[0], stateManager.state);
|
929
1138
|
fn = _util.OPS.showText;
|
930
1139
|
break;
|
1140
|
+
|
931
1141
|
case _util.OPS.nextLineSetSpacingShowText:
|
932
1142
|
operatorList.addOp(_util.OPS.nextLine);
|
933
1143
|
operatorList.addOp(_util.OPS.setWordSpacing, [args.shift()]);
|
@@ -935,94 +1145,121 @@ var PartialEvaluator = function PartialEvaluatorClosure() {
|
|
935
1145
|
args[0] = self.handleText(args[0], stateManager.state);
|
936
1146
|
fn = _util.OPS.showText;
|
937
1147
|
break;
|
1148
|
+
|
938
1149
|
case _util.OPS.setTextRenderingMode:
|
939
1150
|
stateManager.state.textRenderingMode = args[0];
|
940
1151
|
break;
|
1152
|
+
|
941
1153
|
case _util.OPS.setFillColorSpace:
|
942
1154
|
stateManager.state.fillColorSpace = _colorspace.ColorSpace.parse(args[0], xref, resources, self.pdfFunctionFactory);
|
943
1155
|
continue;
|
1156
|
+
|
944
1157
|
case _util.OPS.setStrokeColorSpace:
|
945
1158
|
stateManager.state.strokeColorSpace = _colorspace.ColorSpace.parse(args[0], xref, resources, self.pdfFunctionFactory);
|
946
1159
|
continue;
|
1160
|
+
|
947
1161
|
case _util.OPS.setFillColor:
|
948
1162
|
cs = stateManager.state.fillColorSpace;
|
949
1163
|
args = cs.getRgb(args, 0);
|
950
1164
|
fn = _util.OPS.setFillRGBColor;
|
951
1165
|
break;
|
1166
|
+
|
952
1167
|
case _util.OPS.setStrokeColor:
|
953
1168
|
cs = stateManager.state.strokeColorSpace;
|
954
1169
|
args = cs.getRgb(args, 0);
|
955
1170
|
fn = _util.OPS.setStrokeRGBColor;
|
956
1171
|
break;
|
1172
|
+
|
957
1173
|
case _util.OPS.setFillGray:
|
958
1174
|
stateManager.state.fillColorSpace = _colorspace.ColorSpace.singletons.gray;
|
959
1175
|
args = _colorspace.ColorSpace.singletons.gray.getRgb(args, 0);
|
960
1176
|
fn = _util.OPS.setFillRGBColor;
|
961
1177
|
break;
|
1178
|
+
|
962
1179
|
case _util.OPS.setStrokeGray:
|
963
1180
|
stateManager.state.strokeColorSpace = _colorspace.ColorSpace.singletons.gray;
|
964
1181
|
args = _colorspace.ColorSpace.singletons.gray.getRgb(args, 0);
|
965
1182
|
fn = _util.OPS.setStrokeRGBColor;
|
966
1183
|
break;
|
1184
|
+
|
967
1185
|
case _util.OPS.setFillCMYKColor:
|
968
1186
|
stateManager.state.fillColorSpace = _colorspace.ColorSpace.singletons.cmyk;
|
969
1187
|
args = _colorspace.ColorSpace.singletons.cmyk.getRgb(args, 0);
|
970
1188
|
fn = _util.OPS.setFillRGBColor;
|
971
1189
|
break;
|
1190
|
+
|
972
1191
|
case _util.OPS.setStrokeCMYKColor:
|
973
1192
|
stateManager.state.strokeColorSpace = _colorspace.ColorSpace.singletons.cmyk;
|
974
1193
|
args = _colorspace.ColorSpace.singletons.cmyk.getRgb(args, 0);
|
975
1194
|
fn = _util.OPS.setStrokeRGBColor;
|
976
1195
|
break;
|
1196
|
+
|
977
1197
|
case _util.OPS.setFillRGBColor:
|
978
1198
|
stateManager.state.fillColorSpace = _colorspace.ColorSpace.singletons.rgb;
|
979
1199
|
args = _colorspace.ColorSpace.singletons.rgb.getRgb(args, 0);
|
980
1200
|
break;
|
1201
|
+
|
981
1202
|
case _util.OPS.setStrokeRGBColor:
|
982
1203
|
stateManager.state.strokeColorSpace = _colorspace.ColorSpace.singletons.rgb;
|
983
1204
|
args = _colorspace.ColorSpace.singletons.rgb.getRgb(args, 0);
|
984
1205
|
break;
|
1206
|
+
|
985
1207
|
case _util.OPS.setFillColorN:
|
986
1208
|
cs = stateManager.state.fillColorSpace;
|
1209
|
+
|
987
1210
|
if (cs.name === 'Pattern') {
|
988
1211
|
next(self.handleColorN(operatorList, _util.OPS.setFillColorN, args, cs, patterns, resources, task));
|
989
1212
|
return;
|
990
1213
|
}
|
1214
|
+
|
991
1215
|
args = cs.getRgb(args, 0);
|
992
1216
|
fn = _util.OPS.setFillRGBColor;
|
993
1217
|
break;
|
1218
|
+
|
994
1219
|
case _util.OPS.setStrokeColorN:
|
995
1220
|
cs = stateManager.state.strokeColorSpace;
|
1221
|
+
|
996
1222
|
if (cs.name === 'Pattern') {
|
997
1223
|
next(self.handleColorN(operatorList, _util.OPS.setStrokeColorN, args, cs, patterns, resources, task));
|
998
1224
|
return;
|
999
1225
|
}
|
1226
|
+
|
1000
1227
|
args = cs.getRgb(args, 0);
|
1001
1228
|
fn = _util.OPS.setStrokeRGBColor;
|
1002
1229
|
break;
|
1230
|
+
|
1003
1231
|
case _util.OPS.shadingFill:
|
1004
1232
|
var shadingRes = resources.get('Shading');
|
1233
|
+
|
1005
1234
|
if (!shadingRes) {
|
1006
1235
|
throw new _util.FormatError('No shading resource found');
|
1007
1236
|
}
|
1237
|
+
|
1008
1238
|
var shading = shadingRes.get(args[0].name);
|
1239
|
+
|
1009
1240
|
if (!shading) {
|
1010
1241
|
throw new _util.FormatError('No shading object found');
|
1011
1242
|
}
|
1243
|
+
|
1012
1244
|
var shadingFill = _pattern.Pattern.parseShading(shading, null, xref, resources, self.handler, self.pdfFunctionFactory);
|
1245
|
+
|
1013
1246
|
var patternIR = shadingFill.getIR();
|
1014
1247
|
args = [patternIR];
|
1015
1248
|
fn = _util.OPS.shadingFill;
|
1016
1249
|
break;
|
1250
|
+
|
1017
1251
|
case _util.OPS.setGState:
|
1018
1252
|
var dictName = args[0];
|
1019
1253
|
var extGState = resources.get('ExtGState');
|
1254
|
+
|
1020
1255
|
if (!(0, _primitives.isDict)(extGState) || !extGState.has(dictName.name)) {
|
1021
1256
|
break;
|
1022
1257
|
}
|
1258
|
+
|
1023
1259
|
var gState = extGState.get(dictName.name);
|
1024
1260
|
next(self.setGState(resources, gState, operatorList, task, stateManager));
|
1025
1261
|
return;
|
1262
|
+
|
1026
1263
|
case _util.OPS.moveTo:
|
1027
1264
|
case _util.OPS.lineTo:
|
1028
1265
|
case _util.OPS.curveTo:
|
@@ -1031,9 +1268,11 @@ var PartialEvaluator = function PartialEvaluatorClosure() {
|
|
1031
1268
|
case _util.OPS.closePath:
|
1032
1269
|
self.buildPath(operatorList, fn, args);
|
1033
1270
|
continue;
|
1271
|
+
|
1034
1272
|
case _util.OPS.rectangle:
|
1035
1273
|
self.buildPath(operatorList, fn, args);
|
1036
1274
|
continue;
|
1275
|
+
|
1037
1276
|
case _util.OPS.markPoint:
|
1038
1277
|
case _util.OPS.markPointProps:
|
1039
1278
|
case _util.OPS.beginMarkedContent:
|
@@ -1042,6 +1281,7 @@ var PartialEvaluator = function PartialEvaluatorClosure() {
|
|
1042
1281
|
case _util.OPS.beginCompat:
|
1043
1282
|
case _util.OPS.endCompat:
|
1044
1283
|
continue;
|
1284
|
+
|
1045
1285
|
default:
|
1046
1286
|
if (args !== null) {
|
1047
1287
|
for (i = 0, ii = args.length; i < ii; i++) {
|
@@ -1049,46 +1289,54 @@ var PartialEvaluator = function PartialEvaluatorClosure() {
|
|
1049
1289
|
break;
|
1050
1290
|
}
|
1051
1291
|
}
|
1292
|
+
|
1052
1293
|
if (i < ii) {
|
1053
1294
|
(0, _util.warn)('getOperatorList - ignoring operator: ' + fn);
|
1054
1295
|
continue;
|
1055
1296
|
}
|
1056
1297
|
}
|
1298
|
+
|
1057
1299
|
}
|
1300
|
+
|
1058
1301
|
operatorList.addOp(fn, args);
|
1059
1302
|
}
|
1303
|
+
|
1060
1304
|
if (stop) {
|
1061
1305
|
next(deferred);
|
1062
1306
|
return;
|
1063
1307
|
}
|
1308
|
+
|
1064
1309
|
closePendingRestoreOPS();
|
1065
1310
|
resolve();
|
1066
1311
|
}).catch(function (reason) {
|
1067
|
-
if (
|
1068
|
-
|
1069
|
-
|
1312
|
+
if (_this7.options.ignoreErrors) {
|
1313
|
+
_this7.handler.send('UnsupportedFeature', {
|
1314
|
+
featureId: _util.UNSUPPORTED_FEATURES.unknown
|
1315
|
+
});
|
1316
|
+
|
1317
|
+
(0, _util.warn)("getOperatorList - ignoring errors during \"".concat(task.name, "\" ") + "task: \"".concat(reason, "\"."));
|
1070
1318
|
closePendingRestoreOPS();
|
1071
1319
|
return;
|
1072
1320
|
}
|
1321
|
+
|
1073
1322
|
throw reason;
|
1074
1323
|
});
|
1075
1324
|
},
|
1076
|
-
getTextContent: function getTextContent(
|
1077
|
-
var
|
1078
|
-
|
1079
|
-
var stream = _ref6.stream,
|
1080
|
-
task = _ref6.task,
|
1081
|
-
resources = _ref6.resources,
|
1082
|
-
_ref6$stateManager = _ref6.stateManager,
|
1083
|
-
stateManager = _ref6$stateManager === undefined ? null : _ref6$stateManager,
|
1084
|
-
_ref6$normalizeWhites = _ref6.normalizeWhitespace,
|
1085
|
-
normalizeWhitespace = _ref6$normalizeWhites === undefined ? false : _ref6$normalizeWhites,
|
1086
|
-
_ref6$combineTextItem = _ref6.combineTextItems,
|
1087
|
-
combineTextItems = _ref6$combineTextItem === undefined ? false : _ref6$combineTextItem,
|
1088
|
-
sink = _ref6.sink,
|
1089
|
-
_ref6$seenStyles = _ref6.seenStyles,
|
1090
|
-
seenStyles = _ref6$seenStyles === undefined ? Object.create(null) : _ref6$seenStyles;
|
1325
|
+
getTextContent: function getTextContent(_ref7) {
|
1326
|
+
var _this8 = this;
|
1091
1327
|
|
1328
|
+
var stream = _ref7.stream,
|
1329
|
+
task = _ref7.task,
|
1330
|
+
resources = _ref7.resources,
|
1331
|
+
_ref7$stateManager = _ref7.stateManager,
|
1332
|
+
stateManager = _ref7$stateManager === void 0 ? null : _ref7$stateManager,
|
1333
|
+
_ref7$normalizeWhites = _ref7.normalizeWhitespace,
|
1334
|
+
normalizeWhitespace = _ref7$normalizeWhites === void 0 ? false : _ref7$normalizeWhites,
|
1335
|
+
_ref7$combineTextItem = _ref7.combineTextItems,
|
1336
|
+
combineTextItems = _ref7$combineTextItem === void 0 ? false : _ref7$combineTextItem,
|
1337
|
+
sink = _ref7.sink,
|
1338
|
+
_ref7$seenStyles = _ref7.seenStyles,
|
1339
|
+
seenStyles = _ref7$seenStyles === void 0 ? Object.create(null) : _ref7$seenStyles;
|
1092
1340
|
resources = resources || _primitives.Dict.empty;
|
1093
1341
|
stateManager = stateManager || new StateManager(new TextState());
|
1094
1342
|
var WhitespaceRegexp = /\s/g;
|
@@ -1122,31 +1370,40 @@ var PartialEvaluator = function PartialEvaluatorClosure() {
|
|
1122
1370
|
var skipEmptyXObjs = Object.create(null);
|
1123
1371
|
var preprocessor = new EvaluatorPreprocessor(stream, xref, stateManager);
|
1124
1372
|
var textState;
|
1373
|
+
|
1125
1374
|
function ensureTextContentItem() {
|
1126
1375
|
if (textContentItem.initialized) {
|
1127
1376
|
return textContentItem;
|
1128
1377
|
}
|
1378
|
+
|
1129
1379
|
var font = textState.font;
|
1380
|
+
|
1130
1381
|
if (!(font.loadedName in seenStyles)) {
|
1131
1382
|
seenStyles[font.loadedName] = true;
|
1132
1383
|
textContent.styles[font.loadedName] = {
|
1133
1384
|
fontFamily: font.fallbackName,
|
1134
1385
|
ascent: font.ascent,
|
1135
1386
|
descent: font.descent,
|
1136
|
-
vertical: font.vertical
|
1387
|
+
vertical: !!font.vertical
|
1137
1388
|
};
|
1138
1389
|
}
|
1390
|
+
|
1139
1391
|
textContentItem.fontName = font.loadedName;
|
1140
1392
|
var tsm = [textState.fontSize * textState.textHScale, 0, 0, textState.fontSize, 0, textState.textRise];
|
1393
|
+
|
1141
1394
|
if (font.isType3Font && textState.fontMatrix !== _util.FONT_IDENTITY_MATRIX && textState.fontSize === 1) {
|
1142
1395
|
var glyphHeight = font.bbox[3] - font.bbox[1];
|
1396
|
+
|
1143
1397
|
if (glyphHeight > 0) {
|
1144
1398
|
glyphHeight = glyphHeight * textState.fontMatrix[3];
|
1145
1399
|
tsm[3] *= glyphHeight;
|
1146
1400
|
}
|
1147
1401
|
}
|
1402
|
+
|
1148
1403
|
var trm = _util.Util.transform(textState.ctm, _util.Util.transform(textState.textMatrix, tsm));
|
1404
|
+
|
1149
1405
|
textContentItem.transform = trm;
|
1406
|
+
|
1150
1407
|
if (!font.vertical) {
|
1151
1408
|
textContentItem.width = 0;
|
1152
1409
|
textContentItem.height = Math.sqrt(trm[2] * trm[2] + trm[3] * trm[3]);
|
@@ -1156,6 +1413,7 @@ var PartialEvaluator = function PartialEvaluatorClosure() {
|
|
1156
1413
|
textContentItem.height = 0;
|
1157
1414
|
textContentItem.vertical = true;
|
1158
1415
|
}
|
1416
|
+
|
1159
1417
|
var a = textState.textLineMatrix[0];
|
1160
1418
|
var b = textState.textLineMatrix[1];
|
1161
1419
|
var scaleLineX = Math.sqrt(a * a + b * b);
|
@@ -1166,6 +1424,7 @@ var PartialEvaluator = function PartialEvaluatorClosure() {
|
|
1166
1424
|
textContentItem.lastAdvanceWidth = 0;
|
1167
1425
|
textContentItem.lastAdvanceHeight = 0;
|
1168
1426
|
var spaceWidth = font.spaceWidth / 1000 * textState.fontSize;
|
1427
|
+
|
1169
1428
|
if (spaceWidth) {
|
1170
1429
|
textContentItem.spaceWidth = spaceWidth;
|
1171
1430
|
textContentItem.fakeSpaceMin = spaceWidth * SPACE_FACTOR;
|
@@ -1179,18 +1438,23 @@ var PartialEvaluator = function PartialEvaluatorClosure() {
|
|
1179
1438
|
textContentItem.fakeMultiSpaceMax = 0;
|
1180
1439
|
textContentItem.textRunBreakAllowed = false;
|
1181
1440
|
}
|
1441
|
+
|
1182
1442
|
textContentItem.initialized = true;
|
1183
1443
|
return textContentItem;
|
1184
1444
|
}
|
1445
|
+
|
1185
1446
|
function replaceWhitespace(str) {
|
1186
1447
|
var i = 0,
|
1187
1448
|
ii = str.length,
|
1188
1449
|
code;
|
1450
|
+
|
1189
1451
|
while (i < ii && (code = str.charCodeAt(i)) >= 0x20 && code <= 0x7F) {
|
1190
1452
|
i++;
|
1191
1453
|
}
|
1454
|
+
|
1192
1455
|
return i < ii ? str.replace(WhitespaceRegexp, ' ') : str;
|
1193
1456
|
}
|
1457
|
+
|
1194
1458
|
function runBidiTransform(textChunk) {
|
1195
1459
|
var str = textChunk.str.join('');
|
1196
1460
|
var bidiResult = (0, _bidi.bidi)(str, -1, textChunk.vertical);
|
@@ -1203,42 +1467,53 @@ var PartialEvaluator = function PartialEvaluatorClosure() {
|
|
1203
1467
|
fontName: textChunk.fontName
|
1204
1468
|
};
|
1205
1469
|
}
|
1470
|
+
|
1206
1471
|
function handleSetFont(fontName, fontRef) {
|
1207
1472
|
return self.loadFont(fontName, fontRef, resources).then(function (translated) {
|
1208
1473
|
textState.font = translated.font;
|
1209
1474
|
textState.fontMatrix = translated.font.fontMatrix || _util.FONT_IDENTITY_MATRIX;
|
1210
1475
|
});
|
1211
1476
|
}
|
1477
|
+
|
1212
1478
|
function buildTextContentItem(chars) {
|
1213
1479
|
var font = textState.font;
|
1214
1480
|
var textChunk = ensureTextContentItem();
|
1215
1481
|
var width = 0;
|
1216
1482
|
var height = 0;
|
1217
1483
|
var glyphs = font.charsToGlyphs(chars);
|
1484
|
+
|
1218
1485
|
for (var i = 0; i < glyphs.length; i++) {
|
1219
1486
|
var glyph = glyphs[i];
|
1220
1487
|
var glyphWidth = null;
|
1488
|
+
|
1221
1489
|
if (font.vertical && glyph.vmetric) {
|
1222
1490
|
glyphWidth = glyph.vmetric[0];
|
1223
1491
|
} else {
|
1224
1492
|
glyphWidth = glyph.width;
|
1225
1493
|
}
|
1494
|
+
|
1226
1495
|
var glyphUnicode = glyph.unicode;
|
1227
1496
|
var NormalizedUnicodes = (0, _unicode.getNormalizedUnicodes)();
|
1497
|
+
|
1228
1498
|
if (NormalizedUnicodes[glyphUnicode] !== undefined) {
|
1229
1499
|
glyphUnicode = NormalizedUnicodes[glyphUnicode];
|
1230
1500
|
}
|
1501
|
+
|
1231
1502
|
glyphUnicode = (0, _unicode.reverseIfRtl)(glyphUnicode);
|
1232
1503
|
var charSpacing = textState.charSpacing;
|
1504
|
+
|
1233
1505
|
if (glyph.isSpace) {
|
1234
1506
|
var wordSpacing = textState.wordSpacing;
|
1235
1507
|
charSpacing += wordSpacing;
|
1508
|
+
|
1236
1509
|
if (wordSpacing > 0) {
|
1237
1510
|
addFakeSpaces(wordSpacing, textChunk.str);
|
1238
1511
|
}
|
1239
1512
|
}
|
1513
|
+
|
1240
1514
|
var tx = 0;
|
1241
1515
|
var ty = 0;
|
1516
|
+
|
1242
1517
|
if (!font.vertical) {
|
1243
1518
|
var w0 = glyphWidth * textState.fontMatrix[0];
|
1244
1519
|
tx = (w0 * textState.fontSize + charSpacing) * textState.textHScale;
|
@@ -1248,9 +1523,11 @@ var PartialEvaluator = function PartialEvaluatorClosure() {
|
|
1248
1523
|
ty = w1 * textState.fontSize + charSpacing;
|
1249
1524
|
height += ty;
|
1250
1525
|
}
|
1526
|
+
|
1251
1527
|
textState.translateTextMatrix(tx, ty);
|
1252
1528
|
textChunk.str.push(glyphUnicode);
|
1253
1529
|
}
|
1530
|
+
|
1254
1531
|
if (!font.vertical) {
|
1255
1532
|
textChunk.lastAdvanceWidth = width;
|
1256
1533
|
textChunk.width += width;
|
@@ -1258,39 +1535,53 @@ var PartialEvaluator = function PartialEvaluatorClosure() {
|
|
1258
1535
|
textChunk.lastAdvanceHeight = height;
|
1259
1536
|
textChunk.height += Math.abs(height);
|
1260
1537
|
}
|
1538
|
+
|
1261
1539
|
return textChunk;
|
1262
1540
|
}
|
1541
|
+
|
1263
1542
|
function addFakeSpaces(width, strBuf) {
|
1264
1543
|
if (width < textContentItem.fakeSpaceMin) {
|
1265
1544
|
return;
|
1266
1545
|
}
|
1546
|
+
|
1267
1547
|
if (width < textContentItem.fakeMultiSpaceMin) {
|
1268
1548
|
strBuf.push(' ');
|
1269
1549
|
return;
|
1270
1550
|
}
|
1551
|
+
|
1271
1552
|
var fakeSpaces = Math.round(width / textContentItem.spaceWidth);
|
1553
|
+
|
1272
1554
|
while (fakeSpaces-- > 0) {
|
1273
1555
|
strBuf.push(' ');
|
1274
1556
|
}
|
1275
1557
|
}
|
1558
|
+
|
1276
1559
|
function flushTextContentItem() {
|
1277
1560
|
if (!textContentItem.initialized) {
|
1278
1561
|
return;
|
1279
1562
|
}
|
1280
|
-
|
1281
|
-
textContentItem.
|
1563
|
+
|
1564
|
+
if (!textContentItem.vertical) {
|
1565
|
+
textContentItem.width *= textContentItem.textAdvanceScale;
|
1566
|
+
} else {
|
1567
|
+
textContentItem.height *= textContentItem.textAdvanceScale;
|
1568
|
+
}
|
1569
|
+
|
1282
1570
|
textContent.items.push(runBidiTransform(textContentItem));
|
1283
1571
|
textContentItem.initialized = false;
|
1284
1572
|
textContentItem.str.length = 0;
|
1285
1573
|
}
|
1574
|
+
|
1286
1575
|
function enqueueChunk() {
|
1287
1576
|
var length = textContent.items.length;
|
1577
|
+
|
1288
1578
|
if (length > 0) {
|
1289
1579
|
sink.enqueue(textContent, length);
|
1290
1580
|
textContent.items = [];
|
1291
1581
|
textContent.styles = Object.create(null);
|
1292
1582
|
}
|
1293
1583
|
}
|
1584
|
+
|
1294
1585
|
var timeSlotManager = new TimeSlotManager();
|
1295
1586
|
return new Promise(function promiseBody(resolve, reject) {
|
1296
1587
|
var next = function next(promise) {
|
@@ -1303,48 +1594,60 @@ var PartialEvaluator = function PartialEvaluatorClosure() {
|
|
1303
1594
|
}
|
1304
1595
|
}, reject);
|
1305
1596
|
};
|
1597
|
+
|
1306
1598
|
task.ensureNotTerminated();
|
1307
1599
|
timeSlotManager.reset();
|
1308
1600
|
var stop,
|
1309
1601
|
operation = {},
|
1310
1602
|
args = [];
|
1603
|
+
|
1311
1604
|
while (!(stop = timeSlotManager.check())) {
|
1312
1605
|
args.length = 0;
|
1313
1606
|
operation.args = args;
|
1607
|
+
|
1314
1608
|
if (!preprocessor.read(operation)) {
|
1315
1609
|
break;
|
1316
1610
|
}
|
1611
|
+
|
1317
1612
|
textState = stateManager.state;
|
1318
1613
|
var fn = operation.fn;
|
1319
1614
|
args = operation.args;
|
1320
1615
|
var advance, diff;
|
1616
|
+
|
1321
1617
|
switch (fn | 0) {
|
1322
1618
|
case _util.OPS.setFont:
|
1323
1619
|
var fontNameArg = args[0].name,
|
1324
1620
|
fontSizeArg = args[1];
|
1621
|
+
|
1325
1622
|
if (textState.font && fontNameArg === textState.fontName && fontSizeArg === textState.fontSize) {
|
1326
1623
|
break;
|
1327
1624
|
}
|
1625
|
+
|
1328
1626
|
flushTextContentItem();
|
1329
1627
|
textState.fontName = fontNameArg;
|
1330
1628
|
textState.fontSize = fontSizeArg;
|
1331
1629
|
next(handleSetFont(fontNameArg, null));
|
1332
1630
|
return;
|
1631
|
+
|
1333
1632
|
case _util.OPS.setTextRise:
|
1334
1633
|
flushTextContentItem();
|
1335
1634
|
textState.textRise = args[0];
|
1336
1635
|
break;
|
1636
|
+
|
1337
1637
|
case _util.OPS.setHScale:
|
1338
1638
|
flushTextContentItem();
|
1339
1639
|
textState.textHScale = args[0] / 100;
|
1340
1640
|
break;
|
1641
|
+
|
1341
1642
|
case _util.OPS.setLeading:
|
1342
1643
|
flushTextContentItem();
|
1343
1644
|
textState.leading = args[0];
|
1344
1645
|
break;
|
1646
|
+
|
1345
1647
|
case _util.OPS.moveText:
|
1346
1648
|
var isSameTextLine = !textState.font ? false : (textState.font.vertical ? args[0] : args[1]) === 0;
|
1347
1649
|
advance = args[0] - args[1];
|
1650
|
+
|
1348
1651
|
if (combineTextItems && isSameTextLine && textContentItem.initialized && advance > 0 && advance <= textContentItem.fakeMultiSpaceMax) {
|
1349
1652
|
textState.translateTextLineMatrix(args[0], args[1]);
|
1350
1653
|
textContentItem.width += args[0] - textContentItem.lastAdvanceWidth;
|
@@ -1353,22 +1656,27 @@ var PartialEvaluator = function PartialEvaluatorClosure() {
|
|
1353
1656
|
addFakeSpaces(diff, textContentItem.str);
|
1354
1657
|
break;
|
1355
1658
|
}
|
1659
|
+
|
1356
1660
|
flushTextContentItem();
|
1357
1661
|
textState.translateTextLineMatrix(args[0], args[1]);
|
1358
1662
|
textState.textMatrix = textState.textLineMatrix.slice();
|
1359
1663
|
break;
|
1664
|
+
|
1360
1665
|
case _util.OPS.setLeadingMoveText:
|
1361
1666
|
flushTextContentItem();
|
1362
1667
|
textState.leading = -args[1];
|
1363
1668
|
textState.translateTextLineMatrix(args[0], args[1]);
|
1364
1669
|
textState.textMatrix = textState.textLineMatrix.slice();
|
1365
1670
|
break;
|
1671
|
+
|
1366
1672
|
case _util.OPS.nextLine:
|
1367
1673
|
flushTextContentItem();
|
1368
1674
|
textState.carriageReturn();
|
1369
1675
|
break;
|
1676
|
+
|
1370
1677
|
case _util.OPS.setTextMatrix:
|
1371
1678
|
advance = textState.calcTextLineMatrixAdvance(args[0], args[1], args[2], args[3], args[4], args[5]);
|
1679
|
+
|
1372
1680
|
if (combineTextItems && advance !== null && textContentItem.initialized && advance.value > 0 && advance.value <= textContentItem.fakeMultiSpaceMax) {
|
1373
1681
|
textState.translateTextLineMatrix(advance.width, advance.height);
|
1374
1682
|
textContentItem.width += advance.width - textContentItem.lastAdvanceWidth;
|
@@ -1377,24 +1685,30 @@ var PartialEvaluator = function PartialEvaluatorClosure() {
|
|
1377
1685
|
addFakeSpaces(diff, textContentItem.str);
|
1378
1686
|
break;
|
1379
1687
|
}
|
1688
|
+
|
1380
1689
|
flushTextContentItem();
|
1381
1690
|
textState.setTextMatrix(args[0], args[1], args[2], args[3], args[4], args[5]);
|
1382
1691
|
textState.setTextLineMatrix(args[0], args[1], args[2], args[3], args[4], args[5]);
|
1383
1692
|
break;
|
1693
|
+
|
1384
1694
|
case _util.OPS.setCharSpacing:
|
1385
1695
|
textState.charSpacing = args[0];
|
1386
1696
|
break;
|
1697
|
+
|
1387
1698
|
case _util.OPS.setWordSpacing:
|
1388
1699
|
textState.wordSpacing = args[0];
|
1389
1700
|
break;
|
1701
|
+
|
1390
1702
|
case _util.OPS.beginText:
|
1391
1703
|
flushTextContentItem();
|
1392
1704
|
textState.textMatrix = _util.IDENTITY_MATRIX.slice();
|
1393
1705
|
textState.textLineMatrix = _util.IDENTITY_MATRIX.slice();
|
1394
1706
|
break;
|
1707
|
+
|
1395
1708
|
case _util.OPS.showSpacedText:
|
1396
1709
|
var items = args[0];
|
1397
1710
|
var offset;
|
1711
|
+
|
1398
1712
|
for (var j = 0, jj = items.length; j < jj; j++) {
|
1399
1713
|
if (typeof items[j] === 'string') {
|
1400
1714
|
buildTextContentItem(items[j]);
|
@@ -1402,10 +1716,12 @@ var PartialEvaluator = function PartialEvaluatorClosure() {
|
|
1402
1716
|
ensureTextContentItem();
|
1403
1717
|
advance = items[j] * textState.fontSize / 1000;
|
1404
1718
|
var breakTextRun = false;
|
1719
|
+
|
1405
1720
|
if (textState.font.vertical) {
|
1406
1721
|
offset = advance;
|
1407
1722
|
textState.translateTextMatrix(0, offset);
|
1408
1723
|
breakTextRun = textContentItem.textRunBreakAllowed && advance > textContentItem.fakeMultiSpaceMax;
|
1724
|
+
|
1409
1725
|
if (!breakTextRun) {
|
1410
1726
|
textContentItem.height += offset;
|
1411
1727
|
}
|
@@ -1414,10 +1730,12 @@ var PartialEvaluator = function PartialEvaluatorClosure() {
|
|
1414
1730
|
offset = advance * textState.textHScale;
|
1415
1731
|
textState.translateTextMatrix(offset, 0);
|
1416
1732
|
breakTextRun = textContentItem.textRunBreakAllowed && advance > textContentItem.fakeMultiSpaceMax;
|
1733
|
+
|
1417
1734
|
if (!breakTextRun) {
|
1418
1735
|
textContentItem.width += offset;
|
1419
1736
|
}
|
1420
1737
|
}
|
1738
|
+
|
1421
1739
|
if (breakTextRun) {
|
1422
1740
|
flushTextContentItem();
|
1423
1741
|
} else if (advance > 0) {
|
@@ -1425,15 +1743,19 @@ var PartialEvaluator = function PartialEvaluatorClosure() {
|
|
1425
1743
|
}
|
1426
1744
|
}
|
1427
1745
|
}
|
1746
|
+
|
1428
1747
|
break;
|
1748
|
+
|
1429
1749
|
case _util.OPS.showText:
|
1430
1750
|
buildTextContentItem(args[0]);
|
1431
1751
|
break;
|
1752
|
+
|
1432
1753
|
case _util.OPS.nextLineShowText:
|
1433
1754
|
flushTextContentItem();
|
1434
1755
|
textState.carriageReturn();
|
1435
1756
|
buildTextContentItem(args[0]);
|
1436
1757
|
break;
|
1758
|
+
|
1437
1759
|
case _util.OPS.nextLineSetSpacingShowText:
|
1438
1760
|
flushTextContentItem();
|
1439
1761
|
textState.wordSpacing = args[0];
|
@@ -1441,42 +1763,56 @@ var PartialEvaluator = function PartialEvaluatorClosure() {
|
|
1441
1763
|
textState.carriageReturn();
|
1442
1764
|
buildTextContentItem(args[2]);
|
1443
1765
|
break;
|
1766
|
+
|
1444
1767
|
case _util.OPS.paintXObject:
|
1445
1768
|
flushTextContentItem();
|
1769
|
+
|
1446
1770
|
if (!xobjs) {
|
1447
1771
|
xobjs = resources.get('XObject') || _primitives.Dict.empty;
|
1448
1772
|
}
|
1773
|
+
|
1449
1774
|
var name = args[0].name;
|
1775
|
+
|
1450
1776
|
if (name && skipEmptyXObjs[name] !== undefined) {
|
1451
1777
|
break;
|
1452
1778
|
}
|
1779
|
+
|
1453
1780
|
next(new Promise(function (resolveXObject, rejectXObject) {
|
1454
1781
|
if (!name) {
|
1455
1782
|
throw new _util.FormatError('XObject must be referred to by name.');
|
1456
1783
|
}
|
1784
|
+
|
1457
1785
|
var xobj = xobjs.get(name);
|
1786
|
+
|
1458
1787
|
if (!xobj) {
|
1459
1788
|
resolveXObject();
|
1460
1789
|
return;
|
1461
1790
|
}
|
1791
|
+
|
1462
1792
|
if (!(0, _primitives.isStream)(xobj)) {
|
1463
1793
|
throw new _util.FormatError('XObject should be a stream');
|
1464
1794
|
}
|
1795
|
+
|
1465
1796
|
var type = xobj.dict.get('Subtype');
|
1797
|
+
|
1466
1798
|
if (!(0, _primitives.isName)(type)) {
|
1467
1799
|
throw new _util.FormatError('XObject should have a Name subtype');
|
1468
1800
|
}
|
1801
|
+
|
1469
1802
|
if (type.name !== 'Form') {
|
1470
1803
|
skipEmptyXObjs[name] = true;
|
1471
1804
|
resolveXObject();
|
1472
1805
|
return;
|
1473
1806
|
}
|
1807
|
+
|
1474
1808
|
var currentState = stateManager.state.clone();
|
1475
1809
|
var xObjStateManager = new StateManager(currentState);
|
1476
1810
|
var matrix = xobj.dict.getArray('Matrix');
|
1811
|
+
|
1477
1812
|
if (Array.isArray(matrix) && matrix.length === 6) {
|
1478
1813
|
xObjStateManager.transform(matrix);
|
1479
1814
|
}
|
1815
|
+
|
1480
1816
|
enqueueChunk();
|
1481
1817
|
var sinkWrapper = {
|
1482
1818
|
enqueueInvoked: false,
|
@@ -1488,9 +1824,11 @@ var PartialEvaluator = function PartialEvaluatorClosure() {
|
|
1488
1824
|
get desiredSize() {
|
1489
1825
|
return sink.desiredSize;
|
1490
1826
|
},
|
1827
|
+
|
1491
1828
|
get ready() {
|
1492
1829
|
return sink.ready;
|
1493
1830
|
}
|
1831
|
+
|
1494
1832
|
};
|
1495
1833
|
self.getTextContent({
|
1496
1834
|
stream: xobj,
|
@@ -1505,48 +1843,61 @@ var PartialEvaluator = function PartialEvaluatorClosure() {
|
|
1505
1843
|
if (!sinkWrapper.enqueueInvoked) {
|
1506
1844
|
skipEmptyXObjs[name] = true;
|
1507
1845
|
}
|
1846
|
+
|
1508
1847
|
resolveXObject();
|
1509
1848
|
}, rejectXObject);
|
1510
1849
|
}).catch(function (reason) {
|
1511
1850
|
if (reason instanceof _util.AbortException) {
|
1512
1851
|
return;
|
1513
1852
|
}
|
1853
|
+
|
1514
1854
|
if (self.options.ignoreErrors) {
|
1515
|
-
(0, _util.warn)(
|
1855
|
+
(0, _util.warn)("getTextContent - ignoring XObject: \"".concat(reason, "\"."));
|
1516
1856
|
return;
|
1517
1857
|
}
|
1858
|
+
|
1518
1859
|
throw reason;
|
1519
1860
|
}));
|
1520
1861
|
return;
|
1862
|
+
|
1521
1863
|
case _util.OPS.setGState:
|
1522
1864
|
flushTextContentItem();
|
1523
1865
|
var dictName = args[0];
|
1524
1866
|
var extGState = resources.get('ExtGState');
|
1867
|
+
|
1525
1868
|
if (!(0, _primitives.isDict)(extGState) || !(0, _primitives.isName)(dictName)) {
|
1526
1869
|
break;
|
1527
1870
|
}
|
1871
|
+
|
1528
1872
|
var gState = extGState.get(dictName.name);
|
1873
|
+
|
1529
1874
|
if (!(0, _primitives.isDict)(gState)) {
|
1530
1875
|
break;
|
1531
1876
|
}
|
1877
|
+
|
1532
1878
|
var gStateFont = gState.get('Font');
|
1879
|
+
|
1533
1880
|
if (gStateFont) {
|
1534
1881
|
textState.fontName = null;
|
1535
1882
|
textState.fontSize = gStateFont[1];
|
1536
1883
|
next(handleSetFont(null, gStateFont[0]));
|
1537
1884
|
return;
|
1538
1885
|
}
|
1886
|
+
|
1539
1887
|
break;
|
1540
1888
|
}
|
1889
|
+
|
1541
1890
|
if (textContent.items.length >= sink.desiredSize) {
|
1542
1891
|
stop = true;
|
1543
1892
|
break;
|
1544
1893
|
}
|
1545
1894
|
}
|
1895
|
+
|
1546
1896
|
if (stop) {
|
1547
1897
|
next(deferred);
|
1548
1898
|
return;
|
1549
1899
|
}
|
1900
|
+
|
1550
1901
|
flushTextContentItem();
|
1551
1902
|
enqueueChunk();
|
1552
1903
|
resolve();
|
@@ -1554,55 +1905,66 @@ var PartialEvaluator = function PartialEvaluatorClosure() {
|
|
1554
1905
|
if (reason instanceof _util.AbortException) {
|
1555
1906
|
return;
|
1556
1907
|
}
|
1557
|
-
|
1558
|
-
|
1908
|
+
|
1909
|
+
if (_this8.options.ignoreErrors) {
|
1910
|
+
(0, _util.warn)("getTextContent - ignoring errors during \"".concat(task.name, "\" ") + "task: \"".concat(reason, "\"."));
|
1559
1911
|
flushTextContentItem();
|
1560
1912
|
enqueueChunk();
|
1561
1913
|
return;
|
1562
1914
|
}
|
1915
|
+
|
1563
1916
|
throw reason;
|
1564
1917
|
});
|
1565
1918
|
},
|
1566
|
-
|
1567
1919
|
extractDataStructures: function PartialEvaluator_extractDataStructures(dict, baseDict, properties) {
|
1568
|
-
var
|
1920
|
+
var _this9 = this;
|
1569
1921
|
|
1570
1922
|
var xref = this.xref;
|
1571
1923
|
var toUnicode = dict.get('ToUnicode') || baseDict.get('ToUnicode');
|
1572
1924
|
var toUnicodePromise = toUnicode ? this.readToUnicode(toUnicode) : Promise.resolve(undefined);
|
1925
|
+
|
1573
1926
|
if (properties.composite) {
|
1574
1927
|
var cidSystemInfo = dict.get('CIDSystemInfo');
|
1928
|
+
|
1575
1929
|
if ((0, _primitives.isDict)(cidSystemInfo)) {
|
1576
1930
|
properties.cidSystemInfo = {
|
1577
|
-
registry: cidSystemInfo.get('Registry'),
|
1578
|
-
ordering: cidSystemInfo.get('Ordering'),
|
1931
|
+
registry: (0, _util.stringToPDFString)(cidSystemInfo.get('Registry')),
|
1932
|
+
ordering: (0, _util.stringToPDFString)(cidSystemInfo.get('Ordering')),
|
1579
1933
|
supplement: cidSystemInfo.get('Supplement')
|
1580
1934
|
};
|
1581
1935
|
}
|
1936
|
+
|
1582
1937
|
var cidToGidMap = dict.get('CIDToGIDMap');
|
1938
|
+
|
1583
1939
|
if ((0, _primitives.isStream)(cidToGidMap)) {
|
1584
1940
|
properties.cidToGidMap = this.readCidToGidMap(cidToGidMap);
|
1585
1941
|
}
|
1586
1942
|
}
|
1943
|
+
|
1587
1944
|
var differences = [];
|
1588
1945
|
var baseEncodingName = null;
|
1589
1946
|
var encoding;
|
1947
|
+
|
1590
1948
|
if (dict.has('Encoding')) {
|
1591
1949
|
encoding = dict.get('Encoding');
|
1950
|
+
|
1592
1951
|
if ((0, _primitives.isDict)(encoding)) {
|
1593
1952
|
baseEncodingName = encoding.get('BaseEncoding');
|
1594
1953
|
baseEncodingName = (0, _primitives.isName)(baseEncodingName) ? baseEncodingName.name : null;
|
1954
|
+
|
1595
1955
|
if (encoding.has('Differences')) {
|
1596
1956
|
var diffEncoding = encoding.get('Differences');
|
1597
1957
|
var index = 0;
|
1958
|
+
|
1598
1959
|
for (var j = 0, jj = diffEncoding.length; j < jj; j++) {
|
1599
1960
|
var data = xref.fetchIfRef(diffEncoding[j]);
|
1961
|
+
|
1600
1962
|
if ((0, _util.isNum)(data)) {
|
1601
1963
|
index = data;
|
1602
1964
|
} else if ((0, _primitives.isName)(data)) {
|
1603
1965
|
differences[index++] = data.name;
|
1604
1966
|
} else {
|
1605
|
-
throw new _util.FormatError(
|
1967
|
+
throw new _util.FormatError("Invalid entry in 'Differences' array: ".concat(data));
|
1606
1968
|
}
|
1607
1969
|
}
|
1608
1970
|
}
|
@@ -1611,21 +1973,26 @@ var PartialEvaluator = function PartialEvaluatorClosure() {
|
|
1611
1973
|
} else {
|
1612
1974
|
throw new _util.FormatError('Encoding is not a Name nor a Dict');
|
1613
1975
|
}
|
1976
|
+
|
1614
1977
|
if (baseEncodingName !== 'MacRomanEncoding' && baseEncodingName !== 'MacExpertEncoding' && baseEncodingName !== 'WinAnsiEncoding') {
|
1615
1978
|
baseEncodingName = null;
|
1616
1979
|
}
|
1617
1980
|
}
|
1981
|
+
|
1618
1982
|
if (baseEncodingName) {
|
1619
1983
|
properties.defaultEncoding = (0, _encodings.getEncoding)(baseEncodingName).slice();
|
1620
1984
|
} else {
|
1621
1985
|
var isSymbolicFont = !!(properties.flags & _fonts.FontFlags.Symbolic);
|
1622
1986
|
var isNonsymbolicFont = !!(properties.flags & _fonts.FontFlags.Nonsymbolic);
|
1623
1987
|
encoding = _encodings.StandardEncoding;
|
1988
|
+
|
1624
1989
|
if (properties.type === 'TrueType' && !isNonsymbolicFont) {
|
1625
1990
|
encoding = _encodings.WinAnsiEncoding;
|
1626
1991
|
}
|
1992
|
+
|
1627
1993
|
if (isSymbolicFont) {
|
1628
1994
|
encoding = _encodings.MacRomanEncoding;
|
1995
|
+
|
1629
1996
|
if (!properties.file) {
|
1630
1997
|
if (/Symbol/i.test(properties.name)) {
|
1631
1998
|
encoding = _encodings.SymbolSetEncoding;
|
@@ -1634,15 +2001,17 @@ var PartialEvaluator = function PartialEvaluatorClosure() {
|
|
1634
2001
|
}
|
1635
2002
|
}
|
1636
2003
|
}
|
2004
|
+
|
1637
2005
|
properties.defaultEncoding = encoding;
|
1638
2006
|
}
|
2007
|
+
|
1639
2008
|
properties.differences = differences;
|
1640
2009
|
properties.baseEncodingName = baseEncodingName;
|
1641
2010
|
properties.hasEncoding = !!baseEncodingName || differences.length > 0;
|
1642
2011
|
properties.dict = dict;
|
1643
2012
|
return toUnicodePromise.then(function (toUnicode) {
|
1644
2013
|
properties.toUnicode = toUnicode;
|
1645
|
-
return
|
2014
|
+
return _this9.buildToUnicode(properties);
|
1646
2015
|
}).then(function (toUnicode) {
|
1647
2016
|
properties.toUnicode = toUnicode;
|
1648
2017
|
return properties;
|
@@ -1651,79 +2020,106 @@ var PartialEvaluator = function PartialEvaluatorClosure() {
|
|
1651
2020
|
_buildSimpleFontToUnicode: function _buildSimpleFontToUnicode(properties) {
|
1652
2021
|
(0, _util.assert)(!properties.composite, 'Must be a simple font.');
|
1653
2022
|
var toUnicode = [],
|
1654
|
-
charcode
|
1655
|
-
glyphName
|
2023
|
+
charcode,
|
2024
|
+
glyphName;
|
1656
2025
|
var encoding = properties.defaultEncoding.slice();
|
1657
2026
|
var baseEncodingName = properties.baseEncodingName;
|
1658
2027
|
var differences = properties.differences;
|
2028
|
+
|
1659
2029
|
for (charcode in differences) {
|
1660
2030
|
glyphName = differences[charcode];
|
2031
|
+
|
1661
2032
|
if (glyphName === '.notdef') {
|
1662
2033
|
continue;
|
1663
2034
|
}
|
2035
|
+
|
1664
2036
|
encoding[charcode] = glyphName;
|
1665
2037
|
}
|
2038
|
+
|
1666
2039
|
var glyphsUnicodeMap = (0, _glyphlist.getGlyphsUnicode)();
|
2040
|
+
|
1667
2041
|
for (charcode in encoding) {
|
1668
2042
|
glyphName = encoding[charcode];
|
2043
|
+
|
1669
2044
|
if (glyphName === '') {
|
1670
2045
|
continue;
|
1671
2046
|
} else if (glyphsUnicodeMap[glyphName] === undefined) {
|
1672
2047
|
var code = 0;
|
2048
|
+
|
1673
2049
|
switch (glyphName[0]) {
|
1674
2050
|
case 'G':
|
1675
2051
|
if (glyphName.length === 3) {
|
1676
|
-
code = parseInt(glyphName.
|
2052
|
+
code = parseInt(glyphName.substring(1), 16);
|
1677
2053
|
}
|
2054
|
+
|
1678
2055
|
break;
|
2056
|
+
|
1679
2057
|
case 'g':
|
1680
2058
|
if (glyphName.length === 5) {
|
1681
|
-
code = parseInt(glyphName.
|
2059
|
+
code = parseInt(glyphName.substring(1), 16);
|
1682
2060
|
}
|
2061
|
+
|
1683
2062
|
break;
|
2063
|
+
|
1684
2064
|
case 'C':
|
1685
2065
|
case 'c':
|
1686
2066
|
if (glyphName.length >= 3) {
|
1687
|
-
code = +glyphName.
|
2067
|
+
code = +glyphName.substring(1);
|
1688
2068
|
}
|
2069
|
+
|
1689
2070
|
break;
|
2071
|
+
|
1690
2072
|
default:
|
1691
2073
|
var unicode = (0, _unicode.getUnicodeForGlyph)(glyphName, glyphsUnicodeMap);
|
2074
|
+
|
1692
2075
|
if (unicode !== -1) {
|
1693
2076
|
code = unicode;
|
1694
2077
|
}
|
2078
|
+
|
1695
2079
|
}
|
2080
|
+
|
1696
2081
|
if (code) {
|
1697
2082
|
if (baseEncodingName && code === +charcode) {
|
1698
2083
|
var baseEncoding = (0, _encodings.getEncoding)(baseEncodingName);
|
2084
|
+
|
1699
2085
|
if (baseEncoding && (glyphName = baseEncoding[charcode])) {
|
1700
2086
|
toUnicode[charcode] = String.fromCharCode(glyphsUnicodeMap[glyphName]);
|
1701
2087
|
continue;
|
1702
2088
|
}
|
1703
2089
|
}
|
1704
|
-
|
2090
|
+
|
2091
|
+
toUnicode[charcode] = String.fromCodePoint(code);
|
1705
2092
|
}
|
2093
|
+
|
1706
2094
|
continue;
|
1707
2095
|
}
|
2096
|
+
|
1708
2097
|
toUnicode[charcode] = String.fromCharCode(glyphsUnicodeMap[glyphName]);
|
1709
2098
|
}
|
2099
|
+
|
1710
2100
|
return new _fonts.ToUnicodeMap(toUnicode);
|
1711
2101
|
},
|
1712
2102
|
buildToUnicode: function buildToUnicode(properties) {
|
1713
2103
|
properties.hasIncludedToUnicodeMap = !!properties.toUnicode && properties.toUnicode.length > 0;
|
2104
|
+
|
1714
2105
|
if (properties.hasIncludedToUnicodeMap) {
|
1715
2106
|
if (!properties.composite && properties.hasEncoding) {
|
1716
2107
|
properties.fallbackToUnicode = this._buildSimpleFontToUnicode(properties);
|
1717
2108
|
}
|
2109
|
+
|
1718
2110
|
return Promise.resolve(properties.toUnicode);
|
1719
2111
|
}
|
2112
|
+
|
1720
2113
|
if (!properties.composite) {
|
1721
2114
|
return Promise.resolve(this._buildSimpleFontToUnicode(properties));
|
1722
2115
|
}
|
2116
|
+
|
1723
2117
|
if (properties.composite && (properties.cMap.builtInCMap && !(properties.cMap instanceof _cmap.IdentityCMap) || properties.cidSystemInfo.registry === 'Adobe' && (properties.cidSystemInfo.ordering === 'GB1' || properties.cidSystemInfo.ordering === 'CNS1' || properties.cidSystemInfo.ordering === 'Japan1' || properties.cidSystemInfo.ordering === 'Korea1'))) {
|
1724
2118
|
var registry = properties.cidSystemInfo.registry;
|
1725
2119
|
var ordering = properties.cidSystemInfo.ordering;
|
2120
|
+
|
1726
2121
|
var ucs2CMapName = _primitives.Name.get(registry + '-' + ordering + '-UCS2');
|
2122
|
+
|
1727
2123
|
return _cmap.CMapFactory.create({
|
1728
2124
|
encoding: ucs2CMapName,
|
1729
2125
|
fetchBuiltInCMap: this.fetchBuiltInCMap,
|
@@ -1735,7 +2131,9 @@ var PartialEvaluator = function PartialEvaluatorClosure() {
|
|
1735
2131
|
if (cid > 0xffff) {
|
1736
2132
|
throw new _util.FormatError('Max size of CID is 65,535');
|
1737
2133
|
}
|
2134
|
+
|
1738
2135
|
var ucs2 = ucs2CMap.lookup(cid);
|
2136
|
+
|
1739
2137
|
if (ucs2) {
|
1740
2138
|
toUnicode[charcode] = String.fromCharCode((ucs2.charCodeAt(0) << 8) + ucs2.charCodeAt(1));
|
1741
2139
|
}
|
@@ -1743,11 +2141,12 @@ var PartialEvaluator = function PartialEvaluatorClosure() {
|
|
1743
2141
|
return new _fonts.ToUnicodeMap(toUnicode);
|
1744
2142
|
});
|
1745
2143
|
}
|
2144
|
+
|
1746
2145
|
return Promise.resolve(new _fonts.IdentityToUnicodeMap(properties.firstChar, properties.lastChar));
|
1747
2146
|
},
|
1748
|
-
|
1749
2147
|
readToUnicode: function PartialEvaluator_readToUnicode(toUnicode) {
|
1750
2148
|
var cmapObj = toUnicode;
|
2149
|
+
|
1751
2150
|
if ((0, _primitives.isName)(cmapObj)) {
|
1752
2151
|
return _cmap.CMapFactory.create({
|
1753
2152
|
encoding: cmapObj,
|
@@ -1757,6 +2156,7 @@ var PartialEvaluator = function PartialEvaluatorClosure() {
|
|
1757
2156
|
if (cmap instanceof _cmap.IdentityCMap) {
|
1758
2157
|
return new _fonts.IdentityToUnicodeMap(0, 0xFFFF);
|
1759
2158
|
}
|
2159
|
+
|
1760
2160
|
return new _fonts.ToUnicodeMap(cmap.getMap());
|
1761
2161
|
});
|
1762
2162
|
} else if ((0, _primitives.isStream)(cmapObj)) {
|
@@ -1768,37 +2168,47 @@ var PartialEvaluator = function PartialEvaluatorClosure() {
|
|
1768
2168
|
if (cmap instanceof _cmap.IdentityCMap) {
|
1769
2169
|
return new _fonts.IdentityToUnicodeMap(0, 0xFFFF);
|
1770
2170
|
}
|
2171
|
+
|
1771
2172
|
var map = new Array(cmap.length);
|
1772
2173
|
cmap.forEach(function (charCode, token) {
|
1773
2174
|
var str = [];
|
2175
|
+
|
1774
2176
|
for (var k = 0; k < token.length; k += 2) {
|
1775
2177
|
var w1 = token.charCodeAt(k) << 8 | token.charCodeAt(k + 1);
|
2178
|
+
|
1776
2179
|
if ((w1 & 0xF800) !== 0xD800) {
|
1777
2180
|
str.push(w1);
|
1778
2181
|
continue;
|
1779
2182
|
}
|
2183
|
+
|
1780
2184
|
k += 2;
|
1781
2185
|
var w2 = token.charCodeAt(k) << 8 | token.charCodeAt(k + 1);
|
1782
2186
|
str.push(((w1 & 0x3ff) << 10) + (w2 & 0x3ff) + 0x10000);
|
1783
2187
|
}
|
1784
|
-
|
2188
|
+
|
2189
|
+
map[charCode] = String.fromCodePoint.apply(String, str);
|
1785
2190
|
});
|
1786
2191
|
return new _fonts.ToUnicodeMap(map);
|
1787
2192
|
});
|
1788
2193
|
}
|
2194
|
+
|
1789
2195
|
return Promise.resolve(null);
|
1790
2196
|
},
|
1791
2197
|
readCidToGidMap: function PartialEvaluator_readCidToGidMap(cidToGidStream) {
|
1792
2198
|
var glyphsData = cidToGidStream.getBytes();
|
1793
2199
|
var result = [];
|
2200
|
+
|
1794
2201
|
for (var j = 0, jj = glyphsData.length; j < jj; j++) {
|
1795
2202
|
var glyphID = glyphsData[j++] << 8 | glyphsData[j];
|
2203
|
+
|
1796
2204
|
if (glyphID === 0) {
|
1797
2205
|
continue;
|
1798
2206
|
}
|
2207
|
+
|
1799
2208
|
var code = j >> 1;
|
1800
2209
|
result[code] = glyphID;
|
1801
2210
|
}
|
2211
|
+
|
1802
2212
|
return result;
|
1803
2213
|
},
|
1804
2214
|
extractWidths: function PartialEvaluator_extractWidths(dict, descriptor, properties) {
|
@@ -1808,39 +2218,47 @@ var PartialEvaluator = function PartialEvaluatorClosure() {
|
|
1808
2218
|
var glyphsVMetrics = [];
|
1809
2219
|
var defaultVMetrics;
|
1810
2220
|
var i, ii, j, jj, start, code, widths;
|
2221
|
+
|
1811
2222
|
if (properties.composite) {
|
1812
2223
|
defaultWidth = dict.has('DW') ? dict.get('DW') : 1000;
|
1813
2224
|
widths = dict.get('W');
|
2225
|
+
|
1814
2226
|
if (widths) {
|
1815
2227
|
for (i = 0, ii = widths.length; i < ii; i++) {
|
1816
2228
|
start = xref.fetchIfRef(widths[i++]);
|
1817
2229
|
code = xref.fetchIfRef(widths[i]);
|
2230
|
+
|
1818
2231
|
if (Array.isArray(code)) {
|
1819
2232
|
for (j = 0, jj = code.length; j < jj; j++) {
|
1820
2233
|
glyphsWidths[start++] = xref.fetchIfRef(code[j]);
|
1821
2234
|
}
|
1822
2235
|
} else {
|
1823
2236
|
var width = xref.fetchIfRef(widths[++i]);
|
2237
|
+
|
1824
2238
|
for (j = start; j <= code; j++) {
|
1825
2239
|
glyphsWidths[j] = width;
|
1826
2240
|
}
|
1827
2241
|
}
|
1828
2242
|
}
|
1829
2243
|
}
|
2244
|
+
|
1830
2245
|
if (properties.vertical) {
|
1831
2246
|
var vmetrics = dict.getArray('DW2') || [880, -1000];
|
1832
2247
|
defaultVMetrics = [vmetrics[1], defaultWidth * 0.5, vmetrics[0]];
|
1833
2248
|
vmetrics = dict.get('W2');
|
2249
|
+
|
1834
2250
|
if (vmetrics) {
|
1835
2251
|
for (i = 0, ii = vmetrics.length; i < ii; i++) {
|
1836
2252
|
start = xref.fetchIfRef(vmetrics[i++]);
|
1837
2253
|
code = xref.fetchIfRef(vmetrics[i]);
|
2254
|
+
|
1838
2255
|
if (Array.isArray(code)) {
|
1839
2256
|
for (j = 0, jj = code.length; j < jj; j++) {
|
1840
2257
|
glyphsVMetrics[start++] = [xref.fetchIfRef(code[j++]), xref.fetchIfRef(code[j++]), xref.fetchIfRef(code[j])];
|
1841
2258
|
}
|
1842
2259
|
} else {
|
1843
2260
|
var vmetric = [xref.fetchIfRef(vmetrics[++i]), xref.fetchIfRef(vmetrics[++i]), xref.fetchIfRef(vmetrics[++i])];
|
2261
|
+
|
1844
2262
|
for (j = start; j <= code; j++) {
|
1845
2263
|
glyphsVMetrics[j] = vmetric;
|
1846
2264
|
}
|
@@ -1851,14 +2269,18 @@ var PartialEvaluator = function PartialEvaluatorClosure() {
|
|
1851
2269
|
} else {
|
1852
2270
|
var firstChar = properties.firstChar;
|
1853
2271
|
widths = dict.get('Widths');
|
2272
|
+
|
1854
2273
|
if (widths) {
|
1855
2274
|
j = firstChar;
|
2275
|
+
|
1856
2276
|
for (i = 0, ii = widths.length; i < ii; i++) {
|
1857
2277
|
glyphsWidths[j++] = xref.fetchIfRef(widths[i]);
|
1858
2278
|
}
|
2279
|
+
|
1859
2280
|
defaultWidth = parseFloat(descriptor.get('MissingWidth')) || 0;
|
1860
2281
|
} else {
|
1861
2282
|
var baseFontName = dict.get('BaseFont');
|
2283
|
+
|
1862
2284
|
if ((0, _primitives.isName)(baseFontName)) {
|
1863
2285
|
var metrics = this.getBaseFontMetrics(baseFontName.name);
|
1864
2286
|
glyphsWidths = this.buildCharCodeToWidth(metrics.widths, properties);
|
@@ -1866,25 +2288,32 @@ var PartialEvaluator = function PartialEvaluatorClosure() {
|
|
1866
2288
|
}
|
1867
2289
|
}
|
1868
2290
|
}
|
2291
|
+
|
1869
2292
|
var isMonospace = true;
|
1870
2293
|
var firstWidth = defaultWidth;
|
2294
|
+
|
1871
2295
|
for (var glyph in glyphsWidths) {
|
1872
2296
|
var glyphWidth = glyphsWidths[glyph];
|
2297
|
+
|
1873
2298
|
if (!glyphWidth) {
|
1874
2299
|
continue;
|
1875
2300
|
}
|
2301
|
+
|
1876
2302
|
if (!firstWidth) {
|
1877
2303
|
firstWidth = glyphWidth;
|
1878
2304
|
continue;
|
1879
2305
|
}
|
2306
|
+
|
1880
2307
|
if (firstWidth !== glyphWidth) {
|
1881
2308
|
isMonospace = false;
|
1882
2309
|
break;
|
1883
2310
|
}
|
1884
2311
|
}
|
2312
|
+
|
1885
2313
|
if (isMonospace) {
|
1886
2314
|
properties.flags |= _fonts.FontFlags.FixedPitch;
|
1887
2315
|
}
|
2316
|
+
|
1888
2317
|
properties.defaultWidth = defaultWidth;
|
1889
2318
|
properties.widths = glyphsWidths;
|
1890
2319
|
properties.defaultVMetrics = defaultVMetrics;
|
@@ -1901,6 +2330,7 @@ var PartialEvaluator = function PartialEvaluatorClosure() {
|
|
1901
2330
|
var stdFontMap = (0, _standard_fonts.getStdFontMap)();
|
1902
2331
|
var lookupName = stdFontMap[name] || name;
|
1903
2332
|
var Metrics = (0, _metrics.getMetrics)();
|
2333
|
+
|
1904
2334
|
if (!(lookupName in Metrics)) {
|
1905
2335
|
if (this.isSerifFont(name)) {
|
1906
2336
|
lookupName = 'Times-Roman';
|
@@ -1908,13 +2338,16 @@ var PartialEvaluator = function PartialEvaluatorClosure() {
|
|
1908
2338
|
lookupName = 'Helvetica';
|
1909
2339
|
}
|
1910
2340
|
}
|
2341
|
+
|
1911
2342
|
var glyphWidths = Metrics[lookupName];
|
2343
|
+
|
1912
2344
|
if ((0, _util.isNum)(glyphWidths)) {
|
1913
2345
|
defaultWidth = glyphWidths;
|
1914
2346
|
monospace = true;
|
1915
2347
|
} else {
|
1916
2348
|
widths = glyphWidths();
|
1917
2349
|
}
|
2350
|
+
|
1918
2351
|
return {
|
1919
2352
|
defaultWidth: defaultWidth,
|
1920
2353
|
monospace: monospace,
|
@@ -1925,50 +2358,65 @@ var PartialEvaluator = function PartialEvaluatorClosure() {
|
|
1925
2358
|
var widths = Object.create(null);
|
1926
2359
|
var differences = properties.differences;
|
1927
2360
|
var encoding = properties.defaultEncoding;
|
2361
|
+
|
1928
2362
|
for (var charCode = 0; charCode < 256; charCode++) {
|
1929
2363
|
if (charCode in differences && widthsByGlyphName[differences[charCode]]) {
|
1930
2364
|
widths[charCode] = widthsByGlyphName[differences[charCode]];
|
1931
2365
|
continue;
|
1932
2366
|
}
|
2367
|
+
|
1933
2368
|
if (charCode in encoding && widthsByGlyphName[encoding[charCode]]) {
|
1934
2369
|
widths[charCode] = widthsByGlyphName[encoding[charCode]];
|
1935
2370
|
continue;
|
1936
2371
|
}
|
1937
2372
|
}
|
2373
|
+
|
1938
2374
|
return widths;
|
1939
2375
|
},
|
1940
2376
|
preEvaluateFont: function PartialEvaluator_preEvaluateFont(dict) {
|
1941
2377
|
var baseDict = dict;
|
1942
2378
|
var type = dict.get('Subtype');
|
2379
|
+
|
1943
2380
|
if (!(0, _primitives.isName)(type)) {
|
1944
2381
|
throw new _util.FormatError('invalid font Subtype');
|
1945
2382
|
}
|
2383
|
+
|
1946
2384
|
var composite = false;
|
1947
2385
|
var uint8array;
|
2386
|
+
|
1948
2387
|
if (type.name === 'Type0') {
|
1949
2388
|
var df = dict.get('DescendantFonts');
|
2389
|
+
|
1950
2390
|
if (!df) {
|
1951
2391
|
throw new _util.FormatError('Descendant fonts are not specified');
|
1952
2392
|
}
|
2393
|
+
|
1953
2394
|
dict = Array.isArray(df) ? this.xref.fetchIfRef(df[0]) : df;
|
1954
2395
|
type = dict.get('Subtype');
|
2396
|
+
|
1955
2397
|
if (!(0, _primitives.isName)(type)) {
|
1956
2398
|
throw new _util.FormatError('invalid font Subtype');
|
1957
2399
|
}
|
2400
|
+
|
1958
2401
|
composite = true;
|
1959
2402
|
}
|
2403
|
+
|
1960
2404
|
var descriptor = dict.get('FontDescriptor');
|
2405
|
+
|
1961
2406
|
if (descriptor) {
|
1962
2407
|
var hash = new _murmurhash.MurmurHash3_64();
|
1963
2408
|
var encoding = baseDict.getRaw('Encoding');
|
2409
|
+
|
1964
2410
|
if ((0, _primitives.isName)(encoding)) {
|
1965
2411
|
hash.update(encoding.name);
|
1966
2412
|
} else if ((0, _primitives.isRef)(encoding)) {
|
1967
2413
|
hash.update(encoding.toString());
|
1968
2414
|
} else if ((0, _primitives.isDict)(encoding)) {
|
1969
2415
|
var keys = encoding.getKeys();
|
2416
|
+
|
1970
2417
|
for (var i = 0, ii = keys.length; i < ii; i++) {
|
1971
2418
|
var entry = encoding.getRaw(keys[i]);
|
2419
|
+
|
1972
2420
|
if ((0, _primitives.isName)(entry)) {
|
1973
2421
|
hash.update(entry.name);
|
1974
2422
|
} else if ((0, _primitives.isRef)(entry)) {
|
@@ -1976,19 +2424,24 @@ var PartialEvaluator = function PartialEvaluatorClosure() {
|
|
1976
2424
|
} else if (Array.isArray(entry)) {
|
1977
2425
|
var diffLength = entry.length,
|
1978
2426
|
diffBuf = new Array(diffLength);
|
2427
|
+
|
1979
2428
|
for (var j = 0; j < diffLength; j++) {
|
1980
2429
|
var diffEntry = entry[j];
|
2430
|
+
|
1981
2431
|
if ((0, _primitives.isName)(diffEntry)) {
|
1982
2432
|
diffBuf[j] = diffEntry.name;
|
1983
2433
|
} else if ((0, _util.isNum)(diffEntry) || (0, _primitives.isRef)(diffEntry)) {
|
1984
2434
|
diffBuf[j] = diffEntry.toString();
|
1985
2435
|
}
|
1986
2436
|
}
|
2437
|
+
|
1987
2438
|
hash.update(diffBuf.join());
|
1988
2439
|
}
|
1989
2440
|
}
|
1990
2441
|
}
|
2442
|
+
|
1991
2443
|
var toUnicode = dict.get('ToUnicode') || baseDict.get('ToUnicode');
|
2444
|
+
|
1992
2445
|
if ((0, _primitives.isStream)(toUnicode)) {
|
1993
2446
|
var stream = toUnicode.str || toUnicode;
|
1994
2447
|
uint8array = stream.buffer ? new Uint8Array(stream.buffer.buffer, 0, stream.bufferLength) : new Uint8Array(stream.bytes.buffer, stream.start, stream.end - stream.start);
|
@@ -1996,12 +2449,15 @@ var PartialEvaluator = function PartialEvaluatorClosure() {
|
|
1996
2449
|
} else if ((0, _primitives.isName)(toUnicode)) {
|
1997
2450
|
hash.update(toUnicode.name);
|
1998
2451
|
}
|
2452
|
+
|
1999
2453
|
var widths = dict.get('Widths') || baseDict.get('Widths');
|
2454
|
+
|
2000
2455
|
if (widths) {
|
2001
2456
|
uint8array = new Uint8Array(new Uint32Array(widths).buffer);
|
2002
2457
|
hash.update(uint8array);
|
2003
2458
|
}
|
2004
2459
|
}
|
2460
|
+
|
2005
2461
|
return {
|
2006
2462
|
descriptor: descriptor,
|
2007
2463
|
dict: dict,
|
@@ -2012,7 +2468,7 @@ var PartialEvaluator = function PartialEvaluatorClosure() {
|
|
2012
2468
|
};
|
2013
2469
|
},
|
2014
2470
|
translateFont: function PartialEvaluator_translateFont(preEvaluatedFont) {
|
2015
|
-
var
|
2471
|
+
var _this10 = this;
|
2016
2472
|
|
2017
2473
|
var baseDict = preEvaluatedFont.baseDict;
|
2018
2474
|
var dict = preEvaluatedFont.dict;
|
@@ -2021,6 +2477,7 @@ var PartialEvaluator = function PartialEvaluatorClosure() {
|
|
2021
2477
|
var type = preEvaluatedFont.type;
|
2022
2478
|
var maxCharIndex = composite ? 0xFFFF : 0xFF;
|
2023
2479
|
var properties;
|
2480
|
+
|
2024
2481
|
if (!descriptor) {
|
2025
2482
|
if (type === 'Type3') {
|
2026
2483
|
descriptor = new _primitives.Dict(null);
|
@@ -2028,9 +2485,11 @@ var PartialEvaluator = function PartialEvaluatorClosure() {
|
|
2028
2485
|
descriptor.set('FontBBox', dict.getArray('FontBBox'));
|
2029
2486
|
} else {
|
2030
2487
|
var baseFontName = dict.get('BaseFont');
|
2488
|
+
|
2031
2489
|
if (!(0, _primitives.isName)(baseFontName)) {
|
2032
2490
|
throw new _util.FormatError('Base font is not specified');
|
2033
2491
|
}
|
2492
|
+
|
2034
2493
|
baseFontName = baseFontName.name.replace(/[,_]/g, '-');
|
2035
2494
|
var metrics = this.getBaseFontMetrics(baseFontName);
|
2036
2495
|
var fontNameWoStyle = baseFontName.split('-')[0];
|
@@ -2045,47 +2504,60 @@ var PartialEvaluator = function PartialEvaluatorClosure() {
|
|
2045
2504
|
lastChar: maxCharIndex
|
2046
2505
|
};
|
2047
2506
|
return this.extractDataStructures(dict, dict, properties).then(function (properties) {
|
2048
|
-
properties.widths =
|
2507
|
+
properties.widths = _this10.buildCharCodeToWidth(metrics.widths, properties);
|
2049
2508
|
return new _fonts.Font(baseFontName, null, properties);
|
2050
2509
|
});
|
2051
2510
|
}
|
2052
2511
|
}
|
2512
|
+
|
2053
2513
|
var firstChar = dict.get('FirstChar') || 0;
|
2054
2514
|
var lastChar = dict.get('LastChar') || maxCharIndex;
|
2055
2515
|
var fontName = descriptor.get('FontName');
|
2056
2516
|
var baseFont = dict.get('BaseFont');
|
2517
|
+
|
2057
2518
|
if ((0, _util.isString)(fontName)) {
|
2058
2519
|
fontName = _primitives.Name.get(fontName);
|
2059
2520
|
}
|
2521
|
+
|
2060
2522
|
if ((0, _util.isString)(baseFont)) {
|
2061
2523
|
baseFont = _primitives.Name.get(baseFont);
|
2062
2524
|
}
|
2525
|
+
|
2063
2526
|
if (type !== 'Type3') {
|
2064
2527
|
var fontNameStr = fontName && fontName.name;
|
2065
2528
|
var baseFontStr = baseFont && baseFont.name;
|
2529
|
+
|
2066
2530
|
if (fontNameStr !== baseFontStr) {
|
2067
|
-
(0, _util.info)(
|
2068
|
-
|
2531
|
+
(0, _util.info)("The FontDescriptor's FontName is \"".concat(fontNameStr, "\" but ") + "should be the same as the Font's BaseFont \"".concat(baseFontStr, "\"."));
|
2532
|
+
|
2533
|
+
if (fontNameStr && baseFontStr && baseFontStr.startsWith(fontNameStr)) {
|
2069
2534
|
fontName = baseFont;
|
2070
2535
|
}
|
2071
2536
|
}
|
2072
2537
|
}
|
2538
|
+
|
2073
2539
|
fontName = fontName || baseFont;
|
2540
|
+
|
2074
2541
|
if (!(0, _primitives.isName)(fontName)) {
|
2075
2542
|
throw new _util.FormatError('invalid font name');
|
2076
2543
|
}
|
2544
|
+
|
2077
2545
|
var fontFile = descriptor.get('FontFile', 'FontFile2', 'FontFile3');
|
2546
|
+
|
2078
2547
|
if (fontFile) {
|
2079
2548
|
if (fontFile.dict) {
|
2080
2549
|
var subtype = fontFile.dict.get('Subtype');
|
2550
|
+
|
2081
2551
|
if (subtype) {
|
2082
2552
|
subtype = subtype.name;
|
2083
2553
|
}
|
2554
|
+
|
2084
2555
|
var length1 = fontFile.dict.get('Length1');
|
2085
2556
|
var length2 = fontFile.dict.get('Length2');
|
2086
2557
|
var length3 = fontFile.dict.get('Length3');
|
2087
2558
|
}
|
2088
2559
|
}
|
2560
|
+
|
2089
2561
|
properties = {
|
2090
2562
|
type: type,
|
2091
2563
|
name: fontName.name,
|
@@ -2111,11 +2583,14 @@ var PartialEvaluator = function PartialEvaluatorClosure() {
|
|
2111
2583
|
isType3Font: false
|
2112
2584
|
};
|
2113
2585
|
var cMapPromise;
|
2586
|
+
|
2114
2587
|
if (composite) {
|
2115
2588
|
var cidEncoding = baseDict.get('Encoding');
|
2589
|
+
|
2116
2590
|
if ((0, _primitives.isName)(cidEncoding)) {
|
2117
2591
|
properties.cidEncoding = cidEncoding.name;
|
2118
2592
|
}
|
2593
|
+
|
2119
2594
|
cMapPromise = _cmap.CMapFactory.create({
|
2120
2595
|
encoding: cidEncoding,
|
2121
2596
|
fetchBuiltInCMap: this.fetchBuiltInCMap,
|
@@ -2127,19 +2602,65 @@ var PartialEvaluator = function PartialEvaluatorClosure() {
|
|
2127
2602
|
} else {
|
2128
2603
|
cMapPromise = Promise.resolve(undefined);
|
2129
2604
|
}
|
2605
|
+
|
2130
2606
|
return cMapPromise.then(function () {
|
2131
|
-
return
|
2607
|
+
return _this10.extractDataStructures(dict, baseDict, properties);
|
2132
2608
|
}).then(function (properties) {
|
2133
|
-
|
2609
|
+
_this10.extractWidths(dict, descriptor, properties);
|
2610
|
+
|
2134
2611
|
if (type === 'Type3') {
|
2135
2612
|
properties.isType3Font = true;
|
2136
2613
|
}
|
2614
|
+
|
2137
2615
|
return new _fonts.Font(fontName.name, fontFile, properties);
|
2138
2616
|
});
|
2139
2617
|
}
|
2140
2618
|
};
|
2619
|
+
|
2620
|
+
PartialEvaluator.buildFontPaths = function (font, glyphs, handler) {
|
2621
|
+
function buildPath(fontChar) {
|
2622
|
+
if (font.renderer.hasBuiltPath(fontChar)) {
|
2623
|
+
return;
|
2624
|
+
}
|
2625
|
+
|
2626
|
+
handler.send('commonobj', ["".concat(font.loadedName, "_path_").concat(fontChar), 'FontPath', font.renderer.getPathJs(fontChar)]);
|
2627
|
+
}
|
2628
|
+
|
2629
|
+
var _iteratorNormalCompletion = true;
|
2630
|
+
var _didIteratorError = false;
|
2631
|
+
var _iteratorError = undefined;
|
2632
|
+
|
2633
|
+
try {
|
2634
|
+
for (var _iterator = glyphs[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
|
2635
|
+
var glyph = _step.value;
|
2636
|
+
buildPath(glyph.fontChar);
|
2637
|
+
var accent = glyph.accent;
|
2638
|
+
|
2639
|
+
if (accent && accent.fontChar) {
|
2640
|
+
buildPath(accent.fontChar);
|
2641
|
+
}
|
2642
|
+
}
|
2643
|
+
} catch (err) {
|
2644
|
+
_didIteratorError = true;
|
2645
|
+
_iteratorError = err;
|
2646
|
+
} finally {
|
2647
|
+
try {
|
2648
|
+
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
2649
|
+
_iterator.return();
|
2650
|
+
}
|
2651
|
+
} finally {
|
2652
|
+
if (_didIteratorError) {
|
2653
|
+
throw _iteratorError;
|
2654
|
+
}
|
2655
|
+
}
|
2656
|
+
}
|
2657
|
+
};
|
2658
|
+
|
2141
2659
|
return PartialEvaluator;
|
2142
2660
|
}();
|
2661
|
+
|
2662
|
+
exports.PartialEvaluator = PartialEvaluator;
|
2663
|
+
|
2143
2664
|
var TranslatedFont = function TranslatedFontClosure() {
|
2144
2665
|
function TranslatedFont(loadedName, font, dict) {
|
2145
2666
|
this.loadedName = loadedName;
|
@@ -2148,22 +2669,34 @@ var TranslatedFont = function TranslatedFontClosure() {
|
|
2148
2669
|
this.type3Loaded = null;
|
2149
2670
|
this.sent = false;
|
2150
2671
|
}
|
2672
|
+
|
2151
2673
|
TranslatedFont.prototype = {
|
2152
2674
|
send: function send(handler) {
|
2153
2675
|
if (this.sent) {
|
2154
2676
|
return;
|
2155
2677
|
}
|
2156
|
-
|
2157
|
-
handler.send('commonobj', [this.loadedName, 'Font', fontData]);
|
2678
|
+
|
2158
2679
|
this.sent = true;
|
2680
|
+
handler.send('commonobj', [this.loadedName, 'Font', this.font.exportData()]);
|
2681
|
+
},
|
2682
|
+
fallback: function fallback(handler) {
|
2683
|
+
if (!this.font.data) {
|
2684
|
+
return;
|
2685
|
+
}
|
2686
|
+
|
2687
|
+
this.font.disableFontFace = true;
|
2688
|
+
var glyphs = this.font.glyphCacheValues;
|
2689
|
+
PartialEvaluator.buildFontPaths(this.font, glyphs, handler);
|
2159
2690
|
},
|
2160
2691
|
loadType3Data: function loadType3Data(evaluator, resources, parentOperatorList, task) {
|
2161
2692
|
if (!this.font.isType3Font) {
|
2162
2693
|
throw new Error('Must be a Type3 font.');
|
2163
2694
|
}
|
2695
|
+
|
2164
2696
|
if (this.type3Loaded) {
|
2165
2697
|
return this.type3Loaded;
|
2166
2698
|
}
|
2699
|
+
|
2167
2700
|
var type3Options = Object.create(evaluator.options);
|
2168
2701
|
type3Options.ignoreErrors = false;
|
2169
2702
|
var type3Evaluator = evaluator.clone(type3Options);
|
@@ -2188,7 +2721,7 @@ var TranslatedFont = function TranslatedFontClosure() {
|
|
2188
2721
|
charProcOperatorList[key] = operatorList.getIR();
|
2189
2722
|
parentOperatorList.addDependencies(operatorList.dependencies);
|
2190
2723
|
}).catch(function (reason) {
|
2191
|
-
(0, _util.warn)(
|
2724
|
+
(0, _util.warn)("Type3 font resource \"".concat(key, "\" is not available."));
|
2192
2725
|
var operatorList = new _operator_list.OperatorList();
|
2193
2726
|
charProcOperatorList[key] = operatorList.getIR();
|
2194
2727
|
});
|
@@ -2198,6 +2731,7 @@ var TranslatedFont = function TranslatedFontClosure() {
|
|
2198
2731
|
for (var i = 0, n = charProcKeys.length; i < n; ++i) {
|
2199
2732
|
_loop2();
|
2200
2733
|
}
|
2734
|
+
|
2201
2735
|
this.type3Loaded = loadCharProcsPromise.then(function () {
|
2202
2736
|
translatedFont.charProcOperatorList = charProcOperatorList;
|
2203
2737
|
});
|
@@ -2206,11 +2740,13 @@ var TranslatedFont = function TranslatedFontClosure() {
|
|
2206
2740
|
};
|
2207
2741
|
return TranslatedFont;
|
2208
2742
|
}();
|
2743
|
+
|
2209
2744
|
var StateManager = function StateManagerClosure() {
|
2210
2745
|
function StateManager(initialState) {
|
2211
2746
|
this.state = initialState;
|
2212
2747
|
this.stateStack = [];
|
2213
2748
|
}
|
2749
|
+
|
2214
2750
|
StateManager.prototype = {
|
2215
2751
|
save: function save() {
|
2216
2752
|
var old = this.state;
|
@@ -2219,6 +2755,7 @@ var StateManager = function StateManagerClosure() {
|
|
2219
2755
|
},
|
2220
2756
|
restore: function restore() {
|
2221
2757
|
var prev = this.stateStack.pop();
|
2758
|
+
|
2222
2759
|
if (prev) {
|
2223
2760
|
this.state = prev;
|
2224
2761
|
}
|
@@ -2229,6 +2766,7 @@ var StateManager = function StateManagerClosure() {
|
|
2229
2766
|
};
|
2230
2767
|
return StateManager;
|
2231
2768
|
}();
|
2769
|
+
|
2232
2770
|
var TextState = function TextStateClosure() {
|
2233
2771
|
function TextState() {
|
2234
2772
|
this.ctm = new Float32Array(_util.IDENTITY_MATRIX);
|
@@ -2244,6 +2782,7 @@ var TextState = function TextStateClosure() {
|
|
2244
2782
|
this.textHScale = 1;
|
2245
2783
|
this.textRise = 0;
|
2246
2784
|
}
|
2785
|
+
|
2247
2786
|
TextState.prototype = {
|
2248
2787
|
setTextMatrix: function TextState_setTextMatrix(a, b, c, d, e, f) {
|
2249
2788
|
var m = this.textMatrix;
|
@@ -2275,21 +2814,28 @@ var TextState = function TextStateClosure() {
|
|
2275
2814
|
},
|
2276
2815
|
calcTextLineMatrixAdvance: function TextState_calcTextLineMatrixAdvance(a, b, c, d, e, f) {
|
2277
2816
|
var font = this.font;
|
2817
|
+
|
2278
2818
|
if (!font) {
|
2279
2819
|
return null;
|
2280
2820
|
}
|
2821
|
+
|
2281
2822
|
var m = this.textLineMatrix;
|
2823
|
+
|
2282
2824
|
if (!(a === m[0] && b === m[1] && c === m[2] && d === m[3])) {
|
2283
2825
|
return null;
|
2284
2826
|
}
|
2827
|
+
|
2285
2828
|
var txDiff = e - m[4],
|
2286
2829
|
tyDiff = f - m[5];
|
2830
|
+
|
2287
2831
|
if (font.vertical && txDiff !== 0 || !font.vertical && tyDiff !== 0) {
|
2288
2832
|
return null;
|
2289
2833
|
}
|
2834
|
+
|
2290
2835
|
var tx,
|
2291
2836
|
ty,
|
2292
2837
|
denominator = a * d - b * c;
|
2838
|
+
|
2293
2839
|
if (font.vertical) {
|
2294
2840
|
tx = -tyDiff * c / denominator;
|
2295
2841
|
ty = tyDiff * a / denominator;
|
@@ -2297,6 +2843,7 @@ var TextState = function TextStateClosure() {
|
|
2297
2843
|
tx = txDiff * d / denominator;
|
2298
2844
|
ty = -txDiff * b / denominator;
|
2299
2845
|
}
|
2846
|
+
|
2300
2847
|
return {
|
2301
2848
|
width: tx,
|
2302
2849
|
height: ty,
|
@@ -2321,6 +2868,7 @@ var TextState = function TextStateClosure() {
|
|
2321
2868
|
};
|
2322
2869
|
return TextState;
|
2323
2870
|
}();
|
2871
|
+
|
2324
2872
|
var EvalState = function EvalStateClosure() {
|
2325
2873
|
function EvalState() {
|
2326
2874
|
this.ctm = new Float32Array(_util.IDENTITY_MATRIX);
|
@@ -2329,6 +2877,7 @@ var EvalState = function EvalStateClosure() {
|
|
2329
2877
|
this.fillColorSpace = _colorspace.ColorSpace.singletons.gray;
|
2330
2878
|
this.strokeColorSpace = _colorspace.ColorSpace.singletons.gray;
|
2331
2879
|
}
|
2880
|
+
|
2332
2881
|
EvalState.prototype = {
|
2333
2882
|
clone: function CanvasExtraState_clone() {
|
2334
2883
|
return Object.create(this);
|
@@ -2336,6 +2885,7 @@ var EvalState = function EvalStateClosure() {
|
|
2336
2885
|
};
|
2337
2886
|
return EvalState;
|
2338
2887
|
}();
|
2888
|
+
|
2339
2889
|
var EvaluatorPreprocessor = function EvaluatorPreprocessorClosure() {
|
2340
2890
|
var getOPMap = (0, _util.getLookupTableFactory)(function (t) {
|
2341
2891
|
t['w'] = {
|
@@ -2714,68 +3264,95 @@ var EvaluatorPreprocessor = function EvaluatorPreprocessorClosure() {
|
|
2714
3264
|
t['nul'] = null;
|
2715
3265
|
t['null'] = null;
|
2716
3266
|
});
|
3267
|
+
var MAX_INVALID_PATH_OPS = 20;
|
3268
|
+
|
2717
3269
|
function EvaluatorPreprocessor(stream, xref, stateManager) {
|
2718
3270
|
this.opMap = getOPMap();
|
2719
3271
|
this.parser = new _parser.Parser(new _parser.Lexer(stream, this.opMap), false, xref);
|
2720
3272
|
this.stateManager = stateManager;
|
2721
3273
|
this.nonProcessedArgs = [];
|
3274
|
+
this._numInvalidPathOPS = 0;
|
2722
3275
|
}
|
3276
|
+
|
2723
3277
|
EvaluatorPreprocessor.prototype = {
|
2724
3278
|
get savedStatesDepth() {
|
2725
3279
|
return this.stateManager.stateStack.length;
|
2726
3280
|
},
|
3281
|
+
|
2727
3282
|
read: function EvaluatorPreprocessor_read(operation) {
|
2728
3283
|
var args = operation.args;
|
3284
|
+
|
2729
3285
|
while (true) {
|
2730
3286
|
var obj = this.parser.getObj();
|
3287
|
+
|
2731
3288
|
if ((0, _primitives.isCmd)(obj)) {
|
2732
3289
|
var cmd = obj.cmd;
|
2733
3290
|
var opSpec = this.opMap[cmd];
|
3291
|
+
|
2734
3292
|
if (!opSpec) {
|
2735
|
-
(0, _util.warn)(
|
3293
|
+
(0, _util.warn)("Unknown command \"".concat(cmd, "\"."));
|
2736
3294
|
continue;
|
2737
3295
|
}
|
3296
|
+
|
2738
3297
|
var fn = opSpec.id;
|
2739
3298
|
var numArgs = opSpec.numArgs;
|
2740
3299
|
var argsLength = args !== null ? args.length : 0;
|
3300
|
+
|
2741
3301
|
if (!opSpec.variableArgs) {
|
2742
3302
|
if (argsLength !== numArgs) {
|
2743
3303
|
var nonProcessedArgs = this.nonProcessedArgs;
|
3304
|
+
|
2744
3305
|
while (argsLength > numArgs) {
|
2745
3306
|
nonProcessedArgs.push(args.shift());
|
2746
3307
|
argsLength--;
|
2747
3308
|
}
|
3309
|
+
|
2748
3310
|
while (argsLength < numArgs && nonProcessedArgs.length !== 0) {
|
2749
3311
|
if (args === null) {
|
2750
3312
|
args = [];
|
2751
3313
|
}
|
3314
|
+
|
2752
3315
|
args.unshift(nonProcessedArgs.pop());
|
2753
3316
|
argsLength++;
|
2754
3317
|
}
|
2755
3318
|
}
|
3319
|
+
|
2756
3320
|
if (argsLength < numArgs) {
|
2757
|
-
|
3321
|
+
var partialMsg = "command ".concat(cmd, ": expected ").concat(numArgs, " args, ") + "but received ".concat(argsLength, " args.");
|
3322
|
+
|
3323
|
+
if (fn >= _util.OPS.moveTo && fn <= _util.OPS.endPath && ++this._numInvalidPathOPS > MAX_INVALID_PATH_OPS) {
|
3324
|
+
throw new _util.FormatError("Invalid ".concat(partialMsg));
|
3325
|
+
}
|
3326
|
+
|
3327
|
+
(0, _util.warn)("Skipping ".concat(partialMsg));
|
3328
|
+
|
2758
3329
|
if (args !== null) {
|
2759
3330
|
args.length = 0;
|
2760
3331
|
}
|
3332
|
+
|
2761
3333
|
continue;
|
2762
3334
|
}
|
2763
3335
|
} else if (argsLength > numArgs) {
|
2764
|
-
(0, _util.info)(
|
3336
|
+
(0, _util.info)("Command ".concat(cmd, ": expected [0, ").concat(numArgs, "] args, ") + "but received ".concat(argsLength, " args."));
|
2765
3337
|
}
|
3338
|
+
|
2766
3339
|
this.preprocessCommand(fn, args);
|
2767
3340
|
operation.fn = fn;
|
2768
3341
|
operation.args = args;
|
2769
3342
|
return true;
|
2770
3343
|
}
|
3344
|
+
|
2771
3345
|
if ((0, _primitives.isEOF)(obj)) {
|
2772
3346
|
return false;
|
2773
3347
|
}
|
3348
|
+
|
2774
3349
|
if (obj !== null) {
|
2775
3350
|
if (args === null) {
|
2776
3351
|
args = [];
|
2777
3352
|
}
|
3353
|
+
|
2778
3354
|
args.push(obj);
|
3355
|
+
|
2779
3356
|
if (args.length > 33) {
|
2780
3357
|
throw new _util.FormatError('Too many arguments');
|
2781
3358
|
}
|
@@ -2787,9 +3364,11 @@ var EvaluatorPreprocessor = function EvaluatorPreprocessorClosure() {
|
|
2787
3364
|
case _util.OPS.save:
|
2788
3365
|
this.stateManager.save();
|
2789
3366
|
break;
|
3367
|
+
|
2790
3368
|
case _util.OPS.restore:
|
2791
3369
|
this.stateManager.restore();
|
2792
3370
|
break;
|
3371
|
+
|
2793
3372
|
case _util.OPS.transform:
|
2794
3373
|
this.stateManager.transform(args);
|
2795
3374
|
break;
|
@@ -2797,5 +3376,4 @@ var EvaluatorPreprocessor = function EvaluatorPreprocessorClosure() {
|
|
2797
3376
|
}
|
2798
3377
|
};
|
2799
3378
|
return EvaluatorPreprocessor;
|
2800
|
-
}();
|
2801
|
-
exports.PartialEvaluator = PartialEvaluator;
|
3379
|
+
}();
|