pdfjs-dist 2.2.228 → 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/README.md +4 -0
- package/bower.json +1 -1
- package/build/pdf.js +8816 -19300
- package/build/pdf.js.map +1 -1
- package/build/pdf.min.js +22 -1
- package/build/pdf.worker.entry.js +5 -3
- package/build/pdf.worker.js +27185 -35746
- package/build/pdf.worker.js.map +1 -1
- package/build/pdf.worker.min.js +22 -1
- package/es5/build/pdf.js +26665 -0
- package/es5/build/pdf.js.map +1 -0
- package/es5/build/pdf.min.js +22 -0
- package/{lib/shared/global_scope.js → es5/build/pdf.worker.entry.js} +5 -10
- package/es5/build/pdf.worker.js +61231 -0
- package/es5/build/pdf.worker.js.map +1 -0
- 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/annotation-check.svg +11 -0
- package/es5/web/images/annotation-comment.svg +16 -0
- package/es5/web/images/annotation-help.svg +26 -0
- package/es5/web/images/annotation-insert.svg +10 -0
- package/es5/web/images/annotation-key.svg +11 -0
- package/es5/web/images/annotation-newparagraph.svg +11 -0
- package/es5/web/images/annotation-noicon.svg +7 -0
- package/es5/web/images/annotation-note.svg +42 -0
- package/es5/web/images/annotation-paragraph.svg +16 -0
- package/es5/web/images/loading-icon.gif +0 -0
- package/es5/web/images/shadow.png +0 -0
- package/es5/web/pdf_viewer.css +406 -0
- package/es5/web/pdf_viewer.js +7886 -0
- package/es5/web/pdf_viewer.js.map +1 -0
- package/image_decoders/pdf.image_decoders.js +1498 -4832
- package/image_decoders/pdf.image_decoders.js.map +1 -1
- package/image_decoders/pdf.image_decoders.min.js +22 -1
- package/lib/README.md +7 -0
- package/lib/core/annotation.js +1144 -927
- package/lib/core/arithmetic_decoder.js +81 -97
- package/lib/core/bidi.js +54 -46
- package/lib/core/ccitt.js +88 -81
- package/lib/core/ccitt_stream.js +15 -14
- package/lib/core/cff_parser.js +747 -716
- package/lib/core/charsets.js +4 -4
- package/lib/core/chunked_stream.js +462 -553
- package/lib/core/cmap.js +231 -277
- package/lib/core/colorspace.js +715 -857
- package/lib/core/core_utils.js +57 -52
- package/lib/core/crypto.js +416 -437
- package/lib/core/document.js +629 -670
- package/lib/core/encodings.js +15 -15
- package/lib/core/evaluator.js +3229 -2800
- package/lib/core/font_renderer.js +135 -178
- package/lib/core/fonts.js +602 -534
- package/lib/core/function.js +355 -279
- package/lib/core/glyphlist.js +4527 -4526
- package/lib/core/image.js +442 -439
- package/lib/core/image_utils.js +221 -61
- package/lib/core/jbig2.js +325 -316
- package/lib/core/jbig2_stream.js +18 -17
- package/lib/core/jpeg_stream.js +21 -26
- package/lib/core/jpg.js +289 -233
- package/lib/core/jpx.js +161 -143
- package/lib/core/jpx_stream.js +28 -28
- package/lib/core/metrics.js +2928 -2928
- package/lib/core/murmurhash3.js +87 -102
- package/lib/core/obj.js +1343 -1300
- package/lib/core/operator_list.js +90 -67
- package/lib/core/parser.js +990 -987
- package/lib/core/pattern.js +105 -77
- package/lib/core/pdf_manager.js +149 -316
- package/lib/core/primitives.js +156 -104
- package/lib/core/ps_parser.js +175 -214
- package/lib/core/standard_fonts.js +237 -236
- package/lib/core/stream.js +94 -74
- package/lib/core/type1_parser.js +89 -69
- package/lib/core/unicode.js +1654 -1654
- package/lib/core/worker.js +275 -290
- package/lib/core/worker_stream.js +101 -210
- package/lib/core/writer.js +242 -0
- package/lib/display/annotation_layer.js +772 -1041
- package/lib/display/annotation_storage.js +89 -0
- package/lib/display/api.js +1575 -1868
- package/lib/display/api_compatibility.js +12 -17
- package/lib/display/canvas.js +370 -222
- package/lib/display/content_disposition.js +40 -59
- package/lib/display/display_utils.js +341 -536
- package/lib/display/fetch_stream.js +188 -304
- package/lib/display/font_loader.js +282 -414
- package/lib/display/metadata.js +81 -99
- package/lib/display/network.js +362 -511
- package/lib/display/network_utils.js +25 -18
- package/lib/display/node_stream.js +283 -465
- package/lib/display/node_utils.js +87 -0
- package/lib/display/optional_content_config.js +184 -0
- package/lib/display/pattern_helper.js +93 -44
- package/lib/display/svg.js +1163 -1401
- package/lib/display/text_layer.js +154 -137
- package/lib/display/transport_stream.js +237 -375
- package/lib/display/webgl.js +70 -83
- package/lib/display/worker_options.js +3 -3
- package/lib/display/xml_parser.js +303 -392
- package/lib/examples/node/domstubs.js +37 -37
- package/lib/pdf.js +220 -58
- package/lib/pdf.worker.js +14 -6
- package/lib/shared/compatibility.js +3 -246
- package/lib/shared/is_node.js +7 -6
- package/lib/shared/message_handler.js +327 -332
- package/lib/shared/util.js +271 -306
- package/lib/test/unit/annotation_spec.js +1902 -763
- package/lib/test/unit/annotation_storage_spec.js +83 -0
- package/lib/test/unit/api_spec.js +790 -592
- package/lib/test/unit/bidi_spec.js +7 -7
- package/lib/test/unit/cff_parser_spec.js +73 -72
- package/lib/test/unit/clitests_helper.js +7 -9
- package/lib/test/unit/cmap_spec.js +86 -88
- package/lib/test/unit/colorspace_spec.js +346 -154
- package/lib/test/unit/core_utils_spec.js +125 -105
- package/lib/test/unit/crypto_spec.js +232 -185
- package/lib/test/unit/custom_spec.js +150 -24
- package/lib/test/unit/display_svg_spec.js +34 -39
- package/lib/test/unit/display_utils_spec.js +139 -149
- package/lib/test/unit/document_spec.js +128 -17
- package/lib/test/unit/encodings_spec.js +12 -34
- package/lib/test/unit/evaluator_spec.js +112 -91
- package/lib/test/unit/fetch_stream_spec.js +31 -29
- package/lib/test/unit/function_spec.js +206 -204
- package/lib/test/unit/jasmine-boot.js +48 -32
- package/lib/test/unit/message_handler_spec.js +173 -159
- package/lib/test/unit/metadata_spec.js +71 -71
- package/lib/test/unit/murmurhash3_spec.js +12 -12
- package/lib/test/unit/network_spec.js +13 -11
- package/lib/test/unit/network_utils_spec.js +158 -144
- package/lib/test/unit/node_stream_spec.js +76 -90
- package/lib/test/unit/parser_spec.js +108 -114
- package/lib/test/unit/pdf_find_controller_spec.js +55 -86
- package/lib/test/unit/pdf_find_utils_spec.js +32 -32
- package/lib/test/unit/pdf_history_spec.js +32 -32
- package/lib/test/unit/primitives_spec.js +337 -156
- package/lib/test/unit/stream_spec.js +16 -14
- package/lib/test/unit/test_utils.js +91 -304
- package/lib/test/unit/testreporter.js +33 -22
- package/lib/test/unit/type1_parser_spec.js +42 -42
- package/lib/test/unit/ui_utils_spec.js +299 -461
- package/lib/test/unit/unicode_spec.js +42 -42
- package/lib/test/unit/util_spec.js +129 -149
- package/lib/test/unit/writer_spec.js +84 -0
- package/lib/web/annotation_layer_builder.js +78 -111
- package/lib/web/app.js +1542 -1267
- package/lib/web/app_options.js +76 -91
- package/lib/web/base_tree_viewer.js +100 -0
- package/lib/web/base_viewer.js +869 -834
- package/lib/web/chromecom.js +165 -252
- package/lib/web/debugger.js +149 -205
- package/lib/web/download_manager.js +34 -58
- package/lib/web/firefox_print_service.js +62 -34
- package/lib/web/firefoxcom.js +206 -374
- package/lib/web/genericcom.js +26 -108
- package/lib/web/genericl10n.js +24 -153
- package/lib/web/grab_to_pan.js +30 -30
- package/lib/web/interfaces.js +80 -254
- package/lib/web/overlay_manager.js +70 -246
- package/lib/web/password_prompt.js +38 -64
- package/lib/web/pdf_attachment_viewer.js +150 -126
- package/lib/web/pdf_cursor_tools.js +75 -102
- package/lib/web/pdf_document_properties.js +229 -383
- package/lib/web/pdf_find_bar.js +136 -170
- package/lib/web/pdf_find_controller.js +492 -548
- package/lib/web/pdf_find_utils.js +13 -13
- package/lib/web/pdf_history.js +397 -406
- package/lib/web/pdf_layer_viewer.js +208 -0
- package/lib/web/pdf_link_service.js +304 -348
- package/lib/web/pdf_outline_viewer.js +119 -212
- package/lib/web/pdf_page_view.js +474 -513
- package/lib/web/pdf_presentation_mode.js +308 -357
- package/lib/web/pdf_print_service.js +96 -110
- package/lib/web/pdf_rendering_queue.js +87 -108
- package/lib/web/pdf_sidebar.js +286 -302
- package/lib/web/pdf_sidebar_resizer.js +92 -119
- package/lib/web/pdf_single_page_viewer.js +77 -126
- package/lib/web/pdf_thumbnail_view.js +289 -297
- package/lib/web/pdf_thumbnail_viewer.js +202 -206
- package/lib/web/pdf_viewer.component.js +20 -21
- package/lib/web/pdf_viewer.js +55 -115
- package/lib/web/preferences.js +69 -273
- package/lib/web/secondary_toolbar.js +164 -196
- package/lib/web/text_layer_builder.js +284 -319
- package/lib/web/toolbar.js +217 -210
- package/lib/web/ui_utils.js +274 -421
- package/lib/web/view_history.js +52 -226
- package/lib/web/viewer_compatibility.js +21 -6
- package/package.json +4 -9
- 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 +29 -27
- package/web/pdf_viewer.js +3524 -4746
- package/web/pdf_viewer.js.map +1 -1
- package/webpack.js +6 -5
- package/external/streams/streams-lib.js +0 -3962
- package/external/url/url-lib.js +0 -627
- package/lib/shared/streams_polyfill.js +0 -43
- package/lib/shared/url_polyfill.js +0 -56
- package/web/images/texture.png +0 -0
@@ -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 2020 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.
|
@@ -21,311 +21,492 @@
|
|
21
21
|
*/
|
22
22
|
"use strict";
|
23
23
|
|
24
|
-
var _primitives = require("../../core/primitives");
|
24
|
+
var _primitives = require("../../core/primitives.js");
|
25
25
|
|
26
|
-
var
|
26
|
+
var _stream = require("../../core/stream.js");
|
27
27
|
|
28
|
-
|
29
|
-
describe('Name', function () {
|
30
|
-
it('should retain the given name', function () {
|
31
|
-
var givenName = 'Font';
|
28
|
+
var _test_utils = require("./test_utils.js");
|
32
29
|
|
33
|
-
|
30
|
+
describe("primitives", function () {
|
31
|
+
describe("Name", function () {
|
32
|
+
it("should retain the given name", function () {
|
33
|
+
const givenName = "Font";
|
34
|
+
|
35
|
+
const name = _primitives.Name.get(givenName);
|
34
36
|
|
35
37
|
expect(name.name).toEqual(givenName);
|
36
38
|
});
|
37
|
-
it(
|
38
|
-
|
39
|
+
it("should create only one object for a name and cache it", function () {
|
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);
|
48
50
|
expect(firstFont).not.toBe(firstSubtype);
|
49
51
|
});
|
50
52
|
});
|
51
|
-
describe(
|
52
|
-
it(
|
53
|
-
|
53
|
+
describe("Cmd", function () {
|
54
|
+
it("should retain the given cmd name", function () {
|
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
|
-
it(
|
60
|
-
|
61
|
+
it("should create only one object for a command and cache it", function () {
|
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);
|
70
72
|
expect(firstBT).not.toBe(firstET);
|
71
73
|
});
|
72
74
|
});
|
73
|
-
describe(
|
74
|
-
|
75
|
+
describe("Dict", function () {
|
76
|
+
const checkInvalidHasValues = function (dict) {
|
75
77
|
expect(dict.has()).toBeFalsy();
|
76
|
-
expect(dict.has(
|
78
|
+
expect(dict.has("Prev")).toBeFalsy();
|
77
79
|
};
|
78
80
|
|
79
|
-
|
81
|
+
const checkInvalidKeyValues = function (dict) {
|
80
82
|
expect(dict.get()).toBeUndefined();
|
81
|
-
expect(dict.get(
|
82
|
-
expect(dict.get(
|
83
|
-
expect(dict.get(
|
83
|
+
expect(dict.get("Prev")).toBeUndefined();
|
84
|
+
expect(dict.get("Decode", "D")).toBeUndefined();
|
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();
|
94
|
-
dictWithSizeKey.set(
|
96
|
+
dictWithSizeKey.set("Size", storedSize);
|
95
97
|
dictWithManyKeys = new _primitives.Dict();
|
96
|
-
dictWithManyKeys.set(
|
97
|
-
dictWithManyKeys.set(
|
98
|
-
dictWithManyKeys.set(
|
98
|
+
dictWithManyKeys.set("FontFile", testFontFile);
|
99
|
+
dictWithManyKeys.set("FontFile2", testFontFile2);
|
100
|
+
dictWithManyKeys.set("FontFile3", testFontFile3);
|
99
101
|
done();
|
100
102
|
});
|
101
103
|
afterAll(function () {
|
102
104
|
emptyDict = dictWithSizeKey = dictWithManyKeys = null;
|
103
105
|
});
|
104
|
-
it(
|
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
|
+
});
|
121
|
+
it("should return invalid values for unknown keys", function () {
|
105
122
|
checkInvalidHasValues(emptyDict);
|
106
123
|
checkInvalidKeyValues(emptyDict);
|
107
124
|
});
|
108
|
-
it(
|
109
|
-
expect(dictWithSizeKey.has(
|
110
|
-
expect(dictWithSizeKey.get(
|
111
|
-
expect(dictWithSizeKey.get(
|
112
|
-
expect(dictWithSizeKey.get(
|
125
|
+
it("should return correct value for stored Size key", function () {
|
126
|
+
expect(dictWithSizeKey.has("Size")).toBeTruthy();
|
127
|
+
expect(dictWithSizeKey.get("Size")).toEqual(storedSize);
|
128
|
+
expect(dictWithSizeKey.get("Prev", "Size")).toEqual(storedSize);
|
129
|
+
expect(dictWithSizeKey.get("Prev", "Root", "Size")).toEqual(storedSize);
|
113
130
|
});
|
114
|
-
it(
|
131
|
+
it("should return invalid values for unknown keys when Size key is stored", function () {
|
115
132
|
checkInvalidHasValues(dictWithSizeKey);
|
116
133
|
checkInvalidKeyValues(dictWithSizeKey);
|
117
134
|
});
|
118
|
-
it(
|
119
|
-
|
120
|
-
|
121
|
-
|
135
|
+
it("should not accept to set a key with an undefined value", function () {
|
136
|
+
const dict = new _primitives.Dict();
|
137
|
+
expect(function () {
|
138
|
+
dict.set("Size");
|
139
|
+
}).toThrow(new Error('Dict.set: The "value" cannot be undefined.'));
|
140
|
+
expect(dict.has("Size")).toBeFalsy();
|
122
141
|
checkInvalidKeyValues(dict);
|
123
142
|
});
|
124
|
-
it(
|
125
|
-
expect(dictWithManyKeys.has(
|
126
|
-
expect(dictWithManyKeys.has(
|
127
|
-
expect(dictWithManyKeys.has(
|
128
|
-
expect(dictWithManyKeys.get(
|
129
|
-
expect(dictWithManyKeys.get(
|
130
|
-
expect(dictWithManyKeys.get(
|
143
|
+
it("should return correct values for multiple stored keys", function () {
|
144
|
+
expect(dictWithManyKeys.has("FontFile")).toBeTruthy();
|
145
|
+
expect(dictWithManyKeys.has("FontFile2")).toBeTruthy();
|
146
|
+
expect(dictWithManyKeys.has("FontFile3")).toBeTruthy();
|
147
|
+
expect(dictWithManyKeys.get("FontFile3")).toEqual(testFontFile3);
|
148
|
+
expect(dictWithManyKeys.get("FontFile2", "FontFile3")).toEqual(testFontFile2);
|
149
|
+
expect(dictWithManyKeys.get("FontFile", "FontFile2", "FontFile3")).toEqual(testFontFile);
|
131
150
|
});
|
132
|
-
it(
|
133
|
-
|
151
|
+
it("should asynchronously fetch unknown keys", function (done) {
|
152
|
+
const keyPromises = [dictWithManyKeys.getAsync("Size"), dictWithSizeKey.getAsync("FontFile", "FontFile2", "FontFile3")];
|
134
153
|
Promise.all(keyPromises).then(function (values) {
|
135
154
|
expect(values[0]).toBeUndefined();
|
136
|
-
expect(values[1]).
|
155
|
+
expect(values[1]).toBeUndefined();
|
137
156
|
done();
|
138
|
-
})
|
157
|
+
}).catch(function (reason) {
|
139
158
|
done.fail(reason);
|
140
159
|
});
|
141
160
|
});
|
142
|
-
it(
|
143
|
-
|
161
|
+
it("should asynchronously fetch correct values for multiple stored keys", function (done) {
|
162
|
+
const keyPromises = [dictWithManyKeys.getAsync("FontFile3"), dictWithManyKeys.getAsync("FontFile2", "FontFile3"), dictWithManyKeys.getAsync("FontFile", "FontFile2", "FontFile3")];
|
144
163
|
Promise.all(keyPromises).then(function (values) {
|
145
164
|
expect(values[0]).toEqual(testFontFile3);
|
146
165
|
expect(values[1]).toEqual(testFontFile2);
|
147
166
|
expect(values[2]).toEqual(testFontFile);
|
148
167
|
done();
|
149
|
-
})
|
168
|
+
}).catch(function (reason) {
|
150
169
|
done.fail(reason);
|
151
170
|
});
|
152
171
|
});
|
153
|
-
it(
|
154
|
-
|
172
|
+
it("should callback for each stored key", function () {
|
173
|
+
const callbackSpy = jasmine.createSpy("spy on callback in dictionary");
|
155
174
|
dictWithManyKeys.forEach(callbackSpy);
|
156
175
|
expect(callbackSpy).toHaveBeenCalled();
|
157
|
-
|
158
|
-
expect(callbackSpyCalls.argsFor(0)).toEqual([
|
159
|
-
expect(callbackSpyCalls.argsFor(1)).toEqual([
|
160
|
-
expect(callbackSpyCalls.argsFor(2)).toEqual([
|
176
|
+
const callbackSpyCalls = callbackSpy.calls;
|
177
|
+
expect(callbackSpyCalls.argsFor(0)).toEqual(["FontFile", testFontFile]);
|
178
|
+
expect(callbackSpyCalls.argsFor(1)).toEqual(["FontFile2", testFontFile2]);
|
179
|
+
expect(callbackSpyCalls.argsFor(2)).toEqual(["FontFile3", testFontFile3]);
|
161
180
|
expect(callbackSpyCalls.count()).toEqual(3);
|
162
181
|
});
|
163
|
-
it(
|
164
|
-
|
182
|
+
it("should handle keys pointing to indirect objects, both sync and async", function (done) {
|
183
|
+
const fontRef = _primitives.Ref.get(1, 0);
|
165
184
|
|
166
|
-
|
185
|
+
const xref = new _test_utils.XRefMock([{
|
167
186
|
ref: fontRef,
|
168
187
|
data: testFontFile
|
169
188
|
}]);
|
170
|
-
|
171
|
-
fontDict.set(
|
172
|
-
expect(fontDict.getRaw(
|
173
|
-
expect(fontDict.get(
|
174
|
-
fontDict.getAsync(
|
189
|
+
const fontDict = new _primitives.Dict(xref);
|
190
|
+
fontDict.set("FontFile", fontRef);
|
191
|
+
expect(fontDict.getRaw("FontFile")).toEqual(fontRef);
|
192
|
+
expect(fontDict.get("FontFile", "FontFile2", "FontFile3")).toEqual(testFontFile);
|
193
|
+
fontDict.getAsync("FontFile", "FontFile2", "FontFile3").then(function (value) {
|
175
194
|
expect(value).toEqual(testFontFile);
|
176
195
|
done();
|
177
|
-
})
|
196
|
+
}).catch(function (reason) {
|
178
197
|
done.fail(reason);
|
179
198
|
});
|
180
199
|
});
|
181
|
-
it(
|
182
|
-
|
183
|
-
|
200
|
+
it("should handle arrays containing indirect objects", function () {
|
201
|
+
const minCoordRef = _primitives.Ref.get(1, 0);
|
202
|
+
|
203
|
+
const maxCoordRef = _primitives.Ref.get(2, 0);
|
184
204
|
|
185
|
-
|
186
|
-
|
187
|
-
|
205
|
+
const minCoord = 0;
|
206
|
+
const maxCoord = 1;
|
207
|
+
const xref = new _test_utils.XRefMock([{
|
188
208
|
ref: minCoordRef,
|
189
209
|
data: minCoord
|
190
210
|
}, {
|
191
211
|
ref: maxCoordRef,
|
192
212
|
data: maxCoord
|
193
213
|
}]);
|
194
|
-
|
195
|
-
xObjectDict.set(
|
196
|
-
expect(xObjectDict.get(
|
197
|
-
expect(xObjectDict.getArray(
|
198
|
-
});
|
199
|
-
it(
|
200
|
-
|
201
|
-
|
214
|
+
const xObjectDict = new _primitives.Dict(xref);
|
215
|
+
xObjectDict.set("BBox", [minCoord, maxCoord, minCoordRef, maxCoordRef]);
|
216
|
+
expect(xObjectDict.get("BBox")).toEqual([minCoord, maxCoord, minCoordRef, maxCoordRef]);
|
217
|
+
expect(xObjectDict.getArray("BBox")).toEqual([minCoord, maxCoord, minCoord, maxCoord]);
|
218
|
+
});
|
219
|
+
it("should get all key names", function () {
|
220
|
+
const expectedKeys = ["FontFile", "FontFile2", "FontFile3"];
|
221
|
+
const keys = dictWithManyKeys.getKeys();
|
202
222
|
expect(keys.sort()).toEqual(expectedKeys);
|
203
223
|
});
|
204
|
-
it(
|
205
|
-
|
206
|
-
|
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
|
+
});
|
252
|
+
it("should create only one object for Dict.empty", function () {
|
253
|
+
const firstDictEmpty = _primitives.Dict.empty;
|
254
|
+
const secondDictEmpty = _primitives.Dict.empty;
|
207
255
|
expect(firstDictEmpty).toBe(secondDictEmpty);
|
208
256
|
expect(firstDictEmpty).not.toBe(emptyDict);
|
209
257
|
});
|
210
|
-
it(
|
211
|
-
|
212
|
-
|
213
|
-
fontFileDict.set(
|
258
|
+
it("should correctly merge dictionaries", function () {
|
259
|
+
const expectedKeys = ["FontFile", "FontFile2", "FontFile3", "Size"];
|
260
|
+
const fontFileDict = new _primitives.Dict();
|
261
|
+
fontFileDict.set("FontFile", "Type1 font file");
|
214
262
|
|
215
|
-
|
263
|
+
const mergedDict = _primitives.Dict.merge({
|
264
|
+
xref: null,
|
265
|
+
dictArray: [dictWithManyKeys, dictWithSizeKey, fontFileDict]
|
266
|
+
});
|
216
267
|
|
217
|
-
|
268
|
+
const mergedKeys = mergedDict.getKeys();
|
218
269
|
expect(mergedKeys.sort()).toEqual(expectedKeys);
|
219
|
-
expect(mergedDict.get(
|
270
|
+
expect(mergedDict.get("FontFile")).toEqual(testFontFile);
|
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"]);
|
220
307
|
});
|
221
308
|
});
|
222
|
-
describe(
|
223
|
-
it(
|
224
|
-
|
225
|
-
|
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");
|
226
314
|
|
227
|
-
|
315
|
+
const zeroRef = _primitives.Ref.get(4, 0);
|
316
|
+
|
317
|
+
expect(zeroRef.toString()).toEqual("4R");
|
318
|
+
});
|
319
|
+
it("should retain the stored values", function () {
|
320
|
+
const storedNum = 4;
|
321
|
+
const storedGen = 2;
|
322
|
+
|
323
|
+
const ref = _primitives.Ref.get(storedNum, storedGen);
|
228
324
|
|
229
325
|
expect(ref.num).toEqual(storedNum);
|
230
326
|
expect(ref.gen).toEqual(storedGen);
|
231
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
|
+
});
|
232
341
|
});
|
233
|
-
describe(
|
234
|
-
it(
|
235
|
-
|
342
|
+
describe("RefSet", function () {
|
343
|
+
it("should have a stored value", function () {
|
344
|
+
const ref = _primitives.Ref.get(4, 2);
|
236
345
|
|
237
|
-
|
346
|
+
const refset = new _primitives.RefSet();
|
238
347
|
refset.put(ref);
|
239
348
|
expect(refset.has(ref)).toBeTruthy();
|
240
349
|
});
|
241
|
-
it(
|
242
|
-
|
350
|
+
it("should not have an unknown value", function () {
|
351
|
+
const ref = _primitives.Ref.get(4, 2);
|
243
352
|
|
244
|
-
|
353
|
+
const refset = new _primitives.RefSet();
|
245
354
|
expect(refset.has(ref)).toBeFalsy();
|
246
355
|
refset.put(ref);
|
247
356
|
|
248
|
-
|
357
|
+
const anotherRef = _primitives.Ref.get(2, 4);
|
249
358
|
|
250
359
|
expect(refset.has(anotherRef)).toBeFalsy();
|
251
360
|
});
|
252
361
|
});
|
253
|
-
describe(
|
254
|
-
|
255
|
-
|
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
|
+
});
|
424
|
+
describe("isName", function () {
|
425
|
+
it("handles non-names", function () {
|
426
|
+
const nonName = {};
|
256
427
|
expect((0, _primitives.isName)(nonName)).toEqual(false);
|
257
428
|
});
|
258
|
-
it(
|
259
|
-
|
429
|
+
it("handles names", function () {
|
430
|
+
const name = _primitives.Name.get("Font");
|
260
431
|
|
261
432
|
expect((0, _primitives.isName)(name)).toEqual(true);
|
262
433
|
});
|
263
|
-
it(
|
264
|
-
|
434
|
+
it("handles names with name check", function () {
|
435
|
+
const name = _primitives.Name.get("Font");
|
265
436
|
|
266
|
-
expect((0, _primitives.isName)(name,
|
267
|
-
expect((0, _primitives.isName)(name,
|
437
|
+
expect((0, _primitives.isName)(name, "Font")).toEqual(true);
|
438
|
+
expect((0, _primitives.isName)(name, "Subtype")).toEqual(false);
|
268
439
|
});
|
269
440
|
});
|
270
|
-
describe(
|
271
|
-
it(
|
272
|
-
|
441
|
+
describe("isCmd", function () {
|
442
|
+
it("handles non-commands", function () {
|
443
|
+
const nonCmd = {};
|
273
444
|
expect((0, _primitives.isCmd)(nonCmd)).toEqual(false);
|
274
445
|
});
|
275
|
-
it(
|
276
|
-
|
446
|
+
it("handles commands", function () {
|
447
|
+
const cmd = _primitives.Cmd.get("BT");
|
277
448
|
|
278
449
|
expect((0, _primitives.isCmd)(cmd)).toEqual(true);
|
279
450
|
});
|
280
|
-
it(
|
281
|
-
|
451
|
+
it("handles commands with cmd check", function () {
|
452
|
+
const cmd = _primitives.Cmd.get("BT");
|
282
453
|
|
283
|
-
expect((0, _primitives.isCmd)(cmd,
|
284
|
-
expect((0, _primitives.isCmd)(cmd,
|
454
|
+
expect((0, _primitives.isCmd)(cmd, "BT")).toEqual(true);
|
455
|
+
expect((0, _primitives.isCmd)(cmd, "ET")).toEqual(false);
|
285
456
|
});
|
286
457
|
});
|
287
|
-
describe(
|
288
|
-
it(
|
289
|
-
|
458
|
+
describe("isDict", function () {
|
459
|
+
it("handles non-dictionaries", function () {
|
460
|
+
const nonDict = {};
|
290
461
|
expect((0, _primitives.isDict)(nonDict)).toEqual(false);
|
291
462
|
});
|
292
|
-
it(
|
293
|
-
|
463
|
+
it("handles empty dictionaries with type check", function () {
|
464
|
+
const dict = _primitives.Dict.empty;
|
294
465
|
expect((0, _primitives.isDict)(dict)).toEqual(true);
|
295
|
-
expect((0, _primitives.isDict)(dict,
|
466
|
+
expect((0, _primitives.isDict)(dict, "Page")).toEqual(false);
|
296
467
|
});
|
297
|
-
it(
|
298
|
-
|
299
|
-
dict.set(
|
300
|
-
expect((0, _primitives.isDict)(dict,
|
301
|
-
expect((0, _primitives.isDict)(dict,
|
468
|
+
it("handles dictionaries with type check", function () {
|
469
|
+
const dict = new _primitives.Dict();
|
470
|
+
dict.set("Type", _primitives.Name.get("Page"));
|
471
|
+
expect((0, _primitives.isDict)(dict, "Page")).toEqual(true);
|
472
|
+
expect((0, _primitives.isDict)(dict, "Contents")).toEqual(false);
|
302
473
|
});
|
303
474
|
});
|
304
|
-
describe(
|
305
|
-
it(
|
306
|
-
|
475
|
+
describe("isRef", function () {
|
476
|
+
it("handles non-refs", function () {
|
477
|
+
const nonRef = {};
|
307
478
|
expect((0, _primitives.isRef)(nonRef)).toEqual(false);
|
308
479
|
});
|
309
|
-
it(
|
310
|
-
|
480
|
+
it("handles refs", function () {
|
481
|
+
const ref = _primitives.Ref.get(1, 0);
|
311
482
|
|
312
483
|
expect((0, _primitives.isRef)(ref)).toEqual(true);
|
313
484
|
});
|
314
485
|
});
|
315
|
-
describe(
|
316
|
-
it(
|
317
|
-
|
486
|
+
describe("isRefsEqual", function () {
|
487
|
+
it("should handle Refs pointing to the same object", function () {
|
488
|
+
const ref1 = _primitives.Ref.get(1, 0);
|
318
489
|
|
319
|
-
|
490
|
+
const ref2 = _primitives.Ref.get(1, 0);
|
320
491
|
|
321
492
|
expect((0, _primitives.isRefsEqual)(ref1, ref2)).toEqual(true);
|
322
493
|
});
|
323
|
-
it(
|
324
|
-
|
494
|
+
it("should handle Refs pointing to different objects", function () {
|
495
|
+
const ref1 = _primitives.Ref.get(1, 0);
|
325
496
|
|
326
|
-
|
497
|
+
const ref2 = _primitives.Ref.get(2, 0);
|
327
498
|
|
328
499
|
expect((0, _primitives.isRefsEqual)(ref1, ref2)).toEqual(false);
|
329
500
|
});
|
330
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
|
+
});
|
331
512
|
});
|