diff --git a/Makefile b/Makefile index fa2cf816e..306d7f47a 100644 --- a/Makefile +++ b/Makefile @@ -56,7 +56,7 @@ browser-test: # # This target runs all of the tests that can be run in a JS shell. # The shell used is taken from the JS_SHELL environment variable. If -# that veriable is not defined, the script will attempt to use the copy +# that variable is not defined, the script will attempt to use the copy # of Rhino that comes with the Closure compiler used for producing the # website. SHELL_TARGET = $(NULL) diff --git a/crypto.js b/crypto.js index d73408ad6..c60590777 100644 --- a/crypto.js +++ b/crypto.js @@ -1,7 +1,7 @@ /* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- / /* vim: set shiftwidth=2 tabstop=2 autoindent cindent expandtab: */ -"use strict"; +'use strict'; var ARCFourCipher = (function() { function constructor(key) { @@ -30,7 +30,7 @@ var ARCFourCipher = (function() { a = (a + 1) & 0xFF; tmp = s[a]; b = (b + tmp) & 0xFF; - tmp2 = s[b] + tmp2 = s[b]; s[a] = tmp2; s[b] = tmp; output[i] = data[i] ^ s[(tmp + tmp2) & 0xFF]; @@ -47,22 +47,23 @@ var ARCFourCipher = (function() { var md5 = (function() { 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, + 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]); + var k = new Int32Array([ -680876936, -389564586, 606105819, -1044525330, -176418897, 1200080426, -1473231341, -45705983, 1770035416, -1958414417, -42063, -1990404162, 1804603682, -40341101, -1502002290, 1236535329, -165796510, -1069501632, - 643717713, -373897302, -701558691, 38016083, -660478335, -405537848, 568446438, - -1019803690, -187363961, 1163531501, -1444681467, -51403784, 1735328473, - -1926607734, -378558, -2022574463, 1839030562, -35309556, -1530992060, - 1272893353, -155497632, -1094730640, 681279174, -358537222, -722521979, - 76029189, -640364487, -421815835, 530742520, -995338651, -198630844, 1126891415, - -1416354905, -57434055, 1700485571, -1894986606, -1051523, -2054922799, - 1873313359, -30611744, -1560198380, 1309151649, -145523070, -1120210379, - 718787259, -343485551]); - + 643717713, -373897302, -701558691, 38016083, -660478335, -405537848, + 568446438, -1019803690, -187363961, 1163531501, -1444681467, -51403784, + 1735328473, -1926607734, -378558, -2022574463, 1839030562, -35309556, + -1530992060, 1272893353, -155497632, -1094730640, 681279174, -358537222, + -722521979, 76029189, -640364487, -421815835, 530742520, -995338651, + -198630844, 1126891415, -1416354905, -57434055, 1700485571, -1894986606, + -1051523, -2054922799, 1873313359, -30611744, -1560198380, 1309151649, + -145523070, -1120210379, 718787259, -343485551]); + function hash(data, offset, length) { var h0 = 1732584193, h1 = -271733879, h2 = -1732584194, h3 = 271733878; // pre-processing @@ -76,10 +77,10 @@ var md5 = (function() { for (; i < n; ++i) padded[i] = 0; padded[i++] = (length << 3) & 0xFF; - padded[i++] = (length >> 5) & 0xFF; - padded[i++] = (length >> 13) & 0xFF; - padded[i++] = (length >> 21) & 0xFF; - padded[i++] = (length >>> 29) & 0xFF; + padded[i++] = (length >> 5) & 0xFF; + padded[i++] = (length >> 13) & 0xFF; + padded[i++] = (length >> 21) & 0xFF; + padded[i++] = (length >>> 29) & 0xFF; padded[i++] = 0; padded[i++] = 0; padded[i++] = 0; @@ -87,8 +88,10 @@ var md5 = (function() { // TODO ArrayBuffer ? var w = new Int32Array(16); for (i = 0; i < paddedLength;) { - for (j = 0; j < 16; ++j, i += 4) - w[j] = padded[i] | (padded[i + 1] << 8) | (padded[i + 2] << 16) | (padded[i + 3] << 24); + for (j = 0; j < 16; ++j, i += 4) { + w[j] = (padded[i] | (padded[i + 1] << 8) | + (padded[i + 2] << 16) | (padded[i + 3] << 24)); + } var a = h0, b = h1, c = h2, d = h3, f, g; for (j = 0; j < 64; ++j) { if (j < 16) { @@ -131,7 +134,7 @@ var CipherTransform = (function() { this.streamCipherConstructor = streamCipherConstructor; } constructor.prototype = { - createStream: function (stream) { + createStream: function(stream) { var cipher = new this.streamCipherConstructor(); return new DecryptStream(stream, function(data) { return cipher.encryptBlock(data); @@ -148,10 +151,13 @@ var CipherTransform = (function() { })(); var CipherTransformFactory = (function() { - function prepareKeyData(fileId, password, ownerPassword, userPassword, flags, revision, keyLength) { + function prepareKeyData(fileId, password, ownerPassword, userPassword, + flags, revision, keyLength) { var defaultPasswordBytes = new Uint8Array([ - 0x28, 0xBF, 0x4E, 0x5E, 0x4E, 0x75, 0x8A, 0x41, 0x64, 0x00, 0x4E, 0x56, 0xFF, 0xFA, 0x01, 0x08, - 0x2E, 0x2E, 0x00, 0xB6, 0xD0, 0x68, 0x3E, 0x80, 0x2F, 0x0C, 0xA9, 0xFE, 0x64, 0x53, 0x69, 0x7A]); + 0x28, 0xBF, 0x4E, 0x5E, 0x4E, 0x75, 0x8A, 0x41, + 0x64, 0x00, 0x4E, 0x56, 0xFF, 0xFA, 0x01, 0x08, + 0x2E, 0x2E, 0x00, 0xB6, 0xD0, 0x68, 0x3E, 0x80, + 0x2F, 0x0C, 0xA9, 0xFE, 0x64, 0x53, 0x69, 0x7A]); var hashData = new Uint8Array(88), i = 0, j, n; if (password) { n = Math.min(32, password.length); @@ -183,9 +189,10 @@ var CipherTransformFactory = (function() { var cipher, checkData; if (revision >= 3) { - // padded password in hashData, we can use this array for user password check + // padded password in hashData, we can use this array for user + // password check i = 32; - for(j = 0, n = fileId.length; j < n; ++j) + for (j = 0, n = fileId.length; j < n; ++j) hashData[i++] = fileId[j]; cipher = new ARCFourCipher(encryptionKey); var checkData = cipher.encryptBlock(md5(hashData, 0, i)); @@ -203,37 +210,38 @@ var CipherTransformFactory = (function() { } for (j = 0, n = checkData.length; j < n; ++j) { if (userPassword[j] != checkData[j]) - error("incorrect password"); + error('incorrect password'); } return encryptionKey; - } + } function constructor(dict, fileId, password) { - var filter = dict.get("Filter"); - if (!IsName(filter) || filter.name != "Standard") - error("unknown encryption method"); + var filter = dict.get('Filter'); + if (!IsName(filter) || filter.name != 'Standard') + error('unknown encryption method'); this.dict = dict; - var algorithm = dict.get("V"); + var algorithm = dict.get('V'); if (!IsInt(algorithm) || (algorithm != 1 && algorithm != 2)) - error("unsupported encryption algorithm"); + error('unsupported encryption algorithm'); // TODO support algorithm 4 - var keyLength = dict.get("Length") || 40; + var keyLength = dict.get('Length') || 40; if (!IsInt(keyLength) || keyLength < 40 || (keyLength % 8) != 0) - error("invalid key length"); + error('invalid key length'); // prepare keys - var ownerPassword = stringToBytes(dict.get("O")); - var userPassword = stringToBytes(dict.get("U")); - var flags = dict.get("P"); - var revision = dict.get("R"); + var ownerPassword = stringToBytes(dict.get('O')); + var userPassword = stringToBytes(dict.get('U')); + var flags = dict.get('P'); + var revision = dict.get('R'); var fileIdBytes = stringToBytes(fileId); var passwordBytes; if (password) passwordBytes = stringToBytes(password); - this.encryptionKey = prepareKeyData(fileIdBytes, passwordBytes, - ownerPassword, userPassword, flags, revision, keyLength); + this.encryptionKey = prepareKeyData(fileIdBytes, passwordBytes, + ownerPassword, userPassword, + flags, revision, keyLength); } constructor.prototype = { diff --git a/fonts.js b/fonts.js index 8701f8e5f..d00d114db 100644 --- a/fonts.js +++ b/fonts.js @@ -1,9 +1,9 @@ /* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- / /* vim: set shiftwidth=2 tabstop=2 autoindent cindent expandtab: */ -"use strict"; +'use strict'; -var isWorker = (typeof window == "undefined"); +var isWorker = (typeof window == 'undefined'); /** * Maximum file size of the font. @@ -11,7 +11,7 @@ var isWorker = (typeof window == "undefined"); var kMaxFontFileSize = 40000; /** - * Maximum time to wait for a font to be loaded by @font-face + * Maximum time to wait for a font to be loaded by font-face rules. */ var kMaxWaitForFontFace = 1000; @@ -20,7 +20,7 @@ var kMaxWaitForFontFace = 1000; * many fonts are loaded. */ var fontCount = 0; -var fontName = ""; +var fontName = ''; /** * If for some reason one want to debug without fonts activated, it just need @@ -41,7 +41,7 @@ var Fonts = (function Fonts() { var fonts = Object.create(null); if (!isWorker) { - var ctx = document.createElement("canvas").getContext("2d"); + var ctx = document.createElement('canvas').getContext('2d'); ctx.scale(1 / kScalePrecision, 1); } @@ -94,7 +94,7 @@ var Fonts = (function Fonts() { if (!encoding) return chars; - str = ""; + str = ''; for (var i = 0; i < chars.length; ++i) { var charcode = chars.charCodeAt(i); var unicode = encoding[charcode]; @@ -123,7 +123,7 @@ var Fonts = (function Fonts() { measureCache[text] = width; return width; } - } + }; })(); var FontLoader = { @@ -139,19 +139,19 @@ var FontLoader = { } document.documentElement.removeEventListener( - "pdfjsFontLoad", checkFontsLoaded, false); + 'pdfjsFontLoad', checkFontsLoaded, false); callback(); return true; } - var rules = [ ], names = [ ]; + var rules = [], names = []; for (var i = 0; i < fonts.length; i++) { var font = fonts[i]; if (!Fonts.lookup(font.name)) { var obj = new Font(font.name, font.file, font.properties); - var str = ""; + var str = ''; var data = Fonts.lookup(font.name).data; var length = data.length; for (var j = 0; j < length; j++) @@ -171,7 +171,7 @@ var FontLoader = { if (!checkFontsLoaded()) { document.documentElement.addEventListener( - "pdfjsFontLoad", checkFontsLoaded, false); + 'pdfjsFontLoad', checkFontsLoaded, false); } return; @@ -205,29 +205,29 @@ var FontLoader = { // The postMessage() hackery was added to work around chrome bug // 82402. - var div = document.createElement("div"); - div.setAttribute("style", - 'visibility: hidden;'+ - 'width: 10px; height: 10px;'+ + var div = document.createElement('div'); + div.setAttribute('style', + 'visibility: hidden;' + + 'width: 10px; height: 10px;' + 'position: absolute; top: 0px; left: 0px;'); var html = ''; for (var i = 0; i < names.length; ++i) { - html += 'Hi'; + html += 'Hi'; } div.innerHTML = html; document.body.appendChild(div); if (!this.listeneningForFontLoad) { window.addEventListener( - "message", + 'message', function(e) { var fontNames = JSON.parse(e.data); for (var i = 0; i < fontNames.length; ++i) { var font = Fonts.lookup(fontNames[i]); font.loading = false; } - var evt = document.createEvent("Events"); - evt.initEvent("pdfjsFontLoad", true, false); + var evt = document.createEvent('Events'); + evt.initEvent('pdfjsFontLoad', true, false); document.documentElement.dispatchEvent(evt); }, false); @@ -241,26 +241,26 @@ var FontLoader = { for (var i = 0; i < rules.length; ++i) { src += rules[i]; } - src += '' - src += '
'; for (var i = 0; i < names.length; ++i) { - src += 'Hi
'; + src += 'Hi
'; } src += '