From 8ec1dfde49dfa5278defb841f53a4bef10448bf8 Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Wed, 25 Dec 2019 15:54:34 +0100 Subject: [PATCH 1/3] Add `// prettier-ignore` comments to prevent re-formatting of certain data structures There's a fair number of (primarily) `Array`s/`TypedArray`s whose formatting we don't want disturb, since in many cases that would lead to the code becoming much more difficult to read and/or break existing inline comments. *Please note:* It may be a good idea to look through these cases individually, and possibly re-write some of the them (especially the `String` ones) to reduce the need for all of these ignore commands. --- src/core/bidi.js | 2 ++ src/core/ccitt.js | 6 ++++++ src/core/cff_parser.js | 7 +++++-- src/core/charsets.js | 3 +++ src/core/colorspace.js | 3 +++ src/core/core_utils.js | 1 + src/core/crypto.js | 11 +++++++++++ src/core/document.js | 1 + src/core/encodings.js | 7 +++++++ src/core/fonts.js | 1 + src/core/jbig2.js | 1 + src/core/jpg.js | 2 ++ src/core/jpx.js | 3 +++ src/core/obj.js | 3 ++- src/core/parser.js | 2 ++ src/core/pattern.js | 8 ++++++++ src/core/stream.js | 5 +++++ src/display/canvas.js | 1 + src/display/webgl.js | 2 ++ src/shared/util.js | 1 + test/unit/cff_parser_spec.js | 13 +++++++++++++ test/unit/cmap_spec.js | 7 +++++++ test/unit/colorspace_spec.js | 18 ++++++++++++++++++ test/unit/crypto_spec.js | 16 ++++++++++++++++ test/unit/parser_spec.js | 9 +++++++++ 25 files changed, 130 insertions(+), 3 deletions(-) diff --git a/src/core/bidi.js b/src/core/bidi.js index f749407d4..2dfcc0be1 100644 --- a/src/core/bidi.js +++ b/src/core/bidi.js @@ -17,6 +17,7 @@ import { warn } from '../shared/util'; // Character types for symbols from 0000 to 00FF. // Source: ftp://ftp.unicode.org/Public/UNIDATA/UnicodeData.txt +// prettier-ignore var baseTypes = [ 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'S', 'B', 'S', 'WS', 'B', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', @@ -46,6 +47,7 @@ var baseTypes = [ // http://unicode.org/charts/PDF/U0600.pdf), so we replace it with an // empty string and issue a warning if we encounter this character. The // empty string is required to properly index the items after it. +// prettier-ignore var arabicTypes = [ 'AN', 'AN', 'AN', 'AN', 'AN', 'AN', 'ON', 'ON', 'AL', 'ET', 'ET', 'AL', 'CS', 'AL', 'ON', 'ON', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', diff --git a/src/core/ccitt.js b/src/core/ccitt.js index 3f81e339a..2de51b917 100644 --- a/src/core/ccitt.js +++ b/src/core/ccitt.js @@ -41,6 +41,7 @@ let CCITTFaxDecoder = (function CCITTFaxDecoder() { const twoDimVertR3 = 7; const twoDimVertL3 = 8; + // prettier-ignore const twoDimTable = [ [-1, -1], [-1, -1], // 000000x [7, twoDimVertL3], // 0000010 @@ -109,6 +110,7 @@ let CCITTFaxDecoder = (function CCITTFaxDecoder() { [1, twoDimVert0], [1, twoDimVert0] ]; + // prettier-ignore const whiteTable1 = [ [-1, -1], // 00000 [12, ccittEOL], // 00001 @@ -131,6 +133,7 @@ let CCITTFaxDecoder = (function CCITTFaxDecoder() { [12, 2560] // 11111 ]; + // prettier-ignore const whiteTable2 = [ [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 0000000xx [8, 29], [8, 29], // 00000010x @@ -295,6 +298,7 @@ let CCITTFaxDecoder = (function CCITTFaxDecoder() { [4, 7], [4, 7], [4, 7], [4, 7] ]; + // prettier-ignore const blackTable1 = [ [-1, -1], [-1, -1], // 000000000000x [12, ccittEOL], [12, ccittEOL], // 000000000001x @@ -356,6 +360,7 @@ let CCITTFaxDecoder = (function CCITTFaxDecoder() { [10, 64], [10, 64], [10, 64], [10, 64] ]; + // prettier-ignore const blackTable2 = [ [8, 13], [8, 13], [8, 13], [8, 13], // 00000100xxxx [8, 13], [8, 13], [8, 13], [8, 13], @@ -435,6 +440,7 @@ let CCITTFaxDecoder = (function CCITTFaxDecoder() { [7, 12], [7, 12], [7, 12], [7, 12] ]; + // prettier-ignore const blackTable3 = [ [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 0000xx [6, 9], // 000100 diff --git a/src/core/cff_parser.js b/src/core/cff_parser.js index 400d21967..ed248e05f 100644 --- a/src/core/cff_parser.js +++ b/src/core/cff_parser.js @@ -28,6 +28,7 @@ var MAX_SUBR_NESTING = 10; * The CFF class takes a Type1 file and wrap it into a * 'Compact Font Format' which itself embed Type2 charstrings. */ +// prettier-ignore var CFFStandardStrings = [ '.notdef', 'space', 'exclam', 'quotedbl', 'numbersign', 'dollar', 'percent', 'ampersand', 'quoteright', 'parenleft', 'parenright', 'asterisk', 'plus', @@ -339,8 +340,9 @@ var CFFParser = (function CFFParserClosure() { function parseFloatOperand() { var str = ''; var eof = 15; - var lookup = ['0', '1', '2', '3', '4', '5', '6', '7', '8', - '9', '.', 'E', 'E-', null, '-']; + // prettier-ignore + const lookup = ['0', '1', '2', '3', '4', '5', '6', '7', '8', + '9', '.', 'E', 'E-', null, '-']; var length = dict.length; while (pos < length) { var b = dict[pos++]; @@ -1087,6 +1089,7 @@ var CFFTopDict = (function CFFTopDictClosure() { [[12, 4], 'UnderlineThickness', 'num', 50], [[12, 5], 'PaintType', 'num', 0], [[12, 6], 'CharstringType', 'num', 2], + // prettier-ignore [[12, 7], 'FontMatrix', ['num', 'num', 'num', 'num', 'num', 'num'], [0.001, 0, 0, 0.001, 0, 0]], [13, 'UniqueID', 'num', null], diff --git a/src/core/charsets.js b/src/core/charsets.js index 2f6652efa..fb08f5bf4 100644 --- a/src/core/charsets.js +++ b/src/core/charsets.js @@ -14,6 +14,7 @@ */ /* eslint no-var: error */ +// prettier-ignore const ISOAdobeCharset = [ '.notdef', 'space', 'exclam', 'quotedbl', 'numbersign', 'dollar', 'percent', 'ampersand', 'quoteright', 'parenleft', 'parenright', @@ -51,6 +52,7 @@ const ISOAdobeCharset = [ 'ugrave', 'yacute', 'ydieresis', 'zcaron' ]; +// prettier-ignore const ExpertCharset = [ '.notdef', 'space', 'exclamsmall', 'Hungarumlautsmall', 'dollaroldstyle', 'dollarsuperior', 'ampersandsmall', 'Acutesmall', 'parenleftsuperior', @@ -91,6 +93,7 @@ const ExpertCharset = [ 'Ydieresissmall' ]; +// prettier-ignore const ExpertSubsetCharset = [ '.notdef', 'space', 'dollaroldstyle', 'dollarsuperior', 'parenleftsuperior', 'parenrightsuperior', 'twodotenleader', diff --git a/src/core/colorspace.js b/src/core/colorspace.js index 1c666acac..4d5fa1fd6 100644 --- a/src/core/colorspace.js +++ b/src/core/colorspace.js @@ -863,17 +863,20 @@ const CalGrayCS = (function CalGrayCSClosure() { const CalRGBCS = (function CalRGBCSClosure() { // See http://www.brucelindbloom.com/index.html?Eqn_ChromAdapt.html for these // matrices. + // prettier-ignore const BRADFORD_SCALE_MATRIX = new Float32Array([ 0.8951, 0.2664, -0.1614, -0.7502, 1.7135, 0.0367, 0.0389, -0.0685, 1.0296]); + // prettier-ignore const BRADFORD_SCALE_INVERSE_MATRIX = new Float32Array([ 0.9869929, -0.1470543, 0.1599627, 0.4323053, 0.5183603, 0.0492912, -0.0085287, 0.0400428, 0.9684867]); // See http://www.brucelindbloom.com/index.html?Eqn_RGB_XYZ_Matrix.html. + // prettier-ignore const SRGB_D65_XYZ_TO_RGB_MATRIX = new Float32Array([ 3.2404542, -1.5371385, -0.4985314, -0.9692660, 1.8760108, 0.0415560, diff --git a/src/core/core_utils.js b/src/core/core_utils.js index b18124dad..540790cba 100644 --- a/src/core/core_utils.js +++ b/src/core/core_utils.js @@ -87,6 +87,7 @@ function getInheritableProperty({ dict, key, getArray = false, return values; } +// prettier-ignore const ROMAN_NUMBER_MAP = [ '', 'C', 'CC', 'CCC', 'CD', 'D', 'DC', 'DCC', 'DCCC', 'CM', '', 'X', 'XX', 'XXX', 'XL', 'L', 'LX', 'LXX', 'LXXX', 'XC', diff --git a/src/core/crypto.js b/src/core/crypto.js index 8b0d9dce3..c458094a1 100644 --- a/src/core/crypto.js +++ b/src/core/crypto.js @@ -63,12 +63,14 @@ var ARCFourCipher = (function ARCFourCipherClosure() { })(); var calculateMD5 = (function calculateMD5Closure() { + // prettier-ignore var r = new Uint8Array([ 7, 12, 17, 22, 7, 12, 17, 22, 7, 12, 17, 22, 7, 12, 17, 22, 5, 9, 14, 20, 5, 9, 14, 20, 5, 9, 14, 20, 5, 9, 14, 20, 4, 11, 16, 23, 4, 11, 16, 23, 4, 11, 16, 23, 4, 11, 16, 23, 6, 10, 15, 21, 6, 10, 15, 21, 6, 10, 15, 21, 6, 10, 15, 21]); + // prettier-ignore var k = new Int32Array([ -680876936, -389564586, 606105819, -1044525330, -176418897, 1200080426, -1473231341, -45705983, 1770035416, -1958414417, -42063, -1990404162, @@ -136,6 +138,7 @@ var calculateMD5 = (function calculateMD5Closure() { h2 = (h2 + c) | 0; h3 = (h3 + d) | 0; } + // prettier-ignore return new Uint8Array([ h0 & 0xFF, (h0 >> 8) & 0xFF, (h0 >> 16) & 0xFF, (h0 >>> 24) & 0xFF, h1 & 0xFF, (h1 >> 8) & 0xFF, (h1 >> 16) & 0xFF, (h1 >>> 24) & 0xFF, @@ -263,6 +266,7 @@ var calculateSHA256 = (function calculateSHA256Closure() { return rotr(x, 17) ^ rotr(x, 19) ^ x >>> 10; } + // prettier-ignore var k = [0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5, 0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3, @@ -341,6 +345,7 @@ var calculateSHA256 = (function calculateSHA256Closure() { h6 = (h6 + g) | 0; h7 = (h7 + h) | 0; } + // prettier-ignore return new Uint8Array([ (h0 >> 24) & 0xFF, (h0 >> 16) & 0xFF, (h0 >> 8) & 0xFF, (h0) & 0xFF, (h1 >> 24) & 0xFF, (h1 >> 16) & 0xFF, (h1 >> 8) & 0xFF, (h1) & 0xFF, @@ -421,6 +426,7 @@ var calculateSHA512 = (function calculateSHA512Closure() { result.xor(tmp); } + // prettier-ignore var k = [ new Word64(0x428a2f98, 0xd728ae22), new Word64(0x71374491, 0x23ef65cd), new Word64(0xb5c0fbcf, 0xec4d3b2f), new Word64(0xe9b5dba5, 0x8189dbbc), @@ -635,6 +641,7 @@ class AESBaseCipher { unreachable('Cannot initialize AESBaseCipher.'); } + // prettier-ignore this._s = new Uint8Array([ 0x63, 0x7c, 0x77, 0x7b, 0xf2, 0x6b, 0x6f, 0xc5, 0x30, 0x01, 0x67, 0x2b, 0xfe, 0xd7, 0xab, 0x76, 0xca, 0x82, 0xc9, 0x7d, 0xfa, 0x59, 0x47, 0xf0, @@ -660,6 +667,7 @@ class AESBaseCipher { 0xb0, 0x54, 0xbb, 0x16, ]); + // prettier-ignore this._inv_s = new Uint8Array([ 0x52, 0x09, 0x6a, 0xd5, 0x30, 0x36, 0xa5, 0x38, 0xbf, 0x40, 0xa3, 0x9e, 0x81, 0xf3, 0xd7, 0xfb, 0x7c, 0xe3, 0x39, 0x82, 0x9b, 0x2f, 0xff, 0x87, @@ -685,6 +693,7 @@ class AESBaseCipher { 0x55, 0x21, 0x0c, 0x7d, ]); + // prettier-ignore this._mix = new Uint32Array([ 0x00000000, 0x0e090d0b, 0x1c121a16, 0x121b171d, 0x3824342c, 0x362d3927, 0x24362e3a, 0x2a3f2331, 0x70486858, 0x7e416553, 0x6c5a724e, 0x62537f45, @@ -1040,6 +1049,7 @@ class AES128Cipher extends AESBaseCipher { this._cyclesOfRepetition = 10; this._keySize = 160; // bits + // prettier-ignore this._rcon = new Uint8Array([ 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a, @@ -1373,6 +1383,7 @@ var CipherTransform = (function CipherTransformClosure() { })(); var CipherTransformFactory = (function CipherTransformFactoryClosure() { + // prettier-ignore var defaultPasswordBytes = new Uint8Array([ 0x28, 0xBF, 0x4E, 0x5E, 0x4E, 0x75, 0x8A, 0x41, 0x64, 0x00, 0x4E, 0x56, 0xFF, 0xFA, 0x01, 0x08, diff --git a/src/core/document.js b/src/core/document.js index b58ea7b49..5a13bff39 100644 --- a/src/core/document.js +++ b/src/core/document.js @@ -345,6 +345,7 @@ class Page { } const PDF_HEADER_SIGNATURE = new Uint8Array([0x25, 0x50, 0x44, 0x46, 0x2D]); +// prettier-ignore const STARTXREF_SIGNATURE = new Uint8Array([ 0x73, 0x74, 0x61, 0x72, 0x74, 0x78, 0x72, 0x65, 0x66]); const ENDOBJ_SIGNATURE = new Uint8Array([0x65, 0x6E, 0x64, 0x6F, 0x62, 0x6A]); diff --git a/src/core/encodings.js b/src/core/encodings.js index e8dc244f6..dba3d59a8 100644 --- a/src/core/encodings.js +++ b/src/core/encodings.js @@ -13,6 +13,7 @@ * limitations under the License. */ +// prettier-ignore const ExpertEncoding = [ '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', @@ -56,6 +57,7 @@ const ExpertEncoding = [ 'Ucircumflexsmall', 'Udieresissmall', 'Yacutesmall', 'Thornsmall', 'Ydieresissmall']; +// prettier-ignore const MacExpertEncoding = [ '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', @@ -98,6 +100,7 @@ const MacExpertEncoding = [ 'Macronsmall', 'bsuperior', 'nsuperior', 'msuperior', 'commasuperior', 'periodsuperior', 'Dotaccentsmall', 'Ringsmall', '', '', '', '']; +// prettier-ignore const MacRomanEncoding = [ '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', @@ -134,6 +137,7 @@ const MacRomanEncoding = [ 'tilde', 'macron', 'breve', 'dotaccent', 'ring', 'cedilla', 'hungarumlaut', 'ogonek', 'caron']; +// prettier-ignore const StandardEncoding = [ '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', @@ -162,6 +166,7 @@ const StandardEncoding = [ '', '', '', 'dotlessi', '', '', 'lslash', 'oslash', 'oe', 'germandbls', '', '', '', '']; +// prettier-ignore const WinAnsiEncoding = [ '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', @@ -198,6 +203,7 @@ const WinAnsiEncoding = [ 'ugrave', 'uacute', 'ucircumflex', 'udieresis', 'yacute', 'thorn', 'ydieresis']; +// prettier-ignore const SymbolSetEncoding = [ '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', @@ -236,6 +242,7 @@ const SymbolSetEncoding = [ 'bracketrightex', 'bracketrightbt', 'bracerighttp', 'bracerightmid', 'bracerightbt', '']; +// prettier-ignore const ZapfDingbatsEncoding = [ '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', diff --git a/src/core/fonts.js b/src/core/fonts.js index cd8c954f4..a701250c1 100644 --- a/src/core/fonts.js +++ b/src/core/fonts.js @@ -2037,6 +2037,7 @@ var Font = (function FontClosure() { return names; } + // prettier-ignore var TTOpsStackDeltas = [ 0, 0, 0, 0, 0, 0, 0, 0, -2, -2, -2, -2, 0, 0, -2, -5, -1, -1, -1, -1, -1, -1, -1, -1, 0, 0, -1, 0, -1, -1, -1, -1, diff --git a/src/core/jbig2.js b/src/core/jbig2.js index 73e3d57e2..e268d40ef 100644 --- a/src/core/jbig2.js +++ b/src/core/jbig2.js @@ -73,6 +73,7 @@ var Jbig2Image = (function Jbig2ImageClosure() { } var sign = readBits(1); + // prettier-ignore var value = readBits(1) ? (readBits(1) ? (readBits(1) ? diff --git a/src/core/jpg.js b/src/core/jpg.js index 27d8be1e1..73e891d04 100644 --- a/src/core/jpg.js +++ b/src/core/jpg.js @@ -45,6 +45,7 @@ class EOIMarkerError extends BaseException { } */ var JpegImage = (function JpegImageClosure() { + // prettier-ignore var dctZigZag = new Uint8Array([ 0, 1, 8, @@ -1015,6 +1016,7 @@ var JpegImage = (function JpegImageClosure() { // inverting JPEG (CMYK) images if and only if the image data does *not* // come from a PDF file and no `decodeTransform` was passed by the user. if (!isSourcePDF && numComponents === 4 && !transform) { + // prettier-ignore transform = new Int32Array([ -256, 255, -256, 255, -256, 255, -256, 255]); } diff --git a/src/core/jpx.js b/src/core/jpx.js index cfb318425..f5603c837 100644 --- a/src/core/jpx.js +++ b/src/core/jpx.js @@ -1616,16 +1616,19 @@ var JpxImage = (function JpxImageClosure() { // Table D-1 // The index is binary presentation: 0dddvvhh, ddd - sum of Di (0..4), // vv - sum of Vi (0..2), and hh - sum of Hi (0..2) + // prettier-ignore var LLAndLHContextsLabel = new Uint8Array([ 0, 5, 8, 0, 3, 7, 8, 0, 4, 7, 8, 0, 0, 0, 0, 0, 1, 6, 8, 0, 3, 7, 8, 0, 4, 7, 8, 0, 0, 0, 0, 0, 2, 6, 8, 0, 3, 7, 8, 0, 4, 7, 8, 0, 0, 0, 0, 0, 2, 6, 8, 0, 3, 7, 8, 0, 4, 7, 8, 0, 0, 0, 0, 0, 2, 6, 8, 0, 3, 7, 8, 0, 4, 7, 8 ]); + // prettier-ignore var HLContextLabel = new Uint8Array([ 0, 3, 4, 0, 5, 7, 7, 0, 8, 8, 8, 0, 0, 0, 0, 0, 1, 3, 4, 0, 6, 7, 7, 0, 8, 8, 8, 0, 0, 0, 0, 0, 2, 3, 4, 0, 6, 7, 7, 0, 8, 8, 8, 0, 0, 0, 0, 0, 2, 3, 4, 0, 6, 7, 7, 0, 8, 8, 8, 0, 0, 0, 0, 0, 2, 3, 4, 0, 6, 7, 7, 0, 8, 8, 8 ]); + // prettier-ignore var HHContextLabel = new Uint8Array([ 0, 1, 2, 0, 1, 2, 2, 0, 2, 2, 2, 0, 0, 0, 0, 0, 3, 4, 5, 0, 4, 5, 5, 0, 5, 5, 5, 0, 0, 0, 0, 0, 6, 7, 7, 0, 7, 7, 7, 0, 7, 7, 7, 0, 0, 0, 0, 0, 8, 8, diff --git a/src/core/obj.js b/src/core/obj.js index b50fd56c2..979e5f673 100644 --- a/src/core/obj.js +++ b/src/core/obj.js @@ -1377,8 +1377,9 @@ var XRef = (function XRefClosure() { const CHECK_CONTENT_LENGTH = 25; var trailerBytes = new Uint8Array([116, 114, 97, 105, 108, 101, 114]); + // prettier-ignore var startxrefBytes = new Uint8Array([115, 116, 97, 114, 116, 120, 114, - 101, 102]); + 101, 102]); const objBytes = new Uint8Array([111, 98, 106]); var xrefBytes = new Uint8Array([47, 88, 82, 101, 102]); diff --git a/src/core/parser.js b/src/core/parser.js index 010e9152a..5c0c48cb9 100644 --- a/src/core/parser.js +++ b/src/core/parser.js @@ -565,6 +565,7 @@ class Parser { this.shift(); // 'stream' } else { // Bad stream length, scanning for endstream command. + // prettier-ignore const ENDSTREAM_SIGNATURE = new Uint8Array([ 0x65, 0x6E, 0x64, 0x73, 0x74, 0x72, 0x65, 0x61, 0x6D]); let actualLength = this._findStreamLength(startPos, @@ -724,6 +725,7 @@ class Parser { // A '1' in this array means the character is white space. A '1' or // '2' means the character ends a name or command. +// prettier-ignore const specialChars = [ 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 1, 1, 0, 0, // 0x 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 1x diff --git a/src/core/pattern.js b/src/core/pattern.js index fe9c36e1e..dbfceace1 100644 --- a/src/core/pattern.js +++ b/src/core/pattern.js @@ -514,6 +514,7 @@ Shadings.Mesh = (function MeshClosure() { } var tmp1, tmp2, tmp3, tmp4; switch (f) { + // prettier-ignore case 0: ps[12] = pi + 3; ps[13] = pi + 4; ps[14] = pi + 5; ps[15] = pi + 6; ps[ 8] = pi + 2; /* values for 5, 6, 9, 10 are */ ps[11] = pi + 7; @@ -522,6 +523,7 @@ Shadings.Mesh = (function MeshClosure() { cs[2] = ci + 1; cs[3] = ci + 2; cs[0] = ci; cs[1] = ci + 3; break; + // prettier-ignore case 1: tmp1 = ps[12]; tmp2 = ps[13]; tmp3 = ps[14]; tmp4 = ps[15]; ps[12] = tmp4; ps[13] = pi + 0; ps[14] = pi + 1; ps[15] = pi + 2; @@ -532,6 +534,7 @@ Shadings.Mesh = (function MeshClosure() { cs[2] = tmp2; cs[3] = ci; cs[0] = tmp1; cs[1] = ci + 1; break; + // prettier-ignore case 2: tmp1 = ps[15]; tmp2 = ps[11]; @@ -543,6 +546,7 @@ Shadings.Mesh = (function MeshClosure() { cs[2] = cs[1]; cs[3] = ci; cs[0] = tmp1; cs[1] = ci + 1; break; + // prettier-ignore case 3: ps[12] = ps[0]; ps[13] = pi + 0; ps[14] = pi + 1; ps[15] = pi + 2; ps[ 8] = ps[1]; /* values for 5, 6, 9, 10 are */ ps[11] = pi + 3; @@ -626,6 +630,7 @@ Shadings.Mesh = (function MeshClosure() { } var tmp1, tmp2, tmp3, tmp4; switch (f) { + // prettier-ignore case 0: ps[12] = pi + 3; ps[13] = pi + 4; ps[14] = pi + 5; ps[15] = pi + 6; ps[ 8] = pi + 2; ps[ 9] = pi + 13; ps[10] = pi + 14; ps[11] = pi + 7; @@ -634,6 +639,7 @@ Shadings.Mesh = (function MeshClosure() { cs[2] = ci + 1; cs[3] = ci + 2; cs[0] = ci; cs[1] = ci + 3; break; + // prettier-ignore case 1: tmp1 = ps[12]; tmp2 = ps[13]; tmp3 = ps[14]; tmp4 = ps[15]; ps[12] = tmp4; ps[13] = pi + 0; ps[14] = pi + 1; ps[15] = pi + 2; @@ -644,6 +650,7 @@ Shadings.Mesh = (function MeshClosure() { cs[2] = tmp2; cs[3] = ci; cs[0] = tmp1; cs[1] = ci + 1; break; + // prettier-ignore case 2: tmp1 = ps[15]; tmp2 = ps[11]; @@ -655,6 +662,7 @@ Shadings.Mesh = (function MeshClosure() { cs[2] = cs[1]; cs[3] = ci; cs[0] = tmp1; cs[1] = ci + 1; break; + // prettier-ignore case 3: ps[12] = ps[0]; ps[13] = pi + 0; ps[14] = pi + 1; ps[15] = pi + 2; ps[ 8] = ps[1]; ps[ 9] = pi + 9; ps[10] = pi + 10; ps[11] = pi + 3; diff --git a/src/core/stream.js b/src/core/stream.js index bcb72a5a9..6c226af56 100644 --- a/src/core/stream.js +++ b/src/core/stream.js @@ -330,10 +330,12 @@ var StreamsSequenceStream = (function StreamsSequenceStreamClosure() { })(); var FlateStream = (function FlateStreamClosure() { + // prettier-ignore var codeLenCodeMap = new Int32Array([ 16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15 ]); + // prettier-ignore var lengthDecode = new Int32Array([ 0x00003, 0x00004, 0x00005, 0x00006, 0x00007, 0x00008, 0x00009, 0x0000a, 0x1000b, 0x1000d, 0x1000f, 0x10011, 0x20013, 0x20017, 0x2001b, 0x2001f, @@ -341,6 +343,7 @@ var FlateStream = (function FlateStreamClosure() { 0x50083, 0x500a3, 0x500c3, 0x500e3, 0x00102, 0x00102, 0x00102 ]); + // prettier-ignore var distDecode = new Int32Array([ 0x00001, 0x00002, 0x00003, 0x00004, 0x10005, 0x10007, 0x20009, 0x2000d, 0x30011, 0x30019, 0x40021, 0x40031, 0x50041, 0x50061, 0x60081, 0x600c1, @@ -348,6 +351,7 @@ var FlateStream = (function FlateStreamClosure() { 0xb1001, 0xb1801, 0xc2001, 0xc3001, 0xd4001, 0xd6001 ]); + // prettier-ignore var fixedLitCodeTab = [new Int32Array([ 0x70100, 0x80050, 0x80010, 0x80118, 0x70110, 0x80070, 0x80030, 0x900c0, 0x70108, 0x80060, 0x80020, 0x900a0, 0x80000, 0x80080, 0x80040, 0x900e0, @@ -415,6 +419,7 @@ var FlateStream = (function FlateStreamClosure() { 0x7010f, 0x8006f, 0x8002f, 0x900bf, 0x8000f, 0x8008f, 0x8004f, 0x900ff ]), 9]; + // prettier-ignore var fixedDistCodeTab = [new Int32Array([ 0x50000, 0x50010, 0x50008, 0x50018, 0x50004, 0x50014, 0x5000c, 0x5001c, 0x50002, 0x50012, 0x5000a, 0x5001a, 0x50006, 0x50016, 0x5000e, 0x00000, diff --git a/src/display/canvas.js b/src/display/canvas.js index 3f04a2960..de20977c2 100644 --- a/src/display/canvas.js +++ b/src/display/canvas.js @@ -198,6 +198,7 @@ function compileType3Glyph(imgData) { var width = imgData.width, height = imgData.height; var i, j, j0, width1 = width + 1; var points = new Uint8Array(width1 * (height + 1)); + // prettier-ignore var POINT_TYPES = new Uint8Array([0, 2, 4, 0, 1, 0, 5, 4, 8, 10, 0, 8, 0, 2, 1, 0]); diff --git a/src/display/webgl.js b/src/display/webgl.js index 2722a0f36..80297416f 100644 --- a/src/display/webgl.js +++ b/src/display/webgl.js @@ -178,6 +178,7 @@ var WebGLUtils = (function WebGLUtilsClosure() { // provide texture coordinates for the rectangle. var texCoordBuffer = gl.createBuffer(); gl.bindBuffer(gl.ARRAY_BUFFER, texCoordBuffer); + // prettier-ignore gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([ 0.0, 0.0, 1.0, 0.0, @@ -223,6 +224,7 @@ var WebGLUtils = (function WebGLUtilsClosure() { // it (2 triangles) var buffer = gl.createBuffer(); gl.bindBuffer(gl.ARRAY_BUFFER, buffer); + // prettier-ignore gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([ 0, 0, width, 0, diff --git a/src/shared/util.js b/src/shared/util.js index a6a40ee14..437f58169 100644 --- a/src/shared/util.js +++ b/src/shared/util.js @@ -731,6 +731,7 @@ class Util { } } +// prettier-ignore const PDFStringTranslateTable = [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x2D8, 0x2C7, 0x2C6, 0x2D9, 0x2DD, 0x2DB, 0x2DA, 0x2DC, 0, 0, 0, 0, 0, 0, 0, diff --git a/test/unit/cff_parser_spec.js b/test/unit/cff_parser_spec.js index 7443b3f96..c44ad0ab5 100644 --- a/test/unit/cff_parser_spec.js +++ b/test/unit/cff_parser_spec.js @@ -120,6 +120,7 @@ describe('CFFParser', function() { it('ignores reserved commands in parseDict, and refuses to add privateDict ' + 'keys with invalid values (bug 1308536)', function () { + // prettier-ignore var bytes = new Uint8Array([ 64, 39, 31, 30, 252, 114, 137, 115, 79, 30, 197, 119, 2, 99, 127, 6 ]); @@ -137,6 +138,7 @@ describe('CFFParser', function() { }); it('parses a CharString having cntrmask', function() { + // prettier-ignore var bytes = new Uint8Array([0, 1, // count 1, // offsetSize 0, // offset[0] @@ -167,6 +169,7 @@ describe('CFFParser', function() { /* seacAnalysisEnabled = */ true); parser.parse(); // cff + // prettier-ignore var bytes = new Uint8Array([0, 1, // count 1, // offsetSize 0, // offset[0] @@ -192,6 +195,7 @@ describe('CFFParser', function() { /* seacAnalysisEnabled = */ false); parser.parse(); // cff + // prettier-ignore var bytes = new Uint8Array([0, 1, // count 1, // offsetSize 0, // offset[0] @@ -208,6 +212,7 @@ describe('CFFParser', function() { }); it('parses a CharString endchar no args', function() { + // prettier-ignore var bytes = new Uint8Array([0, 1, // count 1, // offsetSize 0, // offset[0] @@ -230,6 +235,7 @@ describe('CFFParser', function() { it('parses charset format 0', function() { // The first three bytes make the offset large enough to skip predefined. + // prettier-ignore var bytes = new Uint8Array([0x00, 0x00, 0x00, 0x00, // format 0x00, 0x02 // sid/cid @@ -245,6 +251,7 @@ describe('CFFParser', function() { it('parses charset format 1', function() { // The first three bytes make the offset large enough to skip predefined. + // prettier-ignore var bytes = new Uint8Array([0x00, 0x00, 0x00, 0x01, // format 0x00, 0x08, // sid/cid start @@ -262,6 +269,7 @@ describe('CFFParser', function() { it('parses charset format 2', function() { // format 2 is the same as format 1 but the left is card16 // The first three bytes make the offset large enough to skip predefined. + // prettier-ignore var bytes = new Uint8Array([0x00, 0x00, 0x00, 0x02, // format 0x00, 0x08, // sid/cid start @@ -278,6 +286,7 @@ describe('CFFParser', function() { it('parses encoding format 0', function() { // The first two bytes make the offset large enough to skip predefined. + // prettier-ignore var bytes = new Uint8Array([0x00, 0x00, 0x00, // format 0x01, // count @@ -290,6 +299,7 @@ describe('CFFParser', function() { it('parses encoding format 1', function() { // The first two bytes make the offset large enough to skip predefined. + // prettier-ignore var bytes = new Uint8Array([0x00, 0x00, 0x01, // format 0x01, // num ranges @@ -303,6 +313,7 @@ describe('CFFParser', function() { }); it('parses fdselect format 0', function() { + // prettier-ignore var bytes = new Uint8Array([0x00, // format 0x00, // gid: 0 fd: 0 0x01 // gid: 1 fd: 1 @@ -315,6 +326,7 @@ describe('CFFParser', function() { }); it('parses fdselect format 3', function() { + // prettier-ignore var bytes = new Uint8Array([0x03, // format 0x00, 0x02, // range count 0x00, 0x00, // first gid @@ -331,6 +343,7 @@ describe('CFFParser', function() { }); it('parses invalid fdselect format 3 (bug 1146106)', function() { + // prettier-ignore var bytes = new Uint8Array([0x03, // format 0x00, 0x02, // range count 0x00, 0x01, // first gid (invalid) diff --git a/test/unit/cmap_spec.js b/test/unit/cmap_spec.js index 2be4a8d8e..6165c2033 100644 --- a/test/unit/cmap_spec.js +++ b/test/unit/cmap_spec.js @@ -57,6 +57,7 @@ describe('cmap', function() { }); it('parses beginbfchar', function(done) { + // prettier-ignore var str = '2 beginbfchar\n' + '<03> <00>\n' + '<04> <01>\n' + @@ -73,6 +74,7 @@ describe('cmap', function() { }); }); it('parses beginbfrange with range', function(done) { + // prettier-ignore var str = '1 beginbfrange\n' + '<06> <0B> 0\n' + 'endbfrange\n'; @@ -89,6 +91,7 @@ describe('cmap', function() { }); }); it('parses beginbfrange with array', function(done) { + // prettier-ignore var str = '1 beginbfrange\n' + '<0D> <12> [ 0 1 2 3 4 5 ]\n' + 'endbfrange\n'; @@ -105,6 +108,7 @@ describe('cmap', function() { }); }); it('parses begincidchar', function(done) { + // prettier-ignore var str = '1 begincidchar\n' + '<14> 0\n' + 'endcidchar\n'; @@ -119,6 +123,7 @@ describe('cmap', function() { }); }); it('parses begincidrange', function(done) { + // prettier-ignore var str = '1 begincidrange\n' + '<0016> <001B> 0\n' + 'endcidrange\n'; @@ -135,6 +140,7 @@ describe('cmap', function() { }); }); it('decodes codespace ranges', function(done) { + // prettier-ignore var str = '1 begincodespacerange\n' + '<01> <02>\n' + '<00000003> <00000004>\n' + @@ -155,6 +161,7 @@ describe('cmap', function() { }); }); it('decodes 4 byte codespace ranges', function(done) { + // prettier-ignore var str = '1 begincodespacerange\n' + '<8EA1A1A1> <8EA1FEFE>\n' + 'endcodespacerange\n'; diff --git a/test/unit/colorspace_spec.js b/test/unit/colorspace_spec.js index 0749b9d70..c860cbf6b 100644 --- a/test/unit/colorspace_spec.js +++ b/test/unit/colorspace_spec.js @@ -62,6 +62,7 @@ describe('colorspace', function () { let testSrc = new Uint8Array([27, 125, 250, 131]); let testDest = new Uint8ClampedArray(4 * 4 * 3); + // prettier-ignore let expectedDest = new Uint8ClampedArray([ 27, 27, 27, 27, 27, 27, @@ -103,6 +104,7 @@ describe('colorspace', function () { let testSrc = new Uint8Array([27, 125, 250, 131]); let testDest = new Uint8ClampedArray(3 * 3 * 3); + // prettier-ignore let expectedDest = new Uint8ClampedArray([ 27, 27, 27, 27, 27, 27, @@ -138,6 +140,7 @@ describe('colorspace', function () { }); let colorSpace = ColorSpace.parse(cs, xref, res, pdfFunctionFactory); + // prettier-ignore let testSrc = new Uint8Array([ 27, 125, 250, 131, 139, 140, @@ -145,6 +148,7 @@ describe('colorspace', function () { 21, 147, 255 ]); let testDest = new Uint8ClampedArray(4 * 4 * 3); + // prettier-ignore let expectedDest = new Uint8ClampedArray([ 27, 125, 250, 27, 125, 250, @@ -184,6 +188,7 @@ describe('colorspace', function () { }); let colorSpace = ColorSpace.parse(cs, xref, res, pdfFunctionFactory); + // prettier-ignore let testSrc = new Uint8Array([ 27, 125, 250, 131, 139, 140, @@ -191,6 +196,7 @@ describe('colorspace', function () { 21, 147, 255 ]); let testDest = new Uint8ClampedArray(3 * 3 * 3); + // prettier-ignore let expectedDest = new Uint8ClampedArray([ 27, 125, 250, 27, 125, 250, @@ -226,6 +232,7 @@ describe('colorspace', function () { }); let colorSpace = ColorSpace.parse(cs, xref, res, pdfFunctionFactory); + // prettier-ignore let testSrc = new Uint8Array([ 27, 125, 250, 128, 131, 139, 140, 45, @@ -233,6 +240,7 @@ describe('colorspace', function () { 21, 147, 255, 69 ]); let testDest = new Uint8ClampedArray(4 * 4 * 3); + // prettier-ignore let expectedDest = new Uint8ClampedArray([ 135, 81, 18, 135, 81, 18, @@ -272,6 +280,7 @@ describe('colorspace', function () { }); let colorSpace = ColorSpace.parse(cs, xref, res, pdfFunctionFactory); + // prettier-ignore let testSrc = new Uint8Array([ 27, 125, 250, 128, 131, 139, 140, 45, @@ -279,6 +288,7 @@ describe('colorspace', function () { 21, 147, 255, 69 ]); let testDest = new Uint8ClampedArray(3 * 3 * 3); + // prettier-ignore let expectedDest = new Uint8ClampedArray([ 135, 81, 18, 135, 81, 18, @@ -324,6 +334,7 @@ describe('colorspace', function () { let testSrc = new Uint8Array([27, 125, 250, 131]); let testDest = new Uint8ClampedArray(4 * 4 * 3); + // prettier-ignore let expectedDest = new Uint8ClampedArray([ 25, 25, 25, 25, 25, 25, @@ -375,6 +386,7 @@ describe('colorspace', function () { }); let colorSpace = ColorSpace.parse(cs, xref, res, pdfFunctionFactory); + // prettier-ignore let testSrc = new Uint8Array([ 27, 125, 250, 131, 139, 140, @@ -382,6 +394,7 @@ describe('colorspace', function () { 21, 147, 255 ]); let testDest = new Uint8ClampedArray(3 * 3 * 3); + // prettier-ignore let expectedDest = new Uint8ClampedArray([ 0, 238, 255, 0, 238, 255, @@ -425,6 +438,7 @@ describe('colorspace', function () { }); let colorSpace = ColorSpace.parse(cs, xref, res, pdfFunctionFactory); + // prettier-ignore let testSrc = new Uint8Array([ 27, 25, 50, 31, 19, 40, @@ -432,6 +446,7 @@ describe('colorspace', function () { 21, 47, 55 ]); let testDest = new Uint8ClampedArray(3 * 3 * 3); + // prettier-ignore let expectedDest = new Uint8ClampedArray([ 0, 49, 101, 0, 49, 101, @@ -456,6 +471,7 @@ describe('colorspace', function () { describe('IndexedCS', function () { it('should handle the case when cs is an array', function () { + // prettier-ignore let lookup = new Uint8Array([ 23, 155, 35, 147, 69, 93, @@ -480,6 +496,7 @@ describe('colorspace', function () { let testSrc = new Uint8Array([2, 2, 0, 1]); let testDest = new Uint8ClampedArray(3 * 3 * 3); + // prettier-ignore let expectedDest = new Uint8ClampedArray([ 255, 109, 70, 255, 109, 70, @@ -536,6 +553,7 @@ describe('colorspace', function () { let testSrc = new Uint8Array([27, 25, 50, 31]); let testDest = new Uint8ClampedArray(3 * 3 * 3); + // prettier-ignore let expectedDest = new Uint8ClampedArray([ 226, 242, 241, 226, 242, 241, diff --git a/test/unit/crypto_spec.js b/test/unit/crypto_spec.js index 59e07c009..c61b51a73 100644 --- a/test/unit/crypto_spec.js +++ b/test/unit/crypto_spec.js @@ -334,6 +334,7 @@ describe('crypto', function() { alg = new PDF17(); password = new Uint8Array([117, 115, 101, 114]); userValidation = new Uint8Array([117, 169, 4, 32, 159, 101, 22, 220]); + // prettier-ignore userPassword = new Uint8Array([131, 242, 143, 160, 87, 2, 138, 134, 79, 253, 189, 173, 224, 73, 144, 241, 190, 81, 197, 15, 249, 105, 145, 151, 15, 194, 65, @@ -347,10 +348,12 @@ describe('crypto', function() { alg = new PDF17(); password = new Uint8Array([111, 119, 110, 101, 114]); ownerValidation = new Uint8Array([243, 118, 71, 153, 128, 17, 101, 62]); + // prettier-ignore ownerPassword = new Uint8Array([60, 98, 137, 35, 51, 101, 200, 152, 210, 178, 226, 228, 134, 205, 163, 24, 204, 126, 177, 36, 106, 50, 36, 125, 210, 172, 171, 120, 222, 108, 139, 115]); + // prettier-ignore uBytes = new Uint8Array([131, 242, 143, 160, 87, 2, 138, 134, 79, 253, 189, 173, 224, 73, 144, 241, 190, 81, 197, 15, 249, 105, 145, 151, 15, 194, 65, 3, 1, 126, 187, @@ -366,11 +369,13 @@ describe('crypto', function() { alg = new PDF17(); password = new Uint8Array([117, 115, 101, 114]); userKeySalt = new Uint8Array([168, 94, 215, 192, 100, 38, 188, 40]); + // prettier-ignore userEncryption = new Uint8Array([35, 150, 195, 169, 245, 51, 51, 255, 158, 158, 33, 242, 231, 75, 125, 190, 25, 126, 172, 114, 195, 244, 137, 245, 234, 165, 42, 74, 60, 38, 17, 17]); result = alg.getUserKey(password, userKeySalt, userEncryption); + // prettier-ignore expected = new Uint8Array([63, 114, 136, 209, 87, 61, 12, 30, 249, 1, 186, 144, 254, 248, 163, 153, 151, 51, 133, 10, 80, 152, 206, 15, 72, 187, 231, 33, 224, @@ -384,16 +389,19 @@ describe('crypto', function() { alg = new PDF17(); password = new Uint8Array([111, 119, 110, 101, 114]); ownerKeySalt = new Uint8Array([200, 245, 242, 12, 218, 123, 24, 120]); + // prettier-ignore ownerEncryption = new Uint8Array([213, 202, 14, 189, 110, 76, 70, 191, 6, 195, 10, 190, 157, 100, 144, 85, 8, 62, 123, 178, 156, 229, 50, 40, 229, 216, 54, 222, 34, 38, 106, 223]); + // prettier-ignore uBytes = new Uint8Array([131, 242, 143, 160, 87, 2, 138, 134, 79, 253, 189, 173, 224, 73, 144, 241, 190, 81, 197, 15, 249, 105, 145, 151, 15, 194, 65, 3, 1, 126, 187, 221, 117, 169, 4, 32, 159, 101, 22, 220, 168, 94, 215, 192, 100, 38, 188, 40]); result = alg.getOwnerKey(password, ownerKeySalt, uBytes, ownerEncryption); + // prettier-ignore expected = new Uint8Array([63, 114, 136, 209, 87, 61, 12, 30, 249, 1, 186, 144, 254, 248, 163, 153, 151, 51, 133, 10, 80, 152, 206, 15, 72, 187, 231, 33, 224, @@ -408,6 +416,7 @@ describe('crypto', function() { alg = new PDF20(); password = new Uint8Array([117, 115, 101, 114]); userValidation = new Uint8Array([83, 245, 146, 101, 198, 247, 34, 198]); + // prettier-ignore userPassword = new Uint8Array([94, 230, 205, 75, 166, 99, 250, 76, 219, 128, 17, 85, 57, 17, 33, 164, 150, 46, 103, 176, 160, 156, 187, 233, 166, 223, @@ -421,10 +430,12 @@ describe('crypto', function() { alg = new PDF20(); password = new Uint8Array([111, 119, 110, 101, 114]); ownerValidation = new Uint8Array([142, 232, 169, 208, 202, 214, 5, 185]); + // prettier-ignore ownerPassword = new Uint8Array([88, 232, 62, 54, 245, 26, 245, 209, 137, 123, 221, 72, 199, 49, 37, 217, 31, 74, 115, 167, 127, 158, 176, 77, 45, 163, 87, 47, 39, 90, 217, 141]); + // prettier-ignore uBytes = new Uint8Array([94, 230, 205, 75, 166, 99, 250, 76, 219, 128, 17, 85, 57, 17, 33, 164, 150, 46, 103, 176, 160, 156, 187, 233, 166, 223, 163, 253, 147, 235, 95, @@ -440,11 +451,13 @@ describe('crypto', function() { alg = new PDF20(); password = new Uint8Array([117, 115, 101, 114]); userKeySalt = new Uint8Array([191, 11, 16, 94, 237, 216, 20, 175]); + // prettier-ignore userEncryption = new Uint8Array([121, 208, 2, 181, 230, 89, 156, 60, 253, 143, 212, 28, 84, 180, 196, 177, 173, 128, 221, 107, 46, 20, 94, 186, 135, 51, 95, 24, 20, 223, 254, 36]); result = alg.getUserKey(password, userKeySalt, userEncryption); + // prettier-ignore expected = new Uint8Array([42, 218, 213, 39, 73, 91, 72, 79, 67, 38, 248, 133, 18, 189, 61, 34, 107, 79, 29, 56, 59, 181, 213, 118, 113, 34, 65, 210, 87, 174, 22, @@ -458,16 +471,19 @@ describe('crypto', function() { alg = new PDF20(); password = new Uint8Array([111, 119, 110, 101, 114]); ownerKeySalt = new Uint8Array([29, 208, 185, 46, 11, 76, 135, 149]); + // prettier-ignore ownerEncryption = new Uint8Array([209, 73, 224, 77, 103, 155, 201, 181, 190, 68, 223, 20, 62, 90, 56, 210, 5, 240, 178, 128, 238, 124, 68, 254, 253, 244, 62, 108, 208, 135, 10, 251]); + // prettier-ignore uBytes = new Uint8Array([94, 230, 205, 75, 166, 99, 250, 76, 219, 128, 17, 85, 57, 17, 33, 164, 150, 46, 103, 176, 160, 156, 187, 233, 166, 223, 163, 253, 147, 235, 95, 184, 83, 245, 146, 101, 198, 247, 34, 198, 191, 11, 16, 94, 237, 216, 20, 175]); result = alg.getOwnerKey(password, ownerKeySalt, uBytes, ownerEncryption); + // prettier-ignore expected = new Uint8Array([42, 218, 213, 39, 73, 91, 72, 79, 67, 38, 248, 133, 18, 189, 61, 34, 107, 79, 29, 56, 59, 181, 213, 118, 113, 34, 65, 210, 87, 174, 22, diff --git a/test/unit/parser_spec.js b/test/unit/parser_spec.js index 721cb7b29..905cfdfe9 100644 --- a/test/unit/parser_spec.js +++ b/test/unit/parser_spec.js @@ -214,6 +214,7 @@ describe('parser', function() { describe('Linearization', function() { it('should not find a linearization dictionary', function() { // Not an actual linearization dictionary. + // prettier-ignore const stream1 = new StringStream( '3 0 obj\n' + '<<\n' + @@ -225,6 +226,7 @@ describe('parser', function() { expect(Linearization.create(stream1)).toEqual(null); // Linearization dictionary with invalid version number. + // prettier-ignore const stream2 = new StringStream( '1 0 obj\n' + '<<\n' + @@ -236,6 +238,7 @@ describe('parser', function() { }); it('should accept a valid linearization dictionary', function() { + // prettier-ignore const stream = new StringStream( '131 0 obj\n' + '<<\n' + @@ -264,6 +267,7 @@ describe('parser', function() { it('should reject a linearization dictionary with invalid ' + 'integer parameters', function() { // The /L parameter should be equal to the stream length. + // prettier-ignore const stream1 = new StringStream( '1 0 obj\n' + '<<\n' + @@ -283,6 +287,7 @@ describe('parser', function() { 'dictionary does not equal the stream length.')); // The /E parameter should not be zero. + // prettier-ignore const stream2 = new StringStream( '1 0 obj\n' + '<<\n' + @@ -302,6 +307,7 @@ describe('parser', function() { 'dictionary is invalid.')); // The /O parameter should be an integer. + // prettier-ignore const stream3 = new StringStream( '1 0 obj\n' + '<<\n' + @@ -324,6 +330,7 @@ describe('parser', function() { it('should reject a linearization dictionary with invalid hint parameters', function() { // The /H parameter should be an array. + // prettier-ignore const stream1 = new StringStream( '1 0 obj\n' + '<<\n' + @@ -343,6 +350,7 @@ describe('parser', function() { 'is invalid.')); // The hint array should contain two, or four, elements. + // prettier-ignore const stream2 = new StringStream( '1 0 obj\n' + '<<\n' + @@ -362,6 +370,7 @@ describe('parser', function() { 'is invalid.')); // The hint array should not contain zero. + // prettier-ignore const stream3 = new StringStream( '1 0 obj\n' + '<<\n' + From de36b2aabab2b7fd647d9591f959c4540129541d Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Wed, 25 Dec 2019 15:59:37 +0100 Subject: [PATCH 2/3] Enable auto-formatting of the entire code-base using Prettier (issue 11444) Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes). Prettier is being used for a couple of reasons: - To be consistent with `mozilla-central`, where Prettier is already in use across the tree. - To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters. Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some). Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long. *Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit. (On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.) --- .eslintrc | 51 +- .prettierrc | 8 + examples/acroforms/acroforms.js | 43 +- examples/browserify/gulpfile.js | 52 +- examples/browserify/main.js | 40 +- examples/browserify/worker.js | 6 +- examples/components/pageviewer.js | 19 +- examples/components/simpleviewer.js | 26 +- examples/components/singlepageviewer.js | 26 +- examples/image_decoders/jpeg_viewer.js | 28 +- examples/mobile-viewer/viewer.js | 295 +- examples/node/domstubs.js | 104 +- examples/node/getinfo.js | 100 +- examples/node/pdf2png/pdf2png.js | 81 +- examples/node/pdf2svg.js | 99 +- examples/svgviewer/viewer.js | 21 +- examples/text-only/pdf2svg.js | 45 +- examples/webpack/main.js | 40 +- examples/webpack/webpack.config.js | 16 +- extensions/chromium/contentscript.js | 82 +- extensions/chromium/extension-router.js | 100 +- extensions/chromium/options/migration.js | 144 +- extensions/chromium/options/options.js | 196 +- extensions/chromium/pageAction/background.js | 8 +- extensions/chromium/pageAction/popup.js | 2 +- extensions/chromium/pdfHandler-vcros.js | 46 +- extensions/chromium/pdfHandler.js | 143 +- extensions/chromium/preserve-referer.js | 83 +- extensions/chromium/restoretab.js | 4 +- extensions/chromium/suppress-update.js | 8 +- extensions/chromium/telemetry.js | 38 +- extensions/firefox/tools/l10n.js | 2 +- external/builder/builder.js | 153 +- external/builder/preprocessor2.js | 252 +- external/builder/test-fixtures.js | 50 +- external/builder/test-fixtures_esprima.js | 56 +- external/dist/webpack.js | 8 +- external/importL10n/locales.js | 64 +- external/systemjs/plugin-babel-cached.js | 125 +- external/webpack/pdfjsdev-loader.js | 13 +- gulpfile.js | 2028 ++-- src/core/annotation.js | 465 +- src/core/arithmetic_decoder.js | 127 +- src/core/bidi.js | 181 +- src/core/ccitt.js | 144 +- src/core/ccitt_stream.js | 24 +- src/core/cff_parser.js | 880 +- src/core/charsets.js | 188 +- src/core/chunked_stream.js | 51 +- src/core/cmap.js | 562 +- src/core/colorspace.js | 656 +- src/core/core_utils.js | 37 +- src/core/crypto.js | 661 +- src/core/document.js | 437 +- src/core/encodings.js | 484 +- src/core/evaluator.js | 2264 +++-- src/core/font_renderer.js | 384 +- src/core/fonts.js | 1895 ++-- src/core/function.js | 552 +- src/core/glyphlist.js | 9056 +++++++++--------- src/core/image.js | 365 +- src/core/image_utils.js | 88 +- src/core/jbig2.js | 1382 ++- src/core/jbig2_stream.js | 24 +- src/core/jpeg_stream.js | 27 +- src/core/jpg.js | 546 +- src/core/jpx.js | 631 +- src/core/jpx_stream.js | 14 +- src/core/metrics.js | 5860 ++++++------ src/core/murmurhash3.js | 72 +- src/core/obj.js | 990 +- src/core/operator_list.js | 266 +- src/core/parser.js | 647 +- src/core/pattern.js | 415 +- src/core/pdf_manager.js | 42 +- src/core/primitives.js | 31 +- src/core/ps_parser.js | 107 +- src/core/standard_fonts.js | 1048 +- src/core/stream.js | 234 +- src/core/type1_parser.js | 240 +- src/core/unicode.js | 3075 +++--- src/core/worker.js | 581 +- src/core/worker_stream.js | 39 +- src/display/annotation_layer.js | 457 +- src/display/api.js | 1140 ++- src/display/api_compatibility.js | 8 +- src/display/canvas.js | 835 +- src/display/content_disposition.js | 65 +- src/display/display_utils.js | 307 +- src/display/fetch_stream.js | 114 +- src/display/font_loader.js | 503 +- src/display/metadata.js | 96 +- src/display/network.js | 103 +- src/display/network_utils.js | 43 +- src/display/node_stream.js | 129 +- src/display/pattern_helper.js | 276 +- src/display/svg.js | 2978 +++--- src/display/text_layer.js | 191 +- src/display/transport_stream.js | 45 +- src/display/webgl.js | 142 +- src/display/worker_options.js | 16 +- src/display/xml_parser.js | 156 +- src/interfaces.js | 6 +- src/pdf.image_decoders.js | 20 +- src/pdf.js | 62 +- src/pdf.worker.entry.js | 6 +- src/pdf.worker.js | 8 +- src/shared/compatibility.js | 667 +- src/shared/is_node.js | 11 +- src/shared/message_handler.js | 424 +- src/shared/util.js | 243 +- src/worker_loader.js | 12 +- systemjs.config.js | 67 +- test/add_test.js | 55 +- test/chromium/test-telemetry.js | 267 +- test/downloadutils.js | 187 +- test/driver.js | 522 +- test/font/fontutils.js | 52 +- test/font/jasmine-boot.js | 45 +- test/font/ttxdriver.js | 58 +- test/stats/statcmp.js | 101 +- test/test.js | 615 +- test/testutils.js | 31 +- test/unit/annotation_spec.js | 2510 ++--- test/unit/api_spec.js | 2373 +++-- test/unit/bidi_spec.js | 20 +- test/unit/cff_parser_spec.js | 199 +- test/unit/clitests_helper.js | 14 +- test/unit/cmap_spec.js | 439 +- test/unit/colorspace_spec.js | 307 +- test/unit/core_utils_spec.js | 197 +- test/unit/crypto_spec.js | 642 +- test/unit/custom_spec.js | 73 +- test/unit/display_svg_spec.js | 141 +- test/unit/display_utils_spec.js | 241 +- test/unit/document_spec.js | 26 +- test/unit/encodings_spec.js | 24 +- test/unit/evaluator_spec.js | 494 +- test/unit/fetch_stream_spec.js | 65 +- test/unit/function_spec.js | 551 +- test/unit/jasmine-boot.js | 133 +- test/unit/message_handler_spec.js | 614 +- test/unit/metadata_spec.js | 293 +- test/unit/murmurhash3_spec.js | 22 +- test/unit/network_spec.js | 90 +- test/unit/network_utils_spec.js | 561 +- test/unit/node_stream_spec.js | 206 +- test/unit/parser_spec.js | 406 +- test/unit/pdf_find_controller_spec.js | 60 +- test/unit/pdf_find_utils_spec.js | 56 +- test/unit/pdf_history_spec.js | 64 +- test/unit/primitives_spec.js | 331 +- test/unit/stream_spec.js | 39 +- test/unit/test_utils.js | 56 +- test/unit/testreporter.js | 34 +- test/unit/type1_parser_spec.js | 110 +- test/unit/ui_utils_spec.js | 780 +- test/unit/unicode_spec.js | 109 +- test/unit/util_spec.js | 298 +- test/webbrowser.js | 248 +- test/webserver.js | 212 +- web/annotation_layer_builder.js | 45 +- web/app.js | 1776 ++-- web/app_options.js | 61 +- web/base_viewer.js | 582 +- web/chromecom.js | 153 +- web/debugger.js | 287 +- web/download_manager.js | 42 +- web/firefox_print_service.js | 90 +- web/firefoxcom.js | 178 +- web/genericcom.js | 26 +- web/genericl10n.js | 6 +- web/grab_to_pan.js | 47 +- web/interfaces.js | 26 +- web/overlay_manager.js | 47 +- web/password_prompt.js | 43 +- web/pdf_attachment_viewer.js | 63 +- web/pdf_cursor_tools.js | 23 +- web/pdf_document_properties.js | 305 +- web/pdf_find_bar.js | 141 +- web/pdf_find_controller.js | 203 +- web/pdf_find_utils.js | 48 +- web/pdf_history.js | 246 +- web/pdf_link_service.js | 226 +- web/pdf_outline_viewer.js | 75 +- web/pdf_page_view.js | 299 +- web/pdf_presentation_mode.js | 167 +- web/pdf_print_service.js | 232 +- web/pdf_rendering_queue.js | 11 +- web/pdf_sidebar.js | 120 +- web/pdf_sidebar_resizer.js | 57 +- web/pdf_single_page_viewer.js | 33 +- web/pdf_thumbnail_view.js | 247 +- web/pdf_thumbnail_viewer.js | 125 +- web/pdf_viewer.component.js | 37 +- web/pdf_viewer.js | 25 +- web/pdfjs.js | 8 +- web/preferences.js | 86 +- web/secondary_toolbar.js | 227 +- web/text_layer_builder.js | 186 +- web/toolbar.js | 144 +- web/ui_utils.js | 255 +- web/view_history.js | 32 +- web/viewer.js | 262 +- web/viewer_compatibility.js | 13 +- 205 files changed, 40024 insertions(+), 31859 deletions(-) create mode 100644 .prettierrc diff --git a/.eslintrc b/.eslintrc index 2bbb0d3ce..1e1aff530 100644 --- a/.eslintrc +++ b/.eslintrc @@ -11,6 +11,10 @@ "unicorn", ], + "extends": [ + "plugin:prettier/recommended" + ], + "env": { "browser": true, "es6": true, @@ -47,7 +51,6 @@ "no-empty": ["error", { "allowEmptyCatch": true, }], "no-ex-assign": "error", "no-extra-boolean-cast": "error", - "no-extra-semi": "error", "no-func-assign": "error", "no-inner-declarations": ["error", "functions"], "no-invalid-regexp": "error", @@ -84,9 +87,6 @@ "no-implied-eval": "error", "no-iterator": "error", "no-lone-blocks": "error", - "no-multi-spaces": ["error", { - "ignoreEOLComments": true, - }], "no-multi-str": "error", "no-new-func": "error", "no-new-wrappers": "error", @@ -127,48 +127,16 @@ }], // Stylistic Issues - "array-bracket-spacing": ["error", "never"], - "block-spacing": ["error", "always"], - "brace-style": ["error", "1tbs", { - "allowSingleLine": false, - }], - "comma-dangle": ["error", { - "arrays": "ignore", - "objects": "always", - "imports": "never", - "exports": "always", - "functions": "never", - }], - "comma-spacing": ["error", { "before": false, "after": true, }], - "comma-style": ["error", "last"], - "eol-last": "error", - "func-call-spacing": ["error", "never"], - "key-spacing": ["error", { "beforeColon": false, "afterColon": true, "mode": "strict", }], - "keyword-spacing": ["error", { "before": true, "after": true, }], - "linebreak-style": ["error", "unix"], "lines-between-class-members": ["error", "always"], "max-len": ["error", { - "code": 80, + "code": 1000, + "comments": 80, "ignoreUrls": true }], "new-cap": ["error", { "newIsCap": true, "capIsNew": false, }], - "new-parens": "error", "no-array-constructor": "error", "no-multiple-empty-lines": ["error", { "max": 1, "maxEOF": 0, "maxBOF": 1, }], "no-new-object": "error", - "no-tabs": "error", - "no-trailing-spaces": ["error", { "skipBlankLines": false, }], - "no-whitespace-before-property": "error", - "object-curly-spacing": ["error", "always"], - "operator-linebreak": ["error", "after", { "overrides": { ":": "ignore", } }], - "quotes": ["error", "single"], - "semi-spacing": ["error", { "before": false, "after": true, }], - "semi": ["error", "always"], - "space-before-blocks": ["error", "always"], - "space-before-function-paren": ["error", { "anonymous": "ignore", "named": "never", }], - "space-in-parens": ["error", "never"], - "space-infix-ops": ["error", { "int32Hint": false }], - "space-unary-ops": ["error", { "words": true, "nonwords": false, }], "spaced-comment": ["error", "always", { "block": { "balanced": true, @@ -176,12 +144,6 @@ }], // ECMAScript 6 - "arrow-body-style": ["error", "always"], - "arrow-parens": ["error", "always"], - "arrow-spacing": ["error", { - "before": true, - "after": true, - }], "constructor-super": "error", "no-class-assign": "error", "no-confusing-arrow": "error", @@ -197,7 +159,6 @@ "avoidQuotes": true, }], "prefer-const": "off", - "rest-spread-spacing": ["error", "never"], "sort-imports": ["error", { "ignoreCase": true, }], diff --git a/.prettierrc b/.prettierrc new file mode 100644 index 000000000..f5289b11c --- /dev/null +++ b/.prettierrc @@ -0,0 +1,8 @@ +{ + "endOfLine": "lf", + "printWidth": 80, + "semi": true, + "tabWidth": 2, + "trailingComma": "es5", + "useTabs": false +} diff --git a/examples/acroforms/acroforms.js b/examples/acroforms/acroforms.js index 125c3aa83..75a0c8650 100644 --- a/examples/acroforms/acroforms.js +++ b/examples/acroforms/acroforms.js @@ -13,15 +13,15 @@ * limitations under the License. */ -'use strict'; +"use strict"; pdfjsLib.GlobalWorkerOptions.workerSrc = - '../../node_modules/pdfjs-dist/build/pdf.worker.js'; + "../../node_modules/pdfjs-dist/build/pdf.worker.js"; -var DEFAULT_URL = '../../test/pdfs/f1040.pdf'; +var DEFAULT_URL = "../../test/pdfs/f1040.pdf"; var DEFAULT_SCALE = 1.0; -var container = document.getElementById('pageContainer'); +var container = document.getElementById("pageContainer"); // Fetch the PDF document from the URL using promises. var loadingTask = pdfjsLib.getDocument(DEFAULT_URL); @@ -30,23 +30,24 @@ loadingTask.promise.then(function(doc) { var promise = Promise.resolve(); for (var i = 1; i <= doc.numPages; i++) { - promise = promise.then(function (pageNum) { - return doc.getPage(pageNum).then(function (pdfPage) { - // Create the page view. - var pdfPageView = new pdfjsViewer.PDFPageView({ - container: container, - id: pageNum, - scale: DEFAULT_SCALE, - defaultViewport: pdfPage.getViewport({ scale: DEFAULT_SCALE, }), - annotationLayerFactory: - new pdfjsViewer.DefaultAnnotationLayerFactory(), - renderInteractiveForms: true, - }); + promise = promise.then( + function(pageNum) { + return doc.getPage(pageNum).then(function(pdfPage) { + // Create the page view. + var pdfPageView = new pdfjsViewer.PDFPageView({ + container: container, + id: pageNum, + scale: DEFAULT_SCALE, + defaultViewport: pdfPage.getViewport({ scale: DEFAULT_SCALE }), + annotationLayerFactory: new pdfjsViewer.DefaultAnnotationLayerFactory(), + renderInteractiveForms: true, + }); - // Associate the actual page with the view and draw it. - pdfPageView.setPdfPage(pdfPage); - return pdfPageView.draw(); - }); - }.bind(null, i)); + // Associate the actual page with the view and draw it. + pdfPageView.setPdfPage(pdfPage); + return pdfPageView.draw(); + }); + }.bind(null, i) + ); } }); diff --git a/examples/browserify/gulpfile.js b/examples/browserify/gulpfile.js index 0d382c532..241f97f43 100644 --- a/examples/browserify/gulpfile.js +++ b/examples/browserify/gulpfile.js @@ -1,36 +1,40 @@ -var gulp = require('gulp'); -var browserify = require('browserify'); -var streamify = require('gulp-streamify'); -var rename = require('gulp-rename'); -var uglify = require('gulp-uglify'); -var source = require('vinyl-source-stream'); +var gulp = require("gulp"); +var browserify = require("browserify"); +var streamify = require("gulp-streamify"); +var rename = require("gulp-rename"); +var uglify = require("gulp-uglify"); +var source = require("vinyl-source-stream"); -var OUTPUT_PATH = '../../build/browserify'; -var TMP_FILE_PREFIX = '../../build/browserify_'; +var OUTPUT_PATH = "../../build/browserify"; +var TMP_FILE_PREFIX = "../../build/browserify_"; -gulp.task('build-bundle', function() { - return browserify('main.js', { output: TMP_FILE_PREFIX + 'main.tmp', }) - .ignore(require.resolve('pdfjs-dist/build/pdf.worker')) // Reducing size +gulp.task("build-bundle", function() { + return browserify("main.js", { output: TMP_FILE_PREFIX + "main.tmp" }) + .ignore(require.resolve("pdfjs-dist/build/pdf.worker")) // Reducing size .bundle() - .pipe(source(TMP_FILE_PREFIX + 'main.tmp')) + .pipe(source(TMP_FILE_PREFIX + "main.tmp")) .pipe(streamify(uglify())) - .pipe(rename('main.bundle.js')) + .pipe(rename("main.bundle.js")) .pipe(gulp.dest(OUTPUT_PATH)); }); -gulp.task('build-worker', function() { +gulp.task("build-worker", function() { // We can create our own viewer (see worker.js) or use already defined one. - var workerSrc = require.resolve('pdfjs-dist/build/pdf.worker.entry'); - return browserify(workerSrc, { output: TMP_FILE_PREFIX + 'worker.tmp', }) + var workerSrc = require.resolve("pdfjs-dist/build/pdf.worker.entry"); + return browserify(workerSrc, { output: TMP_FILE_PREFIX + "worker.tmp" }) .bundle() - .pipe(source(TMP_FILE_PREFIX + 'worker.tmp')) - .pipe(streamify(uglify({ - compress: { - sequences: false, // Chrome has issue with the generated code if true - }, - }))) - .pipe(rename('pdf.worker.bundle.js')) + .pipe(source(TMP_FILE_PREFIX + "worker.tmp")) + .pipe( + streamify( + uglify({ + compress: { + sequences: false, // Chrome has issue with the generated code if true + }, + }) + ) + ) + .pipe(rename("pdf.worker.bundle.js")) .pipe(gulp.dest(OUTPUT_PATH)); }); -gulp.task('build', gulp.series('build-bundle', 'build-worker')); +gulp.task("build", gulp.series("build-bundle", "build-worker")); diff --git a/examples/browserify/main.js b/examples/browserify/main.js index 8554ffc9b..644a10140 100644 --- a/examples/browserify/main.js +++ b/examples/browserify/main.js @@ -3,31 +3,33 @@ // Hello world example for browserify. -var pdfjsLib = require('pdfjs-dist'); +var pdfjsLib = require("pdfjs-dist"); -var pdfPath = '../learning/helloworld.pdf'; +var pdfPath = "../learning/helloworld.pdf"; // Setting worker path to worker bundle. pdfjsLib.GlobalWorkerOptions.workerSrc = - '../../build/browserify/pdf.worker.bundle.js'; + "../../build/browserify/pdf.worker.bundle.js"; // Loading a document. var loadingTask = pdfjsLib.getDocument(pdfPath); -loadingTask.promise.then(function (pdfDocument) { - // Request a first page - return pdfDocument.getPage(1).then(function (pdfPage) { - // Display page on the existing canvas with 100% scale. - var viewport = pdfPage.getViewport({ scale: 1.0, }); - var canvas = document.getElementById('theCanvas'); - canvas.width = viewport.width; - canvas.height = viewport.height; - var ctx = canvas.getContext('2d'); - var renderTask = pdfPage.render({ - canvasContext: ctx, - viewport: viewport, +loadingTask.promise + .then(function(pdfDocument) { + // Request a first page + return pdfDocument.getPage(1).then(function(pdfPage) { + // Display page on the existing canvas with 100% scale. + var viewport = pdfPage.getViewport({ scale: 1.0 }); + var canvas = document.getElementById("theCanvas"); + canvas.width = viewport.width; + canvas.height = viewport.height; + var ctx = canvas.getContext("2d"); + var renderTask = pdfPage.render({ + canvasContext: ctx, + viewport: viewport, + }); + return renderTask.promise; }); - return renderTask.promise; + }) + .catch(function(reason) { + console.error("Error: " + reason); }); -}).catch(function (reason) { - console.error('Error: ' + reason); -}); diff --git a/examples/browserify/worker.js b/examples/browserify/worker.js index edad61c61..3ae28b39f 100644 --- a/examples/browserify/worker.js +++ b/examples/browserify/worker.js @@ -3,5 +3,7 @@ // Hello world example for browserify: worker bundle. -(typeof window !== 'undefined' ? window : {}).pdfjsWorker = - require('pdfjs-dist/build/pdf.worker'); +(typeof window !== "undefined" + ? window + : {} +).pdfjsWorker = require("pdfjs-dist/build/pdf.worker"); diff --git a/examples/components/pageviewer.js b/examples/components/pageviewer.js index d58f4ccb4..626561c5a 100644 --- a/examples/components/pageviewer.js +++ b/examples/components/pageviewer.js @@ -13,28 +13,29 @@ * limitations under the License. */ -'use strict'; +"use strict"; if (!pdfjsLib.getDocument || !pdfjsViewer.PDFPageView) { - alert('Please build the pdfjs-dist library using\n' + - ' `gulp dist-install`'); + alert( + "Please build the pdfjs-dist library using\n" + " `gulp dist-install`" + ); } // The workerSrc property shall be specified. // pdfjsLib.GlobalWorkerOptions.workerSrc = - '../../node_modules/pdfjs-dist/build/pdf.worker.js'; + "../../node_modules/pdfjs-dist/build/pdf.worker.js"; // Some PDFs need external cmaps. // -var CMAP_URL = '../../node_modules/pdfjs-dist/cmaps/'; +var CMAP_URL = "../../node_modules/pdfjs-dist/cmaps/"; var CMAP_PACKED = true; -var DEFAULT_URL = '../../web/compressed.tracemonkey-pldi-09.pdf'; +var DEFAULT_URL = "../../web/compressed.tracemonkey-pldi-09.pdf"; var PAGE_TO_VIEW = 1; var SCALE = 1.0; -var container = document.getElementById('pageContainer'); +var container = document.getElementById("pageContainer"); // Loading document. var loadingTask = pdfjsLib.getDocument({ @@ -44,13 +45,13 @@ var loadingTask = pdfjsLib.getDocument({ }); loadingTask.promise.then(function(pdfDocument) { // Document loaded, retrieving the page. - return pdfDocument.getPage(PAGE_TO_VIEW).then(function (pdfPage) { + return pdfDocument.getPage(PAGE_TO_VIEW).then(function(pdfPage) { // Creating the page view with default parameters. var pdfPageView = new pdfjsViewer.PDFPageView({ container: container, id: PAGE_TO_VIEW, scale: SCALE, - defaultViewport: pdfPage.getViewport({ scale: SCALE, }), + defaultViewport: pdfPage.getViewport({ scale: SCALE }), // We can enable text/annotations layers, if needed textLayerFactory: new pdfjsViewer.DefaultTextLayerFactory(), annotationLayerFactory: new pdfjsViewer.DefaultAnnotationLayerFactory(), diff --git a/examples/components/simpleviewer.js b/examples/components/simpleviewer.js index 5a87a4028..3bc1f6a94 100644 --- a/examples/components/simpleviewer.js +++ b/examples/components/simpleviewer.js @@ -13,27 +13,28 @@ * limitations under the License. */ -'use strict'; +"use strict"; if (!pdfjsLib.getDocument || !pdfjsViewer.PDFViewer) { - alert('Please build the pdfjs-dist library using\n' + - ' `gulp dist-install`'); + alert( + "Please build the pdfjs-dist library using\n" + " `gulp dist-install`" + ); } // The workerSrc property shall be specified. // pdfjsLib.GlobalWorkerOptions.workerSrc = - '../../node_modules/pdfjs-dist/build/pdf.worker.js'; + "../../node_modules/pdfjs-dist/build/pdf.worker.js"; // Some PDFs need external cmaps. // -var CMAP_URL = '../../node_modules/pdfjs-dist/cmaps/'; +var CMAP_URL = "../../node_modules/pdfjs-dist/cmaps/"; var CMAP_PACKED = true; -var DEFAULT_URL = '../../web/compressed.tracemonkey-pldi-09.pdf'; -var SEARCH_FOR = ''; // try 'Mozilla'; +var DEFAULT_URL = "../../web/compressed.tracemonkey-pldi-09.pdf"; +var SEARCH_FOR = ""; // try 'Mozilla'; -var container = document.getElementById('viewerContainer'); +var container = document.getElementById("viewerContainer"); // (Optionally) enable hyperlinks within PDF files. var pdfLinkService = new pdfjsViewer.PDFLinkService(); @@ -50,12 +51,13 @@ var pdfViewer = new pdfjsViewer.PDFViewer({ }); pdfLinkService.setViewer(pdfViewer); -document.addEventListener('pagesinit', function () { +document.addEventListener("pagesinit", function() { // We can use pdfViewer now, e.g. let's change default scale. - pdfViewer.currentScaleValue = 'page-width'; + pdfViewer.currentScaleValue = "page-width"; - if (SEARCH_FOR) { // We can try search for things - pdfFindController.executeCommand('find', { query: SEARCH_FOR, }); + if (SEARCH_FOR) { + // We can try search for things + pdfFindController.executeCommand("find", { query: SEARCH_FOR }); } }); diff --git a/examples/components/singlepageviewer.js b/examples/components/singlepageviewer.js index d6157f4b1..6ab8cc9e2 100644 --- a/examples/components/singlepageviewer.js +++ b/examples/components/singlepageviewer.js @@ -13,27 +13,28 @@ * limitations under the License. */ -'use strict'; +"use strict"; if (!pdfjsLib.getDocument || !pdfjsViewer.PDFSinglePageViewer) { - alert('Please build the pdfjs-dist library using\n' + - ' `gulp dist-install`'); + alert( + "Please build the pdfjs-dist library using\n" + " `gulp dist-install`" + ); } // The workerSrc property shall be specified. // pdfjsLib.GlobalWorkerOptions.workerSrc = - '../../node_modules/pdfjs-dist/build/pdf.worker.js'; + "../../node_modules/pdfjs-dist/build/pdf.worker.js"; // Some PDFs need external cmaps. // -var CMAP_URL = '../../node_modules/pdfjs-dist/cmaps/'; +var CMAP_URL = "../../node_modules/pdfjs-dist/cmaps/"; var CMAP_PACKED = true; -var DEFAULT_URL = '../../web/compressed.tracemonkey-pldi-09.pdf'; -var SEARCH_FOR = ''; // try 'Mozilla'; +var DEFAULT_URL = "../../web/compressed.tracemonkey-pldi-09.pdf"; +var SEARCH_FOR = ""; // try 'Mozilla'; -var container = document.getElementById('viewerContainer'); +var container = document.getElementById("viewerContainer"); // (Optionally) enable hyperlinks within PDF files. var pdfLinkService = new pdfjsViewer.PDFLinkService(); @@ -50,12 +51,13 @@ var pdfSinglePageViewer = new pdfjsViewer.PDFSinglePageViewer({ }); pdfLinkService.setViewer(pdfSinglePageViewer); -document.addEventListener('pagesinit', function () { +document.addEventListener("pagesinit", function() { // We can use pdfSinglePageViewer now, e.g. let's change default scale. - pdfSinglePageViewer.currentScaleValue = 'page-width'; + pdfSinglePageViewer.currentScaleValue = "page-width"; - if (SEARCH_FOR) { // We can try search for things - pdfFindController.executeCommand('find', { query: SEARCH_FOR, }); + if (SEARCH_FOR) { + // We can try search for things + pdfFindController.executeCommand("find", { query: SEARCH_FOR }); } }); diff --git a/examples/image_decoders/jpeg_viewer.js b/examples/image_decoders/jpeg_viewer.js index 5e2eae152..e84307cf9 100644 --- a/examples/image_decoders/jpeg_viewer.js +++ b/examples/image_decoders/jpeg_viewer.js @@ -13,39 +13,40 @@ * limitations under the License. */ -'use strict'; +"use strict"; if (!pdfjsImageDecoders.JpegImage) { - alert('Please build the pdfjs-dist library using `gulp dist-install`'); + alert("Please build the pdfjs-dist library using `gulp dist-install`"); } -var JPEG_IMAGE = 'fish.jpg'; +var JPEG_IMAGE = "fish.jpg"; -var jpegCanvas = document.getElementById('jpegCanvas'); -var jpegCtx = jpegCanvas.getContext('2d'); +var jpegCanvas = document.getElementById("jpegCanvas"); +var jpegCtx = jpegCanvas.getContext("2d"); // Load the image data, and convert it to a Uint8Array. // var nonBinaryRequest = false; var request = new XMLHttpRequest(); -request.open('GET', JPEG_IMAGE, false); +request.open("GET", JPEG_IMAGE, false); try { - request.responseType = 'arraybuffer'; - nonBinaryRequest = request.responseType !== 'arraybuffer'; + request.responseType = "arraybuffer"; + nonBinaryRequest = request.responseType !== "arraybuffer"; } catch (e) { nonBinaryRequest = true; } if (nonBinaryRequest && request.overrideMimeType) { - request.overrideMimeType('text/plain; charset=x-user-defined'); + request.overrideMimeType("text/plain; charset=x-user-defined"); } request.send(null); var typedArrayImage; if (nonBinaryRequest) { - var str = request.responseText, length = str.length; + var str = request.responseText, + length = str.length; var bytes = new Uint8Array(length); for (var i = 0; i < length; ++i) { - bytes[i] = str.charCodeAt(i) & 0xFF; + bytes[i] = str.charCodeAt(i) & 0xff; } typedArrayImage = bytes; } else { @@ -57,7 +58,8 @@ if (nonBinaryRequest) { var jpegImage = new pdfjsImageDecoders.JpegImage(); jpegImage.parse(typedArrayImage); -var width = jpegImage.width, height = jpegImage.height; +var width = jpegImage.width, + height = jpegImage.height; var jpegData = jpegImage.getData({ width: width, height: height, @@ -68,7 +70,7 @@ var jpegData = jpegImage.getData({ // var imageData = jpegCtx.createImageData(width, height); var imageBytes = imageData.data; -for (var j = 0, k = 0, jj = width * height * 4; j < jj;) { +for (var j = 0, k = 0, jj = width * height * 4; j < jj; ) { imageBytes[j++] = jpegData[k++]; imageBytes[j++] = jpegData[k++]; imageBytes[j++] = jpegData[k++]; diff --git a/examples/mobile-viewer/viewer.js b/examples/mobile-viewer/viewer.js index 099c5b285..e875f72b8 100644 --- a/examples/mobile-viewer/viewer.js +++ b/examples/mobile-viewer/viewer.js @@ -13,26 +13,26 @@ * limitations under the License. */ -'use strict'; +"use strict"; if (!pdfjsLib.getDocument || !pdfjsViewer.PDFViewer) { - alert('Please build the pdfjs-dist library using\n `gulp dist-install`'); + alert("Please build the pdfjs-dist library using\n `gulp dist-install`"); } var USE_ONLY_CSS_ZOOM = true; var TEXT_LAYER_MODE = 0; // DISABLE var MAX_IMAGE_SIZE = 1024 * 1024; -var CMAP_URL = '../../node_modules/pdfjs-dist/cmaps/'; +var CMAP_URL = "../../node_modules/pdfjs-dist/cmaps/"; var CMAP_PACKED = true; pdfjsLib.GlobalWorkerOptions.workerSrc = - '../../node_modules/pdfjs-dist/build/pdf.worker.js'; + "../../node_modules/pdfjs-dist/build/pdf.worker.js"; -var DEFAULT_URL = '../../web/compressed.tracemonkey-pldi-09.pdf'; +var DEFAULT_URL = "../../web/compressed.tracemonkey-pldi-09.pdf"; var DEFAULT_SCALE_DELTA = 1.1; var MIN_SCALE = 0.25; var MAX_SCALE = 10.0; -var DEFAULT_SCALE_VALUE = 'auto'; +var DEFAULT_SCALE_VALUE = "auto"; var PDFViewerApplication = { pdfLoadingTask: null, @@ -49,10 +49,12 @@ var PDFViewerApplication = { open: function(params) { if (this.pdfLoadingTask) { // We need to destroy already opened document - return this.close().then(function () { - // ... and repeat the open() call. - return this.open(params); - }.bind(this)); + return this.close().then( + function() { + // ... and repeat the open() call. + return this.open(params); + }.bind(this) + ); } var url = params.url; @@ -68,45 +70,60 @@ var PDFViewerApplication = { }); this.pdfLoadingTask = loadingTask; - loadingTask.onProgress = function (progressData) { + loadingTask.onProgress = function(progressData) { self.progress(progressData.loaded / progressData.total); }; - return loadingTask.promise.then(function (pdfDocument) { - // Document loaded, specifying document for the viewer. - self.pdfDocument = pdfDocument; - self.pdfViewer.setDocument(pdfDocument); - self.pdfLinkService.setDocument(pdfDocument); - self.pdfHistory.initialize({ fingerprint: pdfDocument.fingerprint, }); + return loadingTask.promise.then( + function(pdfDocument) { + // Document loaded, specifying document for the viewer. + self.pdfDocument = pdfDocument; + self.pdfViewer.setDocument(pdfDocument); + self.pdfLinkService.setDocument(pdfDocument); + self.pdfHistory.initialize({ fingerprint: pdfDocument.fingerprint }); - self.loadingBar.hide(); - self.setTitleUsingMetadata(pdfDocument); - }, function (exception) { - var message = exception && exception.message; - var l10n = self.l10n; - var loadingErrorMessage; + self.loadingBar.hide(); + self.setTitleUsingMetadata(pdfDocument); + }, + function(exception) { + var message = exception && exception.message; + var l10n = self.l10n; + var loadingErrorMessage; - if (exception instanceof pdfjsLib.InvalidPDFException) { - // change error message also for other builds - loadingErrorMessage = l10n.get('invalid_file_error', null, - 'Invalid or corrupted PDF file.'); - } else if (exception instanceof pdfjsLib.MissingPDFException) { - // special message for missing PDFs - loadingErrorMessage = l10n.get('missing_file_error', null, - 'Missing PDF file.'); - } else if (exception instanceof pdfjsLib.UnexpectedResponseException) { - loadingErrorMessage = l10n.get('unexpected_response_error', null, - 'Unexpected server response.'); - } else { - loadingErrorMessage = l10n.get('loading_error', null, - 'An error occurred while loading the PDF.'); + if (exception instanceof pdfjsLib.InvalidPDFException) { + // change error message also for other builds + loadingErrorMessage = l10n.get( + "invalid_file_error", + null, + "Invalid or corrupted PDF file." + ); + } else if (exception instanceof pdfjsLib.MissingPDFException) { + // special message for missing PDFs + loadingErrorMessage = l10n.get( + "missing_file_error", + null, + "Missing PDF file." + ); + } else if (exception instanceof pdfjsLib.UnexpectedResponseException) { + loadingErrorMessage = l10n.get( + "unexpected_response_error", + null, + "Unexpected server response." + ); + } else { + loadingErrorMessage = l10n.get( + "loading_error", + null, + "An error occurred while loading the PDF." + ); + } + + loadingErrorMessage.then(function(msg) { + self.error(msg, { message: message }); + }); + self.loadingBar.hide(); } - - loadingErrorMessage.then(function (msg) { - self.error(msg, { message: message, }); - }); - self.loadingBar.hide(); - }); + ); }, /** @@ -115,8 +132,8 @@ var PDFViewerApplication = { * destruction is completed. */ close: function() { - var errorWrapper = document.getElementById('errorWrapper'); - errorWrapper.setAttribute('hidden', 'true'); + var errorWrapper = document.getElementById("errorWrapper"); + errorWrapper.setAttribute("hidden", "true"); if (!this.pdfLoadingTask) { return Promise.resolve(); @@ -140,9 +157,9 @@ var PDFViewerApplication = { }, get loadingBar() { - var bar = new pdfjsViewer.ProgressBar('#loadingBar', {}); + var bar = new pdfjsViewer.ProgressBar("#loadingBar", {}); - return pdfjsLib.shadow(this, 'loadingBar', bar); + return pdfjsLib.shadow(this, "loadingBar", bar); }, setTitleUsingUrl: function pdfViewSetTitleUsingUrl(url) { @@ -160,99 +177,125 @@ var PDFViewerApplication = { setTitleUsingMetadata: function(pdfDocument) { var self = this; pdfDocument.getMetadata().then(function(data) { - var info = data.info, metadata = data.metadata; + var info = data.info, + metadata = data.metadata; self.documentInfo = info; self.metadata = metadata; // Provides some basic debug information - console.log('PDF ' + pdfDocument.fingerprint + ' [' + - info.PDFFormatVersion + ' ' + (info.Producer || '-').trim() + - ' / ' + (info.Creator || '-').trim() + ']' + - ' (PDF.js: ' + (pdfjsLib.version || '-') + ')'); + console.log( + "PDF " + + pdfDocument.fingerprint + + " [" + + info.PDFFormatVersion + + " " + + (info.Producer || "-").trim() + + " / " + + (info.Creator || "-").trim() + + "]" + + " (PDF.js: " + + (pdfjsLib.version || "-") + + ")" + ); var pdfTitle; - if (metadata && metadata.has('dc:title')) { - var title = metadata.get('dc:title'); + if (metadata && metadata.has("dc:title")) { + var title = metadata.get("dc:title"); // Ghostscript sometimes returns 'Untitled', so prevent setting the // title to 'Untitled. - if (title !== 'Untitled') { + if (title !== "Untitled") { pdfTitle = title; } } - if (!pdfTitle && info && info['Title']) { - pdfTitle = info['Title']; + if (!pdfTitle && info && info["Title"]) { + pdfTitle = info["Title"]; } if (pdfTitle) { - self.setTitle(pdfTitle + ' - ' + document.title); + self.setTitle(pdfTitle + " - " + document.title); } }); }, setTitle: function pdfViewSetTitle(title) { document.title = title; - document.getElementById('title').textContent = title; + document.getElementById("title").textContent = title; }, error: function pdfViewError(message, moreInfo) { var l10n = this.l10n; - var moreInfoText = [l10n.get('error_version_info', - { version: pdfjsLib.version || '?', - build: pdfjsLib.build || '?', }, - 'PDF.js v{{version}} (build: {{build}})')]; + var moreInfoText = [ + l10n.get( + "error_version_info", + { version: pdfjsLib.version || "?", build: pdfjsLib.build || "?" }, + "PDF.js v{{version}} (build: {{build}})" + ), + ]; if (moreInfo) { moreInfoText.push( - l10n.get('error_message', { message: moreInfo.message, }, - 'Message: {{message}}')); + l10n.get( + "error_message", + { message: moreInfo.message }, + "Message: {{message}}" + ) + ); if (moreInfo.stack) { moreInfoText.push( - l10n.get('error_stack', { stack: moreInfo.stack, }, - 'Stack: {{stack}}')); + l10n.get("error_stack", { stack: moreInfo.stack }, "Stack: {{stack}}") + ); } else { if (moreInfo.filename) { moreInfoText.push( - l10n.get('error_file', { file: moreInfo.filename, }, - 'File: {{file}}')); + l10n.get( + "error_file", + { file: moreInfo.filename }, + "File: {{file}}" + ) + ); } if (moreInfo.lineNumber) { moreInfoText.push( - l10n.get('error_line', { line: moreInfo.lineNumber, }, - 'Line: {{line}}')); + l10n.get( + "error_line", + { line: moreInfo.lineNumber }, + "Line: {{line}}" + ) + ); } } } - var errorWrapper = document.getElementById('errorWrapper'); - errorWrapper.removeAttribute('hidden'); + var errorWrapper = document.getElementById("errorWrapper"); + errorWrapper.removeAttribute("hidden"); - var errorMessage = document.getElementById('errorMessage'); + var errorMessage = document.getElementById("errorMessage"); errorMessage.textContent = message; - var closeButton = document.getElementById('errorClose'); + var closeButton = document.getElementById("errorClose"); closeButton.onclick = function() { - errorWrapper.setAttribute('hidden', 'true'); + errorWrapper.setAttribute("hidden", "true"); }; - var errorMoreInfo = document.getElementById('errorMoreInfo'); - var moreInfoButton = document.getElementById('errorShowMore'); - var lessInfoButton = document.getElementById('errorShowLess'); + var errorMoreInfo = document.getElementById("errorMoreInfo"); + var moreInfoButton = document.getElementById("errorShowMore"); + var lessInfoButton = document.getElementById("errorShowLess"); moreInfoButton.onclick = function() { - errorMoreInfo.removeAttribute('hidden'); - moreInfoButton.setAttribute('hidden', 'true'); - lessInfoButton.removeAttribute('hidden'); - errorMoreInfo.style.height = errorMoreInfo.scrollHeight + 'px'; + errorMoreInfo.removeAttribute("hidden"); + moreInfoButton.setAttribute("hidden", "true"); + lessInfoButton.removeAttribute("hidden"); + errorMoreInfo.style.height = errorMoreInfo.scrollHeight + "px"; }; lessInfoButton.onclick = function() { - errorMoreInfo.setAttribute('hidden', 'true'); - moreInfoButton.removeAttribute('hidden'); - lessInfoButton.setAttribute('hidden', 'true'); + errorMoreInfo.setAttribute("hidden", "true"); + moreInfoButton.removeAttribute("hidden"); + lessInfoButton.setAttribute("hidden", "true"); }; - moreInfoButton.removeAttribute('hidden'); - lessInfoButton.setAttribute('hidden', 'true'); - Promise.all(moreInfoText).then(function (parts) { - errorMoreInfo.value = parts.join('\n'); + moreInfoButton.removeAttribute("hidden"); + lessInfoButton.setAttribute("hidden", "true"); + Promise.all(moreInfoText).then(function(parts) { + errorMoreInfo.value = parts.join("\n"); }); }, @@ -302,7 +345,7 @@ var PDFViewerApplication = { this.l10n = pdfjsViewer.NullL10n; - var container = document.getElementById('viewerContainer'); + var container = document.getElementById("viewerContainer"); var pdfViewer = new pdfjsViewer.PDFViewer({ container: container, linkService: linkService, @@ -318,69 +361,77 @@ var PDFViewerApplication = { }); linkService.setHistory(this.pdfHistory); - document.getElementById('previous').addEventListener('click', function() { + document.getElementById("previous").addEventListener("click", function() { PDFViewerApplication.page--; }); - document.getElementById('next').addEventListener('click', function() { + document.getElementById("next").addEventListener("click", function() { PDFViewerApplication.page++; }); - document.getElementById('zoomIn').addEventListener('click', function() { + document.getElementById("zoomIn").addEventListener("click", function() { PDFViewerApplication.zoomIn(); }); - document.getElementById('zoomOut').addEventListener('click', function() { + document.getElementById("zoomOut").addEventListener("click", function() { PDFViewerApplication.zoomOut(); }); - document.getElementById('pageNumber').addEventListener('click', function() { + document.getElementById("pageNumber").addEventListener("click", function() { this.select(); }); - document.getElementById('pageNumber').addEventListener('change', - function() { - PDFViewerApplication.page = (this.value | 0); + document + .getElementById("pageNumber") + .addEventListener("change", function() { + PDFViewerApplication.page = this.value | 0; - // Ensure that the page number input displays the correct value, - // even if the value entered by the user was invalid - // (e.g. a floating point number). - if (this.value !== PDFViewerApplication.page.toString()) { - this.value = PDFViewerApplication.page; - } - }); + // Ensure that the page number input displays the correct value, + // even if the value entered by the user was invalid + // (e.g. a floating point number). + if (this.value !== PDFViewerApplication.page.toString()) { + this.value = PDFViewerApplication.page; + } + }); - document.addEventListener('pagesinit', function () { + document.addEventListener("pagesinit", function() { // We can use pdfViewer now, e.g. let's change default scale. pdfViewer.currentScaleValue = DEFAULT_SCALE_VALUE; }); - document.addEventListener('pagechanging', function (evt) { - var page = evt.detail.pageNumber; - var numPages = PDFViewerApplication.pagesCount; + document.addEventListener( + "pagechanging", + function(evt) { + var page = evt.detail.pageNumber; + var numPages = PDFViewerApplication.pagesCount; - document.getElementById('pageNumber').value = page; - document.getElementById('previous').disabled = (page <= 1); - document.getElementById('next').disabled = (page >= numPages); - }, true); + document.getElementById("pageNumber").value = page; + document.getElementById("previous").disabled = page <= 1; + document.getElementById("next").disabled = page >= numPages; + }, + true + ); }, }; -document.addEventListener('DOMContentLoaded', function () { - PDFViewerApplication.initUI(); -}, true); +document.addEventListener( + "DOMContentLoaded", + function() { + PDFViewerApplication.initUI(); + }, + true +); (function animationStartedClosure() { // The offsetParent is not set until the PDF.js iframe or object is visible. // Waiting for first animation. - PDFViewerApplication.animationStartedPromise = new Promise( - function (resolve) { - window.requestAnimationFrame(resolve); - }); + PDFViewerApplication.animationStartedPromise = new Promise(function(resolve) { + window.requestAnimationFrame(resolve); + }); })(); // We need to delay opening until all HTML is loaded. -PDFViewerApplication.animationStartedPromise.then(function () { +PDFViewerApplication.animationStartedPromise.then(function() { PDFViewerApplication.open({ url: DEFAULT_URL, }); diff --git a/examples/node/domstubs.js b/examples/node/domstubs.js index 9c671aae4..dcf1720fc 100644 --- a/examples/node/domstubs.js +++ b/examples/node/domstubs.js @@ -2,10 +2,18 @@ * http://creativecommons.org/publicdomain/zero/1.0/ */ function xmlEncode(s) { - var i = 0, ch; + var i = 0, + ch; s = String(s); - while (i < s.length && (ch = s[i]) !== '&' && ch !== '<' && - ch !== '\"' && ch !== '\n' && ch !== '\r' && ch !== '\t') { + while ( + i < s.length && + (ch = s[i]) !== "&" && + ch !== "<" && + ch !== '"' && + ch !== "\n" && + ch !== "\r" && + ch !== "\t" + ) { i++; } if (i >= s.length) { @@ -15,23 +23,23 @@ function xmlEncode(s) { while (i < s.length) { ch = s[i++]; switch (ch) { - case '&': - buf += '&'; + case "&": + buf += "&"; break; - case '<': - buf += '<'; + case "<": + buf += "<"; break; - case '\"': - buf += '"'; + case '"': + buf += """; break; - case '\n': - buf += ' '; + case "\n": + buf += " "; break; - case '\r': - buf += ' '; + case "\r": + buf += " "; break; - case '\t': - buf += ' '; + case "\t": + buf += " "; break; default: buf += ch; @@ -45,9 +53,9 @@ function DOMElement(name) { this.nodeName = name; this.childNodes = []; this.attributes = {}; - this.textContent = ''; + this.textContent = ""; - if (name === 'style') { + if (name === "style") { this.sheet = { cssRules: [], insertRule: function(rule) { @@ -74,7 +82,7 @@ DOMElement.prototype = { // Assuming that there is only one matching attribute for a given name, // across all namespaces. if (NS) { - var suffix = ':' + name; + var suffix = ":" + name; for (var fullName in this.attributes) { if (fullName.slice(-suffix.length) === suffix) { return this.attributes[fullName]; @@ -85,7 +93,7 @@ DOMElement.prototype = { }, setAttribute: function DOMElement_setAttribute(name, value) { - value = value || ''; + value = value || ""; value = xmlEncode(value); this.attributes[name] = value; }, @@ -123,7 +131,7 @@ DOMElement.prototype = { while ((chunk = serializer.getNext()) !== null) { buf.push(chunk); } - return buf.join(''); + return buf.join(""); }, getSerializer: function DOMElement_getSerializer() { @@ -147,37 +155,39 @@ DOMElementSerializer.prototype = { getNext: function DOMElementSerializer_getNext() { var node = this._node; switch (this._state) { - case 0: // Start opening tag. + case 0: // Start opening tag. ++this._state; - return '<' + node.nodeName; - case 1: // Add SVG namespace if this is the root element. + return "<" + node.nodeName; + case 1: // Add SVG namespace if this is the root element. ++this._state; - if (node.nodeName === 'svg:svg') { - return ' xmlns:xlink="http://www.w3.org/1999/xlink"' + - ' xmlns:svg="http://www.w3.org/2000/svg"'; + if (node.nodeName === "svg:svg") { + return ( + ' xmlns:xlink="http://www.w3.org/1999/xlink"' + + ' xmlns:svg="http://www.w3.org/2000/svg"' + ); } - /* falls through */ - case 2: // Initialize variables for looping over attributes. + /* falls through */ + case 2: // Initialize variables for looping over attributes. ++this._state; this._loopIndex = 0; this._attributeKeys = Object.keys(node.attributes); - /* falls through */ - case 3: // Serialize any attributes and end opening tag. + /* falls through */ + case 3: // Serialize any attributes and end opening tag. if (this._loopIndex < this._attributeKeys.length) { var name = this._attributeKeys[this._loopIndex++]; - return ' ' + name + '="' + xmlEncode(node.attributes[name]) + '"'; + return " " + name + '="' + xmlEncode(node.attributes[name]) + '"'; } ++this._state; - return '>'; - case 4: // Serialize textContent for tspan/style elements. - if (node.nodeName === 'svg:tspan' || node.nodeName === 'svg:style') { + return ">"; + case 4: // Serialize textContent for tspan/style elements. + if (node.nodeName === "svg:tspan" || node.nodeName === "svg:style") { this._state = 6; return xmlEncode(node.textContent); } ++this._state; this._loopIndex = 0; - /* falls through */ - case 5: // Serialize child nodes (only for non-tspan/style elements). + /* falls through */ + case 5: // Serialize child nodes (only for non-tspan/style elements). var value; while (true) { value = this._childSerializer && this._childSerializer.getNext(); @@ -193,14 +203,14 @@ DOMElementSerializer.prototype = { break; } } - /* falls through */ - case 6: // Ending tag. + /* falls through */ + case 6: // Ending tag. ++this._state; - return ''; - case 7: // Done. + return ""; + case 7: // Done. return null; default: - throw new Error('Unexpected serialization state: ' + this._state); + throw new Error("Unexpected serialization state: " + this._state); } }, }; @@ -209,7 +219,7 @@ const document = { childNodes: [], get currentScript() { - return { src: '', }; + return { src: "" }; }, get documentElement() { @@ -222,12 +232,12 @@ const document = { }, createElement: function(element) { - return this.createElementNS('', element); + return this.createElementNS("", element); }, getElementsByTagName: function(element) { - if (element === 'head') { - return [this.head || (this.head = new DOMElement('head'))]; + if (element === "head") { + return [this.head || (this.head = new DOMElement("head"))]; } return []; }, @@ -256,13 +266,13 @@ var exported_symbols = Object.keys(exports); exports.setStubs = function(namespace) { exported_symbols.forEach(function(key) { - console.assert(!(key in namespace), 'property should not be set: ' + key); + console.assert(!(key in namespace), "property should not be set: " + key); namespace[key] = exports[key]; }); }; exports.unsetStubs = function(namespace) { exported_symbols.forEach(function(key) { - console.assert(key in namespace, 'property should be set: ' + key); + console.assert(key in namespace, "property should be set: " + key); delete namespace[key]; }); }; diff --git a/examples/node/getinfo.js b/examples/node/getinfo.js index 3df0b2bac..1dade92d5 100644 --- a/examples/node/getinfo.js +++ b/examples/node/getinfo.js @@ -8,60 +8,68 @@ // // Run `gulp dist-install` to generate 'pdfjs-dist' npm package files. -var pdfjsLib = require('pdfjs-dist'); +var pdfjsLib = require("pdfjs-dist"); // Loading file from file system into typed array -var pdfPath = process.argv[2] || '../../web/compressed.tracemonkey-pldi-09.pdf'; +var pdfPath = process.argv[2] || "../../web/compressed.tracemonkey-pldi-09.pdf"; // Will be using promises to load document, pages and misc data instead of // callback. var loadingTask = pdfjsLib.getDocument(pdfPath); -loadingTask.promise.then(function(doc) { - var numPages = doc.numPages; - console.log('# Document Loaded'); - console.log('Number of Pages: ' + numPages); - console.log(); - - var lastPromise; // will be used to chain promises - lastPromise = doc.getMetadata().then(function (data) { - console.log('# Metadata Is Loaded'); - console.log('## Info'); - console.log(JSON.stringify(data.info, null, 2)); +loadingTask.promise + .then(function(doc) { + var numPages = doc.numPages; + console.log("# Document Loaded"); + console.log("Number of Pages: " + numPages); console.log(); - if (data.metadata) { - console.log('## Metadata'); - console.log(JSON.stringify(data.metadata.getAll(), null, 2)); - console.log(); - } - }); - var loadPage = function (pageNum) { - return doc.getPage(pageNum).then(function (page) { - console.log('# Page ' + pageNum); - var viewport = page.getViewport({ scale: 1.0, }); - console.log('Size: ' + viewport.width + 'x' + viewport.height); + var lastPromise; // will be used to chain promises + lastPromise = doc.getMetadata().then(function(data) { + console.log("# Metadata Is Loaded"); + console.log("## Info"); + console.log(JSON.stringify(data.info, null, 2)); console.log(); - return page.getTextContent().then(function (content) { - // Content contains lots of information about the text layout and - // styles, but we need only strings at the moment - var strings = content.items.map(function (item) { - return item.str; - }); - console.log('## Text Content'); - console.log(strings.join(' ')); - }).then(function () { + if (data.metadata) { + console.log("## Metadata"); + console.log(JSON.stringify(data.metadata.getAll(), null, 2)); console.log(); - }); + } }); - }; - // Loading of the first page will wait on metadata and subsequent loadings - // will wait on the previous pages. - for (var i = 1; i <= numPages; i++) { - lastPromise = lastPromise.then(loadPage.bind(null, i)); - } - return lastPromise; -}).then(function () { - console.log('# End of Document'); -}, function (err) { - console.error('Error: ' + err); -}); + + var loadPage = function(pageNum) { + return doc.getPage(pageNum).then(function(page) { + console.log("# Page " + pageNum); + var viewport = page.getViewport({ scale: 1.0 }); + console.log("Size: " + viewport.width + "x" + viewport.height); + console.log(); + return page + .getTextContent() + .then(function(content) { + // Content contains lots of information about the text layout and + // styles, but we need only strings at the moment + var strings = content.items.map(function(item) { + return item.str; + }); + console.log("## Text Content"); + console.log(strings.join(" ")); + }) + .then(function() { + console.log(); + }); + }); + }; + // Loading of the first page will wait on metadata and subsequent loadings + // will wait on the previous pages. + for (var i = 1; i <= numPages; i++) { + lastPromise = lastPromise.then(loadPage.bind(null, i)); + } + return lastPromise; + }) + .then( + function() { + console.log("# End of Document"); + }, + function(err) { + console.error("Error: " + err); + } + ); diff --git a/examples/node/pdf2png/pdf2png.js b/examples/node/pdf2png/pdf2png.js index 273fcd971..fad613687 100644 --- a/examples/node/pdf2png/pdf2png.js +++ b/examples/node/pdf2png/pdf2png.js @@ -13,16 +13,16 @@ * limitations under the License. */ -var Canvas = require('canvas'); -var assert = require('assert').strict; -var fs = require('fs'); +var Canvas = require("canvas"); +var assert = require("assert").strict; +var fs = require("fs"); function NodeCanvasFactory() {} NodeCanvasFactory.prototype = { create: function NodeCanvasFactory_create(width, height) { - assert(width > 0 && height > 0, 'Invalid canvas size'); + assert(width > 0 && height > 0, "Invalid canvas size"); var canvas = Canvas.createCanvas(width, height); - var context = canvas.getContext('2d'); + var context = canvas.getContext("2d"); return { canvas: canvas, context: context, @@ -30,14 +30,14 @@ NodeCanvasFactory.prototype = { }, reset: function NodeCanvasFactory_reset(canvasAndContext, width, height) { - assert(canvasAndContext.canvas, 'Canvas is not specified'); - assert(width > 0 && height > 0, 'Invalid canvas size'); + assert(canvasAndContext.canvas, "Canvas is not specified"); + assert(width > 0 && height > 0, "Invalid canvas size"); canvasAndContext.canvas.width = width; canvasAndContext.canvas.height = height; }, destroy: function NodeCanvasFactory_destroy(canvasAndContext) { - assert(canvasAndContext.canvas, 'Canvas is not specified'); + assert(canvasAndContext.canvas, "Canvas is not specified"); // Zeroing the width and height cause Firefox to release graphics // resources immediately, which can greatly reduce memory consumption. @@ -48,46 +48,51 @@ NodeCanvasFactory.prototype = { }, }; -var pdfjsLib = require('pdfjs-dist'); +var pdfjsLib = require("pdfjs-dist"); // Relative path of the PDF file. -var pdfURL = '../../../web/compressed.tracemonkey-pldi-09.pdf'; +var pdfURL = "../../../web/compressed.tracemonkey-pldi-09.pdf"; // Read the PDF file into a typed array so PDF.js can load it. var rawData = new Uint8Array(fs.readFileSync(pdfURL)); // Load the PDF file. var loadingTask = pdfjsLib.getDocument(rawData); -loadingTask.promise.then(function(pdfDocument) { - console.log('# PDF document loaded.'); +loadingTask.promise + .then(function(pdfDocument) { + console.log("# PDF document loaded."); - // Get the first page. - pdfDocument.getPage(1).then(function (page) { - // Render the page on a Node canvas with 100% scale. - var viewport = page.getViewport({ scale: 1.0, }); - var canvasFactory = new NodeCanvasFactory(); - var canvasAndContext = - canvasFactory.create(viewport.width, viewport.height); - var renderContext = { - canvasContext: canvasAndContext.context, - viewport: viewport, - canvasFactory: canvasFactory, - }; + // Get the first page. + pdfDocument.getPage(1).then(function(page) { + // Render the page on a Node canvas with 100% scale. + var viewport = page.getViewport({ scale: 1.0 }); + var canvasFactory = new NodeCanvasFactory(); + var canvasAndContext = canvasFactory.create( + viewport.width, + viewport.height + ); + var renderContext = { + canvasContext: canvasAndContext.context, + viewport: viewport, + canvasFactory: canvasFactory, + }; - var renderTask = page.render(renderContext); - renderTask.promise.then(function() { - // Convert the canvas to an image buffer. - var image = canvasAndContext.canvas.toBuffer(); - fs.writeFile('output.png', image, function (error) { - if (error) { - console.error('Error: ' + error); - } else { - console.log( - 'Finished converting first page of PDF file to a PNG image.'); - } + var renderTask = page.render(renderContext); + renderTask.promise.then(function() { + // Convert the canvas to an image buffer. + var image = canvasAndContext.canvas.toBuffer(); + fs.writeFile("output.png", image, function(error) { + if (error) { + console.error("Error: " + error); + } else { + console.log( + "Finished converting first page of PDF file to a PNG image." + ); + } + }); }); }); + }) + .catch(function(reason) { + console.log(reason); }); -}).catch(function(reason) { - console.log(reason); -}); diff --git a/examples/node/pdf2svg.js b/examples/node/pdf2svg.js index 50860d869..14d6ce494 100644 --- a/examples/node/pdf2svg.js +++ b/examples/node/pdf2svg.js @@ -5,29 +5,29 @@ // Node tool to dump SVG output into a file. // -var fs = require('fs'); -var util = require('util'); -var path = require('path'); -var stream = require('stream'); +var fs = require("fs"); +var util = require("util"); +var path = require("path"); +var stream = require("stream"); // HACK few hacks to let PDF.js be loaded not as a module in global space. -require('./domstubs.js').setStubs(global); +require("./domstubs.js").setStubs(global); // Run `gulp dist-install` to generate 'pdfjs-dist' npm package files. -var pdfjsLib = require('pdfjs-dist'); +var pdfjsLib = require("pdfjs-dist"); // Loading file from file system into typed array -var pdfPath = process.argv[2] || '../../web/compressed.tracemonkey-pldi-09.pdf'; +var pdfPath = process.argv[2] || "../../web/compressed.tracemonkey-pldi-09.pdf"; var data = new Uint8Array(fs.readFileSync(pdfPath)); -var outputDirectory = './svgdump'; +var outputDirectory = "./svgdump"; try { // Note: This creates a directory only one level deep. If you want to create // multiple subdirectories on the fly, use the mkdirp module from npm. fs.mkdirSync(outputDirectory); } catch (e) { - if (e.code !== 'EEXIST') { + if (e.code !== "EEXIST") { throw e; } } @@ -35,7 +35,7 @@ try { // Dumps svg outputs to a folder called svgdump function getFilePathForPage(pageNum) { var name = path.basename(pdfPath, path.extname(pdfPath)); - return path.join(outputDirectory, name + '-' + pageNum + '.svg'); + return path.join(outputDirectory, name + "-" + pageNum + ".svg"); } /** @@ -71,9 +71,9 @@ function writeSvgToFile(svgElement, filePath) { }); var writableStream = fs.createWriteStream(filePath); return new Promise(function(resolve, reject) { - readableSvgStream.once('error', reject); - writableStream.once('error', reject); - writableStream.once('finish', resolve); + readableSvgStream.once("error", reject); + writableStream.once("error", reject); + writableStream.once("finish", resolve); readableSvgStream.pipe(writableStream); }).catch(function(err) { readableSvgStream = null; // Explicitly null because of v8 bug 6512. @@ -90,41 +90,48 @@ var loadingTask = pdfjsLib.getDocument({ // processing. nativeImageDecoderSupport: pdfjsLib.NativeImageDecoding.DISPLAY, }); -loadingTask.promise.then(function(doc) { - var numPages = doc.numPages; - console.log('# Document Loaded'); - console.log('Number of Pages: ' + numPages); - console.log(); +loadingTask.promise + .then(function(doc) { + var numPages = doc.numPages; + console.log("# Document Loaded"); + console.log("Number of Pages: " + numPages); + console.log(); - var lastPromise = Promise.resolve(); // will be used to chain promises - var loadPage = function (pageNum) { - return doc.getPage(pageNum).then(function (page) { - console.log('# Page ' + pageNum); - var viewport = page.getViewport({ scale: 1.0, }); - console.log('Size: ' + viewport.width + 'x' + viewport.height); - console.log(); + var lastPromise = Promise.resolve(); // will be used to chain promises + var loadPage = function(pageNum) { + return doc.getPage(pageNum).then(function(page) { + console.log("# Page " + pageNum); + var viewport = page.getViewport({ scale: 1.0 }); + console.log("Size: " + viewport.width + "x" + viewport.height); + console.log(); - return page.getOperatorList().then(function (opList) { - var svgGfx = new pdfjsLib.SVGGraphics(page.commonObjs, page.objs); - svgGfx.embedFonts = true; - return svgGfx.getSVG(opList, viewport).then(function (svg) { - return writeSvgToFile(svg, getFilePathForPage(pageNum)) - .then(function () { - console.log('Page: ' + pageNum); - }, function(err) { - console.log('Error: ' + err); - }); + return page.getOperatorList().then(function(opList) { + var svgGfx = new pdfjsLib.SVGGraphics(page.commonObjs, page.objs); + svgGfx.embedFonts = true; + return svgGfx.getSVG(opList, viewport).then(function(svg) { + return writeSvgToFile(svg, getFilePathForPage(pageNum)).then( + function() { + console.log("Page: " + pageNum); + }, + function(err) { + console.log("Error: " + err); + } + ); + }); }); }); - }); - }; + }; - for (var i = 1; i <= numPages; i++) { - lastPromise = lastPromise.then(loadPage.bind(null, i)); - } - return lastPromise; -}).then(function () { - console.log('# End of Document'); -}, function (err) { - console.error('Error: ' + err); -}); + for (var i = 1; i <= numPages; i++) { + lastPromise = lastPromise.then(loadPage.bind(null, i)); + } + return lastPromise; + }) + .then( + function() { + console.log("# End of Document"); + }, + function(err) { + console.error("Error: " + err); + } + ); diff --git a/examples/svgviewer/viewer.js b/examples/svgviewer/viewer.js index 718b143aa..9a32261d3 100644 --- a/examples/svgviewer/viewer.js +++ b/examples/svgviewer/viewer.js @@ -13,26 +13,27 @@ * limitations under the License. */ -'use strict'; +"use strict"; if (!pdfjsLib.getDocument || !pdfjsViewer.PDFViewer) { - alert('Please build the pdfjs-dist library using\n' + - ' `gulp dist-install`'); + alert( + "Please build the pdfjs-dist library using\n" + " `gulp dist-install`" + ); } // The workerSrc property shall be specified. // pdfjsLib.GlobalWorkerOptions.workerSrc = - '../../node_modules/pdfjs-dist/build/pdf.worker.js'; + "../../node_modules/pdfjs-dist/build/pdf.worker.js"; // Some PDFs need external cmaps. // -var CMAP_URL = '../../node_modules/pdfjs-dist/cmaps/'; +var CMAP_URL = "../../node_modules/pdfjs-dist/cmaps/"; var CMAP_PACKED = true; -var DEFAULT_URL = '../../web/compressed.tracemonkey-pldi-09.pdf'; +var DEFAULT_URL = "../../web/compressed.tracemonkey-pldi-09.pdf"; -var container = document.getElementById('viewerContainer'); +var container = document.getElementById("viewerContainer"); // (Optionally) enable hyperlinks within PDF files. var pdfLinkService = new pdfjsViewer.PDFLinkService(); @@ -40,14 +41,14 @@ var pdfLinkService = new pdfjsViewer.PDFLinkService(); var pdfViewer = new pdfjsViewer.PDFViewer({ container: container, linkService: pdfLinkService, - renderer: 'svg', + renderer: "svg", textLayerMode: 0, }); pdfLinkService.setViewer(pdfViewer); -document.addEventListener('pagesinit', function () { +document.addEventListener("pagesinit", function() { // We can use pdfViewer now, e.g. let's change default scale. - pdfViewer.currentScaleValue = 'page-width'; + pdfViewer.currentScaleValue = "page-width"; }); // Loading document. diff --git a/examples/text-only/pdf2svg.js b/examples/text-only/pdf2svg.js index 3ce9d6259..51bfd2cd7 100644 --- a/examples/text-only/pdf2svg.js +++ b/examples/text-only/pdf2svg.js @@ -13,34 +13,35 @@ * limitations under the License. */ -var PDF_PATH = '../../web/compressed.tracemonkey-pldi-09.pdf'; +var PDF_PATH = "../../web/compressed.tracemonkey-pldi-09.pdf"; var PAGE_NUMBER = 1; var PAGE_SCALE = 1.5; -var SVG_NS = 'http://www.w3.org/2000/svg'; +var SVG_NS = "http://www.w3.org/2000/svg"; pdfjsLib.GlobalWorkerOptions.workerSrc = - '../../node_modules/pdfjs-dist/build/pdf.worker.js'; + "../../node_modules/pdfjs-dist/build/pdf.worker.js"; function buildSVG(viewport, textContent) { // Building SVG with size of the viewport (for simplicity) - var svg = document.createElementNS(SVG_NS, 'svg:svg'); - svg.setAttribute('width', viewport.width + 'px'); - svg.setAttribute('height', viewport.height + 'px'); + var svg = document.createElementNS(SVG_NS, "svg:svg"); + svg.setAttribute("width", viewport.width + "px"); + svg.setAttribute("height", viewport.height + "px"); // items are transformed to have 1px font size - svg.setAttribute('font-size', 1); + svg.setAttribute("font-size", 1); // processing all items - textContent.items.forEach(function (textItem) { + textContent.items.forEach(function(textItem) { // we have to take in account viewport transform, which includes scale, // rotation and Y-axis flip, and not forgetting to flip text. var tx = pdfjsLib.Util.transform( pdfjsLib.Util.transform(viewport.transform, textItem.transform), - [1, 0, 0, -1, 0, 0]); + [1, 0, 0, -1, 0, 0] + ); var style = textContent.styles[textItem.fontName]; // adding text element - var text = document.createElementNS(SVG_NS, 'svg:text'); - text.setAttribute('transform', 'matrix(' + tx.join(' ') + ')'); - text.setAttribute('font-family', style.fontFamily); + var text = document.createElementNS(SVG_NS, "svg:text"); + text.setAttribute("transform", "matrix(" + tx.join(" ") + ")"); + text.setAttribute("font-family", style.fontFamily); text.textContent = textItem.str; svg.appendChild(text); }); @@ -49,23 +50,25 @@ function buildSVG(viewport, textContent) { function pageLoaded() { // Loading document and page text content - var loadingTask = pdfjsLib.getDocument({ url: PDF_PATH, }); + var loadingTask = pdfjsLib.getDocument({ url: PDF_PATH }); loadingTask.promise.then(function(pdfDocument) { - pdfDocument.getPage(PAGE_NUMBER).then(function (page) { - var viewport = page.getViewport({ scale: PAGE_SCALE, }); - page.getTextContent().then(function (textContent) { + pdfDocument.getPage(PAGE_NUMBER).then(function(page) { + var viewport = page.getViewport({ scale: PAGE_SCALE }); + page.getTextContent().then(function(textContent) { // building SVG and adding that to the DOM var svg = buildSVG(viewport, textContent); - document.getElementById('pageContainer').appendChild(svg); + document.getElementById("pageContainer").appendChild(svg); }); }); }); } -document.addEventListener('DOMContentLoaded', function () { - if (typeof pdfjsLib === 'undefined') { - alert('Built version of PDF.js was not found.\n' + - 'Please run `gulp dist-install`.'); +document.addEventListener("DOMContentLoaded", function() { + if (typeof pdfjsLib === "undefined") { + alert( + "Built version of PDF.js was not found.\n" + + "Please run `gulp dist-install`." + ); return; } pageLoaded(); diff --git a/examples/webpack/main.js b/examples/webpack/main.js index bc21b5f32..053bea8a0 100644 --- a/examples/webpack/main.js +++ b/examples/webpack/main.js @@ -3,31 +3,33 @@ // Hello world example for webpack. -var pdfjsLib = require('pdfjs-dist'); +var pdfjsLib = require("pdfjs-dist"); -var pdfPath = '../learning/helloworld.pdf'; +var pdfPath = "../learning/helloworld.pdf"; // Setting worker path to worker bundle. pdfjsLib.GlobalWorkerOptions.workerSrc = - '../../build/webpack/pdf.worker.bundle.js'; + "../../build/webpack/pdf.worker.bundle.js"; // Loading a document. var loadingTask = pdfjsLib.getDocument(pdfPath); -loadingTask.promise.then(function (pdfDocument) { - // Request a first page - return pdfDocument.getPage(1).then(function (pdfPage) { - // Display page on the existing canvas with 100% scale. - var viewport = pdfPage.getViewport({ scale: 1.0, }); - var canvas = document.getElementById('theCanvas'); - canvas.width = viewport.width; - canvas.height = viewport.height; - var ctx = canvas.getContext('2d'); - var renderTask = pdfPage.render({ - canvasContext: ctx, - viewport: viewport, +loadingTask.promise + .then(function(pdfDocument) { + // Request a first page + return pdfDocument.getPage(1).then(function(pdfPage) { + // Display page on the existing canvas with 100% scale. + var viewport = pdfPage.getViewport({ scale: 1.0 }); + var canvas = document.getElementById("theCanvas"); + canvas.width = viewport.width; + canvas.height = viewport.height; + var ctx = canvas.getContext("2d"); + var renderTask = pdfPage.render({ + canvasContext: ctx, + viewport: viewport, + }); + return renderTask.promise; }); - return renderTask.promise; + }) + .catch(function(reason) { + console.error("Error: " + reason); }); -}).catch(function (reason) { - console.error('Error: ' + reason); -}); diff --git a/examples/webpack/webpack.config.js b/examples/webpack/webpack.config.js index 69ff53edc..4db8758f3 100644 --- a/examples/webpack/webpack.config.js +++ b/examples/webpack/webpack.config.js @@ -1,16 +1,16 @@ -var webpack = require('webpack'); // eslint-disable-line no-unused-vars -var path = require('path'); +var webpack = require("webpack"); // eslint-disable-line no-unused-vars +var path = require("path"); module.exports = { context: __dirname, entry: { - 'main': './main.js', - 'pdf.worker': 'pdfjs-dist/build/pdf.worker.entry', + main: "./main.js", + "pdf.worker": "pdfjs-dist/build/pdf.worker.entry", }, - mode: 'none', + mode: "none", output: { - path: path.join(__dirname, '../../build/webpack'), - publicPath: '../../build/webpack/', - filename: '[name].bundle.js', + path: path.join(__dirname, "../../build/webpack"), + publicPath: "../../build/webpack/", + filename: "[name].bundle.js", }, }; diff --git a/extensions/chromium/contentscript.js b/extensions/chromium/contentscript.js index 3a7d86fde..5680a5b3a 100644 --- a/extensions/chromium/contentscript.js +++ b/extensions/chromium/contentscript.js @@ -14,22 +14,22 @@ See the License for the specific language governing permissions and limitations under the License. */ -'use strict'; +"use strict"; -var VIEWER_URL = chrome.extension.getURL('content/web/viewer.html'); +var VIEWER_URL = chrome.extension.getURL("content/web/viewer.html"); function getViewerURL(pdf_url) { - return VIEWER_URL + '?file=' + encodeURIComponent(pdf_url); + return VIEWER_URL + "?file=" + encodeURIComponent(pdf_url); } -if (CSS.supports('animation', '0s')) { - document.addEventListener('animationstart', onAnimationStart, true); +if (CSS.supports("animation", "0s")) { + document.addEventListener("animationstart", onAnimationStart, true); } else { - document.addEventListener('webkitAnimationStart', onAnimationStart, true); + document.addEventListener("webkitAnimationStart", onAnimationStart, true); } function onAnimationStart(event) { - if (event.animationName === 'pdfjs-detected-object-or-embed') { + if (event.animationName === "pdfjs-detected-object-or-embed") { watchObjectOrEmbed(event.target); } } @@ -40,19 +40,23 @@ function onAnimationStart(event) { // invocations have no effect. function watchObjectOrEmbed(elem) { var mimeType = elem.type; - if (mimeType && mimeType.toLowerCase() !== 'application/pdf') { + if (mimeType && mimeType.toLowerCase() !== "application/pdf") { return; } // - var srcAttribute = 'src' in elem ? 'src' : 'data'; + var srcAttribute = "src" in elem ? "src" : "data"; var path = elem[srcAttribute]; if (!mimeType && !/\.pdf($|[?#])/i.test(path)) { return; } - if (elem.tagName === 'EMBED' && elem.name === 'plugin' && - elem.parentNode === document.body && - elem.parentNode.childElementCount === 1 && elem.src === location.href) { + if ( + elem.tagName === "EMBED" && + elem.name === "plugin" && + elem.parentNode === document.body && + elem.parentNode.childElementCount === 1 && + elem.src === location.href + ) { // This page is most likely Chrome's default page that embeds a PDF file. // The fact that the extension's background page did not intercept and // redirect this PDF request means that this PDF cannot be opened by PDF.js, @@ -62,7 +66,7 @@ function watchObjectOrEmbed(elem) { // Until #4483 is fixed, POST requests should be ignored. return; } - if (elem.tagName === 'EMBED' && elem.src === 'about:blank') { + if (elem.tagName === "EMBED" && elem.src === "about:blank") { // Starting from Chrome 76, internal embeds do not have the original URL, // but "about:blank" instead. // See https://github.com/mozilla/pdf.js/issues/11137 @@ -76,9 +80,9 @@ function watchObjectOrEmbed(elem) { var tagName = elem.tagName.toUpperCase(); var updateEmbedOrObject; - if (tagName === 'EMBED') { + if (tagName === "EMBED") { updateEmbedOrObject = updateEmbedElement; - } else if (tagName === 'OBJECT') { + } else if (tagName === "OBJECT") { updateEmbedOrObject = updateObjectElement; } else { return; @@ -115,7 +119,7 @@ function watchObjectOrEmbed(elem) { // Display the PDF Viewer in an . function updateEmbedElement(elem) { - if (elem.type === 'text/html' && elem.src.lastIndexOf(VIEWER_URL, 0) === 0) { + if (elem.type === "text/html" && elem.src.lastIndexOf(VIEWER_URL, 0) === 0) { // The viewer is already shown. return; } @@ -126,7 +130,7 @@ function updateEmbedElement(elem) { if (parentNode) { parentNode.removeChild(elem); } - elem.type = 'text/html'; + elem.type = "text/html"; elem.src = getEmbeddedViewerURL(elem.src); if (parentNode) { parentNode.insertBefore(elem, nextSibling); @@ -155,21 +159,21 @@ function updateObjectElement(elem) { var iframe = elem.firstElementChild; if (!iframe || !iframe.__inserted_by_pdfjs) { iframe = createFullSizeIframe(); - elem.textContent = ''; + elem.textContent = ""; elem.appendChild(iframe); iframe.__inserted_by_pdfjs = true; } iframe.src = getEmbeddedViewerURL(elem.data); // Some bogus content type that is not handled by any plugin. - elem.type = 'application/not-a-pee-dee-eff-type'; + elem.type = "application/not-a-pee-dee-eff-type"; // Force the to reload and render its fallback content. - elem.data += ''; + elem.data += ""; // Usually the browser renders plugin content in this tag, which is completely // oblivious of styles such as padding, but we insert and render child nodes, // so force padding to be zero to avoid undesired dimension changes. - elem.style.padding = '0'; + elem.style.padding = "0"; // and elements have a "display:inline" style by default. // Despite this property, when a plugin is loaded in the tag, the tag is @@ -180,27 +184,27 @@ function updateObjectElement(elem) { // web pages is respected. // ( behaves as expected with the default display value, but setting it // to display:inline-block doesn't hurt). - elem.style.display = 'inline-block'; + elem.style.display = "inline-block"; } // Create an