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
@@ -23,25 +23,27 @@
|
|
23
23
|
|
24
24
|
var _primitives = require("../../core/primitives.js");
|
25
25
|
|
26
|
+
var _stream = require("../../core/stream.js");
|
27
|
+
|
26
28
|
var _test_utils = require("./test_utils.js");
|
27
29
|
|
28
30
|
describe("primitives", function () {
|
29
31
|
describe("Name", function () {
|
30
32
|
it("should retain the given name", function () {
|
31
|
-
|
33
|
+
const givenName = "Font";
|
32
34
|
|
33
|
-
|
35
|
+
const name = _primitives.Name.get(givenName);
|
34
36
|
|
35
37
|
expect(name.name).toEqual(givenName);
|
36
38
|
});
|
37
39
|
it("should create only one object for a name and cache it", function () {
|
38
|
-
|
40
|
+
const firstFont = _primitives.Name.get("Font");
|
39
41
|
|
40
|
-
|
42
|
+
const secondFont = _primitives.Name.get("Font");
|
41
43
|
|
42
|
-
|
44
|
+
const firstSubtype = _primitives.Name.get("Subtype");
|
43
45
|
|
44
|
-
|
46
|
+
const secondSubtype = _primitives.Name.get("Subtype");
|
45
47
|
|
46
48
|
expect(firstFont).toBe(secondFont);
|
47
49
|
expect(firstSubtype).toBe(secondSubtype);
|
@@ -50,20 +52,20 @@ describe("primitives", function () {
|
|
50
52
|
});
|
51
53
|
describe("Cmd", function () {
|
52
54
|
it("should retain the given cmd name", function () {
|
53
|
-
|
55
|
+
const givenCmd = "BT";
|
54
56
|
|
55
|
-
|
57
|
+
const cmd = _primitives.Cmd.get(givenCmd);
|
56
58
|
|
57
59
|
expect(cmd.cmd).toEqual(givenCmd);
|
58
60
|
});
|
59
61
|
it("should create only one object for a command and cache it", function () {
|
60
|
-
|
62
|
+
const firstBT = _primitives.Cmd.get("BT");
|
61
63
|
|
62
|
-
|
64
|
+
const secondBT = _primitives.Cmd.get("BT");
|
63
65
|
|
64
|
-
|
66
|
+
const firstET = _primitives.Cmd.get("ET");
|
65
67
|
|
66
|
-
|
68
|
+
const secondET = _primitives.Cmd.get("ET");
|
67
69
|
|
68
70
|
expect(firstBT).toBe(secondBT);
|
69
71
|
expect(firstET).toBe(secondET);
|
@@ -71,23 +73,23 @@ describe("primitives", function () {
|
|
71
73
|
});
|
72
74
|
});
|
73
75
|
describe("Dict", function () {
|
74
|
-
|
76
|
+
const checkInvalidHasValues = function (dict) {
|
75
77
|
expect(dict.has()).toBeFalsy();
|
76
78
|
expect(dict.has("Prev")).toBeFalsy();
|
77
79
|
};
|
78
80
|
|
79
|
-
|
81
|
+
const checkInvalidKeyValues = function (dict) {
|
80
82
|
expect(dict.get()).toBeUndefined();
|
81
83
|
expect(dict.get("Prev")).toBeUndefined();
|
82
84
|
expect(dict.get("Decode", "D")).toBeUndefined();
|
83
85
|
expect(dict.get("FontFile", "FontFile2", "FontFile3")).toBeUndefined();
|
84
86
|
};
|
85
87
|
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
88
|
+
let emptyDict, dictWithSizeKey, dictWithManyKeys;
|
89
|
+
const storedSize = 42;
|
90
|
+
const testFontFile = "file1";
|
91
|
+
const testFontFile2 = "file2";
|
92
|
+
const testFontFile3 = "file3";
|
91
93
|
beforeAll(function (done) {
|
92
94
|
emptyDict = new _primitives.Dict();
|
93
95
|
dictWithSizeKey = new _primitives.Dict();
|
@@ -101,6 +103,21 @@ describe("primitives", function () {
|
|
101
103
|
afterAll(function () {
|
102
104
|
emptyDict = dictWithSizeKey = dictWithManyKeys = null;
|
103
105
|
});
|
106
|
+
it("should allow assigning an XRef table after creation", function () {
|
107
|
+
const dict = new _primitives.Dict(null);
|
108
|
+
expect(dict.xref).toEqual(null);
|
109
|
+
const xref = new _test_utils.XRefMock([]);
|
110
|
+
dict.assignXref(xref);
|
111
|
+
expect(dict.xref).toEqual(xref);
|
112
|
+
});
|
113
|
+
it("should return correct size", function () {
|
114
|
+
const dict = new _primitives.Dict(null);
|
115
|
+
expect(dict.size).toEqual(0);
|
116
|
+
dict.set("Type", _primitives.Name.get("Page"));
|
117
|
+
expect(dict.size).toEqual(1);
|
118
|
+
dict.set("Contents", _primitives.Ref.get(10, 0));
|
119
|
+
expect(dict.size).toEqual(2);
|
120
|
+
});
|
104
121
|
it("should return invalid values for unknown keys", function () {
|
105
122
|
checkInvalidHasValues(emptyDict);
|
106
123
|
checkInvalidKeyValues(emptyDict);
|
@@ -132,7 +149,7 @@ describe("primitives", function () {
|
|
132
149
|
expect(dictWithManyKeys.get("FontFile", "FontFile2", "FontFile3")).toEqual(testFontFile);
|
133
150
|
});
|
134
151
|
it("should asynchronously fetch unknown keys", function (done) {
|
135
|
-
|
152
|
+
const keyPromises = [dictWithManyKeys.getAsync("Size"), dictWithSizeKey.getAsync("FontFile", "FontFile2", "FontFile3")];
|
136
153
|
Promise.all(keyPromises).then(function (values) {
|
137
154
|
expect(values[0]).toBeUndefined();
|
138
155
|
expect(values[1]).toBeUndefined();
|
@@ -142,7 +159,7 @@ describe("primitives", function () {
|
|
142
159
|
});
|
143
160
|
});
|
144
161
|
it("should asynchronously fetch correct values for multiple stored keys", function (done) {
|
145
|
-
|
162
|
+
const keyPromises = [dictWithManyKeys.getAsync("FontFile3"), dictWithManyKeys.getAsync("FontFile2", "FontFile3"), dictWithManyKeys.getAsync("FontFile", "FontFile2", "FontFile3")];
|
146
163
|
Promise.all(keyPromises).then(function (values) {
|
147
164
|
expect(values[0]).toEqual(testFontFile3);
|
148
165
|
expect(values[1]).toEqual(testFontFile2);
|
@@ -153,23 +170,23 @@ describe("primitives", function () {
|
|
153
170
|
});
|
154
171
|
});
|
155
172
|
it("should callback for each stored key", function () {
|
156
|
-
|
173
|
+
const callbackSpy = jasmine.createSpy("spy on callback in dictionary");
|
157
174
|
dictWithManyKeys.forEach(callbackSpy);
|
158
175
|
expect(callbackSpy).toHaveBeenCalled();
|
159
|
-
|
176
|
+
const callbackSpyCalls = callbackSpy.calls;
|
160
177
|
expect(callbackSpyCalls.argsFor(0)).toEqual(["FontFile", testFontFile]);
|
161
178
|
expect(callbackSpyCalls.argsFor(1)).toEqual(["FontFile2", testFontFile2]);
|
162
179
|
expect(callbackSpyCalls.argsFor(2)).toEqual(["FontFile3", testFontFile3]);
|
163
180
|
expect(callbackSpyCalls.count()).toEqual(3);
|
164
181
|
});
|
165
182
|
it("should handle keys pointing to indirect objects, both sync and async", function (done) {
|
166
|
-
|
183
|
+
const fontRef = _primitives.Ref.get(1, 0);
|
167
184
|
|
168
|
-
|
185
|
+
const xref = new _test_utils.XRefMock([{
|
169
186
|
ref: fontRef,
|
170
187
|
data: testFontFile
|
171
188
|
}]);
|
172
|
-
|
189
|
+
const fontDict = new _primitives.Dict(xref);
|
173
190
|
fontDict.set("FontFile", fontRef);
|
174
191
|
expect(fontDict.getRaw("FontFile")).toEqual(fontRef);
|
175
192
|
expect(fontDict.get("FontFile", "FontFile2", "FontFile3")).toEqual(testFontFile);
|
@@ -181,89 +198,241 @@ describe("primitives", function () {
|
|
181
198
|
});
|
182
199
|
});
|
183
200
|
it("should handle arrays containing indirect objects", function () {
|
184
|
-
|
185
|
-
|
201
|
+
const minCoordRef = _primitives.Ref.get(1, 0);
|
202
|
+
|
203
|
+
const maxCoordRef = _primitives.Ref.get(2, 0);
|
186
204
|
|
187
|
-
|
188
|
-
|
189
|
-
|
205
|
+
const minCoord = 0;
|
206
|
+
const maxCoord = 1;
|
207
|
+
const xref = new _test_utils.XRefMock([{
|
190
208
|
ref: minCoordRef,
|
191
209
|
data: minCoord
|
192
210
|
}, {
|
193
211
|
ref: maxCoordRef,
|
194
212
|
data: maxCoord
|
195
213
|
}]);
|
196
|
-
|
214
|
+
const xObjectDict = new _primitives.Dict(xref);
|
197
215
|
xObjectDict.set("BBox", [minCoord, maxCoord, minCoordRef, maxCoordRef]);
|
198
216
|
expect(xObjectDict.get("BBox")).toEqual([minCoord, maxCoord, minCoordRef, maxCoordRef]);
|
199
217
|
expect(xObjectDict.getArray("BBox")).toEqual([minCoord, maxCoord, minCoord, maxCoord]);
|
200
218
|
});
|
201
219
|
it("should get all key names", function () {
|
202
|
-
|
203
|
-
|
220
|
+
const expectedKeys = ["FontFile", "FontFile2", "FontFile3"];
|
221
|
+
const keys = dictWithManyKeys.getKeys();
|
204
222
|
expect(keys.sort()).toEqual(expectedKeys);
|
205
223
|
});
|
224
|
+
it("should get all raw values", function () {
|
225
|
+
const expectedRawValues1 = [testFontFile, testFontFile2, testFontFile3];
|
226
|
+
const rawValues1 = dictWithManyKeys.getRawValues();
|
227
|
+
expect(rawValues1.sort()).toEqual(expectedRawValues1);
|
228
|
+
|
229
|
+
const typeName = _primitives.Name.get("Page");
|
230
|
+
|
231
|
+
const resources = new _primitives.Dict(null),
|
232
|
+
resourcesRef = _primitives.Ref.get(5, 0);
|
233
|
+
|
234
|
+
const contents = new _stream.StringStream("data"),
|
235
|
+
contentsRef = _primitives.Ref.get(10, 0);
|
236
|
+
|
237
|
+
const xref = new _test_utils.XRefMock([{
|
238
|
+
ref: resourcesRef,
|
239
|
+
data: resources
|
240
|
+
}, {
|
241
|
+
ref: contentsRef,
|
242
|
+
data: contents
|
243
|
+
}]);
|
244
|
+
const dict = new _primitives.Dict(xref);
|
245
|
+
dict.set("Type", typeName);
|
246
|
+
dict.set("Resources", resourcesRef);
|
247
|
+
dict.set("Contents", contentsRef);
|
248
|
+
const expectedRawValues2 = [contentsRef, resourcesRef, typeName];
|
249
|
+
const rawValues2 = dict.getRawValues();
|
250
|
+
expect(rawValues2.sort()).toEqual(expectedRawValues2);
|
251
|
+
});
|
206
252
|
it("should create only one object for Dict.empty", function () {
|
207
|
-
|
208
|
-
|
253
|
+
const firstDictEmpty = _primitives.Dict.empty;
|
254
|
+
const secondDictEmpty = _primitives.Dict.empty;
|
209
255
|
expect(firstDictEmpty).toBe(secondDictEmpty);
|
210
256
|
expect(firstDictEmpty).not.toBe(emptyDict);
|
211
257
|
});
|
212
258
|
it("should correctly merge dictionaries", function () {
|
213
|
-
|
214
|
-
|
259
|
+
const expectedKeys = ["FontFile", "FontFile2", "FontFile3", "Size"];
|
260
|
+
const fontFileDict = new _primitives.Dict();
|
215
261
|
fontFileDict.set("FontFile", "Type1 font file");
|
216
262
|
|
217
|
-
|
263
|
+
const mergedDict = _primitives.Dict.merge({
|
264
|
+
xref: null,
|
265
|
+
dictArray: [dictWithManyKeys, dictWithSizeKey, fontFileDict]
|
266
|
+
});
|
218
267
|
|
219
|
-
|
268
|
+
const mergedKeys = mergedDict.getKeys();
|
220
269
|
expect(mergedKeys.sort()).toEqual(expectedKeys);
|
221
270
|
expect(mergedDict.get("FontFile")).toEqual(testFontFile);
|
222
271
|
});
|
272
|
+
it("should correctly merge sub-dictionaries", function () {
|
273
|
+
const localFontDict = new _primitives.Dict();
|
274
|
+
localFontDict.set("F1", "Local font one");
|
275
|
+
const globalFontDict = new _primitives.Dict();
|
276
|
+
globalFontDict.set("F1", "Global font one");
|
277
|
+
globalFontDict.set("F2", "Global font two");
|
278
|
+
globalFontDict.set("F3", "Global font three");
|
279
|
+
const localDict = new _primitives.Dict();
|
280
|
+
localDict.set("Font", localFontDict);
|
281
|
+
const globalDict = new _primitives.Dict();
|
282
|
+
globalDict.set("Font", globalFontDict);
|
283
|
+
|
284
|
+
const mergedDict = _primitives.Dict.merge({
|
285
|
+
xref: null,
|
286
|
+
dictArray: [localDict, globalDict]
|
287
|
+
});
|
288
|
+
|
289
|
+
const mergedSubDict = _primitives.Dict.merge({
|
290
|
+
xref: null,
|
291
|
+
dictArray: [localDict, globalDict],
|
292
|
+
mergeSubDicts: true
|
293
|
+
});
|
294
|
+
|
295
|
+
const mergedFontDict = mergedDict.get("Font");
|
296
|
+
const mergedSubFontDict = mergedSubDict.get("Font");
|
297
|
+
expect(mergedFontDict instanceof _primitives.Dict).toEqual(true);
|
298
|
+
expect(mergedSubFontDict instanceof _primitives.Dict).toEqual(true);
|
299
|
+
const mergedFontDictKeys = mergedFontDict.getKeys();
|
300
|
+
const mergedSubFontDictKeys = mergedSubFontDict.getKeys();
|
301
|
+
expect(mergedFontDictKeys).toEqual(["F1"]);
|
302
|
+
expect(mergedSubFontDictKeys).toEqual(["F1", "F2", "F3"]);
|
303
|
+
const mergedFontDictValues = mergedFontDict.getRawValues();
|
304
|
+
const mergedSubFontDictValues = mergedSubFontDict.getRawValues();
|
305
|
+
expect(mergedFontDictValues).toEqual(["Local font one"]);
|
306
|
+
expect(mergedSubFontDictValues).toEqual(["Local font one", "Global font two", "Global font three"]);
|
307
|
+
});
|
223
308
|
});
|
224
309
|
describe("Ref", function () {
|
310
|
+
it("should get a string representation", function () {
|
311
|
+
const nonZeroRef = _primitives.Ref.get(4, 2);
|
312
|
+
|
313
|
+
expect(nonZeroRef.toString()).toEqual("4R2");
|
314
|
+
|
315
|
+
const zeroRef = _primitives.Ref.get(4, 0);
|
316
|
+
|
317
|
+
expect(zeroRef.toString()).toEqual("4R");
|
318
|
+
});
|
225
319
|
it("should retain the stored values", function () {
|
226
|
-
|
227
|
-
|
320
|
+
const storedNum = 4;
|
321
|
+
const storedGen = 2;
|
228
322
|
|
229
|
-
|
323
|
+
const ref = _primitives.Ref.get(storedNum, storedGen);
|
230
324
|
|
231
325
|
expect(ref.num).toEqual(storedNum);
|
232
326
|
expect(ref.gen).toEqual(storedGen);
|
233
327
|
});
|
328
|
+
it("should create only one object for a reference and cache it", function () {
|
329
|
+
const firstRef = _primitives.Ref.get(4, 2);
|
330
|
+
|
331
|
+
const secondRef = _primitives.Ref.get(4, 2);
|
332
|
+
|
333
|
+
const firstOtherRef = _primitives.Ref.get(5, 2);
|
334
|
+
|
335
|
+
const secondOtherRef = _primitives.Ref.get(5, 2);
|
336
|
+
|
337
|
+
expect(firstRef).toBe(secondRef);
|
338
|
+
expect(firstOtherRef).toBe(secondOtherRef);
|
339
|
+
expect(firstRef).not.toBe(firstOtherRef);
|
340
|
+
});
|
234
341
|
});
|
235
342
|
describe("RefSet", function () {
|
236
343
|
it("should have a stored value", function () {
|
237
|
-
|
344
|
+
const ref = _primitives.Ref.get(4, 2);
|
238
345
|
|
239
|
-
|
346
|
+
const refset = new _primitives.RefSet();
|
240
347
|
refset.put(ref);
|
241
348
|
expect(refset.has(ref)).toBeTruthy();
|
242
349
|
});
|
243
350
|
it("should not have an unknown value", function () {
|
244
|
-
|
351
|
+
const ref = _primitives.Ref.get(4, 2);
|
245
352
|
|
246
|
-
|
353
|
+
const refset = new _primitives.RefSet();
|
247
354
|
expect(refset.has(ref)).toBeFalsy();
|
248
355
|
refset.put(ref);
|
249
356
|
|
250
|
-
|
357
|
+
const anotherRef = _primitives.Ref.get(2, 4);
|
251
358
|
|
252
359
|
expect(refset.has(anotherRef)).toBeFalsy();
|
253
360
|
});
|
254
361
|
});
|
362
|
+
describe("RefSetCache", function () {
|
363
|
+
const ref1 = _primitives.Ref.get(4, 2);
|
364
|
+
|
365
|
+
const ref2 = _primitives.Ref.get(5, 2);
|
366
|
+
|
367
|
+
const obj1 = _primitives.Name.get("foo");
|
368
|
+
|
369
|
+
const obj2 = _primitives.Name.get("bar");
|
370
|
+
|
371
|
+
let cache;
|
372
|
+
beforeEach(function (done) {
|
373
|
+
cache = new _primitives.RefSetCache();
|
374
|
+
done();
|
375
|
+
});
|
376
|
+
afterEach(function () {
|
377
|
+
cache = null;
|
378
|
+
});
|
379
|
+
it("should put, have and get a value", function () {
|
380
|
+
cache.put(ref1, obj1);
|
381
|
+
expect(cache.has(ref1)).toBeTruthy();
|
382
|
+
expect(cache.has(ref2)).toBeFalsy();
|
383
|
+
expect(cache.get(ref1)).toBe(obj1);
|
384
|
+
});
|
385
|
+
it("should put, have and get a value by alias", function () {
|
386
|
+
cache.put(ref1, obj1);
|
387
|
+
cache.putAlias(ref2, ref1);
|
388
|
+
expect(cache.has(ref1)).toBeTruthy();
|
389
|
+
expect(cache.has(ref2)).toBeTruthy();
|
390
|
+
expect(cache.get(ref1)).toBe(obj1);
|
391
|
+
expect(cache.get(ref2)).toBe(obj1);
|
392
|
+
});
|
393
|
+
it("should report the size of the cache", function () {
|
394
|
+
cache.put(ref1, obj1);
|
395
|
+
expect(cache.size).toEqual(1);
|
396
|
+
cache.put(ref2, obj2);
|
397
|
+
expect(cache.size).toEqual(2);
|
398
|
+
});
|
399
|
+
it("should clear the cache", function () {
|
400
|
+
cache.put(ref1, obj1);
|
401
|
+
expect(cache.size).toEqual(1);
|
402
|
+
cache.clear();
|
403
|
+
expect(cache.size).toEqual(0);
|
404
|
+
});
|
405
|
+
it("should support iteration", function () {
|
406
|
+
cache.put(ref1, obj1);
|
407
|
+
cache.put(ref2, obj2);
|
408
|
+
const values = [];
|
409
|
+
cache.forEach(function (value) {
|
410
|
+
values.push(value);
|
411
|
+
});
|
412
|
+
expect(values).toEqual([obj1, obj2]);
|
413
|
+
});
|
414
|
+
});
|
415
|
+
describe("isEOF", function () {
|
416
|
+
it("handles non-EOF", function () {
|
417
|
+
const nonEOF = "foo";
|
418
|
+
expect((0, _primitives.isEOF)(nonEOF)).toEqual(false);
|
419
|
+
});
|
420
|
+
it("handles EOF", function () {
|
421
|
+
expect((0, _primitives.isEOF)(_primitives.EOF)).toEqual(true);
|
422
|
+
});
|
423
|
+
});
|
255
424
|
describe("isName", function () {
|
256
425
|
it("handles non-names", function () {
|
257
|
-
|
426
|
+
const nonName = {};
|
258
427
|
expect((0, _primitives.isName)(nonName)).toEqual(false);
|
259
428
|
});
|
260
429
|
it("handles names", function () {
|
261
|
-
|
430
|
+
const name = _primitives.Name.get("Font");
|
262
431
|
|
263
432
|
expect((0, _primitives.isName)(name)).toEqual(true);
|
264
433
|
});
|
265
434
|
it("handles names with name check", function () {
|
266
|
-
|
435
|
+
const name = _primitives.Name.get("Font");
|
267
436
|
|
268
437
|
expect((0, _primitives.isName)(name, "Font")).toEqual(true);
|
269
438
|
expect((0, _primitives.isName)(name, "Subtype")).toEqual(false);
|
@@ -271,16 +440,16 @@ describe("primitives", function () {
|
|
271
440
|
});
|
272
441
|
describe("isCmd", function () {
|
273
442
|
it("handles non-commands", function () {
|
274
|
-
|
443
|
+
const nonCmd = {};
|
275
444
|
expect((0, _primitives.isCmd)(nonCmd)).toEqual(false);
|
276
445
|
});
|
277
446
|
it("handles commands", function () {
|
278
|
-
|
447
|
+
const cmd = _primitives.Cmd.get("BT");
|
279
448
|
|
280
449
|
expect((0, _primitives.isCmd)(cmd)).toEqual(true);
|
281
450
|
});
|
282
451
|
it("handles commands with cmd check", function () {
|
283
|
-
|
452
|
+
const cmd = _primitives.Cmd.get("BT");
|
284
453
|
|
285
454
|
expect((0, _primitives.isCmd)(cmd, "BT")).toEqual(true);
|
286
455
|
expect((0, _primitives.isCmd)(cmd, "ET")).toEqual(false);
|
@@ -288,16 +457,16 @@ describe("primitives", function () {
|
|
288
457
|
});
|
289
458
|
describe("isDict", function () {
|
290
459
|
it("handles non-dictionaries", function () {
|
291
|
-
|
460
|
+
const nonDict = {};
|
292
461
|
expect((0, _primitives.isDict)(nonDict)).toEqual(false);
|
293
462
|
});
|
294
463
|
it("handles empty dictionaries with type check", function () {
|
295
|
-
|
464
|
+
const dict = _primitives.Dict.empty;
|
296
465
|
expect((0, _primitives.isDict)(dict)).toEqual(true);
|
297
466
|
expect((0, _primitives.isDict)(dict, "Page")).toEqual(false);
|
298
467
|
});
|
299
468
|
it("handles dictionaries with type check", function () {
|
300
|
-
|
469
|
+
const dict = new _primitives.Dict();
|
301
470
|
dict.set("Type", _primitives.Name.get("Page"));
|
302
471
|
expect((0, _primitives.isDict)(dict, "Page")).toEqual(true);
|
303
472
|
expect((0, _primitives.isDict)(dict, "Contents")).toEqual(false);
|
@@ -305,29 +474,39 @@ describe("primitives", function () {
|
|
305
474
|
});
|
306
475
|
describe("isRef", function () {
|
307
476
|
it("handles non-refs", function () {
|
308
|
-
|
477
|
+
const nonRef = {};
|
309
478
|
expect((0, _primitives.isRef)(nonRef)).toEqual(false);
|
310
479
|
});
|
311
480
|
it("handles refs", function () {
|
312
|
-
|
481
|
+
const ref = _primitives.Ref.get(1, 0);
|
313
482
|
|
314
483
|
expect((0, _primitives.isRef)(ref)).toEqual(true);
|
315
484
|
});
|
316
485
|
});
|
317
486
|
describe("isRefsEqual", function () {
|
318
487
|
it("should handle Refs pointing to the same object", function () {
|
319
|
-
|
488
|
+
const ref1 = _primitives.Ref.get(1, 0);
|
320
489
|
|
321
|
-
|
490
|
+
const ref2 = _primitives.Ref.get(1, 0);
|
322
491
|
|
323
492
|
expect((0, _primitives.isRefsEqual)(ref1, ref2)).toEqual(true);
|
324
493
|
});
|
325
494
|
it("should handle Refs pointing to different objects", function () {
|
326
|
-
|
495
|
+
const ref1 = _primitives.Ref.get(1, 0);
|
327
496
|
|
328
|
-
|
497
|
+
const ref2 = _primitives.Ref.get(2, 0);
|
329
498
|
|
330
499
|
expect((0, _primitives.isRefsEqual)(ref1, ref2)).toEqual(false);
|
331
500
|
});
|
332
501
|
});
|
502
|
+
describe("isStream", function () {
|
503
|
+
it("handles non-streams", function () {
|
504
|
+
const nonStream = {};
|
505
|
+
expect((0, _primitives.isStream)(nonStream)).toEqual(false);
|
506
|
+
});
|
507
|
+
it("handles streams", function () {
|
508
|
+
const stream = new _stream.StringStream("foo");
|
509
|
+
expect((0, _primitives.isStream)(stream)).toEqual(true);
|
510
|
+
});
|
511
|
+
});
|
333
512
|
});
|
@@ -26,15 +26,18 @@ Object.defineProperty(exports, "__esModule", {
|
|
26
26
|
});
|
27
27
|
exports.buildGetDocumentParams = buildGetDocumentParams;
|
28
28
|
exports.createIdFactory = createIdFactory;
|
29
|
-
exports.
|
29
|
+
exports.isEmptyObj = isEmptyObj;
|
30
|
+
exports.TEST_PDFS_PATH = exports.XRefMock = exports.NodeFileReaderFactory = exports.DOMFileReaderFactory = void 0;
|
31
|
+
|
32
|
+
var _primitives = require("../../core/primitives.js");
|
33
|
+
|
34
|
+
var _document = require("../../core/document.js");
|
30
35
|
|
31
36
|
var _util = require("../../shared/util.js");
|
32
37
|
|
33
38
|
var _is_node = require("../../shared/is_node.js");
|
34
39
|
|
35
|
-
var
|
36
|
-
|
37
|
-
var _document = require("../../core/document.js");
|
40
|
+
var _stream = require("../../core/stream.js");
|
38
41
|
|
39
42
|
class DOMFileReaderFactory {
|
40
43
|
static async fetch(params) {
|
@@ -92,86 +95,14 @@ function buildGetDocumentParams(filename, options) {
|
|
92
95
|
return params;
|
93
96
|
}
|
94
97
|
|
95
|
-
class NodeCanvasFactory {
|
96
|
-
create(width, height) {
|
97
|
-
(0, _util.assert)(width > 0 && height > 0, "Invalid canvas size");
|
98
|
-
|
99
|
-
const Canvas = require("canvas");
|
100
|
-
|
101
|
-
const canvas = Canvas.createCanvas(width, height);
|
102
|
-
return {
|
103
|
-
canvas,
|
104
|
-
context: canvas.getContext("2d")
|
105
|
-
};
|
106
|
-
}
|
107
|
-
|
108
|
-
reset(canvasAndContext, width, height) {
|
109
|
-
(0, _util.assert)(canvasAndContext.canvas, "Canvas is not specified");
|
110
|
-
(0, _util.assert)(width > 0 && height > 0, "Invalid canvas size");
|
111
|
-
canvasAndContext.canvas.width = width;
|
112
|
-
canvasAndContext.canvas.height = height;
|
113
|
-
}
|
114
|
-
|
115
|
-
destroy(canvasAndContext) {
|
116
|
-
(0, _util.assert)(canvasAndContext.canvas, "Canvas is not specified");
|
117
|
-
canvasAndContext.canvas.width = 0;
|
118
|
-
canvasAndContext.canvas.height = 0;
|
119
|
-
canvasAndContext.canvas = null;
|
120
|
-
canvasAndContext.context = null;
|
121
|
-
}
|
122
|
-
|
123
|
-
}
|
124
|
-
|
125
|
-
exports.NodeCanvasFactory = NodeCanvasFactory;
|
126
|
-
|
127
|
-
class NodeCMapReaderFactory {
|
128
|
-
constructor({
|
129
|
-
baseUrl = null,
|
130
|
-
isCompressed = false
|
131
|
-
}) {
|
132
|
-
this.baseUrl = baseUrl;
|
133
|
-
this.isCompressed = isCompressed;
|
134
|
-
}
|
135
|
-
|
136
|
-
async fetch({
|
137
|
-
name
|
138
|
-
}) {
|
139
|
-
if (!this.baseUrl) {
|
140
|
-
throw new Error('The CMap "baseUrl" parameter must be specified, ensure that ' + 'the "cMapUrl" and "cMapPacked" API parameters are provided.');
|
141
|
-
}
|
142
|
-
|
143
|
-
if (!name) {
|
144
|
-
throw new Error("CMap name must be specified.");
|
145
|
-
}
|
146
|
-
|
147
|
-
const url = this.baseUrl + name + (this.isCompressed ? ".bcmap" : "");
|
148
|
-
const compressionType = this.isCompressed ? _util.CMapCompressionType.BINARY : _util.CMapCompressionType.NONE;
|
149
|
-
return new Promise((resolve, reject) => {
|
150
|
-
const fs = require("fs");
|
151
|
-
|
152
|
-
fs.readFile(url, (error, data) => {
|
153
|
-
if (error || !data) {
|
154
|
-
reject(new Error(error));
|
155
|
-
return;
|
156
|
-
}
|
157
|
-
|
158
|
-
resolve({
|
159
|
-
cMapData: new Uint8Array(data),
|
160
|
-
compressionType
|
161
|
-
});
|
162
|
-
});
|
163
|
-
}).catch(reason => {
|
164
|
-
throw new Error(`Unable to load ${this.isCompressed ? "binary " : ""}` + `CMap at: ${url}`);
|
165
|
-
});
|
166
|
-
}
|
167
|
-
|
168
|
-
}
|
169
|
-
|
170
|
-
exports.NodeCMapReaderFactory = NodeCMapReaderFactory;
|
171
|
-
|
172
98
|
class XRefMock {
|
173
99
|
constructor(array) {
|
174
100
|
this._map = Object.create(null);
|
101
|
+
this.stats = {
|
102
|
+
streamTypes: Object.create(null),
|
103
|
+
fontTypes: Object.create(null)
|
104
|
+
};
|
105
|
+
this._newRefNum = null;
|
175
106
|
|
176
107
|
for (const key in array) {
|
177
108
|
const obj = array[key];
|
@@ -179,6 +110,18 @@ class XRefMock {
|
|
179
110
|
}
|
180
111
|
}
|
181
112
|
|
113
|
+
getNewRef() {
|
114
|
+
if (this._newRefNum === null) {
|
115
|
+
this._newRefNum = Object.keys(this._map).length;
|
116
|
+
}
|
117
|
+
|
118
|
+
return _primitives.Ref.get(this._newRefNum++, 0);
|
119
|
+
}
|
120
|
+
|
121
|
+
resetNewRef() {
|
122
|
+
this.newRef = null;
|
123
|
+
}
|
124
|
+
|
182
125
|
fetch(ref) {
|
183
126
|
return this._map[ref.toString()];
|
184
127
|
}
|
@@ -204,14 +147,24 @@ class XRefMock {
|
|
204
147
|
exports.XRefMock = XRefMock;
|
205
148
|
|
206
149
|
function createIdFactory(pageIndex) {
|
207
|
-
const
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
}
|
150
|
+
const pdfManager = {
|
151
|
+
get docId() {
|
152
|
+
return "d0";
|
153
|
+
}
|
212
154
|
|
213
|
-
|
214
|
-
|
155
|
+
};
|
156
|
+
const stream = new _stream.StringStream("Dummy_PDF_data");
|
157
|
+
const pdfDocument = new _document.PDFDocument(pdfManager, stream);
|
158
|
+
const page = new _document.Page({
|
159
|
+
pdfManager: pdfDocument.pdfManager,
|
160
|
+
xref: pdfDocument.xref,
|
161
|
+
pageIndex,
|
162
|
+
globalIdFactory: pdfDocument._globalIdFactory
|
215
163
|
});
|
216
|
-
return page.
|
164
|
+
return page._localIdFactory;
|
165
|
+
}
|
166
|
+
|
167
|
+
function isEmptyObj(obj) {
|
168
|
+
(0, _util.assert)(typeof obj === "object" && obj !== null, "isEmptyObj - invalid argument.");
|
169
|
+
return Object.keys(obj).length === 0;
|
217
170
|
}
|