Merge pull request #4507 from Snuffleupagus/src-core-braces

Fix coding style in src/core
This commit is contained in:
Tim van der Meij 2014-03-22 22:50:17 +01:00
commit 8863ee5d7b
5 changed files with 272 additions and 185 deletions

View File

@ -55,7 +55,7 @@ var ChunkedStream = (function ChunkedStreamClosure() {
return this.numChunksLoaded === this.numChunks;
},
onReceiveData: function(begin, chunk) {
onReceiveData: function ChunkedStream_onReceiveData(begin, chunk) {
var end = begin + chunk.byteLength;
assert(begin % this.chunkSize === 0, 'Bad begin offset: ' + begin);
@ -78,11 +78,11 @@ var ChunkedStream = (function ChunkedStreamClosure() {
}
},
onReceiveInitialData: function (data) {
onReceiveInitialData: function ChunkedStream_onReceiveInitialData(data) {
this.bytes.set(data);
this.initialDataLength = data.length;
var endChunk = this.end === data.length ?
this.numChunks : Math.floor(data.length / this.chunkSize);
var endChunk = (this.end === data.length ?
this.numChunks : Math.floor(data.length / this.chunkSize));
for (var i = 0; i < endChunk; i++) {
this.loadedChunks[i] = true;
++this.numChunksLoaded;
@ -167,8 +167,9 @@ var ChunkedStream = (function ChunkedStreamClosure() {
}
var end = pos + length;
if (end > strEnd)
if (end > strEnd) {
end = strEnd;
}
this.ensureRange(pos, end);
this.pos = end;
@ -187,8 +188,9 @@ var ChunkedStream = (function ChunkedStreamClosure() {
},
skip: function ChunkedStream_skip(n) {
if (!n)
if (!n) {
n = 1;
}
this.pos += n;
},
@ -406,13 +408,13 @@ var ChunkedStreamManager = (function ChunkedStreamManagerClosure() {
}
if (prevChunk >= 0 && prevChunk + 1 !== chunk) {
groupedChunks.push({
beginChunk: beginChunk, endChunk: prevChunk + 1});
groupedChunks.push({ beginChunk: beginChunk,
endChunk: prevChunk + 1 });
beginChunk = chunk;
}
if (i + 1 === chunks.length) {
groupedChunks.push({
beginChunk: beginChunk, endChunk: chunk + 1});
groupedChunks.push({ beginChunk: beginChunk,
endChunk: chunk + 1 });
}
prevChunk = chunk;
@ -421,8 +423,8 @@ var ChunkedStreamManager = (function ChunkedStreamManagerClosure() {
},
onProgress: function ChunkedStreamManager_onProgress(args) {
var bytesLoaded = this.stream.numChunksLoaded * this.chunkSize +
args.loaded;
var bytesLoaded = (this.stream.numChunksLoaded * this.chunkSize +
args.loaded);
this.msgHandler.send('DocProgress', {
loaded: bytesLoaded,
total: this.length

View File

@ -128,8 +128,9 @@ var Page = (function PageClosure() {
var xref = this.xref;
var i, n = content.length;
var streams = [];
for (i = 0; i < n; ++i)
for (i = 0; i < n; ++i) {
streams.push(xref.fetchIfRef(content[i]));
}
stream = new StreamsSequenceStream(streams);
} else if (isStream(content)) {
stream = content;
@ -181,17 +182,16 @@ var Page = (function PageClosure() {
// Properties
]);
var partialEvaluator = new PartialEvaluator(
pdfManager, this.xref, handler,
this.pageIndex, 'p' + this.pageIndex + '_',
this.idCounters, this.fontCache);
var partialEvaluator = new PartialEvaluator(pdfManager, this.xref,
handler, this.pageIndex,
'p' + this.pageIndex + '_',
this.idCounters,
this.fontCache);
var dataPromises = Promise.all(
[contentStreamPromise, resourcesPromise], reject);
var dataPromises = Promise.all([contentStreamPromise, resourcesPromise],
reject);
dataPromises.then(function(data) {
var contentStream = data[0];
var opList = new OperatorList(intent, handler, self.pageIndex);
handler.send('StartRenderPage', {
@ -249,10 +249,11 @@ var Page = (function PageClosure() {
resourcesPromise]);
dataPromises.then(function(data) {
var contentStream = data[0];
var partialEvaluator = new PartialEvaluator(
pdfManager, self.xref, handler,
self.pageIndex, 'p' + self.pageIndex + '_',
self.idCounters, self.fontCache);
var partialEvaluator = new PartialEvaluator(pdfManager, self.xref,
handler, self.pageIndex,
'p' + self.pageIndex + '_',
self.idCounters,
self.fontCache);
var bidiTexts = partialEvaluator.getTextContent(contentStream,
self.resources);
@ -273,7 +274,7 @@ var Page = (function PageClosure() {
get annotations() {
var annotations = [];
var annotationRefs = this.annotationRefs || [];
var annotationRefs = (this.annotationRefs || []);
for (var i = 0, n = annotationRefs.length; i < n; ++i) {
var annotationRef = annotationRefs[i];
var annotation = Annotation.fromRef(this.xref, annotationRef);
@ -297,13 +298,14 @@ var Page = (function PageClosure() {
*/
var PDFDocument = (function PDFDocumentClosure() {
function PDFDocument(pdfManager, arg, password) {
if (isStream(arg))
if (isStream(arg)) {
init.call(this, pdfManager, arg, password);
else if (isArrayBuffer(arg))
} else if (isArrayBuffer(arg)) {
init.call(this, pdfManager, new Stream(arg), password);
else
} else {
error('PDFDocument: Unknown argument type');
}
}
function init(pdfManager, stream, password) {
assertWellFormed(stream.length > 0, 'stream must have data');
@ -317,16 +319,18 @@ var PDFDocument = (function PDFDocumentClosure() {
var pos = stream.pos;
var end = stream.end;
var strBuf = [];
if (pos + limit > end)
if (pos + limit > end) {
limit = end - pos;
}
for (var n = 0; n < limit; ++n) {
strBuf.push(String.fromCharCode(stream.getByte()));
}
var str = strBuf.join('');
stream.pos = pos;
var index = backwards ? str.lastIndexOf(needle) : str.indexOf(needle);
if (index == -1)
if (index == -1) {
return false; /* not found */
}
stream.pos += index;
return true; /* found */
}
@ -399,16 +403,18 @@ var PDFDocument = (function PDFDocumentClosure() {
if (linearization) {
// Find end of first obj.
stream.reset();
if (find(stream, 'endobj', 1024))
if (find(stream, 'endobj', 1024)) {
startXRef = stream.pos + 6;
}
} else {
// Find startxref by jumping backward from the end of the file.
var step = 1024;
var found = false, pos = stream.end;
while (!found && pos > 0) {
pos -= step - 'startxref'.length;
if (pos < 0)
if (pos < 0) {
pos = 0;
}
stream.pos = pos;
found = find(stream, 'startxref', step, true);
}
@ -424,18 +430,20 @@ var PDFDocument = (function PDFDocumentClosure() {
ch = stream.getByte();
}
startXRef = parseInt(str, 10);
if (isNaN(startXRef))
if (isNaN(startXRef)) {
startXRef = 0;
}
}
}
// shadow the prototype getter with a data property
return shadow(this, 'startXRef', startXRef);
},
get mainXRefEntriesOffset() {
var mainXRefEntriesOffset = 0;
var linearization = this.linearization;
if (linearization)
if (linearization) {
mainXRefEntriesOffset = linearization.mainXRefEntriesOffset;
}
// shadow the prototype getter with a data property
return shadow(this, 'mainXRefEntriesOffset', mainXRefEntriesOffset);
},
@ -496,8 +504,8 @@ var PDFDocument = (function PDFDocumentClosure() {
var value = infoDict.get(key);
// Make sure the value conforms to the spec.
if (validEntries[key](value)) {
docInfo[key] = typeof value !== 'string' ? value :
stringToPDFString(value);
docInfo[key] = (typeof value !== 'string' ?
value : stringToPDFString(value));
} else {
info('Bad value in document info for "' + key + '"');
}

View File

@ -29,8 +29,8 @@ var FontRendererFactory = (function FontRendererFactoryClosure() {
}
function parseCmap(data, start, end) {
var offset = getUshort(data, start + 2) === 1 ? getLong(data, start + 8) :
getLong(data, start + 16);
var offset = (getUshort(data, start + 2) === 1 ?
getLong(data, start + 8) : getLong(data, start + 16));
var format = getUshort(data, start + offset);
if (format === 4) {
var length = getUshort(data, start + offset + 2);
@ -79,13 +79,13 @@ var FontRendererFactory = (function FontRendererFactoryClosure() {
function parseCff(data, start, end) {
var properties = {};
var parser = new CFFParser(
new Stream(data, start, end - start), properties);
var parser = new CFFParser(new Stream(data, start, end - start),
properties);
var cff = parser.parse();
return {
glyphs: cff.charStrings.objects,
subrs: cff.topDict.privateDict && cff.topDict.privateDict.subrsIndex &&
cff.topDict.privateDict.subrsIndex.objects,
subrs: (cff.topDict.privateDict && cff.topDict.privateDict.subrsIndex &&
cff.topDict.privateDict.subrsIndex.objects),
gsubrs: cff.globalSubrIndex && cff.globalSubrIndex.objects
};
}
@ -413,10 +413,11 @@ var FontRendererFactory = (function FontRendererFactoryClosure() {
var xa = x + stack.shift(), ya = y + stack.shift();
var xb = xa + stack.shift(), yb = ya + stack.shift();
x = xb; y = yb;
if (Math.abs(x - x0) > Math.abs(y - y0))
if (Math.abs(x - x0) > Math.abs(y - y0)) {
x += stack.shift();
else
} else {
y += stack.shift();
}
bezierCurveTo(xa, ya, xb, yb, x, y);
break;
default:
@ -562,15 +563,16 @@ var FontRendererFactory = (function FontRendererFactoryClosure() {
}
break;
default:
if (v < 32)
if (v < 32) {
error('unknown operator: ' + v);
if (v < 247)
}
if (v < 247) {
stack.push(v - 139);
else if (v < 251)
} else if (v < 251) {
stack.push((v - 247) * 256 + code[i++] + 108);
else if (v < 255)
} else if (v < 255) {
stack.push(-(v - 251) * 256 - code[i++] - 108);
else {
} else {
stack.push(((code[i] << 24) | (code[i + 1] << 16) |
(code[i + 2] << 8) | code[i + 3]) / 65536);
i += 4;
@ -654,10 +656,10 @@ var FontRendererFactory = (function FontRendererFactoryClosure() {
this.glyphNameMap = glyphNameMap || GlyphsUnicode;
this.compiledGlyphs = [];
this.gsubrsBias = this.gsubrs.length < 1240 ? 107 :
this.gsubrs.length < 33900 ? 1131 : 32768;
this.subrsBias = this.subrs.length < 1240 ? 107 :
this.subrs.length < 33900 ? 1131 : 32768;
this.gsubrsBias = (this.gsubrs.length < 1240 ?
107 : (this.gsubrs.length < 33900 ? 1131 : 32768));
this.subrsBias = (this.subrs.length < 1240 ?
107 : (this.subrs.length < 33900 ? 1131 : 32768));
}
Util.inherit(Type2Compiled, CompiledFont, {
@ -697,8 +699,8 @@ var FontRendererFactory = (function FontRendererFactoryClosure() {
}
if (glyf) {
var fontMatrix = !unitsPerEm ? font.fontMatrix :
[1 / unitsPerEm, 0, 0, 1 / unitsPerEm, 0, 0];
var fontMatrix = (!unitsPerEm ? font.fontMatrix :
[1 / unitsPerEm, 0, 0, 1 / unitsPerEm, 0, 0]);
return new TrueTypeCompiled(
parseGlyfTable(glyf, loca, indexToLocFormat), cmap, fontMatrix);
} else {

View File

@ -21,8 +21,8 @@
var Stream = (function StreamClosure() {
function Stream(arrayBuffer, start, length, dict) {
this.bytes = arrayBuffer instanceof Uint8Array ? arrayBuffer :
new Uint8Array(arrayBuffer);
this.bytes = (arrayBuffer instanceof Uint8Array ?
arrayBuffer : new Uint8Array(arrayBuffer));
this.start = start || 0;
this.pos = this.start;
this.end = (start + length) || this.bytes.length;
@ -36,8 +36,9 @@ var Stream = (function StreamClosure() {
return this.end - this.start;
},
getByte: function Stream_getByte() {
if (this.pos >= this.end)
if (this.pos >= this.end) {
return -1;
}
return this.bytes[this.pos++];
},
getUint16: function Stream_getUint16() {
@ -59,13 +60,13 @@ var Stream = (function StreamClosure() {
var pos = this.pos;
var strEnd = this.end;
if (!length)
if (!length) {
return bytes.subarray(pos, strEnd);
}
var end = pos + length;
if (end > strEnd)
if (end > strEnd) {
end = strEnd;
}
this.pos = end;
return bytes.subarray(pos, end);
},
@ -75,8 +76,9 @@ var Stream = (function StreamClosure() {
return bytes;
},
skip: function Stream_skip(n) {
if (!n)
if (!n) {
n = 1;
}
this.pos += n;
},
reset: function Stream_reset() {
@ -98,8 +100,9 @@ var StringStream = (function StringStreamClosure() {
function StringStream(str) {
var length = str.length;
var bytes = new Uint8Array(length);
for (var n = 0; n < length; ++n)
for (var n = 0; n < length; ++n) {
bytes[n] = str.charCodeAt(n);
}
Stream.call(this, bytes);
}
@ -149,8 +152,9 @@ var DecodeStream = (function DecodeStreamClosure() {
getByte: function DecodeStream_getByte() {
var pos = this.pos;
while (this.bufferLength <= pos) {
if (this.eof)
if (this.eof) {
return -1;
}
this.readBlock();
}
return this.buffer[this.pos++];
@ -174,23 +178,25 @@ var DecodeStream = (function DecodeStreamClosure() {
this.ensureBuffer(pos + length);
end = pos + length;
while (!this.eof && this.bufferLength < end)
while (!this.eof && this.bufferLength < end) {
this.readBlock();
}
var bufEnd = this.bufferLength;
if (end > bufEnd)
if (end > bufEnd) {
end = bufEnd;
}
} else {
while (!this.eof)
while (!this.eof) {
this.readBlock();
}
end = this.bufferLength;
// checking if bufferLength is still 0 then
// the buffer has to be initialized
if (!end)
if (!end) {
this.buffer = new Uint8Array(0);
}
}
this.pos = end;
return this.buffer.subarray(pos, end);
@ -202,13 +208,15 @@ var DecodeStream = (function DecodeStreamClosure() {
},
makeSubStream: function DecodeStream_makeSubStream(start, length, dict) {
var end = start + length;
while (this.bufferLength <= end && !this.eof)
while (this.bufferLength <= end && !this.eof) {
this.readBlock();
}
return new Stream(this.buffer, start, length, dict);
},
skip: function Stream_skip(n) {
if (!n)
if (!n) {
n = 1;
}
this.pos += n;
},
reset: function DecodeStream_reset() {
@ -365,14 +373,18 @@ var FlateStream = (function FlateStreamClosure() {
var cmf = str.getByte();
var flg = str.getByte();
if (cmf == -1 || flg == -1)
if (cmf == -1 || flg == -1) {
error('Invalid header in flate stream: ' + cmf + ', ' + flg);
if ((cmf & 0x0f) != 0x08)
}
if ((cmf & 0x0f) != 0x08) {
error('Unknown compression method in flate stream: ' + cmf + ', ' + flg);
if ((((cmf << 8) + flg) % 31) !== 0)
}
if ((((cmf << 8) + flg) % 31) !== 0) {
error('Bad FCHECK in flate stream: ' + cmf + ', ' + flg);
if (flg & 0x20)
}
if (flg & 0x20) {
error('FDICT bit set in flate stream: ' + cmf + ', ' + flg);
}
this.codeSize = 0;
this.codeBuf = 0;
@ -420,8 +432,9 @@ var FlateStream = (function FlateStreamClosure() {
var code = codes[codeBuf & ((1 << maxLen) - 1)];
var codeLen = code >> 16;
var codeVal = code & 0xffff;
if (codeSize === 0 || codeSize < codeLen || codeLen === 0)
if (codeSize === 0 || codeSize < codeLen || codeLen === 0) {
error('Bad encoding in flate stream');
}
this.codeBuf = (codeBuf >> codeLen);
this.codeSize = (codeSize - codeLen);
return codeVal;
@ -434,9 +447,10 @@ var FlateStream = (function FlateStreamClosure() {
// find max code length
var maxLen = 0;
for (var i = 0; i < n; ++i) {
if (lengths[i] > maxLen)
if (lengths[i] > maxLen) {
maxLen = lengths[i];
}
}
// build the table
var size = 1 << maxLen;
@ -455,9 +469,9 @@ var FlateStream = (function FlateStreamClosure() {
}
// fill the table entries
for (var i = code2; i < size; i += skip)
for (var i = code2; i < size; i += skip) {
codes[i] = (len << 16) | val;
}
++code;
}
}
@ -470,8 +484,9 @@ var FlateStream = (function FlateStreamClosure() {
var str = this.str;
// read block header
var hdr = this.getBits(3);
if (hdr & 1)
if (hdr & 1) {
this.eof = true;
}
hdr >>= 1;
if (hdr === 0) { // uncompressed block
@ -535,8 +550,9 @@ var FlateStream = (function FlateStreamClosure() {
// build the code lengths code table
var codeLenCodeLengths = new Uint8Array(codeLenCodeMap.length);
for (var i = 0; i < numCodeLenCodes; ++i)
for (var i = 0; i < numCodeLenCodes; ++i) {
codeLenCodeLengths[codeLenCodeMap[i]] = this.getBits(3);
}
var codeLenCodeTab = this.generateHuffmanTable(codeLenCodeLengths);
// build the literal and distance code tables
@ -558,9 +574,10 @@ var FlateStream = (function FlateStreamClosure() {
}
var repeatLength = this.getBits(bitsLength) + bitsOffset;
while (repeatLength-- > 0)
while (repeatLength-- > 0) {
codeLengths[i++] = what;
}
}
litCodeTable =
this.generateHuffmanTable(codeLengths.subarray(0, numLitCodes));
@ -590,22 +607,25 @@ var FlateStream = (function FlateStreamClosure() {
code1 -= 257;
code1 = lengthDecode[code1];
var code2 = code1 >> 16;
if (code2 > 0)
if (code2 > 0) {
code2 = this.getBits(code2);
}
var len = (code1 & 0xffff) + code2;
code1 = this.getCode(distCodeTable);
code1 = distDecode[code1];
code2 = code1 >> 16;
if (code2 > 0)
if (code2 > 0) {
code2 = this.getBits(code2);
}
var dist = (code1 & 0xffff) + code2;
if (pos + len >= limit) {
buffer = this.ensureBuffer(pos + len);
limit = buffer.length;
}
for (var k = 0; k < len; ++k, ++pos)
for (var k = 0; k < len; ++k, ++pos) {
buffer[pos] = buffer[pos - dist];
}
}
};
return FlateStream;
@ -615,15 +635,18 @@ var PredictorStream = (function PredictorStreamClosure() {
function PredictorStream(str, maybeLength, params) {
var predictor = this.predictor = params.get('Predictor') || 1;
if (predictor <= 1)
if (predictor <= 1) {
return str; // no prediction
if (predictor !== 2 && (predictor < 10 || predictor > 15))
}
if (predictor !== 2 && (predictor < 10 || predictor > 15)) {
error('Unsupported predictor: ' + predictor);
}
if (predictor === 2)
if (predictor === 2) {
this.readBlock = this.readBlockTiff;
else
} else {
this.readBlock = this.readBlockPng;
}
this.str = str;
this.dict = str.dict;
@ -672,8 +695,9 @@ var PredictorStream = (function PredictorStreamClosure() {
inbuf &= 0xFFFF;
}
} else if (bits === 8) {
for (var i = 0; i < colors; ++i)
for (var i = 0; i < colors; ++i) {
buffer[pos++] = rawBytes[i];
}
for (; i < rowBytes; ++i) {
buffer[pos] = buffer[pos - colors] + rawBytes[i];
pos++;
@ -725,30 +749,35 @@ var PredictorStream = (function PredictorStreamClosure() {
var buffer = this.ensureBuffer(bufferLength + rowBytes);
var prevRow = buffer.subarray(bufferLength - rowBytes, bufferLength);
if (prevRow.length === 0)
if (prevRow.length === 0) {
prevRow = new Uint8Array(rowBytes);
}
var j = bufferLength;
switch (predictor) {
case 0:
for (var i = 0; i < rowBytes; ++i)
for (var i = 0; i < rowBytes; ++i) {
buffer[j++] = rawBytes[i];
}
break;
case 1:
for (var i = 0; i < pixBytes; ++i)
for (var i = 0; i < pixBytes; ++i) {
buffer[j++] = rawBytes[i];
}
for (; i < rowBytes; ++i) {
buffer[j] = (buffer[j - pixBytes] + rawBytes[i]) & 0xFF;
j++;
}
break;
case 2:
for (var i = 0; i < rowBytes; ++i)
for (var i = 0; i < rowBytes; ++i) {
buffer[j++] = (prevRow[i] + rawBytes[i]) & 0xFF;
}
break;
case 3:
for (var i = 0; i < pixBytes; ++i)
for (var i = 0; i < pixBytes; ++i) {
buffer[j++] = (prevRow[i] >> 1) + rawBytes[i];
}
for (; i < rowBytes; ++i) {
buffer[j] = (((prevRow[i] + buffer[j - pixBytes]) >> 1) +
rawBytes[i]) & 0xFF;
@ -770,23 +799,27 @@ var PredictorStream = (function PredictorStreamClosure() {
var p = left + up - upLeft;
var pa = p - left;
if (pa < 0)
if (pa < 0) {
pa = -pa;
}
var pb = p - up;
if (pb < 0)
if (pb < 0) {
pb = -pb;
}
var pc = p - upLeft;
if (pc < 0)
if (pc < 0) {
pc = -pc;
}
var c = rawBytes[i];
if (pa <= pb && pa <= pc)
if (pa <= pb && pa <= pc) {
buffer[j++] = left + c;
else if (pb <= pc)
} else if (pb <= pc) {
buffer[j++] = up + c;
else
} else {
buffer[j++] = upLeft + c;
}
}
break;
default:
error('Unsupported predictor: ' + predictor);
@ -826,12 +859,14 @@ var JpegStream = (function JpegStreamClosure() {
});
JpegStream.prototype.ensureBuffer = function JpegStream_ensureBuffer(req) {
if (this.bufferLength)
if (this.bufferLength) {
return;
}
try {
var jpegImage = new JpegImage();
if (this.colorTransform != -1)
if (this.colorTransform != -1) {
jpegImage.colorTransform = this.colorTransform;
}
jpegImage.parse(this.bytes);
var width = jpegImage.width;
var height = jpegImage.height;
@ -892,8 +927,9 @@ var JpxStream = (function JpxStreamClosure() {
});
JpxStream.prototype.ensureBuffer = function JpxStream_ensureBuffer(req) {
if (this.bufferLength)
if (this.bufferLength) {
return;
}
var jpxImage = new JpxImage();
jpxImage.parse(this.bytes);
@ -901,8 +937,9 @@ var JpxStream = (function JpxStreamClosure() {
var width = jpxImage.width;
var height = jpxImage.height;
var componentsCount = jpxImage.componentsCount;
if (componentsCount != 1 && componentsCount != 3 && componentsCount != 4)
if (componentsCount != 1 && componentsCount != 3 && componentsCount != 4) {
error('JPX with ' + componentsCount + ' components is not supported');
}
var data = new Uint8Array(width * height * componentsCount);
@ -922,8 +959,9 @@ var JpxStream = (function JpxStreamClosure() {
rowFeed = width - tileWidth;
sourcePosition = 0;
for (var j = 0; j < tileHeight; j++) {
for (var i = 0; i < tileWidth; i++)
for (var i = 0; i < tileWidth; i++) {
data[dataPosition++] = data0[sourcePosition++];
}
dataPosition += rowFeed;
}
break;
@ -1000,8 +1038,9 @@ var Jbig2Stream = (function Jbig2StreamClosure() {
});
Jbig2Stream.prototype.ensureBuffer = function Jbig2Stream_ensureBuffer(req) {
if (this.bufferLength)
if (this.bufferLength) {
return;
}
var jbig2Image = new Jbig2Image();
@ -1026,8 +1065,9 @@ var Jbig2Stream = (function Jbig2StreamClosure() {
var dataLength = data.length;
// JBIG2 had black as 1 and white as 0, inverting the colors
for (var i = 0; i < dataLength; i++)
for (var i = 0; i < dataLength; i++) {
data[i] ^= 0xFF;
}
this.buffer = data;
this.bufferLength = dataLength;
@ -1073,8 +1113,9 @@ var DecryptStream = (function DecryptStreamClosure() {
var bufferLength = this.bufferLength;
var i, n = chunk.length;
var buffer = this.ensureBuffer(bufferLength + n);
for (i = 0; i < n; i++)
for (i = 0; i < n; i++) {
buffer[bufferLength++] = chunk[i];
}
this.bufferLength = bufferLength;
};
@ -1119,8 +1160,9 @@ var Ascii85Stream = (function Ascii85StreamClosure() {
// special code for z
if (c == Z_LOWER_CHAR) {
buffer = this.ensureBuffer(bufferLength + 4);
for (var i = 0; i < 4; ++i)
for (var i = 0; i < 4; ++i) {
buffer[bufferLength + i] = 0;
}
this.bufferLength += 4;
} else {
var input = this.input;
@ -1133,21 +1175,24 @@ var Ascii85Stream = (function Ascii85StreamClosure() {
input[i] = c;
if (c === EOF || c == TILDA_CHAR)
if (c === EOF || c == TILDA_CHAR) {
break;
}
}
buffer = this.ensureBuffer(bufferLength + i - 1);
this.bufferLength += i - 1;
// partial ending;
if (i < 5) {
for (; i < 5; ++i)
for (; i < 5; ++i) {
input[i] = 0x21 + 84;
}
this.eof = true;
}
var t = 0;
for (var i = 0; i < 5; ++i)
for (var i = 0; i < 5; ++i) {
t = t * 85 + (input[i] - 0x21);
}
for (var i = 3; i >= 0; --i) {
buffer[bufferLength + i] = t & 0xFF;
@ -1257,9 +1302,10 @@ var RunLengthStream = (function RunLengthStreamClosure() {
n = 257 - n;
var b = repeatHeader[1];
var buffer = this.ensureBuffer(bufferLength + n + 1);
for (var i = 0; i < n; i++)
for (var i = 0; i < n; i++) {
buffer[bufferLength++] = b;
}
}
this.bufferLength = bufferLength;
};
@ -1706,8 +1752,9 @@ var CCITTFaxStream = (function CCITTFaxStreamClosure() {
this.columns = params.get('Columns') || 1728;
this.rows = params.get('Rows') || 0;
var eoblock = params.get('EndOfBlock');
if (eoblock === null || eoblock === undefined)
if (eoblock === null || eoblock === undefined) {
eoblock = true;
}
this.eoblock = eoblock;
this.black = params.get('BlackIs1') || false;
@ -1779,8 +1826,9 @@ var CCITTFaxStream = (function CCITTFaxStreamClosure() {
this.err = true;
a1 = this.columns;
}
if ((codingPos & 1) ^ blackPixels)
if ((codingPos & 1) ^ blackPixels) {
++codingPos;
}
codingLine[codingPos] = a1;
} else if (a1 < codingLine[codingPos]) {
@ -1789,8 +1837,9 @@ var CCITTFaxStream = (function CCITTFaxStreamClosure() {
this.err = true;
a1 = 0;
}
while (codingPos > 0 && a1 < codingLine[codingPos - 1])
while (codingPos > 0 && a1 < codingLine[codingPos - 1]) {
--codingPos;
}
codingLine[codingPos] = a1;
}
@ -1805,16 +1854,16 @@ var CCITTFaxStream = (function CCITTFaxStreamClosure() {
var refPos, blackPixels, bits;
if (this.outputBits === 0) {
if (this.eof)
if (this.eof) {
return null;
}
this.err = false;
var code1, code2, code3;
if (this.nextLine2D) {
for (var i = 0; codingLine[i] < columns; ++i)
for (var i = 0; codingLine[i] < columns; ++i) {
refLine[i] = codingLine[i];
}
refLine[i++] = columns;
refLine[i] = columns;
codingLine[0] = 0;
@ -1827,8 +1876,9 @@ var CCITTFaxStream = (function CCITTFaxStreamClosure() {
switch (code1) {
case twoDimPass:
this.addPixels(refLine[refPos + 1], blackPixels);
if (refLine[refPos + 1] < columns)
if (refLine[refPos + 1] < columns) {
refPos += 2;
}
break;
case twoDimHoriz:
code1 = code2 = 0;
@ -1864,9 +1914,10 @@ var CCITTFaxStream = (function CCITTFaxStreamClosure() {
if (codingLine[this.codingPos] < columns) {
++refPos;
while (refLine[refPos] <= codingLine[this.codingPos] &&
refLine[refPos] < columns)
refLine[refPos] < columns) {
refPos += 2;
}
}
break;
case twoDimVertR2:
this.addPixels(refLine[refPos] + 2, blackPixels);
@ -1885,9 +1936,10 @@ var CCITTFaxStream = (function CCITTFaxStreamClosure() {
if (codingLine[this.codingPos] < columns) {
++refPos;
while (refLine[refPos] <= codingLine[this.codingPos] &&
refLine[refPos] < columns)
refLine[refPos] < columns) {
refPos += 2;
}
}
break;
case twoDimVert0:
this.addPixels(refLine[refPos], blackPixels);
@ -1895,49 +1947,55 @@ var CCITTFaxStream = (function CCITTFaxStreamClosure() {
if (codingLine[this.codingPos] < columns) {
++refPos;
while (refLine[refPos] <= codingLine[this.codingPos] &&
refLine[refPos] < columns)
refLine[refPos] < columns) {
refPos += 2;
}
}
break;
case twoDimVertL3:
this.addPixelsNeg(refLine[refPos] - 3, blackPixels);
blackPixels ^= 1;
if (codingLine[this.codingPos] < columns) {
if (refPos > 0)
if (refPos > 0) {
--refPos;
else
} else {
++refPos;
}
while (refLine[refPos] <= codingLine[this.codingPos] &&
refLine[refPos] < columns)
refLine[refPos] < columns) {
refPos += 2;
}
}
break;
case twoDimVertL2:
this.addPixelsNeg(refLine[refPos] - 2, blackPixels);
blackPixels ^= 1;
if (codingLine[this.codingPos] < columns) {
if (refPos > 0)
if (refPos > 0) {
--refPos;
else
} else {
++refPos;
}
while (refLine[refPos] <= codingLine[this.codingPos] &&
refLine[refPos] < columns)
refLine[refPos] < columns) {
refPos += 2;
}
}
break;
case twoDimVertL1:
this.addPixelsNeg(refLine[refPos] - 1, blackPixels);
blackPixels ^= 1;
if (codingLine[this.codingPos] < columns) {
if (refPos > 0)
if (refPos > 0) {
--refPos;
else
} else {
++refPos;
}
while (refLine[refPos] <= codingLine[this.codingPos] &&
refLine[refPos] < columns)
refLine[refPos] < columns) {
refPos += 2;
}
}
break;
case EOF:
this.addPixels(columns, 0);
@ -1969,8 +2027,9 @@ var CCITTFaxStream = (function CCITTFaxStreamClosure() {
}
}
if (this.byteAlign)
if (this.byteAlign) {
this.inputBits &= ~7;
}
var gotEOL = false;
@ -2006,8 +2065,9 @@ var CCITTFaxStream = (function CCITTFaxStreamClosure() {
if (this.encoding >= 0) {
for (var i = 0; i < 4; ++i) {
code1 = this.lookBits(12);
if (code1 != 1)
if (code1 != 1) {
info('bad rtc code: ' + code1);
}
this.eatBits(12);
if (this.encoding > 0) {
this.lookBits(1);
@ -2036,10 +2096,11 @@ var CCITTFaxStream = (function CCITTFaxStreamClosure() {
}
}
if (codingLine[0] > 0)
if (codingLine[0] > 0) {
this.outputBits = codingLine[this.codingPos = 0];
else
} else {
this.outputBits = codingLine[this.codingPos = 1];
}
this.row++;
}
@ -2099,10 +2160,12 @@ var CCITTFaxStream = (function CCITTFaxStreamClosure() {
var limitValue = limit || 0;
for (var i = start; i <= end; ++i) {
var code = this.lookBits(i);
if (code == EOF)
if (code == EOF) {
return [true, 1, false];
if (i < end)
}
if (i < end) {
code <<= end - i;
}
if (!limitValue || code >= limitValue) {
var p = table[code - limitValue];
if (p[0] == i) {
@ -2128,9 +2191,10 @@ var CCITTFaxStream = (function CCITTFaxStreamClosure() {
}
} else {
var result = this.findTableCode(1, 7, twoDimTable);
if (result[0] && result[2])
if (result[0] && result[2]) {
return result[1];
}
}
info('Bad two dim code');
return EOF;
};
@ -2143,13 +2207,15 @@ var CCITTFaxStream = (function CCITTFaxStreamClosure() {
var n;
if (this.eoblock) {
code = this.lookBits(12);
if (code == EOF)
if (code == EOF) {
return 1;
}
if ((code >> 5) === 0)
if ((code >> 5) === 0) {
p = whiteTable1[code];
else
} else {
p = whiteTable2[code >> 3];
}
if (p[0] > 0) {
this.eatBits(p[0]);
@ -2157,13 +2223,15 @@ var CCITTFaxStream = (function CCITTFaxStreamClosure() {
}
} else {
var result = this.findTableCode(1, 9, whiteTable2);
if (result[0])
if (result[0]) {
return result[1];
}
result = this.findTableCode(11, 12, whiteTable1);
if (result[0])
if (result[0]) {
return result[1];
}
}
info('bad white code');
this.eatBits(1);
return 1;
@ -2175,14 +2243,16 @@ var CCITTFaxStream = (function CCITTFaxStreamClosure() {
var code, p;
if (this.eoblock) {
code = this.lookBits(13);
if (code == EOF)
if (code == EOF) {
return 1;
if ((code >> 7) === 0)
}
if ((code >> 7) === 0) {
p = blackTable1[code];
else if ((code >> 9) === 0 && (code >> 7) !== 0)
} else if ((code >> 9) === 0 && (code >> 7) !== 0) {
p = blackTable2[(code >> 1) - 64];
else
} else {
p = blackTable3[code >> 7];
}
if (p[0] > 0) {
this.eatBits(p[0]);
@ -2190,17 +2260,20 @@ var CCITTFaxStream = (function CCITTFaxStreamClosure() {
}
} else {
var result = this.findTableCode(2, 6, blackTable3);
if (result[0])
if (result[0]) {
return result[1];
}
result = this.findTableCode(7, 12, blackTable2, 64);
if (result[0])
if (result[0]) {
return result[1];
}
result = this.findTableCode(10, 13, blackTable1);
if (result[0])
if (result[0]) {
return result[1];
}
}
info('bad black code');
this.eatBits(1);
return 1;
@ -2210,8 +2283,9 @@ var CCITTFaxStream = (function CCITTFaxStreamClosure() {
var c;
while (this.inputBits < n) {
if ((c = this.str.getByte()) === -1) {
if (this.inputBits === 0)
if (this.inputBits === 0) {
return EOF;
}
return ((this.inputBuf << (n - this.inputBits)) &
(0xFFFF >> (16 - n)));
}
@ -2222,8 +2296,9 @@ var CCITTFaxStream = (function CCITTFaxStreamClosure() {
};
CCITTFaxStream.prototype.eatBits = function CCITTFaxStream_eatBits(n) {
if ((this.inputBits -= n) < 0)
if ((this.inputBits -= n) < 0) {
this.inputBits = 0;
}
};
return CCITTFaxStream;
@ -2282,8 +2357,9 @@ var LZWStream = (function LZWStreamClosure() {
var i, j, q;
var lzwState = this.lzwState;
if (!lzwState)
if (!lzwState) {
return; // eof was found
}
var earlyChange = lzwState.earlyChange;
var nextCode = lzwState.nextCode;
@ -2344,9 +2420,10 @@ var LZWStream = (function LZWStreamClosure() {
} while (estimatedDecodedSize < decodedLength);
buffer = this.ensureBuffer(this.bufferLength + estimatedDecodedSize);
}
for (j = 0; j < currentSequenceLength; j++)
for (j = 0; j < currentSequenceLength; j++) {
buffer[currentBufferLength++] = currentSequence[j];
}
}
lzwState.nextCode = nextCode;
lzwState.codeLength = codeLength;
lzwState.prevCode = prevCode;

View File

@ -39,8 +39,7 @@ var WorkerMessageHandler = PDFJS.WorkerMessageHandler = {
var javaScriptPromise = pdfManager.ensureCatalog('javaScript');
Promise.all([numPagesPromise, fingerprintPromise, outlinePromise,
infoPromise, metadataPromise, encryptedPromise,
javaScriptPromise]).then(
function onDocReady(results) {
javaScriptPromise]).then(function onDocReady(results) {
var doc = {
numPages: results[0],
@ -153,7 +152,7 @@ var WorkerMessageHandler = PDFJS.WorkerMessageHandler = {
onError: function onError(status) {
if (status == 404) {
var exception = new MissingPDFException( 'Missing PDF "' +
var exception = new MissingPDFException('Missing PDF "' +
source.url + '".');
handler.send('MissingPDF', { exception: exception });
} else {
@ -254,8 +253,7 @@ var WorkerMessageHandler = PDFJS.WorkerMessageHandler = {
if (ex instanceof PasswordException) {
// after password exception prepare to receive a new password
// to repeat loading
pdfManager.passwordChangedPromise =
new LegacyPromise();
pdfManager.passwordChangedPromise = new LegacyPromise();
pdfManager.passwordChangedPromise.then(pdfManagerReady);
}