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.

Files changed (133) hide show
  1. package/bower.json +1 -1
  2. package/build/pdf.js +867 -216
  3. package/build/pdf.js.map +1 -1
  4. package/build/pdf.min.js +1 -1
  5. package/build/pdf.worker.js +10214 -8547
  6. package/build/pdf.worker.js.map +1 -1
  7. package/build/pdf.worker.min.js +1 -1
  8. package/es5/build/pdf.js +2023 -1046
  9. package/es5/build/pdf.js.map +1 -1
  10. package/es5/build/pdf.min.js +22 -0
  11. package/es5/build/pdf.worker.js +11136 -8144
  12. package/es5/build/pdf.worker.js.map +1 -1
  13. package/es5/build/pdf.worker.min.js +22 -0
  14. package/es5/image_decoders/pdf.image_decoders.js +12529 -0
  15. package/es5/image_decoders/pdf.image_decoders.js.map +1 -0
  16. package/es5/image_decoders/pdf.image_decoders.min.js +22 -0
  17. package/es5/web/images/shadow.png +0 -0
  18. package/es5/web/pdf_viewer.css +8 -5
  19. package/es5/web/pdf_viewer.js +195 -51
  20. package/es5/web/pdf_viewer.js.map +1 -1
  21. package/image_decoders/pdf.image_decoders.js +24 -16
  22. package/image_decoders/pdf.image_decoders.js.map +1 -1
  23. package/image_decoders/pdf.image_decoders.min.js +1 -1
  24. package/lib/core/annotation.js +479 -43
  25. package/lib/core/cff_parser.js +643 -615
  26. package/lib/core/chunked_stream.js +64 -50
  27. package/lib/core/colorspace.js +126 -104
  28. package/lib/core/crypto.js +37 -0
  29. package/lib/core/document.js +128 -75
  30. package/lib/core/evaluator.js +3015 -2754
  31. package/lib/core/fonts.js +47 -46
  32. package/lib/core/function.js +79 -6
  33. package/lib/core/image.js +364 -357
  34. package/lib/core/image_utils.js +109 -8
  35. package/lib/core/jpg.js +8 -3
  36. package/lib/core/obj.js +255 -34
  37. package/lib/core/operator_list.js +17 -15
  38. package/lib/core/parser.js +40 -3
  39. package/lib/core/pattern.js +24 -11
  40. package/lib/core/primitives.js +112 -53
  41. package/lib/core/type1_parser.js +2 -0
  42. package/lib/core/worker.js +102 -37
  43. package/lib/core/writer.js +242 -0
  44. package/lib/display/annotation_layer.js +51 -10
  45. package/lib/display/annotation_storage.js +89 -0
  46. package/lib/display/api.js +140 -54
  47. package/lib/display/canvas.js +215 -46
  48. package/lib/display/display_utils.js +55 -18
  49. package/lib/display/fetch_stream.js +6 -0
  50. package/lib/display/font_loader.js +26 -15
  51. package/lib/display/metadata.js +1 -7
  52. package/lib/display/network.js +0 -14
  53. package/lib/display/node_utils.js +87 -0
  54. package/lib/display/optional_content_config.js +184 -0
  55. package/lib/display/svg.js +1 -1
  56. package/lib/display/text_layer.js +4 -1
  57. package/lib/pdf.js +2 -2
  58. package/lib/pdf.worker.js +2 -2
  59. package/lib/shared/is_node.js +1 -1
  60. package/lib/shared/util.js +13 -10
  61. package/lib/test/unit/annotation_spec.js +520 -50
  62. package/lib/test/unit/annotation_storage_spec.js +83 -0
  63. package/lib/test/unit/api_spec.js +16 -6
  64. package/lib/test/unit/cmap_spec.js +4 -4
  65. package/lib/test/unit/colorspace_spec.js +216 -24
  66. package/lib/test/unit/crypto_spec.js +51 -4
  67. package/lib/test/unit/custom_spec.js +129 -1
  68. package/lib/test/unit/document_spec.js +112 -1
  69. package/lib/test/unit/evaluator_spec.js +29 -10
  70. package/lib/test/unit/jasmine-boot.js +1 -1
  71. package/lib/test/unit/metadata_spec.js +3 -3
  72. package/lib/test/unit/primitives_spec.js +242 -63
  73. package/lib/test/unit/test_utils.js +42 -89
  74. package/lib/test/unit/testreporter.js +17 -6
  75. package/lib/test/unit/util_spec.js +13 -12
  76. package/lib/test/unit/writer_spec.js +84 -0
  77. package/lib/web/annotation_layer_builder.js +13 -9
  78. package/lib/web/app.js +231 -26
  79. package/lib/web/app_options.js +1 -6
  80. package/lib/web/base_tree_viewer.js +100 -0
  81. package/lib/web/base_viewer.js +53 -4
  82. package/lib/web/download_manager.js +3 -10
  83. package/lib/web/firefox_print_service.js +32 -12
  84. package/lib/web/firefoxcom.js +20 -6
  85. package/lib/web/interfaces.js +1 -1
  86. package/lib/web/pdf_attachment_viewer.js +80 -38
  87. package/lib/web/pdf_find_controller.js +2 -1
  88. package/lib/web/pdf_layer_viewer.js +208 -0
  89. package/lib/web/pdf_outline_viewer.js +24 -57
  90. package/lib/web/pdf_page_view.js +29 -6
  91. package/lib/web/pdf_print_service.js +13 -11
  92. package/lib/web/pdf_sidebar.js +46 -25
  93. package/lib/web/pdf_thumbnail_view.js +16 -3
  94. package/lib/web/pdf_thumbnail_viewer.js +17 -1
  95. package/lib/web/pdf_viewer.component.js +2 -2
  96. package/lib/web/preferences.js +1 -1
  97. package/lib/web/toolbar.js +1 -1
  98. package/lib/web/ui_utils.js +7 -1
  99. package/package.json +3 -1
  100. package/types/display/annotation_layer.d.ts +61 -0
  101. package/types/display/annotation_storage.d.ts +36 -0
  102. package/types/display/api.d.ts +1107 -0
  103. package/types/display/api_compatibility.d.ts +1 -0
  104. package/types/display/canvas.d.ts +4 -0
  105. package/types/display/content_disposition.d.ts +7 -0
  106. package/types/display/display_utils.d.ts +243 -0
  107. package/types/display/fetch_stream.d.ts +67 -0
  108. package/types/display/font_loader.d.ts +19 -0
  109. package/types/display/metadata.d.ts +9 -0
  110. package/types/display/network.d.ts +80 -0
  111. package/types/display/network_utils.d.ts +14 -0
  112. package/types/display/node_stream.d.ts +72 -0
  113. package/types/display/node_utils.d.ts +6 -0
  114. package/types/display/optional_content_config.d.ts +12 -0
  115. package/types/display/pattern_helper.d.ts +5 -0
  116. package/types/display/svg.d.ts +2 -0
  117. package/types/display/text_layer.d.ts +83 -0
  118. package/types/display/transport_stream.d.ts +57 -0
  119. package/types/display/webgl.d.ts +20 -0
  120. package/types/display/worker_options.d.ts +27 -0
  121. package/types/display/xml_parser.d.ts +35 -0
  122. package/types/pdf.d.ts +33 -0
  123. package/types/shared/compatibility.d.ts +1 -0
  124. package/types/shared/is_node.d.ts +1 -0
  125. package/types/shared/message_handler.d.ts +62 -0
  126. package/types/shared/util.d.ts +421 -0
  127. package/web/images/shadow.png +0 -0
  128. package/web/pdf_viewer.css +8 -5
  129. package/web/pdf_viewer.js +109 -33
  130. package/web/pdf_viewer.js.map +1 -1
  131. package/webpack.js +1 -9
  132. package/es5/web/images/texture.png +0 -0
  133. package/web/images/texture.png +0 -0
@@ -0,0 +1,83 @@
1
+ /**
2
+ * @licstart The following is the entire license notice for the
3
+ * Javascript code in this page
4
+ *
5
+ * Copyright 2020 Mozilla Foundation
6
+ *
7
+ * Licensed under the Apache License, Version 2.0 (the "License");
8
+ * you may not use this file except in compliance with the License.
9
+ * You may obtain a copy of the License at
10
+ *
11
+ * http://www.apache.org/licenses/LICENSE-2.0
12
+ *
13
+ * Unless required by applicable law or agreed to in writing, software
14
+ * distributed under the License is distributed on an "AS IS" BASIS,
15
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
+ * See the License for the specific language governing permissions and
17
+ * limitations under the License.
18
+ *
19
+ * @licend The above is the entire license notice for the
20
+ * Javascript code in this page
21
+ */
22
+ "use strict";
23
+
24
+ var _annotation_storage = require("../../display/annotation_storage.js");
25
+
26
+ describe("AnnotationStorage", function () {
27
+ describe("GetOrCreateValue", function () {
28
+ it("should get and set a new value in the annotation storage", function (done) {
29
+ const annotationStorage = new _annotation_storage.AnnotationStorage();
30
+ let value = annotationStorage.getOrCreateValue("123A", "hello world");
31
+ expect(value).toEqual("hello world");
32
+ value = annotationStorage.getOrCreateValue("123A", "an other string");
33
+ expect(value).toEqual("hello world");
34
+ done();
35
+ });
36
+ });
37
+ describe("SetValue", function () {
38
+ it("should set a new value in the annotation storage", function (done) {
39
+ const annotationStorage = new _annotation_storage.AnnotationStorage();
40
+ annotationStorage.setValue("123A", "an other string");
41
+ const value = annotationStorage.getAll()["123A"];
42
+ expect(value).toEqual("an other string");
43
+ done();
44
+ });
45
+ it("should call onSetModified() if value is changed", function (done) {
46
+ const annotationStorage = new _annotation_storage.AnnotationStorage();
47
+ let called = false;
48
+
49
+ const callback = function () {
50
+ called = true;
51
+ };
52
+
53
+ annotationStorage.onSetModified = callback;
54
+ annotationStorage.getOrCreateValue("asdf", "original");
55
+ expect(called).toBe(false);
56
+ annotationStorage.setValue("asdf", "original");
57
+ expect(called).toBe(false);
58
+ annotationStorage.setValue("asdf", "modified");
59
+ expect(called).toBe(true);
60
+ done();
61
+ });
62
+ });
63
+ describe("ResetModified", function () {
64
+ it("should call onResetModified() if set", function (done) {
65
+ const annotationStorage = new _annotation_storage.AnnotationStorage();
66
+ let called = false;
67
+
68
+ const callback = function () {
69
+ called = true;
70
+ };
71
+
72
+ annotationStorage.onResetModified = callback;
73
+ annotationStorage.getOrCreateValue("asdf", "original");
74
+ annotationStorage.setValue("asdf", "original");
75
+ annotationStorage.resetModified();
76
+ expect(called).toBe(false);
77
+ annotationStorage.setValue("asdf", "modified");
78
+ annotationStorage.resetModified();
79
+ expect(called).toBe(true);
80
+ done();
81
+ });
82
+ });
83
+ });
@@ -39,6 +39,8 @@ var _is_node = require("../../shared/is_node.js");
39
39
 
40
40
  var _metadata = require("../../display/metadata.js");
41
41
 
42
+ var _node_utils = require("../../display/node_utils.js");
43
+
42
44
  describe("api", function () {
43
45
  const basicApiFileName = "basicapi.pdf";
44
46
  const basicApiFileLength = 105779;
@@ -46,7 +48,7 @@ describe("api", function () {
46
48
  let CanvasFactory;
47
49
  beforeAll(function (done) {
48
50
  if (_is_node.isNodeJS) {
49
- CanvasFactory = new _test_utils.NodeCanvasFactory();
51
+ CanvasFactory = new _node_utils.NodeCanvasFactory();
50
52
  } else {
51
53
  CanvasFactory = new _display_utils.DOMCanvasFactory();
52
54
  }
@@ -1240,8 +1242,8 @@ describe("api", function () {
1240
1242
  const result1 = loadingTask1.promise.then(pdfDoc => {
1241
1243
  return pdfDoc.getPage(1).then(pdfPage => {
1242
1244
  return pdfPage.getOperatorList().then(opList => {
1243
- expect(opList.fnArray.length).toEqual(722);
1244
- expect(opList.argsArray.length).toEqual(722);
1245
+ expect(opList.fnArray.length).toBeGreaterThan(100);
1246
+ expect(opList.argsArray.length).toBeGreaterThan(100);
1245
1247
  expect(opList.lastChunk).toEqual(true);
1246
1248
  return loadingTask1.destroy();
1247
1249
  });
@@ -1386,6 +1388,7 @@ describe("api", function () {
1386
1388
  }, done.fail);
1387
1389
  });
1388
1390
  it("multiple render() on the same canvas", function (done) {
1391
+ const optionalContentConfigPromise = pdfDocument.getOptionalContentConfig();
1389
1392
  var viewport = page.getViewport({
1390
1393
  scale: 1
1391
1394
  });
@@ -1393,12 +1396,14 @@ describe("api", function () {
1393
1396
  var renderTask1 = page.render({
1394
1397
  canvasContext: canvasAndCtx.context,
1395
1398
  canvasFactory: CanvasFactory,
1396
- viewport
1399
+ viewport,
1400
+ optionalContentConfigPromise
1397
1401
  });
1398
1402
  var renderTask2 = page.render({
1399
1403
  canvasContext: canvasAndCtx.context,
1400
1404
  canvasFactory: CanvasFactory,
1401
- viewport
1405
+ viewport,
1406
+ optionalContentConfigPromise
1402
1407
  });
1403
1408
  Promise.all([renderTask1.promise, renderTask2.promise.then(() => {
1404
1409
  done.fail("shall fail rendering");
@@ -1444,7 +1449,12 @@ describe("api", function () {
1444
1449
  canvasFactory: CanvasFactory,
1445
1450
  viewport
1446
1451
  });
1447
- pdfDoc.cleanup().then(() => {
1452
+
1453
+ renderTask.onContinue = function (cont) {
1454
+ waitSome(cont);
1455
+ };
1456
+
1457
+ return pdfDoc.cleanup().then(() => {
1448
1458
  throw new Error("shall fail cleanup");
1449
1459
  }, reason => {
1450
1460
  expect(reason instanceof Error).toEqual(true);
@@ -29,7 +29,7 @@ var _is_node = require("../../shared/is_node.js");
29
29
 
30
30
  var _primitives = require("../../core/primitives.js");
31
31
 
32
- var _test_utils = require("./test_utils.js");
32
+ var _node_utils = require("../../display/node_utils.js");
33
33
 
34
34
  var _stream = require("../../core/stream.js");
35
35
 
@@ -44,7 +44,7 @@ describe("cmap", function () {
44
44
  var CMapReaderFactory;
45
45
 
46
46
  if (_is_node.isNodeJS) {
47
- CMapReaderFactory = new _test_utils.NodeCMapReaderFactory({
47
+ CMapReaderFactory = new _node_utils.NodeCMapReaderFactory({
48
48
  baseUrl: cMapUrl.node,
49
49
  isCompressed: cMapPacked
50
50
  });
@@ -297,7 +297,7 @@ describe("cmap", function () {
297
297
  });
298
298
  it("attempts to load a built-in CMap without the necessary API parameters", function (done) {
299
299
  function tmpFetchBuiltInCMap(name) {
300
- var CMapReaderFactory = _is_node.isNodeJS ? new _test_utils.NodeCMapReaderFactory({}) : new _display_utils.DOMCMapReaderFactory({});
300
+ var CMapReaderFactory = _is_node.isNodeJS ? new _node_utils.NodeCMapReaderFactory({}) : new _display_utils.DOMCMapReaderFactory({});
301
301
  return CMapReaderFactory.fetch({
302
302
  name
303
303
  });
@@ -322,7 +322,7 @@ describe("cmap", function () {
322
322
  let CMapReaderFactory;
323
323
 
324
324
  if (_is_node.isNodeJS) {
325
- CMapReaderFactory = new _test_utils.NodeCMapReaderFactory({
325
+ CMapReaderFactory = new _node_utils.NodeCMapReaderFactory({
326
326
  baseUrl: cMapUrl.node,
327
327
  isCompressed: false
328
328
  });
@@ -27,12 +27,14 @@ var _stream = require("../../core/stream.js");
27
27
 
28
28
  var _colorspace = require("../../core/colorspace.js");
29
29
 
30
+ var _image_utils = require("../../core/image_utils.js");
31
+
30
32
  var _function = require("../../core/function.js");
31
33
 
32
34
  var _test_utils = require("./test_utils.js");
33
35
 
34
36
  describe("colorspace", function () {
35
- describe("ColorSpace", function () {
37
+ describe("ColorSpace.isDefaultDecode", function () {
36
38
  it("should be true if decode is not an array", function () {
37
39
  expect(_colorspace.ColorSpace.isDefaultDecode("string", 0)).toBeTruthy();
38
40
  });
@@ -50,6 +52,130 @@ describe("colorspace", function () {
50
52
  expect(_colorspace.ColorSpace.isDefaultDecode([1, 0, 0, 1, 0, 1, 0, 1], 4)).toBeFalsy();
51
53
  });
52
54
  });
55
+ describe("ColorSpace caching", function () {
56
+ let localColorSpaceCache = null;
57
+ beforeAll(function (done) {
58
+ localColorSpaceCache = new _image_utils.LocalColorSpaceCache();
59
+ done();
60
+ });
61
+ afterAll(function (done) {
62
+ localColorSpaceCache = null;
63
+ done();
64
+ });
65
+ it("caching by Name", function () {
66
+ const xref = new _test_utils.XRefMock();
67
+ const pdfFunctionFactory = new _function.PDFFunctionFactory({
68
+ xref
69
+ });
70
+
71
+ const colorSpace1 = _colorspace.ColorSpace.parse({
72
+ cs: _primitives.Name.get("Pattern"),
73
+ xref,
74
+ resources: null,
75
+ pdfFunctionFactory,
76
+ localColorSpaceCache
77
+ });
78
+
79
+ expect(colorSpace1.name).toEqual("Pattern");
80
+
81
+ const colorSpace2 = _colorspace.ColorSpace.parse({
82
+ cs: _primitives.Name.get("Pattern"),
83
+ xref,
84
+ resources: null,
85
+ pdfFunctionFactory,
86
+ localColorSpaceCache
87
+ });
88
+
89
+ expect(colorSpace2.name).toEqual("Pattern");
90
+
91
+ const colorSpaceNonCached = _colorspace.ColorSpace.parse({
92
+ cs: _primitives.Name.get("Pattern"),
93
+ xref,
94
+ resources: null,
95
+ pdfFunctionFactory,
96
+ localColorSpaceCache: new _image_utils.LocalColorSpaceCache()
97
+ });
98
+
99
+ expect(colorSpaceNonCached.name).toEqual("Pattern");
100
+
101
+ const colorSpaceOther = _colorspace.ColorSpace.parse({
102
+ cs: _primitives.Name.get("RGB"),
103
+ xref,
104
+ resources: null,
105
+ pdfFunctionFactory,
106
+ localColorSpaceCache
107
+ });
108
+
109
+ expect(colorSpaceOther.name).toEqual("DeviceRGB");
110
+ expect(colorSpace1).toBe(colorSpace2);
111
+ expect(colorSpace1).not.toBe(colorSpaceNonCached);
112
+ expect(colorSpace1).not.toBe(colorSpaceOther);
113
+ });
114
+ it("caching by Ref", function () {
115
+ const paramsCalGray = new _primitives.Dict();
116
+ paramsCalGray.set("WhitePoint", [1, 1, 1]);
117
+ paramsCalGray.set("BlackPoint", [0, 0, 0]);
118
+ paramsCalGray.set("Gamma", 2.0);
119
+ const paramsCalRGB = new _primitives.Dict();
120
+ paramsCalRGB.set("WhitePoint", [1, 1, 1]);
121
+ paramsCalRGB.set("BlackPoint", [0, 0, 0]);
122
+ paramsCalRGB.set("Gamma", [1, 1, 1]);
123
+ paramsCalRGB.set("Matrix", [1, 0, 0, 0, 1, 0, 0, 0, 1]);
124
+ const xref = new _test_utils.XRefMock([{
125
+ ref: _primitives.Ref.get(50, 0),
126
+ data: [_primitives.Name.get("CalGray"), paramsCalGray]
127
+ }, {
128
+ ref: _primitives.Ref.get(100, 0),
129
+ data: [_primitives.Name.get("CalRGB"), paramsCalRGB]
130
+ }]);
131
+ const pdfFunctionFactory = new _function.PDFFunctionFactory({
132
+ xref
133
+ });
134
+
135
+ const colorSpace1 = _colorspace.ColorSpace.parse({
136
+ cs: _primitives.Ref.get(50, 0),
137
+ xref,
138
+ resources: null,
139
+ pdfFunctionFactory,
140
+ localColorSpaceCache
141
+ });
142
+
143
+ expect(colorSpace1.name).toEqual("CalGray");
144
+
145
+ const colorSpace2 = _colorspace.ColorSpace.parse({
146
+ cs: _primitives.Ref.get(50, 0),
147
+ xref,
148
+ resources: null,
149
+ pdfFunctionFactory,
150
+ localColorSpaceCache
151
+ });
152
+
153
+ expect(colorSpace2.name).toEqual("CalGray");
154
+
155
+ const colorSpaceNonCached = _colorspace.ColorSpace.parse({
156
+ cs: _primitives.Ref.get(50, 0),
157
+ xref,
158
+ resources: null,
159
+ pdfFunctionFactory,
160
+ localColorSpaceCache: new _image_utils.LocalColorSpaceCache()
161
+ });
162
+
163
+ expect(colorSpaceNonCached.name).toEqual("CalGray");
164
+
165
+ const colorSpaceOther = _colorspace.ColorSpace.parse({
166
+ cs: _primitives.Ref.get(100, 0),
167
+ xref,
168
+ resources: null,
169
+ pdfFunctionFactory,
170
+ localColorSpaceCache
171
+ });
172
+
173
+ expect(colorSpaceOther.name).toEqual("CalRGB");
174
+ expect(colorSpace1).toBe(colorSpace2);
175
+ expect(colorSpace1).not.toBe(colorSpaceNonCached);
176
+ expect(colorSpace1).not.toBe(colorSpaceOther);
177
+ });
178
+ });
53
179
  describe("DeviceGrayCS", function () {
54
180
  it("should handle the case when cs is a Name object", function () {
55
181
  const cs = _primitives.Name.get("DeviceGray");
@@ -58,12 +184,18 @@ describe("colorspace", function () {
58
184
  ref: _primitives.Ref.get(10, 0),
59
185
  data: new _primitives.Dict()
60
186
  }]);
61
- const res = new _primitives.Dict();
187
+ const resources = new _primitives.Dict();
62
188
  const pdfFunctionFactory = new _function.PDFFunctionFactory({
63
189
  xref
64
190
  });
65
191
 
66
- const colorSpace = _colorspace.ColorSpace.parse(cs, xref, res, pdfFunctionFactory);
192
+ const colorSpace = _colorspace.ColorSpace.parse({
193
+ cs,
194
+ xref,
195
+ resources,
196
+ pdfFunctionFactory,
197
+ localColorSpaceCache: new _image_utils.LocalColorSpaceCache()
198
+ });
67
199
 
68
200
  const testSrc = new Uint8Array([27, 125, 250, 131]);
69
201
  const testDest = new Uint8ClampedArray(4 * 4 * 3);
@@ -81,12 +213,18 @@ describe("colorspace", function () {
81
213
  ref: cs,
82
214
  data: _primitives.Name.get("DeviceGray")
83
215
  }]);
84
- const res = new _primitives.Dict();
216
+ const resources = new _primitives.Dict();
85
217
  const pdfFunctionFactory = new _function.PDFFunctionFactory({
86
218
  xref
87
219
  });
88
220
 
89
- const colorSpace = _colorspace.ColorSpace.parse(cs, xref, res, pdfFunctionFactory);
221
+ const colorSpace = _colorspace.ColorSpace.parse({
222
+ cs,
223
+ xref,
224
+ resources,
225
+ pdfFunctionFactory,
226
+ localColorSpaceCache: new _image_utils.LocalColorSpaceCache()
227
+ });
90
228
 
91
229
  const testSrc = new Uint8Array([27, 125, 250, 131]);
92
230
  const testDest = new Uint8ClampedArray(3 * 3 * 3);
@@ -106,12 +244,18 @@ describe("colorspace", function () {
106
244
  ref: _primitives.Ref.get(10, 0),
107
245
  data: new _primitives.Dict()
108
246
  }]);
109
- const res = new _primitives.Dict();
247
+ const resources = new _primitives.Dict();
110
248
  const pdfFunctionFactory = new _function.PDFFunctionFactory({
111
249
  xref
112
250
  });
113
251
 
114
- const colorSpace = _colorspace.ColorSpace.parse(cs, xref, res, pdfFunctionFactory);
252
+ const colorSpace = _colorspace.ColorSpace.parse({
253
+ cs,
254
+ xref,
255
+ resources,
256
+ pdfFunctionFactory,
257
+ localColorSpaceCache: new _image_utils.LocalColorSpaceCache()
258
+ });
115
259
 
116
260
  const testSrc = new Uint8Array([27, 125, 250, 131, 139, 140, 111, 25, 198, 21, 147, 255]);
117
261
  const testDest = new Uint8ClampedArray(4 * 4 * 3);
@@ -129,12 +273,18 @@ describe("colorspace", function () {
129
273
  ref: cs,
130
274
  data: _primitives.Name.get("DeviceRGB")
131
275
  }]);
132
- const res = new _primitives.Dict();
276
+ const resources = new _primitives.Dict();
133
277
  const pdfFunctionFactory = new _function.PDFFunctionFactory({
134
278
  xref
135
279
  });
136
280
 
137
- const colorSpace = _colorspace.ColorSpace.parse(cs, xref, res, pdfFunctionFactory);
281
+ const colorSpace = _colorspace.ColorSpace.parse({
282
+ cs,
283
+ xref,
284
+ resources,
285
+ pdfFunctionFactory,
286
+ localColorSpaceCache: new _image_utils.LocalColorSpaceCache()
287
+ });
138
288
 
139
289
  const testSrc = new Uint8Array([27, 125, 250, 131, 139, 140, 111, 25, 198, 21, 147, 255]);
140
290
  const testDest = new Uint8ClampedArray(3 * 3 * 3);
@@ -154,12 +304,18 @@ describe("colorspace", function () {
154
304
  ref: _primitives.Ref.get(10, 0),
155
305
  data: new _primitives.Dict()
156
306
  }]);
157
- const res = new _primitives.Dict();
307
+ const resources = new _primitives.Dict();
158
308
  const pdfFunctionFactory = new _function.PDFFunctionFactory({
159
309
  xref
160
310
  });
161
311
 
162
- const colorSpace = _colorspace.ColorSpace.parse(cs, xref, res, pdfFunctionFactory);
312
+ const colorSpace = _colorspace.ColorSpace.parse({
313
+ cs,
314
+ xref,
315
+ resources,
316
+ pdfFunctionFactory,
317
+ localColorSpaceCache: new _image_utils.LocalColorSpaceCache()
318
+ });
163
319
 
164
320
  const testSrc = new Uint8Array([27, 125, 250, 128, 131, 139, 140, 45, 111, 25, 198, 78, 21, 147, 255, 69]);
165
321
  const testDest = new Uint8ClampedArray(4 * 4 * 3);
@@ -177,12 +333,18 @@ describe("colorspace", function () {
177
333
  ref: cs,
178
334
  data: _primitives.Name.get("DeviceCMYK")
179
335
  }]);
180
- const res = new _primitives.Dict();
336
+ const resources = new _primitives.Dict();
181
337
  const pdfFunctionFactory = new _function.PDFFunctionFactory({
182
338
  xref
183
339
  });
184
340
 
185
- const colorSpace = _colorspace.ColorSpace.parse(cs, xref, res, pdfFunctionFactory);
341
+ const colorSpace = _colorspace.ColorSpace.parse({
342
+ cs,
343
+ xref,
344
+ resources,
345
+ pdfFunctionFactory,
346
+ localColorSpaceCache: new _image_utils.LocalColorSpaceCache()
347
+ });
186
348
 
187
349
  const testSrc = new Uint8Array([27, 125, 250, 128, 131, 139, 140, 45, 111, 25, 198, 78, 21, 147, 255, 69]);
188
350
  const testDest = new Uint8ClampedArray(3 * 3 * 3);
@@ -205,12 +367,18 @@ describe("colorspace", function () {
205
367
  ref: _primitives.Ref.get(10, 0),
206
368
  data: new _primitives.Dict()
207
369
  }]);
208
- const res = new _primitives.Dict();
370
+ const resources = new _primitives.Dict();
209
371
  const pdfFunctionFactory = new _function.PDFFunctionFactory({
210
372
  xref
211
373
  });
212
374
 
213
- const colorSpace = _colorspace.ColorSpace.parse(cs, xref, res, pdfFunctionFactory);
375
+ const colorSpace = _colorspace.ColorSpace.parse({
376
+ cs,
377
+ xref,
378
+ resources,
379
+ pdfFunctionFactory,
380
+ localColorSpaceCache: new _image_utils.LocalColorSpaceCache()
381
+ });
214
382
 
215
383
  const testSrc = new Uint8Array([27, 125, 250, 131]);
216
384
  const testDest = new Uint8ClampedArray(4 * 4 * 3);
@@ -234,12 +402,18 @@ describe("colorspace", function () {
234
402
  ref: _primitives.Ref.get(10, 0),
235
403
  data: new _primitives.Dict()
236
404
  }]);
237
- const res = new _primitives.Dict();
405
+ const resources = new _primitives.Dict();
238
406
  const pdfFunctionFactory = new _function.PDFFunctionFactory({
239
407
  xref
240
408
  });
241
409
 
242
- const colorSpace = _colorspace.ColorSpace.parse(cs, xref, res, pdfFunctionFactory);
410
+ const colorSpace = _colorspace.ColorSpace.parse({
411
+ cs,
412
+ xref,
413
+ resources,
414
+ pdfFunctionFactory,
415
+ localColorSpaceCache: new _image_utils.LocalColorSpaceCache()
416
+ });
243
417
 
244
418
  const testSrc = new Uint8Array([27, 125, 250, 131, 139, 140, 111, 25, 198, 21, 147, 255]);
245
419
  const testDest = new Uint8ClampedArray(3 * 3 * 3);
@@ -262,12 +436,18 @@ describe("colorspace", function () {
262
436
  ref: _primitives.Ref.get(10, 0),
263
437
  data: new _primitives.Dict()
264
438
  }]);
265
- const res = new _primitives.Dict();
439
+ const resources = new _primitives.Dict();
266
440
  const pdfFunctionFactory = new _function.PDFFunctionFactory({
267
441
  xref
268
442
  });
269
443
 
270
- const colorSpace = _colorspace.ColorSpace.parse(cs, xref, res, pdfFunctionFactory);
444
+ const colorSpace = _colorspace.ColorSpace.parse({
445
+ cs,
446
+ xref,
447
+ resources,
448
+ pdfFunctionFactory,
449
+ localColorSpaceCache: new _image_utils.LocalColorSpaceCache()
450
+ });
271
451
 
272
452
  const testSrc = new Uint8Array([27, 25, 50, 31, 19, 40, 11, 25, 98, 21, 47, 55]);
273
453
  const testDest = new Uint8ClampedArray(3 * 3 * 3);
@@ -282,18 +462,24 @@ describe("colorspace", function () {
282
462
  });
283
463
  describe("IndexedCS", function () {
284
464
  it("should handle the case when cs is an array", function () {
285
- const lookup = new Uint8Array([23, 155, 35, 147, 69, 93, 255, 109, 70]);
465
+ const lookup = new _stream.Stream(new Uint8Array([23, 155, 35, 147, 69, 93, 255, 109, 70]));
286
466
  const cs = [_primitives.Name.get("Indexed"), _primitives.Name.get("DeviceRGB"), 2, lookup];
287
467
  const xref = new _test_utils.XRefMock([{
288
468
  ref: _primitives.Ref.get(10, 0),
289
469
  data: new _primitives.Dict()
290
470
  }]);
291
- const res = new _primitives.Dict();
471
+ const resources = new _primitives.Dict();
292
472
  const pdfFunctionFactory = new _function.PDFFunctionFactory({
293
473
  xref
294
474
  });
295
475
 
296
- const colorSpace = _colorspace.ColorSpace.parse(cs, xref, res, pdfFunctionFactory);
476
+ const colorSpace = _colorspace.ColorSpace.parse({
477
+ cs,
478
+ xref,
479
+ resources,
480
+ pdfFunctionFactory,
481
+ localColorSpaceCache: new _image_utils.LocalColorSpaceCache()
482
+ });
297
483
 
298
484
  const testSrc = new Uint8Array([2, 2, 0, 1]);
299
485
  const testDest = new Uint8ClampedArray(3 * 3 * 3);
@@ -322,12 +508,18 @@ describe("colorspace", function () {
322
508
  ref: fnRef,
323
509
  data: fn
324
510
  }]);
325
- const res = new _primitives.Dict();
511
+ const resources = new _primitives.Dict();
326
512
  const pdfFunctionFactory = new _function.PDFFunctionFactory({
327
513
  xref
328
514
  });
329
515
 
330
- const colorSpace = _colorspace.ColorSpace.parse(cs, xref, res, pdfFunctionFactory);
516
+ const colorSpace = _colorspace.ColorSpace.parse({
517
+ cs,
518
+ xref,
519
+ resources,
520
+ pdfFunctionFactory,
521
+ localColorSpaceCache: new _image_utils.LocalColorSpaceCache()
522
+ });
331
523
 
332
524
  const testSrc = new Uint8Array([27, 25, 50, 31]);
333
525
  const testDest = new Uint8ClampedArray(3 * 3 * 3);
@@ -406,7 +406,15 @@ describe("CipherTransformFactory", function () {
406
406
  done.fail("Password should be rejected.");
407
407
  }
408
408
 
409
- var fileId1, fileId2, dict1, dict2;
409
+ function ensureEncryptDecryptIsIdentity(dict, fileId, password, string) {
410
+ const factory = new _crypto.CipherTransformFactory(dict, fileId, password);
411
+ const cipher = factory.createCipherTransform(123, 0);
412
+ const encrypted = cipher.encryptString(string);
413
+ const decrypted = cipher.decryptString(encrypted);
414
+ expect(string).toEqual(decrypted);
415
+ }
416
+
417
+ var fileId1, fileId2, dict1, dict2, dict3;
410
418
  var aes256Dict, aes256IsoDict, aes256BlankDict, aes256IsoBlankDict;
411
419
  beforeAll(function (done) {
412
420
  fileId1 = unescape("%F6%C6%AF%17%F3rR%8DRM%9A%80%D1%EF%DF%18");
@@ -429,7 +437,7 @@ describe("CipherTransformFactory", function () {
429
437
  P: -1084,
430
438
  R: 4
431
439
  });
432
- aes256Dict = buildDict({
440
+ dict3 = {
433
441
  Filter: _primitives.Name.get("Standard"),
434
442
  V: 5,
435
443
  Length: 256,
@@ -440,7 +448,8 @@ describe("CipherTransformFactory", function () {
440
448
  Perms: unescape("%D8%FC%844%E5e%0DB%5D%7Ff%FD%3COMM"),
441
449
  P: -1084,
442
450
  R: 5
443
- });
451
+ };
452
+ aes256Dict = buildDict(dict3);
444
453
  aes256IsoDict = buildDict({
445
454
  Filter: _primitives.Name.get("Standard"),
446
455
  V: 5,
@@ -480,7 +489,7 @@ describe("CipherTransformFactory", function () {
480
489
  done();
481
490
  });
482
491
  afterAll(function () {
483
- fileId1 = fileId2 = dict1 = dict2 = null;
492
+ fileId1 = fileId2 = dict1 = dict2 = dict3 = null;
484
493
  aes256Dict = aes256IsoDict = aes256BlankDict = aes256IsoBlankDict = null;
485
494
  });
486
495
  describe("#ctor", function () {
@@ -534,4 +543,42 @@ describe("CipherTransformFactory", function () {
534
543
  ensurePasswordCorrect(done, dict2, fileId2);
535
544
  });
536
545
  });
546
+ describe("Encrypt and decrypt", function () {
547
+ it("should encrypt and decrypt using ARCFour", function (done) {
548
+ dict3.CF = buildDict({
549
+ Identity: buildDict({
550
+ CFM: _primitives.Name.get("V2")
551
+ })
552
+ });
553
+ const dict = buildDict(dict3);
554
+ ensureEncryptDecryptIsIdentity(dict, fileId1, "user", "hello world");
555
+ done();
556
+ });
557
+ it("should encrypt and decrypt using AES128", function (done) {
558
+ dict3.CF = buildDict({
559
+ Identity: buildDict({
560
+ CFM: _primitives.Name.get("AESV2")
561
+ })
562
+ });
563
+ const dict = buildDict(dict3);
564
+ ensureEncryptDecryptIsIdentity(dict, fileId1, "user", "a");
565
+ ensureEncryptDecryptIsIdentity(dict, fileId1, "user", "aa");
566
+ ensureEncryptDecryptIsIdentity(dict, fileId1, "user", "aaaaaaaaaaaaaaaa");
567
+ ensureEncryptDecryptIsIdentity(dict, fileId1, "user", "aaaaaaaaaaaaaaaaaaa");
568
+ done();
569
+ });
570
+ it("should encrypt and decrypt using AES256", function (done) {
571
+ dict3.CF = buildDict({
572
+ Identity: buildDict({
573
+ CFM: _primitives.Name.get("AESV3")
574
+ })
575
+ });
576
+ const dict = buildDict(dict3);
577
+ ensureEncryptDecryptIsIdentity(dict, fileId1, "user", "aaaa");
578
+ ensureEncryptDecryptIsIdentity(dict, fileId1, "user", "aaaaa");
579
+ ensureEncryptDecryptIsIdentity(dict, fileId1, "user", "aaaaaaaaaaaaaaaa");
580
+ ensureEncryptDecryptIsIdentity(dict, fileId1, "user", "aaaaaaaaaaaaaaaaaaaaaa");
581
+ done();
582
+ });
583
+ });
537
584
  });