pdfjs-dist 2.5.207 → 2.6.347
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 +867 -216
- package/build/pdf.js.map +1 -1
- package/build/pdf.min.js +1 -1
- package/build/pdf.worker.js +10214 -8547
- package/build/pdf.worker.js.map +1 -1
- package/build/pdf.worker.min.js +1 -1
- package/es5/build/pdf.js +2023 -1046
- package/es5/build/pdf.js.map +1 -1
- package/es5/build/pdf.min.js +22 -0
- package/es5/build/pdf.worker.js +11136 -8144
- package/es5/build/pdf.worker.js.map +1 -1
- package/es5/build/pdf.worker.min.js +22 -0
- package/es5/image_decoders/pdf.image_decoders.js +12529 -0
- package/es5/image_decoders/pdf.image_decoders.js.map +1 -0
- package/es5/image_decoders/pdf.image_decoders.min.js +22 -0
- package/es5/web/images/shadow.png +0 -0
- package/es5/web/pdf_viewer.css +8 -5
- package/es5/web/pdf_viewer.js +195 -51
- package/es5/web/pdf_viewer.js.map +1 -1
- package/image_decoders/pdf.image_decoders.js +24 -16
- package/image_decoders/pdf.image_decoders.js.map +1 -1
- package/image_decoders/pdf.image_decoders.min.js +1 -1
- package/lib/core/annotation.js +479 -43
- package/lib/core/cff_parser.js +643 -615
- package/lib/core/chunked_stream.js +64 -50
- package/lib/core/colorspace.js +126 -104
- package/lib/core/crypto.js +37 -0
- package/lib/core/document.js +128 -75
- package/lib/core/evaluator.js +3015 -2754
- package/lib/core/fonts.js +47 -46
- package/lib/core/function.js +79 -6
- package/lib/core/image.js +364 -357
- package/lib/core/image_utils.js +109 -8
- package/lib/core/jpg.js +8 -3
- package/lib/core/obj.js +255 -34
- package/lib/core/operator_list.js +17 -15
- package/lib/core/parser.js +40 -3
- package/lib/core/pattern.js +24 -11
- package/lib/core/primitives.js +112 -53
- package/lib/core/type1_parser.js +2 -0
- package/lib/core/worker.js +102 -37
- package/lib/core/writer.js +242 -0
- package/lib/display/annotation_layer.js +51 -10
- package/lib/display/annotation_storage.js +89 -0
- package/lib/display/api.js +140 -54
- package/lib/display/canvas.js +215 -46
- package/lib/display/display_utils.js +55 -18
- package/lib/display/fetch_stream.js +6 -0
- package/lib/display/font_loader.js +26 -15
- package/lib/display/metadata.js +1 -7
- package/lib/display/network.js +0 -14
- package/lib/display/node_utils.js +87 -0
- package/lib/display/optional_content_config.js +184 -0
- package/lib/display/svg.js +1 -1
- package/lib/display/text_layer.js +4 -1
- package/lib/pdf.js +2 -2
- package/lib/pdf.worker.js +2 -2
- package/lib/shared/is_node.js +1 -1
- package/lib/shared/util.js +13 -10
- package/lib/test/unit/annotation_spec.js +520 -50
- package/lib/test/unit/annotation_storage_spec.js +83 -0
- package/lib/test/unit/api_spec.js +16 -6
- package/lib/test/unit/cmap_spec.js +4 -4
- package/lib/test/unit/colorspace_spec.js +216 -24
- package/lib/test/unit/crypto_spec.js +51 -4
- package/lib/test/unit/custom_spec.js +129 -1
- package/lib/test/unit/document_spec.js +112 -1
- package/lib/test/unit/evaluator_spec.js +29 -10
- package/lib/test/unit/jasmine-boot.js +1 -1
- package/lib/test/unit/metadata_spec.js +3 -3
- package/lib/test/unit/primitives_spec.js +242 -63
- package/lib/test/unit/test_utils.js +42 -89
- package/lib/test/unit/testreporter.js +17 -6
- package/lib/test/unit/util_spec.js +13 -12
- package/lib/test/unit/writer_spec.js +84 -0
- package/lib/web/annotation_layer_builder.js +13 -9
- package/lib/web/app.js +231 -26
- package/lib/web/app_options.js +1 -6
- package/lib/web/base_tree_viewer.js +100 -0
- package/lib/web/base_viewer.js +53 -4
- package/lib/web/download_manager.js +3 -10
- package/lib/web/firefox_print_service.js +32 -12
- package/lib/web/firefoxcom.js +20 -6
- package/lib/web/interfaces.js +1 -1
- package/lib/web/pdf_attachment_viewer.js +80 -38
- package/lib/web/pdf_find_controller.js +2 -1
- package/lib/web/pdf_layer_viewer.js +208 -0
- package/lib/web/pdf_outline_viewer.js +24 -57
- package/lib/web/pdf_page_view.js +29 -6
- package/lib/web/pdf_print_service.js +13 -11
- package/lib/web/pdf_sidebar.js +46 -25
- package/lib/web/pdf_thumbnail_view.js +16 -3
- package/lib/web/pdf_thumbnail_viewer.js +17 -1
- package/lib/web/pdf_viewer.component.js +2 -2
- package/lib/web/preferences.js +1 -1
- package/lib/web/toolbar.js +1 -1
- package/lib/web/ui_utils.js +7 -1
- package/package.json +3 -1
- package/types/display/annotation_layer.d.ts +61 -0
- package/types/display/annotation_storage.d.ts +36 -0
- package/types/display/api.d.ts +1107 -0
- package/types/display/api_compatibility.d.ts +1 -0
- package/types/display/canvas.d.ts +4 -0
- package/types/display/content_disposition.d.ts +7 -0
- package/types/display/display_utils.d.ts +243 -0
- package/types/display/fetch_stream.d.ts +67 -0
- package/types/display/font_loader.d.ts +19 -0
- package/types/display/metadata.d.ts +9 -0
- package/types/display/network.d.ts +80 -0
- package/types/display/network_utils.d.ts +14 -0
- package/types/display/node_stream.d.ts +72 -0
- package/types/display/node_utils.d.ts +6 -0
- package/types/display/optional_content_config.d.ts +12 -0
- package/types/display/pattern_helper.d.ts +5 -0
- package/types/display/svg.d.ts +2 -0
- package/types/display/text_layer.d.ts +83 -0
- package/types/display/transport_stream.d.ts +57 -0
- package/types/display/webgl.d.ts +20 -0
- package/types/display/worker_options.d.ts +27 -0
- package/types/display/xml_parser.d.ts +35 -0
- package/types/pdf.d.ts +33 -0
- package/types/shared/compatibility.d.ts +1 -0
- package/types/shared/is_node.d.ts +1 -0
- package/types/shared/message_handler.d.ts +62 -0
- package/types/shared/util.d.ts +421 -0
- package/web/images/shadow.png +0 -0
- package/web/pdf_viewer.css +8 -5
- package/web/pdf_viewer.js +109 -33
- package/web/pdf_viewer.js.map +1 -1
- package/webpack.js +1 -9
- package/es5/web/images/texture.png +0 -0
- package/web/images/texture.png +0 -0
@@ -37,8 +37,7 @@ class ChunkedStream {
|
|
37
37
|
this.pos = 0;
|
38
38
|
this.end = length;
|
39
39
|
this.chunkSize = chunkSize;
|
40
|
-
this.
|
41
|
-
this.numChunksLoaded = 0;
|
40
|
+
this._loadedChunks = new Set();
|
42
41
|
this.numChunks = Math.ceil(length / chunkSize);
|
43
42
|
this.manager = manager;
|
44
43
|
this.progressiveDataLength = 0;
|
@@ -49,7 +48,7 @@ class ChunkedStream {
|
|
49
48
|
const chunks = [];
|
50
49
|
|
51
50
|
for (let chunk = 0, n = this.numChunks; chunk < n; ++chunk) {
|
52
|
-
if (!this.
|
51
|
+
if (!this._loadedChunks.has(chunk)) {
|
53
52
|
chunks.push(chunk);
|
54
53
|
}
|
55
54
|
}
|
@@ -61,6 +60,10 @@ class ChunkedStream {
|
|
61
60
|
return [this];
|
62
61
|
}
|
63
62
|
|
63
|
+
get numChunksLoaded() {
|
64
|
+
return this._loadedChunks.size;
|
65
|
+
}
|
66
|
+
|
64
67
|
allChunksLoaded() {
|
65
68
|
return this.numChunksLoaded === this.numChunks;
|
66
69
|
}
|
@@ -83,10 +86,7 @@ class ChunkedStream {
|
|
83
86
|
const endChunk = Math.floor((end - 1) / chunkSize) + 1;
|
84
87
|
|
85
88
|
for (let curChunk = beginChunk; curChunk < endChunk; ++curChunk) {
|
86
|
-
|
87
|
-
this.loadedChunks[curChunk] = true;
|
88
|
-
++this.numChunksLoaded;
|
89
|
-
}
|
89
|
+
this._loadedChunks.add(curChunk);
|
90
90
|
}
|
91
91
|
}
|
92
92
|
|
@@ -99,10 +99,7 @@ class ChunkedStream {
|
|
99
99
|
const endChunk = position >= this.end ? this.numChunks : Math.floor(position / this.chunkSize);
|
100
100
|
|
101
101
|
for (let curChunk = beginChunk; curChunk < endChunk; ++curChunk) {
|
102
|
-
|
103
|
-
this.loadedChunks[curChunk] = true;
|
104
|
-
++this.numChunksLoaded;
|
105
|
-
}
|
102
|
+
this._loadedChunks.add(curChunk);
|
106
103
|
}
|
107
104
|
}
|
108
105
|
|
@@ -117,7 +114,7 @@ class ChunkedStream {
|
|
117
114
|
return;
|
118
115
|
}
|
119
116
|
|
120
|
-
if (!this.
|
117
|
+
if (!this._loadedChunks.has(chunk)) {
|
121
118
|
throw new _core_utils.MissingDataException(pos, pos + 1);
|
122
119
|
}
|
123
120
|
|
@@ -138,7 +135,7 @@ class ChunkedStream {
|
|
138
135
|
const endChunk = Math.floor((end - 1) / chunkSize) + 1;
|
139
136
|
|
140
137
|
for (let chunk = beginChunk; chunk < endChunk; ++chunk) {
|
141
|
-
if (!this.
|
138
|
+
if (!this._loadedChunks.has(chunk)) {
|
142
139
|
throw new _core_utils.MissingDataException(begin, end);
|
143
140
|
}
|
144
141
|
}
|
@@ -150,7 +147,7 @@ class ChunkedStream {
|
|
150
147
|
for (let i = 0; i < numChunks; ++i) {
|
151
148
|
const chunk = (beginChunk + i) % numChunks;
|
152
149
|
|
153
|
-
if (!this.
|
150
|
+
if (!this._loadedChunks.has(chunk)) {
|
154
151
|
return chunk;
|
155
152
|
}
|
156
153
|
}
|
@@ -159,7 +156,7 @@ class ChunkedStream {
|
|
159
156
|
}
|
160
157
|
|
161
158
|
hasChunk(chunk) {
|
162
|
-
return
|
159
|
+
return this._loadedChunks.has(chunk);
|
163
160
|
}
|
164
161
|
|
165
162
|
get length() {
|
@@ -302,7 +299,7 @@ class ChunkedStream {
|
|
302
299
|
const missingChunks = [];
|
303
300
|
|
304
301
|
for (let chunk = beginChunk; chunk < endChunk; ++chunk) {
|
305
|
-
if (!this.
|
302
|
+
if (!this._loadedChunks.has(chunk)) {
|
306
303
|
missingChunks.push(chunk);
|
307
304
|
}
|
308
305
|
}
|
@@ -338,9 +335,9 @@ class ChunkedStreamManager {
|
|
338
335
|
this.disableAutoFetch = args.disableAutoFetch;
|
339
336
|
this.msgHandler = args.msgHandler;
|
340
337
|
this.currRequestId = 0;
|
341
|
-
this.
|
342
|
-
this.
|
343
|
-
this.
|
338
|
+
this._chunksNeededByRequest = new Map();
|
339
|
+
this._requestsByChunk = new Map();
|
340
|
+
this._promisesByRequest = new Map();
|
344
341
|
this.progressiveDataLength = 0;
|
345
342
|
this.aborted = false;
|
346
343
|
this._loadedStreamCapability = (0, _util.createPromiseCapability)();
|
@@ -409,47 +406,57 @@ class ChunkedStreamManager {
|
|
409
406
|
|
410
407
|
_requestChunks(chunks) {
|
411
408
|
const requestId = this.currRequestId++;
|
412
|
-
const chunksNeeded =
|
413
|
-
|
409
|
+
const chunksNeeded = new Set();
|
410
|
+
|
411
|
+
this._chunksNeededByRequest.set(requestId, chunksNeeded);
|
414
412
|
|
415
413
|
for (const chunk of chunks) {
|
416
414
|
if (!this.stream.hasChunk(chunk)) {
|
417
|
-
chunksNeeded
|
415
|
+
chunksNeeded.add(chunk);
|
418
416
|
}
|
419
417
|
}
|
420
418
|
|
421
|
-
if (
|
419
|
+
if (chunksNeeded.size === 0) {
|
422
420
|
return Promise.resolve();
|
423
421
|
}
|
424
422
|
|
425
423
|
const capability = (0, _util.createPromiseCapability)();
|
426
|
-
|
424
|
+
|
425
|
+
this._promisesByRequest.set(requestId, capability);
|
426
|
+
|
427
427
|
const chunksToRequest = [];
|
428
428
|
|
429
|
-
for (
|
430
|
-
|
429
|
+
for (const chunk of chunksNeeded) {
|
430
|
+
let requestIds = this._requestsByChunk.get(chunk);
|
431
|
+
|
432
|
+
if (!requestIds) {
|
433
|
+
requestIds = [];
|
434
|
+
|
435
|
+
this._requestsByChunk.set(chunk, requestIds);
|
431
436
|
|
432
|
-
if (!(chunk in this.requestsByChunk)) {
|
433
|
-
this.requestsByChunk[chunk] = [];
|
434
437
|
chunksToRequest.push(chunk);
|
435
438
|
}
|
436
439
|
|
437
|
-
|
438
|
-
}
|
439
|
-
|
440
|
-
if (!chunksToRequest.length) {
|
441
|
-
return capability.promise;
|
440
|
+
requestIds.push(requestId);
|
442
441
|
}
|
443
442
|
|
444
|
-
|
443
|
+
if (chunksToRequest.length > 0) {
|
444
|
+
const groupedChunksToRequest = this.groupChunks(chunksToRequest);
|
445
445
|
|
446
|
-
|
447
|
-
|
448
|
-
|
449
|
-
|
446
|
+
for (const groupedChunk of groupedChunksToRequest) {
|
447
|
+
const begin = groupedChunk.beginChunk * this.chunkSize;
|
448
|
+
const end = Math.min(groupedChunk.endChunk * this.chunkSize, this.length);
|
449
|
+
this.sendRequest(begin, end);
|
450
|
+
}
|
450
451
|
}
|
451
452
|
|
452
|
-
return capability.promise
|
453
|
+
return capability.promise.catch(reason => {
|
454
|
+
if (this.aborted) {
|
455
|
+
return;
|
456
|
+
}
|
457
|
+
|
458
|
+
throw reason;
|
459
|
+
});
|
453
460
|
}
|
454
461
|
|
455
462
|
getStream() {
|
@@ -551,17 +558,22 @@ class ChunkedStreamManager {
|
|
551
558
|
const loadedRequests = [];
|
552
559
|
|
553
560
|
for (let curChunk = beginChunk; curChunk < endChunk; ++curChunk) {
|
554
|
-
const requestIds = this.
|
555
|
-
|
561
|
+
const requestIds = this._requestsByChunk.get(curChunk);
|
562
|
+
|
563
|
+
if (!requestIds) {
|
564
|
+
continue;
|
565
|
+
}
|
566
|
+
|
567
|
+
this._requestsByChunk.delete(curChunk);
|
556
568
|
|
557
569
|
for (const requestId of requestIds) {
|
558
|
-
const chunksNeeded = this.
|
570
|
+
const chunksNeeded = this._chunksNeededByRequest.get(requestId);
|
559
571
|
|
560
|
-
if (curChunk
|
561
|
-
delete
|
572
|
+
if (chunksNeeded.has(curChunk)) {
|
573
|
+
chunksNeeded.delete(curChunk);
|
562
574
|
}
|
563
575
|
|
564
|
-
if (
|
576
|
+
if (chunksNeeded.size > 0) {
|
565
577
|
continue;
|
566
578
|
}
|
567
579
|
|
@@ -569,7 +581,7 @@ class ChunkedStreamManager {
|
|
569
581
|
}
|
570
582
|
}
|
571
583
|
|
572
|
-
if (!this.disableAutoFetch &&
|
584
|
+
if (!this.disableAutoFetch && this._requestsByChunk.size === 0) {
|
573
585
|
let nextEmptyChunk;
|
574
586
|
|
575
587
|
if (this.stream.numChunksLoaded === 1) {
|
@@ -588,8 +600,10 @@ class ChunkedStreamManager {
|
|
588
600
|
}
|
589
601
|
|
590
602
|
for (const requestId of loadedRequests) {
|
591
|
-
const capability = this.
|
592
|
-
|
603
|
+
const capability = this._promisesByRequest.get(requestId);
|
604
|
+
|
605
|
+
this._promisesByRequest.delete(requestId);
|
606
|
+
|
593
607
|
capability.resolve();
|
594
608
|
}
|
595
609
|
|
@@ -618,8 +632,8 @@ class ChunkedStreamManager {
|
|
618
632
|
this.pdfNetworkStream.cancelAllRequests(reason);
|
619
633
|
}
|
620
634
|
|
621
|
-
for (const
|
622
|
-
|
635
|
+
for (const capability of this._promisesByRequest.values()) {
|
636
|
+
capability.reject(reason);
|
623
637
|
}
|
624
638
|
}
|
625
639
|
|
package/lib/core/colorspace.js
CHANGED
@@ -30,6 +30,8 @@ var _util = require("../shared/util.js");
|
|
30
30
|
|
31
31
|
var _primitives = require("./primitives.js");
|
32
32
|
|
33
|
+
var _core_utils = require("./core_utils.js");
|
34
|
+
|
33
35
|
function resizeRgbImage(src, dest, w1, h1, w2, h2, alpha01) {
|
34
36
|
const COMPONENTS = 3;
|
35
37
|
alpha01 = alpha01 !== 1 ? 0 : alpha01;
|
@@ -162,135 +164,162 @@ class ColorSpace {
|
|
162
164
|
return (0, _util.shadow)(this, "usesZeroToOneRange", true);
|
163
165
|
}
|
164
166
|
|
165
|
-
static
|
166
|
-
|
167
|
-
|
168
|
-
|
167
|
+
static _cache(cacheKey, xref, localColorSpaceCache, parsedColorSpace) {
|
168
|
+
if (!localColorSpaceCache) {
|
169
|
+
throw new Error('ColorSpace._cache - expected "localColorSpaceCache" argument.');
|
170
|
+
}
|
169
171
|
|
170
|
-
|
171
|
-
|
172
|
-
|
172
|
+
if (!parsedColorSpace) {
|
173
|
+
throw new Error('ColorSpace._cache - expected "parsedColorSpace" argument.');
|
174
|
+
}
|
173
175
|
|
174
|
-
|
175
|
-
case "DeviceGrayCS":
|
176
|
-
return this.singletons.gray;
|
176
|
+
let csName, csRef;
|
177
177
|
|
178
|
-
|
179
|
-
|
178
|
+
if (cacheKey instanceof _primitives.Ref) {
|
179
|
+
csRef = cacheKey;
|
180
|
+
cacheKey = xref.fetch(cacheKey);
|
181
|
+
}
|
180
182
|
|
181
|
-
|
182
|
-
|
183
|
+
if (cacheKey instanceof _primitives.Name) {
|
184
|
+
csName = cacheKey.name;
|
185
|
+
}
|
183
186
|
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
return new CalGrayCS(whitePoint, blackPoint, gamma);
|
187
|
+
if (csName || csRef) {
|
188
|
+
localColorSpaceCache.set(csName, csRef, parsedColorSpace);
|
189
|
+
}
|
190
|
+
}
|
189
191
|
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
192
|
+
static getCached(cacheKey, xref, localColorSpaceCache) {
|
193
|
+
if (!localColorSpaceCache) {
|
194
|
+
throw new Error('ColorSpace.getCached - expected "localColorSpaceCache" argument.');
|
195
|
+
}
|
196
|
+
|
197
|
+
if (cacheKey instanceof _primitives.Ref) {
|
198
|
+
const localColorSpace = localColorSpaceCache.getByRef(cacheKey);
|
196
199
|
|
197
|
-
|
198
|
-
|
200
|
+
if (localColorSpace) {
|
201
|
+
return localColorSpace;
|
202
|
+
}
|
199
203
|
|
200
|
-
|
201
|
-
|
204
|
+
try {
|
205
|
+
cacheKey = xref.fetch(cacheKey);
|
206
|
+
} catch (ex) {
|
207
|
+
if (ex instanceof _core_utils.MissingDataException) {
|
208
|
+
throw ex;
|
202
209
|
}
|
210
|
+
}
|
211
|
+
}
|
203
212
|
|
204
|
-
|
213
|
+
if (cacheKey instanceof _primitives.Name) {
|
214
|
+
const localColorSpace = localColorSpaceCache.getByName(cacheKey.name);
|
205
215
|
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
return new IndexedCS(this.fromIR(baseIndexedCS), hiVal, lookup);
|
216
|
+
if (localColorSpace) {
|
217
|
+
return localColorSpace;
|
218
|
+
}
|
219
|
+
}
|
211
220
|
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
221
|
+
return null;
|
222
|
+
}
|
223
|
+
|
224
|
+
static async parseAsync({
|
225
|
+
cs,
|
226
|
+
xref,
|
227
|
+
resources = null,
|
228
|
+
pdfFunctionFactory,
|
229
|
+
localColorSpaceCache
|
230
|
+
}) {
|
231
|
+
const parsedColorSpace = this._parse(cs, xref, resources, pdfFunctionFactory);
|
217
232
|
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
return new LabCS(whitePoint, blackPoint, range);
|
233
|
+
this._cache(cs, xref, localColorSpaceCache, parsedColorSpace);
|
234
|
+
|
235
|
+
return parsedColorSpace;
|
236
|
+
}
|
223
237
|
|
224
|
-
|
225
|
-
|
238
|
+
static parse({
|
239
|
+
cs,
|
240
|
+
xref,
|
241
|
+
resources = null,
|
242
|
+
pdfFunctionFactory,
|
243
|
+
localColorSpaceCache
|
244
|
+
}) {
|
245
|
+
const cachedColorSpace = this.getCached(cs, xref, localColorSpaceCache);
|
246
|
+
|
247
|
+
if (cachedColorSpace) {
|
248
|
+
return cachedColorSpace;
|
226
249
|
}
|
250
|
+
|
251
|
+
const parsedColorSpace = this._parse(cs, xref, resources, pdfFunctionFactory);
|
252
|
+
|
253
|
+
this._cache(cs, xref, localColorSpaceCache, parsedColorSpace);
|
254
|
+
|
255
|
+
return parsedColorSpace;
|
227
256
|
}
|
228
257
|
|
229
|
-
static
|
258
|
+
static _parse(cs, xref, resources = null, pdfFunctionFactory) {
|
230
259
|
cs = xref.fetchIfRef(cs);
|
231
260
|
|
232
261
|
if ((0, _primitives.isName)(cs)) {
|
233
262
|
switch (cs.name) {
|
234
263
|
case "DeviceGray":
|
235
264
|
case "G":
|
236
|
-
return
|
265
|
+
return this.singletons.gray;
|
237
266
|
|
238
267
|
case "DeviceRGB":
|
239
268
|
case "RGB":
|
240
|
-
return
|
269
|
+
return this.singletons.rgb;
|
241
270
|
|
242
271
|
case "DeviceCMYK":
|
243
272
|
case "CMYK":
|
244
|
-
return
|
273
|
+
return this.singletons.cmyk;
|
245
274
|
|
246
275
|
case "Pattern":
|
247
|
-
return
|
276
|
+
return new PatternCS(null);
|
248
277
|
|
249
278
|
default:
|
250
|
-
if ((0, _primitives.isDict)(
|
251
|
-
const colorSpaces =
|
279
|
+
if ((0, _primitives.isDict)(resources)) {
|
280
|
+
const colorSpaces = resources.get("ColorSpace");
|
252
281
|
|
253
282
|
if ((0, _primitives.isDict)(colorSpaces)) {
|
254
|
-
const
|
283
|
+
const resourcesCS = colorSpaces.get(cs.name);
|
255
284
|
|
256
|
-
if (
|
257
|
-
if ((0, _primitives.isName)(
|
258
|
-
return this.
|
285
|
+
if (resourcesCS) {
|
286
|
+
if ((0, _primitives.isName)(resourcesCS)) {
|
287
|
+
return this._parse(resourcesCS, xref, resources, pdfFunctionFactory);
|
259
288
|
}
|
260
289
|
|
261
|
-
cs =
|
290
|
+
cs = resourcesCS;
|
262
291
|
break;
|
263
292
|
}
|
264
293
|
}
|
265
294
|
}
|
266
295
|
|
267
|
-
throw new _util.FormatError(`
|
296
|
+
throw new _util.FormatError(`Unrecognized ColorSpace: ${cs.name}`);
|
268
297
|
}
|
269
298
|
}
|
270
299
|
|
271
300
|
if (Array.isArray(cs)) {
|
272
301
|
const mode = xref.fetchIfRef(cs[0]).name;
|
273
|
-
let
|
302
|
+
let params, numComps, baseCS, whitePoint, blackPoint, gamma;
|
274
303
|
|
275
304
|
switch (mode) {
|
276
305
|
case "DeviceGray":
|
277
306
|
case "G":
|
278
|
-
return
|
307
|
+
return this.singletons.gray;
|
279
308
|
|
280
309
|
case "DeviceRGB":
|
281
310
|
case "RGB":
|
282
|
-
return
|
311
|
+
return this.singletons.rgb;
|
283
312
|
|
284
313
|
case "DeviceCMYK":
|
285
314
|
case "CMYK":
|
286
|
-
return
|
315
|
+
return this.singletons.cmyk;
|
287
316
|
|
288
317
|
case "CalGray":
|
289
318
|
params = xref.fetchIfRef(cs[1]);
|
290
319
|
whitePoint = params.getArray("WhitePoint");
|
291
320
|
blackPoint = params.getArray("BlackPoint");
|
292
321
|
gamma = params.get("Gamma");
|
293
|
-
return
|
322
|
+
return new CalGrayCS(whitePoint, blackPoint, gamma);
|
294
323
|
|
295
324
|
case "CalRGB":
|
296
325
|
params = xref.fetchIfRef(cs[1]);
|
@@ -298,77 +327,71 @@ class ColorSpace {
|
|
298
327
|
blackPoint = params.getArray("BlackPoint");
|
299
328
|
gamma = params.getArray("Gamma");
|
300
329
|
const matrix = params.getArray("Matrix");
|
301
|
-
return
|
330
|
+
return new CalRGBCS(whitePoint, blackPoint, gamma, matrix);
|
302
331
|
|
303
332
|
case "ICCBased":
|
304
333
|
const stream = xref.fetchIfRef(cs[1]);
|
305
334
|
const dict = stream.dict;
|
306
335
|
numComps = dict.get("N");
|
307
|
-
alt = dict.get("Alternate");
|
336
|
+
const alt = dict.get("Alternate");
|
308
337
|
|
309
338
|
if (alt) {
|
310
|
-
const
|
311
|
-
const altCS = this.fromIR(altIR, pdfFunctionFactory);
|
339
|
+
const altCS = this._parse(alt, xref, resources, pdfFunctionFactory);
|
312
340
|
|
313
341
|
if (altCS.numComps === numComps) {
|
314
|
-
return
|
342
|
+
return altCS;
|
315
343
|
}
|
316
344
|
|
317
345
|
(0, _util.warn)("ICCBased color space: Ignoring incorrect /Alternate entry.");
|
318
346
|
}
|
319
347
|
|
320
348
|
if (numComps === 1) {
|
321
|
-
return
|
349
|
+
return this.singletons.gray;
|
322
350
|
} else if (numComps === 3) {
|
323
|
-
return
|
351
|
+
return this.singletons.rgb;
|
324
352
|
} else if (numComps === 4) {
|
325
|
-
return
|
353
|
+
return this.singletons.cmyk;
|
326
354
|
}
|
327
355
|
|
328
356
|
break;
|
329
357
|
|
330
358
|
case "Pattern":
|
331
|
-
|
359
|
+
baseCS = cs[1] || null;
|
332
360
|
|
333
|
-
if (
|
334
|
-
|
361
|
+
if (baseCS) {
|
362
|
+
baseCS = this._parse(baseCS, xref, resources, pdfFunctionFactory);
|
335
363
|
}
|
336
364
|
|
337
|
-
return
|
365
|
+
return new PatternCS(baseCS);
|
338
366
|
|
339
367
|
case "Indexed":
|
340
368
|
case "I":
|
341
|
-
|
369
|
+
baseCS = this._parse(cs[1], xref, resources, pdfFunctionFactory);
|
342
370
|
const hiVal = xref.fetchIfRef(cs[2]) + 1;
|
343
|
-
|
344
|
-
|
345
|
-
if ((0, _primitives.isStream)(lookup)) {
|
346
|
-
lookup = lookup.getBytes();
|
347
|
-
}
|
348
|
-
|
349
|
-
return ["IndexedCS", baseIndexedCS, hiVal, lookup];
|
371
|
+
const lookup = xref.fetchIfRef(cs[3]);
|
372
|
+
return new IndexedCS(baseCS, hiVal, lookup);
|
350
373
|
|
351
374
|
case "Separation":
|
352
375
|
case "DeviceN":
|
353
376
|
const name = xref.fetchIfRef(cs[1]);
|
354
377
|
numComps = Array.isArray(name) ? name.length : 1;
|
355
|
-
|
356
|
-
const tintFn = pdfFunctionFactory.create(
|
357
|
-
return
|
378
|
+
baseCS = this._parse(cs[2], xref, resources, pdfFunctionFactory);
|
379
|
+
const tintFn = pdfFunctionFactory.create(cs[3]);
|
380
|
+
return new AlternateCS(numComps, baseCS, tintFn);
|
358
381
|
|
359
382
|
case "Lab":
|
360
383
|
params = xref.fetchIfRef(cs[1]);
|
361
384
|
whitePoint = params.getArray("WhitePoint");
|
362
385
|
blackPoint = params.getArray("BlackPoint");
|
363
386
|
const range = params.getArray("Range");
|
364
|
-
return
|
387
|
+
return new LabCS(whitePoint, blackPoint, range);
|
365
388
|
|
366
389
|
default:
|
367
|
-
throw new _util.FormatError(`
|
390
|
+
throw new _util.FormatError(`Unimplemented ColorSpace object: ${mode}`);
|
368
391
|
}
|
369
392
|
}
|
370
393
|
|
371
|
-
throw new _util.FormatError(`
|
394
|
+
throw new _util.FormatError(`Unrecognized ColorSpace object: ${cs}`);
|
372
395
|
}
|
373
396
|
|
374
397
|
static isDefaultDecode(decode, numComps) {
|
@@ -484,23 +507,18 @@ class IndexedCS extends ColorSpace {
|
|
484
507
|
super("Indexed", 1);
|
485
508
|
this.base = base;
|
486
509
|
this.highVal = highVal;
|
487
|
-
const
|
488
|
-
|
510
|
+
const length = base.numComps * highVal;
|
511
|
+
this.lookup = new Uint8Array(length);
|
489
512
|
|
490
513
|
if ((0, _primitives.isStream)(lookup)) {
|
491
|
-
this.lookup = new Uint8Array(length);
|
492
514
|
const bytes = lookup.getBytes(length);
|
493
515
|
this.lookup.set(bytes);
|
494
|
-
} else if (
|
495
|
-
this.lookup = new Uint8Array(length);
|
496
|
-
|
516
|
+
} else if (typeof lookup === "string") {
|
497
517
|
for (let i = 0; i < length; ++i) {
|
498
|
-
this.lookup[i] = lookup.charCodeAt(i);
|
518
|
+
this.lookup[i] = lookup.charCodeAt(i) & 0xff;
|
499
519
|
}
|
500
|
-
} else if (lookup instanceof Uint8Array) {
|
501
|
-
this.lookup = lookup;
|
502
520
|
} else {
|
503
|
-
throw new _util.FormatError(`
|
521
|
+
throw new _util.FormatError(`IndexedCS - unrecognized lookup table: ${lookup}`);
|
504
522
|
}
|
505
523
|
}
|
506
524
|
|
@@ -762,6 +780,10 @@ const CalRGBCS = function CalRGBCSClosure() {
|
|
762
780
|
return adjustToRange(0, 1, 12.92 * color);
|
763
781
|
}
|
764
782
|
|
783
|
+
if (color >= 0.99554525) {
|
784
|
+
return 1;
|
785
|
+
}
|
786
|
+
|
765
787
|
return adjustToRange(0, 1, (1 + 0.055) * color ** (1 / 2.4) - 0.055);
|
766
788
|
}
|
767
789
|
|
@@ -834,9 +856,9 @@ const CalRGBCS = function CalRGBCSClosure() {
|
|
834
856
|
const A = adjustToRange(0, 1, src[srcOffset] * scale);
|
835
857
|
const B = adjustToRange(0, 1, src[srcOffset + 1] * scale);
|
836
858
|
const C = adjustToRange(0, 1, src[srcOffset + 2] * scale);
|
837
|
-
const AGR = A ** cs.GR;
|
838
|
-
const BGG = B ** cs.GG;
|
839
|
-
const CGB = C ** cs.GB;
|
859
|
+
const AGR = A === 1 ? 1 : A ** cs.GR;
|
860
|
+
const BGG = B === 1 ? 1 : B ** cs.GG;
|
861
|
+
const CGB = C === 1 ? 1 : C ** cs.GB;
|
840
862
|
const X = cs.MXA * AGR + cs.MXB * BGG + cs.MXC * CGB;
|
841
863
|
const Y = cs.MYA * AGR + cs.MYB * BGG + cs.MYC * CGB;
|
842
864
|
const Z = cs.MZA * AGR + cs.MZB * BGG + cs.MZC * CGB;
|