pdfjs-dist 2.0.487 → 2.1.266

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of pdfjs-dist might be problematic. Click here for more details.

Files changed (161) hide show
  1. package/bower.json +1 -1
  2. package/build/pdf.js +15564 -9476
  3. package/build/pdf.js.map +1 -1
  4. package/build/pdf.min.js +1 -1
  5. package/build/pdf.worker.js +46644 -36309
  6. package/build/pdf.worker.js.map +1 -1
  7. package/build/pdf.worker.min.js +1 -1
  8. package/external/url/url-lib.js +627 -0
  9. package/image_decoders/pdf.image_decoders.js +11430 -0
  10. package/image_decoders/pdf.image_decoders.js.map +1 -0
  11. package/image_decoders/pdf.image_decoders.min.js +1 -0
  12. package/lib/core/annotation.js +406 -131
  13. package/lib/core/arithmetic_decoder.js +275 -245
  14. package/lib/core/bidi.js +65 -6
  15. package/lib/core/ccitt.js +173 -18
  16. package/lib/core/ccitt_stream.js +15 -6
  17. package/lib/core/cff_parser.js +376 -53
  18. package/lib/core/charsets.js +5 -4
  19. package/lib/core/chunked_stream.js +387 -149
  20. package/lib/core/cmap.js +310 -75
  21. package/lib/core/colorspace.js +874 -594
  22. package/lib/core/crypto.js +290 -45
  23. package/lib/core/document.js +545 -260
  24. package/lib/core/encodings.js +19 -10
  25. package/lib/core/evaluator.js +725 -147
  26. package/lib/core/font_renderer.js +360 -91
  27. package/lib/core/fonts.js +791 -186
  28. package/lib/core/function.js +284 -71
  29. package/lib/core/glyphlist.js +3 -2
  30. package/lib/core/image.js +168 -61
  31. package/lib/core/jbig2.js +479 -66
  32. package/lib/core/jbig2_stream.js +19 -8
  33. package/lib/core/jpeg_stream.js +38 -13
  34. package/lib/core/jpg.js +252 -29
  35. package/lib/core/jpx.js +396 -6
  36. package/lib/core/jpx_stream.js +18 -6
  37. package/lib/core/metrics.js +4 -4
  38. package/lib/core/murmurhash3.js +24 -6
  39. package/lib/core/obj.js +1137 -475
  40. package/lib/core/operator_list.js +108 -6
  41. package/lib/core/parser.js +321 -68
  42. package/lib/core/pattern.js +145 -13
  43. package/lib/core/pdf_manager.js +321 -133
  44. package/lib/core/primitives.js +75 -22
  45. package/lib/core/ps_parser.js +134 -45
  46. package/lib/core/standard_fonts.js +10 -10
  47. package/lib/core/stream.js +313 -34
  48. package/lib/core/type1_parser.js +143 -13
  49. package/lib/core/unicode.js +31 -4
  50. package/lib/core/worker.js +210 -66
  51. package/lib/display/annotation_layer.js +361 -123
  52. package/lib/display/api.js +1454 -729
  53. package/lib/display/api_compatibility.js +11 -13
  54. package/lib/display/canvas.js +324 -29
  55. package/lib/display/content_disposition.js +83 -32
  56. package/lib/display/dom_utils.js +226 -41
  57. package/lib/display/fetch_stream.js +208 -84
  58. package/lib/display/font_loader.js +465 -236
  59. package/lib/display/metadata.js +38 -16
  60. package/lib/display/network.js +216 -51
  61. package/lib/display/network_utils.js +32 -19
  62. package/lib/display/node_stream.js +352 -169
  63. package/lib/display/pattern_helper.js +58 -7
  64. package/lib/display/svg.js +242 -29
  65. package/lib/display/text_layer.js +132 -18
  66. package/lib/display/transport_stream.js +171 -42
  67. package/lib/display/webgl.js +64 -18
  68. package/lib/display/worker_options.js +5 -4
  69. package/lib/display/xml_parser.js +166 -53
  70. package/lib/examples/node/domstubs.js +57 -4
  71. package/lib/pdf.js +21 -4
  72. package/lib/pdf.worker.js +5 -3
  73. package/lib/shared/compatibility.js +158 -564
  74. package/lib/shared/global_scope.js +2 -2
  75. package/lib/shared/is_node.js +4 -4
  76. package/lib/shared/message_handler.js +521 -0
  77. package/lib/shared/streams_polyfill.js +21 -17
  78. package/lib/shared/url_polyfill.js +56 -0
  79. package/lib/shared/util.js +295 -650
  80. package/lib/test/unit/annotation_spec.js +629 -345
  81. package/lib/test/unit/api_spec.js +555 -253
  82. package/lib/test/unit/bidi_spec.js +7 -7
  83. package/lib/test/unit/cff_parser_spec.js +40 -11
  84. package/lib/test/unit/clitests_helper.js +9 -7
  85. package/lib/test/unit/cmap_spec.js +80 -26
  86. package/lib/test/unit/colorspace_spec.js +99 -52
  87. package/lib/test/unit/crypto_spec.js +17 -5
  88. package/lib/test/unit/custom_spec.js +41 -53
  89. package/lib/test/unit/display_svg_spec.js +33 -17
  90. package/lib/test/unit/document_spec.js +3 -3
  91. package/lib/test/unit/dom_utils_spec.js +9 -9
  92. package/lib/test/unit/encodings_spec.js +25 -45
  93. package/lib/test/unit/evaluator_spec.js +34 -9
  94. package/lib/test/unit/function_spec.js +17 -5
  95. package/lib/test/unit/jasmine-boot.js +31 -18
  96. package/lib/test/unit/{util_stream_spec.js → message_handler_spec.js} +41 -69
  97. package/lib/test/unit/metadata_spec.js +71 -11
  98. package/lib/test/unit/murmurhash3_spec.js +3 -3
  99. package/lib/test/unit/network_spec.js +20 -5
  100. package/lib/test/unit/network_utils_spec.js +41 -14
  101. package/lib/test/unit/node_stream_spec.js +51 -27
  102. package/lib/test/unit/parser_spec.js +35 -8
  103. package/lib/test/unit/pdf_find_controller_spec.js +230 -0
  104. package/lib/test/unit/pdf_find_utils_spec.js +63 -0
  105. package/lib/test/unit/pdf_history_spec.js +21 -9
  106. package/lib/test/unit/primitives_spec.js +24 -4
  107. package/lib/test/unit/stream_spec.js +12 -4
  108. package/lib/test/unit/test_utils.js +90 -27
  109. package/lib/test/unit/testreporter.js +21 -3
  110. package/lib/test/unit/type1_parser_spec.js +8 -6
  111. package/lib/test/unit/ui_utils_spec.js +452 -14
  112. package/lib/test/unit/unicode_spec.js +14 -11
  113. package/lib/test/unit/util_spec.js +131 -9
  114. package/lib/web/annotation_layer_builder.js +39 -22
  115. package/lib/web/app.js +1240 -582
  116. package/lib/web/app_options.js +71 -41
  117. package/lib/web/base_viewer.js +508 -179
  118. package/lib/web/chromecom.js +261 -117
  119. package/lib/web/debugger.js +166 -22
  120. package/lib/web/download_manager.js +31 -13
  121. package/lib/web/firefox_print_service.js +17 -9
  122. package/lib/web/firefoxcom.js +283 -79
  123. package/lib/web/genericcom.js +89 -30
  124. package/lib/web/genericl10n.js +142 -30
  125. package/lib/web/grab_to_pan.js +26 -4
  126. package/lib/web/interfaces.js +170 -47
  127. package/lib/web/overlay_manager.js +235 -85
  128. package/lib/web/password_prompt.js +21 -13
  129. package/lib/web/pdf_attachment_viewer.js +38 -18
  130. package/lib/web/pdf_cursor_tools.js +39 -16
  131. package/lib/web/pdf_document_properties.js +80 -30
  132. package/lib/web/pdf_find_bar.js +84 -40
  133. package/lib/web/pdf_find_controller.js +495 -184
  134. package/lib/web/pdf_find_utils.js +111 -0
  135. package/lib/web/pdf_history.js +190 -53
  136. package/lib/web/pdf_link_service.js +137 -76
  137. package/lib/web/pdf_outline_viewer.js +73 -22
  138. package/lib/web/pdf_page_view.js +196 -63
  139. package/lib/web/pdf_presentation_mode.js +99 -34
  140. package/lib/web/pdf_print_service.js +57 -11
  141. package/lib/web/pdf_rendering_queue.js +27 -5
  142. package/lib/web/pdf_sidebar.js +120 -67
  143. package/lib/web/pdf_sidebar_resizer.js +42 -16
  144. package/lib/web/pdf_single_page_viewer.js +74 -66
  145. package/lib/web/pdf_thumbnail_view.js +103 -32
  146. package/lib/web/pdf_thumbnail_viewer.js +64 -24
  147. package/lib/web/pdf_viewer.component.js +112 -32
  148. package/lib/web/pdf_viewer.js +91 -52
  149. package/lib/web/preferences.js +275 -80
  150. package/lib/web/secondary_toolbar.js +165 -40
  151. package/lib/web/text_layer_builder.js +162 -65
  152. package/lib/web/toolbar.js +78 -43
  153. package/lib/web/ui_utils.js +462 -136
  154. package/lib/web/view_history.js +215 -67
  155. package/lib/web/viewer_compatibility.js +4 -13
  156. package/package.json +5 -4
  157. package/web/pdf_viewer.css +58 -1
  158. package/web/pdf_viewer.js +6346 -3919
  159. package/web/pdf_viewer.js.map +1 -1
  160. package/lib/test/unit/fonts_spec.js +0 -81
  161. package/lib/web/dom_events.js +0 -137
@@ -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 2017 Mozilla Foundation
5
+ * Copyright 2018 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,17 +19,17 @@
19
19
  * @licend The above is the entire license notice for the
20
20
  * Javascript code in this page
21
21
  */
22
- 'use strict';
22
+ "use strict";
23
23
 
24
- var _primitives = require('../../core/primitives');
24
+ var _primitives = require("../../core/primitives");
25
25
 
26
- var _stream = require('../../core/stream');
26
+ var _stream = require("../../core/stream");
27
27
 
28
- var _colorspace = require('../../core/colorspace');
28
+ var _colorspace = require("../../core/colorspace");
29
29
 
30
- var _function = require('../../core/function');
30
+ var _function = require("../../core/function");
31
31
 
32
- var _test_utils = require('./test_utils');
32
+ var _test_utils = require("./test_utils");
33
33
 
34
34
  describe('colorspace', function () {
35
35
  describe('ColorSpace', function () {
@@ -53,18 +53,23 @@ describe('colorspace', function () {
53
53
  describe('DeviceGrayCS', function () {
54
54
  it('should handle the case when cs is a Name object', function () {
55
55
  var cs = _primitives.Name.get('DeviceGray');
56
+
56
57
  var xref = new _test_utils.XRefMock([{
57
58
  ref: new _primitives.Ref(10, 0),
58
59
  data: new _primitives.Dict()
59
60
  }]);
60
61
  var res = new _primitives.Dict();
61
- var pdfFunctionFactory = new _function.PDFFunctionFactory({ xref: xref });
62
+ var pdfFunctionFactory = new _function.PDFFunctionFactory({
63
+ xref: xref
64
+ });
65
+
62
66
  var colorSpace = _colorspace.ColorSpace.parse(cs, xref, res, pdfFunctionFactory);
67
+
63
68
  var testSrc = new Uint8Array([27, 125, 250, 131]);
64
- var testDest = new Uint8Array(4 * 4 * 3);
65
- var expectedDest = new Uint8Array([27, 27, 27, 27, 27, 27, 125, 125, 125, 125, 125, 125, 27, 27, 27, 27, 27, 27, 125, 125, 125, 125, 125, 125, 250, 250, 250, 250, 250, 250, 131, 131, 131, 131, 131, 131, 250, 250, 250, 250, 250, 250, 131, 131, 131, 131, 131, 131]);
69
+ var testDest = new Uint8ClampedArray(4 * 4 * 3);
70
+ var expectedDest = new Uint8ClampedArray([27, 27, 27, 27, 27, 27, 125, 125, 125, 125, 125, 125, 27, 27, 27, 27, 27, 27, 125, 125, 125, 125, 125, 125, 250, 250, 250, 250, 250, 250, 131, 131, 131, 131, 131, 131, 250, 250, 250, 250, 250, 250, 131, 131, 131, 131, 131, 131]);
66
71
  colorSpace.fillRgb(testDest, 2, 2, 4, 4, 4, 8, testSrc, 0);
67
- expect(colorSpace.getRgb(new Float32Array([0.1]), 0)).toEqual(new Uint8Array([25, 25, 25]));
72
+ expect(colorSpace.getRgb(new Float32Array([0.1]), 0)).toEqual(new Uint8ClampedArray([26, 26, 26]));
68
73
  expect(colorSpace.getOutputLength(2, 0)).toEqual(6);
69
74
  expect(colorSpace.isPassthrough(8)).toBeFalsy();
70
75
  expect(testDest).toEqual(expectedDest);
@@ -76,13 +81,17 @@ describe('colorspace', function () {
76
81
  data: _primitives.Name.get('DeviceGray')
77
82
  }]);
78
83
  var res = new _primitives.Dict();
79
- var pdfFunctionFactory = new _function.PDFFunctionFactory({ xref: xref });
84
+ var pdfFunctionFactory = new _function.PDFFunctionFactory({
85
+ xref: xref
86
+ });
87
+
80
88
  var colorSpace = _colorspace.ColorSpace.parse(cs, xref, res, pdfFunctionFactory);
89
+
81
90
  var testSrc = new Uint8Array([27, 125, 250, 131]);
82
- var testDest = new Uint8Array(3 * 3 * 3);
83
- var expectedDest = new Uint8Array([27, 27, 27, 27, 27, 27, 125, 125, 125, 27, 27, 27, 27, 27, 27, 125, 125, 125, 250, 250, 250, 250, 250, 250, 131, 131, 131]);
91
+ var testDest = new Uint8ClampedArray(3 * 3 * 3);
92
+ var expectedDest = new Uint8ClampedArray([27, 27, 27, 27, 27, 27, 125, 125, 125, 27, 27, 27, 27, 27, 27, 125, 125, 125, 250, 250, 250, 250, 250, 250, 131, 131, 131]);
84
93
  colorSpace.fillRgb(testDest, 2, 2, 3, 3, 3, 8, testSrc, 0);
85
- expect(colorSpace.getRgb(new Float32Array([0.2]), 0)).toEqual(new Uint8Array([51, 51, 51]));
94
+ expect(colorSpace.getRgb(new Float32Array([0.2]), 0)).toEqual(new Uint8ClampedArray([51, 51, 51]));
86
95
  expect(colorSpace.getOutputLength(3, 1)).toEqual(12);
87
96
  expect(colorSpace.isPassthrough(8)).toBeFalsy();
88
97
  expect(testDest).toEqual(expectedDest);
@@ -91,18 +100,23 @@ describe('colorspace', function () {
91
100
  describe('DeviceRgbCS', function () {
92
101
  it('should handle the case when cs is a Name object', function () {
93
102
  var cs = _primitives.Name.get('DeviceRGB');
103
+
94
104
  var xref = new _test_utils.XRefMock([{
95
105
  ref: new _primitives.Ref(10, 0),
96
106
  data: new _primitives.Dict()
97
107
  }]);
98
108
  var res = new _primitives.Dict();
99
- var pdfFunctionFactory = new _function.PDFFunctionFactory({ xref: xref });
109
+ var pdfFunctionFactory = new _function.PDFFunctionFactory({
110
+ xref: xref
111
+ });
112
+
100
113
  var colorSpace = _colorspace.ColorSpace.parse(cs, xref, res, pdfFunctionFactory);
114
+
101
115
  var testSrc = new Uint8Array([27, 125, 250, 131, 139, 140, 111, 25, 198, 21, 147, 255]);
102
- var testDest = new Uint8Array(4 * 4 * 3);
103
- var expectedDest = new Uint8Array([27, 125, 250, 27, 125, 250, 131, 139, 140, 131, 139, 140, 27, 125, 250, 27, 125, 250, 131, 139, 140, 131, 139, 140, 111, 25, 198, 111, 25, 198, 21, 147, 255, 21, 147, 255, 111, 25, 198, 111, 25, 198, 21, 147, 255, 21, 147, 255]);
116
+ var testDest = new Uint8ClampedArray(4 * 4 * 3);
117
+ var expectedDest = new Uint8ClampedArray([27, 125, 250, 27, 125, 250, 131, 139, 140, 131, 139, 140, 27, 125, 250, 27, 125, 250, 131, 139, 140, 131, 139, 140, 111, 25, 198, 111, 25, 198, 21, 147, 255, 21, 147, 255, 111, 25, 198, 111, 25, 198, 21, 147, 255, 21, 147, 255]);
104
118
  colorSpace.fillRgb(testDest, 2, 2, 4, 4, 4, 8, testSrc, 0);
105
- expect(colorSpace.getRgb(new Float32Array([0.1, 0.2, 0.3]), 0)).toEqual(new Uint8Array([25, 51, 76]));
119
+ expect(colorSpace.getRgb(new Float32Array([0.1, 0.2, 0.3]), 0)).toEqual(new Uint8ClampedArray([26, 51, 77]));
106
120
  expect(colorSpace.getOutputLength(4, 0)).toEqual(4);
107
121
  expect(colorSpace.isPassthrough(8)).toBeTruthy();
108
122
  expect(testDest).toEqual(expectedDest);
@@ -114,13 +128,17 @@ describe('colorspace', function () {
114
128
  data: _primitives.Name.get('DeviceRGB')
115
129
  }]);
116
130
  var res = new _primitives.Dict();
117
- var pdfFunctionFactory = new _function.PDFFunctionFactory({ xref: xref });
131
+ var pdfFunctionFactory = new _function.PDFFunctionFactory({
132
+ xref: xref
133
+ });
134
+
118
135
  var colorSpace = _colorspace.ColorSpace.parse(cs, xref, res, pdfFunctionFactory);
136
+
119
137
  var testSrc = new Uint8Array([27, 125, 250, 131, 139, 140, 111, 25, 198, 21, 147, 255]);
120
- var testDest = new Uint8Array(3 * 3 * 3);
121
- var expectedDest = new Uint8Array([27, 125, 250, 27, 125, 250, 131, 139, 140, 27, 125, 250, 27, 125, 250, 131, 139, 140, 111, 25, 198, 111, 25, 198, 21, 147, 255]);
138
+ var testDest = new Uint8ClampedArray(3 * 3 * 3);
139
+ var expectedDest = new Uint8ClampedArray([27, 125, 250, 27, 125, 250, 131, 139, 140, 27, 125, 250, 27, 125, 250, 131, 139, 140, 111, 25, 198, 111, 25, 198, 21, 147, 255]);
122
140
  colorSpace.fillRgb(testDest, 2, 2, 3, 3, 3, 8, testSrc, 0);
123
- expect(colorSpace.getRgb(new Float32Array([0.1, 0.2, 0.3]), 0)).toEqual(new Uint8Array([25, 51, 76]));
141
+ expect(colorSpace.getRgb(new Float32Array([0.1, 0.2, 0.3]), 0)).toEqual(new Uint8ClampedArray([26, 51, 77]));
124
142
  expect(colorSpace.getOutputLength(4, 1)).toEqual(5);
125
143
  expect(colorSpace.isPassthrough(8)).toBeTruthy();
126
144
  expect(testDest).toEqual(expectedDest);
@@ -129,18 +147,23 @@ describe('colorspace', function () {
129
147
  describe('DeviceCmykCS', function () {
130
148
  it('should handle the case when cs is a Name object', function () {
131
149
  var cs = _primitives.Name.get('DeviceCMYK');
150
+
132
151
  var xref = new _test_utils.XRefMock([{
133
152
  ref: new _primitives.Ref(10, 0),
134
153
  data: new _primitives.Dict()
135
154
  }]);
136
155
  var res = new _primitives.Dict();
137
- var pdfFunctionFactory = new _function.PDFFunctionFactory({ xref: xref });
156
+ var pdfFunctionFactory = new _function.PDFFunctionFactory({
157
+ xref: xref
158
+ });
159
+
138
160
  var colorSpace = _colorspace.ColorSpace.parse(cs, xref, res, pdfFunctionFactory);
161
+
139
162
  var testSrc = new Uint8Array([27, 125, 250, 128, 131, 139, 140, 45, 111, 25, 198, 78, 21, 147, 255, 69]);
140
- var testDest = new Uint8Array(4 * 4 * 3);
141
- var expectedDest = new Uint8Array([135, 80, 18, 135, 80, 18, 113, 102, 97, 113, 102, 97, 135, 80, 18, 135, 80, 18, 113, 102, 97, 113, 102, 97, 112, 143, 75, 112, 143, 75, 188, 98, 27, 188, 98, 27, 112, 143, 75, 112, 143, 75, 188, 98, 27, 188, 98, 27]);
163
+ var testDest = new Uint8ClampedArray(4 * 4 * 3);
164
+ var expectedDest = new Uint8ClampedArray([135, 81, 18, 135, 81, 18, 114, 102, 97, 114, 102, 97, 135, 81, 18, 135, 81, 18, 114, 102, 97, 114, 102, 97, 112, 144, 75, 112, 144, 75, 188, 98, 27, 188, 98, 27, 112, 144, 75, 112, 144, 75, 188, 98, 27, 188, 98, 27]);
142
165
  colorSpace.fillRgb(testDest, 2, 2, 4, 4, 4, 8, testSrc, 0);
143
- expect(colorSpace.getRgb(new Float32Array([0.1, 0.2, 0.3, 1]), 0)).toEqual(new Uint8Array([31, 27, 20]));
166
+ expect(colorSpace.getRgb(new Float32Array([0.1, 0.2, 0.3, 1]), 0)).toEqual(new Uint8ClampedArray([32, 28, 21]));
144
167
  expect(colorSpace.getOutputLength(4, 0)).toEqual(3);
145
168
  expect(colorSpace.isPassthrough(8)).toBeFalsy();
146
169
  expect(testDest).toEqual(expectedDest);
@@ -152,13 +175,17 @@ describe('colorspace', function () {
152
175
  data: _primitives.Name.get('DeviceCMYK')
153
176
  }]);
154
177
  var res = new _primitives.Dict();
155
- var pdfFunctionFactory = new _function.PDFFunctionFactory({ xref: xref });
178
+ var pdfFunctionFactory = new _function.PDFFunctionFactory({
179
+ xref: xref
180
+ });
181
+
156
182
  var colorSpace = _colorspace.ColorSpace.parse(cs, xref, res, pdfFunctionFactory);
183
+
157
184
  var testSrc = new Uint8Array([27, 125, 250, 128, 131, 139, 140, 45, 111, 25, 198, 78, 21, 147, 255, 69]);
158
- var testDest = new Uint8Array(3 * 3 * 3);
159
- var expectedDest = new Uint8Array([135, 80, 18, 135, 80, 18, 113, 102, 97, 135, 80, 18, 135, 80, 18, 113, 102, 97, 112, 143, 75, 112, 143, 75, 188, 98, 27]);
185
+ var testDest = new Uint8ClampedArray(3 * 3 * 3);
186
+ var expectedDest = new Uint8ClampedArray([135, 81, 18, 135, 81, 18, 114, 102, 97, 135, 81, 18, 135, 81, 18, 114, 102, 97, 112, 144, 75, 112, 144, 75, 188, 98, 27]);
160
187
  colorSpace.fillRgb(testDest, 2, 2, 3, 3, 3, 8, testSrc, 0);
161
- expect(colorSpace.getRgb(new Float32Array([0.1, 0.2, 0.3, 1]), 0)).toEqual(new Uint8Array([31, 27, 20]));
188
+ expect(colorSpace.getRgb(new Float32Array([0.1, 0.2, 0.3, 1]), 0)).toEqual(new Uint8ClampedArray([32, 28, 21]));
162
189
  expect(colorSpace.getOutputLength(4, 1)).toEqual(4);
163
190
  expect(colorSpace.isPassthrough(8)).toBeFalsy();
164
191
  expect(testDest).toEqual(expectedDest);
@@ -176,13 +203,17 @@ describe('colorspace', function () {
176
203
  data: new _primitives.Dict()
177
204
  }]);
178
205
  var res = new _primitives.Dict();
179
- var pdfFunctionFactory = new _function.PDFFunctionFactory({ xref: xref });
206
+ var pdfFunctionFactory = new _function.PDFFunctionFactory({
207
+ xref: xref
208
+ });
209
+
180
210
  var colorSpace = _colorspace.ColorSpace.parse(cs, xref, res, pdfFunctionFactory);
211
+
181
212
  var testSrc = new Uint8Array([27, 125, 250, 131]);
182
- var testDest = new Uint8Array(4 * 4 * 3);
183
- var expectedDest = new Uint8Array([25, 25, 25, 25, 25, 25, 143, 143, 143, 143, 143, 143, 25, 25, 25, 25, 25, 25, 143, 143, 143, 143, 143, 143, 251, 251, 251, 251, 251, 251, 148, 148, 148, 148, 148, 148, 251, 251, 251, 251, 251, 251, 148, 148, 148, 148, 148, 148]);
213
+ var testDest = new Uint8ClampedArray(4 * 4 * 3);
214
+ var expectedDest = new Uint8ClampedArray([25, 25, 25, 25, 25, 25, 143, 143, 143, 143, 143, 143, 25, 25, 25, 25, 25, 25, 143, 143, 143, 143, 143, 143, 251, 251, 251, 251, 251, 251, 149, 149, 149, 149, 149, 149, 251, 251, 251, 251, 251, 251, 149, 149, 149, 149, 149, 149]);
184
215
  colorSpace.fillRgb(testDest, 2, 2, 4, 4, 4, 8, testSrc, 0);
185
- expect(colorSpace.getRgb(new Float32Array([1.0]), 0)).toEqual(new Uint8Array([255, 255, 255]));
216
+ expect(colorSpace.getRgb(new Float32Array([1.0]), 0)).toEqual(new Uint8ClampedArray([255, 255, 255]));
186
217
  expect(colorSpace.getOutputLength(4, 0)).toEqual(12);
187
218
  expect(colorSpace.isPassthrough(8)).toBeFalsy();
188
219
  expect(testDest).toEqual(expectedDest);
@@ -201,13 +232,17 @@ describe('colorspace', function () {
201
232
  data: new _primitives.Dict()
202
233
  }]);
203
234
  var res = new _primitives.Dict();
204
- var pdfFunctionFactory = new _function.PDFFunctionFactory({ xref: xref });
235
+ var pdfFunctionFactory = new _function.PDFFunctionFactory({
236
+ xref: xref
237
+ });
238
+
205
239
  var colorSpace = _colorspace.ColorSpace.parse(cs, xref, res, pdfFunctionFactory);
240
+
206
241
  var testSrc = new Uint8Array([27, 125, 250, 131, 139, 140, 111, 25, 198, 21, 147, 255]);
207
- var testDest = new Uint8Array(3 * 3 * 3);
208
- var expectedDest = new Uint8Array([0, 238, 255, 0, 238, 255, 185, 196, 195, 0, 238, 255, 0, 238, 255, 185, 196, 195, 235, 0, 243, 235, 0, 243, 0, 255, 255]);
242
+ var testDest = new Uint8ClampedArray(3 * 3 * 3);
243
+ var expectedDest = new Uint8ClampedArray([0, 238, 255, 0, 238, 255, 185, 196, 195, 0, 238, 255, 0, 238, 255, 185, 196, 195, 235, 0, 243, 235, 0, 243, 0, 255, 255]);
209
244
  colorSpace.fillRgb(testDest, 2, 2, 3, 3, 3, 8, testSrc, 0);
210
- expect(colorSpace.getRgb(new Float32Array([0.1, 0.2, 0.3]), 0)).toEqual(new Uint8Array([0, 147, 151]));
245
+ expect(colorSpace.getRgb(new Float32Array([0.1, 0.2, 0.3]), 0)).toEqual(new Uint8ClampedArray([0, 147, 151]));
211
246
  expect(colorSpace.getOutputLength(4, 0)).toEqual(4);
212
247
  expect(colorSpace.isPassthrough(8)).toBeFalsy();
213
248
  expect(testDest).toEqual(expectedDest);
@@ -225,13 +260,17 @@ describe('colorspace', function () {
225
260
  data: new _primitives.Dict()
226
261
  }]);
227
262
  var res = new _primitives.Dict();
228
- var pdfFunctionFactory = new _function.PDFFunctionFactory({ xref: xref });
263
+ var pdfFunctionFactory = new _function.PDFFunctionFactory({
264
+ xref: xref
265
+ });
266
+
229
267
  var colorSpace = _colorspace.ColorSpace.parse(cs, xref, res, pdfFunctionFactory);
268
+
230
269
  var testSrc = new Uint8Array([27, 25, 50, 31, 19, 40, 11, 25, 98, 21, 47, 55]);
231
- var testDest = new Uint8Array(3 * 3 * 3);
232
- var expectedDest = new Uint8Array([0, 49, 101, 0, 49, 101, 0, 53, 116, 0, 49, 101, 0, 49, 101, 0, 53, 116, 0, 40, 39, 0, 40, 39, 0, 43, 90]);
270
+ var testDest = new Uint8ClampedArray(3 * 3 * 3);
271
+ var expectedDest = new Uint8ClampedArray([0, 49, 101, 0, 49, 101, 0, 53, 117, 0, 49, 101, 0, 49, 101, 0, 53, 117, 0, 41, 40, 0, 41, 40, 0, 43, 90]);
233
272
  colorSpace.fillRgb(testDest, 2, 2, 3, 3, 3, 8, testSrc, 0);
234
- expect(colorSpace.getRgb([55, 25, 35], 0)).toEqual(new Uint8Array([188, 99, 61]));
273
+ expect(colorSpace.getRgb([55, 25, 35], 0)).toEqual(new Uint8ClampedArray([188, 100, 61]));
235
274
  expect(colorSpace.getOutputLength(4, 0)).toEqual(4);
236
275
  expect(colorSpace.isPassthrough(8)).toBeFalsy();
237
276
  expect(colorSpace.isDefaultDecode([0, 1])).toBeTruthy();
@@ -247,15 +286,19 @@ describe('colorspace', function () {
247
286
  data: new _primitives.Dict()
248
287
  }]);
249
288
  var res = new _primitives.Dict();
250
- var pdfFunctionFactory = new _function.PDFFunctionFactory({ xref: xref });
289
+ var pdfFunctionFactory = new _function.PDFFunctionFactory({
290
+ xref: xref
291
+ });
292
+
251
293
  var colorSpace = _colorspace.ColorSpace.parse(cs, xref, res, pdfFunctionFactory);
294
+
252
295
  var testSrc = new Uint8Array([2, 2, 0, 1]);
253
- var testDest = new Uint8Array(3 * 3 * 3);
254
- var expectedDest = new Uint8Array([255, 109, 70, 255, 109, 70, 255, 109, 70, 255, 109, 70, 255, 109, 70, 255, 109, 70, 23, 155, 35, 23, 155, 35, 147, 69, 93]);
296
+ var testDest = new Uint8ClampedArray(3 * 3 * 3);
297
+ var expectedDest = new Uint8ClampedArray([255, 109, 70, 255, 109, 70, 255, 109, 70, 255, 109, 70, 255, 109, 70, 255, 109, 70, 23, 155, 35, 23, 155, 35, 147, 69, 93]);
255
298
  colorSpace.fillRgb(testDest, 2, 2, 3, 3, 3, 8, testSrc, 0);
256
- expect(colorSpace.getRgb([2], 0)).toEqual(new Uint8Array([255, 109, 70]));
299
+ expect(colorSpace.getRgb([2], 0)).toEqual(new Uint8ClampedArray([255, 109, 70]));
257
300
  expect(colorSpace.isPassthrough(8)).toBeFalsy();
258
- expect(colorSpace.isDefaultDecode([0, 1])).toBeTruthy();
301
+ expect(colorSpace.isDefaultDecode([0, 1], 1)).toBeTruthy();
259
302
  expect(testDest).toEqual(expectedDest);
260
303
  });
261
304
  });
@@ -275,13 +318,17 @@ describe('colorspace', function () {
275
318
  data: fn
276
319
  }]);
277
320
  var res = new _primitives.Dict();
278
- var pdfFunctionFactory = new _function.PDFFunctionFactory({ xref: xref });
321
+ var pdfFunctionFactory = new _function.PDFFunctionFactory({
322
+ xref: xref
323
+ });
324
+
279
325
  var colorSpace = _colorspace.ColorSpace.parse(cs, xref, res, pdfFunctionFactory);
326
+
280
327
  var testSrc = new Uint8Array([27, 25, 50, 31]);
281
- var testDest = new Uint8Array(3 * 3 * 3);
282
- var expectedDest = new Uint8Array([227, 243, 242, 227, 243, 242, 228, 243, 242, 227, 243, 242, 227, 243, 242, 228, 243, 242, 203, 233, 229, 203, 233, 229, 222, 241, 239]);
328
+ var testDest = new Uint8ClampedArray(3 * 3 * 3);
329
+ var expectedDest = new Uint8ClampedArray([226, 242, 241, 226, 242, 241, 229, 244, 242, 226, 242, 241, 226, 242, 241, 229, 244, 242, 203, 232, 229, 203, 232, 229, 222, 241, 238]);
283
330
  colorSpace.fillRgb(testDest, 2, 2, 3, 3, 3, 8, testSrc, 0);
284
- expect(colorSpace.getRgb([0.1], 0)).toEqual(new Uint8Array([228, 243, 241]));
331
+ expect(colorSpace.getRgb([0.1], 0)).toEqual(new Uint8ClampedArray([228, 243, 242]));
285
332
  expect(colorSpace.isPassthrough(8)).toBeFalsy();
286
333
  expect(colorSpace.isDefaultDecode([0, 1])).toBeTruthy();
287
334
  expect(testDest).toEqual(expectedDest);
@@ -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 2017 Mozilla Foundation
5
+ * Copyright 2018 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,13 +19,13 @@
19
19
  * @licend The above is the entire license notice for the
20
20
  * Javascript code in this page
21
21
  */
22
- 'use strict';
22
+ "use strict";
23
23
 
24
- var _crypto = require('../../core/crypto');
24
+ var _crypto = require("../../core/crypto");
25
25
 
26
- var _primitives = require('../../core/primitives');
26
+ var _primitives = require("../../core/primitives");
27
27
 
28
- var _util = require('../../shared/util');
28
+ var _util = require("../../shared/util");
29
29
 
30
30
  describe('crypto', function () {
31
31
  function hex2binary(s) {
@@ -35,14 +35,17 @@ describe('crypto', function () {
35
35
  i,
36
36
  j;
37
37
  var result = new Uint8Array(n);
38
+
38
39
  for (i = 0, j = 0; i < n; ++i) {
39
40
  var d1 = s.charAt(j++);
40
41
  var d2 = s.charAt(j++);
41
42
  var value = digits.indexOf(d1) << 4 | digits.indexOf(d2);
42
43
  result[i] = value;
43
44
  }
45
+
44
46
  return result;
45
47
  }
48
+
46
49
  describe('calculateMD5', function () {
47
50
  it('should pass RFC 1321 test #1', function () {
48
51
  var input, result, expected;
@@ -357,11 +360,14 @@ describe('crypto', function () {
357
360
  describe('CipherTransformFactory', function () {
358
361
  function buildDict(map) {
359
362
  var dict = new _primitives.Dict();
363
+
360
364
  for (var key in map) {
361
365
  dict.set(key, map[key]);
362
366
  }
367
+
363
368
  return dict;
364
369
  }
370
+
365
371
  function ensurePasswordCorrect(done, dict, fileId, password) {
366
372
  try {
367
373
  var factory = new _crypto.CipherTransformFactory(dict, fileId, password);
@@ -370,8 +376,10 @@ describe('CipherTransformFactory', function () {
370
376
  done.fail('Password should be accepted: ' + ex);
371
377
  return;
372
378
  }
379
+
373
380
  done();
374
381
  }
382
+
375
383
  function ensurePasswordNeeded(done, dict, fileId, password) {
376
384
  try {
377
385
  new _crypto.CipherTransformFactory(dict, fileId, password);
@@ -381,8 +389,10 @@ describe('CipherTransformFactory', function () {
381
389
  done();
382
390
  return;
383
391
  }
392
+
384
393
  done.fail('Password should be rejected.');
385
394
  }
395
+
386
396
  function ensurePasswordIncorrect(done, dict, fileId, password) {
387
397
  try {
388
398
  new _crypto.CipherTransformFactory(dict, fileId, password);
@@ -392,8 +402,10 @@ describe('CipherTransformFactory', function () {
392
402
  done();
393
403
  return;
394
404
  }
405
+
395
406
  done.fail('Password should be rejected.');
396
407
  }
408
+
397
409
  var fileId1, fileId2, dict1, dict2;
398
410
  var aes256Dict, aes256IsoDict, aes256BlankDict, aes256IsoBlankDict;
399
411
  beforeAll(function (done) {
@@ -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 2017 Mozilla Foundation
5
+ * Copyright 2018 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,17 +19,15 @@
19
19
  * @licend The above is the entire license notice for the
20
20
  * Javascript code in this page
21
21
  */
22
- 'use strict';
22
+ "use strict";
23
23
 
24
- var _test_utils = require('./test_utils');
24
+ var _test_utils = require("./test_utils");
25
25
 
26
- var _dom_utils = require('../../display/dom_utils');
26
+ var _dom_utils = require("../../display/dom_utils");
27
27
 
28
- var _api = require('../../display/api');
28
+ var _api = require("../../display/api");
29
29
 
30
- var _is_node = require('../../shared/is_node');
31
-
32
- var _is_node2 = _interopRequireDefault(_is_node);
30
+ var _is_node = _interopRequireDefault(require("../../shared/is_node"));
33
31
 
34
32
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
35
33
 
@@ -42,24 +40,26 @@ function getTopLeftPixel(canvasContext) {
42
40
  a: imgData.data[3]
43
41
  };
44
42
  }
43
+
45
44
  describe('custom canvas rendering', function () {
46
45
  var transparentGetDocumentParams = (0, _test_utils.buildGetDocumentParams)('transparent.pdf');
47
- var CanvasFactory = void 0;
48
- var loadingTask = void 0;
49
- var page = void 0;
46
+ var CanvasFactory;
47
+ var loadingTask;
48
+ var page;
50
49
  beforeAll(function (done) {
51
- if ((0, _is_node2.default)()) {} else {
50
+ if ((0, _is_node.default)()) {
51
+ CanvasFactory = new _test_utils.NodeCanvasFactory();
52
+ } else {
52
53
  CanvasFactory = new _dom_utils.DOMCanvasFactory();
53
54
  }
55
+
54
56
  loadingTask = (0, _api.getDocument)(transparentGetDocumentParams);
55
57
  loadingTask.promise.then(function (doc) {
56
58
  return doc.getPage(1);
57
59
  }).then(function (data) {
58
60
  page = data;
59
61
  done();
60
- }).catch(function (reason) {
61
- done.fail(reason);
62
- });
62
+ }).catch(done.fail);
63
63
  });
64
64
  afterAll(function (done) {
65
65
  CanvasFactory = null;
@@ -67,56 +67,44 @@ describe('custom canvas rendering', function () {
67
67
  loadingTask.destroy().then(done);
68
68
  });
69
69
  it('renders to canvas with a default white background', function (done) {
70
- if ((0, _is_node2.default)()) {
71
- pending('TODO: Support Canvas testing in Node.js.');
72
- }
73
- var viewport = page.getViewport(1);
70
+ var viewport = page.getViewport({
71
+ scale: 1
72
+ });
74
73
  var canvasAndCtx = CanvasFactory.create(viewport.width, viewport.height);
75
- page.render({
74
+ var renderTask = page.render({
76
75
  canvasContext: canvasAndCtx.context,
77
76
  viewport: viewport
78
- }).then(function () {
79
- var _getTopLeftPixel = getTopLeftPixel(canvasAndCtx.context),
80
- r = _getTopLeftPixel.r,
81
- g = _getTopLeftPixel.g,
82
- b = _getTopLeftPixel.b,
83
- a = _getTopLeftPixel.a;
84
-
77
+ });
78
+ renderTask.promise.then(function () {
79
+ expect(getTopLeftPixel(canvasAndCtx.context)).toEqual({
80
+ r: 255,
81
+ g: 255,
82
+ b: 255,
83
+ a: 255
84
+ });
85
85
  CanvasFactory.destroy(canvasAndCtx);
86
- expect(r).toEqual(255);
87
- expect(g).toEqual(255);
88
- expect(b).toEqual(255);
89
- expect(a).toEqual(255);
90
86
  done();
91
- }).catch(function (reason) {
92
- done(reason);
93
- });
87
+ }).catch(done.fail);
94
88
  });
95
89
  it('renders to canvas with a custom background', function (done) {
96
- if ((0, _is_node2.default)()) {
97
- pending('TODO: Support Canvas testing in Node.js.');
98
- }
99
- var viewport = page.getViewport(1);
90
+ var viewport = page.getViewport({
91
+ scale: 1
92
+ });
100
93
  var canvasAndCtx = CanvasFactory.create(viewport.width, viewport.height);
101
- page.render({
94
+ var renderTask = page.render({
102
95
  canvasContext: canvasAndCtx.context,
103
96
  viewport: viewport,
104
97
  background: 'rgba(255,0,0,1.0)'
105
- }).then(function () {
106
- var _getTopLeftPixel2 = getTopLeftPixel(canvasAndCtx.context),
107
- r = _getTopLeftPixel2.r,
108
- g = _getTopLeftPixel2.g,
109
- b = _getTopLeftPixel2.b,
110
- a = _getTopLeftPixel2.a;
111
-
98
+ });
99
+ renderTask.promise.then(function () {
100
+ expect(getTopLeftPixel(canvasAndCtx.context)).toEqual({
101
+ r: 255,
102
+ g: 0,
103
+ b: 0,
104
+ a: 255
105
+ });
112
106
  CanvasFactory.destroy(canvasAndCtx);
113
- expect(r).toEqual(255);
114
- expect(g).toEqual(0);
115
- expect(b).toEqual(0);
116
- expect(a).toEqual(255);
117
107
  done();
118
- }).catch(function (reason) {
119
- done(reason);
120
- });
108
+ }).catch(done.fail);
121
109
  });
122
110
  });
@@ -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 2017 Mozilla Foundation
5
+ * Copyright 2018 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,55 +19,64 @@
19
19
  * @licend The above is the entire license notice for the
20
20
  * Javascript code in this page
21
21
  */
22
- 'use strict';
22
+ "use strict";
23
23
 
24
- var _domstubs = require('../../examples/node/domstubs');
24
+ var _domstubs = require("../../examples/node/domstubs");
25
25
 
26
- var _test_utils = require('./test_utils');
26
+ var _test_utils = require("./test_utils");
27
27
 
28
- var _api = require('../../display/api');
28
+ var _api = require("../../display/api");
29
29
 
30
- var _is_node = require('../../shared/is_node');
30
+ var _is_node = _interopRequireDefault(require("../../shared/is_node"));
31
31
 
32
- var _is_node2 = _interopRequireDefault(_is_node);
32
+ var _util = require("../../shared/util");
33
33
 
34
- var _util = require('../../shared/util');
35
-
36
- var _svg = require('../../display/svg');
34
+ var _svg = require("../../display/svg");
37
35
 
38
36
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
39
37
 
40
38
  var XLINK_NS = 'http://www.w3.org/1999/xlink';
39
+
41
40
  function withZlib(isZlibRequired, callback) {
42
41
  if (isZlibRequired) {
43
- if (!(0, _is_node2.default)()) {
42
+ if (!(0, _is_node.default)()) {
44
43
  throw new Error('zlib test can only be run in Node.js');
45
44
  }
45
+
46
46
  return callback();
47
47
  }
48
- if (!(0, _is_node2.default)()) {
48
+
49
+ if (!(0, _is_node.default)()) {
49
50
  return callback();
50
51
  }
52
+
51
53
  var zlib = require('zlib');
54
+
52
55
  var deflateSync = zlib.deflateSync;
53
56
  zlib.deflateSync = disabledDeflateSync;
57
+
54
58
  function disabledDeflateSync() {
55
59
  throw new Error('zlib.deflateSync is explicitly disabled for testing.');
56
60
  }
61
+
57
62
  function restoreDeflateSync() {
58
63
  if (zlib.deflateSync === disabledDeflateSync) {
59
64
  zlib.deflateSync = deflateSync;
60
65
  }
61
66
  }
67
+
62
68
  var promise = callback();
63
69
  promise.then(restoreDeflateSync, restoreDeflateSync);
64
70
  return promise;
65
71
  }
72
+
66
73
  describe('SVGGraphics', function () {
67
74
  var loadingTask;
68
75
  var page;
69
76
  beforeAll(function (done) {
70
- loadingTask = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)('xobject-image.pdf', { nativeImageDecoderSupport: _util.NativeImageDecoding.DISPLAY }));
77
+ loadingTask = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)('xobject-image.pdf', {
78
+ nativeImageDecoderSupport: _util.NativeImageDecoding.DISPLAY
79
+ }));
71
80
  loadingTask.promise.then(function (doc) {
72
81
  doc.getPage(1).then(function (firstPage) {
73
82
  page = firstPage;
@@ -93,35 +102,42 @@ describe('SVGGraphics', function () {
93
102
  }
94
103
  };
95
104
  var xobjectObjId = 'img_p0_1';
96
- if ((0, _is_node2.default)()) {
105
+
106
+ if ((0, _is_node.default)()) {
97
107
  (0, _domstubs.setStubs)(global);
98
108
  }
109
+
99
110
  try {
100
111
  var imgData = svgGfx.objs.get(xobjectObjId);
101
112
  svgGfx.paintInlineImageXObject(imgData, elementContainer);
102
113
  } finally {
103
- if ((0, _is_node2.default)()) {
114
+ if ((0, _is_node.default)()) {
104
115
  (0, _domstubs.unsetStubs)(global);
105
116
  }
106
117
  }
118
+
107
119
  return svgImg;
108
120
  });
109
121
  }
122
+
110
123
  it('should fail require("zlib") unless in Node.js', function () {
111
124
  function testFunc() {
112
125
  require('zlib');
113
126
  }
127
+
114
128
  expect(testFunc.toString()).toMatch(/\srequire\(["']zlib["']\)/);
115
- if ((0, _is_node2.default)()) {
129
+
130
+ if ((0, _is_node.default)()) {
116
131
  expect(testFunc).not.toThrow();
117
132
  } else {
118
133
  expect(testFunc).toThrow();
119
134
  }
120
135
  });
121
136
  it('should produce a reasonably small svg:image', function (done) {
122
- if (!(0, _is_node2.default)()) {
137
+ if (!(0, _is_node.default)()) {
123
138
  pending('zlib.deflateSync is not supported in non-Node environments.');
124
139
  }
140
+
125
141
  withZlib(true, getSVGImage).then(function (svgImg) {
126
142
  expect(svgImg.nodeName).toBe('svg:image');
127
143
  expect(svgImg.getAttributeNS(null, 'width')).toBe('200px');