Fixes lint warning W004 in src/core

This commit is contained in:
Tim van der Meij 2014-04-07 23:42:54 +02:00
parent 7a2cb7cddd
commit df91acf239
14 changed files with 593 additions and 516 deletions

View File

@ -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;

View File

@ -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) {

View File

@ -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);

View File

@ -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) {

View File

@ -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);
@ -1376,7 +1381,7 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
(symbolsFonts[fontNameWoStyle] ? FontFlags.Symbolic :
FontFlags.Nonsymbolic);
var properties = {
properties = {
type: type.name,
name: baseFontName,
widths: metrics.widths,
@ -1441,7 +1446,7 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
}
}
var properties = {
properties = {
type: type.name,
name: fontName.name,
subtype: subtype,
@ -1683,7 +1688,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 +1942,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 +1965,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 +2009,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 +2020,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 +2046,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 +2062,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 +2090,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 +2101,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 +2118,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;

View File

@ -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);

File diff suppressed because it is too large Load Diff

View File

@ -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;
}
},

View File

@ -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;
}

View File

@ -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);
}
};

View File

@ -988,13 +988,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 +1333,7 @@ var ObjectLoader = (function() {
}
function addChildren(node, nodesToVisit) {
var value;
if (isDict(node) || isStream(node)) {
var map;
if (isDict(node)) {
@ -1340,14 +1342,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);
}

View File

@ -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]) {

View File

@ -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);
}

View File

@ -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) {