pdfjs-dist 2.1.266 → 2.5.207
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/CODE_OF_CONDUCT.md +15 -0
- package/README.md +4 -0
- package/bower.json +1 -1
- package/build/pdf.js +8382 -18492
- 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 +20417 -29816
- package/build/pdf.worker.js.map +1 -1
- package/build/pdf.worker.min.js +22 -1
- package/es5/build/pdf.js +25688 -0
- package/es5/build/pdf.js.map +1 -0
- package/{lib/shared/global_scope.js → es5/build/pdf.worker.entry.js} +5 -10
- package/es5/build/pdf.worker.js +58239 -0
- package/es5/build/pdf.worker.js.map +1 -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/images/texture.png +0 -0
- package/es5/web/pdf_viewer.css +403 -0
- package/es5/web/pdf_viewer.js +7742 -0
- package/es5/web/pdf_viewer.js.map +1 -0
- package/image_decoders/pdf.image_decoders.js +1475 -4897
- 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 +750 -899
- 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 +235 -183
- package/lib/core/charsets.js +4 -4
- package/lib/core/chunked_stream.js +447 -542
- package/lib/core/cmap.js +222 -264
- package/lib/core/colorspace.js +699 -863
- package/lib/core/core_utils.js +152 -0
- package/lib/core/crypto.js +379 -437
- package/lib/core/document.js +573 -660
- package/lib/core/encodings.js +15 -15
- package/lib/core/evaluator.js +1103 -868
- package/lib/core/font_renderer.js +135 -178
- package/lib/core/fonts.js +570 -491
- package/lib/core/function.js +291 -288
- package/lib/core/glyphlist.js +4527 -4526
- package/lib/core/image.js +145 -149
- package/lib/core/image_utils.js +170 -0
- 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 +284 -232
- package/lib/core/jpx.js +161 -143
- package/lib/core/jpx_stream.js +28 -28
- package/lib/core/metrics.js +2929 -2929
- package/lib/core/murmurhash3.js +90 -101
- package/lib/core/obj.js +1183 -1157
- package/lib/core/operator_list.js +99 -67
- package/lib/core/parser.js +972 -911
- package/lib/core/pattern.js +87 -70
- package/lib/core/pdf_manager.js +150 -315
- package/lib/core/primitives.js +83 -56
- 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 +87 -69
- package/lib/core/unicode.js +1654 -1654
- package/lib/core/worker.js +193 -390
- package/lib/core/worker_stream.js +168 -0
- package/lib/display/annotation_layer.js +741 -972
- package/lib/display/api.js +1500 -1791
- package/lib/display/api_compatibility.js +12 -17
- package/lib/display/canvas.js +165 -165
- package/lib/display/content_disposition.js +40 -59
- package/lib/display/display_utils.js +515 -0
- package/lib/display/fetch_stream.js +183 -298
- package/lib/display/font_loader.js +273 -413
- package/lib/display/metadata.js +86 -98
- package/lib/display/network.js +266 -359
- package/lib/display/network_utils.js +25 -18
- package/lib/display/node_stream.js +285 -458
- package/lib/display/pattern_helper.js +113 -65
- package/lib/display/svg.js +1166 -901
- package/lib/display/text_layer.js +156 -132
- package/lib/display/transport_stream.js +262 -278
- 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 +40 -37
- package/lib/pdf.js +226 -59
- 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 +266 -416
- package/lib/test/unit/annotation_spec.js +1555 -701
- package/lib/test/unit/api_spec.js +802 -604
- package/lib/test/unit/bidi_spec.js +7 -7
- package/lib/test/unit/cff_parser_spec.js +84 -69
- package/lib/test/unit/clitests_helper.js +7 -9
- package/lib/test/unit/cmap_spec.js +74 -76
- package/lib/test/unit/colorspace_spec.js +166 -161
- package/lib/test/unit/core_utils_spec.js +211 -0
- package/lib/test/unit/crypto_spec.js +181 -181
- package/lib/test/unit/custom_spec.js +20 -22
- package/lib/test/unit/display_svg_spec.js +34 -39
- package/lib/test/unit/display_utils_spec.js +263 -0
- package/lib/test/unit/document_spec.js +16 -21
- package/lib/test/unit/encodings_spec.js +12 -34
- package/lib/test/unit/evaluator_spec.js +83 -83
- package/lib/test/unit/fetch_stream_spec.js +111 -0
- package/lib/test/unit/function_spec.js +206 -204
- package/lib/test/unit/jasmine-boot.js +46 -30
- package/lib/test/unit/message_handler_spec.js +173 -159
- package/lib/test/unit/metadata_spec.js +69 -69
- package/lib/test/unit/murmurhash3_spec.js +12 -12
- package/lib/test/unit/network_spec.js +13 -61
- package/lib/test/unit/network_utils_spec.js +183 -119
- package/lib/test/unit/node_stream_spec.js +78 -92
- package/lib/test/unit/parser_spec.js +172 -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 +140 -125
- package/lib/test/unit/stream_spec.js +16 -14
- package/lib/test/unit/test_utils.js +131 -143
- package/lib/test/unit/testreporter.js +19 -19
- package/lib/test/unit/type1_parser_spec.js +42 -42
- package/lib/test/unit/ui_utils_spec.js +297 -459
- package/lib/test/unit/unicode_spec.js +38 -38
- package/lib/test/unit/util_spec.js +121 -305
- package/lib/web/annotation_layer_builder.js +66 -103
- package/lib/web/app.js +1328 -1214
- package/lib/web/app_options.js +105 -107
- package/lib/web/base_viewer.js +824 -838
- package/lib/web/chromecom.js +165 -252
- package/lib/web/debugger.js +149 -205
- package/lib/web/download_manager.js +39 -55
- package/lib/web/firefox_print_service.js +37 -27
- package/lib/web/firefoxcom.js +212 -363
- package/lib/web/genericcom.js +26 -108
- package/lib/web/genericl10n.js +24 -153
- package/lib/web/grab_to_pan.js +32 -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 +113 -131
- package/lib/web/pdf_cursor_tools.js +75 -102
- package/lib/web/pdf_document_properties.js +221 -306
- package/lib/web/pdf_find_bar.js +136 -170
- package/lib/web/pdf_find_controller.js +491 -548
- package/lib/web/pdf_find_utils.js +13 -13
- package/lib/web/pdf_history.js +397 -406
- package/lib/web/pdf_link_service.js +304 -348
- package/lib/web/pdf_outline_viewer.js +140 -175
- package/lib/web/pdf_page_view.js +452 -523
- package/lib/web/pdf_presentation_mode.js +308 -357
- package/lib/web/pdf_print_service.js +90 -104
- package/lib/web/pdf_rendering_queue.js +84 -108
- package/lib/web/pdf_sidebar.js +276 -306
- 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 +276 -297
- package/lib/web/pdf_thumbnail_viewer.js +186 -206
- package/lib/web/pdf_viewer.component.js +20 -21
- package/lib/web/pdf_viewer.js +55 -115
- package/lib/web/preferences.js +82 -286
- package/lib/web/secondary_toolbar.js +164 -196
- package/lib/web/text_layer_builder.js +282 -339
- package/lib/web/toolbar.js +217 -210
- package/lib/web/ui_utils.js +267 -420
- package/lib/web/view_history.js +52 -226
- package/lib/web/viewer_compatibility.js +21 -6
- package/package.json +2 -9
- package/web/pdf_viewer.css +35 -25
- package/web/pdf_viewer.js +3489 -4855
- package/web/pdf_viewer.js.map +1 -1
- package/webpack.js +14 -5
- package/external/streams/streams-lib.js +0 -3962
- package/external/url/url-lib.js +0 -627
- package/lib/display/dom_utils.js +0 -494
- package/lib/shared/streams_polyfill.js +0 -43
- package/lib/shared/url_polyfill.js +0 -56
- package/lib/test/unit/dom_utils_spec.js +0 -89
@@ -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,41 +21,41 @@
|
|
21
21
|
*/
|
22
22
|
"use strict";
|
23
23
|
|
24
|
-
var _pdf_find_utils = require("../../web/pdf_find_utils");
|
24
|
+
var _pdf_find_utils = require("../../web/pdf_find_utils.js");
|
25
25
|
|
26
|
-
describe(
|
27
|
-
describe(
|
28
|
-
it(
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
26
|
+
describe("pdf_find_utils", function () {
|
27
|
+
describe("getCharacterType", function () {
|
28
|
+
it("gets expected character types", function () {
|
29
|
+
const characters = {
|
30
|
+
A: _pdf_find_utils.CharacterType.ALPHA_LETTER,
|
31
|
+
a: _pdf_find_utils.CharacterType.ALPHA_LETTER,
|
32
|
+
"0": _pdf_find_utils.CharacterType.ALPHA_LETTER,
|
33
|
+
"5": _pdf_find_utils.CharacterType.ALPHA_LETTER,
|
34
|
+
Ä: _pdf_find_utils.CharacterType.ALPHA_LETTER,
|
35
|
+
ä: _pdf_find_utils.CharacterType.ALPHA_LETTER,
|
36
|
+
_: _pdf_find_utils.CharacterType.ALPHA_LETTER,
|
37
|
+
" ": _pdf_find_utils.CharacterType.SPACE,
|
38
|
+
"\t": _pdf_find_utils.CharacterType.SPACE,
|
39
|
+
"\r": _pdf_find_utils.CharacterType.SPACE,
|
40
|
+
"\n": _pdf_find_utils.CharacterType.SPACE,
|
41
|
+
"\xA0": _pdf_find_utils.CharacterType.SPACE,
|
42
|
+
"-": _pdf_find_utils.CharacterType.PUNCT,
|
43
|
+
",": _pdf_find_utils.CharacterType.PUNCT,
|
44
|
+
".": _pdf_find_utils.CharacterType.PUNCT,
|
45
|
+
";": _pdf_find_utils.CharacterType.PUNCT,
|
46
|
+
":": _pdf_find_utils.CharacterType.PUNCT,
|
47
47
|
"\u2122": _pdf_find_utils.CharacterType.ALPHA_LETTER,
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
48
|
+
ล: _pdf_find_utils.CharacterType.THAI_LETTER,
|
49
|
+
䀀: _pdf_find_utils.CharacterType.HAN_LETTER,
|
50
|
+
縷: _pdf_find_utils.CharacterType.HAN_LETTER,
|
51
|
+
ダ: _pdf_find_utils.CharacterType.KATAKANA_LETTER,
|
52
|
+
ぐ: _pdf_find_utils.CharacterType.HIRAGANA_LETTER,
|
53
|
+
タ: _pdf_find_utils.CharacterType.HALFWIDTH_KATAKANA_LETTER
|
54
54
|
};
|
55
55
|
|
56
|
-
for (
|
57
|
-
|
58
|
-
|
56
|
+
for (const character in characters) {
|
57
|
+
const charCode = character.charCodeAt(0);
|
58
|
+
const type = characters[character];
|
59
59
|
expect((0, _pdf_find_utils.getCharacterType)(charCode)).toEqual(type);
|
60
60
|
}
|
61
61
|
});
|
@@ -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,73 +21,73 @@
|
|
21
21
|
*/
|
22
22
|
"use strict";
|
23
23
|
|
24
|
-
var _pdf_history = require("../../web/pdf_history");
|
24
|
+
var _pdf_history = require("../../web/pdf_history.js");
|
25
25
|
|
26
|
-
describe(
|
27
|
-
describe(
|
28
|
-
it(
|
29
|
-
expect((0, _pdf_history.isDestHashesEqual)(null,
|
30
|
-
expect((0, _pdf_history.isDestHashesEqual)(
|
31
|
-
expect((0, _pdf_history.isDestHashesEqual)(
|
32
|
-
expect((0, _pdf_history.isDestHashesEqual)(
|
33
|
-
expect((0, _pdf_history.isDestHashesEqual)(
|
34
|
-
|
26
|
+
describe("pdf_history", function () {
|
27
|
+
describe("isDestHashesEqual", function () {
|
28
|
+
it("should reject non-equal destination hashes", function () {
|
29
|
+
expect((0, _pdf_history.isDestHashesEqual)(null, "page.157")).toEqual(false);
|
30
|
+
expect((0, _pdf_history.isDestHashesEqual)("title.0", "page.157")).toEqual(false);
|
31
|
+
expect((0, _pdf_history.isDestHashesEqual)("page=1&zoom=auto", "page.157")).toEqual(false);
|
32
|
+
expect((0, _pdf_history.isDestHashesEqual)("nameddest-page.157", "page.157")).toEqual(false);
|
33
|
+
expect((0, _pdf_history.isDestHashesEqual)("page.157", "nameddest=page.157")).toEqual(false);
|
34
|
+
const destArrayString = JSON.stringify([{
|
35
35
|
num: 3757,
|
36
36
|
gen: 0
|
37
37
|
}, {
|
38
|
-
name:
|
38
|
+
name: "XYZ"
|
39
39
|
}, 92.918, 748.972, null]);
|
40
|
-
expect((0, _pdf_history.isDestHashesEqual)(destArrayString,
|
41
|
-
expect((0, _pdf_history.isDestHashesEqual)(
|
40
|
+
expect((0, _pdf_history.isDestHashesEqual)(destArrayString, "page.157")).toEqual(false);
|
41
|
+
expect((0, _pdf_history.isDestHashesEqual)("page.157", destArrayString)).toEqual(false);
|
42
42
|
});
|
43
|
-
it(
|
44
|
-
expect((0, _pdf_history.isDestHashesEqual)(
|
45
|
-
expect((0, _pdf_history.isDestHashesEqual)(
|
46
|
-
expect((0, _pdf_history.isDestHashesEqual)(
|
43
|
+
it("should accept equal destination hashes", function () {
|
44
|
+
expect((0, _pdf_history.isDestHashesEqual)("page.157", "page.157")).toEqual(true);
|
45
|
+
expect((0, _pdf_history.isDestHashesEqual)("nameddest=page.157", "page.157")).toEqual(true);
|
46
|
+
expect((0, _pdf_history.isDestHashesEqual)("nameddest=page.157&zoom=100", "page.157")).toEqual(true);
|
47
47
|
});
|
48
48
|
});
|
49
|
-
describe(
|
50
|
-
|
49
|
+
describe("isDestArraysEqual", function () {
|
50
|
+
const firstDest = [{
|
51
51
|
num: 1,
|
52
52
|
gen: 0
|
53
53
|
}, {
|
54
|
-
name:
|
54
|
+
name: "XYZ"
|
55
55
|
}, 0, 375, null];
|
56
|
-
|
56
|
+
const secondDest = [{
|
57
57
|
num: 5,
|
58
58
|
gen: 0
|
59
59
|
}, {
|
60
|
-
name:
|
60
|
+
name: "XYZ"
|
61
61
|
}, 0, 375, null];
|
62
|
-
|
62
|
+
const thirdDest = [{
|
63
63
|
num: 1,
|
64
64
|
gen: 0
|
65
65
|
}, {
|
66
|
-
name:
|
66
|
+
name: "XYZ"
|
67
67
|
}, 750, 0, null];
|
68
|
-
|
68
|
+
const fourthDest = [{
|
69
69
|
num: 1,
|
70
70
|
gen: 0
|
71
71
|
}, {
|
72
|
-
name:
|
72
|
+
name: "XYZ"
|
73
73
|
}, 0, 375, 1.0];
|
74
|
-
|
74
|
+
const fifthDest = [{
|
75
75
|
gen: 0,
|
76
76
|
num: 1
|
77
77
|
}, {
|
78
|
-
name:
|
78
|
+
name: "XYZ"
|
79
79
|
}, 0, 375, null];
|
80
|
-
it(
|
80
|
+
it("should reject non-equal destination arrays", function () {
|
81
81
|
expect((0, _pdf_history.isDestArraysEqual)(firstDest, undefined)).toEqual(false);
|
82
82
|
expect((0, _pdf_history.isDestArraysEqual)(firstDest, [1, 2, 3, 4, 5])).toEqual(false);
|
83
83
|
expect((0, _pdf_history.isDestArraysEqual)(firstDest, secondDest)).toEqual(false);
|
84
84
|
expect((0, _pdf_history.isDestArraysEqual)(firstDest, thirdDest)).toEqual(false);
|
85
85
|
expect((0, _pdf_history.isDestArraysEqual)(firstDest, fourthDest)).toEqual(false);
|
86
86
|
});
|
87
|
-
it(
|
87
|
+
it("should accept equal destination arrays", function () {
|
88
88
|
expect((0, _pdf_history.isDestArraysEqual)(firstDest, firstDest)).toEqual(true);
|
89
89
|
expect((0, _pdf_history.isDestArraysEqual)(firstDest, fifthDest)).toEqual(true);
|
90
|
-
|
90
|
+
const firstDestCopy = firstDest.slice();
|
91
91
|
expect(firstDest).not.toBe(firstDestCopy);
|
92
92
|
expect((0, _pdf_history.isDestArraysEqual)(firstDest, firstDestCopy)).toEqual(true);
|
93
93
|
});
|
@@ -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,126 +21,128 @@
|
|
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 _test_utils = require("./test_utils");
|
26
|
+
var _test_utils = require("./test_utils.js");
|
27
27
|
|
28
|
-
describe(
|
29
|
-
describe(
|
30
|
-
it(
|
31
|
-
var givenName =
|
28
|
+
describe("primitives", function () {
|
29
|
+
describe("Name", function () {
|
30
|
+
it("should retain the given name", function () {
|
31
|
+
var givenName = "Font";
|
32
32
|
|
33
33
|
var name = _primitives.Name.get(givenName);
|
34
34
|
|
35
35
|
expect(name.name).toEqual(givenName);
|
36
36
|
});
|
37
|
-
it(
|
38
|
-
var firstFont = _primitives.Name.get(
|
37
|
+
it("should create only one object for a name and cache it", function () {
|
38
|
+
var firstFont = _primitives.Name.get("Font");
|
39
39
|
|
40
|
-
var secondFont = _primitives.Name.get(
|
40
|
+
var secondFont = _primitives.Name.get("Font");
|
41
41
|
|
42
|
-
var firstSubtype = _primitives.Name.get(
|
42
|
+
var firstSubtype = _primitives.Name.get("Subtype");
|
43
43
|
|
44
|
-
var secondSubtype = _primitives.Name.get(
|
44
|
+
var secondSubtype = _primitives.Name.get("Subtype");
|
45
45
|
|
46
46
|
expect(firstFont).toBe(secondFont);
|
47
47
|
expect(firstSubtype).toBe(secondSubtype);
|
48
48
|
expect(firstFont).not.toBe(firstSubtype);
|
49
49
|
});
|
50
50
|
});
|
51
|
-
describe(
|
52
|
-
it(
|
53
|
-
var givenCmd =
|
51
|
+
describe("Cmd", function () {
|
52
|
+
it("should retain the given cmd name", function () {
|
53
|
+
var givenCmd = "BT";
|
54
54
|
|
55
55
|
var cmd = _primitives.Cmd.get(givenCmd);
|
56
56
|
|
57
57
|
expect(cmd.cmd).toEqual(givenCmd);
|
58
58
|
});
|
59
|
-
it(
|
60
|
-
var firstBT = _primitives.Cmd.get(
|
59
|
+
it("should create only one object for a command and cache it", function () {
|
60
|
+
var firstBT = _primitives.Cmd.get("BT");
|
61
61
|
|
62
|
-
var secondBT = _primitives.Cmd.get(
|
62
|
+
var secondBT = _primitives.Cmd.get("BT");
|
63
63
|
|
64
|
-
var firstET = _primitives.Cmd.get(
|
64
|
+
var firstET = _primitives.Cmd.get("ET");
|
65
65
|
|
66
|
-
var secondET = _primitives.Cmd.get(
|
66
|
+
var secondET = _primitives.Cmd.get("ET");
|
67
67
|
|
68
68
|
expect(firstBT).toBe(secondBT);
|
69
69
|
expect(firstET).toBe(secondET);
|
70
70
|
expect(firstBT).not.toBe(firstET);
|
71
71
|
});
|
72
72
|
});
|
73
|
-
describe(
|
74
|
-
var checkInvalidHasValues = function
|
73
|
+
describe("Dict", function () {
|
74
|
+
var checkInvalidHasValues = function (dict) {
|
75
75
|
expect(dict.has()).toBeFalsy();
|
76
|
-
expect(dict.has(
|
76
|
+
expect(dict.has("Prev")).toBeFalsy();
|
77
77
|
};
|
78
78
|
|
79
|
-
var checkInvalidKeyValues = function
|
79
|
+
var checkInvalidKeyValues = function (dict) {
|
80
80
|
expect(dict.get()).toBeUndefined();
|
81
|
-
expect(dict.get(
|
82
|
-
expect(dict.get(
|
83
|
-
expect(dict.get(
|
81
|
+
expect(dict.get("Prev")).toBeUndefined();
|
82
|
+
expect(dict.get("Decode", "D")).toBeUndefined();
|
83
|
+
expect(dict.get("FontFile", "FontFile2", "FontFile3")).toBeUndefined();
|
84
84
|
};
|
85
85
|
|
86
86
|
var emptyDict, dictWithSizeKey, dictWithManyKeys;
|
87
87
|
var storedSize = 42;
|
88
|
-
var testFontFile =
|
89
|
-
var testFontFile2 =
|
90
|
-
var testFontFile3 =
|
88
|
+
var testFontFile = "file1";
|
89
|
+
var testFontFile2 = "file2";
|
90
|
+
var testFontFile3 = "file3";
|
91
91
|
beforeAll(function (done) {
|
92
92
|
emptyDict = new _primitives.Dict();
|
93
93
|
dictWithSizeKey = new _primitives.Dict();
|
94
|
-
dictWithSizeKey.set(
|
94
|
+
dictWithSizeKey.set("Size", storedSize);
|
95
95
|
dictWithManyKeys = new _primitives.Dict();
|
96
|
-
dictWithManyKeys.set(
|
97
|
-
dictWithManyKeys.set(
|
98
|
-
dictWithManyKeys.set(
|
96
|
+
dictWithManyKeys.set("FontFile", testFontFile);
|
97
|
+
dictWithManyKeys.set("FontFile2", testFontFile2);
|
98
|
+
dictWithManyKeys.set("FontFile3", testFontFile3);
|
99
99
|
done();
|
100
100
|
});
|
101
101
|
afterAll(function () {
|
102
102
|
emptyDict = dictWithSizeKey = dictWithManyKeys = null;
|
103
103
|
});
|
104
|
-
it(
|
104
|
+
it("should return invalid values for unknown keys", function () {
|
105
105
|
checkInvalidHasValues(emptyDict);
|
106
106
|
checkInvalidKeyValues(emptyDict);
|
107
107
|
});
|
108
|
-
it(
|
109
|
-
expect(dictWithSizeKey.has(
|
110
|
-
expect(dictWithSizeKey.get(
|
111
|
-
expect(dictWithSizeKey.get(
|
112
|
-
expect(dictWithSizeKey.get(
|
108
|
+
it("should return correct value for stored Size key", function () {
|
109
|
+
expect(dictWithSizeKey.has("Size")).toBeTruthy();
|
110
|
+
expect(dictWithSizeKey.get("Size")).toEqual(storedSize);
|
111
|
+
expect(dictWithSizeKey.get("Prev", "Size")).toEqual(storedSize);
|
112
|
+
expect(dictWithSizeKey.get("Prev", "Root", "Size")).toEqual(storedSize);
|
113
113
|
});
|
114
|
-
it(
|
114
|
+
it("should return invalid values for unknown keys when Size key is stored", function () {
|
115
115
|
checkInvalidHasValues(dictWithSizeKey);
|
116
116
|
checkInvalidKeyValues(dictWithSizeKey);
|
117
117
|
});
|
118
|
-
it(
|
119
|
-
|
120
|
-
|
121
|
-
|
118
|
+
it("should not accept to set a key with an undefined value", function () {
|
119
|
+
const dict = new _primitives.Dict();
|
120
|
+
expect(function () {
|
121
|
+
dict.set("Size");
|
122
|
+
}).toThrow(new Error('Dict.set: The "value" cannot be undefined.'));
|
123
|
+
expect(dict.has("Size")).toBeFalsy();
|
122
124
|
checkInvalidKeyValues(dict);
|
123
125
|
});
|
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(
|
126
|
+
it("should return correct values for multiple stored keys", function () {
|
127
|
+
expect(dictWithManyKeys.has("FontFile")).toBeTruthy();
|
128
|
+
expect(dictWithManyKeys.has("FontFile2")).toBeTruthy();
|
129
|
+
expect(dictWithManyKeys.has("FontFile3")).toBeTruthy();
|
130
|
+
expect(dictWithManyKeys.get("FontFile3")).toEqual(testFontFile3);
|
131
|
+
expect(dictWithManyKeys.get("FontFile2", "FontFile3")).toEqual(testFontFile2);
|
132
|
+
expect(dictWithManyKeys.get("FontFile", "FontFile2", "FontFile3")).toEqual(testFontFile);
|
131
133
|
});
|
132
|
-
it(
|
133
|
-
var keyPromises = [dictWithManyKeys.getAsync(
|
134
|
+
it("should asynchronously fetch unknown keys", function (done) {
|
135
|
+
var keyPromises = [dictWithManyKeys.getAsync("Size"), dictWithSizeKey.getAsync("FontFile", "FontFile2", "FontFile3")];
|
134
136
|
Promise.all(keyPromises).then(function (values) {
|
135
137
|
expect(values[0]).toBeUndefined();
|
136
|
-
expect(values[1]).
|
138
|
+
expect(values[1]).toBeUndefined();
|
137
139
|
done();
|
138
140
|
}).catch(function (reason) {
|
139
141
|
done.fail(reason);
|
140
142
|
});
|
141
143
|
});
|
142
|
-
it(
|
143
|
-
var keyPromises = [dictWithManyKeys.getAsync(
|
144
|
+
it("should asynchronously fetch correct values for multiple stored keys", function (done) {
|
145
|
+
var keyPromises = [dictWithManyKeys.getAsync("FontFile3"), dictWithManyKeys.getAsync("FontFile2", "FontFile3"), dictWithManyKeys.getAsync("FontFile", "FontFile2", "FontFile3")];
|
144
146
|
Promise.all(keyPromises).then(function (values) {
|
145
147
|
expect(values[0]).toEqual(testFontFile3);
|
146
148
|
expect(values[1]).toEqual(testFontFile2);
|
@@ -150,36 +152,38 @@ describe('primitives', function () {
|
|
150
152
|
done.fail(reason);
|
151
153
|
});
|
152
154
|
});
|
153
|
-
it(
|
154
|
-
var callbackSpy = jasmine.createSpy(
|
155
|
+
it("should callback for each stored key", function () {
|
156
|
+
var callbackSpy = jasmine.createSpy("spy on callback in dictionary");
|
155
157
|
dictWithManyKeys.forEach(callbackSpy);
|
156
158
|
expect(callbackSpy).toHaveBeenCalled();
|
157
159
|
var callbackSpyCalls = callbackSpy.calls;
|
158
|
-
expect(callbackSpyCalls.argsFor(0)).toEqual([
|
159
|
-
expect(callbackSpyCalls.argsFor(1)).toEqual([
|
160
|
-
expect(callbackSpyCalls.argsFor(2)).toEqual([
|
160
|
+
expect(callbackSpyCalls.argsFor(0)).toEqual(["FontFile", testFontFile]);
|
161
|
+
expect(callbackSpyCalls.argsFor(1)).toEqual(["FontFile2", testFontFile2]);
|
162
|
+
expect(callbackSpyCalls.argsFor(2)).toEqual(["FontFile3", testFontFile3]);
|
161
163
|
expect(callbackSpyCalls.count()).toEqual(3);
|
162
164
|
});
|
163
|
-
it(
|
164
|
-
var fontRef =
|
165
|
+
it("should handle keys pointing to indirect objects, both sync and async", function (done) {
|
166
|
+
var fontRef = _primitives.Ref.get(1, 0);
|
167
|
+
|
165
168
|
var xref = new _test_utils.XRefMock([{
|
166
169
|
ref: fontRef,
|
167
170
|
data: testFontFile
|
168
171
|
}]);
|
169
172
|
var fontDict = new _primitives.Dict(xref);
|
170
|
-
fontDict.set(
|
171
|
-
expect(fontDict.getRaw(
|
172
|
-
expect(fontDict.get(
|
173
|
-
fontDict.getAsync(
|
173
|
+
fontDict.set("FontFile", fontRef);
|
174
|
+
expect(fontDict.getRaw("FontFile")).toEqual(fontRef);
|
175
|
+
expect(fontDict.get("FontFile", "FontFile2", "FontFile3")).toEqual(testFontFile);
|
176
|
+
fontDict.getAsync("FontFile", "FontFile2", "FontFile3").then(function (value) {
|
174
177
|
expect(value).toEqual(testFontFile);
|
175
178
|
done();
|
176
179
|
}).catch(function (reason) {
|
177
180
|
done.fail(reason);
|
178
181
|
});
|
179
182
|
});
|
180
|
-
it(
|
181
|
-
var minCoordRef =
|
182
|
-
maxCoordRef =
|
183
|
+
it("should handle arrays containing indirect objects", function () {
|
184
|
+
var minCoordRef = _primitives.Ref.get(1, 0),
|
185
|
+
maxCoordRef = _primitives.Ref.get(2, 0);
|
186
|
+
|
183
187
|
var minCoord = 0,
|
184
188
|
maxCoord = 1;
|
185
189
|
var xref = new _test_utils.XRefMock([{
|
@@ -190,128 +194,139 @@ describe('primitives', function () {
|
|
190
194
|
data: maxCoord
|
191
195
|
}]);
|
192
196
|
var xObjectDict = new _primitives.Dict(xref);
|
193
|
-
xObjectDict.set(
|
194
|
-
expect(xObjectDict.get(
|
195
|
-
expect(xObjectDict.getArray(
|
197
|
+
xObjectDict.set("BBox", [minCoord, maxCoord, minCoordRef, maxCoordRef]);
|
198
|
+
expect(xObjectDict.get("BBox")).toEqual([minCoord, maxCoord, minCoordRef, maxCoordRef]);
|
199
|
+
expect(xObjectDict.getArray("BBox")).toEqual([minCoord, maxCoord, minCoord, maxCoord]);
|
196
200
|
});
|
197
|
-
it(
|
198
|
-
var expectedKeys = [
|
201
|
+
it("should get all key names", function () {
|
202
|
+
var expectedKeys = ["FontFile", "FontFile2", "FontFile3"];
|
199
203
|
var keys = dictWithManyKeys.getKeys();
|
200
204
|
expect(keys.sort()).toEqual(expectedKeys);
|
201
205
|
});
|
202
|
-
it(
|
206
|
+
it("should create only one object for Dict.empty", function () {
|
203
207
|
var firstDictEmpty = _primitives.Dict.empty;
|
204
208
|
var secondDictEmpty = _primitives.Dict.empty;
|
205
209
|
expect(firstDictEmpty).toBe(secondDictEmpty);
|
206
210
|
expect(firstDictEmpty).not.toBe(emptyDict);
|
207
211
|
});
|
208
|
-
it(
|
209
|
-
var expectedKeys = [
|
212
|
+
it("should correctly merge dictionaries", function () {
|
213
|
+
var expectedKeys = ["FontFile", "FontFile2", "FontFile3", "Size"];
|
210
214
|
var fontFileDict = new _primitives.Dict();
|
211
|
-
fontFileDict.set(
|
215
|
+
fontFileDict.set("FontFile", "Type1 font file");
|
212
216
|
|
213
217
|
var mergedDict = _primitives.Dict.merge(null, [dictWithManyKeys, dictWithSizeKey, fontFileDict]);
|
214
218
|
|
215
219
|
var mergedKeys = mergedDict.getKeys();
|
216
220
|
expect(mergedKeys.sort()).toEqual(expectedKeys);
|
217
|
-
expect(mergedDict.get(
|
221
|
+
expect(mergedDict.get("FontFile")).toEqual(testFontFile);
|
218
222
|
});
|
219
223
|
});
|
220
|
-
describe(
|
221
|
-
it(
|
224
|
+
describe("Ref", function () {
|
225
|
+
it("should retain the stored values", function () {
|
222
226
|
var storedNum = 4;
|
223
227
|
var storedGen = 2;
|
224
|
-
|
228
|
+
|
229
|
+
var ref = _primitives.Ref.get(storedNum, storedGen);
|
230
|
+
|
225
231
|
expect(ref.num).toEqual(storedNum);
|
226
232
|
expect(ref.gen).toEqual(storedGen);
|
227
233
|
});
|
228
234
|
});
|
229
|
-
describe(
|
230
|
-
it(
|
231
|
-
var ref =
|
235
|
+
describe("RefSet", function () {
|
236
|
+
it("should have a stored value", function () {
|
237
|
+
var ref = _primitives.Ref.get(4, 2);
|
238
|
+
|
232
239
|
var refset = new _primitives.RefSet();
|
233
240
|
refset.put(ref);
|
234
241
|
expect(refset.has(ref)).toBeTruthy();
|
235
242
|
});
|
236
|
-
it(
|
237
|
-
var ref =
|
243
|
+
it("should not have an unknown value", function () {
|
244
|
+
var ref = _primitives.Ref.get(4, 2);
|
245
|
+
|
238
246
|
var refset = new _primitives.RefSet();
|
239
247
|
expect(refset.has(ref)).toBeFalsy();
|
240
248
|
refset.put(ref);
|
241
|
-
|
249
|
+
|
250
|
+
var anotherRef = _primitives.Ref.get(2, 4);
|
251
|
+
|
242
252
|
expect(refset.has(anotherRef)).toBeFalsy();
|
243
253
|
});
|
244
254
|
});
|
245
|
-
describe(
|
246
|
-
it(
|
255
|
+
describe("isName", function () {
|
256
|
+
it("handles non-names", function () {
|
247
257
|
var nonName = {};
|
248
258
|
expect((0, _primitives.isName)(nonName)).toEqual(false);
|
249
259
|
});
|
250
|
-
it(
|
251
|
-
var name = _primitives.Name.get(
|
260
|
+
it("handles names", function () {
|
261
|
+
var name = _primitives.Name.get("Font");
|
252
262
|
|
253
263
|
expect((0, _primitives.isName)(name)).toEqual(true);
|
254
264
|
});
|
255
|
-
it(
|
256
|
-
var name = _primitives.Name.get(
|
265
|
+
it("handles names with name check", function () {
|
266
|
+
var name = _primitives.Name.get("Font");
|
257
267
|
|
258
|
-
expect((0, _primitives.isName)(name,
|
259
|
-
expect((0, _primitives.isName)(name,
|
268
|
+
expect((0, _primitives.isName)(name, "Font")).toEqual(true);
|
269
|
+
expect((0, _primitives.isName)(name, "Subtype")).toEqual(false);
|
260
270
|
});
|
261
271
|
});
|
262
|
-
describe(
|
263
|
-
it(
|
272
|
+
describe("isCmd", function () {
|
273
|
+
it("handles non-commands", function () {
|
264
274
|
var nonCmd = {};
|
265
275
|
expect((0, _primitives.isCmd)(nonCmd)).toEqual(false);
|
266
276
|
});
|
267
|
-
it(
|
268
|
-
var cmd = _primitives.Cmd.get(
|
277
|
+
it("handles commands", function () {
|
278
|
+
var cmd = _primitives.Cmd.get("BT");
|
269
279
|
|
270
280
|
expect((0, _primitives.isCmd)(cmd)).toEqual(true);
|
271
281
|
});
|
272
|
-
it(
|
273
|
-
var cmd = _primitives.Cmd.get(
|
282
|
+
it("handles commands with cmd check", function () {
|
283
|
+
var cmd = _primitives.Cmd.get("BT");
|
274
284
|
|
275
|
-
expect((0, _primitives.isCmd)(cmd,
|
276
|
-
expect((0, _primitives.isCmd)(cmd,
|
285
|
+
expect((0, _primitives.isCmd)(cmd, "BT")).toEqual(true);
|
286
|
+
expect((0, _primitives.isCmd)(cmd, "ET")).toEqual(false);
|
277
287
|
});
|
278
288
|
});
|
279
|
-
describe(
|
280
|
-
it(
|
289
|
+
describe("isDict", function () {
|
290
|
+
it("handles non-dictionaries", function () {
|
281
291
|
var nonDict = {};
|
282
292
|
expect((0, _primitives.isDict)(nonDict)).toEqual(false);
|
283
293
|
});
|
284
|
-
it(
|
294
|
+
it("handles empty dictionaries with type check", function () {
|
285
295
|
var dict = _primitives.Dict.empty;
|
286
296
|
expect((0, _primitives.isDict)(dict)).toEqual(true);
|
287
|
-
expect((0, _primitives.isDict)(dict,
|
297
|
+
expect((0, _primitives.isDict)(dict, "Page")).toEqual(false);
|
288
298
|
});
|
289
|
-
it(
|
299
|
+
it("handles dictionaries with type check", function () {
|
290
300
|
var dict = new _primitives.Dict();
|
291
|
-
dict.set(
|
292
|
-
expect((0, _primitives.isDict)(dict,
|
293
|
-
expect((0, _primitives.isDict)(dict,
|
301
|
+
dict.set("Type", _primitives.Name.get("Page"));
|
302
|
+
expect((0, _primitives.isDict)(dict, "Page")).toEqual(true);
|
303
|
+
expect((0, _primitives.isDict)(dict, "Contents")).toEqual(false);
|
294
304
|
});
|
295
305
|
});
|
296
|
-
describe(
|
297
|
-
it(
|
306
|
+
describe("isRef", function () {
|
307
|
+
it("handles non-refs", function () {
|
298
308
|
var nonRef = {};
|
299
309
|
expect((0, _primitives.isRef)(nonRef)).toEqual(false);
|
300
310
|
});
|
301
|
-
it(
|
302
|
-
var ref =
|
311
|
+
it("handles refs", function () {
|
312
|
+
var ref = _primitives.Ref.get(1, 0);
|
313
|
+
|
303
314
|
expect((0, _primitives.isRef)(ref)).toEqual(true);
|
304
315
|
});
|
305
316
|
});
|
306
|
-
describe(
|
307
|
-
it(
|
308
|
-
var ref1 =
|
309
|
-
|
317
|
+
describe("isRefsEqual", function () {
|
318
|
+
it("should handle Refs pointing to the same object", function () {
|
319
|
+
var ref1 = _primitives.Ref.get(1, 0);
|
320
|
+
|
321
|
+
var ref2 = _primitives.Ref.get(1, 0);
|
322
|
+
|
310
323
|
expect((0, _primitives.isRefsEqual)(ref1, ref2)).toEqual(true);
|
311
324
|
});
|
312
|
-
it(
|
313
|
-
var ref1 =
|
314
|
-
|
325
|
+
it("should handle Refs pointing to different objects", function () {
|
326
|
+
var ref1 = _primitives.Ref.get(1, 0);
|
327
|
+
|
328
|
+
var ref2 = _primitives.Ref.get(2, 0);
|
329
|
+
|
315
330
|
expect((0, _primitives.isRefsEqual)(ref1, ref2)).toEqual(false);
|
316
331
|
});
|
317
332
|
});
|