pdfjs-dist 2.0.489 → 2.2.228

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 (169) hide show
  1. package/CODE_OF_CONDUCT.md +15 -0
  2. package/bower.json +1 -1
  3. package/build/pdf.js +18515 -11402
  4. package/build/pdf.js.map +1 -1
  5. package/build/pdf.min.js +1 -1
  6. package/build/pdf.worker.js +48266 -37137
  7. package/build/pdf.worker.js.map +1 -1
  8. package/build/pdf.worker.min.js +1 -1
  9. package/external/url/url-lib.js +627 -0
  10. package/image_decoders/pdf.image_decoders.js +11350 -0
  11. package/image_decoders/pdf.image_decoders.js.map +1 -0
  12. package/image_decoders/pdf.image_decoders.min.js +1 -0
  13. package/lib/core/annotation.js +587 -242
  14. package/lib/core/arithmetic_decoder.js +275 -245
  15. package/lib/core/bidi.js +65 -6
  16. package/lib/core/ccitt.js +173 -18
  17. package/lib/core/ccitt_stream.js +15 -6
  18. package/lib/core/cff_parser.js +433 -61
  19. package/lib/core/charsets.js +5 -4
  20. package/lib/core/chunked_stream.js +400 -152
  21. package/lib/core/cmap.js +326 -87
  22. package/lib/core/colorspace.js +874 -594
  23. package/lib/core/core_utils.js +147 -0
  24. package/lib/core/crypto.js +290 -45
  25. package/lib/core/document.js +560 -268
  26. package/lib/core/encodings.js +19 -10
  27. package/lib/core/evaluator.js +1005 -360
  28. package/lib/core/font_renderer.js +331 -97
  29. package/lib/core/fonts.js +812 -195
  30. package/lib/core/function.js +284 -71
  31. package/lib/core/glyphlist.js +4 -3
  32. package/lib/core/image.js +169 -62
  33. package/lib/core/image_utils.js +111 -0
  34. package/lib/core/jbig2.js +479 -66
  35. package/lib/core/jbig2_stream.js +19 -8
  36. package/lib/core/jpeg_stream.js +38 -13
  37. package/lib/core/jpg.js +253 -29
  38. package/lib/core/jpx.js +396 -6
  39. package/lib/core/jpx_stream.js +18 -6
  40. package/lib/core/metrics.js +15 -15
  41. package/lib/core/murmurhash3.js +56 -34
  42. package/lib/core/obj.js +1354 -488
  43. package/lib/core/operator_list.js +144 -31
  44. package/lib/core/parser.js +539 -191
  45. package/lib/core/pattern.js +148 -14
  46. package/lib/core/pdf_manager.js +323 -133
  47. package/lib/core/primitives.js +111 -24
  48. package/lib/core/ps_parser.js +134 -45
  49. package/lib/core/standard_fonts.js +17 -17
  50. package/lib/core/stream.js +313 -34
  51. package/lib/core/type1_parser.js +143 -13
  52. package/lib/core/unicode.js +32 -5
  53. package/lib/core/worker.js +217 -190
  54. package/lib/core/worker_stream.js +277 -0
  55. package/lib/display/annotation_layer.js +450 -133
  56. package/lib/display/api.js +1597 -784
  57. package/lib/display/api_compatibility.js +11 -13
  58. package/lib/display/canvas.js +360 -44
  59. package/lib/display/content_disposition.js +83 -32
  60. package/lib/display/display_utils.js +747 -0
  61. package/lib/display/fetch_stream.js +221 -90
  62. package/lib/display/font_loader.js +468 -236
  63. package/lib/display/metadata.js +38 -16
  64. package/lib/display/network.js +635 -428
  65. package/lib/display/network_utils.js +32 -19
  66. package/lib/display/node_stream.js +367 -175
  67. package/lib/display/pattern_helper.js +81 -31
  68. package/lib/display/svg.js +1235 -519
  69. package/lib/display/text_layer.js +153 -29
  70. package/lib/display/transport_stream.js +345 -94
  71. package/lib/display/webgl.js +64 -18
  72. package/lib/display/worker_options.js +5 -4
  73. package/lib/display/xml_parser.js +166 -53
  74. package/lib/examples/node/domstubs.js +60 -4
  75. package/lib/pdf.js +36 -14
  76. package/lib/pdf.worker.js +5 -3
  77. package/lib/shared/compatibility.js +158 -564
  78. package/lib/shared/global_scope.js +2 -2
  79. package/lib/shared/is_node.js +4 -4
  80. package/lib/shared/message_handler.js +521 -0
  81. package/lib/shared/streams_polyfill.js +21 -17
  82. package/lib/shared/url_polyfill.js +56 -0
  83. package/lib/shared/util.js +243 -710
  84. package/lib/test/unit/annotation_spec.js +870 -401
  85. package/lib/test/unit/api_spec.js +657 -345
  86. package/lib/test/unit/bidi_spec.js +7 -7
  87. package/lib/test/unit/cff_parser_spec.js +54 -11
  88. package/lib/test/unit/clitests_helper.js +10 -8
  89. package/lib/test/unit/cmap_spec.js +95 -41
  90. package/lib/test/unit/colorspace_spec.js +115 -63
  91. package/lib/test/unit/core_utils_spec.js +191 -0
  92. package/lib/test/unit/crypto_spec.js +17 -5
  93. package/lib/test/unit/custom_spec.js +43 -55
  94. package/lib/test/unit/display_svg_spec.js +34 -18
  95. package/lib/test/unit/display_utils_spec.js +273 -0
  96. package/lib/test/unit/document_spec.js +8 -13
  97. package/lib/test/unit/encodings_spec.js +25 -45
  98. package/lib/test/unit/evaluator_spec.js +38 -15
  99. package/lib/test/unit/fetch_stream_spec.js +109 -0
  100. package/lib/test/unit/function_spec.js +17 -5
  101. package/lib/test/unit/jasmine-boot.js +33 -20
  102. package/lib/test/unit/{util_stream_spec.js → message_handler_spec.js} +41 -69
  103. package/lib/test/unit/metadata_spec.js +71 -11
  104. package/lib/test/unit/murmurhash3_spec.js +3 -3
  105. package/lib/test/unit/network_spec.js +19 -54
  106. package/lib/test/unit/network_utils_spec.js +91 -14
  107. package/lib/test/unit/node_stream_spec.js +56 -32
  108. package/lib/test/unit/parser_spec.js +162 -71
  109. package/lib/test/unit/pdf_find_controller_spec.js +230 -0
  110. package/lib/test/unit/pdf_find_utils_spec.js +63 -0
  111. package/lib/test/unit/pdf_history_spec.js +21 -9
  112. package/lib/test/unit/primitives_spec.js +53 -20
  113. package/lib/test/unit/stream_spec.js +12 -4
  114. package/lib/test/unit/test_utils.js +273 -56
  115. package/lib/test/unit/testreporter.js +21 -3
  116. package/lib/test/unit/type1_parser_spec.js +8 -6
  117. package/lib/test/unit/ui_utils_spec.js +454 -16
  118. package/lib/test/unit/unicode_spec.js +18 -15
  119. package/lib/test/unit/util_spec.js +87 -128
  120. package/lib/web/annotation_layer_builder.js +39 -22
  121. package/lib/web/app.js +1290 -588
  122. package/lib/web/app_options.js +100 -62
  123. package/lib/web/base_viewer.js +511 -182
  124. package/lib/web/chromecom.js +261 -117
  125. package/lib/web/debugger.js +166 -22
  126. package/lib/web/download_manager.js +32 -13
  127. package/lib/web/firefox_print_service.js +20 -10
  128. package/lib/web/firefoxcom.js +315 -80
  129. package/lib/web/genericcom.js +89 -30
  130. package/lib/web/genericl10n.js +142 -30
  131. package/lib/web/grab_to_pan.js +28 -4
  132. package/lib/web/interfaces.js +170 -47
  133. package/lib/web/overlay_manager.js +235 -85
  134. package/lib/web/password_prompt.js +22 -14
  135. package/lib/web/pdf_attachment_viewer.js +38 -18
  136. package/lib/web/pdf_cursor_tools.js +39 -16
  137. package/lib/web/pdf_document_properties.js +255 -136
  138. package/lib/web/pdf_find_bar.js +84 -40
  139. package/lib/web/pdf_find_controller.js +495 -184
  140. package/lib/web/pdf_find_utils.js +111 -0
  141. package/lib/web/pdf_history.js +190 -53
  142. package/lib/web/pdf_link_service.js +138 -77
  143. package/lib/web/pdf_outline_viewer.js +122 -46
  144. package/lib/web/pdf_page_view.js +191 -67
  145. package/lib/web/pdf_presentation_mode.js +99 -34
  146. package/lib/web/pdf_print_service.js +61 -13
  147. package/lib/web/pdf_rendering_queue.js +28 -9
  148. package/lib/web/pdf_sidebar.js +141 -81
  149. package/lib/web/pdf_sidebar_resizer.js +42 -16
  150. package/lib/web/pdf_single_page_viewer.js +74 -66
  151. package/lib/web/pdf_thumbnail_view.js +104 -33
  152. package/lib/web/pdf_thumbnail_viewer.js +66 -26
  153. package/lib/web/pdf_viewer.component.js +112 -32
  154. package/lib/web/pdf_viewer.js +91 -52
  155. package/lib/web/preferences.js +284 -89
  156. package/lib/web/secondary_toolbar.js +165 -40
  157. package/lib/web/text_layer_builder.js +134 -59
  158. package/lib/web/toolbar.js +78 -43
  159. package/lib/web/ui_utils.js +462 -136
  160. package/lib/web/view_history.js +215 -67
  161. package/lib/web/viewer_compatibility.js +4 -13
  162. package/package.json +5 -4
  163. package/web/pdf_viewer.css +79 -11
  164. package/web/pdf_viewer.js +6107 -3748
  165. package/web/pdf_viewer.js.map +1 -1
  166. package/lib/display/dom_utils.js +0 -309
  167. package/lib/test/unit/dom_utils_spec.js +0 -89
  168. package/lib/test/unit/fonts_spec.js +0 -81
  169. package/lib/web/dom_events.js +0 -137
package/lib/core/ccitt.js CHANGED
@@ -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 2019 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,14 +19,14 @@
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
24
  Object.defineProperty(exports, "__esModule", {
25
25
  value: true
26
26
  });
27
- exports.CCITTFaxDecoder = undefined;
27
+ exports.CCITTFaxDecoder = void 0;
28
28
 
29
- var _util = require('../shared/util');
29
+ var _util = require("../shared/util");
30
30
 
31
31
  var CCITTFaxDecoder = function CCITTFaxDecoder() {
32
32
  var ccittEOL = -2;
@@ -46,12 +46,14 @@ var CCITTFaxDecoder = function CCITTFaxDecoder() {
46
46
  var blackTable1 = [[-1, -1], [-1, -1], [12, ccittEOL], [12, ccittEOL], [-1, -1], [-1, -1], [-1, -1], [-1, -1], [-1, -1], [-1, -1], [-1, -1], [-1, -1], [-1, -1], [-1, -1], [-1, -1], [-1, -1], [-1, -1], [-1, -1], [-1, -1], [-1, -1], [-1, -1], [-1, -1], [-1, -1], [-1, -1], [-1, -1], [-1, -1], [-1, -1], [-1, -1], [-1, -1], [-1, -1], [-1, -1], [-1, -1], [11, 1792], [11, 1792], [11, 1792], [11, 1792], [12, 1984], [12, 1984], [12, 2048], [12, 2048], [12, 2112], [12, 2112], [12, 2176], [12, 2176], [12, 2240], [12, 2240], [12, 2304], [12, 2304], [11, 1856], [11, 1856], [11, 1856], [11, 1856], [11, 1920], [11, 1920], [11, 1920], [11, 1920], [12, 2368], [12, 2368], [12, 2432], [12, 2432], [12, 2496], [12, 2496], [12, 2560], [12, 2560], [10, 18], [10, 18], [10, 18], [10, 18], [10, 18], [10, 18], [10, 18], [10, 18], [12, 52], [12, 52], [13, 640], [13, 704], [13, 768], [13, 832], [12, 55], [12, 55], [12, 56], [12, 56], [13, 1280], [13, 1344], [13, 1408], [13, 1472], [12, 59], [12, 59], [12, 60], [12, 60], [13, 1536], [13, 1600], [11, 24], [11, 24], [11, 24], [11, 24], [11, 25], [11, 25], [11, 25], [11, 25], [13, 1664], [13, 1728], [12, 320], [12, 320], [12, 384], [12, 384], [12, 448], [12, 448], [13, 512], [13, 576], [12, 53], [12, 53], [12, 54], [12, 54], [13, 896], [13, 960], [13, 1024], [13, 1088], [13, 1152], [13, 1216], [10, 64], [10, 64], [10, 64], [10, 64], [10, 64], [10, 64], [10, 64], [10, 64]];
47
47
  var blackTable2 = [[8, 13], [8, 13], [8, 13], [8, 13], [8, 13], [8, 13], [8, 13], [8, 13], [8, 13], [8, 13], [8, 13], [8, 13], [8, 13], [8, 13], [8, 13], [8, 13], [11, 23], [11, 23], [12, 50], [12, 51], [12, 44], [12, 45], [12, 46], [12, 47], [12, 57], [12, 58], [12, 61], [12, 256], [10, 16], [10, 16], [10, 16], [10, 16], [10, 17], [10, 17], [10, 17], [10, 17], [12, 48], [12, 49], [12, 62], [12, 63], [12, 30], [12, 31], [12, 32], [12, 33], [12, 40], [12, 41], [11, 22], [11, 22], [8, 14], [8, 14], [8, 14], [8, 14], [8, 14], [8, 14], [8, 14], [8, 14], [8, 14], [8, 14], [8, 14], [8, 14], [8, 14], [8, 14], [8, 14], [8, 14], [7, 10], [7, 10], [7, 10], [7, 10], [7, 10], [7, 10], [7, 10], [7, 10], [7, 10], [7, 10], [7, 10], [7, 10], [7, 10], [7, 10], [7, 10], [7, 10], [7, 10], [7, 10], [7, 10], [7, 10], [7, 10], [7, 10], [7, 10], [7, 10], [7, 10], [7, 10], [7, 10], [7, 10], [7, 10], [7, 10], [7, 10], [7, 10], [7, 11], [7, 11], [7, 11], [7, 11], [7, 11], [7, 11], [7, 11], [7, 11], [7, 11], [7, 11], [7, 11], [7, 11], [7, 11], [7, 11], [7, 11], [7, 11], [7, 11], [7, 11], [7, 11], [7, 11], [7, 11], [7, 11], [7, 11], [7, 11], [7, 11], [7, 11], [7, 11], [7, 11], [7, 11], [7, 11], [7, 11], [7, 11], [9, 15], [9, 15], [9, 15], [9, 15], [9, 15], [9, 15], [9, 15], [9, 15], [12, 128], [12, 192], [12, 26], [12, 27], [12, 28], [12, 29], [11, 19], [11, 19], [11, 20], [11, 20], [12, 34], [12, 35], [12, 36], [12, 37], [12, 38], [12, 39], [11, 21], [11, 21], [12, 42], [12, 43], [10, 0], [10, 0], [10, 0], [10, 0], [7, 12], [7, 12], [7, 12], [7, 12], [7, 12], [7, 12], [7, 12], [7, 12], [7, 12], [7, 12], [7, 12], [7, 12], [7, 12], [7, 12], [7, 12], [7, 12], [7, 12], [7, 12], [7, 12], [7, 12], [7, 12], [7, 12], [7, 12], [7, 12], [7, 12], [7, 12], [7, 12], [7, 12], [7, 12], [7, 12], [7, 12], [7, 12]];
48
48
  var blackTable3 = [[-1, -1], [-1, -1], [-1, -1], [-1, -1], [6, 9], [6, 8], [5, 7], [5, 7], [4, 6], [4, 6], [4, 6], [4, 6], [4, 5], [4, 5], [4, 5], [4, 5], [3, 1], [3, 1], [3, 1], [3, 1], [3, 1], [3, 1], [3, 1], [3, 1], [3, 4], [3, 4], [3, 4], [3, 4], [3, 4], [3, 4], [3, 4], [3, 4], [2, 3], [2, 3], [2, 3], [2, 3], [2, 3], [2, 3], [2, 3], [2, 3], [2, 3], [2, 3], [2, 3], [2, 3], [2, 3], [2, 3], [2, 3], [2, 3], [2, 2], [2, 2], [2, 2], [2, 2], [2, 2], [2, 2], [2, 2], [2, 2], [2, 2], [2, 2], [2, 2], [2, 2], [2, 2], [2, 2], [2, 2], [2, 2]];
49
+
49
50
  function CCITTFaxDecoder(source) {
50
51
  var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
51
52
 
52
53
  if (!source || typeof source.next !== 'function') {
53
54
  throw new Error('CCITTFaxDecoder - invalid "source" parameter.');
54
55
  }
56
+
55
57
  this.source = source;
56
58
  this.eof = false;
57
59
  this.encoding = options['K'] || 0;
@@ -60,9 +62,11 @@ var CCITTFaxDecoder = function CCITTFaxDecoder() {
60
62
  this.columns = options['Columns'] || 1728;
61
63
  this.rows = options['Rows'] || 0;
62
64
  var eoblock = options['EndOfBlock'];
65
+
63
66
  if (eoblock === null || eoblock === undefined) {
64
67
  eoblock = true;
65
68
  }
69
+
66
70
  this.eoblock = eoblock;
67
71
  this.black = options['BlackIs1'] || false;
68
72
  this.codingLine = new Uint32Array(this.columns + 1);
@@ -75,66 +79,79 @@ var CCITTFaxDecoder = function CCITTFaxDecoder() {
75
79
  this.inputBuf = 0;
76
80
  this.outputBits = 0;
77
81
  this.rowsDone = false;
78
- var code1 = void 0;
82
+ var code1;
83
+
79
84
  while ((code1 = this._lookBits(12)) === 0) {
80
85
  this._eatBits(1);
81
86
  }
87
+
82
88
  if (code1 === 1) {
83
89
  this._eatBits(12);
84
90
  }
91
+
85
92
  if (this.encoding > 0) {
86
93
  this.nextLine2D = !this._lookBits(1);
94
+
87
95
  this._eatBits(1);
88
96
  }
89
97
  }
98
+
90
99
  CCITTFaxDecoder.prototype = {
91
100
  readNextChar: function readNextChar() {
92
101
  if (this.eof) {
93
102
  return -1;
94
103
  }
104
+
95
105
  var refLine = this.refLine;
96
106
  var codingLine = this.codingLine;
97
107
  var columns = this.columns;
98
- var refPos = void 0,
99
- blackPixels = void 0,
100
- bits = void 0,
101
- i = void 0;
108
+ var refPos, blackPixels, bits, i;
109
+
102
110
  if (this.outputBits === 0) {
103
111
  if (this.rowsDone) {
104
112
  this.eof = true;
105
113
  }
114
+
106
115
  if (this.eof) {
107
116
  return -1;
108
117
  }
118
+
109
119
  this.err = false;
110
- var code1 = void 0,
111
- code2 = void 0,
112
- code3 = void 0;
120
+ var code1, code2, code3;
121
+
113
122
  if (this.nextLine2D) {
114
123
  for (i = 0; codingLine[i] < columns; ++i) {
115
124
  refLine[i] = codingLine[i];
116
125
  }
126
+
117
127
  refLine[i++] = columns;
118
128
  refLine[i] = columns;
119
129
  codingLine[0] = 0;
120
130
  this.codingPos = 0;
121
131
  refPos = 0;
122
132
  blackPixels = 0;
133
+
123
134
  while (codingLine[this.codingPos] < columns) {
124
135
  code1 = this._getTwoDimCode();
136
+
125
137
  switch (code1) {
126
138
  case twoDimPass:
127
139
  this._addPixels(refLine[refPos + 1], blackPixels);
140
+
128
141
  if (refLine[refPos + 1] < columns) {
129
142
  refPos += 2;
130
143
  }
144
+
131
145
  break;
146
+
132
147
  case twoDimHoriz:
133
148
  code1 = code2 = 0;
149
+
134
150
  if (blackPixels) {
135
151
  do {
136
152
  code1 += code3 = this._getBlackCode();
137
153
  } while (code3 >= 64);
154
+
138
155
  do {
139
156
  code2 += code3 = this._getWhiteCode();
140
157
  } while (code3 >= 64);
@@ -142,107 +159,152 @@ var CCITTFaxDecoder = function CCITTFaxDecoder() {
142
159
  do {
143
160
  code1 += code3 = this._getWhiteCode();
144
161
  } while (code3 >= 64);
162
+
145
163
  do {
146
164
  code2 += code3 = this._getBlackCode();
147
165
  } while (code3 >= 64);
148
166
  }
167
+
149
168
  this._addPixels(codingLine[this.codingPos] + code1, blackPixels);
169
+
150
170
  if (codingLine[this.codingPos] < columns) {
151
171
  this._addPixels(codingLine[this.codingPos] + code2, blackPixels ^ 1);
152
172
  }
173
+
153
174
  while (refLine[refPos] <= codingLine[this.codingPos] && refLine[refPos] < columns) {
154
175
  refPos += 2;
155
176
  }
177
+
156
178
  break;
179
+
157
180
  case twoDimVertR3:
158
181
  this._addPixels(refLine[refPos] + 3, blackPixels);
182
+
159
183
  blackPixels ^= 1;
184
+
160
185
  if (codingLine[this.codingPos] < columns) {
161
186
  ++refPos;
187
+
162
188
  while (refLine[refPos] <= codingLine[this.codingPos] && refLine[refPos] < columns) {
163
189
  refPos += 2;
164
190
  }
165
191
  }
192
+
166
193
  break;
194
+
167
195
  case twoDimVertR2:
168
196
  this._addPixels(refLine[refPos] + 2, blackPixels);
197
+
169
198
  blackPixels ^= 1;
199
+
170
200
  if (codingLine[this.codingPos] < columns) {
171
201
  ++refPos;
202
+
172
203
  while (refLine[refPos] <= codingLine[this.codingPos] && refLine[refPos] < columns) {
173
204
  refPos += 2;
174
205
  }
175
206
  }
207
+
176
208
  break;
209
+
177
210
  case twoDimVertR1:
178
211
  this._addPixels(refLine[refPos] + 1, blackPixels);
212
+
179
213
  blackPixels ^= 1;
214
+
180
215
  if (codingLine[this.codingPos] < columns) {
181
216
  ++refPos;
217
+
182
218
  while (refLine[refPos] <= codingLine[this.codingPos] && refLine[refPos] < columns) {
183
219
  refPos += 2;
184
220
  }
185
221
  }
222
+
186
223
  break;
224
+
187
225
  case twoDimVert0:
188
226
  this._addPixels(refLine[refPos], blackPixels);
227
+
189
228
  blackPixels ^= 1;
229
+
190
230
  if (codingLine[this.codingPos] < columns) {
191
231
  ++refPos;
232
+
192
233
  while (refLine[refPos] <= codingLine[this.codingPos] && refLine[refPos] < columns) {
193
234
  refPos += 2;
194
235
  }
195
236
  }
237
+
196
238
  break;
239
+
197
240
  case twoDimVertL3:
198
241
  this._addPixelsNeg(refLine[refPos] - 3, blackPixels);
242
+
199
243
  blackPixels ^= 1;
244
+
200
245
  if (codingLine[this.codingPos] < columns) {
201
246
  if (refPos > 0) {
202
247
  --refPos;
203
248
  } else {
204
249
  ++refPos;
205
250
  }
251
+
206
252
  while (refLine[refPos] <= codingLine[this.codingPos] && refLine[refPos] < columns) {
207
253
  refPos += 2;
208
254
  }
209
255
  }
256
+
210
257
  break;
258
+
211
259
  case twoDimVertL2:
212
260
  this._addPixelsNeg(refLine[refPos] - 2, blackPixels);
261
+
213
262
  blackPixels ^= 1;
263
+
214
264
  if (codingLine[this.codingPos] < columns) {
215
265
  if (refPos > 0) {
216
266
  --refPos;
217
267
  } else {
218
268
  ++refPos;
219
269
  }
270
+
220
271
  while (refLine[refPos] <= codingLine[this.codingPos] && refLine[refPos] < columns) {
221
272
  refPos += 2;
222
273
  }
223
274
  }
275
+
224
276
  break;
277
+
225
278
  case twoDimVertL1:
226
279
  this._addPixelsNeg(refLine[refPos] - 1, blackPixels);
280
+
227
281
  blackPixels ^= 1;
282
+
228
283
  if (codingLine[this.codingPos] < columns) {
229
284
  if (refPos > 0) {
230
285
  --refPos;
231
286
  } else {
232
287
  ++refPos;
233
288
  }
289
+
234
290
  while (refLine[refPos] <= codingLine[this.codingPos] && refLine[refPos] < columns) {
235
291
  refPos += 2;
236
292
  }
237
293
  }
294
+
238
295
  break;
296
+
239
297
  case ccittEOF:
240
298
  this._addPixels(columns, 0);
299
+
241
300
  this.eof = true;
242
301
  break;
302
+
243
303
  default:
244
304
  (0, _util.info)('bad 2d code');
305
+
245
306
  this._addPixels(columns, 0);
307
+
246
308
  this.err = true;
247
309
  }
248
310
  }
@@ -250,8 +312,10 @@ var CCITTFaxDecoder = function CCITTFaxDecoder() {
250
312
  codingLine[0] = 0;
251
313
  this.codingPos = 0;
252
314
  blackPixels = 0;
315
+
253
316
  while (codingLine[this.codingPos] < columns) {
254
317
  code1 = 0;
318
+
255
319
  if (blackPixels) {
256
320
  do {
257
321
  code1 += code3 = this._getBlackCode();
@@ -261,92 +325,125 @@ var CCITTFaxDecoder = function CCITTFaxDecoder() {
261
325
  code1 += code3 = this._getWhiteCode();
262
326
  } while (code3 >= 64);
263
327
  }
328
+
264
329
  this._addPixels(codingLine[this.codingPos] + code1, blackPixels);
330
+
265
331
  blackPixels ^= 1;
266
332
  }
267
333
  }
334
+
268
335
  var gotEOL = false;
336
+
269
337
  if (this.byteAlign) {
270
338
  this.inputBits &= ~7;
271
339
  }
340
+
272
341
  if (!this.eoblock && this.row === this.rows - 1) {
273
342
  this.rowsDone = true;
274
343
  } else {
275
344
  code1 = this._lookBits(12);
345
+
276
346
  if (this.eoline) {
277
347
  while (code1 !== ccittEOF && code1 !== 1) {
278
348
  this._eatBits(1);
349
+
279
350
  code1 = this._lookBits(12);
280
351
  }
281
352
  } else {
282
353
  while (code1 === 0) {
283
354
  this._eatBits(1);
355
+
284
356
  code1 = this._lookBits(12);
285
357
  }
286
358
  }
359
+
287
360
  if (code1 === 1) {
288
361
  this._eatBits(12);
362
+
289
363
  gotEOL = true;
290
364
  } else if (code1 === ccittEOF) {
291
365
  this.eof = true;
292
366
  }
293
367
  }
368
+
294
369
  if (!this.eof && this.encoding > 0 && !this.rowsDone) {
295
370
  this.nextLine2D = !this._lookBits(1);
371
+
296
372
  this._eatBits(1);
297
373
  }
374
+
298
375
  if (this.eoblock && gotEOL && this.byteAlign) {
299
376
  code1 = this._lookBits(12);
377
+
300
378
  if (code1 === 1) {
301
379
  this._eatBits(12);
380
+
302
381
  if (this.encoding > 0) {
303
382
  this._lookBits(1);
383
+
304
384
  this._eatBits(1);
305
385
  }
386
+
306
387
  if (this.encoding >= 0) {
307
388
  for (i = 0; i < 4; ++i) {
308
389
  code1 = this._lookBits(12);
390
+
309
391
  if (code1 !== 1) {
310
392
  (0, _util.info)('bad rtc code: ' + code1);
311
393
  }
394
+
312
395
  this._eatBits(12);
396
+
313
397
  if (this.encoding > 0) {
314
398
  this._lookBits(1);
399
+
315
400
  this._eatBits(1);
316
401
  }
317
402
  }
318
403
  }
404
+
319
405
  this.eof = true;
320
406
  }
321
407
  } else if (this.err && this.eoline) {
322
408
  while (true) {
323
409
  code1 = this._lookBits(13);
410
+
324
411
  if (code1 === ccittEOF) {
325
412
  this.eof = true;
326
413
  return -1;
327
414
  }
415
+
328
416
  if (code1 >> 1 === 1) {
329
417
  break;
330
418
  }
419
+
331
420
  this._eatBits(1);
332
421
  }
422
+
333
423
  this._eatBits(12);
424
+
334
425
  if (this.encoding > 0) {
335
426
  this._eatBits(1);
427
+
336
428
  this.nextLine2D = !(code1 & 1);
337
429
  }
338
430
  }
431
+
339
432
  if (codingLine[0] > 0) {
340
433
  this.outputBits = codingLine[this.codingPos = 0];
341
434
  } else {
342
435
  this.outputBits = codingLine[this.codingPos = 1];
343
436
  }
437
+
344
438
  this.row++;
345
439
  }
346
- var c = void 0;
440
+
441
+ var c;
442
+
347
443
  if (this.outputBits >= 8) {
348
444
  c = this.codingPos & 1 ? 0 : 0xFF;
349
445
  this.outputBits -= 8;
446
+
350
447
  if (this.outputBits === 0 && codingLine[this.codingPos] < columns) {
351
448
  this.codingPos++;
352
449
  this.outputBits = codingLine[this.codingPos] - codingLine[this.codingPos - 1];
@@ -354,21 +451,27 @@ var CCITTFaxDecoder = function CCITTFaxDecoder() {
354
451
  } else {
355
452
  bits = 8;
356
453
  c = 0;
454
+
357
455
  do {
358
456
  if (this.outputBits > bits) {
359
457
  c <<= bits;
458
+
360
459
  if (!(this.codingPos & 1)) {
361
460
  c |= 0xFF >> 8 - bits;
362
461
  }
462
+
363
463
  this.outputBits -= bits;
364
464
  bits = 0;
365
465
  } else {
366
466
  c <<= this.outputBits;
467
+
367
468
  if (!(this.codingPos & 1)) {
368
469
  c |= 0xFF >> 8 - this.outputBits;
369
470
  }
471
+
370
472
  bits -= this.outputBits;
371
473
  this.outputBits = 0;
474
+
372
475
  if (codingLine[this.codingPos] < columns) {
373
476
  this.codingPos++;
374
477
  this.outputBits = codingLine[this.codingPos] - codingLine[this.codingPos - 1];
@@ -379,39 +482,48 @@ var CCITTFaxDecoder = function CCITTFaxDecoder() {
379
482
  }
380
483
  } while (bits);
381
484
  }
485
+
382
486
  if (this.black) {
383
487
  c ^= 0xFF;
384
488
  }
489
+
385
490
  return c;
386
491
  },
387
492
  _addPixels: function _addPixels(a1, blackPixels) {
388
493
  var codingLine = this.codingLine;
389
494
  var codingPos = this.codingPos;
495
+
390
496
  if (a1 > codingLine[codingPos]) {
391
497
  if (a1 > this.columns) {
392
498
  (0, _util.info)('row is wrong length');
393
499
  this.err = true;
394
500
  a1 = this.columns;
395
501
  }
502
+
396
503
  if (codingPos & 1 ^ blackPixels) {
397
504
  ++codingPos;
398
505
  }
506
+
399
507
  codingLine[codingPos] = a1;
400
508
  }
509
+
401
510
  this.codingPos = codingPos;
402
511
  },
403
512
  _addPixelsNeg: function _addPixelsNeg(a1, blackPixels) {
404
513
  var codingLine = this.codingLine;
405
514
  var codingPos = this.codingPos;
515
+
406
516
  if (a1 > codingLine[codingPos]) {
407
517
  if (a1 > this.columns) {
408
518
  (0, _util.info)('row is wrong length');
409
519
  this.err = true;
410
520
  a1 = this.columns;
411
521
  }
522
+
412
523
  if (codingPos & 1 ^ blackPixels) {
413
524
  ++codingPos;
414
525
  }
526
+
415
527
  codingLine[codingPos] = a1;
416
528
  } else if (a1 < codingLine[codingPos]) {
417
529
  if (a1 < 0) {
@@ -419,91 +531,119 @@ var CCITTFaxDecoder = function CCITTFaxDecoder() {
419
531
  this.err = true;
420
532
  a1 = 0;
421
533
  }
534
+
422
535
  while (codingPos > 0 && a1 < codingLine[codingPos - 1]) {
423
536
  --codingPos;
424
537
  }
538
+
425
539
  codingLine[codingPos] = a1;
426
540
  }
541
+
427
542
  this.codingPos = codingPos;
428
543
  },
429
544
  _findTableCode: function _findTableCode(start, end, table, limit) {
430
545
  var limitValue = limit || 0;
546
+
431
547
  for (var i = start; i <= end; ++i) {
432
548
  var code = this._lookBits(i);
549
+
433
550
  if (code === ccittEOF) {
434
551
  return [true, 1, false];
435
552
  }
553
+
436
554
  if (i < end) {
437
555
  code <<= end - i;
438
556
  }
557
+
439
558
  if (!limitValue || code >= limitValue) {
440
559
  var p = table[code - limitValue];
560
+
441
561
  if (p[0] === i) {
442
562
  this._eatBits(i);
563
+
443
564
  return [true, p[1], true];
444
565
  }
445
566
  }
446
567
  }
568
+
447
569
  return [false, 0, false];
448
570
  },
449
571
  _getTwoDimCode: function _getTwoDimCode() {
450
572
  var code = 0;
451
- var p = void 0;
573
+ var p;
574
+
452
575
  if (this.eoblock) {
453
576
  code = this._lookBits(7);
454
577
  p = twoDimTable[code];
578
+
455
579
  if (p && p[0] > 0) {
456
580
  this._eatBits(p[0]);
581
+
457
582
  return p[1];
458
583
  }
459
584
  } else {
460
585
  var result = this._findTableCode(1, 7, twoDimTable);
586
+
461
587
  if (result[0] && result[2]) {
462
588
  return result[1];
463
589
  }
464
590
  }
591
+
465
592
  (0, _util.info)('Bad two dim code');
466
593
  return ccittEOF;
467
594
  },
468
595
  _getWhiteCode: function _getWhiteCode() {
469
596
  var code = 0;
470
- var p = void 0;
597
+ var p;
598
+
471
599
  if (this.eoblock) {
472
600
  code = this._lookBits(12);
601
+
473
602
  if (code === ccittEOF) {
474
603
  return 1;
475
604
  }
605
+
476
606
  if (code >> 5 === 0) {
477
607
  p = whiteTable1[code];
478
608
  } else {
479
609
  p = whiteTable2[code >> 3];
480
610
  }
611
+
481
612
  if (p[0] > 0) {
482
613
  this._eatBits(p[0]);
614
+
483
615
  return p[1];
484
616
  }
485
617
  } else {
486
618
  var result = this._findTableCode(1, 9, whiteTable2);
619
+
487
620
  if (result[0]) {
488
621
  return result[1];
489
622
  }
623
+
490
624
  result = this._findTableCode(11, 12, whiteTable1);
625
+
491
626
  if (result[0]) {
492
627
  return result[1];
493
628
  }
494
629
  }
630
+
495
631
  (0, _util.info)('bad white code');
632
+
496
633
  this._eatBits(1);
634
+
497
635
  return 1;
498
636
  },
499
637
  _getBlackCode: function _getBlackCode() {
500
- var code = void 0,
501
- p = void 0;
638
+ var code, p;
639
+
502
640
  if (this.eoblock) {
503
641
  code = this._lookBits(13);
642
+
504
643
  if (code === ccittEOF) {
505
644
  return 1;
506
645
  }
646
+
507
647
  if (code >> 7 === 0) {
508
648
  p = blackTable1[code];
509
649
  } else if (code >> 9 === 0 && code >> 7 !== 0) {
@@ -511,40 +651,54 @@ var CCITTFaxDecoder = function CCITTFaxDecoder() {
511
651
  } else {
512
652
  p = blackTable3[code >> 7];
513
653
  }
654
+
514
655
  if (p[0] > 0) {
515
656
  this._eatBits(p[0]);
657
+
516
658
  return p[1];
517
659
  }
518
660
  } else {
519
661
  var result = this._findTableCode(2, 6, blackTable3);
662
+
520
663
  if (result[0]) {
521
664
  return result[1];
522
665
  }
666
+
523
667
  result = this._findTableCode(7, 12, blackTable2, 64);
668
+
524
669
  if (result[0]) {
525
670
  return result[1];
526
671
  }
672
+
527
673
  result = this._findTableCode(10, 13, blackTable1);
674
+
528
675
  if (result[0]) {
529
676
  return result[1];
530
677
  }
531
678
  }
679
+
532
680
  (0, _util.info)('bad black code');
681
+
533
682
  this._eatBits(1);
683
+
534
684
  return 1;
535
685
  },
536
686
  _lookBits: function _lookBits(n) {
537
- var c = void 0;
687
+ var c;
688
+
538
689
  while (this.inputBits < n) {
539
690
  if ((c = this.source.next()) === -1) {
540
691
  if (this.inputBits === 0) {
541
692
  return ccittEOF;
542
693
  }
694
+
543
695
  return this.inputBuf << n - this.inputBits & 0xFFFF >> 16 - n;
544
696
  }
697
+
545
698
  this.inputBuf = this.inputBuf << 8 | c;
546
699
  this.inputBits += 8;
547
700
  }
701
+
548
702
  return this.inputBuf >> this.inputBits - n & 0xFFFF >> 16 - n;
549
703
  },
550
704
  _eatBits: function _eatBits(n) {
@@ -555,4 +709,5 @@ var CCITTFaxDecoder = function CCITTFaxDecoder() {
555
709
  };
556
710
  return CCITTFaxDecoder;
557
711
  }();
712
+
558
713
  exports.CCITTFaxDecoder = CCITTFaxDecoder;