pdfjs-dist 2.0.943 → 2.4.456
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 +8286 -14230
- 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 +25500 -26628
- package/build/pdf.worker.js.map +1 -1
- package/build/pdf.worker.min.js +22 -1
- package/es5/build/pdf.js +25473 -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 +57878 -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 +407 -0
- package/es5/web/pdf_viewer.js +7757 -0
- package/es5/web/pdf_viewer.js.map +1 -0
- package/image_decoders/pdf.image_decoders.js +2887 -4094
- 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 +855 -778
- package/lib/core/arithmetic_decoder.js +325 -311
- package/lib/core/bidi.js +117 -50
- package/lib/core/ccitt.js +251 -89
- package/lib/core/ccitt_stream.js +26 -16
- package/lib/core/cff_parser.js +525 -197
- package/lib/core/charsets.js +6 -5
- package/lib/core/chunked_stream.js +541 -406
- package/lib/core/cmap.js +368 -253
- package/lib/core/colorspace.js +781 -800
- package/lib/core/core_utils.js +152 -0
- package/lib/core/crypto.js +609 -422
- package/lib/core/document.js +649 -481
- package/lib/core/encodings.js +33 -24
- package/lib/core/evaluator.js +1471 -736
- package/lib/core/font_renderer.js +289 -149
- package/lib/core/fonts.js +1067 -413
- package/lib/core/function.js +517 -287
- package/lib/core/glyphlist.js +4529 -4527
- package/lib/core/image.js +232 -114
- package/lib/core/image_utils.js +94 -0
- package/lib/core/jbig2.js +711 -342
- package/lib/core/jbig2_stream.js +31 -19
- package/lib/core/jpeg_stream.js +151 -26
- package/lib/core/jpg.js +433 -181
- package/lib/core/jpx.js +551 -143
- package/lib/core/jpx_stream.js +40 -28
- package/lib/core/metrics.js +2931 -2931
- package/lib/core/murmurhash3.js +104 -97
- package/lib/core/obj.js +1561 -1053
- package/lib/core/operator_list.js +192 -64
- package/lib/core/parser.js +1162 -864
- package/lib/core/pattern.js +224 -75
- package/lib/core/pdf_manager.js +154 -285
- package/lib/core/primitives.js +145 -69
- package/lib/core/ps_parser.js +212 -162
- package/lib/core/standard_fonts.js +245 -244
- package/lib/core/stream.js +353 -81
- package/lib/core/type1_parser.js +218 -68
- package/lib/core/unicode.js +1682 -1655
- package/lib/core/worker.js +233 -302
- package/lib/core/worker_stream.js +168 -0
- package/lib/display/annotation_layer.js +808 -862
- package/lib/display/api.js +1778 -1462
- package/lib/display/api_compatibility.js +14 -9
- package/lib/display/canvas.js +463 -140
- package/lib/display/content_disposition.js +86 -58
- package/lib/display/display_utils.js +524 -0
- package/lib/display/fetch_stream.js +202 -274
- package/lib/display/font_loader.js +311 -333
- package/lib/display/metadata.js +98 -88
- package/lib/display/network.js +343 -347
- package/lib/display/network_utils.js +46 -26
- package/lib/display/node_stream.js +326 -404
- package/lib/display/pattern_helper.js +168 -69
- package/lib/display/svg.js +1296 -885
- package/lib/display/text_layer.js +229 -103
- package/lib/display/transport_stream.js +290 -250
- package/lib/display/webgl.js +116 -83
- package/lib/display/worker_options.js +6 -5
- package/lib/display/xml_parser.js +358 -337
- package/lib/examples/node/domstubs.js +95 -39
- package/lib/pdf.js +49 -31
- package/lib/pdf.worker.js +7 -5
- package/lib/shared/compatibility.js +3 -145
- package/lib/shared/is_node.js +8 -7
- package/lib/shared/message_handler.js +367 -314
- package/lib/shared/util.js +421 -415
- package/lib/test/unit/annotation_spec.js +1570 -690
- package/lib/test/unit/api_spec.js +855 -493
- package/lib/test/unit/bidi_spec.js +12 -12
- package/lib/test/unit/cff_parser_spec.js +88 -61
- package/lib/test/unit/clitests_helper.js +9 -12
- package/lib/test/unit/cmap_spec.js +140 -88
- package/lib/test/unit/colorspace_spec.js +204 -152
- package/lib/test/unit/core_utils_spec.js +211 -0
- package/lib/test/unit/crypto_spec.js +194 -182
- package/lib/test/unit/custom_spec.js +50 -64
- package/lib/test/unit/display_svg_spec.js +53 -38
- package/lib/test/unit/display_utils_spec.js +263 -0
- package/lib/test/unit/document_spec.js +17 -22
- package/lib/test/unit/encodings_spec.js +15 -57
- package/lib/test/unit/evaluator_spec.js +90 -83
- package/lib/test/unit/fetch_stream_spec.js +111 -0
- package/lib/test/unit/function_spec.js +219 -205
- package/lib/test/unit/jasmine-boot.js +68 -39
- package/lib/test/unit/message_handler_spec.js +187 -160
- package/lib/test/unit/metadata_spec.js +87 -34
- package/lib/test/unit/murmurhash3_spec.js +13 -13
- package/lib/test/unit/network_spec.js +26 -59
- package/lib/test/unit/network_utils_spec.js +187 -121
- package/lib/test/unit/node_stream_spec.js +98 -90
- package/lib/test/unit/parser_spec.js +173 -131
- package/lib/test/unit/pdf_find_controller_spec.js +148 -67
- package/lib/test/unit/pdf_find_utils_spec.js +35 -34
- package/lib/test/unit/pdf_history_spec.js +45 -33
- package/lib/test/unit/primitives_spec.js +161 -126
- package/lib/test/unit/stream_spec.js +22 -15
- package/lib/test/unit/test_utils.js +149 -98
- package/lib/test/unit/testreporter.js +36 -18
- package/lib/test/unit/type1_parser_spec.js +46 -44
- package/lib/test/unit/ui_utils_spec.js +388 -372
- package/lib/test/unit/unicode_spec.js +49 -46
- package/lib/test/unit/util_spec.js +144 -248
- package/lib/web/annotation_layer_builder.js +75 -95
- package/lib/web/app.js +1538 -1147
- package/lib/web/app_options.js +116 -104
- package/lib/web/base_viewer.js +950 -775
- package/lib/web/chromecom.js +217 -225
- package/lib/web/debugger.js +236 -148
- package/lib/web/download_manager.js +50 -50
- package/lib/web/firefox_print_service.js +51 -33
- package/lib/web/firefoxcom.js +225 -352
- package/lib/web/genericcom.js +30 -93
- package/lib/web/genericl10n.js +26 -143
- package/lib/web/grab_to_pan.js +57 -33
- package/lib/web/interfaces.js +105 -232
- package/lib/web/overlay_manager.js +73 -227
- package/lib/web/password_prompt.js +44 -62
- package/lib/web/pdf_attachment_viewer.js +118 -123
- package/lib/web/pdf_cursor_tools.js +89 -93
- package/lib/web/pdf_document_properties.js +242 -281
- package/lib/web/pdf_find_bar.js +157 -163
- package/lib/web/pdf_find_controller.js +598 -454
- package/lib/web/pdf_find_utils.js +32 -16
- package/lib/web/pdf_history.js +481 -355
- package/lib/web/pdf_link_service.js +355 -323
- package/lib/web/pdf_outline_viewer.js +167 -152
- package/lib/web/pdf_page_view.js +511 -457
- package/lib/web/pdf_presentation_mode.js +347 -335
- package/lib/web/pdf_print_service.js +133 -103
- package/lib/web/pdf_rendering_queue.js +98 -100
- package/lib/web/pdf_sidebar.js +323 -299
- package/lib/web/pdf_sidebar_resizer.js +107 -108
- package/lib/web/pdf_single_page_viewer.js +94 -146
- package/lib/web/pdf_thumbnail_view.js +319 -269
- package/lib/web/pdf_thumbnail_viewer.js +219 -199
- package/lib/web/pdf_viewer.component.js +111 -32
- package/lib/web/pdf_viewer.js +61 -101
- package/lib/web/preferences.js +87 -272
- package/lib/web/secondary_toolbar.js +207 -220
- package/lib/web/text_layer_builder.js +322 -322
- package/lib/web/toolbar.js +227 -180
- package/lib/web/ui_utils.js +476 -421
- package/lib/web/view_history.js +59 -208
- package/lib/web/viewer_compatibility.js +9 -6
- package/package.json +2 -9
- package/web/pdf_viewer.css +36 -22
- package/web/pdf_viewer.js +4407 -4516
- 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 -441
- package/lib/shared/streams_polyfill.js +0 -39
- package/lib/shared/url_polyfill.js +0 -50
- package/lib/test/unit/dom_utils_spec.js +0 -89
- package/lib/web/dom_events.js +0 -140
@@ -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.
|
@@ -19,114 +19,130 @@
|
|
19
19
|
* @licend The above is the entire license notice for the
|
20
20
|
* Javascript code in this page
|
21
21
|
*/
|
22
|
-
|
22
|
+
"use strict";
|
23
23
|
|
24
|
-
var _primitives = require(
|
24
|
+
var _primitives = require("../../core/primitives.js");
|
25
25
|
|
26
|
-
var _test_utils = require(
|
26
|
+
var _test_utils = require("./test_utils.js");
|
27
|
+
|
28
|
+
describe("primitives", function () {
|
29
|
+
describe("Name", function () {
|
30
|
+
it("should retain the given name", function () {
|
31
|
+
var givenName = "Font";
|
27
32
|
|
28
|
-
describe('primitives', function () {
|
29
|
-
describe('Name', function () {
|
30
|
-
it('should retain the given name', function () {
|
31
|
-
var givenName = 'Font';
|
32
33
|
var name = _primitives.Name.get(givenName);
|
34
|
+
|
33
35
|
expect(name.name).toEqual(givenName);
|
34
36
|
});
|
35
|
-
it(
|
36
|
-
var firstFont = _primitives.Name.get(
|
37
|
-
|
38
|
-
var
|
39
|
-
|
37
|
+
it("should create only one object for a name and cache it", function () {
|
38
|
+
var firstFont = _primitives.Name.get("Font");
|
39
|
+
|
40
|
+
var secondFont = _primitives.Name.get("Font");
|
41
|
+
|
42
|
+
var firstSubtype = _primitives.Name.get("Subtype");
|
43
|
+
|
44
|
+
var secondSubtype = _primitives.Name.get("Subtype");
|
45
|
+
|
40
46
|
expect(firstFont).toBe(secondFont);
|
41
47
|
expect(firstSubtype).toBe(secondSubtype);
|
42
48
|
expect(firstFont).not.toBe(firstSubtype);
|
43
49
|
});
|
44
50
|
});
|
45
|
-
describe(
|
46
|
-
it(
|
47
|
-
var givenCmd =
|
51
|
+
describe("Cmd", function () {
|
52
|
+
it("should retain the given cmd name", function () {
|
53
|
+
var givenCmd = "BT";
|
54
|
+
|
48
55
|
var cmd = _primitives.Cmd.get(givenCmd);
|
56
|
+
|
49
57
|
expect(cmd.cmd).toEqual(givenCmd);
|
50
58
|
});
|
51
|
-
it(
|
52
|
-
var firstBT = _primitives.Cmd.get(
|
53
|
-
|
54
|
-
var
|
55
|
-
|
59
|
+
it("should create only one object for a command and cache it", function () {
|
60
|
+
var firstBT = _primitives.Cmd.get("BT");
|
61
|
+
|
62
|
+
var secondBT = _primitives.Cmd.get("BT");
|
63
|
+
|
64
|
+
var firstET = _primitives.Cmd.get("ET");
|
65
|
+
|
66
|
+
var secondET = _primitives.Cmd.get("ET");
|
67
|
+
|
56
68
|
expect(firstBT).toBe(secondBT);
|
57
69
|
expect(firstET).toBe(secondET);
|
58
70
|
expect(firstBT).not.toBe(firstET);
|
59
71
|
});
|
60
72
|
});
|
61
|
-
describe(
|
62
|
-
var checkInvalidHasValues = function
|
73
|
+
describe("Dict", function () {
|
74
|
+
var checkInvalidHasValues = function (dict) {
|
63
75
|
expect(dict.has()).toBeFalsy();
|
64
|
-
expect(dict.has(
|
76
|
+
expect(dict.has("Prev")).toBeFalsy();
|
65
77
|
};
|
66
|
-
|
78
|
+
|
79
|
+
var checkInvalidKeyValues = function (dict) {
|
67
80
|
expect(dict.get()).toBeUndefined();
|
68
|
-
expect(dict.get(
|
69
|
-
expect(dict.get(
|
70
|
-
expect(dict.get(
|
81
|
+
expect(dict.get("Prev")).toBeUndefined();
|
82
|
+
expect(dict.get("Decode", "D")).toBeUndefined();
|
83
|
+
expect(dict.get("FontFile", "FontFile2", "FontFile3")).toBeUndefined();
|
71
84
|
};
|
85
|
+
|
72
86
|
var emptyDict, dictWithSizeKey, dictWithManyKeys;
|
73
87
|
var storedSize = 42;
|
74
|
-
var testFontFile =
|
75
|
-
var testFontFile2 =
|
76
|
-
var testFontFile3 =
|
88
|
+
var testFontFile = "file1";
|
89
|
+
var testFontFile2 = "file2";
|
90
|
+
var testFontFile3 = "file3";
|
77
91
|
beforeAll(function (done) {
|
78
92
|
emptyDict = new _primitives.Dict();
|
79
93
|
dictWithSizeKey = new _primitives.Dict();
|
80
|
-
dictWithSizeKey.set(
|
94
|
+
dictWithSizeKey.set("Size", storedSize);
|
81
95
|
dictWithManyKeys = new _primitives.Dict();
|
82
|
-
dictWithManyKeys.set(
|
83
|
-
dictWithManyKeys.set(
|
84
|
-
dictWithManyKeys.set(
|
96
|
+
dictWithManyKeys.set("FontFile", testFontFile);
|
97
|
+
dictWithManyKeys.set("FontFile2", testFontFile2);
|
98
|
+
dictWithManyKeys.set("FontFile3", testFontFile3);
|
85
99
|
done();
|
86
100
|
});
|
87
101
|
afterAll(function () {
|
88
102
|
emptyDict = dictWithSizeKey = dictWithManyKeys = null;
|
89
103
|
});
|
90
|
-
it(
|
104
|
+
it("should return invalid values for unknown keys", function () {
|
91
105
|
checkInvalidHasValues(emptyDict);
|
92
106
|
checkInvalidKeyValues(emptyDict);
|
93
107
|
});
|
94
|
-
it(
|
95
|
-
expect(dictWithSizeKey.has(
|
96
|
-
expect(dictWithSizeKey.get(
|
97
|
-
expect(dictWithSizeKey.get(
|
98
|
-
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);
|
99
113
|
});
|
100
|
-
it(
|
114
|
+
it("should return invalid values for unknown keys when Size key is stored", function () {
|
101
115
|
checkInvalidHasValues(dictWithSizeKey);
|
102
116
|
checkInvalidKeyValues(dictWithSizeKey);
|
103
117
|
});
|
104
|
-
it(
|
105
|
-
|
106
|
-
|
107
|
-
|
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();
|
108
124
|
checkInvalidKeyValues(dict);
|
109
125
|
});
|
110
|
-
it(
|
111
|
-
expect(dictWithManyKeys.has(
|
112
|
-
expect(dictWithManyKeys.has(
|
113
|
-
expect(dictWithManyKeys.has(
|
114
|
-
expect(dictWithManyKeys.get(
|
115
|
-
expect(dictWithManyKeys.get(
|
116
|
-
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);
|
117
133
|
});
|
118
|
-
it(
|
119
|
-
var keyPromises = [dictWithManyKeys.getAsync(
|
134
|
+
it("should asynchronously fetch unknown keys", function (done) {
|
135
|
+
var keyPromises = [dictWithManyKeys.getAsync("Size"), dictWithSizeKey.getAsync("FontFile", "FontFile2", "FontFile3")];
|
120
136
|
Promise.all(keyPromises).then(function (values) {
|
121
137
|
expect(values[0]).toBeUndefined();
|
122
|
-
expect(values[1]).
|
138
|
+
expect(values[1]).toBeUndefined();
|
123
139
|
done();
|
124
140
|
}).catch(function (reason) {
|
125
141
|
done.fail(reason);
|
126
142
|
});
|
127
143
|
});
|
128
|
-
it(
|
129
|
-
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")];
|
130
146
|
Promise.all(keyPromises).then(function (values) {
|
131
147
|
expect(values[0]).toEqual(testFontFile3);
|
132
148
|
expect(values[1]).toEqual(testFontFile2);
|
@@ -136,36 +152,38 @@ describe('primitives', function () {
|
|
136
152
|
done.fail(reason);
|
137
153
|
});
|
138
154
|
});
|
139
|
-
it(
|
140
|
-
var callbackSpy = jasmine.createSpy(
|
155
|
+
it("should callback for each stored key", function () {
|
156
|
+
var callbackSpy = jasmine.createSpy("spy on callback in dictionary");
|
141
157
|
dictWithManyKeys.forEach(callbackSpy);
|
142
158
|
expect(callbackSpy).toHaveBeenCalled();
|
143
159
|
var callbackSpyCalls = callbackSpy.calls;
|
144
|
-
expect(callbackSpyCalls.argsFor(0)).toEqual([
|
145
|
-
expect(callbackSpyCalls.argsFor(1)).toEqual([
|
146
|
-
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]);
|
147
163
|
expect(callbackSpyCalls.count()).toEqual(3);
|
148
164
|
});
|
149
|
-
it(
|
150
|
-
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
|
+
|
151
168
|
var xref = new _test_utils.XRefMock([{
|
152
169
|
ref: fontRef,
|
153
170
|
data: testFontFile
|
154
171
|
}]);
|
155
172
|
var fontDict = new _primitives.Dict(xref);
|
156
|
-
fontDict.set(
|
157
|
-
expect(fontDict.getRaw(
|
158
|
-
expect(fontDict.get(
|
159
|
-
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) {
|
160
177
|
expect(value).toEqual(testFontFile);
|
161
178
|
done();
|
162
179
|
}).catch(function (reason) {
|
163
180
|
done.fail(reason);
|
164
181
|
});
|
165
182
|
});
|
166
|
-
it(
|
167
|
-
var minCoordRef =
|
168
|
-
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
|
+
|
169
187
|
var minCoord = 0,
|
170
188
|
maxCoord = 1;
|
171
189
|
var xref = new _test_utils.XRefMock([{
|
@@ -176,122 +194,139 @@ describe('primitives', function () {
|
|
176
194
|
data: maxCoord
|
177
195
|
}]);
|
178
196
|
var xObjectDict = new _primitives.Dict(xref);
|
179
|
-
xObjectDict.set(
|
180
|
-
expect(xObjectDict.get(
|
181
|
-
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]);
|
182
200
|
});
|
183
|
-
it(
|
184
|
-
var expectedKeys = [
|
201
|
+
it("should get all key names", function () {
|
202
|
+
var expectedKeys = ["FontFile", "FontFile2", "FontFile3"];
|
185
203
|
var keys = dictWithManyKeys.getKeys();
|
186
204
|
expect(keys.sort()).toEqual(expectedKeys);
|
187
205
|
});
|
188
|
-
it(
|
206
|
+
it("should create only one object for Dict.empty", function () {
|
189
207
|
var firstDictEmpty = _primitives.Dict.empty;
|
190
208
|
var secondDictEmpty = _primitives.Dict.empty;
|
191
209
|
expect(firstDictEmpty).toBe(secondDictEmpty);
|
192
210
|
expect(firstDictEmpty).not.toBe(emptyDict);
|
193
211
|
});
|
194
|
-
it(
|
195
|
-
var expectedKeys = [
|
212
|
+
it("should correctly merge dictionaries", function () {
|
213
|
+
var expectedKeys = ["FontFile", "FontFile2", "FontFile3", "Size"];
|
196
214
|
var fontFileDict = new _primitives.Dict();
|
197
|
-
fontFileDict.set(
|
215
|
+
fontFileDict.set("FontFile", "Type1 font file");
|
216
|
+
|
198
217
|
var mergedDict = _primitives.Dict.merge(null, [dictWithManyKeys, dictWithSizeKey, fontFileDict]);
|
218
|
+
|
199
219
|
var mergedKeys = mergedDict.getKeys();
|
200
220
|
expect(mergedKeys.sort()).toEqual(expectedKeys);
|
201
|
-
expect(mergedDict.get(
|
221
|
+
expect(mergedDict.get("FontFile")).toEqual(testFontFile);
|
202
222
|
});
|
203
223
|
});
|
204
|
-
describe(
|
205
|
-
it(
|
224
|
+
describe("Ref", function () {
|
225
|
+
it("should retain the stored values", function () {
|
206
226
|
var storedNum = 4;
|
207
227
|
var storedGen = 2;
|
208
|
-
|
228
|
+
|
229
|
+
var ref = _primitives.Ref.get(storedNum, storedGen);
|
230
|
+
|
209
231
|
expect(ref.num).toEqual(storedNum);
|
210
232
|
expect(ref.gen).toEqual(storedGen);
|
211
233
|
});
|
212
234
|
});
|
213
|
-
describe(
|
214
|
-
it(
|
215
|
-
var ref =
|
235
|
+
describe("RefSet", function () {
|
236
|
+
it("should have a stored value", function () {
|
237
|
+
var ref = _primitives.Ref.get(4, 2);
|
238
|
+
|
216
239
|
var refset = new _primitives.RefSet();
|
217
240
|
refset.put(ref);
|
218
241
|
expect(refset.has(ref)).toBeTruthy();
|
219
242
|
});
|
220
|
-
it(
|
221
|
-
var ref =
|
243
|
+
it("should not have an unknown value", function () {
|
244
|
+
var ref = _primitives.Ref.get(4, 2);
|
245
|
+
|
222
246
|
var refset = new _primitives.RefSet();
|
223
247
|
expect(refset.has(ref)).toBeFalsy();
|
224
248
|
refset.put(ref);
|
225
|
-
|
249
|
+
|
250
|
+
var anotherRef = _primitives.Ref.get(2, 4);
|
251
|
+
|
226
252
|
expect(refset.has(anotherRef)).toBeFalsy();
|
227
253
|
});
|
228
254
|
});
|
229
|
-
describe(
|
230
|
-
it(
|
255
|
+
describe("isName", function () {
|
256
|
+
it("handles non-names", function () {
|
231
257
|
var nonName = {};
|
232
258
|
expect((0, _primitives.isName)(nonName)).toEqual(false);
|
233
259
|
});
|
234
|
-
it(
|
235
|
-
var name = _primitives.Name.get(
|
260
|
+
it("handles names", function () {
|
261
|
+
var name = _primitives.Name.get("Font");
|
262
|
+
|
236
263
|
expect((0, _primitives.isName)(name)).toEqual(true);
|
237
264
|
});
|
238
|
-
it(
|
239
|
-
var name = _primitives.Name.get(
|
240
|
-
|
241
|
-
expect((0, _primitives.isName)(name,
|
265
|
+
it("handles names with name check", function () {
|
266
|
+
var name = _primitives.Name.get("Font");
|
267
|
+
|
268
|
+
expect((0, _primitives.isName)(name, "Font")).toEqual(true);
|
269
|
+
expect((0, _primitives.isName)(name, "Subtype")).toEqual(false);
|
242
270
|
});
|
243
271
|
});
|
244
|
-
describe(
|
245
|
-
it(
|
272
|
+
describe("isCmd", function () {
|
273
|
+
it("handles non-commands", function () {
|
246
274
|
var nonCmd = {};
|
247
275
|
expect((0, _primitives.isCmd)(nonCmd)).toEqual(false);
|
248
276
|
});
|
249
|
-
it(
|
250
|
-
var cmd = _primitives.Cmd.get(
|
277
|
+
it("handles commands", function () {
|
278
|
+
var cmd = _primitives.Cmd.get("BT");
|
279
|
+
|
251
280
|
expect((0, _primitives.isCmd)(cmd)).toEqual(true);
|
252
281
|
});
|
253
|
-
it(
|
254
|
-
var cmd = _primitives.Cmd.get(
|
255
|
-
|
256
|
-
expect((0, _primitives.isCmd)(cmd,
|
282
|
+
it("handles commands with cmd check", function () {
|
283
|
+
var cmd = _primitives.Cmd.get("BT");
|
284
|
+
|
285
|
+
expect((0, _primitives.isCmd)(cmd, "BT")).toEqual(true);
|
286
|
+
expect((0, _primitives.isCmd)(cmd, "ET")).toEqual(false);
|
257
287
|
});
|
258
288
|
});
|
259
|
-
describe(
|
260
|
-
it(
|
289
|
+
describe("isDict", function () {
|
290
|
+
it("handles non-dictionaries", function () {
|
261
291
|
var nonDict = {};
|
262
292
|
expect((0, _primitives.isDict)(nonDict)).toEqual(false);
|
263
293
|
});
|
264
|
-
it(
|
294
|
+
it("handles empty dictionaries with type check", function () {
|
265
295
|
var dict = _primitives.Dict.empty;
|
266
296
|
expect((0, _primitives.isDict)(dict)).toEqual(true);
|
267
|
-
expect((0, _primitives.isDict)(dict,
|
297
|
+
expect((0, _primitives.isDict)(dict, "Page")).toEqual(false);
|
268
298
|
});
|
269
|
-
it(
|
299
|
+
it("handles dictionaries with type check", function () {
|
270
300
|
var dict = new _primitives.Dict();
|
271
|
-
dict.set(
|
272
|
-
expect((0, _primitives.isDict)(dict,
|
273
|
-
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);
|
274
304
|
});
|
275
305
|
});
|
276
|
-
describe(
|
277
|
-
it(
|
306
|
+
describe("isRef", function () {
|
307
|
+
it("handles non-refs", function () {
|
278
308
|
var nonRef = {};
|
279
309
|
expect((0, _primitives.isRef)(nonRef)).toEqual(false);
|
280
310
|
});
|
281
|
-
it(
|
282
|
-
var ref =
|
311
|
+
it("handles refs", function () {
|
312
|
+
var ref = _primitives.Ref.get(1, 0);
|
313
|
+
|
283
314
|
expect((0, _primitives.isRef)(ref)).toEqual(true);
|
284
315
|
});
|
285
316
|
});
|
286
|
-
describe(
|
287
|
-
it(
|
288
|
-
var ref1 =
|
289
|
-
|
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
|
+
|
290
323
|
expect((0, _primitives.isRefsEqual)(ref1, ref2)).toEqual(true);
|
291
324
|
});
|
292
|
-
it(
|
293
|
-
var ref1 =
|
294
|
-
|
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
|
+
|
295
330
|
expect((0, _primitives.isRefsEqual)(ref1, ref2)).toEqual(false);
|
296
331
|
});
|
297
332
|
});
|
@@ -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.
|
@@ -19,52 +19,59 @@
|
|
19
19
|
* @licend The above is the entire license notice for the
|
20
20
|
* Javascript code in this page
|
21
21
|
*/
|
22
|
-
|
22
|
+
"use strict";
|
23
23
|
|
24
|
-
var _stream = require(
|
24
|
+
var _stream = require("../../core/stream.js");
|
25
25
|
|
26
|
-
var _primitives = require(
|
26
|
+
var _primitives = require("../../core/primitives.js");
|
27
27
|
|
28
|
-
describe(
|
28
|
+
describe("stream", function () {
|
29
29
|
beforeEach(function () {
|
30
30
|
jasmine.addMatchers({
|
31
|
-
toMatchTypedArray
|
31
|
+
toMatchTypedArray(util, customEqualityTesters) {
|
32
32
|
return {
|
33
|
-
compare
|
33
|
+
compare(actual, expected) {
|
34
34
|
var result = {};
|
35
|
+
|
35
36
|
if (actual.length !== expected.length) {
|
36
37
|
result.pass = false;
|
37
|
-
result.message =
|
38
|
+
result.message = "Array length: " + actual.length + ", expected: " + expected.length;
|
38
39
|
return result;
|
39
40
|
}
|
41
|
+
|
40
42
|
result.pass = true;
|
43
|
+
|
41
44
|
for (var i = 0, ii = expected.length; i < ii; i++) {
|
42
45
|
var a = actual[i],
|
43
46
|
b = expected[i];
|
47
|
+
|
44
48
|
if (a !== b) {
|
45
49
|
result.pass = false;
|
46
50
|
break;
|
47
51
|
}
|
48
52
|
}
|
53
|
+
|
49
54
|
return result;
|
50
55
|
}
|
56
|
+
|
51
57
|
};
|
52
58
|
}
|
59
|
+
|
53
60
|
});
|
54
61
|
});
|
55
|
-
describe(
|
56
|
-
it(
|
62
|
+
describe("PredictorStream", function () {
|
63
|
+
it("should decode simple predictor data", function () {
|
57
64
|
var dict = new _primitives.Dict();
|
58
|
-
dict.set(
|
59
|
-
dict.set(
|
60
|
-
dict.set(
|
61
|
-
dict.set(
|
65
|
+
dict.set("Predictor", 12);
|
66
|
+
dict.set("Colors", 1);
|
67
|
+
dict.set("BitsPerComponent", 8);
|
68
|
+
dict.set("Columns", 2);
|
62
69
|
var input = new _stream.Stream(new Uint8Array([2, 100, 3, 2, 1, 255, 2, 1, 255]), 0, 9, dict);
|
63
70
|
var predictor = new _stream.PredictorStream(input, 9, dict);
|
64
71
|
var result = predictor.getBytes(6);
|
65
72
|
expect(result).toMatchTypedArray(new Uint8Array([100, 3, 101, 2, 102, 1]));
|
66
73
|
predictor.reset();
|
67
|
-
|
74
|
+
const clampedResult = predictor.getBytes(6, true);
|
68
75
|
expect(clampedResult).toEqual(new Uint8ClampedArray([100, 3, 101, 2, 102, 1]));
|
69
76
|
});
|
70
77
|
});
|