diff --git a/make.js b/make.js index 2fd89efdb..ae664f202 100644 --- a/make.js +++ b/make.js @@ -317,7 +317,7 @@ target.bundle = function(args) { } } - var bundle = cat(SRC_FILES), + var bundleContent = cat(SRC_FILES), bundleVersion = VERSION, bundleBuild = exec('git log --format="%h" -n 1', {silent: true}).output.replace('\n', ''); @@ -325,15 +325,15 @@ target.bundle = function(args) { crlfchecker.checkIfCrlfIsPresent(SRC_FILES); // Strip out all the vim/license headers. - bundle = bundle.replace(reg, ''); + bundleContent = bundleContent.replace(reg, ''); // Append external files last since we don't want to modify them. - bundle += cat(EXT_SRC_FILES); + bundleContent += cat(EXT_SRC_FILES); // This just preprocesses the empty pdf.js file, we don't actually want to // preprocess everything yet since other build targets use this file. builder.preprocess(filename, dir, builder.merge(defines, - {BUNDLE: bundle, + {BUNDLE: bundleContent, BUNDLE_VERSION: bundleVersion, BUNDLE_BUILD: bundleBuild})); } @@ -1274,7 +1274,6 @@ target.lint = function() { 'web/', 'test/downloadutils.js', 'test/driver.js', - 'test/reporter.js', 'test/test.js', 'test/testutils.js', 'test/webbrowser.js', @@ -1292,10 +1291,10 @@ target.lint = function() { exec('npm install jshint@2.4.x'); // TODO read version from package.json } - exit(exec('"' + jshintPath + '" --reporter test/reporter.js ' + - LINT_FILES.join(' ')).code); - - crlfchecker.checkIfCrlfIsPresent(LINT_FILES); + var exitCode = exec('"' + jshintPath + '" ' + LINT_FILES.join(' ')).code; + if (exitCode === 0) { + echo('files checked, no errors found'); + } }; // diff --git a/src/core/bidi.js b/src/core/bidi.js index 39a15bd8a..a5aee277e 100644 --- a/src/core/bidi.js +++ b/src/core/bidi.js @@ -77,7 +77,6 @@ var bidi = PDFJS.bidi = (function bidiClosure() { } function findUnequal(arr, start, value) { - var j; for (var j = start, jj = arr.length; j < jj; ++j) { if (arr[j] != value) { return j; @@ -164,7 +163,8 @@ var bidi = PDFJS.bidi = (function bidiClosure() { types.length = 0; var numBidi = 0; - for (var i = 0; i < strLength; ++i) { + var i, ii; + for (i = 0; i < strLength; ++i) { chars[i] = str.charAt(i); var charCode = str.charCodeAt(i); @@ -204,7 +204,7 @@ var bidi = PDFJS.bidi = (function bidiClosure() { } var levels = []; - for (var i = 0; i < strLength; ++i) { + for (i = 0; i < strLength; ++i) { levels[i] = startLevel; } @@ -221,7 +221,7 @@ var bidi = PDFJS.bidi = (function bidiClosure() { start of the level run, it will get the type of sor. */ var lastType = sor; - for (var i = 0; i < strLength; ++i) { + for (i = 0; i < strLength; ++i) { if (types[i] == 'NSM') { types[i] = lastType; } else { @@ -234,9 +234,10 @@ var bidi = PDFJS.bidi = (function bidiClosure() { first strong type (R, L, AL, or sor) is found. If an AL is found, change the type of the European number to Arabic number. */ - var lastType = sor; - for (var i = 0; i < strLength; ++i) { - var t = types[i]; + lastType = sor; + var t; + for (i = 0; i < strLength; ++i) { + t = types[i]; if (t == 'EN') { types[i] = (lastType == 'AL') ? 'AN' : 'EN'; } else if (t == 'R' || t == 'L' || t == 'AL') { @@ -247,8 +248,8 @@ var bidi = PDFJS.bidi = (function bidiClosure() { /* W3. Change all ALs to R. */ - for (var i = 0; i < strLength; ++i) { - var t = types[i]; + for (i = 0; i < strLength; ++i) { + t = types[i]; if (t == 'AL') { types[i] = 'R'; } @@ -259,7 +260,7 @@ var bidi = PDFJS.bidi = (function bidiClosure() { European number. A single common separator between two numbers of the same type changes to that type: */ - for (var i = 1; i < strLength - 1; ++i) { + for (i = 1; i < strLength - 1; ++i) { if (types[i] == 'ES' && types[i - 1] == 'EN' && types[i + 1] == 'EN') { types[i] = 'EN'; } @@ -273,17 +274,18 @@ var bidi = PDFJS.bidi = (function bidiClosure() { W5. A sequence of European terminators adjacent to European numbers changes to all European numbers: */ - for (var i = 0; i < strLength; ++i) { + for (i = 0; i < strLength; ++i) { if (types[i] == 'EN') { // do before - for (var j = i - 1; j >= 0; --j) { + var j; + for (j = i - 1; j >= 0; --j) { if (types[j] != 'ET') { break; } types[j] = 'EN'; } // do after - for (var j = i + 1; j < strLength; --j) { + for (j = i + 1; j < strLength; --j) { if (types[j] != 'ET') { break; } @@ -295,8 +297,8 @@ var bidi = PDFJS.bidi = (function bidiClosure() { /* W6. Otherwise, separators and terminators change to Other Neutral: */ - for (var i = 0; i < strLength; ++i) { - var t = types[i]; + for (i = 0; i < strLength; ++i) { + t = types[i]; if (t == 'WS' || t == 'ES' || t == 'ET' || t == 'CS') { types[i] = 'ON'; } @@ -307,9 +309,9 @@ var bidi = PDFJS.bidi = (function bidiClosure() { first strong type (R, L, or sor) is found. If an L is found, then change the type of the European number to L. */ - var lastType = sor; - for (var i = 0; i < strLength; ++i) { - var t = types[i]; + lastType = sor; + for (i = 0; i < strLength; ++i) { + t = types[i]; if (t == 'EN') { types[i] = ((lastType == 'L') ? 'L' : 'EN'); } else if (t == 'R' || t == 'L') { @@ -323,7 +325,7 @@ var bidi = PDFJS.bidi = (function bidiClosure() { numbers are treated as though they were R. Start-of-level-run (sor) and end-of-level-run (eor) are used at level run boundaries. */ - for (var i = 0; i < strLength; ++i) { + for (i = 0; i < strLength; ++i) { if (types[i] == 'ON') { var end = findUnequal(types, i + 1, 'ON'); var before = sor; @@ -351,7 +353,7 @@ var bidi = PDFJS.bidi = (function bidiClosure() { /* N2. Any remaining neutrals take the embedding direction. */ - for (var i = 0; i < strLength; ++i) { + for (i = 0; i < strLength; ++i) { if (types[i] == 'ON') { types[i] = e; } @@ -364,8 +366,8 @@ var bidi = PDFJS.bidi = (function bidiClosure() { I2. For all characters with an odd (right-to-left) embedding direction, those of type L, EN or AN go up one level. */ - for (var i = 0; i < strLength; ++i) { - var t = types[i]; + for (i = 0; i < strLength; ++i) { + t = types[i]; if (isEven(levels[i])) { if (t == 'R') { levels[i] += 1; @@ -401,8 +403,9 @@ var bidi = PDFJS.bidi = (function bidiClosure() { // find highest level & lowest odd level var highestLevel = -1; var lowestOddLevel = 99; - for (var i = 0, ii = levels.length; i < ii; ++i) { - var level = levels[i]; + var level; + for (i = 0, ii = levels.length; i < ii; ++i) { + level = levels[i]; if (highestLevel < level) { highestLevel = level; } @@ -412,10 +415,10 @@ var bidi = PDFJS.bidi = (function bidiClosure() { } // now reverse between those limits - for (var level = highestLevel; level >= lowestOddLevel; --level) { + for (level = highestLevel; level >= lowestOddLevel; --level) { // find segments to reverse var start = -1; - for (var i = 0, ii = levels.length; i < ii; ++i) { + for (i = 0, ii = levels.length; i < ii; ++i) { if (levels[i] < level) { if (start >= 0) { reverseValues(chars, start, i); @@ -449,7 +452,7 @@ var bidi = PDFJS.bidi = (function bidiClosure() { // Finally, return string var result = ''; - for (var i = 0, ii = chars.length; i < ii; ++i) { + for (i = 0, ii = chars.length; i < ii; ++i) { var ch = chars[i]; if (ch != '<' && ch != '>') { result += ch; diff --git a/src/core/chunked_stream.js b/src/core/chunked_stream.js index 216301fd6..b82f26d13 100644 --- a/src/core/chunked_stream.js +++ b/src/core/chunked_stream.js @@ -69,10 +69,11 @@ var ChunkedStream = (function ChunkedStreamClosure() { var chunkSize = this.chunkSize; var beginChunk = Math.floor(begin / chunkSize); var endChunk = Math.floor((end - 1) / chunkSize) + 1; + var curChunk; - for (var chunk = beginChunk; chunk < endChunk; ++chunk) { - if (!(chunk in this.loadedChunks)) { - this.loadedChunks[chunk] = true; + for (curChunk = beginChunk; curChunk < endChunk; ++curChunk) { + if (!(curChunk in this.loadedChunks)) { + this.loadedChunks[curChunk] = true; ++this.numChunksLoaded; } } @@ -109,13 +110,14 @@ var ChunkedStream = (function ChunkedStreamClosure() { }, nextEmptyChunk: function ChunkedStream_nextEmptyChunk(beginChunk) { - for (var chunk = beginChunk, n = this.numChunks; chunk < n; ++chunk) { + var chunk, n; + for (chunk = beginChunk, n = this.numChunks; chunk < n; ++chunk) { if (!(chunk in this.loadedChunks)) { return chunk; } } // Wrap around to beginning - for (var chunk = 0; chunk < beginChunk; ++chunk) { + for (chunk = 0; chunk < beginChunk; ++chunk) { if (!(chunk in this.loadedChunks)) { return chunk; } @@ -314,8 +316,9 @@ var ChunkedStreamManager = (function ChunkedStreamManagerClosure() { var requestId = this.currRequestId++; var chunksNeeded; + var i, ii; this.chunksNeededByRequest[requestId] = chunksNeeded = {}; - for (var i = 0, ii = chunks.length; i < ii; i++) { + for (i = 0, ii = chunks.length; i < ii; i++) { if (!this.stream.hasChunk(chunks[i])) { chunksNeeded[chunks[i]] = true; } @@ -346,7 +349,7 @@ var ChunkedStreamManager = (function ChunkedStreamManagerClosure() { var groupedChunksToRequest = this.groupChunks(chunksToRequest); - for (var i = 0; i < groupedChunksToRequest.length; ++i) { + for (i = 0; i < groupedChunksToRequest.length; ++i) { var groupedChunk = groupedChunksToRequest[i]; var begin = groupedChunk.beginChunk * this.chunkSize; var end = Math.min(groupedChunk.endChunk * this.chunkSize, this.length); @@ -445,14 +448,14 @@ var ChunkedStreamManager = (function ChunkedStreamManagerClosure() { } var loadedRequests = []; - for (var chunk = beginChunk; chunk < endChunk; ++chunk) { - + var i, requestId; + for (chunk = beginChunk; chunk < endChunk; ++chunk) { // The server might return more chunks than requested var requestIds = this.requestsByChunk[chunk] || []; delete this.requestsByChunk[chunk]; - for (var i = 0; i < requestIds.length; ++i) { - var requestId = requestIds[i]; + for (i = 0; i < requestIds.length; ++i) { + requestId = requestIds[i]; var chunksNeeded = this.chunksNeededByRequest[requestId]; if (chunk in chunksNeeded) { delete chunksNeeded[chunk]; @@ -486,8 +489,8 @@ var ChunkedStreamManager = (function ChunkedStreamManagerClosure() { } } - for (var i = 0; i < loadedRequests.length; ++i) { - var requestId = loadedRequests[i]; + for (i = 0; i < loadedRequests.length; ++i) { + requestId = loadedRequests[i]; var callback = this.callbacksByRequest[requestId]; delete this.callbacksByRequest[requestId]; if (callback) { diff --git a/src/core/cmap.js b/src/core/cmap.js index a88667ffb..f19529035 100644 --- a/src/core/cmap.js +++ b/src/core/cmap.js @@ -451,6 +451,7 @@ var BinaryCMapReader = (function BinaryCMapReaderClosure() { var ucs2DataSize = 1; var subitemsCount = stream.readNumber(); + var i; switch (type) { case 0: // codespacerange stream.readHex(start, dataSize); @@ -458,7 +459,7 @@ var BinaryCMapReader = (function BinaryCMapReaderClosure() { addHex(end, start, dataSize); cMap.addCodespaceRange(dataSize + 1, hexToInt(start, dataSize), hexToInt(end, dataSize)); - for (var i = 1; i < subitemsCount; i++) { + for (i = 1; i < subitemsCount; i++) { incHex(end, dataSize); stream.readHexNumber(start, dataSize); addHex(start, end, dataSize); @@ -474,7 +475,7 @@ var BinaryCMapReader = (function BinaryCMapReaderClosure() { addHex(end, start, dataSize); code = stream.readNumber(); // undefined range, skipping - for (var i = 1; i < subitemsCount; i++) { + for (i = 1; i < subitemsCount; i++) { incHex(end, dataSize); stream.readHexNumber(start, dataSize); addHex(start, end, dataSize); @@ -488,7 +489,7 @@ var BinaryCMapReader = (function BinaryCMapReaderClosure() { stream.readHex(char, dataSize); code = stream.readNumber(); cMap.mapOne(hexToInt(char, dataSize), String.fromCharCode(code)); - for (var i = 1; i < subitemsCount; i++) { + for (i = 1; i < subitemsCount; i++) { incHex(char, dataSize); if (!sequence) { stream.readHexNumber(tmp, dataSize); @@ -505,7 +506,7 @@ var BinaryCMapReader = (function BinaryCMapReaderClosure() { code = stream.readNumber(); cMap.mapRange(hexToInt(start, dataSize), hexToInt(end, dataSize), String.fromCharCode(code)); - for (var i = 1; i < subitemsCount; i++) { + for (i = 1; i < subitemsCount; i++) { incHex(end, dataSize); if (!sequence) { stream.readHexNumber(start, dataSize); @@ -525,7 +526,7 @@ var BinaryCMapReader = (function BinaryCMapReaderClosure() { stream.readHex(charCode, dataSize); cMap.mapOne(hexToInt(char, ucs2DataSize), hexToStr(charCode, dataSize)); - for (var i = 1; i < subitemsCount; i++) { + for (i = 1; i < subitemsCount; i++) { incHex(char, ucs2DataSize); if (!sequence) { stream.readHexNumber(tmp, ucs2DataSize); @@ -546,7 +547,7 @@ var BinaryCMapReader = (function BinaryCMapReaderClosure() { cMap.mapRange(hexToInt(start, ucs2DataSize), hexToInt(end, ucs2DataSize), hexToStr(charCode, dataSize)); - for (var i = 1; i < subitemsCount; i++) { + for (i = 1; i < subitemsCount; i++) { incHex(end, ucs2DataSize); if (!sequence) { stream.readHexNumber(start, ucs2DataSize); diff --git a/src/core/crypto.js b/src/core/crypto.js index dca99a06b..eb5d5341e 100644 --- a/src/core/crypto.js +++ b/src/core/crypto.js @@ -505,7 +505,7 @@ var CipherTransformFactory = (function CipherTransformFactoryClosure() { hashData[i++] = fileId[j]; } cipher = new ARCFourCipher(encryptionKey); - var checkData = cipher.encryptBlock(calculateMD5(hashData, 0, i)); + checkData = cipher.encryptBlock(calculateMD5(hashData, 0, i)); n = encryptionKey.length; var derivedKey = new Uint8Array(n), k; for (j = 1; j <= 19; ++j) { diff --git a/src/core/evaluator.js b/src/core/evaluator.js index 936cc189e..e189a6ab4 100644 --- a/src/core/evaluator.js +++ b/src/core/evaluator.js @@ -53,12 +53,13 @@ var PartialEvaluator = (function PartialEvaluatorClosure() { var nodes = [resources]; while (nodes.length) { + var key; var node = nodes.shift(); // First check the current resources for blend modes. var graphicStates = node.get('ExtGState'); if (isDict(graphicStates)) { graphicStates = graphicStates.getAll(); - for (var key in graphicStates) { + for (key in graphicStates) { var graphicState = graphicStates[key]; var bm = graphicState['BM']; if (isName(bm) && bm.name !== 'Normal') { @@ -72,7 +73,7 @@ var PartialEvaluator = (function PartialEvaluatorClosure() { continue; } xObjects = xObjects.getAll(); - for (var key in xObjects) { + for (key in xObjects) { var xObject = xObjects[key]; if (!isStream(xObject)) { continue; @@ -144,6 +145,7 @@ var PartialEvaluator = (function PartialEvaluatorClosure() { } var imageMask = (dict.get('ImageMask', 'IM') || false); + var imgData, args; if (imageMask) { // This depends on a tmpCanvas being filled with the // current fillStyle, such that processing the pixel @@ -159,10 +161,10 @@ var PartialEvaluator = (function PartialEvaluatorClosure() { var canTransfer = image instanceof DecodeStream; var inverseDecode = (!!decode && decode[0] > 0); - var imgData = PDFImage.createMask(imgArray, width, height, - canTransfer, inverseDecode); + imgData = PDFImage.createMask(imgArray, width, height, + canTransfer, inverseDecode); imgData.cached = true; - var args = [imgData]; + args = [imgData]; operatorList.addOp(OPS.paintImageMaskXObject, args); if (cacheKey) { cache.key = cacheKey; @@ -183,7 +185,7 @@ var PartialEvaluator = (function PartialEvaluatorClosure() { inline, null, null); // We force the use of RGBA_32BPP images here, because we can't handle // any other kind. - var imgData = imageObj.createImageData(/* forceRGBA = */ true); + imgData = imageObj.createImageData(/* forceRGBA = */ true); operatorList.addOp(OPS.paintInlineImageXObject, [imgData]); return; } @@ -193,7 +195,7 @@ var PartialEvaluator = (function PartialEvaluatorClosure() { var uniquePrefix = (this.uniquePrefix || ''); var objId = 'img_' + uniquePrefix + (++this.idCounters.obj); operatorList.addDependency(objId); - var args = [objId, w, h]; + args = [objId, w, h]; if (!softMask && !mask && image instanceof JpegStream && image.isNativelySupported(this.xref, resources)) { @@ -511,10 +513,11 @@ var PartialEvaluator = (function PartialEvaluatorClosure() { var preprocessor = new EvaluatorPreprocessor(stream, xref, stateManager); var promise = new LegacyPromise(); - var operation; + var operation, i, ii; while ((operation = preprocessor.read())) { var args = operation.args; var fn = operation.fn; + var shading; switch (fn) { case OPS.setStrokeColorN: @@ -537,10 +540,10 @@ var PartialEvaluator = (function PartialEvaluatorClosure() { args = []; continue; } else if (typeNum == SHADING_PATTERN) { - var shading = dict.get('Shading'); + shading = dict.get('Shading'); var matrix = dict.get('Matrix'); - var pattern = Pattern.parseShading(shading, matrix, xref, - resources); + pattern = Pattern.parseShading(shading, matrix, xref, + resources); args = pattern.getIR(); } else { error('Unkown PatternType ' + typeNum); @@ -609,7 +612,7 @@ var PartialEvaluator = (function PartialEvaluatorClosure() { case OPS.showSpacedText: var arr = args[0]; var arrLength = arr.length; - for (var i = 0; i < arrLength; ++i) { + for (i = 0; i < arrLength; ++i) { if (isString(arr[i])) { arr[i] = this.handleText(arr[i], stateManager.state); } @@ -635,7 +638,7 @@ var PartialEvaluator = (function PartialEvaluatorClosure() { error('No shading resource found'); } - var shading = shadingRes.get(args[0].name); + shading = shadingRes.get(args[0].name); if (!shading) { error('No shading object found'); } @@ -665,7 +668,7 @@ var PartialEvaluator = (function PartialEvaluatorClosure() { // Some PDFs don't close all restores inside object/form. // Closing those for them. - for (var i = 0, ii = preprocessor.savedStatesDepth; i < ii; i++) { + for (i = 0, ii = preprocessor.savedStatesDepth; i < ii; i++) { operatorList.addOp(OPS.restore, []); } @@ -874,17 +877,18 @@ var PartialEvaluator = (function PartialEvaluatorClosure() { case OPS.showSpacedText: var items = args[0]; var textChunk = newTextChunk(); + var offset; for (var j = 0, jj = items.length; j < jj; j++) { if (typeof items[j] === 'string') { buildTextGeometry(items[j], textChunk); } else { var val = items[j] / 1000; if (!textState.font.vertical) { - var offset = -val * textState.fontSize * textState.textHScale; + offset = -val * textState.fontSize * textState.textHScale; textState.translateTextMatrix(offset, 0); textChunk.width += offset; } else { - var offset = -val * textState.fontSize; + offset = -val * textState.fontSize; textState.translateTextMatrix(0, offset); textChunk.height += offset; } @@ -1023,8 +1027,9 @@ var PartialEvaluator = (function PartialEvaluatorClosure() { // differences to be merged in here not require us to hold on to it. var differences = []; var baseEncodingName = null; + var encoding; if (dict.has('Encoding')) { - var encoding = dict.get('Encoding'); + encoding = dict.get('Encoding'); if (isDict(encoding)) { baseEncodingName = encoding.get('BaseEncoding'); baseEncodingName = (isName(baseEncodingName) ? @@ -1059,9 +1064,8 @@ var PartialEvaluator = (function PartialEvaluatorClosure() { if (baseEncodingName) { properties.defaultEncoding = Encodings[baseEncodingName].slice(); } else { - var encoding = (properties.type === 'TrueType' ? - Encodings.WinAnsiEncoding : - Encodings.StandardEncoding); + encoding = (properties.type === 'TrueType' ? + Encodings.WinAnsiEncoding : Encodings.StandardEncoding); // The Symbolic attribute can be misused for regular fonts // Heuristic: we have to check if the font is a standard one also if (!!(properties.flags & FontFlags.Symbolic)) { @@ -1130,21 +1134,22 @@ var PartialEvaluator = (function PartialEvaluatorClosure() { var defaultWidth = 0; var glyphsVMetrics = []; var defaultVMetrics; + var i, ii, j, jj, start, code, widths; if (properties.composite) { defaultWidth = dict.get('DW') || 1000; - var widths = dict.get('W'); + widths = dict.get('W'); if (widths) { - for (var i = 0, ii = widths.length; i < ii; i++) { - var start = widths[i++]; - var code = xref.fetchIfRef(widths[i]); + for (i = 0, ii = widths.length; i < ii; i++) { + start = widths[i++]; + code = xref.fetchIfRef(widths[i]); if (isArray(code)) { - for (var j = 0, jj = code.length; j < jj; j++) { + for (j = 0, jj = code.length; j < jj; j++) { glyphsWidths[start++] = code[j]; } } else { var width = widths[++i]; - for (var j = start; j <= code; j++) { + for (j = start; j <= code; j++) { glyphsWidths[j] = width; } } @@ -1156,16 +1161,16 @@ var PartialEvaluator = (function PartialEvaluatorClosure() { defaultVMetrics = [vmetrics[1], defaultWidth * 0.5, vmetrics[0]]; vmetrics = dict.get('W2'); if (vmetrics) { - for (var i = 0, ii = vmetrics.length; i < ii; i++) { - var start = vmetrics[i++]; - var code = xref.fetchIfRef(vmetrics[i]); + for (i = 0, ii = vmetrics.length; i < ii; i++) { + start = vmetrics[i++]; + code = xref.fetchIfRef(vmetrics[i]); if (isArray(code)) { - for (var j = 0, jj = code.length; j < jj; j++) { + for (j = 0, jj = code.length; j < jj; j++) { glyphsVMetrics[start++] = [code[j++], code[j++], code[j]]; } } else { var vmetric = [vmetrics[++i], vmetrics[++i], vmetrics[++i]]; - for (var j = start; j <= code; j++) { + for (j = start; j <= code; j++) { glyphsVMetrics[j] = vmetric; } } @@ -1174,10 +1179,10 @@ var PartialEvaluator = (function PartialEvaluatorClosure() { } } else { var firstChar = properties.firstChar; - var widths = dict.get('Widths'); + widths = dict.get('Widths'); if (widths) { - var j = firstChar; - for (var i = 0, ii = widths.length; i < ii; i++) { + j = firstChar; + for (i = 0, ii = widths.length; i < ii; i++) { glyphsWidths[j++] = widths[i]; } defaultWidth = (parseFloat(descriptor.get('MissingWidth')) || 0); @@ -1285,6 +1290,7 @@ var PartialEvaluator = (function PartialEvaluatorClosure() { assertWellFormed(isName(type), 'invalid font Subtype'); var composite = false; + var uint8array; if (type.name == 'Type0') { // If font is a composite // - get the descendant font @@ -1314,7 +1320,7 @@ var PartialEvaluator = (function PartialEvaluatorClosure() { var toUnicode = dict.get('ToUnicode') || baseDict.get('ToUnicode'); if (isStream(toUnicode)) { var stream = toUnicode.str || toUnicode; - var uint8array = stream.buffer ? + uint8array = stream.buffer ? new Uint8Array(stream.buffer.buffer, 0, stream.bufferLength) : new Uint8Array(stream.bytes.buffer, stream.start, stream.end - stream.start); @@ -1326,7 +1332,7 @@ var PartialEvaluator = (function PartialEvaluatorClosure() { var widths = dict.get('Widths') || baseDict.get('Widths'); if (widths) { - var uint8array = new Uint8Array(new Uint32Array(widths).buffer); + uint8array = new Uint8Array(new Uint32Array(widths).buffer); hash.update(uint8array); } } @@ -1348,6 +1354,7 @@ var PartialEvaluator = (function PartialEvaluatorClosure() { var descriptor = preEvaluatedFont.descriptor; var type = dict.get('Subtype'); var maxCharIndex = (composite ? 0xFFFF : 0xFF); + var properties; if (!descriptor) { if (type.name == 'Type3') { @@ -1376,7 +1383,7 @@ var PartialEvaluator = (function PartialEvaluatorClosure() { (symbolsFonts[fontNameWoStyle] ? FontFlags.Symbolic : FontFlags.Nonsymbolic); - var properties = { + properties = { type: type.name, name: baseFontName, widths: metrics.widths, @@ -1441,7 +1448,7 @@ var PartialEvaluator = (function PartialEvaluatorClosure() { } } - var properties = { + properties = { type: type.name, name: fontName.name, subtype: subtype, @@ -1683,7 +1690,7 @@ var EvalState = (function EvalStateClosure() { return EvalState; })(); -var EvaluatorPreprocessor = (function EvaluatorPreprocessor() { +var EvaluatorPreprocessor = (function EvaluatorPreprocessorClosure() { // Specifies properties for each command // // If variableArgs === true: [0, `numArgs`] expected @@ -1937,7 +1944,8 @@ var QueueOptimizer = (function QueueOptimizerClosure() { var maxX = 0; var map = [], maxLineHeight = 0; var currentX = IMAGE_PADDING, currentY = IMAGE_PADDING; - for (var q = 0; q < count; q++) { + var q; + for (q = 0; q < count; q++) { var transform = argsArray[j + (q << 2) + 1]; var img = argsArray[j + (q << 2) + 2][0]; if (currentX + img.width > MAX_WIDTH) { @@ -1959,7 +1967,7 @@ var QueueOptimizer = (function QueueOptimizerClosure() { var imgHeight = currentY + maxLineHeight + IMAGE_PADDING; var imgData = new Uint8Array(imgWidth * imgHeight * 4); var imgRowSize = imgWidth << 2; - for (var q = 0; q < count; q++) { + for (q = 0; q < count; q++) { var data = argsArray[j + (q << 2) + 2][0].data; // copy image by lines and extends pixels into padding var rowSize = map[q].w << 2; @@ -2003,7 +2011,7 @@ var QueueOptimizer = (function QueueOptimizerClosure() { var fnArray = context.fnArray, argsArray = context.argsArray; var j = context.currentOperation - 3, i = j + 4; - var ii = fnArray.length; + var ii = fnArray.length, q; for (; i < ii && fnArray[i - 4] === fnArray[i]; i++) {} var count = (i - j) >> 2; @@ -2014,12 +2022,13 @@ var QueueOptimizer = (function QueueOptimizerClosure() { } var isSameImage = false; + var transformArgs; if (argsArray[j + 1][1] === 0 && argsArray[j + 1][2] === 0) { i = j + 4; isSameImage = true; - for (var q = 1; q < count; q++, i += 4) { + for (q = 1; q < count; q++, i += 4) { var prevTransformArgs = argsArray[i - 3]; - var transformArgs = argsArray[i + 1]; + transformArgs = argsArray[i + 1]; if (argsArray[i - 2][0] !== argsArray[i + 2][0] || prevTransformArgs[0] !== transformArgs[0] || prevTransformArgs[1] !== transformArgs[1] || @@ -2039,8 +2048,8 @@ var QueueOptimizer = (function QueueOptimizerClosure() { count = Math.min(count, MAX_SAME_IMAGES_IN_MASKS_BLOCK); var positions = new Float32Array(count * 2); i = j + 1; - for (var q = 0; q < count; q++) { - var transformArgs = argsArray[i]; + for (q = 0; q < count; q++) { + transformArgs = argsArray[i]; positions[(q << 1)] = transformArgs[4]; positions[(q << 1) + 1] = transformArgs[5]; i += 4; @@ -2055,8 +2064,8 @@ var QueueOptimizer = (function QueueOptimizerClosure() { } else { count = Math.min(count, MAX_IMAGES_IN_MASKS_BLOCK); var images = []; - for (var q = 0; q < count; q++) { - var transformArgs = argsArray[j + (q << 2) + 1]; + for (q = 0; q < count; q++) { + transformArgs = argsArray[j + (q << 2) + 1]; var maskParams = argsArray[j + (q << 2) + 2][0]; images.push({ data: maskParams.data, width: maskParams.width, height: maskParams.height, @@ -2083,6 +2092,7 @@ var QueueOptimizer = (function QueueOptimizerClosure() { return; } var ii = fnArray.length; + var transformArgs; for (; i + 3 < ii && fnArray[i - 4] === fnArray[i]; i += 4) { if (fnArray[i - 3] !== fnArray[i + 1] || fnArray[i - 2] !== fnArray[i + 2] || @@ -2093,7 +2103,7 @@ var QueueOptimizer = (function QueueOptimizerClosure() { break; // different image } var prevTransformArgs = argsArray[i - 3]; - var transformArgs = argsArray[i + 1]; + transformArgs = argsArray[i + 1]; if (prevTransformArgs[0] !== transformArgs[0] || prevTransformArgs[1] !== transformArgs[1] || prevTransformArgs[2] !== transformArgs[2] || @@ -2110,7 +2120,7 @@ var QueueOptimizer = (function QueueOptimizerClosure() { var positions = new Float32Array(count * 2); i = j + 1; for (var q = 0; q < count; q++) { - var transformArgs = argsArray[i]; + transformArgs = argsArray[i]; positions[(q << 1)] = transformArgs[4]; positions[(q << 1) + 1] = transformArgs[5]; i += 4; diff --git a/src/core/font_renderer.js b/src/core/font_renderer.js index 117f51065..ebaacc3ed 100644 --- a/src/core/font_renderer.js +++ b/src/core/font_renderer.js @@ -33,22 +33,23 @@ var FontRendererFactory = (function FontRendererFactoryClosure() { var offset = (getUshort(data, start + 2) === 1 ? getLong(data, start + 8) : getLong(data, start + 16)); var format = getUshort(data, start + offset); + var length, ranges, p, i; if (format === 4) { - var length = getUshort(data, start + offset + 2); + length = getUshort(data, start + offset + 2); var segCount = getUshort(data, start + offset + 6) >> 1; - var p = start + offset + 14; - var ranges = []; - for (var i = 0; i < segCount; i++, p += 2) { + p = start + offset + 14; + ranges = []; + for (i = 0; i < segCount; i++, p += 2) { ranges[i] = {end: getUshort(data, p)}; } p += 2; - for (var i = 0; i < segCount; i++, p += 2) { + for (i = 0; i < segCount; i++, p += 2) { ranges[i].start = getUshort(data, p); } - for (var i = 0; i < segCount; i++, p += 2) { + for (i = 0; i < segCount; i++, p += 2) { ranges[i].idDelta = getUshort(data, p); } - for (var i = 0; i < segCount; i++, p += 2) { + for (i = 0; i < segCount; i++, p += 2) { var idOffset = getUshort(data, p); if (idOffset === 0) { continue; @@ -61,11 +62,11 @@ var FontRendererFactory = (function FontRendererFactoryClosure() { } return ranges; } else if (format === 12) { - var length = getLong(data, start + offset + 4); + length = getLong(data, start + offset + 4); var groups = getLong(data, start + offset + 12); - var p = start + offset + 16; - var ranges = []; - for (var i = 0; i < groups; i++) { + p = start + offset + 16; + ranges = []; + for (i = 0; i < groups; i++) { ranges.push({ start: getLong(data, p), end: getLong(data, p + 4), @@ -151,12 +152,13 @@ var FontRendererFactory = (function FontRendererFactoryClosure() { var yMin = ((code[i + 4] << 24) | (code[i + 5] << 16)) >> 16; var xMax = ((code[i + 6] << 24) | (code[i + 7] << 16)) >> 16; var yMax = ((code[i + 8] << 24) | (code[i + 9] << 16)) >> 16; + var flags; + var x = 0, y = 0; i += 10; if (numberOfContours < 0) { // composite glyph - var x = 0, y = 0; do { - var flags = (code[i] << 8) | code[i + 1]; + flags = (code[i] << 8) | code[i + 1]; var glyphIndex = (code[i + 2] << 8) | code[i + 3]; i += 4; var arg1, arg2; @@ -201,7 +203,8 @@ var FontRendererFactory = (function FontRendererFactoryClosure() { } else { // simple glyph var endPtsOfContours = []; - for (var j = 0; j < numberOfContours; j++) { + var j, jj; + for (j = 0; j < numberOfContours; j++) { endPtsOfContours.push((code[i] << 8) | code[i + 1]); i += 2; } @@ -210,7 +213,8 @@ var FontRendererFactory = (function FontRendererFactoryClosure() { var numberOfPoints = endPtsOfContours[endPtsOfContours.length - 1] + 1; var points = []; while (points.length < numberOfPoints) { - var flags = code[i++], repeat = 1; + flags = code[i++]; + var repeat = 1; if ((flags & 0x08)) { repeat += code[i++]; } @@ -218,8 +222,7 @@ var FontRendererFactory = (function FontRendererFactoryClosure() { points.push({flags: flags}); } } - var x = 0, y = 0; - for (var j = 0; j < numberOfPoints; j++) { + for (j = 0; j < numberOfPoints; j++) { switch (points[j].flags & 0x12) { case 0x00: x += ((code[i] << 24) | (code[i + 1] << 16)) >> 16; @@ -234,7 +237,7 @@ var FontRendererFactory = (function FontRendererFactoryClosure() { } points[j].x = x; } - for (var j = 0; j < numberOfPoints; j++) { + for (j = 0; j < numberOfPoints; j++) { switch (points[j].flags & 0x24) { case 0x00: y += ((code[i] << 24) | (code[i + 1] << 16)) >> 16; @@ -251,7 +254,7 @@ var FontRendererFactory = (function FontRendererFactoryClosure() { } var startPoint = 0; - for (var i = 0; i < numberOfContours; i++) { + for (i = 0; i < numberOfContours; i++) { var endPoint = endPtsOfContours[i]; // contours might have implicit points, which is located in the middle // between two neighboring off-curve points @@ -272,7 +275,7 @@ var FontRendererFactory = (function FontRendererFactoryClosure() { contour.push(p); } moveTo(contour[0].x, contour[0].y); - for (var j = 1, jj = contour.length; j < jj; j++) { + for (j = 1, jj = contour.length; j < jj; j++) { if ((contour[j].flags & 1)) { lineTo(contour[j].x, contour[j].y); } else if ((contour[j + 1].flags & 1)){ @@ -311,6 +314,7 @@ var FontRendererFactory = (function FontRendererFactoryClosure() { while (i < code.length) { var stackClean = false; var v = code[i++]; + var xa, xb, ya, yb, y1, y2, y3, n, subrCode; switch (v) { case 1: // hstem stems += stack.length >> 1; @@ -356,15 +360,15 @@ var FontRendererFactory = (function FontRendererFactoryClosure() { break; case 8: // rrcurveto while (stack.length > 0) { - var xa = x + stack.shift(), ya = y + stack.shift(); - var xb = xa + stack.shift(), yb = ya + stack.shift(); + xa = x + stack.shift(); ya = y + stack.shift(); + xb = xa + stack.shift(); yb = ya + stack.shift(); x = xb + stack.shift(); y = yb + stack.shift(); bezierCurveTo(xa, ya, xb, yb, x, y); } break; case 10: // callsubr - var n = stack.pop() + font.subrsBias; - var subrCode = font.subrs[n]; + n = stack.pop() + font.subrsBias; + subrCode = font.subrs[n]; if (subrCode) { parse(subrCode); } @@ -375,44 +379,44 @@ var FontRendererFactory = (function FontRendererFactoryClosure() { v = code[i++]; switch (v) { case 34: // flex - var xa = x + stack.shift(); - var xb = xa + stack.shift(), y1 = y + stack.shift(); + xa = x + stack.shift(); + xb = xa + stack.shift(); y1 = y + stack.shift(); x = xb + stack.shift(); bezierCurveTo(xa, y, xb, y1, x, y1); - var xa = x + stack.shift(); - var xb = xa + stack.shift(); + xa = x + stack.shift(); + xb = xa + stack.shift(); x = xb + stack.shift(); bezierCurveTo(xa, y1, xb, y, x, y); break; case 35: // flex - var xa = x + stack.shift(), ya = y + stack.shift(); - var xb = xa + stack.shift(), yb = ya + stack.shift(); + xa = x + stack.shift(); ya = y + stack.shift(); + xb = xa + stack.shift(); yb = ya + stack.shift(); x = xb + stack.shift(); y = yb + stack.shift(); bezierCurveTo(xa, ya, xb, yb, x, y); - var xa = x + stack.shift(), ya = y + stack.shift(); - var xb = xa + stack.shift(), yb = ya + stack.shift(); + xa = x + stack.shift(); ya = y + stack.shift(); + xb = xa + stack.shift(); yb = ya + stack.shift(); x = xb + stack.shift(); y = yb + stack.shift(); bezierCurveTo(xa, ya, xb, yb, x, y); stack.pop(); // fd break; case 36: // hflex1 - var xa = x + stack.shift(), y1 = y + stack.shift(); - var xb = xa + stack.shift(), y2 = y1 + stack.shift(); + xa = x + stack.shift(); y1 = y + stack.shift(); + xb = xa + stack.shift(); y2 = y1 + stack.shift(); x = xb + stack.shift(); bezierCurveTo(xa, y1, xb, y2, x, y2); - var xa = x + stack.shift(); - var xb = xa + stack.shift(), y3 = y2 + stack.shift(); + xa = x + stack.shift(); + xb = xa + stack.shift(); y3 = y2 + stack.shift(); x = xb + stack.shift(); bezierCurveTo(xa, y2, xb, y3, x, y); break; case 37: // flex1 var x0 = x, y0 = y; - var xa = x + stack.shift(), ya = y + stack.shift(); - var xb = xa + stack.shift(), yb = ya + stack.shift(); + xa = x + stack.shift(); ya = y + stack.shift(); + xb = xa + stack.shift(); yb = ya + stack.shift(); x = xb + stack.shift(); y = yb + stack.shift(); bezierCurveTo(xa, ya, xb, yb, x, y); - var xa = x + stack.shift(), ya = y + stack.shift(); - var xb = xa + stack.shift(), yb = ya + stack.shift(); + xa = x + stack.shift(); ya = y + stack.shift(); + xb = xa + stack.shift(); yb = ya + stack.shift(); x = xb; y = yb; if (Math.abs(x - x0) > Math.abs(y - y0)) { x += stack.shift(); @@ -474,8 +478,8 @@ var FontRendererFactory = (function FontRendererFactoryClosure() { break; case 24: // rcurveline while (stack.length > 2) { - var xa = x + stack.shift(), ya = y + stack.shift(); - var xb = xa + stack.shift(), yb = ya + stack.shift(); + xa = x + stack.shift(); ya = y + stack.shift(); + xb = xa + stack.shift(); yb = ya + stack.shift(); x = xb + stack.shift(); y = yb + stack.shift(); bezierCurveTo(xa, ya, xb, yb, x, y); } @@ -489,8 +493,8 @@ var FontRendererFactory = (function FontRendererFactoryClosure() { y += stack.shift(); lineTo(x, y); } - var xa = x + stack.shift(), ya = y + stack.shift(); - var xb = xa + stack.shift(), yb = ya + stack.shift(); + xa = x + stack.shift(); ya = y + stack.shift(); + xb = xa + stack.shift(); yb = ya + stack.shift(); x = xb + stack.shift(); y = yb + stack.shift(); bezierCurveTo(xa, ya, xb, yb, x, y); break; @@ -499,8 +503,8 @@ var FontRendererFactory = (function FontRendererFactoryClosure() { x += stack.shift(); } while (stack.length > 0) { - var xa = x, ya = y + stack.shift(); - var xb = xa + stack.shift(), yb = ya + stack.shift(); + xa = x; ya = y + stack.shift(); + xb = xa + stack.shift(); yb = ya + stack.shift(); x = xb; y = yb + stack.shift(); bezierCurveTo(xa, ya, xb, yb, x, y); } @@ -510,8 +514,8 @@ var FontRendererFactory = (function FontRendererFactoryClosure() { y += stack.shift(); } while (stack.length > 0) { - var xa = x + stack.shift(), ya = y; - var xb = xa + stack.shift(), yb = ya + stack.shift(); + xa = x + stack.shift(); ya = y; + xb = xa + stack.shift(); yb = ya + stack.shift(); x = xb + stack.shift(); y = yb; bezierCurveTo(xa, ya, xb, yb, x, y); } @@ -521,16 +525,16 @@ var FontRendererFactory = (function FontRendererFactoryClosure() { i += 2; break; case 29: // callgsubr - var n = stack.pop() + font.gsubrsBias; - var subrCode = font.gsubrs[n]; + n = stack.pop() + font.gsubrsBias; + subrCode = font.gsubrs[n]; if (subrCode) { parse(subrCode); } break; case 30: // vhcurveto while (stack.length > 0) { - var xa = x, ya = y + stack.shift(); - var xb = xa + stack.shift(), yb = ya + stack.shift(); + xa = x; ya = y + stack.shift(); + xb = xa + stack.shift(); yb = ya + stack.shift(); x = xb + stack.shift(); y = yb + (stack.length === 1 ? stack.shift() : 0); bezierCurveTo(xa, ya, xb, yb, x, y); @@ -538,8 +542,8 @@ var FontRendererFactory = (function FontRendererFactoryClosure() { break; } - var xa = x + stack.shift(), ya = y; - var xb = xa + stack.shift(), yb = ya + stack.shift(); + xa = x + stack.shift(); ya = y; + xb = xa + stack.shift(); yb = ya + stack.shift(); y = yb + stack.shift(); x = xb + (stack.length === 1 ? stack.shift() : 0); bezierCurveTo(xa, ya, xb, yb, x, y); @@ -547,8 +551,8 @@ var FontRendererFactory = (function FontRendererFactoryClosure() { break; case 31: // hvcurveto while (stack.length > 0) { - var xa = x + stack.shift(), ya = y; - var xb = xa + stack.shift(), yb = ya + stack.shift(); + xa = x + stack.shift(); ya = y; + xb = xa + stack.shift(); yb = ya + stack.shift(); y = yb + stack.shift(); x = xb + (stack.length === 1 ? stack.shift() : 0); bezierCurveTo(xa, ya, xb, yb, x, y); @@ -556,8 +560,8 @@ var FontRendererFactory = (function FontRendererFactoryClosure() { break; } - var xa = x, ya = y + stack.shift(); - var xb = xa + stack.shift(), yb = ya + stack.shift(); + xa = x; ya = y + stack.shift(); + xb = xa + stack.shift(); yb = ya + stack.shift(); x = xb + stack.shift(); y = yb + (stack.length === 1 ? stack.shift() : 0); bezierCurveTo(xa, ya, xb, yb, x, y); diff --git a/src/core/fonts.js b/src/core/fonts.js index 3da4cae21..4d21a503c 100644 --- a/src/core/fonts.js +++ b/src/core/fonts.js @@ -2148,6 +2148,7 @@ var Glyph = (function GlyphClosure() { */ var Font = (function FontClosure() { function Font(name, file, properties) { + var charCode; this.name = name; this.loadedName = properties.loadedName; @@ -2187,7 +2188,7 @@ var Font = (function FontClosure() { this.toFontChar = []; if (properties.type == 'Type3') { - for (var charCode = 0; charCode < 256; charCode++) { + for (charCode = 0; charCode < 256; charCode++) { this.toFontChar[charCode] = (this.differences[charCode] || properties.defaultEncoding[charCode]); } @@ -2231,7 +2232,7 @@ var Font = (function FontClosure() { this.toUnicode = map; } else if (/Symbol/i.test(fontName)) { var symbols = Encodings.SymbolSetEncoding; - for (var charCode in symbols) { + for (charCode in symbols) { var fontChar = GlyphsUnicode[symbols[charCode]]; if (!fontChar) { continue; @@ -2240,13 +2241,13 @@ var Font = (function FontClosure() { } } else if (isStandardFont) { this.toFontChar = []; - for (var charCode in properties.defaultEncoding) { + for (charCode in properties.defaultEncoding) { var glyphName = properties.differences[charCode] || properties.defaultEncoding[charCode]; this.toFontChar[charCode] = GlyphsUnicode[glyphName]; } } else { - for (var charCode in this.toUnicode) { + for (charCode in this.toUnicode) { this.toFontChar[charCode] = this.toUnicode[charCode].charCodeAt(0); } } @@ -2516,7 +2517,8 @@ var Font = (function FontClosure() { '\x00\x01' + // encodingID string32(4 + numTables * 8); // start of the table record - for (var i = ranges.length - 1; i >= 0; --i) { + var i, ii, j, jj; + for (i = ranges.length - 1; i >= 0; --i) { if (ranges[i][0] <= 0xFFFF) { break; } } var bmpLength = i + 1; @@ -2538,16 +2540,17 @@ var Font = (function FontClosure() { var idRangeOffsets = ''; var glyphsIds = ''; var bias = 0; - - for (var i = 0, ii = bmpLength; i < ii; i++) { - var range = ranges[i]; - var start = range[0]; - var end = range[1]; + + var range, start, end, codes; + for (i = 0, ii = bmpLength; i < ii; i++) { + range = ranges[i]; + start = range[0]; + end = range[1]; startCount += string16(start); endCount += string16(end); - var codes = range[2]; + codes = range[2]; var contiguous = true; - for (var j = 1, jj = codes.length; j < jj; ++j) { + for (j = 1, jj = codes.length; j < jj; ++j) { if (codes[j] !== codes[j - 1] + 1) { contiguous = false; break; @@ -2560,7 +2563,7 @@ var Font = (function FontClosure() { idDeltas += string16(0); idRangeOffsets += string16(offset); - for (var j = 0, jj = codes.length; j < jj; ++j) { + for (j = 0, jj = codes.length; j < jj; ++j) { glyphsIds += string16(codes[j]); } } else { @@ -2594,14 +2597,14 @@ var Font = (function FontClosure() { string32(4 + numTables * 8 + 4 + format314.length); // start of the table record format31012 = ''; - for (var i = 0, ii = ranges.length; i < ii; i++) { - var range = ranges[i]; - var start = range[0]; - var codes = range[2]; + for (i = 0, ii = ranges.length; i < ii; i++) { + range = ranges[i]; + start = range[0]; + codes = range[2]; var code = codes[0]; - for (var j = 1, jj = codes.length; j < jj; ++j) { + for (j = 1, jj = codes.length; j < jj; ++j) { if (codes[j] !== codes[j - 1] + 1) { - var end = range[0] + j - 1; + end = range[0] + j - 1; format31012 += string32(start) + // startCharCode string32(end) + // endCharCode string32(code); // startGlyphID @@ -2793,11 +2796,12 @@ var Font = (function FontClosure() { // Mac want 1-byte per character strings while Windows want // 2-bytes per character, so duplicate the names table var stringsUnicode = []; - for (var i = 0, ii = strings.length; i < ii; i++) { - var str = proto[1][i] || strings[i]; + var i, ii, j, jj, str; + for (i = 0, ii = strings.length; i < ii; i++) { + str = proto[1][i] || strings[i]; var strBufUnicode = []; - for (var j = 0, jj = str.length; j < jj; j++) { + for (j = 0, jj = str.length; j < jj; j++) { strBufUnicode.push(string16(str.charCodeAt(j))); } stringsUnicode.push(strBufUnicode.join('')); @@ -2816,10 +2820,10 @@ var Font = (function FontClosure() { // Build the name records field var strOffset = 0; - for (var i = 0, ii = platforms.length; i < ii; i++) { + for (i = 0, ii = platforms.length; i < ii; i++) { var strs = names[i]; - for (var j = 0, jj = strs.length; j < jj; j++) { - var str = strs[j]; + for (j = 0, jj = strs.length; j < jj; j++) { + str = strs[j]; var nameRecord = platforms[i] + // platform ID encodings[i] + // encoding ID @@ -2901,6 +2905,7 @@ var Font = (function FontClosure() { * PDF spec */ function readCmapTable(cmap, font, isSymbolicFont) { + var segment; var start = (font.start ? font.start : 0) + cmap.offset; font.pos = start; @@ -2957,10 +2962,11 @@ var Font = (function FontClosure() { var hasShortCmap = false; var mappings = []; + var j, glyphId; // TODO(mack): refactor this cmap subtable reading logic out if (format === 0) { - for (var j = 0; j < 256; j++) { + for (j = 0; j < 256; j++) { var index = font.getByte(); if (!index) { continue; @@ -2991,7 +2997,7 @@ var Font = (function FontClosure() { var offsetsCount = 0; for (segIndex = 0; segIndex < segCount; segIndex++) { - var segment = segments[segIndex]; + segment = segments[segIndex]; var rangeOffset = font.getUint16(); if (!rangeOffset) { segment.offsetIndex = -1; @@ -3005,22 +3011,24 @@ var Font = (function FontClosure() { } var offsets = []; - for (var j = 0; j < offsetsCount; j++) { + for (j = 0; j < offsetsCount; j++) { offsets.push(font.getUint16()); } for (segIndex = 0; segIndex < segCount; segIndex++) { - var segment = segments[segIndex]; - var start = segment.start, end = segment.end; - var delta = segment.delta, offsetIndex = segment.offsetIndex; + segment = segments[segIndex]; + start = segment.start; + var end = segment.end; + var delta = segment.delta; + offsetIndex = segment.offsetIndex; - for (var j = start; j <= end; j++) { + for (j = start; j <= end; j++) { if (j == 0xFFFF) { continue; } - var glyphId = (offsetIndex < 0 ? - j : offsets[offsetIndex + j - start]); + glyphId = (offsetIndex < 0 ? + j : offsets[offsetIndex + j - start]); glyphId = (glyphId + delta) & 0xFFFF; if (glyphId === 0) { continue; @@ -3042,8 +3050,8 @@ var Font = (function FontClosure() { var glyphs = []; var ids = []; - for (var j = 0; j < entryCount; j++) { - var glyphId = font.getUint16(); + for (j = 0; j < entryCount; j++) { + glyphId = font.getUint16(); var charCode = firstCode + j; mappings.push({ @@ -3059,7 +3067,7 @@ var Font = (function FontClosure() { mappings.sort(function (a, b) { return a.charCode - b.charCode; }); - for (var i = 1; i < mappings.length; i++) { + for (i = 1; i < mappings.length; i++) { if (mappings[i - 1].charCode === mappings[i].charCode) { mappings.splice(i, 1); i--; @@ -3099,13 +3107,14 @@ var Font = (function FontClosure() { var numMissing = numOfSidebearings - ((metrics.length - numOfMetrics * 4) >> 1); + var i, ii; if (numMissing > 0) { font.pos = (font.start ? font.start : 0) + metrics.offset; var entries = ''; - for (var i = 0, ii = metrics.length; i < ii; i++) { + for (i = 0, ii = metrics.length; i < ii; i++) { entries += String.fromCharCode(font.getByte()); } - for (var i = 0; i < numMissing; i++) { + for (i = 0; i < numMissing; i++) { entries += '\x00\x00'; } metrics.data = stringToArray(entries); @@ -3126,8 +3135,8 @@ var Font = (function FontClosure() { return glyf.length; } - var j = 10, flagsCount = 0; - for (var i = 0; i < contoursCount; i++) { + var i, j = 10, flagsCount = 0; + for (i = 0; i < contoursCount; i++) { var endPoint = (glyf[j] << 8) | glyf[j + 1]; flagsCount = endPoint + 1; j += 2; @@ -3139,7 +3148,7 @@ var Font = (function FontClosure() { var instructionsEnd = j; // validating flags var coordinatesLength = 0; - for (var i = 0; i < flagsCount; i++) { + for (i = 0; i < flagsCount; i++) { var flag = glyf[j++]; if (flag & 0xC0) { // reserved flags must be zero, cleaning up @@ -3270,7 +3279,8 @@ var Font = (function FontClosure() { var startOffset = itemDecode(locaData, 0); var writeOffset = 0; itemEncode(locaData, 0, writeOffset); - for (var i = 0, j = itemSize; i < numGlyphs; i++, j += itemSize) { + var i, j; + for (i = 0, j = itemSize; i < numGlyphs; i++, j += itemSize) { var endOffset = itemDecode(locaData, j); if (endOffset > oldGlyfDataLength && ((oldGlyfDataLength + 3) & ~3) === endOffset) { @@ -3297,7 +3307,7 @@ var Font = (function FontClosure() { // to have single glyph with one point var simpleGlyph = new Uint8Array( [0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 49, 0]); - for (var i = 0, j = itemSize; i < numGlyphs; i++, j += itemSize) { + for (i = 0, j = itemSize; i < numGlyphs; i++, j += itemSize) { itemEncode(locaData, j, simpleGlyph.length); } glyf.data = simpleGlyph; @@ -3331,6 +3341,8 @@ var Font = (function FontClosure() { var glyphNames; var valid = true; + var i; + switch (version) { case 0x00010000: glyphNames = MacStandardGlyphOrdering; @@ -3342,7 +3354,7 @@ var Font = (function FontClosure() { break; } var glyphNameIndexes = []; - for (var i = 0; i < numGlyphs; ++i) { + for (i = 0; i < numGlyphs; ++i) { var index = font.getUint16(); if (index >= 32768) { valid = false; @@ -3357,13 +3369,13 @@ var Font = (function FontClosure() { while (font.pos < end) { var stringLength = font.getByte(); var string = ''; - for (var i = 0; i < stringLength; ++i) { + for (i = 0; i < stringLength; ++i) { string += String.fromCharCode(font.getByte()); } customNames.push(string); } glyphNames = []; - for (var i = 0; i < numGlyphs; ++i) { + for (i = 0; i < numGlyphs; ++i) { var j = glyphNameIndexes[i]; if (j < 258) { glyphNames.push(MacStandardGlyphOrdering[j]); @@ -3399,7 +3411,9 @@ var Font = (function FontClosure() { var stringsStart = font.getUint16(); var records = []; var NAME_RECORD_LENGTH = 12; - for (var i = 0; i < numRecords && + var i, ii; + + for (i = 0; i < numRecords && font.pos + NAME_RECORD_LENGTH <= end; i++) { var r = { platform: font.getUint16(), @@ -3415,7 +3429,7 @@ var Font = (function FontClosure() { records.push(r); } } - for (var i = 0, ii = records.length; i < ii; i++) { + for (i = 0, ii = records.length; i < ii; i++) { var record = records[i]; var pos = start + stringsStart + record.offset; if (pos + record.length > end) { @@ -3452,7 +3466,7 @@ var Font = (function FontClosure() { function sanitizeTTProgram(table, ttContext) { var data = table.data; - var i = 0, n, lastEndf = 0, lastDeff = 0; + var i = 0, j, n, b, funcId, pc, lastEndf = 0, lastDeff = 0; var stack = []; var callstack = []; var functionsCalled = []; @@ -3468,7 +3482,7 @@ var Font = (function FontClosure() { if (inFDEF || inELSE) { i += n; } else { - for (var j = 0; j < n; j++) { + for (j = 0; j < n; j++) { stack.push(data[i++]); } } @@ -3477,8 +3491,8 @@ var Font = (function FontClosure() { if (inFDEF || inELSE) { i += n * 2; } else { - for (var j = 0; j < n; j++) { - var b = data[i++]; + for (j = 0; j < n; j++) { + b = data[i++]; stack.push((b << 8) | data[i++]); } } @@ -3487,7 +3501,7 @@ var Font = (function FontClosure() { if (inFDEF || inELSE) { i += n; } else { - for (var j = 0; j < n; j++) { + for (j = 0; j < n; j++) { stack.push(data[i++]); } } @@ -3496,15 +3510,15 @@ var Font = (function FontClosure() { if (inFDEF || inELSE) { i += n * 2; } else { - for (var j = 0; j < n; j++) { - var b = data[i++]; + for (j = 0; j < n; j++) { + b = data[i++]; stack.push((b << 8) | data[i++]); } } } else if (op === 0x2B && !tooComplexToFollowFunctions) { // CALL if (!inFDEF && !inELSE) { // collecting inforamtion about which functions are used - var funcId = stack[stack.length - 1]; + funcId = stack[stack.length - 1]; ttContext.functionsUsed[funcId] = true; if (funcId in ttContext.functionsStackDeltas) { stack.length += ttContext.functionsStackDeltas[funcId]; @@ -3512,7 +3526,7 @@ var Font = (function FontClosure() { functionsCalled.indexOf(funcId) < 0) { callstack.push({data: data, i: i, stackTop: stack.length - 1}); functionsCalled.push(funcId); - var pc = ttContext.functionsDefined[funcId]; + pc = ttContext.functionsDefined[funcId]; if (!pc) { warn('TT: CALL non-existent function'); ttContext.hintsValid = false; @@ -3530,20 +3544,20 @@ var Font = (function FontClosure() { inFDEF = true; // collecting inforamtion about which functions are defined lastDeff = i; - var funcId = stack.pop(); + funcId = stack.pop(); ttContext.functionsDefined[funcId] = {data: data, i: i}; } else if (op === 0x2D) { // ENDF - end of function if (inFDEF) { inFDEF = false; lastEndf = i; } else { - var pc = callstack.pop(); + pc = callstack.pop(); if (!pc) { warn('TT: ENDF bad stack'); ttContext.hintsValid = false; return; } - var funcId = functionsCalled.pop(); + funcId = functionsCalled.pop(); data = pc.data; i = pc.i; ttContext.functionsStackDeltas[funcId] = @@ -3636,13 +3650,14 @@ var Font = (function FontClosure() { if (content.length > 1) { // concatenating the content items var newLength = 0; - for (var j = 0, jj = content.length; j < jj; j++) { + var j, jj; + for (j = 0, jj = content.length; j < jj; j++) { newLength += content[j].length; } newLength = (newLength + 3) & ~3; var result = new Uint8Array(newLength); var pos = 0; - for (var j = 0, jj = content.length; j < jj; j++) { + for (j = 0, jj = content.length; j < jj; j++) { result.set(content[j], pos); pos += content[j].length; } @@ -3684,11 +3699,13 @@ var Font = (function FontClosure() { var header = readOpenTypeHeader(font); var numTables = header.numTables; + var cff, cffFile; var tables = { 'OS/2': null, cmap: null, head: null, hhea: null, hmtx: null, maxp: null, name: null, post: null }; + var table, tableData; for (var i = 0; i < numTables; i++) { - var table = readTableEntry(font); + table = readTableEntry(font); if (VALID_TABLES.indexOf(table.tag) < 0) { continue; // skipping table if it's not a required or optional table } @@ -3703,8 +3720,8 @@ var Font = (function FontClosure() { // OpenType font if (!tables.head || !tables.hhea || !tables.maxp || !tables.post) { // no major tables: throwing everything at CFFFont - var cffFile = new Stream(tables['CFF '].data); - var cff = new CFFFont(cffFile, properties); + cffFile = new Stream(tables['CFF '].data); + cff = new CFFFont(cffFile, properties); return this.convert(name, cff, properties); } @@ -3812,11 +3829,11 @@ var Font = (function FontClosure() { } } - var charCodeToGlyphId = []; + var charCodeToGlyphId = [], charCode; if (properties.type == 'CIDFontType2') { var cidToGidMap = properties.cidToGidMap || []; var cMap = properties.cMap.map; - for (var charCode in cMap) { + for (charCode in cMap) { charCode |= 0; var cid = cMap[charCode]; assert(cid.length === 1, 'Max size of CID is 65,535'); @@ -3856,7 +3873,7 @@ var Font = (function FontClosure() { properties.baseEncodingName === 'WinAnsiEncoding') { baseEncoding = Encodings[properties.baseEncodingName]; } - for (var charCode = 0; charCode < 256; charCode++) { + for (charCode = 0; charCode < 256; charCode++) { var glyphName; if (this.differences && charCode in this.differences) { glyphName = this.differences[charCode]; @@ -3878,7 +3895,7 @@ var Font = (function FontClosure() { } var found = false; - for (var i = 0; i < cmapMappingsLength; ++i) { + for (i = 0; i < cmapMappingsLength; ++i) { if (cmapMappings[i].charCode === unicodeOrCharCode) { charCodeToGlyphId[charCode] = cmapMappings[i].glyphId; found = true; @@ -3888,7 +3905,7 @@ var Font = (function FontClosure() { if (!found && properties.glyphNames) { // Try to map using the post table. There are currently no known // pdfs that this fixes. - var glyphId = properties.glyphNames.indexOf(glyphName); + glyphId = properties.glyphNames.indexOf(glyphName); if (glyphId > 0) { charCodeToGlyphId[charCode] = glyphId; } @@ -3908,8 +3925,8 @@ var Font = (function FontClosure() { // associated glyph descriptions from the subtable'. This means // charcodes in the cmap will be single bytes, so no-op since // glyph.charCode & 0xFF === glyph.charCode - for (var i = 0; i < cmapMappingsLength; ++i) { - var charCode = cmapMappings[i].charCode & 0xFF; + for (i = 0; i < cmapMappingsLength; ++i) { + charCode = cmapMappings[i].charCode & 0xFF; charCodeToGlyphId[charCode] = cmapMappings[i].glyphId; } } @@ -3958,9 +3975,9 @@ var Font = (function FontClosure() { if (!isTrueType) { try { // Trying to repair CFF file - var cffFile = new Stream(tables['CFF '].data); + cffFile = new Stream(tables['CFF '].data); var parser = new CFFParser(cffFile, properties); - var cff = parser.parse(); + cff = parser.parse(); var compiler = new CFFCompiler(cff); tables['CFF '].data = compiler.compile(); } catch (e) { @@ -3981,11 +3998,11 @@ var Font = (function FontClosure() { } // rewrite the tables but tweak offsets - for (var i = 0; i < numTables; i++) { - var table = tables[tablesNames[i]]; + for (i = 0; i < numTables; i++) { + table = tables[tablesNames[i]]; var data = []; - var tableData = table.data; + tableData = table.data; for (var j = 0, jj = tableData.length; j < jj; j++) { data.push(tableData[j]); } @@ -3993,9 +4010,9 @@ var Font = (function FontClosure() { } // Add the table datas - for (var i = 0; i < numTables; i++) { - var table = tables[tablesNames[i]]; - var tableData = table.data; + for (i = 0; i < numTables; i++) { + table = tables[tablesNames[i]]; + tableData = table.data; ttf.file += bytesToString(new Uint8Array(tableData)); // 4-byte aligned data @@ -4030,15 +4047,15 @@ var Font = (function FontClosure() { var numGlyphs = font.numGlyphs; var seacs = font.seacs; + var charCode; if (SEAC_ANALYSIS_ENABLED && seacs && seacs.length) { var matrix = properties.fontMatrix || FONT_IDENTITY_MATRIX; var charset = font.getCharset(); var charCodeToGlyphId = mapping; var toFontChar = newMapping.toFontChar; - var seacs = font.seacs; var seacMap = Object.create(null); var glyphIdToCharCode = Object.create(null); - for (var charCode in charCodeToGlyphId) { + for (charCode in charCodeToGlyphId) { glyphIdToCharCode[charCodeToGlyphId[charCode]] = charCode | 0; } for (var glyphId in seacs) { @@ -4055,7 +4072,7 @@ var Font = (function FontClosure() { x: seac[0] * matrix[0] + seac[1] * matrix[2] + matrix[4], y: seac[0] * matrix[1] + seac[1] * matrix[3] + matrix[5] }; - var charCode = glyphIdToCharCode[glyphId]; + charCode = glyphIdToCharCode[glyphId]; seacMap[charCode] = { baseFontCharCode: toFontChar[glyphIdToCharCode[baseGlyphId]], accentFontCharCode: toFontChar[glyphIdToCharCode[accentGlyphId]], @@ -4151,10 +4168,11 @@ var Font = (function FontClosure() { 'post': stringToArray(createPostTable(properties)) }; - for (var field in fields) { + var field; + for (field in fields) { createTableEntry(otf, field, fields[field]); } - for (var field in fields) { + for (field in fields) { var table = fields[field]; otf.file += bytesToString(new Uint8Array(table)); } @@ -4184,15 +4202,16 @@ var Font = (function FontClosure() { // the differences array only contains adobe standard or symbol set names, // in pratice it seems better to always try to create a toUnicode // map based of the default encoding. + var toUnicode, charcode; if (!properties.composite /* is simple font */) { - var toUnicode = []; + toUnicode = []; var encoding = properties.defaultEncoding.slice(); // Merge in the differences array. var differences = properties.differences; - for (var charcode in differences) { + for (charcode in differences) { encoding[charcode] = differences[charcode]; } - for (var charcode in encoding) { + for (charcode in encoding) { // a) Map the character code to a character name. var glyphName = encoding[charcode]; // b) Look up the character name in the Adobe Glyph List (see the @@ -4234,8 +4253,8 @@ var Font = (function FontClosure() { var ucs2CMap = CMapFactory.create(ucs2CMapName, { url: PDFJS.cMapUrl, packed: PDFJS.cMapPacked }, null); var cMap = properties.cMap; - var toUnicode = []; - for (var charcode in cMap.map) { + toUnicode = []; + for (charcode in cMap.map) { var cid = cMap.map[charcode]; assert(cid.length === 1, 'Max size of CID is 65,535'); // e) Map the CID obtained in step (a) according to the CMap obtained @@ -4252,7 +4271,7 @@ var Font = (function FontClosure() { } // The viewer's choice, just use an identity map. - var toUnicode = []; + toUnicode = []; var firstChar = properties.firstChar, lastChar = properties.lastChar; for (var i = firstChar; i <= lastChar; i++) { toUnicode[i] = String.fromCharCode(i); @@ -4313,7 +4332,7 @@ var Font = (function FontClosure() { if (this.cMap && charcode in this.cMap.map) { widthCode = this.cMap.map[charcode].charCodeAt(0); } - var width = this.widths[widthCode]; + width = this.widths[widthCode]; width = isNum(width) ? width : this.defaultWidth; var vmetric = this.vmetrics && this.vmetrics[widthCode]; @@ -4359,7 +4378,7 @@ var Font = (function FontClosure() { charsToGlyphs: function Font_charsToGlyphs(chars) { var charsCache = this.charsCache; - var glyphs; + var glyphs, glyph, charcode; // if we translated this string before, just grab it from the cache if (charsCache) { @@ -4376,17 +4395,17 @@ var Font = (function FontClosure() { glyphs = []; var charsCacheKey = chars; + var i = 0, ii; if (this.cMap) { - var i = 0; // composite fonts have multi-byte strings convert the string from // single-byte to multi-byte while (i < chars.length) { var c = this.cMap.readCharCode(chars, i); - var charcode = c[0]; + charcode = c[0]; var length = c[1]; i += length; - var glyph = this.charToGlyph(charcode); + glyph = this.charToGlyph(charcode); glyphs.push(glyph); // placing null after each word break charcode (ASCII SPACE) // Ignore occurences of 0x20 in multiple-byte codes. @@ -4395,9 +4414,9 @@ var Font = (function FontClosure() { } } } else { - for (var i = 0, ii = chars.length; i < ii; ++i) { - var charcode = chars.charCodeAt(i); - var glyph = this.charToGlyph(charcode); + for (i = 0, ii = chars.length; i < ii; ++i) { + charcode = chars.charCodeAt(i); + glyph = this.charToGlyph(charcode); glyphs.push(glyph); if (charcode == 0x20) { glyphs.push(null); @@ -4441,12 +4460,14 @@ var ErrorFont = (function ErrorFontClosure() { */ function type1FontGlyphMapping(properties, builtInEncoding, glyphNames) { var charCodeToGlyphId = Object.create(null); + var glyphId, charCode, baseEncoding; + if (properties.baseEncodingName) { // If a valid base encoding name was used, the mapping is initialized with // that. - var baseEncoding = Encodings[properties.baseEncodingName]; - for (var charCode = 0; charCode < baseEncoding.length; charCode++) { - var glyphId = glyphNames.indexOf(baseEncoding[charCode]); + baseEncoding = Encodings[properties.baseEncodingName]; + for (charCode = 0; charCode < baseEncoding.length; charCode++) { + glyphId = glyphNames.indexOf(baseEncoding[charCode]); if (glyphId >= 0) { charCodeToGlyphId[charCode] = glyphId; } @@ -4454,15 +4475,15 @@ function type1FontGlyphMapping(properties, builtInEncoding, glyphNames) { } else if (!!(properties.flags & FontFlags.Symbolic)) { // For a symbolic font the encoding should be the fonts built-in // encoding. - for (var charCode in builtInEncoding) { + for (charCode in builtInEncoding) { charCodeToGlyphId[charCode] = builtInEncoding[charCode]; } } else { // For non-symbolic fonts that don't have a base encoding the standard // encoding should be used. - var baseEncoding = Encodings.StandardEncoding; - for (var charCode = 0; charCode < baseEncoding.length; charCode++) { - var glyphId = glyphNames.indexOf(baseEncoding[charCode]); + baseEncoding = Encodings.StandardEncoding; + for (charCode = 0; charCode < baseEncoding.length; charCode++) { + glyphId = glyphNames.indexOf(baseEncoding[charCode]); if (glyphId >= 0) { charCodeToGlyphId[charCode] = glyphId; } @@ -4472,9 +4493,9 @@ function type1FontGlyphMapping(properties, builtInEncoding, glyphNames) { // Lastly, merge in the differences. var differences = properties.differences; if (differences) { - for (var charCode in differences) { + for (charCode in differences) { var glyphName = differences[charCode]; - var glyphId = glyphNames.indexOf(glyphName); + glyphId = glyphNames.indexOf(glyphName); if (glyphId >= 0) { charCodeToGlyphId[charCode] = glyphId; } @@ -4552,6 +4573,7 @@ var Type1CharString = (function Type1CharStringClosure() { convert: function Type1CharString_convert(encoded, subrs) { var count = encoded.length; var error = false; + var wx, sbx, subrNumber; for (var i = 0; i < count; i++) { var value = encoded[i]; if (value < 32) { @@ -4609,7 +4631,7 @@ var Type1CharString = (function Type1CharStringClosure() { error = true; break; } - var subrNumber = this.stack.pop(); + subrNumber = this.stack.pop(); error = this.convert(subrs[subrNumber], subrs); break; case 11: // return @@ -4621,8 +4643,8 @@ var Type1CharString = (function Type1CharStringClosure() { } // To convert to type2 we have to move the width value to the // first part of the charstring and then use hmoveto with lsb. - var wx = this.stack.pop(); - var sbx = this.stack.pop(); + wx = this.stack.pop(); + sbx = this.stack.pop(); this.lsb = sbx; this.width = wx; this.stack.push(sbx); @@ -4695,9 +4717,9 @@ var Type1CharString = (function Type1CharStringClosure() { // (dx, dy). The height argument will not be used for vmtx and // vhea tables reconstruction -- ignoring it. var wy = this.stack.pop(); - var wx = this.stack.pop(); + wx = this.stack.pop(); var sby = this.stack.pop(); - var sbx = this.stack.pop(); + sbx = this.stack.pop(); this.lsb = sbx; this.width = wx; this.stack.push(sbx, sby); @@ -4717,7 +4739,7 @@ var Type1CharString = (function Type1CharStringClosure() { error = true; break; } - var subrNumber = this.stack.pop(); + subrNumber = this.stack.pop(); var numArgs = this.stack.pop(); if (subrNumber === 0 && numArgs === 3) { var flexArgs = this.stack.splice(this.stack.length - 17, 17); @@ -4939,7 +4961,7 @@ var Type1Parser = (function Type1ParserClosure() { } } }; - var token; + var token, length, data, lenIV, encoded; while ((token = this.getToken()) !== null) { if (token !== '/') { continue; @@ -4963,12 +4985,11 @@ var Type1Parser = (function Type1ParserClosure() { continue; } var glyph = this.getToken(); - var length = this.readInt(); + length = this.readInt(); this.getToken(); // read in 'RD' or '-|' - var data = stream.makeSubStream(stream.pos, length); - var lenIV = program.properties.privateData['lenIV']; - var encoded = decrypt(data.getBytes(), CHAR_STRS_ENCRYPT_KEY, - lenIV); + data = stream.makeSubStream(stream.pos, length); + lenIV = program.properties.privateData['lenIV']; + encoded = decrypt(data.getBytes(), CHAR_STRS_ENCRYPT_KEY, lenIV); // Skip past the required space and binary data. stream.skip(length); this.nextChar(); @@ -4987,12 +5008,11 @@ var Type1Parser = (function Type1ParserClosure() { this.getToken(); // read in 'array' while ((token = this.getToken()) === 'dup') { var index = this.readInt(); - var length = this.readInt(); + length = this.readInt(); this.getToken(); // read in 'RD' or '-|' - var data = stream.makeSubStream(stream.pos, length); - var lenIV = program.properties.privateData['lenIV']; - var encoded = decrypt(data.getBytes(), CHAR_STRS_ENCRYPT_KEY, - lenIV); + data = stream.makeSubStream(stream.pos, length); + lenIV = program.properties.privateData['lenIV']; + encoded = decrypt(data.getBytes(), CHAR_STRS_ENCRYPT_KEY, lenIV); // Skip past the required space and binary data. stream.skip(length); this.nextChar(); @@ -5039,8 +5059,8 @@ var Type1Parser = (function Type1ParserClosure() { } for (var i = 0; i < charstrings.length; i++) { - var glyph = charstrings[i].glyph; - var encoded = charstrings[i].encoded; + glyph = charstrings[i].glyph; + encoded = charstrings[i].encoded; var charString = new Type1CharString(); var error = charString.convert(encoded, subrs); var output = charString.output; @@ -5086,7 +5106,7 @@ var Type1Parser = (function Type1ParserClosure() { this.getToken(); // read in 'array' for (var j = 0; j < size; j++) { - var token = this.getToken(); + token = this.getToken(); // skipping till first dup or def (e.g. ignoring for statement) while (token !== 'dup' && token !== 'def') { token = this.getToken(); @@ -5254,15 +5274,15 @@ Type1Font.prototype = { getGlyphMapping: function Type1Font_getGlyphMapping(properties) { var charstrings = this.charstrings; - var glyphNames = ['.notdef']; - for (var glyphId = 0; glyphId < charstrings.length; glyphId++) { + var glyphNames = ['.notdef'], glyphId; + for (glyphId = 0; glyphId < charstrings.length; glyphId++) { glyphNames.push(charstrings[glyphId].glyphName); } var encoding = properties.builtInEncoding; if (encoding) { var builtInEncoding = {}; for (var charCode in encoding) { - var glyphId = glyphNames.indexOf(encoding[charCode]); + glyphId = glyphNames.indexOf(encoding[charCode]); if (glyphId >= 0) { builtInEncoding[charCode] = glyphId; } @@ -5307,11 +5327,12 @@ Type1Font.prototype = { // Add a bunch of empty subrs to deal with the Type2 bias var type2Subrs = []; - for (var i = 0; i < bias; i++) { + var i; + for (i = 0; i < bias; i++) { type2Subrs.push([0x0B]); } - for (var i = 0; i < count; i++) { + for (i = 0; i < count; i++) { type2Subrs.push(type1Subrs[i]); } @@ -5352,7 +5373,8 @@ Type1Font.prototype = { var count = glyphs.length; var charsetArray = [0]; - for (var i = 0; i < count; i++) { + var i, ii; + for (i = 0; i < count; i++) { var index = CFFStandardStrings.indexOf(charstrings[i].glyphName); // TODO: Insert the string and correctly map it. Previously it was // thought mapping names that aren't in the standard strings to .notdef @@ -5367,7 +5389,7 @@ Type1Font.prototype = { var charStringsIndex = new CFFIndex(); charStringsIndex.add([0x8B, 0x0E]); // .notdef - for (var i = 0; i < count; i++) { + for (i = 0; i < count; i++) { charStringsIndex.add(glyphs[i]); } cff.charStrings = charStringsIndex; @@ -5390,7 +5412,7 @@ Type1Font.prototype = { 'StdHW', 'StdVW' ]; - for (var i = 0, ii = fields.length; i < ii; i++) { + for (i = 0, ii = fields.length; i < ii; i++) { var field = fields[i]; if (!properties.privateData.hasOwnProperty(field)) { continue; @@ -5408,7 +5430,7 @@ Type1Font.prototype = { cff.topDict.privateDict = privateDict; var subrIndex = new CFFIndex(); - for (var i = 0, ii = subrs.length; i < ii; i++) { + for (i = 0, ii = subrs.length; i < ii; i++) { subrIndex.add(subrs[i]); } privateDict.subrsIndex = subrIndex; @@ -5447,12 +5469,13 @@ var CFFFont = (function CFFFontClosure() { var cff = this.cff; var charsets = cff.charset.charset; var charCodeToGlyphId = Object.create(null); + var glyphId; if (this.properties.composite) { if (this.cff.isCIDFont) { // If the font is actually a CID font then we should use the charset // to map CIDs to GIDs. - for (var glyphId = 0; glyphId < charsets.length; glyphId++) { + for (glyphId = 0; glyphId < charsets.length; glyphId++) { var cidString = String.fromCharCode(charsets[glyphId]); var charCode = this.properties.cMap.map.indexOf(cidString); charCodeToGlyphId[charCode] = glyphId; @@ -5460,7 +5483,7 @@ var CFFFont = (function CFFFontClosure() { } else { // If it is NOT actually a CID font then CIDs should be mapped // directly to GIDs. - for (var glyphId = 0; glyphId < cff.charStrings.count; glyphId++) { + for (glyphId = 0; glyphId < cff.charStrings.count; glyphId++) { charCodeToGlyphId[glyphId] = glyphId; } } @@ -5728,7 +5751,7 @@ var CFFParser = (function CFFParserClosure() { var operands = []; var entries = []; - var pos = 0; + pos = 0; var end = dict.length; while (pos < end) { var b = dict[pos]; @@ -5752,13 +5775,14 @@ var CFFParser = (function CFFParserClosure() { var offsets = []; var start = pos; var end = pos; + var i, ii; if (count !== 0) { var offsetSize = bytes[pos++]; // add 1 for offset to determine size of last object var startPos = pos + ((count + 1) * offsetSize) - 1; - for (var i = 0, ii = count + 1; i < ii; ++i) { + for (i = 0, ii = count + 1; i < ii; ++i) { var offset = 0; for (var j = 0; j < offsetSize; ++j) { offset <<= 8; @@ -5768,7 +5792,7 @@ var CFFParser = (function CFFParserClosure() { } end = offsets[count]; } - for (var i = 0, ii = offsets.length - 1; i < ii; ++i) { + for (i = 0, ii = offsets.length - 1; i < ii; ++i) { var offsetStart = offsets[i]; var offsetEnd = offsets[i + 1]; cffIndex.add(bytes.subarray(offsetStart, offsetEnd)); @@ -5984,31 +6008,32 @@ var CFFParser = (function CFFParserClosure() { var start = pos; var format = bytes[pos++]; var charset = ['.notdef']; + var id, count, i; // subtract 1 for the .notdef glyph length -= 1; switch (format) { case 0: - for (var i = 0; i < length; i++) { - var id = (bytes[pos++] << 8) | bytes[pos++]; + for (i = 0; i < length; i++) { + id = (bytes[pos++] << 8) | bytes[pos++]; charset.push(cid ? id : strings.get(id)); } break; case 1: while (charset.length <= length) { - var id = (bytes[pos++] << 8) | bytes[pos++]; - var count = bytes[pos++]; - for (var i = 0; i <= count; i++) { + id = (bytes[pos++] << 8) | bytes[pos++]; + count = bytes[pos++]; + for (i = 0; i <= count; i++) { charset.push(cid ? id++ : strings.get(id++)); } } break; case 2: while (charset.length <= length) { - var id = (bytes[pos++] << 8) | bytes[pos++]; - var count = (bytes[pos++] << 8) | bytes[pos++]; - for (var i = 0; i <= count; i++) { + id = (bytes[pos++] << 8) | bytes[pos++]; + count = (bytes[pos++] << 8) | bytes[pos++]; + for (i = 0; i <= count; i++) { charset.push(cid ? id++ : strings.get(id++)); } } @@ -6030,12 +6055,12 @@ var CFFParser = (function CFFParserClosure() { var bytes = this.bytes; var predefined = false; var hasSupplement = false; - var format; + var format, i, ii; var raw = null; function readSupplement() { var supplementsCount = bytes[pos++]; - for (var i = 0; i < supplementsCount; i++) { + for (i = 0; i < supplementsCount; i++) { var code = bytes[pos++]; var sid = (bytes[pos++] << 8) + (bytes[pos++] & 0xff); encoding[code] = charset.indexOf(strings.get(sid)); @@ -6047,7 +6072,7 @@ var CFFParser = (function CFFParserClosure() { format = pos; var baseEncoding = pos ? Encodings.ExpertEncoding : Encodings.StandardEncoding; - for (var i = 0, ii = charset.length; i < ii; i++) { + for (i = 0, ii = charset.length; i < ii; i++) { var index = baseEncoding.indexOf(charset[i]); if (index != -1) { encoding[index] = i; @@ -6055,11 +6080,11 @@ var CFFParser = (function CFFParserClosure() { } } else { var dataStart = pos; - var format = bytes[pos++]; + format = bytes[pos++]; switch (format & 0x7f) { case 0: var glyphsCount = bytes[pos++]; - for (var i = 1; i <= glyphsCount; i++) { + for (i = 1; i <= glyphsCount; i++) { encoding[bytes[pos++]] = i; } break; @@ -6067,7 +6092,7 @@ var CFFParser = (function CFFParserClosure() { case 1: var rangesCount = bytes[pos++]; var gid = 1; - for (var i = 0; i < rangesCount; i++) { + for (i = 0; i < rangesCount; i++) { var start = bytes[pos++]; var left = bytes[pos++]; for (var j = start; j <= start + left; j++) { @@ -6101,16 +6126,18 @@ var CFFParser = (function CFFParserClosure() { var bytes = this.bytes; var format = bytes[pos++]; var fdSelect = []; + var i; + switch (format) { case 0: - for (var i = 0; i < length; ++i) { + for (i = 0; i < length; ++i) { var id = bytes[pos++]; fdSelect.push(id); } break; case 3: var rangesCount = (bytes[pos++] << 8) | bytes[pos++]; - for (var i = 0; i < rangesCount; ++i) { + for (i = 0; i < rangesCount; ++i) { var first = (bytes[pos++] << 8) | bytes[pos++]; var fdIndex = bytes[pos++]; var next = (bytes[pos] << 8) | bytes[pos + 1]; @@ -6570,7 +6597,7 @@ var CFFCompiler = (function CFFCompilerClosure() { output.add(fdSelect); // It is unclear if the sub font dictionary can have CID related // dictionary keys, but the sanitizer doesn't like them so remove them. - var compiled = this.compileTopDicts(cff.fdArray, output.length, true); + compiled = this.compileTopDicts(cff.fdArray, output.length, true); topDictTracker.setEntryLocation('FDArray', [output.length], output); output.add(compiled.output); var fontDictTrackers = compiled.trackers; @@ -6604,7 +6631,8 @@ var CFFCompiler = (function CFFCompilerClosure() { } var nibbles = ''; - for (var i = 0, ii = value.length; i < ii; ++i) { + var i, ii; + for (i = 0, ii = value.length; i < ii; ++i) { var a = value[i]; if (a === 'e') { nibbles += value[++i] === '-' ? 'c' : 'b'; @@ -6618,7 +6646,7 @@ var CFFCompiler = (function CFFCompilerClosure() { } nibbles += (nibbles.length & 1) ? 'f' : 'ff'; var out = [30]; - for (var i = 0, ii = nibbles.length; i < ii; i += 2) { + for (i = 0, ii = nibbles.length; i < ii; i += 2) { out.push(parseInt(nibbles.substr(i, 2), 16)); } return out; @@ -6821,8 +6849,8 @@ var CFFCompiler = (function CFFCompilerClosure() { var data = [(count >> 8) & 0xFF, count & 0xff]; - var lastOffset = 1; - for (var i = 0; i < count; ++i) { + var lastOffset = 1, i; + for (i = 0; i < count; ++i) { lastOffset += objects[i].length; } @@ -6842,7 +6870,7 @@ var CFFCompiler = (function CFFCompilerClosure() { // Add another offset after this one because we need a new offset var relativeOffset = 1; - for (var i = 0; i < count + 1; i++) { + for (i = 0; i < count + 1; i++) { if (offsetSize === 1) { data.push(relativeOffset & 0xFF); } else if (offsetSize === 2) { @@ -6865,7 +6893,7 @@ var CFFCompiler = (function CFFCompilerClosure() { } var offset = data.length; - for (var i = 0; i < count; i++) { + for (i = 0; i < count; i++) { // Notify the tracker where the object will be offset in the data. if (trackers[i]) { trackers[i].offset(data.length); diff --git a/src/core/image.js b/src/core/image.js index edc8443dd..19d867a43 100644 --- a/src/core/image.js +++ b/src/core/image.js @@ -268,20 +268,20 @@ var PDFImage = (function PDFImageClosure() { var decodeMap = this.decode; var numComps = this.numComps; - var decodeAddends, decodeCoefficients; var decodeAddends = this.decodeAddends; var decodeCoefficients = this.decodeCoefficients; var max = (1 << bpc) - 1; + var i, ii; if (bpc === 1) { // If the buffer needed decode that means it just needs to be inverted. - for (var i = 0, ii = buffer.length; i < ii; i++) { + for (i = 0, ii = buffer.length; i < ii; i++) { buffer[i] = +!(buffer[i]); } return; } var index = 0; - for (var i = 0, ii = this.width * this.height; i < ii; i++) { + for (i = 0, ii = this.width * this.height; i < ii; i++) { for (var j = 0; j < numComps; j++) { buffer[index] = decodeAndClamp(buffer[index], decodeAddends[j], decodeCoefficients[j], max); @@ -308,10 +308,11 @@ var PDFImage = (function PDFImageClosure() { var rowComps = width * numComps; var max = (1 << bpc) - 1; + var i = 0, ii, buf; if (bpc === 1) { // Optimization for reading 1 bpc images. - var i = 0, buf, mask, loop1End, loop2End; + var mask, loop1End, loop2End; for (var j = 0; j < height; j++) { loop1End = i + (rowComps & ~7); loop2End = i + rowComps; @@ -342,8 +343,9 @@ var PDFImage = (function PDFImageClosure() { } } else { // The general case that handles all other bpc values. - var bits = 0, buf = 0; - for (var i = 0, ii = length; i < ii; ++i) { + var bits = 0; + buf = 0; + for (i = 0, ii = length; i < ii; ++i) { if (i % rowComps === 0) { buf = 0; bits = 0; @@ -367,11 +369,11 @@ var PDFImage = (function PDFImageClosure() { actualHeight, image) { var smask = this.smask; var mask = this.mask; - var alphaBuf; + var alphaBuf, sw, sh, i, ii, j; if (smask) { - var sw = smask.width; - var sh = smask.height; + sw = smask.width; + sh = smask.height; alphaBuf = new Uint8Array(sw * sh); smask.fillGrayBuffer(alphaBuf); if (sw != width || sh != height) { @@ -380,14 +382,14 @@ var PDFImage = (function PDFImageClosure() { } } else if (mask) { if (mask instanceof PDFImage) { - var sw = mask.width; - var sh = mask.height; + sw = mask.width; + sh = mask.height; alphaBuf = new Uint8Array(sw * sh); mask.numComps = 1; mask.fillGrayBuffer(alphaBuf); // Need to invert values in rgbaBuf - for (var i = 0, ii = sw * sh; i < ii; ++i) { + for (i = 0, ii = sw * sh; i < ii; ++i) { alphaBuf[i] = 255 - alphaBuf[i]; } @@ -400,10 +402,10 @@ var PDFImage = (function PDFImageClosure() { // then they should be painted. alphaBuf = new Uint8Array(width * height); var numComps = this.numComps; - for (var i = 0, ii = width * height; i < ii; ++i) { + for (i = 0, ii = width * height; i < ii; ++i) { var opacity = 0; var imageOffset = i * numComps; - for (var j = 0; j < numComps; ++j) { + for (j = 0; j < numComps; ++j) { var color = image[imageOffset + j]; var maskOffset = j * 2; if (color < mask[maskOffset] || color > mask[maskOffset + 1]) { @@ -419,12 +421,12 @@ var PDFImage = (function PDFImageClosure() { } if (alphaBuf) { - for (var i = 0, j = 3, ii = width * actualHeight; i < ii; ++i, j += 4) { + for (i = 0, j = 3, ii = width * actualHeight; i < ii; ++i, j += 4) { rgbaBuf[j] = alphaBuf[i]; } } else { // No mask. - for (var i = 0, j = 3, ii = width * actualHeight; i < ii; ++i, j += 4) { + for (i = 0, j = 3, ii = width * actualHeight; i < ii; ++i, j += 4) { rgbaBuf[j] = 255; } } @@ -560,18 +562,19 @@ var PDFImage = (function PDFImageClosure() { var imgArray = this.getImageBytes(height * rowBytes); var comps = this.getComponents(imgArray); + var i, length; if (bpc === 1) { // inline decoding (= inversion) for 1 bpc images - var length = width * height; + length = width * height; if (this.needsDecode) { // invert and scale to {0, 255} - for (var i = 0; i < length; ++i) { + for (i = 0; i < length; ++i) { buffer[i] = (comps[i] - 1) & 255; } } else { // scale to {0, 255} - for (var i = 0; i < length; ++i) { + for (i = 0; i < length; ++i) { buffer[i] = (-comps[i]) & 255; } } @@ -581,10 +584,10 @@ var PDFImage = (function PDFImageClosure() { if (this.needsDecode) { this.decodeBuffer(comps); } - var length = width * height; + length = width * height; // we aren't using a colorspace so we need to scale the value var scale = 255 / ((1 << bpc) - 1); - for (var i = 0; i < length; ++i) { + for (i = 0; i < length; ++i) { buffer[i] = (scale * comps[i]) | 0; } }, diff --git a/src/core/jbig2.js b/src/core/jbig2.js index c3102fa55..1fc244afe 100755 --- a/src/core/jbig2.js +++ b/src/core/jbig2.js @@ -237,8 +237,9 @@ var Jbig2Image = (function Jbig2ImageClosure() { var templateY = new Int8Array(templateLength); var changingTemplateEntries = []; var reuseMask = 0, minX = 0, maxX = 0, minY = 0; + var c, k; - for (var k = 0; k < templateLength; k++) { + for (k = 0; k < templateLength; k++) { templateX[k] = template[k].x; templateY[k] = template[k].y; minX = Math.min(minX, template[k].x); @@ -260,7 +261,7 @@ var Jbig2Image = (function Jbig2ImageClosure() { var changingTemplateX = new Int8Array(changingEntriesLength); var changingTemplateY = new Int8Array(changingEntriesLength); var changingTemplateBit = new Uint16Array(changingEntriesLength); - for (var c = 0; c < changingEntriesLength; c++) { + for (c = 0; c < changingEntriesLength; c++) { k = changingTemplateEntries[c]; changingTemplateX[c] = template[k].x; changingTemplateY[c] = template[k].y; @@ -279,7 +280,7 @@ var Jbig2Image = (function Jbig2ImageClosure() { var decoder = decodingContext.decoder; var contexts = decodingContext.contextCache.getContexts('GB'); - var ltp = 0, c, j, i0, j0, k, contextLabel = 0, bit, shift; + var ltp = 0, j, i0, j0, contextLabel = 0, bit, shift; for (var i = 0; i < height; i++) { if (prediction) { var sltp = decoder.readBit(contexts, pseudoPixelContext); @@ -346,7 +347,8 @@ var Jbig2Image = (function Jbig2ImageClosure() { var codingTemplateLength = codingTemplate.length; var codingTemplateX = new Int32Array(codingTemplateLength); var codingTemplateY = new Int32Array(codingTemplateLength); - for (var k = 0; k < codingTemplateLength; k++) { + var k; + for (k = 0; k < codingTemplateLength; k++) { codingTemplateX[k] = codingTemplate[k].x; codingTemplateY[k] = codingTemplate[k].y; } @@ -358,7 +360,7 @@ var Jbig2Image = (function Jbig2ImageClosure() { var referenceTemplateLength = referenceTemplate.length; var referenceTemplateX = new Int32Array(referenceTemplateLength); var referenceTemplateY = new Int32Array(referenceTemplateLength); - for (var k = 0; k < referenceTemplateLength; k++) { + for (k = 0; k < referenceTemplateLength; k++) { referenceTemplateX[k] = referenceTemplate[k].x; referenceTemplateY[k] = referenceTemplate[k].y; } @@ -383,19 +385,20 @@ var Jbig2Image = (function Jbig2ImageClosure() { var row = new Uint8Array(width); bitmap.push(row); for (var j = 0; j < width; j++) { - + var i0, j0; var contextLabel = 0; - for (var k = 0; k < codingTemplateLength; k++) { - var i0 = i + codingTemplateY[k], j0 = j + codingTemplateX[k]; + for (k = 0; k < codingTemplateLength; k++) { + i0 = i + codingTemplateY[k]; + j0 = j + codingTemplateX[k]; if (i0 < 0 || j0 < 0 || j0 >= width) { contextLabel <<= 1; // out of bound pixel } else { contextLabel = (contextLabel << 1) | bitmap[i0][j0]; } } - for (var k = 0; k < referenceTemplateLength; k++) { - var i0 = i + referenceTemplateY[k] + offsetY; - var j0 = j + referenceTemplateX[k] + offsetX; + for (k = 0; k < referenceTemplateLength; k++) { + i0 = i + referenceTemplateY[k] + offsetY; + j0 = j + referenceTemplateX[k] + offsetX; if (i0 < 0 || i0 >= referenceHeight || j0 < 0 || j0 >= referenceWidth) { contextLabel <<= 1; // out of bound pixel @@ -512,8 +515,9 @@ var Jbig2Image = (function Jbig2ImageClosure() { // Prepare bitmap var bitmap = []; - for (var i = 0; i < height; i++) { - var row = new Uint8Array(width); + var i, row; + for (i = 0; i < height; i++) { + row = new Uint8Array(width); if (defaultPixelValue) { for (var j = 0; j < width; j++) { row[j] = defaultPixelValue; @@ -526,7 +530,7 @@ var Jbig2Image = (function Jbig2ImageClosure() { var contextCache = decodingContext.contextCache; var stripT = -decodeInteger(contextCache, 'IADT', decoder); // 6.4.6 var firstS = 0; - var i = 0; + i = 0; while (i < numberOfSymbolInstances) { var deltaT = decodeInteger(contextCache, 'IADT', decoder); // 6.4.6 stripT += deltaT; @@ -535,12 +539,12 @@ var Jbig2Image = (function Jbig2ImageClosure() { firstS += deltaFirstS; var currentS = firstS; do { - var currentT = stripSize == 1 ? 0 : - decodeInteger(contextCache, 'IAIT', decoder); // 6.4.9 + var currentT = (stripSize == 1 ? 0 : + decodeInteger(contextCache, 'IAIT', decoder)); // 6.4.9 var t = stripSize * stripT + currentT; var symbolId = decodeIAID(contextCache, decoder, symbolCodeLength); - var applyRefinement = refinement && - decodeInteger(contextCache, 'IARI', decoder); + var applyRefinement = (refinement && + decodeInteger(contextCache, 'IARI', decoder)); var symbolBitmap = inputSymbols[symbolId]; var symbolWidth = symbolBitmap[0].length; var symbolHeight = symbolBitmap.length; @@ -558,25 +562,26 @@ var Jbig2Image = (function Jbig2ImageClosure() { } var offsetT = t - ((referenceCorner & 1) ? 0 : symbolHeight); var offsetS = currentS - ((referenceCorner & 2) ? symbolWidth : 0); + var s2, t2, symbolRow; if (transposed) { // Place Symbol Bitmap from T1,S1 - for (var s2 = 0; s2 < symbolHeight; s2++) { - var row = bitmap[offsetS + s2]; + for (s2 = 0; s2 < symbolHeight; s2++) { + row = bitmap[offsetS + s2]; if (!row) { continue; } - var symbolRow = symbolBitmap[s2]; + symbolRow = symbolBitmap[s2]; // To ignore Parts of Symbol bitmap which goes // outside bitmap region var maxWidth = Math.min(width - offsetT, symbolWidth); switch (combinationOperator) { case 0: // OR - for (var t2 = 0; t2 < maxWidth; t2++) { + for (t2 = 0; t2 < maxWidth; t2++) { row[offsetT + t2] |= symbolRow[t2]; } break; case 2: // XOR - for (var t2 = 0; t2 < maxWidth; t2++) { + for (t2 = 0; t2 < maxWidth; t2++) { row[offsetT + t2] ^= symbolRow[t2]; } break; @@ -587,20 +592,20 @@ var Jbig2Image = (function Jbig2ImageClosure() { } currentS += symbolHeight - 1; } else { - for (var t2 = 0; t2 < symbolHeight; t2++) { - var row = bitmap[offsetT + t2]; + for (t2 = 0; t2 < symbolHeight; t2++) { + row = bitmap[offsetT + t2]; if (!row) { continue; } - var symbolRow = symbolBitmap[t2]; + symbolRow = symbolBitmap[t2]; switch (combinationOperator) { case 0: // OR - for (var s2 = 0; s2 < symbolWidth; s2++) { + for (s2 = 0; s2 < symbolWidth; s2++) { row[offsetS + s2] |= symbolRow[s2]; } break; case 2: // XOR - for (var s2 = 0; s2 < symbolWidth; s2++) { + for (s2 = 0; s2 < symbolWidth; s2++) { row[offsetS + s2] ^= symbolRow[s2]; } break; @@ -655,7 +660,8 @@ var Jbig2Image = (function Jbig2ImageClosure() { var referredToSegmentNumberSize = (segmentHeader.number <= 256 ? 1 : (segmentHeader.number <= 65536 ? 2 : 4)); var referredTo = []; - for (var i = 0; i < referredToCount; i++) { + var i, ii; + for (i = 0; i < referredToCount; i++) { var number = (referredToSegmentNumberSize == 1 ? data[position] : (referredToSegmentNumberSize == 2 ? readUint16(data, position) : readUint32(data, position))); @@ -690,7 +696,7 @@ var Jbig2Image = (function Jbig2ImageClosure() { searchPattern[3] = (genericRegionInfo.height >> 16) & 0xFF; searchPattern[4] = (genericRegionInfo.height >> 8) & 0xFF; searchPattern[5] = genericRegionInfo.height & 0xFF; - for (var i = position, ii = data.length; i < ii; i++) { + for (i = position, ii = data.length; i < ii; i++) { var j = 0; while (j < searchPatternLength && searchPattern[j] === data[i + j]) { j++; @@ -757,7 +763,7 @@ var Jbig2Image = (function Jbig2ImageClosure() { var header = segment.header; var data = segment.data, position = segment.start, end = segment.end; - var args; + var args, at, i, atLength; switch (header.type) { case 0: // SymbolDictionary // 7.4.2 Symbol dictionary segment syntax @@ -775,9 +781,9 @@ var Jbig2Image = (function Jbig2ImageClosure() { dictionary.refinementTemplate = (dictionaryFlags >> 12) & 1; position += 2; if (!dictionary.huffman) { - var atLength = dictionary.template === 0 ? 4 : 1; - var at = []; - for (var i = 0; i < atLength; i++) { + atLength = dictionary.template === 0 ? 4 : 1; + at = []; + for (i = 0; i < atLength; i++) { at.push({ x: readInt8(data, position), y: readInt8(data, position + 1) @@ -787,8 +793,8 @@ var Jbig2Image = (function Jbig2ImageClosure() { dictionary.at = at; } if (dictionary.refinement && !dictionary.refinementTemplate) { - var at = []; - for (var i = 0; i < 2; i++) { + at = []; + for (i = 0; i < 2; i++) { at.push({ x: readInt8(data, position), y: readInt8(data, position + 1) @@ -834,8 +840,8 @@ var Jbig2Image = (function Jbig2ImageClosure() { !!(textRegionHuffmanFlags & 14); } if (textRegion.refinement && !textRegion.refinementTemplate) { - var at = []; - for (var i = 0; i < 2; i++) { + at = []; + for (i = 0; i < 2; i++) { at.push({ x: readInt8(data, position), y: readInt8(data, position + 1) @@ -862,9 +868,9 @@ var Jbig2Image = (function Jbig2ImageClosure() { genericRegion.template = (genericRegionSegmentFlags >> 1) & 3; genericRegion.prediction = !!(genericRegionSegmentFlags & 8); if (!genericRegion.mmr) { - var atLength = genericRegion.template === 0 ? 4 : 1; - var at = []; - for (var i = 0; i < atLength; i++) { + atLength = genericRegion.template === 0 ? 4 : 1; + at = []; + for (i = 0; i < atLength; i++) { at.push({ x: readInt8(data, position), y: readInt8(data, position + 1) @@ -976,12 +982,13 @@ var Jbig2Image = (function Jbig2ImageClosure() { var buffer = this.buffer; var mask0 = 128 >> (regionInfo.x & 7); var offset0 = regionInfo.y * rowSize + (regionInfo.x >> 3); + var i, j, mask, offset; switch (combinationOperator) { case 0: // OR - for (var i = 0; i < height; i++) { - var mask = mask0; - var offset = offset0; - for (var j = 0; j < width; j++) { + for (i = 0; i < height; i++) { + mask = mask0; + offset = offset0; + for (j = 0; j < width; j++) { if (bitmap[i][j]) { buffer[offset] |= mask; } @@ -995,10 +1002,10 @@ var Jbig2Image = (function Jbig2ImageClosure() { } break; case 2: // XOR - for (var i = 0; i < height; i++) { - var mask = mask0; - var offset = offset0; - for (var j = 0; j < width; j++) { + for (i = 0; i < height; i++) { + mask = mask0; + offset = offset0; + for (j = 0; j < width; j++) { if (bitmap[i][j]) { buffer[offset] ^= mask; } diff --git a/src/core/jpx.js b/src/core/jpx.js index f051784d0..392f9a659 100644 --- a/src/core/jpx.js +++ b/src/core/jpx.js @@ -139,7 +139,7 @@ var JpxImage = (function JpxImageClosure() { var code = readUint16(data, position); position += 2; - var length = 0, j; + var length = 0, j, sqcd, spqcds, spqcdSize, scalarExpounded, tile; switch (code) { case 0xFF4F: // Start of codestream (SOC) context.mainHeader = true; @@ -181,8 +181,7 @@ var JpxImage = (function JpxImageClosure() { length = readUint16(data, position); var qcd = {}; j = position + 2; - var sqcd = data[j++]; - var spqcdSize, scalarExpounded; + sqcd = data[j++]; switch (sqcd & 0x1F) { case 0: spqcdSize = 8; @@ -202,7 +201,7 @@ var JpxImage = (function JpxImageClosure() { qcd.noQuantization = (spqcdSize == 8); qcd.scalarExpounded = scalarExpounded; qcd.guardBits = sqcd >> 5; - var spqcds = []; + spqcds = []; while (j < length + position) { var spqcd = {}; if (spqcdSize == 8) { @@ -234,8 +233,7 @@ var JpxImage = (function JpxImageClosure() { cqcc = readUint16(data, j); j += 2; } - var sqcd = data[j++]; - var spqcdSize, scalarExpounded; + sqcd = data[j++]; switch (sqcd & 0x1F) { case 0: spqcdSize = 8; @@ -255,9 +253,9 @@ var JpxImage = (function JpxImageClosure() { qcc.noQuantization = (spqcdSize == 8); qcc.scalarExpounded = scalarExpounded; qcc.guardBits = sqcd >> 5; - var spqcds = []; + spqcds = []; while (j < (length + position)) { - var spqcd = {}; + spqcd = {}; if (spqcdSize == 8) { spqcd.epsilon = data[j++] >> 3; spqcd.mu = 0; @@ -330,7 +328,7 @@ var JpxImage = (function JpxImageClosure() { break; case 0xFF90: // Start of tile-part (SOT) length = readUint16(data, position); - var tile = {}; + tile = {}; tile.index = readUint16(data, position + 2); tile.length = readUint32(data, position + 4); tile.dataEnd = tile.length + position - 2; @@ -348,7 +346,7 @@ var JpxImage = (function JpxImageClosure() { context.currentTile = tile; break; case 0xFF93: // Start of data (SOD) - var tile = context.currentTile; + tile = context.currentTile; if (tile.partIndex === 0) { initializeTile(context, tile.index); buildPackets(context); @@ -409,12 +407,12 @@ var JpxImage = (function JpxImageClosure() { function calculateTileGrids(context, components) { var siz = context.SIZ; // Section B.3 Division into tile and tile-components - var tiles = []; + var tile, tiles = []; var numXtiles = Math.ceil((siz.Xsiz - siz.XTOsiz) / siz.XTsiz); var numYtiles = Math.ceil((siz.Ysiz - siz.YTOsiz) / siz.YTsiz); for (var q = 0; q < numYtiles; q++) { for (var p = 0; p < numXtiles; p++) { - var tile = {}; + tile = {}; tile.tx0 = Math.max(siz.XTOsiz + p * siz.XTsiz, siz.XOsiz); tile.ty0 = Math.max(siz.YTOsiz + q * siz.YTsiz, siz.YOsiz); tile.tx1 = Math.min(siz.XTOsiz + (p + 1) * siz.XTsiz, siz.Xsiz); @@ -432,7 +430,8 @@ var JpxImage = (function JpxImageClosure() { var component = components[i]; var tileComponents = []; for (var j = 0, jj = tiles.length; j < jj; j++) { - var tileComponent = {}, tile = tiles[j]; + var tileComponent = {}; + tile = tiles[j]; tileComponent.tcx0 = Math.ceil(tile.tx0 / component.XRsiz); tileComponent.tcy0 = Math.ceil(tile.ty0 / component.YRsiz); tileComponent.tcx1 = Math.ceil(tile.tx1 / component.XRsiz); @@ -498,9 +497,10 @@ var JpxImage = (function JpxImageClosure() { var precinctParameters = subband.resolution.precinctParameters; var codeblocks = []; var precincts = []; - for (var j = cby0; j < cby1; j++) { - for (var i = cbx0; i < cbx1; i++) { - var codeblock = { + var i, ii, j, codeblock, precinctNumber; + for (j = cby0; j < cby1; j++) { + for (i = cbx0; i < cbx1; i++) { + codeblock = { cbx: i, cby: j, tbx0: codeblockWidth * i, @@ -515,8 +515,7 @@ var JpxImage = (function JpxImageClosure() { var pj = Math.floor((codeblock.tby0 - precinctParameters.precinctYOffset) / precinctParameters.precinctHeight); - var precinctNumber = pj + - pi * precinctParameters.numprecinctswide; + precinctNumber = pj + pi * precinctParameters.numprecinctswide; codeblock.tbx0_ = Math.max(subband.tbx0, codeblock.tbx0); codeblock.tby0_ = Math.max(subband.tby0, codeblock.tby0); codeblock.tbx1_ = Math.min(subband.tbx1, codeblock.tbx1); @@ -816,19 +815,20 @@ var JpxImage = (function JpxImageClosure() { continue; } var layerNumber = packet.layerNumber; - var queue = []; + var queue = [], codeblock; for (var i = 0, ii = packet.codeblocks.length; i < ii; i++) { - var codeblock = packet.codeblocks[i]; + codeblock = packet.codeblocks[i]; var precinct = codeblock.precinct; var codeblockColumn = codeblock.cbx - precinct.cbxMin; var codeblockRow = codeblock.cby - precinct.cbyMin; var codeblockIncluded = false; var firstTimeInclusion = false; + var valueReady; if ('included' in codeblock) { codeblockIncluded = !!readBits(1); } else { // reading inclusion tree - var precinct = codeblock.precinct; + precinct = codeblock.precinct; var inclusionTree, zeroBitPlanesTree; if ('inclusionTree' in precinct) { inclusionTree = precinct.inclusionTree; @@ -845,7 +845,7 @@ var JpxImage = (function JpxImageClosure() { if (inclusionTree.reset(codeblockColumn, codeblockRow, layerNumber)) { while (true) { if (readBits(1)) { - var valueReady = !inclusionTree.nextLevel(); + valueReady = !inclusionTree.nextLevel(); if (valueReady) { codeblock.included = true; codeblockIncluded = firstTimeInclusion = true; @@ -866,7 +866,7 @@ var JpxImage = (function JpxImageClosure() { zeroBitPlanesTree.reset(codeblockColumn, codeblockRow); while (true) { if (readBits(1)) { - var valueReady = !zeroBitPlanesTree.nextLevel(); + valueReady = !zeroBitPlanesTree.nextLevel(); if (valueReady) { break; } @@ -894,7 +894,7 @@ var JpxImage = (function JpxImageClosure() { alignToByte(); while (queue.length > 0) { var packetItem = queue.shift(); - var codeblock = packetItem.codeblock; + codeblock = packetItem.codeblock; if (!('data' in codeblock)) { codeblock.data = []; } @@ -930,14 +930,15 @@ var JpxImage = (function JpxImageClosure() { // collect data var data = codeblock.data, totalLength = 0, codingpasses = 0; - for (var q = 0, qq = data.length; q < qq; q++) { - var dataItem = data[q]; + var q, qq, dataItem; + for (q = 0, qq = data.length; q < qq; q++) { + dataItem = data[q]; totalLength += dataItem.end - dataItem.start; codingpasses += dataItem.codingpasses; } var encodedData = new Uint8Array(totalLength), k = 0; - for (var q = 0, qq = data.length; q < qq; q++) { - var dataItem = data[q]; + for (q = 0, qq = data.length; q < qq; q++) { + dataItem = data[q]; var chunk = dataItem.data.subarray(dataItem.start, dataItem.end); encodedData.set(chunk, k); k += chunk.length; @@ -946,7 +947,7 @@ var JpxImage = (function JpxImageClosure() { var decoder = new ArithmeticDecoder(encodedData, 0, totalLength); bitModel.setDecoder(decoder); - for (var q = 0; q < codingpasses; q++) { + for (q = 0; q < codingpasses; q++) { switch (currentCodingpassType) { case 0: bitModel.runSignificancePropogationPass(); @@ -972,7 +973,7 @@ var JpxImage = (function JpxImageClosure() { var bitsDecoded = bitModel.bitsDecoded; var magnitudeCorrection = reversible ? 0 : 0.5; for (var j = 0; j < blockHeight; j++) { - for (var k = 0; k < blockWidth; k++) { + for (k = 0; k < blockWidth; k++) { n = magnitude[position]; if (n !== 0) { n = (n + magnitudeCorrection) * delta; @@ -1068,32 +1069,35 @@ var JpxImage = (function JpxImageClosure() { for (var i = 0, ii = context.tiles.length; i < ii; i++) { var tile = context.tiles[i]; var result = []; - for (var c = 0; c < componentsCount; c++) { + var c; + for (c = 0; c < componentsCount; c++) { var image = transformTile(context, tile, c); result.push(image); } // Section G.2.2 Inverse multi component transform + var y0items, y1items, y2items, j, jj, y0, y1, y2; + var component, offset, tileImage, items; if (tile.codingStyleDefaultParameters.multipleComponentTransform) { var component0 = tile.components[0]; if (!component0.codingStyleParameters.reversibleTransformation) { // inverse irreversible multiple component transform - var y0items = result[0].items; - var y1items = result[1].items; - var y2items = result[2].items; - for (var j = 0, jj = y0items.length; j < jj; ++j) { - var y0 = y0items[j] + 0.5, y1 = y1items[j], y2 = y2items[j]; + y0items = result[0].items; + y1items = result[1].items; + y2items = result[2].items; + for (j = 0, jj = y0items.length; j < jj; ++j) { + y0 = y0items[j] + 0.5; y1 = y1items[j]; y2 = y2items[j]; y0items[j] = y0 + 1.402 * y2; y1items[j] = y0 - 0.34413 * y1 - 0.71414 * y2; y2items[j] = y0 + 1.772 * y1; } } else { // inverse reversible multiple component transform - var y0items = result[0].items; - var y1items = result[1].items; - var y2items = result[2].items; - for (var j = 0, jj = y0items.length; j < jj; ++j) { - var y0 = y0items[j], y1 = y1items[j], y2 = y2items[j]; + y0items = result[0].items; + y1items = result[1].items; + y2items = result[2].items; + for (j = 0, jj = y0items.length; j < jj; ++j) { + y0 = y0items[j]; y1 = y1items[j]; y2 = y2items[j]; var i1 = y0 - ((y2 + y1) >> 2); y1items[j] = i1; y0items[j] = y2 + i1; @@ -1103,15 +1107,15 @@ var JpxImage = (function JpxImageClosure() { } // To simplify things: shift and clamp output to 8 bit unsigned - for (var c = 0; c < componentsCount; c++) { - var component = components[c]; + for (c = 0; c < componentsCount; c++) { + component = components[c]; var shift = component.precision - 8; - var tileImage = result[c]; - var items = tileImage.items; + tileImage = result[c]; + items = tileImage.items; var data = new Uint8Array(items.length); var low = -(128 << shift); var high = 127 << shift; - for (var j = 0, jj = items.length; j < jj; j++) { + for (j = 0, jj = items.length; j < jj; j++) { var val = items[j]; data[j] = val <= low ? 0 : val >= high ? 255 : (val >> shift) + 128; } @@ -1157,9 +1161,9 @@ var JpxImage = (function JpxImageClosure() { } TagTree.prototype = { reset: function TagTree_reset(i, j) { - var currentLevel = 0, value = 0; + var currentLevel = 0, value = 0, level; while (currentLevel < this.levels.length) { - var level = this.levels[currentLevel]; + level = this.levels[currentLevel]; var index = i + j * level.width; if (index in level.items) { value = level.items[index]; @@ -1171,7 +1175,7 @@ var JpxImage = (function JpxImageClosure() { currentLevel++; } currentLevel--; - var level = this.levels[currentLevel]; + level = this.levels[currentLevel]; level.items[level.index] = value; this.currentLevel = currentLevel; delete this.value; @@ -1191,7 +1195,7 @@ var JpxImage = (function JpxImageClosure() { } this.currentLevel = currentLevel; - var level = this.levels[currentLevel]; + level = this.levels[currentLevel]; level.items[level.index] = value; return true; } @@ -1257,7 +1261,7 @@ var JpxImage = (function JpxImageClosure() { var level = this.levels[levelIndex]; var currentValue = level.items[level.index]; while (--levelIndex >= 0) { - var level = this.levels[levelIndex]; + level = this.levels[levelIndex]; level.items[level.index] = currentValue; } }, @@ -1272,7 +1276,7 @@ var JpxImage = (function JpxImageClosure() { } this.currentLevel = currentLevel; - var level = this.levels[currentLevel]; + level = this.levels[currentLevel]; level.items[level.index] = value; return true; } @@ -1351,9 +1355,10 @@ var JpxImage = (function JpxImageClosure() { var width = this.width, height = this.height; var left = (column > 0); var right = (column + 1 < width); + var i; if (row > 0) { - var i = index - width; + i = index - width; if (left) { neighborsSignificance[i - 1] += 0x10; } @@ -1364,7 +1369,7 @@ var JpxImage = (function JpxImageClosure() { } if (row + 1 < height) { - var i = index + width; + i = index + width; if (left) { neighborsSignificance[i - 1] += 0x10; } @@ -1434,6 +1439,7 @@ var JpxImage = (function JpxImageClosure() { var coefficentsMagnitude = this.coefficentsMagnitude; var coefficentsSign = this.coefficentsSign; var contribution, sign0, sign1, significance1; + var contextLabel, decoded; // calculate horizontal contribution significance1 = (column > 0 && coefficentsMagnitude[index - 1] !== 0); @@ -1471,11 +1477,11 @@ var JpxImage = (function JpxImageClosure() { } if (contribution >= 0) { - var contextLabel = 9 + contribution; - var decoded = this.decoder.readBit(this.contexts, contextLabel); + contextLabel = 9 + contribution; + decoded = this.decoder.readBit(this.contexts, contextLabel); } else { - var contextLabel = 9 - contribution; - var decoded = this.decoder.readBit(this.contexts, contextLabel) ^ 1; + contextLabel = 9 - contribution; + decoded = this.decoder.readBit(this.contexts, contextLabel) ^ 1; } return decoded; }, @@ -1552,7 +1558,7 @@ var JpxImage = (function JpxImageClosure() { neighborsSignificance[index0 + twoRowsDown] === 0 && neighborsSignificance[index0 + threeRowsDown] === 0); var i1 = 0, index = index0; - var i; + var i, sign; if (allEmpty) { var hasSignificantCoefficent = decoder.readBit(contexts, RUNLENGTH_CONTEXT); @@ -1568,7 +1574,7 @@ var JpxImage = (function JpxImageClosure() { i = i0 + i1; index += i1 * width; - var sign = this.decodeSignBit(i, j, index); + sign = this.decodeSignBit(i, j, index); coefficentsSign[index] = sign; coefficentsMagnitude[index] = 1; this.setNeighborsSignificance(i, j, index); @@ -1595,7 +1601,7 @@ var JpxImage = (function JpxImageClosure() { var contextLabel = labels[neighborsSignificance[index]]; var decision = decoder.readBit(contexts, contextLabel); if (decision == 1) { - var sign = this.decodeSignBit(i, j, index); + sign = this.decodeSignBit(i, j, index); coefficentsSign[index] = sign; coefficentsMagnitude[index] = 1; this.setNeighborsSignificance(i, j, index); @@ -1659,11 +1665,11 @@ var JpxImage = (function JpxImageClosure() { var width = llWidth + hlWidth; var height = llHeight + lhHeight; var items = new Float32Array(width * height); - var i, j, k, l; + var i, j, k, l, v, u; for (i = 0, k = 0; i < llHeight; i++) { l = i * 2 * width; - for (var j = 0; j < llWidth; j++, k++, l += 2) { + for (j = 0; j < llWidth; j++, k++, l += 2) { items[l] = llItems[k]; } } @@ -1693,12 +1699,12 @@ var JpxImage = (function JpxImageClosure() { if (width === 1) { // if width = 1, when u0 even keep items as is, when odd divide by 2 if ((u0 & 1) !== 0) { - for (var v = 0, k = 0; v < height; v++, k += width) { + for (v = 0, k = 0; v < height; v++, k += width) { items[k] *= 0.5; } } } else { - for (var v = 0, k = 0; v < height; v++, k += width) { + for (v = 0, k = 0; v < height; v++, k += width) { rowBuffer.set(items.subarray(k, k + width), bufferPadding); this.extend(rowBuffer, bufferPadding, width); @@ -1721,18 +1727,19 @@ var JpxImage = (function JpxImageClosure() { for (i = 0; i < numBuffers; i++) { colBuffers.push(new Float32Array(height + 2 * bufferPadding)); } - var b, currentBuffer = 0, ll = bufferPadding + height; + var b, currentBuffer = 0; + ll = bufferPadding + height; // Section F.3.5 VER_SR if (height === 1) { // if height = 1, when v0 even keep items as is, when odd divide by 2 if ((v0 & 1) !== 0) { - for (var u = 0; u < width; u++) { + for (u = 0; u < width; u++) { items[u] *= 0.5; } } } else { - for (var u = 0; u < width; u++) { + for (u = 0; u < width; u++) { // if we ran out of buffers, copy several image columns at once if (currentBuffer === 0) { numBuffers = Math.min(width - u, numBuffers); @@ -1780,7 +1787,7 @@ var JpxImage = (function JpxImageClosure() { IrreversibleTransform.prototype.filter = function irreversibleTransformFilter(y, offset, length, i0, x) { var len = length >> 1; - var offset = offset | 0; + offset = offset | 0; var alpha = -1.586134342059924; var beta = -0.052980118572961; @@ -1788,32 +1795,33 @@ var JpxImage = (function JpxImageClosure() { var delta = 0.443506852043971; var K = 1.230174104914001; var K_ = 1 / K; + var j, n, nn; // step 1 is combined with step 3 // step 2 - for (var j = offset - 3, n = len + 4; n--; j += 2) { + for (j = offset - 3, n = len + 4; n--; j += 2) { x[j] = K_ * y[j]; } // step 1 & 3 - for (var j = offset - 2, n = len + 3; n--; j += 2) { + for (j = offset - 2, n = len + 3; n--; j += 2) { x[j] = K * y[j] - delta * (x[j - 1] + x[j + 1]); } // step 4 - for (var j = offset - 1, n = len + 2; n--; j += 2) { + for (j = offset - 1, n = len + 2; n--; j += 2) { x[j] -= gamma * (x[j - 1] + x[j + 1]); } // step 5 - for (var j = offset, n = len + 1; n--; j += 2) { + for (j = offset, n = len + 1; n--; j += 2) { x[j] -= beta * (x[j - 1] + x[j + 1]); } // step 6 - for (var j = offset + 1, n = len; n--; j += 2) { + for (j = offset + 1, n = len; n--; j += 2) { x[j] -= alpha * (x[j - 1] + x[j + 1]); } }; @@ -1831,13 +1839,14 @@ var JpxImage = (function JpxImageClosure() { ReversibleTransform.prototype.filter = function reversibleTransformFilter(y, offset, length, i0, x) { var len = length >> 1; - var offset = offset | 0; + offset = offset | 0; + var j, n; - for (var j = offset, n = len + 1; n--; j += 2) { + for (j = offset, n = len + 1; n--; j += 2) { x[j] = y[j] - ((y[j - 1] + y[j + 1] + 2) >> 2); } - for (var j = offset + 1, n = len; n--; j += 2) { + for (j = offset + 1, n = len; n--; j += 2) { x[j] = y[j] + ((x[j - 1] + x[j + 1]) >> 1); } }; diff --git a/src/core/murmurhash3.js b/src/core/murmurhash3.js index 929dd3ab7..aa7421fc2 100644 --- a/src/core/murmurhash3.js +++ b/src/core/murmurhash3.js @@ -37,10 +37,11 @@ var MurmurHash3_64 = (function MurmurHash3_64Closure (seed) { MurmurHash3_64.prototype = { update: function MurmurHash3_64_update(input) { var useUint32ArrayView = false; + var i; if (typeof input == 'string') { var data = new Uint8Array(input.length * 2); var length = 0; - for (var i = 0; i < input.length; i++) { + for (i = 0; i < input.length; i++) { var code = input.charCodeAt(i); if (code <= 0xff) { data[length++] = code; @@ -78,7 +79,7 @@ var MurmurHash3_64 = (function MurmurHash3_64Closure (seed) { var C1_LOW = C1 & MASK_LOW; var C2_LOW = C2 & MASK_LOW; - for (var i = 0; i < blockCounts; i++) { + for (i = 0; i < blockCounts; i++) { if (i & 1) { k1 = dataUint32[i]; k1 = (k1 * C1 & MASK_HIGH) | (k1 * C1_LOW & MASK_LOW); diff --git a/src/core/obj.js b/src/core/obj.js index 59c8dbf46..bf88bf252 100644 --- a/src/core/obj.js +++ b/src/core/obj.js @@ -151,8 +151,9 @@ var Dict = (function DictClosure() { getAll: function Dict_getAll() { var all = Object.create(null); var queue = null; - for (var key in this.map) { - var obj = this.get(key); + var key, obj; + for (key in this.map) { + obj = this.get(key); if (obj instanceof Dict) { if (isRecursionAllowedFor(obj)) { (queue || (queue = [])).push({target: all, key: key, obj: obj}); @@ -178,8 +179,8 @@ var Dict = (function DictClosure() { continue; } var dereferenced = Object.create(null); - for (var key in itemObj.map) { - var obj = itemObj.get(key); + for (key in itemObj.map) { + obj = itemObj.get(key); if (obj instanceof Dict) { if (isRecursionAllowedFor(obj)) { queue.push({target: dereferenced, key: key, obj: obj}); @@ -988,13 +989,14 @@ var XRef = (function XRefClosure() { } } // reading XRef streams - for (var i = 0, ii = xrefStms.length; i < ii; ++i) { + var i, ii; + for (i = 0, ii = xrefStms.length; i < ii; ++i) { this.startXRefQueue.push(xrefStms[i]); this.readXRef(/* recoveryMode */ true); } // finding main trailer var dict; - for (var i = 0, ii = trailers.length; i < ii; ++i) { + for (i = 0, ii = trailers.length; i < ii; ++i) { stream.pos = trailers[i]; var parser = new Parser(new Lexer(stream), true, null); var obj = parser.getObj(); @@ -1332,6 +1334,7 @@ var ObjectLoader = (function() { } function addChildren(node, nodesToVisit) { + var value; if (isDict(node) || isStream(node)) { var map; if (isDict(node)) { @@ -1340,14 +1343,14 @@ var ObjectLoader = (function() { map = node.dict.map; } for (var key in map) { - var value = map[key]; + value = map[key]; if (mayHaveChildren(value)) { nodesToVisit.push(value); } } } else if (isArray(node)) { for (var i = 0, ii = node.length; i < ii; i++) { - var value = node[i]; + value = node[i]; if (mayHaveChildren(value)) { nodesToVisit.push(value); } diff --git a/src/core/parser.js b/src/core/parser.js index acdb46bfc..fb5e20f05 100644 --- a/src/core/parser.js +++ b/src/core/parser.js @@ -192,7 +192,7 @@ var Parser = (function ParserClosure() { var a = 1; var b = 0; - for (var i = 0, ii = imageBytes.length; i < ii; ++i) { + for (i = 0, ii = imageBytes.length; i < ii; ++i) { a = (a + (imageBytes[i] & 0xff)) % 65521; b = (b + a) % 65521; } @@ -261,11 +261,11 @@ var Parser = (function ParserClosure() { var ENDSTREAM_SIGNATURE_LENGTH = 9; var ENDSTREAM_SIGNATURE = [0x65, 0x6E, 0x64, 0x73, 0x74, 0x72, 0x65, 0x61, 0x6D]; - var skipped = 0, found = false; + var skipped = 0, found = false, i, j; while (stream.pos < stream.end) { var scanBytes = stream.peekBytes(SCAN_BLOCK_SIZE); var scanLength = scanBytes.length - ENDSTREAM_SIGNATURE_LENGTH; - var found = false, i, j; + found = false; for (i = 0, j = 0; i < scanLength; i++) { var b = scanBytes[i]; if (b !== ENDSTREAM_SIGNATURE[j]) { diff --git a/src/core/pattern.js b/src/core/pattern.js index a59c766a5..f84567e89 100644 --- a/src/core/pattern.js +++ b/src/core/pattern.js @@ -162,15 +162,16 @@ Shadings.RadialAxial = (function RadialAxialClosure() { return; } + var rgbColor; for (var i = t0; i <= t1; i += step) { - var rgbColor = cs.getRgb(fn([i]), 0); + rgbColor = cs.getRgb(fn([i]), 0); var cssColor = Util.makeCssRgb(rgbColor); colorStops.push([(i - t0) / diff, cssColor]); } var background = 'transparent'; if (dict.has('Background')) { - var rgbColor = cs.getRgb(dict.get('Background'), 0); + rgbColor = cs.getRgb(dict.get('Background'), 0); background = Util.makeCssRgb(rgbColor); } diff --git a/src/core/stream.js b/src/core/stream.js index b2580f985..0faa56b12 100644 --- a/src/core/stream.js +++ b/src/core/stream.js @@ -446,7 +446,8 @@ var FlateStream = (function FlateStreamClosure() { // find max code length var maxLen = 0; - for (var i = 0; i < n; ++i) { + var i; + for (i = 0; i < n; ++i) { if (lengths[i] > maxLen) { maxLen = lengths[i]; } @@ -463,13 +464,13 @@ var FlateStream = (function FlateStreamClosure() { // bit-reverse the code var code2 = 0; var t = code; - for (var i = 0; i < len; ++i) { + for (i = 0; i < len; ++i) { code2 = (code2 << 1) | (t & 1); t >>= 1; } // fill the table entries - for (var i = code2; i < size; i += skip) { + for (i = code2; i < size; i += skip) { codes[i] = (len << 16) | val; } ++code; @@ -481,6 +482,7 @@ var FlateStream = (function FlateStreamClosure() { }; FlateStream.prototype.readBlock = function FlateStream_readBlock() { + var buffer, len; var str = this.str; // read block header var hdr = this.getBits(3); @@ -518,7 +520,7 @@ var FlateStream = (function FlateStreamClosure() { this.codeSize = 0; var bufferLength = this.bufferLength; - var buffer = this.ensureBuffer(bufferLength + blockLen); + buffer = this.ensureBuffer(bufferLength + blockLen); var end = bufferLength + blockLen; this.bufferLength = end; if (blockLen === 0) { @@ -550,24 +552,26 @@ var FlateStream = (function FlateStreamClosure() { // build the code lengths code table var codeLenCodeLengths = new Uint8Array(codeLenCodeMap.length); - for (var i = 0; i < numCodeLenCodes; ++i) { + var i; + for (i = 0; i < numCodeLenCodes; ++i) { codeLenCodeLengths[codeLenCodeMap[i]] = this.getBits(3); } var codeLenCodeTab = this.generateHuffmanTable(codeLenCodeLengths); // build the literal and distance code tables - var len = 0; - var i = 0; + len = 0; + i = 0; var codes = numLitCodes + numDistCodes; var codeLengths = new Uint8Array(codes); + var bitsLength, bitsOffset, what; while (i < codes) { var code = this.getCode(codeLenCodeTab); if (code == 16) { - var bitsLength = 2, bitsOffset = 3, what = len; + bitsLength = 2; bitsOffset = 3; what = len; } else if (code == 17) { - var bitsLength = 3, bitsOffset = 3, what = (len = 0); + bitsLength = 3; bitsOffset = 3; what = (len = 0); } else if (code == 18) { - var bitsLength = 7, bitsOffset = 11, what = (len = 0); + bitsLength = 7; bitsOffset = 11; what = (len = 0); } else { codeLengths[i++] = len = code; continue; @@ -587,7 +591,7 @@ var FlateStream = (function FlateStreamClosure() { error('Unknown block type in flate stream'); } - var buffer = this.buffer; + buffer = this.buffer; var limit = buffer ? buffer.length : 0; var pos = this.bufferLength; while (true) { @@ -610,7 +614,7 @@ var FlateStream = (function FlateStreamClosure() { if (code2 > 0) { code2 = this.getBits(code2); } - var len = (code1 & 0xffff) + code2; + len = (code1 & 0xffff) + code2; code1 = this.getCode(distCodeTable); code1 = distDecode[code1]; code2 = code1 >> 16; @@ -683,9 +687,10 @@ var PredictorStream = (function PredictorStreamClosure() { var inbuf = 0, outbuf = 0; var inbits = 0, outbits = 0; var pos = bufferLength; + var i; if (bits === 1) { - for (var i = 0; i < rowBytes; ++i) { + for (i = 0; i < rowBytes; ++i) { var c = rawBytes[i]; inbuf = (inbuf << 8) | c; // bitwise addition is exclusive or @@ -695,7 +700,7 @@ var PredictorStream = (function PredictorStreamClosure() { inbuf &= 0xFFFF; } } else if (bits === 8) { - for (var i = 0; i < colors; ++i) { + for (i = 0; i < colors; ++i) { buffer[pos++] = rawBytes[i]; } for (; i < rowBytes; ++i) { @@ -707,7 +712,7 @@ var PredictorStream = (function PredictorStreamClosure() { var bitMask = (1 << bits) - 1; var j = 0, k = bufferLength; var columns = this.columns; - for (var i = 0; i < columns; ++i) { + for (i = 0; i < columns; ++i) { for (var kk = 0; kk < colors; ++kk) { if (inbits < bits) { inbuf = (inbuf << 8) | (rawBytes[j++] & 0xFF); @@ -753,15 +758,15 @@ var PredictorStream = (function PredictorStreamClosure() { prevRow = new Uint8Array(rowBytes); } - var j = bufferLength; + var i, j = bufferLength, up, c; switch (predictor) { case 0: - for (var i = 0; i < rowBytes; ++i) { + for (i = 0; i < rowBytes; ++i) { buffer[j++] = rawBytes[i]; } break; case 1: - for (var i = 0; i < pixBytes; ++i) { + for (i = 0; i < pixBytes; ++i) { buffer[j++] = rawBytes[i]; } for (; i < rowBytes; ++i) { @@ -770,12 +775,12 @@ var PredictorStream = (function PredictorStreamClosure() { } break; case 2: - for (var i = 0; i < rowBytes; ++i) { + for (i = 0; i < rowBytes; ++i) { buffer[j++] = (prevRow[i] + rawBytes[i]) & 0xFF; } break; case 3: - for (var i = 0; i < pixBytes; ++i) { + for (i = 0; i < pixBytes; ++i) { buffer[j++] = (prevRow[i] >> 1) + rawBytes[i]; } for (; i < rowBytes; ++i) { @@ -787,13 +792,13 @@ var PredictorStream = (function PredictorStreamClosure() { case 4: // we need to save the up left pixels values. the simplest way // is to create a new buffer - for (var i = 0; i < pixBytes; ++i) { - var up = prevRow[i]; - var c = rawBytes[i]; + for (i = 0; i < pixBytes; ++i) { + up = prevRow[i]; + c = rawBytes[i]; buffer[j++] = up + c; } for (; i < rowBytes; ++i) { - var up = prevRow[i]; + up = prevRow[i]; var upLeft = prevRow[i - pixBytes]; var left = buffer[j - pixBytes]; var p = left + up - upLeft; @@ -811,7 +816,7 @@ var PredictorStream = (function PredictorStreamClosure() { pc = -pc; } - var c = rawBytes[i]; + c = rawBytes[i]; if (pa <= pb && pa <= pc) { buffer[j++] = left + c; } else if (pb <= pc) { @@ -951,6 +956,7 @@ var JpxStream = (function JpxStreamClosure() { var tileTop = tileCompoments[0].top; var dataPosition, sourcePosition, data0, data1, data2, data3, rowFeed; + var i, j; switch (componentsCount) { case 1: data0 = tileCompoments[0].items; @@ -958,8 +964,8 @@ var JpxStream = (function JpxStreamClosure() { dataPosition = width * tileTop + tileLeft; rowFeed = width - tileWidth; sourcePosition = 0; - for (var j = 0; j < tileHeight; j++) { - for (var i = 0; i < tileWidth; i++) { + for (j = 0; j < tileHeight; j++) { + for (i = 0; i < tileWidth; i++) { data[dataPosition++] = data0[sourcePosition++]; } dataPosition += rowFeed; @@ -973,8 +979,8 @@ var JpxStream = (function JpxStreamClosure() { dataPosition = (width * tileTop + tileLeft) * 3; rowFeed = (width - tileWidth) * 3; sourcePosition = 0; - for (var j = 0; j < tileHeight; j++) { - for (var i = 0; i < tileWidth; i++) { + for (j = 0; j < tileHeight; j++) { + for (i = 0; i < tileWidth; i++) { data[dataPosition++] = data0[sourcePosition]; data[dataPosition++] = data1[sourcePosition]; data[dataPosition++] = data2[sourcePosition]; @@ -992,8 +998,8 @@ var JpxStream = (function JpxStreamClosure() { dataPosition = (width * tileTop + tileLeft) * 4; rowFeed = (width - tileWidth) * 4; sourcePosition = 0; - for (var j = 0; j < tileHeight; j++) { - for (var i = 0; i < tileWidth; i++) { + for (j = 0; j < tileHeight; j++) { + for (i = 0; i < tileWidth; i++) { data[dataPosition++] = data0[sourcePosition]; data[dataPosition++] = data1[sourcePosition]; data[dataPosition++] = data2[sourcePosition]; @@ -1156,18 +1162,19 @@ var Ascii85Stream = (function Ascii85StreamClosure() { } var bufferLength = this.bufferLength, buffer; + var i; // special code for z if (c == Z_LOWER_CHAR) { buffer = this.ensureBuffer(bufferLength + 4); - for (var i = 0; i < 4; ++i) { + for (i = 0; i < 4; ++i) { buffer[bufferLength + i] = 0; } this.bufferLength += 4; } else { var input = this.input; input[0] = c; - for (var i = 1; i < 5; ++i) { + for (i = 1; i < 5; ++i) { c = str.getByte(); while (Lexer.isSpace(c)) { c = str.getByte(); @@ -1190,11 +1197,11 @@ var Ascii85Stream = (function Ascii85StreamClosure() { this.eof = true; } var t = 0; - for (var i = 0; i < 5; ++i) { + for (i = 0; i < 5; ++i) { t = t * 85 + (input[i] - 0x21); } - for (var i = 3; i >= 0; --i) { + for (i = 3; i >= 0; --i) { buffer[bufferLength + i] = t & 0xFF; t >>= 8; } @@ -1287,11 +1294,12 @@ var RunLengthStream = (function RunLengthStreamClosure() { return; } + var buffer; var bufferLength = this.bufferLength; var n = repeatHeader[0]; if (n < 128) { // copy n bytes - var buffer = this.ensureBuffer(bufferLength + n + 1); + buffer = this.ensureBuffer(bufferLength + n + 1); buffer[bufferLength++] = repeatHeader[1]; if (n > 0) { var source = this.str.getBytes(n); @@ -1301,7 +1309,7 @@ var RunLengthStream = (function RunLengthStreamClosure() { } else { n = 257 - n; var b = repeatHeader[1]; - var buffer = this.ensureBuffer(bufferLength + n + 1); + buffer = this.ensureBuffer(bufferLength + n + 1); for (var i = 0; i < n; i++) { buffer[bufferLength++] = b; } @@ -1851,7 +1859,7 @@ var CCITTFaxStream = (function CCITTFaxStreamClosure() { var codingLine = this.codingLine; var columns = this.columns; - var refPos, blackPixels, bits; + var refPos, blackPixels, bits, i; if (this.outputBits === 0) { if (this.eof) { @@ -1861,7 +1869,7 @@ var CCITTFaxStream = (function CCITTFaxStreamClosure() { var code1, code2, code3; if (this.nextLine2D) { - for (var i = 0; codingLine[i] < columns; ++i) { + for (i = 0; codingLine[i] < columns; ++i) { refLine[i] = codingLine[i]; } refLine[i++] = columns; @@ -2063,7 +2071,7 @@ var CCITTFaxStream = (function CCITTFaxStreamClosure() { this.eatBits(1); } if (this.encoding >= 0) { - for (var i = 0; i < 4; ++i) { + for (i = 0; i < 4; ++i) { code1 = this.lookBits(12); if (code1 != 1) { info('bad rtc code: ' + code1); @@ -2114,7 +2122,7 @@ var CCITTFaxStream = (function CCITTFaxStreamClosure() { codingLine[this.codingPos - 1]); } } else { - var bits = 8; + bits = 8; c = 0; do { if (this.outputBits > bits) { diff --git a/src/display/api.js b/src/display/api.js index 66304ea19..7495907e1 100644 --- a/src/display/api.js +++ b/src/display/api.js @@ -596,8 +596,9 @@ var PDFPageProxy = (function PDFPageProxyClosure() { _renderPageChunk: function PDFPageProxy_renderPageChunk(operatorListChunk, intent) { var intentState = this.intentStates[intent]; + var i, ii; // Add the new chunk to the current operator list. - for (var i = 0, ii = operatorListChunk.length; i < ii; i++) { + for (i = 0, ii = operatorListChunk.length; i < ii; i++) { intentState.operatorList.fnArray.push(operatorListChunk.fnArray[i]); intentState.operatorList.argsArray.push( operatorListChunk.argsArray[i]); @@ -605,7 +606,7 @@ var PDFPageProxy = (function PDFPageProxyClosure() { intentState.operatorList.lastChunk = operatorListChunk.lastChunk; // Notify all the rendering tasks there are more operators to be consumed. - for (var i = 0; i < intentState.renderTasks.length; i++) { + for (i = 0; i < intentState.renderTasks.length; i++) { intentState.renderTasks[i].operatorListChanged(); } @@ -886,17 +887,18 @@ var WorkerTransport = (function WorkerTransportClosure() { var pageIndex = data[1]; var type = data[2]; var pageProxy = this.pageCache[pageIndex]; + var imageData; if (pageProxy.objs.hasData(id)) { return; } switch (type) { case 'JpegStream': - var imageData = data[3]; + imageData = data[3]; loadJpegStream(id, imageData, pageProxy.objs); break; case 'Image': - var imageData = data[3]; + imageData = data[3]; pageProxy.objs.resolve(id, imageData); // heuristics that will allow not to store large data @@ -952,15 +954,16 @@ var WorkerTransport = (function WorkerTransportClosure() { var tmpCtx = tmpCanvas.getContext('2d'); tmpCtx.drawImage(img, 0, 0); var data = tmpCtx.getImageData(0, 0, width, height).data; + var i, j; if (components == 3) { - for (var i = 0, j = 0; i < rgbaLength; i += 4, j += 3) { + for (i = 0, j = 0; i < rgbaLength; i += 4, j += 3) { buf[j] = data[i]; buf[j + 1] = data[i + 1]; buf[j + 2] = data[i + 2]; } } else if (components == 1) { - for (var i = 0, j = 0; i < rgbaLength; i += 4, j++) { + for (i = 0, j = 0; i < rgbaLength; i += 4, j++) { buf[j] = data[i]; } } @@ -1003,7 +1006,7 @@ var WorkerTransport = (function WorkerTransportClosure() { if (pageIndex in this.pagePromises) { return this.pagePromises[pageIndex]; } - var promise = new PDFJS.LegacyPromise(); + promise = new PDFJS.LegacyPromise(); this.pagePromises[pageIndex] = promise; this.messageHandler.send('GetPageRequest', { pageIndex: pageIndex }); return promise; diff --git a/src/display/canvas.js b/src/display/canvas.js index 55d11dcf5..9e6414f4a 100644 --- a/src/display/canvas.js +++ b/src/display/canvas.js @@ -453,13 +453,13 @@ var CanvasGraphics = (function CanvasGraphicsClosure() { var partialChunkHeight = height - fullChunks * fullChunkHeight; var chunkImgData = ctx.createImageData(width, fullChunkHeight); - var srcPos = 0; + var srcPos = 0, destPos; var src = imgData.data; var dest = chunkImgData.data; + var i, j, thisChunkHeight, elemsInThisChunk; // There are multiple forms in which the pixel data can be passed, and // imgData.kind tells us which one this is. - if (imgData.kind === ImageKind.GRAYSCALE_1BPP) { // Grayscale, 1 bit per pixel (i.e. black-and-white). var destDataLength = dest.length; @@ -471,11 +471,11 @@ var CanvasGraphics = (function CanvasGraphicsClosure() { var white = 0xFFFFFFFF; var black = (PDFJS.isLittleEndian || !PDFJS.hasCanvasTypedArrays) ? 0xFF000000 : 0x000000FF; - for (var i = 0; i < totalChunks; i++) { - var thisChunkHeight = + for (i = 0; i < totalChunks; i++) { + thisChunkHeight = (i < fullChunks) ? fullChunkHeight : partialChunkHeight; - var destPos = 0; - for (var j = 0; j < thisChunkHeight; j++) { + destPos = 0; + for (j = 0; j < thisChunkHeight; j++) { var srcDiff = srcLength - srcPos; var k = 0; var kEnd = (srcDiff > fullSrcDiff) ? width : srcDiff * 8 - 7; @@ -510,29 +510,27 @@ var CanvasGraphics = (function CanvasGraphicsClosure() { ctx.putImageData(chunkImgData, 0, i * fullChunkHeight); } - } else if (imgData.kind === ImageKind.RGBA_32BPP) { // RGBA, 32-bits per pixel. - for (var i = 0; i < totalChunks; i++) { - var thisChunkHeight = + for (i = 0; i < totalChunks; i++) { + thisChunkHeight = (i < fullChunks) ? fullChunkHeight : partialChunkHeight; - var elemsInThisChunk = imgData.width * thisChunkHeight * 4; + elemsInThisChunk = imgData.width * thisChunkHeight * 4; dest.set(src.subarray(srcPos, srcPos + elemsInThisChunk)); srcPos += elemsInThisChunk; ctx.putImageData(chunkImgData, 0, i * fullChunkHeight); } - } else if (imgData.kind === ImageKind.RGB_24BPP) { // RGB, 24-bits per pixel. - for (var i = 0; i < totalChunks; i++) { - var thisChunkHeight = + for (i = 0; i < totalChunks; i++) { + thisChunkHeight = (i < fullChunks) ? fullChunkHeight : partialChunkHeight; - var elemsInThisChunk = imgData.width * thisChunkHeight * 3; - var destPos = 0; - for (var j = 0; j < elemsInThisChunk; j += 3) { + elemsInThisChunk = imgData.width * thisChunkHeight * 3; + destPos = 0; + for (j = 0; j < elemsInThisChunk; j += 3) { dest[destPos++] = src[srcPos++]; dest[destPos++] = src[srcPos++]; dest[destPos++] = src[srcPos++]; @@ -540,9 +538,8 @@ var CanvasGraphics = (function CanvasGraphicsClosure() { } ctx.putImageData(chunkImgData, 0, i * fullChunkHeight); } - } else { - error('bad image kind: ' + imgData.kind); + error('bad image kind: ' + imgData.kind); } } @@ -1311,6 +1308,8 @@ var CanvasGraphics = (function CanvasGraphicsClosure() { var glyphsLength = glyphs.length; var vertical = font.vertical; var defaultVMetrics = font.defaultVMetrics; + var i, glyph, width; + var VERTICAL_TEXT_ROTATION = Math.PI / 2; if (fontSize === 0) { return; @@ -1324,9 +1323,8 @@ var CanvasGraphics = (function CanvasGraphicsClosure() { ctx.scale(textHScale, 1); - for (var i = 0; i < glyphsLength; ++i) { - - var glyph = glyphs[i]; + for (i = 0; i < glyphsLength; ++i) { + glyph = glyphs[i]; if (glyph === null) { // word break this.ctx.translate(wordSpacing, 0); @@ -1342,8 +1340,8 @@ var CanvasGraphics = (function CanvasGraphicsClosure() { this.restore(); var transformed = Util.applyTransform([glyph.width, 0], fontMatrix); - var width = (transformed[0] * fontSize + charSpacing) * - current.fontDirection; + width = ((transformed[0] * fontSize + charSpacing) * + current.fontDirection); ctx.translate(width, 0); current.x += width * textHScale; @@ -1371,8 +1369,8 @@ var CanvasGraphics = (function CanvasGraphicsClosure() { ctx.lineWidth = lineWidth; var x = 0; - for (var i = 0; i < glyphsLength; ++i) { - var glyph = glyphs[i]; + for (i = 0; i < glyphsLength; ++i) { + glyph = glyphs[i]; if (glyph === null) { // word break x += current.fontDirection * wordSpacing; @@ -1387,7 +1385,7 @@ var CanvasGraphics = (function CanvasGraphicsClosure() { vx = -vx * fontSize * current.fontMatrix[0]; var vy = vmetric[2] * fontSize * current.fontMatrix[0]; } - var width = vmetric ? -vmetric[0] : glyph.width; + width = vmetric ? -vmetric[0] : glyph.width; var charWidth = width * fontSize * current.fontMatrix[0] + charSpacing * current.fontDirection; var accent = glyph.accent; @@ -1509,6 +1507,7 @@ var CanvasGraphics = (function CanvasGraphicsClosure() { this.current.strokeColor = color; }, getColorN_Pattern: function CanvasGraphics_getColorN_Pattern(IR, cs) { + var pattern; if (IR[0] == 'TilingPattern') { var args = IR[1]; var base = cs.base; @@ -1518,10 +1517,10 @@ var CanvasGraphics = (function CanvasGraphicsClosure() { color = base.getRgb(args, 0); } - var pattern = new TilingPattern(IR, color, this.ctx, this.objs, - this.commonObjs, this.baseTransform); + pattern = new TilingPattern(IR, color, this.ctx, this.objs, + this.commonObjs, this.baseTransform); } else { - var pattern = getShadingPatternFromIR(IR); + pattern = getShadingPatternFromIR(IR); } return pattern; }, @@ -1999,12 +1998,12 @@ var CanvasGraphics = (function CanvasGraphicsClosure() { var c = currentTransform[2], d = currentTransform[3]; var heightScale = Math.max(Math.sqrt(c * c + d * d), 1); - var imgToPaint; + var imgToPaint, tmpCanvas; // instanceof HTMLElement does not work in jsdom node.js module if (imgData instanceof HTMLElement || !imgData.data) { imgToPaint = imgData; } else { - var tmpCanvas = CachedCanvases.getCanvas('inlineImage', width, height); + tmpCanvas = CachedCanvases.getCanvas('inlineImage', width, height); var tmpCtx = tmpCanvas.context; putBinaryImageData(tmpCtx, imgData); imgToPaint = tmpCanvas.canvas; @@ -2026,8 +2025,7 @@ var CanvasGraphics = (function CanvasGraphicsClosure() { newHeight = Math.ceil(paintHeight / 2); heightScale /= paintHeight / newHeight; } - var tmpCanvas = CachedCanvases.getCanvas(tmpCanvasId, - newWidth, newHeight); + tmpCanvas = CachedCanvases.getCanvas(tmpCanvasId, newWidth, newHeight); tmpCtx = tmpCanvas.context; tmpCtx.clearRect(0, 0, newWidth, newHeight); tmpCtx.drawImage(imgToPaint, 0, 0, paintWidth, paintHeight, diff --git a/src/display/pattern_helper.js b/src/display/pattern_helper.js index 85cba5d67..8359d6775 100644 --- a/src/display/pattern_helper.js +++ b/src/display/pattern_helper.js @@ -117,12 +117,13 @@ var createMeshCanvas = (function createMeshCanvasClosure() { function drawFigure(data, figure, context) { var ps = figure.coords; var cs = figure.colors; + var i, ii; switch (figure.type) { case 'lattice': var verticesPerRow = figure.verticesPerRow; var rows = Math.floor(ps.length / verticesPerRow) - 1; var cols = verticesPerRow - 1; - for (var i = 0; i < rows; i++) { + for (i = 0; i < rows; i++) { var q = i * verticesPerRow; for (var j = 0; j < cols; j++, q++) { drawTriangle(data, context, @@ -135,7 +136,7 @@ var createMeshCanvas = (function createMeshCanvasClosure() { } break; case 'triangles': - for (var i = 0, ii = ps.length; i < ii; i += 3) { + for (i = 0, ii = ps.length; i < ii; i += 3) { drawTriangle(data, context, ps[i], ps[i + 1], ps[i + 2], cs[i], cs[i + 1], cs[i + 2]); @@ -176,30 +177,30 @@ var createMeshCanvas = (function createMeshCanvasClosure() { scaleY: 1 / scaleY }; - var canvas; + var canvas, tmpCanvas, i, ii; if (WebGLUtils.isEnabled) { canvas = WebGLUtils.drawFigures(width, height, backgroundColor, figures, context); // https://bugzilla.mozilla.org/show_bug.cgi?id=972126 - var tmpCanvas = CachedCanvases.getCanvas('mesh', width, height, false); + tmpCanvas = CachedCanvases.getCanvas('mesh', width, height, false); tmpCanvas.context.drawImage(canvas, 0, 0); canvas = tmpCanvas.canvas; } else { - var tmpCanvas = CachedCanvases.getCanvas('mesh', width, height, false); + tmpCanvas = CachedCanvases.getCanvas('mesh', width, height, false); var tmpCtx = tmpCanvas.context; var data = tmpCtx.createImageData(width, height); if (backgroundColor) { var bytes = data.data; - for (var i = 0, ii = bytes.length; i < ii; i += 4) { + for (i = 0, ii = bytes.length; i < ii; i += 4) { bytes[i] = backgroundColor[0]; bytes[i + 1] = backgroundColor[1]; bytes[i + 2] = backgroundColor[2]; bytes[i + 3] = 255; } } - for (var i = 0; i < figures.length; i++) { + for (i = 0; i < figures.length; i++) { drawFigure(data, figures[i], context); } tmpCtx.putImageData(data, 0, 0); @@ -414,7 +415,7 @@ var TilingPattern = (function TilingPatternClosure() { getPattern: function TilingPattern_getPattern(ctx, owner) { var temporaryPatternCanvas = this.createPatternCanvas(owner); - var ctx = this.ctx; + ctx = this.ctx; ctx.setTransform.apply(ctx, this.baseTransform); ctx.transform.apply(ctx, this.matrix); this.scaleToContext(); diff --git a/src/display/webgl.js b/src/display/webgl.js index 13d68bc13..cfef4c865 100644 --- a/src/display/webgl.js +++ b/src/display/webgl.js @@ -294,10 +294,11 @@ var WebGLUtils = (function WebGLUtilsClosure() { // count triangle points var count = 0; - for (var i = 0, ii = figures.length; i < ii; i++) { + var i, ii, rows; + for (i = 0, ii = figures.length; i < ii; i++) { switch (figures[i].type) { case 'lattice': - var rows = (figures[i].coords.length / figures[i].verticesPerRow) | 0; + rows = (figures[i].coords.length / figures[i].verticesPerRow) | 0; count += (rows - 1) * (figures[i].verticesPerRow - 1) * 6; break; case 'triangles': @@ -310,12 +311,12 @@ var WebGLUtils = (function WebGLUtilsClosure() { var colors = new Uint8Array(count * 3); var coordsMap = context.coords, colorsMap = context.colors; var pIndex = 0, cIndex = 0; - for (var i = 0, ii = figures.length; i < ii; i++) { + for (i = 0, ii = figures.length; i < ii; i++) { var figure = figures[i], ps = figure.coords, cs = figure.colors; switch (figure.type) { case 'lattice': var cols = figure.verticesPerRow; - var rows = (ps.length / cols) | 0; + rows = (ps.length / cols) | 0; for (var row = 1; row < rows; row++) { var offset = row * cols + 1; for (var col = 1; col < cols; col++, offset++) { diff --git a/src/shared/annotation.js b/src/shared/annotation.js index 7ae2b7aeb..31bbf1a13 100644 --- a/src/shared/annotation.js +++ b/src/shared/annotation.js @@ -112,7 +112,8 @@ var Annotation = (function AnnotationClosure() { var isInvalid = false; var numPositive = 0; for (var i = 0; i < dashArrayLength; i++) { - if (!(+dashArray[i] >= 0)) { + var validNumber = (+dashArray[i] >= 0); + if (!validNumber) { isInvalid = true; break; } else if (dashArray[i] > 0) { @@ -673,10 +674,12 @@ var TextAnnotation = (function TextAnnotationClosure() { var content = document.createElement('div'); content.className = 'annotTextContent'; content.setAttribute('hidden', true); + + var i, ii; if (item.hasBgColor) { var color = item.color; var rgb = []; - for (var i = 0; i < 3; ++i) { + for (i = 0; i < 3; ++i) { // Enlighten the color (70%) var c = Math.round(color[i] * 255); rgb[i] = Math.round((255 - c) * 0.7) + c; @@ -693,7 +696,7 @@ var TextAnnotation = (function TextAnnotationClosure() { } else { var e = document.createElement('span'); var lines = item.content.split(/(?:\r\n?|\n)/); - for (var i = 0, ii = lines.length; i < ii; ++i) { + for (i = 0, ii = lines.length; i < ii; ++i) { var line = lines[i]; e.appendChild(document.createTextNode(line)); if (i < (ii - 1)) { diff --git a/src/shared/colorspace.js b/src/shared/colorspace.js index 2cf181ac1..d2e9c3482 100644 --- a/src/shared/colorspace.js +++ b/src/shared/colorspace.js @@ -85,10 +85,10 @@ var ColorSpace = (function ColorSpaceClosure() { var rgbBuf = null; var numComponentColors = 1 << bpc; var needsResizing = originalHeight != height || originalWidth != width; + var i, ii; if (this.isPassthrough(bpc)) { rgbBuf = comps; - } else if (this.numComps === 1 && count > numComponentColors && this.name !== 'DeviceGray' && this.name !== 'DeviceRGB') { // Optimization: create a color map when there is just one component and @@ -102,18 +102,20 @@ var ColorSpace = (function ColorSpaceClosure() { // we are reparsing colorspaces too much?). var allColors = bpc <= 8 ? new Uint8Array(numComponentColors) : new Uint16Array(numComponentColors); - for (var i = 0; i < numComponentColors; i++) { + var key; + for (i = 0; i < numComponentColors; i++) { allColors[i] = i; } var colorMap = new Uint8Array(numComponentColors * 3); this.getRgbBuffer(allColors, 0, numComponentColors, colorMap, 0, bpc, /* alpha01 = */ 0); + var destPos, rgbPos; if (!needsResizing) { // Fill in the RGB values directly into |dest|. - var destPos = 0; - for (var i = 0; i < count; ++i) { - var key = comps[i] * 3; + destPos = 0; + for (i = 0; i < count; ++i) { + key = comps[i] * 3; dest[destPos++] = colorMap[key]; dest[destPos++] = colorMap[key + 1]; dest[destPos++] = colorMap[key + 2]; @@ -121,9 +123,9 @@ var ColorSpace = (function ColorSpaceClosure() { } } else { rgbBuf = new Uint8Array(count * 3); - var rgbPos = 0; - for (var i = 0; i < count; ++i) { - var key = comps[i] * 3; + rgbPos = 0; + for (i = 0; i < count; ++i) { + key = comps[i] * 3; rgbBuf[rgbPos++] = colorMap[key]; rgbBuf[rgbPos++] = colorMap[key + 1]; rgbBuf[rgbPos++] = colorMap[key + 2]; @@ -146,9 +148,9 @@ var ColorSpace = (function ColorSpaceClosure() { rgbBuf = PDFImage.resize(rgbBuf, bpc, 3, originalWidth, originalHeight, width, height); } - var rgbPos = 0; - var destPos = 0; - for (var i = 0, ii = width * actualHeight; i < ii; i++) { + rgbPos = 0; + destPos = 0; + for (i = 0, ii = width * actualHeight; i < ii; i++) { dest[destPos++] = rgbBuf[rgbPos++]; dest[destPos++] = rgbBuf[rgbPos++]; dest[destPos++] = rgbBuf[rgbPos++]; @@ -174,6 +176,7 @@ var ColorSpace = (function ColorSpaceClosure() { ColorSpace.fromIR = function ColorSpace_fromIR(IR) { var name = isArray(IR) ? IR[0] : IR; + var whitePoint, blackPoint; switch (name) { case 'DeviceGrayCS': @@ -183,8 +186,8 @@ var ColorSpace = (function ColorSpaceClosure() { case 'DeviceCmykCS': return this.singletons.cmyk; case 'CalGrayCS': - var whitePoint = IR[1].WhitePoint; - var blackPoint = IR[1].BlackPoint; + whitePoint = IR[1].WhitePoint; + blackPoint = IR[1].BlackPoint; var gamma = IR[1].Gamma; return new CalGrayCS(whitePoint, blackPoint, gamma); case 'PatternCS': @@ -206,8 +209,8 @@ var ColorSpace = (function ColorSpaceClosure() { return new AlternateCS(numComps, ColorSpace.fromIR(alt), PDFFunction.fromIR(tintFnIR)); case 'LabCS': - var whitePoint = IR[1].WhitePoint; - var blackPoint = IR[1].BlackPoint; + whitePoint = IR[1].WhitePoint; + blackPoint = IR[1].BlackPoint; var range = IR[1].Range; return new LabCS(whitePoint, blackPoint, range); default: @@ -252,6 +255,7 @@ var ColorSpace = (function ColorSpaceClosure() { } else if (isArray(cs)) { mode = cs[0].name; this.mode = mode; + var numComps, params; switch (mode) { case 'DeviceGray': @@ -264,14 +268,14 @@ var ColorSpace = (function ColorSpaceClosure() { case 'CMYK': return 'DeviceCmykCS'; case 'CalGray': - var params = cs[1].getAll(); + params = cs[1].getAll(); return ['CalGrayCS', params]; case 'CalRGB': return 'DeviceRgbCS'; case 'ICCBased': var stream = xref.fetchIfRef(cs[1]); var dict = stream.dict; - var numComps = dict.get('N'); + numComps = dict.get('N'); if (numComps == 1) { return 'DeviceGrayCS'; } else if (numComps == 3) { @@ -298,7 +302,7 @@ var ColorSpace = (function ColorSpaceClosure() { case 'Separation': case 'DeviceN': var name = cs[1]; - var numComps = 1; + numComps = 1; if (isName(name)) { numComps = 1; } else if (isArray(name)) { @@ -308,7 +312,7 @@ var ColorSpace = (function ColorSpaceClosure() { var tintFnIR = PDFFunction.getIR(xref, xref.fetchIfRef(cs[3])); return ['AlternateCS', numComps, alt, tintFnIR]; case 'Lab': - var params = cs[1].getAll(); + params = cs[1].getAll(); return ['LabCS', params]; default: error('unimplemented color space object "' + mode + '"'); @@ -403,13 +407,14 @@ var AlternateCS = (function AlternateCSClosure() { var numComps = this.numComps; var scaled = new Float32Array(numComps); - for (var i = 0; i < count; i++) { - for (var j = 0; j < numComps; j++) { + var i, j; + for (i = 0; i < count; i++) { + for (j = 0; j < numComps; j++) { scaled[j] = src[srcOffset++] * scale; } var tinted = tintFn(scaled); if (usesZeroToOneRange) { - for (var j = 0; j < baseNumComps; j++) { + for (j = 0; j < baseNumComps; j++) { baseBuf[pos++] = tinted[j] * 255; } } else { diff --git a/src/shared/fonts_utils.js b/src/shared/fonts_utils.js index a14d92106..a2dc4dc60 100644 --- a/src/shared/fonts_utils.js +++ b/src/shared/fonts_utils.js @@ -37,20 +37,21 @@ function readCharset(aStream, aCharstrings) { var format = aStream.getByte(); var count = aCharstrings.length - 1; + var i, sid; if (format === 0) { charset['.notdef'] = readCharstringEncoding(aCharstrings[0]); - for (var i = 1; i < count + 1; i++) { - var sid = aStream.getByte() << 8 | aStream.getByte(); + for (i = 1; i < count + 1; i++) { + sid = aStream.getByte() << 8 | aStream.getByte(); charset[CFFStrings[sid]] = readCharstringEncoding(aCharstrings[i]); } } else if (format == 1) { - for (var i = 1; i < count + 1; i++) { + for (i = 1; i < count + 1; i++) { var first = aStream.getByte(); first = (first << 8) | aStream.getByte(); var numLeft = aStream.getByte(); for (var j = 0; j <= numLeft; j++) { - var sid = first++; + sid = first++; charset[CFFStrings[sid]] = readCharstringEncoding(aCharstrings[j]); } } @@ -223,7 +224,8 @@ function readFontIndexData(aStream, aIsByte) { } var offsets = []; - for (var i = 0; i < count + 1; i++) { + var i; + for (i = 0; i < count + 1; i++) { offsets.push(getNextOffset()); } @@ -233,7 +235,7 @@ function readFontIndexData(aStream, aIsByte) { // Now extract the objects var relativeOffset = aStream.pos; var objects = []; - for (var i = 0; i < count; i++) { + for (i = 0; i < count; i++) { var offset = offsets[i]; aStream.pos = relativeOffset + offset - 1; @@ -332,14 +334,15 @@ var Type2Parser = function type2Parser(aFilePath) { dump('strings: ' + strings); // Fill up the Strings dictionary with the new unique strings - for (var i = 0; i < strings.length; i++) { + var i; + for (i = 0; i < strings.length; i++) { CFFStrings.push(strings[i].join('')); } // Parse the TopDict operator var objects = []; var count = topDict.length; - for (var i = 0; i < count; i++) { + for (i = 0; i < count; i++) { parseAsToken(topDict[i], CFFDictDataMap); } @@ -356,7 +359,7 @@ var Type2Parser = function type2Parser(aFilePath) { aStream.pos = priv.offset; var privateDict = []; - for (var i = 0; i < priv.size; i++) { + for (i = 0; i < priv.size; i++) { privateDict.push(aStream.getByte()); } dump('privateData:' + privateDict); diff --git a/src/shared/function.js b/src/shared/function.js index fe0bedb99..1ed30ad95 100644 --- a/src/shared/function.js +++ b/src/shared/function.js @@ -27,8 +27,9 @@ var PDFFunction = (function PDFFunctionClosure() { return { getSampleArray: function PDFFunction_getSampleArray(size, outputSize, bps, str) { + var i, ii; var length = 1; - for (var i = 0, ii = size.length; i < ii; i++) { + for (i = 0, ii = size.length; i < ii; i++) { length *= size[i]; } length *= outputSize; @@ -41,7 +42,7 @@ var PDFFunction = (function PDFFunctionClosure() { var strBytes = str.getBytes((length * bps + 7) / 8); var strIdx = 0; - for (var i = 0; i < length; i++) { + for (i = 0; i < length; i++) { while (codeSize < bps) { codeBuf <<= 8; codeBuf |= strBytes[strIdx++]; @@ -184,13 +185,14 @@ var PDFFunction = (function PDFFunctionClosure() { var cubeVertices = 1 << m; var cubeN = new Float64Array(cubeVertices); var cubeVertex = new Uint32Array(cubeVertices); - for (var j = 0; j < cubeVertices; j++) { + var i, j; + for (j = 0; j < cubeVertices; j++) { cubeN[j] = 1; } var k = n, pos = 1; // Map x_i to y_j for 0 <= i < m using the sampled function. - for (var i = 0; i < m; ++i) { + for (i = 0; i < m; ++i) { // x_i' = min(max(x_i, Domain_2i), Domain_2i+1) var domain_2i = domain[i][0]; var domain_2i_1 = domain[i][1]; @@ -211,7 +213,7 @@ var PDFFunction = (function PDFFunctionClosure() { var n1 = e - e0; // (e - e0) / (e1 - e0); var offset0 = e0 * k; var offset1 = offset0 + k; // e1 * k - for (var j = 0; j < cubeVertices; j++) { + for (j = 0; j < cubeVertices; j++) { if (j & pos) { cubeN[j] *= n1; cubeVertex[j] += offset1; @@ -226,10 +228,10 @@ var PDFFunction = (function PDFFunctionClosure() { } var y = new Float64Array(n); - for (var j = 0; j < n; ++j) { + for (j = 0; j < n; ++j) { // Sum all cube vertices' samples portions var rj = 0; - for (var i = 0; i < cubeVertices; i++) { + for (i = 0; i < cubeVertices; i++) { rj += samples[cubeVertex[i] + j] * cubeN[i]; } diff --git a/src/shared/util.js b/src/shared/util.js index 01e7fbff3..1aed2d57f 100644 --- a/src/shared/util.js +++ b/src/shared/util.js @@ -237,9 +237,10 @@ function combineUrl(baseUrl, url) { if (/^[a-z][a-z0-9+\-.]*:/i.test(url)) { return url; } + var i; if (url.charAt(0) == '/') { // absolute path - var i = baseUrl.indexOf('://'); + i = baseUrl.indexOf('://'); if (url.charAt(1) === '/') { ++i; } else { @@ -248,7 +249,7 @@ function combineUrl(baseUrl, url) { return baseUrl.substring(0, i) + url; } else { // relative path - var pathLength = baseUrl.length, i; + var pathLength = baseUrl.length; i = baseUrl.lastIndexOf('#'); pathLength = i >= 0 ? i : pathLength; i = baseUrl.lastIndexOf('?', pathLength); @@ -1263,17 +1264,18 @@ var StatTimer = (function StatTimerClosure() { delete this.started[name]; }, toString: function StatTimer_toString() { + var i, ii; var times = this.times; var out = ''; // Find the longest name for padding purposes. var longest = 0; - for (var i = 0, ii = times.length; i < ii; ++i) { + for (i = 0, ii = times.length; i < ii; ++i) { var name = times[i]['name']; if (name.length > longest) { longest = name.length; } } - for (var i = 0, ii = times.length; i < ii; ++i) { + for (i = 0, ii = times.length; i < ii; ++i) { var span = times[i]; var duration = span.end - span.start; out += rpad(span['name'], ' ', longest) + ' ' + duration + 'ms\n'; diff --git a/test/downloadutils.js b/test/downloadutils.js index 483734e7a..486ecff8b 100644 --- a/test/downloadutils.js +++ b/test/downloadutils.js @@ -28,19 +28,20 @@ function downloadFile(file, url, callback, redirects) { var completed = false; var protocol = /^https:\/\//.test(url) ? https : http; protocol.get(url, function (response) { + var redirectTo; if (response.statusCode === 301 || response.statusCode === 302 || response.statusCode === 307 || response.statusCode === 308) { if (redirects > 10) { callback('Too many redirects'); } - var redirectTo = response.headers.location; + redirectTo = response.headers.location; redirectTo = require('url').resolve(url, redirectTo); downloadFile(file, redirectTo, callback, (redirects || 0) + 1); return; } if (response.statusCode === 404 && url.indexOf('web.archive.org') < 0) { // trying waybackmachine - var redirectTo = 'http://web.archive.org/web/' + url; + redirectTo = 'http://web.archive.org/web/' + url; downloadFile(file, redirectTo, callback, (redirects || 0) + 1); return; } diff --git a/test/reporter.js b/test/reporter.js deleted file mode 100644 index 4c3275e82..000000000 --- a/test/reporter.js +++ /dev/null @@ -1,50 +0,0 @@ -/* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* vim: set shiftwidth=2 tabstop=2 autoindent cindent expandtab: */ -/* Copyright 2012 Mozilla Foundation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -/* jshint node:true */ - -'use strict'; - -module.exports = { - reporter: function reporter(res) { - var len = 0; - var str = ''; - - res.forEach(function(r) { - var file = r.file; - var err = r.error; - - switch (err.code) { - case 'W004': // variable is already defined - case 'W018': // confusing use of ! - break; - default: - len++; - str += file + ': line ' + err.line + ', col ' + - err.character + ', ' + err.reason + '\n'; - } - }); - - if (str) { - process.stdout.write(str + '\n' + len + ' error' + - ((len === 1) ? '' : 's') + '\n'); - process.exit(2); - } else { - process.stdout.write('files checked, no errors found\n'); - process.exit(0); - } - } -}; diff --git a/test/test.js b/test/test.js index 9f06f6369..1c3160b3f 100644 --- a/test/test.js +++ b/test/test.js @@ -438,10 +438,11 @@ function refTestPostHandler(req, res) { res.writeHead(200, {'Content-Type': 'text/plain'}); res.end(); + var session; if (pathname === '/tellMeToQuit') { // finding by path var browserPath = parsedUrl.query.path; - var session = sessions.filter(function (session) { + session = sessions.filter(function (session) { return session.config.path === browserPath; })[0]; monitorBrowserTimeout(session, null); @@ -463,7 +464,7 @@ function refTestPostHandler(req, res) { var snapshot = data.snapshot; var lastPageNum = data.lastPageNum; - var session = getSession(browser); + session = getSession(browser); monitorBrowserTimeout(session, handleSessionTimeout); var taskResults = session.taskResults[id]; @@ -720,4 +721,4 @@ var host = '127.0.0.1'; var options = parseOptions(); var stats; -main(); \ No newline at end of file +main(); diff --git a/test/testutils.js b/test/testutils.js index 9a9d1bb9a..5048a88f4 100644 --- a/test/testutils.js +++ b/test/testutils.js @@ -75,14 +75,15 @@ var stdinBuffer = '', endOfStdin = false, stdinInitialized = false; var stdinOnLineCallbacks = []; function handleStdinBuffer() { + var callback; if (endOfStdin) { if (stdinBuffer && stdinOnLineCallbacks.length > 0) { - var callback = stdinOnLineCallbacks.shift(); + callback = stdinOnLineCallbacks.shift(); callback(stdinBuffer); stdinBuffer = null; } while (stdinOnLineCallbacks.length > 0) { - var callback = stdinOnLineCallbacks.shift(); + callback = stdinOnLineCallbacks.shift(); callback(); } return; @@ -92,7 +93,7 @@ function handleStdinBuffer() { if (i < 0) { return; } - var callback = stdinOnLineCallbacks.shift(); + callback = stdinOnLineCallbacks.shift(); var result = stdinBuffer.substring(0, i + 1); stdinBuffer = stdinBuffer.substring(i + 1); callback(result); @@ -143,4 +144,4 @@ exports.confirm = function confirm(message, callback) { confirm(message, callback); } }); -}; \ No newline at end of file +}; diff --git a/test/unit/font_spec.js b/test/unit/font_spec.js index 15d1ce1bf..45c480cf6 100644 --- a/test/unit/font_spec.js +++ b/test/unit/font_spec.js @@ -196,7 +196,7 @@ describe('font', function() { expect(charset.charset[1]).toEqual('exclam'); // CID font - var charset = parser.parseCharsets(3, 2, new CFFStrings(), true); + charset = parser.parseCharsets(3, 2, new CFFStrings(), true); expect(charset.charset[1]).toEqual(2); }); @@ -212,7 +212,7 @@ describe('font', function() { expect(charset.charset).toEqual(['.notdef', 'quoteright', 'parenleft']); // CID font - var charset = parser.parseCharsets(3, 2, new CFFStrings(), true); + charset = parser.parseCharsets(3, 2, new CFFStrings(), true); expect(charset.charset).toEqual(['.notdef', 8, 9]); }); @@ -229,7 +229,7 @@ describe('font', function() { expect(charset.charset).toEqual(['.notdef', 'quoteright', 'parenleft']); // CID font - var charset = parser.parseCharsets(3, 2, new CFFStrings(), true); + charset = parser.parseCharsets(3, 2, new CFFStrings(), true); expect(charset.charset).toEqual(['.notdef', 8, 9]); }); @@ -349,7 +349,7 @@ describe('font', function() { var parser = new Type1Parser(stream); expect(parser.readNumberArray()).toEqual([1, 2]); // Variation on spacing. - var stream = new StringStream('[ 1 2 ]'); + stream = new StringStream('[ 1 2 ]'); parser = new Type1Parser(stream); expect(parser.readNumberArray()).toEqual([1, 2]); }); diff --git a/web/compatibility.js b/web/compatibility.js index a74027123..21ac29fc5 100644 --- a/web/compatibility.js +++ b/web/compatibility.js @@ -58,17 +58,17 @@ if (typeof PDFJS === 'undefined') { } function TypedArray(arg1) { - var result; + var result, i, n; if (typeof arg1 === 'number') { result = []; - for (var i = 0; i < arg1; ++i) { + for (i = 0; i < arg1; ++i) { result[i] = 0; } } else if ('slice' in arg1) { result = arg1.slice(0); } else { result = []; - for (var i = 0, n = arg1.length; i < n; ++i) { + for (i = 0, n = arg1.length; i < n; ++i) { result[i] = arg1[i]; } } diff --git a/web/debugger.js b/web/debugger.js index 21e1193a1..ee217b9e0 100644 --- a/web/debugger.js +++ b/web/debugger.js @@ -211,10 +211,11 @@ var StepperManager = (function StepperManagerClosure() { return stepper; }, selectStepper: function selectStepper(pageIndex, selectPanel) { + var i; if (selectPanel) { this.manager.selectPanel(this); } - for (var i = 0; i < steppers.length; ++i) { + for (i = 0; i < steppers.length; ++i) { var stepper = steppers[i]; if (stepper.pageIndex == pageIndex) { stepper.panel.removeAttribute('hidden'); @@ -223,7 +224,7 @@ var StepperManager = (function StepperManagerClosure() { } } var options = stepperChooser.options; - for (var i = 0; i < options.length; ++i) { + for (i = 0; i < options.length; ++i) { var option = options[i]; option.selected = option.value == pageIndex; } @@ -344,7 +345,7 @@ var Stepper = (function StepperClosure() { var self = this; var chunk = document.createDocumentFragment(); var operatorsToDisplay = Math.min(MAX_OPERATORS_COUNT, - operatorList.fnArray.length); + operatorList.fnArray.length); for (var i = this.operatorListIdx; i < operatorsToDisplay; i++) { var line = c('tr'); line.className = 'line'; @@ -369,7 +370,7 @@ var Stepper = (function StepperClosure() { if (fn in glyphCommands) { var glyphIndex = glyphCommands[fn]; var glyphs = args[glyphIndex]; - var decArgs = args.slice(); + decArgs = args.slice(); var newArg; if (fn === 'showSpacedText') { newArg = []; diff --git a/web/page_view.js b/web/page_view.js index 546ab3fd3..388e1c629 100644 --- a/web/page_view.js +++ b/web/page_view.js @@ -348,7 +348,7 @@ var PageView = function pageView(container, id, scale, var x = 0, y = 0; var width = 0, height = 0, widthScale, heightScale; - var changeOrientation = !!(this.rotation % 180); + var changeOrientation = (this.rotation % 180 === 0 ? false : true); var pageWidth = (changeOrientation ? this.height : this.width) / this.scale / CSS_UNITS; var pageHeight = (changeOrientation ? this.width : this.height) / diff --git a/web/viewer.js b/web/viewer.js index d7e8dc3d0..7003d9cf0 100644 --- a/web/viewer.js +++ b/web/viewer.js @@ -639,7 +639,7 @@ var PDFView = { if (exception && exception.name === 'InvalidPDFException') { // change error message also for other builds - var loadingErrorMessage = mozL10n.get('invalid_file_error', null, + loadingErrorMessage = mozL10n.get('invalid_file_error', null, 'Invalid or corrupted PDF file.'); //#if B2G // window.alert(loadingErrorMessage); @@ -649,7 +649,7 @@ var PDFView = { if (exception && exception.name === 'MissingPDFException') { // special message for missing PDF's - var loadingErrorMessage = mozL10n.get('missing_file_error', null, + loadingErrorMessage = mozL10n.get('missing_file_error', null, 'Missing PDF file.'); //#if B2G @@ -1478,10 +1478,11 @@ var PDFView = { } var alertNotReady = false; + var i, ii; if (!this.pages.length) { alertNotReady = true; } else { - for (var i = 0, ii = this.pages.length; i < ii; ++i) { + for (i = 0, ii = this.pages.length; i < ii; ++i) { if (!this.pages[i].pdfPage) { alertNotReady = true; break; @@ -1497,7 +1498,7 @@ var PDFView = { var body = document.querySelector('body'); body.setAttribute('data-mozPrintCallback', true); - for (var i = 0, ii = this.pages.length; i < ii; ++i) { + for (i = 0, ii = this.pages.length; i < ii; ++i) { this.pages[i].beforePrint(); } }, @@ -1511,14 +1512,15 @@ var PDFView = { rotatePages: function pdfViewRotatePages(delta) { var currentPage = this.pages[this.page - 1]; + var i, l; this.pageRotation = (this.pageRotation + 360 + delta) % 360; - for (var i = 0, l = this.pages.length; i < l; i++) { + for (i = 0, l = this.pages.length; i < l; i++) { var page = this.pages[i]; page.update(page.scale, this.pageRotation); } - for (var i = 0, l = this.thumbnails.length; i < l; i++) { + for (i = 0, l = this.thumbnails.length; i < l; i++) { var thumb = this.thumbnails[i]; thumb.update(this.pageRotation); }