Merge pull request #4577 from timvandermeij/reporter

Removes custom test/reporter.js from the lint process
This commit is contained in:
Yury Delendik 2014-04-10 19:17:48 -05:00
commit 2c61f60a4e
34 changed files with 761 additions and 707 deletions

17
make.js
View File

@ -317,7 +317,7 @@ target.bundle = function(args) {
} }
} }
var bundle = cat(SRC_FILES), var bundleContent = cat(SRC_FILES),
bundleVersion = VERSION, bundleVersion = VERSION,
bundleBuild = exec('git log --format="%h" -n 1', bundleBuild = exec('git log --format="%h" -n 1',
{silent: true}).output.replace('\n', ''); {silent: true}).output.replace('\n', '');
@ -325,15 +325,15 @@ target.bundle = function(args) {
crlfchecker.checkIfCrlfIsPresent(SRC_FILES); crlfchecker.checkIfCrlfIsPresent(SRC_FILES);
// Strip out all the vim/license headers. // Strip out all the vim/license headers.
bundle = bundle.replace(reg, ''); bundleContent = bundleContent.replace(reg, '');
// Append external files last since we don't want to modify them. // Append external files last since we don't want to modify them.
bundle += cat(EXT_SRC_FILES); bundleContent += cat(EXT_SRC_FILES);
// This just preprocesses the empty pdf.js file, we don't actually want to // This just preprocesses the empty pdf.js file, we don't actually want to
// preprocess everything yet since other build targets use this file. // preprocess everything yet since other build targets use this file.
builder.preprocess(filename, dir, builder.merge(defines, builder.preprocess(filename, dir, builder.merge(defines,
{BUNDLE: bundle, {BUNDLE: bundleContent,
BUNDLE_VERSION: bundleVersion, BUNDLE_VERSION: bundleVersion,
BUNDLE_BUILD: bundleBuild})); BUNDLE_BUILD: bundleBuild}));
} }
@ -1274,7 +1274,6 @@ target.lint = function() {
'web/', 'web/',
'test/downloadutils.js', 'test/downloadutils.js',
'test/driver.js', 'test/driver.js',
'test/reporter.js',
'test/test.js', 'test/test.js',
'test/testutils.js', 'test/testutils.js',
'test/webbrowser.js', 'test/webbrowser.js',
@ -1292,10 +1291,10 @@ target.lint = function() {
exec('npm install jshint@2.4.x'); // TODO read version from package.json exec('npm install jshint@2.4.x'); // TODO read version from package.json
} }
exit(exec('"' + jshintPath + '" --reporter test/reporter.js ' + var exitCode = exec('"' + jshintPath + '" ' + LINT_FILES.join(' ')).code;
LINT_FILES.join(' ')).code); if (exitCode === 0) {
echo('files checked, no errors found');
crlfchecker.checkIfCrlfIsPresent(LINT_FILES); }
}; };
// //

View File

@ -77,7 +77,6 @@ var bidi = PDFJS.bidi = (function bidiClosure() {
} }
function findUnequal(arr, start, value) { function findUnequal(arr, start, value) {
var j;
for (var j = start, jj = arr.length; j < jj; ++j) { for (var j = start, jj = arr.length; j < jj; ++j) {
if (arr[j] != value) { if (arr[j] != value) {
return j; return j;
@ -164,7 +163,8 @@ var bidi = PDFJS.bidi = (function bidiClosure() {
types.length = 0; types.length = 0;
var numBidi = 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); chars[i] = str.charAt(i);
var charCode = str.charCodeAt(i); var charCode = str.charCodeAt(i);
@ -204,7 +204,7 @@ var bidi = PDFJS.bidi = (function bidiClosure() {
} }
var levels = []; var levels = [];
for (var i = 0; i < strLength; ++i) { for (i = 0; i < strLength; ++i) {
levels[i] = startLevel; 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. start of the level run, it will get the type of sor.
*/ */
var lastType = sor; var lastType = sor;
for (var i = 0; i < strLength; ++i) { for (i = 0; i < strLength; ++i) {
if (types[i] == 'NSM') { if (types[i] == 'NSM') {
types[i] = lastType; types[i] = lastType;
} else { } 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 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. the type of the European number to Arabic number.
*/ */
var lastType = sor; lastType = sor;
for (var i = 0; i < strLength; ++i) { var t;
var t = types[i]; for (i = 0; i < strLength; ++i) {
t = types[i];
if (t == 'EN') { if (t == 'EN') {
types[i] = (lastType == 'AL') ? 'AN' : 'EN'; types[i] = (lastType == 'AL') ? 'AN' : 'EN';
} else if (t == 'R' || t == 'L' || t == 'AL') { } else if (t == 'R' || t == 'L' || t == 'AL') {
@ -247,8 +248,8 @@ var bidi = PDFJS.bidi = (function bidiClosure() {
/* /*
W3. Change all ALs to R. W3. Change all ALs to R.
*/ */
for (var i = 0; i < strLength; ++i) { for (i = 0; i < strLength; ++i) {
var t = types[i]; t = types[i];
if (t == 'AL') { if (t == 'AL') {
types[i] = 'R'; 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 European number. A single common separator between two numbers of the same
type changes to that type: 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') { if (types[i] == 'ES' && types[i - 1] == 'EN' && types[i + 1] == 'EN') {
types[i] = '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 W5. A sequence of European terminators adjacent to European numbers changes
to all European numbers: to all European numbers:
*/ */
for (var i = 0; i < strLength; ++i) { for (i = 0; i < strLength; ++i) {
if (types[i] == 'EN') { if (types[i] == 'EN') {
// do before // do before
for (var j = i - 1; j >= 0; --j) { var j;
for (j = i - 1; j >= 0; --j) {
if (types[j] != 'ET') { if (types[j] != 'ET') {
break; break;
} }
types[j] = 'EN'; types[j] = 'EN';
} }
// do after // do after
for (var j = i + 1; j < strLength; --j) { for (j = i + 1; j < strLength; --j) {
if (types[j] != 'ET') { if (types[j] != 'ET') {
break; break;
} }
@ -295,8 +297,8 @@ var bidi = PDFJS.bidi = (function bidiClosure() {
/* /*
W6. Otherwise, separators and terminators change to Other Neutral: W6. Otherwise, separators and terminators change to Other Neutral:
*/ */
for (var i = 0; i < strLength; ++i) { for (i = 0; i < strLength; ++i) {
var t = types[i]; t = types[i];
if (t == 'WS' || t == 'ES' || t == 'ET' || t == 'CS') { if (t == 'WS' || t == 'ES' || t == 'ET' || t == 'CS') {
types[i] = 'ON'; 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 first strong type (R, L, or sor) is found. If an L is found, then change
the type of the European number to L. the type of the European number to L.
*/ */
var lastType = sor; lastType = sor;
for (var i = 0; i < strLength; ++i) { for (i = 0; i < strLength; ++i) {
var t = types[i]; t = types[i];
if (t == 'EN') { if (t == 'EN') {
types[i] = ((lastType == 'L') ? 'L' : 'EN'); types[i] = ((lastType == 'L') ? 'L' : 'EN');
} else if (t == 'R' || t == 'L') { } 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 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. 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') { if (types[i] == 'ON') {
var end = findUnequal(types, i + 1, 'ON'); var end = findUnequal(types, i + 1, 'ON');
var before = sor; var before = sor;
@ -351,7 +353,7 @@ var bidi = PDFJS.bidi = (function bidiClosure() {
/* /*
N2. Any remaining neutrals take the embedding direction. 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') { if (types[i] == 'ON') {
types[i] = e; 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, I2. For all characters with an odd (right-to-left) embedding direction,
those of type L, EN or AN go up one level. those of type L, EN or AN go up one level.
*/ */
for (var i = 0; i < strLength; ++i) { for (i = 0; i < strLength; ++i) {
var t = types[i]; t = types[i];
if (isEven(levels[i])) { if (isEven(levels[i])) {
if (t == 'R') { if (t == 'R') {
levels[i] += 1; levels[i] += 1;
@ -401,8 +403,9 @@ var bidi = PDFJS.bidi = (function bidiClosure() {
// find highest level & lowest odd level // find highest level & lowest odd level
var highestLevel = -1; var highestLevel = -1;
var lowestOddLevel = 99; var lowestOddLevel = 99;
for (var i = 0, ii = levels.length; i < ii; ++i) { var level;
var level = levels[i]; for (i = 0, ii = levels.length; i < ii; ++i) {
level = levels[i];
if (highestLevel < level) { if (highestLevel < level) {
highestLevel = level; highestLevel = level;
} }
@ -412,10 +415,10 @@ var bidi = PDFJS.bidi = (function bidiClosure() {
} }
// now reverse between those limits // now reverse between those limits
for (var level = highestLevel; level >= lowestOddLevel; --level) { for (level = highestLevel; level >= lowestOddLevel; --level) {
// find segments to reverse // find segments to reverse
var start = -1; 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 (levels[i] < level) {
if (start >= 0) { if (start >= 0) {
reverseValues(chars, start, i); reverseValues(chars, start, i);
@ -449,7 +452,7 @@ var bidi = PDFJS.bidi = (function bidiClosure() {
// Finally, return string // Finally, return string
var result = ''; 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]; var ch = chars[i];
if (ch != '<' && ch != '>') { if (ch != '<' && ch != '>') {
result += ch; result += ch;

View File

@ -69,10 +69,11 @@ var ChunkedStream = (function ChunkedStreamClosure() {
var chunkSize = this.chunkSize; var chunkSize = this.chunkSize;
var beginChunk = Math.floor(begin / chunkSize); var beginChunk = Math.floor(begin / chunkSize);
var endChunk = Math.floor((end - 1) / chunkSize) + 1; var endChunk = Math.floor((end - 1) / chunkSize) + 1;
var curChunk;
for (var chunk = beginChunk; chunk < endChunk; ++chunk) { for (curChunk = beginChunk; curChunk < endChunk; ++curChunk) {
if (!(chunk in this.loadedChunks)) { if (!(curChunk in this.loadedChunks)) {
this.loadedChunks[chunk] = true; this.loadedChunks[curChunk] = true;
++this.numChunksLoaded; ++this.numChunksLoaded;
} }
} }
@ -109,13 +110,14 @@ var ChunkedStream = (function ChunkedStreamClosure() {
}, },
nextEmptyChunk: function ChunkedStream_nextEmptyChunk(beginChunk) { 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)) { if (!(chunk in this.loadedChunks)) {
return chunk; return chunk;
} }
} }
// Wrap around to beginning // Wrap around to beginning
for (var chunk = 0; chunk < beginChunk; ++chunk) { for (chunk = 0; chunk < beginChunk; ++chunk) {
if (!(chunk in this.loadedChunks)) { if (!(chunk in this.loadedChunks)) {
return chunk; return chunk;
} }
@ -314,8 +316,9 @@ var ChunkedStreamManager = (function ChunkedStreamManagerClosure() {
var requestId = this.currRequestId++; var requestId = this.currRequestId++;
var chunksNeeded; var chunksNeeded;
var i, ii;
this.chunksNeededByRequest[requestId] = chunksNeeded = {}; 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])) { if (!this.stream.hasChunk(chunks[i])) {
chunksNeeded[chunks[i]] = true; chunksNeeded[chunks[i]] = true;
} }
@ -346,7 +349,7 @@ var ChunkedStreamManager = (function ChunkedStreamManagerClosure() {
var groupedChunksToRequest = this.groupChunks(chunksToRequest); 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 groupedChunk = groupedChunksToRequest[i];
var begin = groupedChunk.beginChunk * this.chunkSize; var begin = groupedChunk.beginChunk * this.chunkSize;
var end = Math.min(groupedChunk.endChunk * this.chunkSize, this.length); var end = Math.min(groupedChunk.endChunk * this.chunkSize, this.length);
@ -445,14 +448,14 @@ var ChunkedStreamManager = (function ChunkedStreamManagerClosure() {
} }
var loadedRequests = []; 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 // The server might return more chunks than requested
var requestIds = this.requestsByChunk[chunk] || []; var requestIds = this.requestsByChunk[chunk] || [];
delete this.requestsByChunk[chunk]; delete this.requestsByChunk[chunk];
for (var i = 0; i < requestIds.length; ++i) { for (i = 0; i < requestIds.length; ++i) {
var requestId = requestIds[i]; requestId = requestIds[i];
var chunksNeeded = this.chunksNeededByRequest[requestId]; var chunksNeeded = this.chunksNeededByRequest[requestId];
if (chunk in chunksNeeded) { if (chunk in chunksNeeded) {
delete chunksNeeded[chunk]; delete chunksNeeded[chunk];
@ -486,8 +489,8 @@ var ChunkedStreamManager = (function ChunkedStreamManagerClosure() {
} }
} }
for (var i = 0; i < loadedRequests.length; ++i) { for (i = 0; i < loadedRequests.length; ++i) {
var requestId = loadedRequests[i]; requestId = loadedRequests[i];
var callback = this.callbacksByRequest[requestId]; var callback = this.callbacksByRequest[requestId];
delete this.callbacksByRequest[requestId]; delete this.callbacksByRequest[requestId];
if (callback) { if (callback) {

View File

@ -451,6 +451,7 @@ var BinaryCMapReader = (function BinaryCMapReaderClosure() {
var ucs2DataSize = 1; var ucs2DataSize = 1;
var subitemsCount = stream.readNumber(); var subitemsCount = stream.readNumber();
var i;
switch (type) { switch (type) {
case 0: // codespacerange case 0: // codespacerange
stream.readHex(start, dataSize); stream.readHex(start, dataSize);
@ -458,7 +459,7 @@ var BinaryCMapReader = (function BinaryCMapReaderClosure() {
addHex(end, start, dataSize); addHex(end, start, dataSize);
cMap.addCodespaceRange(dataSize + 1, hexToInt(start, dataSize), cMap.addCodespaceRange(dataSize + 1, hexToInt(start, dataSize),
hexToInt(end, dataSize)); hexToInt(end, dataSize));
for (var i = 1; i < subitemsCount; i++) { for (i = 1; i < subitemsCount; i++) {
incHex(end, dataSize); incHex(end, dataSize);
stream.readHexNumber(start, dataSize); stream.readHexNumber(start, dataSize);
addHex(start, end, dataSize); addHex(start, end, dataSize);
@ -474,7 +475,7 @@ var BinaryCMapReader = (function BinaryCMapReaderClosure() {
addHex(end, start, dataSize); addHex(end, start, dataSize);
code = stream.readNumber(); code = stream.readNumber();
// undefined range, skipping // undefined range, skipping
for (var i = 1; i < subitemsCount; i++) { for (i = 1; i < subitemsCount; i++) {
incHex(end, dataSize); incHex(end, dataSize);
stream.readHexNumber(start, dataSize); stream.readHexNumber(start, dataSize);
addHex(start, end, dataSize); addHex(start, end, dataSize);
@ -488,7 +489,7 @@ var BinaryCMapReader = (function BinaryCMapReaderClosure() {
stream.readHex(char, dataSize); stream.readHex(char, dataSize);
code = stream.readNumber(); code = stream.readNumber();
cMap.mapOne(hexToInt(char, dataSize), String.fromCharCode(code)); cMap.mapOne(hexToInt(char, dataSize), String.fromCharCode(code));
for (var i = 1; i < subitemsCount; i++) { for (i = 1; i < subitemsCount; i++) {
incHex(char, dataSize); incHex(char, dataSize);
if (!sequence) { if (!sequence) {
stream.readHexNumber(tmp, dataSize); stream.readHexNumber(tmp, dataSize);
@ -505,7 +506,7 @@ var BinaryCMapReader = (function BinaryCMapReaderClosure() {
code = stream.readNumber(); code = stream.readNumber();
cMap.mapRange(hexToInt(start, dataSize), hexToInt(end, dataSize), cMap.mapRange(hexToInt(start, dataSize), hexToInt(end, dataSize),
String.fromCharCode(code)); String.fromCharCode(code));
for (var i = 1; i < subitemsCount; i++) { for (i = 1; i < subitemsCount; i++) {
incHex(end, dataSize); incHex(end, dataSize);
if (!sequence) { if (!sequence) {
stream.readHexNumber(start, dataSize); stream.readHexNumber(start, dataSize);
@ -525,7 +526,7 @@ var BinaryCMapReader = (function BinaryCMapReaderClosure() {
stream.readHex(charCode, dataSize); stream.readHex(charCode, dataSize);
cMap.mapOne(hexToInt(char, ucs2DataSize), cMap.mapOne(hexToInt(char, ucs2DataSize),
hexToStr(charCode, dataSize)); hexToStr(charCode, dataSize));
for (var i = 1; i < subitemsCount; i++) { for (i = 1; i < subitemsCount; i++) {
incHex(char, ucs2DataSize); incHex(char, ucs2DataSize);
if (!sequence) { if (!sequence) {
stream.readHexNumber(tmp, ucs2DataSize); stream.readHexNumber(tmp, ucs2DataSize);
@ -546,7 +547,7 @@ var BinaryCMapReader = (function BinaryCMapReaderClosure() {
cMap.mapRange(hexToInt(start, ucs2DataSize), cMap.mapRange(hexToInt(start, ucs2DataSize),
hexToInt(end, ucs2DataSize), hexToInt(end, ucs2DataSize),
hexToStr(charCode, dataSize)); hexToStr(charCode, dataSize));
for (var i = 1; i < subitemsCount; i++) { for (i = 1; i < subitemsCount; i++) {
incHex(end, ucs2DataSize); incHex(end, ucs2DataSize);
if (!sequence) { if (!sequence) {
stream.readHexNumber(start, ucs2DataSize); stream.readHexNumber(start, ucs2DataSize);

View File

@ -505,7 +505,7 @@ var CipherTransformFactory = (function CipherTransformFactoryClosure() {
hashData[i++] = fileId[j]; hashData[i++] = fileId[j];
} }
cipher = new ARCFourCipher(encryptionKey); cipher = new ARCFourCipher(encryptionKey);
var checkData = cipher.encryptBlock(calculateMD5(hashData, 0, i)); checkData = cipher.encryptBlock(calculateMD5(hashData, 0, i));
n = encryptionKey.length; n = encryptionKey.length;
var derivedKey = new Uint8Array(n), k; var derivedKey = new Uint8Array(n), k;
for (j = 1; j <= 19; ++j) { for (j = 1; j <= 19; ++j) {

View File

@ -53,12 +53,13 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
var nodes = [resources]; var nodes = [resources];
while (nodes.length) { while (nodes.length) {
var key;
var node = nodes.shift(); var node = nodes.shift();
// First check the current resources for blend modes. // First check the current resources for blend modes.
var graphicStates = node.get('ExtGState'); var graphicStates = node.get('ExtGState');
if (isDict(graphicStates)) { if (isDict(graphicStates)) {
graphicStates = graphicStates.getAll(); graphicStates = graphicStates.getAll();
for (var key in graphicStates) { for (key in graphicStates) {
var graphicState = graphicStates[key]; var graphicState = graphicStates[key];
var bm = graphicState['BM']; var bm = graphicState['BM'];
if (isName(bm) && bm.name !== 'Normal') { if (isName(bm) && bm.name !== 'Normal') {
@ -72,7 +73,7 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
continue; continue;
} }
xObjects = xObjects.getAll(); xObjects = xObjects.getAll();
for (var key in xObjects) { for (key in xObjects) {
var xObject = xObjects[key]; var xObject = xObjects[key];
if (!isStream(xObject)) { if (!isStream(xObject)) {
continue; continue;
@ -144,6 +145,7 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
} }
var imageMask = (dict.get('ImageMask', 'IM') || false); var imageMask = (dict.get('ImageMask', 'IM') || false);
var imgData, args;
if (imageMask) { if (imageMask) {
// This depends on a tmpCanvas being filled with the // This depends on a tmpCanvas being filled with the
// current fillStyle, such that processing the pixel // current fillStyle, such that processing the pixel
@ -159,10 +161,10 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
var canTransfer = image instanceof DecodeStream; var canTransfer = image instanceof DecodeStream;
var inverseDecode = (!!decode && decode[0] > 0); var inverseDecode = (!!decode && decode[0] > 0);
var imgData = PDFImage.createMask(imgArray, width, height, imgData = PDFImage.createMask(imgArray, width, height,
canTransfer, inverseDecode); canTransfer, inverseDecode);
imgData.cached = true; imgData.cached = true;
var args = [imgData]; args = [imgData];
operatorList.addOp(OPS.paintImageMaskXObject, args); operatorList.addOp(OPS.paintImageMaskXObject, args);
if (cacheKey) { if (cacheKey) {
cache.key = cacheKey; cache.key = cacheKey;
@ -183,7 +185,7 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
inline, null, null); inline, null, null);
// We force the use of RGBA_32BPP images here, because we can't handle // We force the use of RGBA_32BPP images here, because we can't handle
// any other kind. // any other kind.
var imgData = imageObj.createImageData(/* forceRGBA = */ true); imgData = imageObj.createImageData(/* forceRGBA = */ true);
operatorList.addOp(OPS.paintInlineImageXObject, [imgData]); operatorList.addOp(OPS.paintInlineImageXObject, [imgData]);
return; return;
} }
@ -193,7 +195,7 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
var uniquePrefix = (this.uniquePrefix || ''); var uniquePrefix = (this.uniquePrefix || '');
var objId = 'img_' + uniquePrefix + (++this.idCounters.obj); var objId = 'img_' + uniquePrefix + (++this.idCounters.obj);
operatorList.addDependency(objId); operatorList.addDependency(objId);
var args = [objId, w, h]; args = [objId, w, h];
if (!softMask && !mask && image instanceof JpegStream && if (!softMask && !mask && image instanceof JpegStream &&
image.isNativelySupported(this.xref, resources)) { image.isNativelySupported(this.xref, resources)) {
@ -511,10 +513,11 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
var preprocessor = new EvaluatorPreprocessor(stream, xref, stateManager); var preprocessor = new EvaluatorPreprocessor(stream, xref, stateManager);
var promise = new LegacyPromise(); var promise = new LegacyPromise();
var operation; var operation, i, ii;
while ((operation = preprocessor.read())) { while ((operation = preprocessor.read())) {
var args = operation.args; var args = operation.args;
var fn = operation.fn; var fn = operation.fn;
var shading;
switch (fn) { switch (fn) {
case OPS.setStrokeColorN: case OPS.setStrokeColorN:
@ -537,10 +540,10 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
args = []; args = [];
continue; continue;
} else if (typeNum == SHADING_PATTERN) { } else if (typeNum == SHADING_PATTERN) {
var shading = dict.get('Shading'); shading = dict.get('Shading');
var matrix = dict.get('Matrix'); var matrix = dict.get('Matrix');
var pattern = Pattern.parseShading(shading, matrix, xref, pattern = Pattern.parseShading(shading, matrix, xref,
resources); resources);
args = pattern.getIR(); args = pattern.getIR();
} else { } else {
error('Unkown PatternType ' + typeNum); error('Unkown PatternType ' + typeNum);
@ -609,7 +612,7 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
case OPS.showSpacedText: case OPS.showSpacedText:
var arr = args[0]; var arr = args[0];
var arrLength = arr.length; var arrLength = arr.length;
for (var i = 0; i < arrLength; ++i) { for (i = 0; i < arrLength; ++i) {
if (isString(arr[i])) { if (isString(arr[i])) {
arr[i] = this.handleText(arr[i], stateManager.state); arr[i] = this.handleText(arr[i], stateManager.state);
} }
@ -635,7 +638,7 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
error('No shading resource found'); error('No shading resource found');
} }
var shading = shadingRes.get(args[0].name); shading = shadingRes.get(args[0].name);
if (!shading) { if (!shading) {
error('No shading object found'); error('No shading object found');
} }
@ -665,7 +668,7 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
// Some PDFs don't close all restores inside object/form. // Some PDFs don't close all restores inside object/form.
// Closing those for them. // 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, []); operatorList.addOp(OPS.restore, []);
} }
@ -874,17 +877,18 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
case OPS.showSpacedText: case OPS.showSpacedText:
var items = args[0]; var items = args[0];
var textChunk = newTextChunk(); var textChunk = newTextChunk();
var offset;
for (var j = 0, jj = items.length; j < jj; j++) { for (var j = 0, jj = items.length; j < jj; j++) {
if (typeof items[j] === 'string') { if (typeof items[j] === 'string') {
buildTextGeometry(items[j], textChunk); buildTextGeometry(items[j], textChunk);
} else { } else {
var val = items[j] / 1000; var val = items[j] / 1000;
if (!textState.font.vertical) { if (!textState.font.vertical) {
var offset = -val * textState.fontSize * textState.textHScale; offset = -val * textState.fontSize * textState.textHScale;
textState.translateTextMatrix(offset, 0); textState.translateTextMatrix(offset, 0);
textChunk.width += offset; textChunk.width += offset;
} else { } else {
var offset = -val * textState.fontSize; offset = -val * textState.fontSize;
textState.translateTextMatrix(0, offset); textState.translateTextMatrix(0, offset);
textChunk.height += 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. // differences to be merged in here not require us to hold on to it.
var differences = []; var differences = [];
var baseEncodingName = null; var baseEncodingName = null;
var encoding;
if (dict.has('Encoding')) { if (dict.has('Encoding')) {
var encoding = dict.get('Encoding'); encoding = dict.get('Encoding');
if (isDict(encoding)) { if (isDict(encoding)) {
baseEncodingName = encoding.get('BaseEncoding'); baseEncodingName = encoding.get('BaseEncoding');
baseEncodingName = (isName(baseEncodingName) ? baseEncodingName = (isName(baseEncodingName) ?
@ -1059,9 +1064,8 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
if (baseEncodingName) { if (baseEncodingName) {
properties.defaultEncoding = Encodings[baseEncodingName].slice(); properties.defaultEncoding = Encodings[baseEncodingName].slice();
} else { } else {
var encoding = (properties.type === 'TrueType' ? encoding = (properties.type === 'TrueType' ?
Encodings.WinAnsiEncoding : Encodings.WinAnsiEncoding : Encodings.StandardEncoding);
Encodings.StandardEncoding);
// The Symbolic attribute can be misused for regular fonts // The Symbolic attribute can be misused for regular fonts
// Heuristic: we have to check if the font is a standard one also // Heuristic: we have to check if the font is a standard one also
if (!!(properties.flags & FontFlags.Symbolic)) { if (!!(properties.flags & FontFlags.Symbolic)) {
@ -1130,21 +1134,22 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
var defaultWidth = 0; var defaultWidth = 0;
var glyphsVMetrics = []; var glyphsVMetrics = [];
var defaultVMetrics; var defaultVMetrics;
var i, ii, j, jj, start, code, widths;
if (properties.composite) { if (properties.composite) {
defaultWidth = dict.get('DW') || 1000; defaultWidth = dict.get('DW') || 1000;
var widths = dict.get('W'); widths = dict.get('W');
if (widths) { if (widths) {
for (var i = 0, ii = widths.length; i < ii; i++) { for (i = 0, ii = widths.length; i < ii; i++) {
var start = widths[i++]; start = widths[i++];
var code = xref.fetchIfRef(widths[i]); code = xref.fetchIfRef(widths[i]);
if (isArray(code)) { 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]; glyphsWidths[start++] = code[j];
} }
} else { } else {
var width = widths[++i]; var width = widths[++i];
for (var j = start; j <= code; j++) { for (j = start; j <= code; j++) {
glyphsWidths[j] = width; glyphsWidths[j] = width;
} }
} }
@ -1156,16 +1161,16 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
defaultVMetrics = [vmetrics[1], defaultWidth * 0.5, vmetrics[0]]; defaultVMetrics = [vmetrics[1], defaultWidth * 0.5, vmetrics[0]];
vmetrics = dict.get('W2'); vmetrics = dict.get('W2');
if (vmetrics) { if (vmetrics) {
for (var i = 0, ii = vmetrics.length; i < ii; i++) { for (i = 0, ii = vmetrics.length; i < ii; i++) {
var start = vmetrics[i++]; start = vmetrics[i++];
var code = xref.fetchIfRef(vmetrics[i]); code = xref.fetchIfRef(vmetrics[i]);
if (isArray(code)) { 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]]; glyphsVMetrics[start++] = [code[j++], code[j++], code[j]];
} }
} else { } else {
var vmetric = [vmetrics[++i], vmetrics[++i], vmetrics[++i]]; var vmetric = [vmetrics[++i], vmetrics[++i], vmetrics[++i]];
for (var j = start; j <= code; j++) { for (j = start; j <= code; j++) {
glyphsVMetrics[j] = vmetric; glyphsVMetrics[j] = vmetric;
} }
} }
@ -1174,10 +1179,10 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
} }
} else { } else {
var firstChar = properties.firstChar; var firstChar = properties.firstChar;
var widths = dict.get('Widths'); widths = dict.get('Widths');
if (widths) { if (widths) {
var j = firstChar; j = firstChar;
for (var i = 0, ii = widths.length; i < ii; i++) { for (i = 0, ii = widths.length; i < ii; i++) {
glyphsWidths[j++] = widths[i]; glyphsWidths[j++] = widths[i];
} }
defaultWidth = (parseFloat(descriptor.get('MissingWidth')) || 0); defaultWidth = (parseFloat(descriptor.get('MissingWidth')) || 0);
@ -1285,6 +1290,7 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
assertWellFormed(isName(type), 'invalid font Subtype'); assertWellFormed(isName(type), 'invalid font Subtype');
var composite = false; var composite = false;
var uint8array;
if (type.name == 'Type0') { if (type.name == 'Type0') {
// If font is a composite // If font is a composite
// - get the descendant font // - get the descendant font
@ -1314,7 +1320,7 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
var toUnicode = dict.get('ToUnicode') || baseDict.get('ToUnicode'); var toUnicode = dict.get('ToUnicode') || baseDict.get('ToUnicode');
if (isStream(toUnicode)) { if (isStream(toUnicode)) {
var stream = toUnicode.str || toUnicode; var stream = toUnicode.str || toUnicode;
var uint8array = stream.buffer ? uint8array = stream.buffer ?
new Uint8Array(stream.buffer.buffer, 0, stream.bufferLength) : new Uint8Array(stream.buffer.buffer, 0, stream.bufferLength) :
new Uint8Array(stream.bytes.buffer, new Uint8Array(stream.bytes.buffer,
stream.start, stream.end - stream.start); stream.start, stream.end - stream.start);
@ -1326,7 +1332,7 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
var widths = dict.get('Widths') || baseDict.get('Widths'); var widths = dict.get('Widths') || baseDict.get('Widths');
if (widths) { if (widths) {
var uint8array = new Uint8Array(new Uint32Array(widths).buffer); uint8array = new Uint8Array(new Uint32Array(widths).buffer);
hash.update(uint8array); hash.update(uint8array);
} }
} }
@ -1348,6 +1354,7 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
var descriptor = preEvaluatedFont.descriptor; var descriptor = preEvaluatedFont.descriptor;
var type = dict.get('Subtype'); var type = dict.get('Subtype');
var maxCharIndex = (composite ? 0xFFFF : 0xFF); var maxCharIndex = (composite ? 0xFFFF : 0xFF);
var properties;
if (!descriptor) { if (!descriptor) {
if (type.name == 'Type3') { if (type.name == 'Type3') {
@ -1376,7 +1383,7 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
(symbolsFonts[fontNameWoStyle] ? FontFlags.Symbolic : (symbolsFonts[fontNameWoStyle] ? FontFlags.Symbolic :
FontFlags.Nonsymbolic); FontFlags.Nonsymbolic);
var properties = { properties = {
type: type.name, type: type.name,
name: baseFontName, name: baseFontName,
widths: metrics.widths, widths: metrics.widths,
@ -1441,7 +1448,7 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
} }
} }
var properties = { properties = {
type: type.name, type: type.name,
name: fontName.name, name: fontName.name,
subtype: subtype, subtype: subtype,
@ -1683,7 +1690,7 @@ var EvalState = (function EvalStateClosure() {
return EvalState; return EvalState;
})(); })();
var EvaluatorPreprocessor = (function EvaluatorPreprocessor() { var EvaluatorPreprocessor = (function EvaluatorPreprocessorClosure() {
// Specifies properties for each command // Specifies properties for each command
// //
// If variableArgs === true: [0, `numArgs`] expected // If variableArgs === true: [0, `numArgs`] expected
@ -1937,7 +1944,8 @@ var QueueOptimizer = (function QueueOptimizerClosure() {
var maxX = 0; var maxX = 0;
var map = [], maxLineHeight = 0; var map = [], maxLineHeight = 0;
var currentX = IMAGE_PADDING, currentY = IMAGE_PADDING; 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 transform = argsArray[j + (q << 2) + 1];
var img = argsArray[j + (q << 2) + 2][0]; var img = argsArray[j + (q << 2) + 2][0];
if (currentX + img.width > MAX_WIDTH) { if (currentX + img.width > MAX_WIDTH) {
@ -1959,7 +1967,7 @@ var QueueOptimizer = (function QueueOptimizerClosure() {
var imgHeight = currentY + maxLineHeight + IMAGE_PADDING; var imgHeight = currentY + maxLineHeight + IMAGE_PADDING;
var imgData = new Uint8Array(imgWidth * imgHeight * 4); var imgData = new Uint8Array(imgWidth * imgHeight * 4);
var imgRowSize = imgWidth << 2; 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; var data = argsArray[j + (q << 2) + 2][0].data;
// copy image by lines and extends pixels into padding // copy image by lines and extends pixels into padding
var rowSize = map[q].w << 2; var rowSize = map[q].w << 2;
@ -2003,7 +2011,7 @@ var QueueOptimizer = (function QueueOptimizerClosure() {
var fnArray = context.fnArray, argsArray = context.argsArray; var fnArray = context.fnArray, argsArray = context.argsArray;
var j = context.currentOperation - 3, i = j + 4; 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++) {} for (; i < ii && fnArray[i - 4] === fnArray[i]; i++) {}
var count = (i - j) >> 2; var count = (i - j) >> 2;
@ -2014,12 +2022,13 @@ var QueueOptimizer = (function QueueOptimizerClosure() {
} }
var isSameImage = false; var isSameImage = false;
var transformArgs;
if (argsArray[j + 1][1] === 0 && argsArray[j + 1][2] === 0) { if (argsArray[j + 1][1] === 0 && argsArray[j + 1][2] === 0) {
i = j + 4; i = j + 4;
isSameImage = true; 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 prevTransformArgs = argsArray[i - 3];
var transformArgs = argsArray[i + 1]; transformArgs = argsArray[i + 1];
if (argsArray[i - 2][0] !== argsArray[i + 2][0] || if (argsArray[i - 2][0] !== argsArray[i + 2][0] ||
prevTransformArgs[0] !== transformArgs[0] || prevTransformArgs[0] !== transformArgs[0] ||
prevTransformArgs[1] !== transformArgs[1] || prevTransformArgs[1] !== transformArgs[1] ||
@ -2039,8 +2048,8 @@ var QueueOptimizer = (function QueueOptimizerClosure() {
count = Math.min(count, MAX_SAME_IMAGES_IN_MASKS_BLOCK); count = Math.min(count, MAX_SAME_IMAGES_IN_MASKS_BLOCK);
var positions = new Float32Array(count * 2); var positions = new Float32Array(count * 2);
i = j + 1; i = j + 1;
for (var q = 0; q < count; q++) { for (q = 0; q < count; q++) {
var transformArgs = argsArray[i]; transformArgs = argsArray[i];
positions[(q << 1)] = transformArgs[4]; positions[(q << 1)] = transformArgs[4];
positions[(q << 1) + 1] = transformArgs[5]; positions[(q << 1) + 1] = transformArgs[5];
i += 4; i += 4;
@ -2055,8 +2064,8 @@ var QueueOptimizer = (function QueueOptimizerClosure() {
} else { } else {
count = Math.min(count, MAX_IMAGES_IN_MASKS_BLOCK); count = Math.min(count, MAX_IMAGES_IN_MASKS_BLOCK);
var images = []; var images = [];
for (var q = 0; q < count; q++) { for (q = 0; q < count; q++) {
var transformArgs = argsArray[j + (q << 2) + 1]; transformArgs = argsArray[j + (q << 2) + 1];
var maskParams = argsArray[j + (q << 2) + 2][0]; var maskParams = argsArray[j + (q << 2) + 2][0];
images.push({ data: maskParams.data, width: maskParams.width, images.push({ data: maskParams.data, width: maskParams.width,
height: maskParams.height, height: maskParams.height,
@ -2083,6 +2092,7 @@ var QueueOptimizer = (function QueueOptimizerClosure() {
return; return;
} }
var ii = fnArray.length; var ii = fnArray.length;
var transformArgs;
for (; i + 3 < ii && fnArray[i - 4] === fnArray[i]; i += 4) { for (; i + 3 < ii && fnArray[i - 4] === fnArray[i]; i += 4) {
if (fnArray[i - 3] !== fnArray[i + 1] || if (fnArray[i - 3] !== fnArray[i + 1] ||
fnArray[i - 2] !== fnArray[i + 2] || fnArray[i - 2] !== fnArray[i + 2] ||
@ -2093,7 +2103,7 @@ var QueueOptimizer = (function QueueOptimizerClosure() {
break; // different image break; // different image
} }
var prevTransformArgs = argsArray[i - 3]; var prevTransformArgs = argsArray[i - 3];
var transformArgs = argsArray[i + 1]; transformArgs = argsArray[i + 1];
if (prevTransformArgs[0] !== transformArgs[0] || if (prevTransformArgs[0] !== transformArgs[0] ||
prevTransformArgs[1] !== transformArgs[1] || prevTransformArgs[1] !== transformArgs[1] ||
prevTransformArgs[2] !== transformArgs[2] || prevTransformArgs[2] !== transformArgs[2] ||
@ -2110,7 +2120,7 @@ var QueueOptimizer = (function QueueOptimizerClosure() {
var positions = new Float32Array(count * 2); var positions = new Float32Array(count * 2);
i = j + 1; i = j + 1;
for (var q = 0; q < count; q++) { for (var q = 0; q < count; q++) {
var transformArgs = argsArray[i]; transformArgs = argsArray[i];
positions[(q << 1)] = transformArgs[4]; positions[(q << 1)] = transformArgs[4];
positions[(q << 1) + 1] = transformArgs[5]; positions[(q << 1) + 1] = transformArgs[5];
i += 4; i += 4;

View File

@ -33,22 +33,23 @@ var FontRendererFactory = (function FontRendererFactoryClosure() {
var offset = (getUshort(data, start + 2) === 1 ? var offset = (getUshort(data, start + 2) === 1 ?
getLong(data, start + 8) : getLong(data, start + 16)); getLong(data, start + 8) : getLong(data, start + 16));
var format = getUshort(data, start + offset); var format = getUshort(data, start + offset);
var length, ranges, p, i;
if (format === 4) { 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 segCount = getUshort(data, start + offset + 6) >> 1;
var p = start + offset + 14; p = start + offset + 14;
var ranges = []; ranges = [];
for (var i = 0; i < segCount; i++, p += 2) { for (i = 0; i < segCount; i++, p += 2) {
ranges[i] = {end: getUshort(data, p)}; ranges[i] = {end: getUshort(data, p)};
} }
p += 2; 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); 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); 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); var idOffset = getUshort(data, p);
if (idOffset === 0) { if (idOffset === 0) {
continue; continue;
@ -61,11 +62,11 @@ var FontRendererFactory = (function FontRendererFactoryClosure() {
} }
return ranges; return ranges;
} else if (format === 12) { } 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 groups = getLong(data, start + offset + 12);
var p = start + offset + 16; p = start + offset + 16;
var ranges = []; ranges = [];
for (var i = 0; i < groups; i++) { for (i = 0; i < groups; i++) {
ranges.push({ ranges.push({
start: getLong(data, p), start: getLong(data, p),
end: getLong(data, p + 4), 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 yMin = ((code[i + 4] << 24) | (code[i + 5] << 16)) >> 16;
var xMax = ((code[i + 6] << 24) | (code[i + 7] << 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 yMax = ((code[i + 8] << 24) | (code[i + 9] << 16)) >> 16;
var flags;
var x = 0, y = 0;
i += 10; i += 10;
if (numberOfContours < 0) { if (numberOfContours < 0) {
// composite glyph // composite glyph
var x = 0, y = 0;
do { 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]; var glyphIndex = (code[i + 2] << 8) | code[i + 3];
i += 4; i += 4;
var arg1, arg2; var arg1, arg2;
@ -201,7 +203,8 @@ var FontRendererFactory = (function FontRendererFactoryClosure() {
} else { } else {
// simple glyph // simple glyph
var endPtsOfContours = []; 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]); endPtsOfContours.push((code[i] << 8) | code[i + 1]);
i += 2; i += 2;
} }
@ -210,7 +213,8 @@ var FontRendererFactory = (function FontRendererFactoryClosure() {
var numberOfPoints = endPtsOfContours[endPtsOfContours.length - 1] + 1; var numberOfPoints = endPtsOfContours[endPtsOfContours.length - 1] + 1;
var points = []; var points = [];
while (points.length < numberOfPoints) { while (points.length < numberOfPoints) {
var flags = code[i++], repeat = 1; flags = code[i++];
var repeat = 1;
if ((flags & 0x08)) { if ((flags & 0x08)) {
repeat += code[i++]; repeat += code[i++];
} }
@ -218,8 +222,7 @@ var FontRendererFactory = (function FontRendererFactoryClosure() {
points.push({flags: flags}); points.push({flags: flags});
} }
} }
var x = 0, y = 0; for (j = 0; j < numberOfPoints; j++) {
for (var j = 0; j < numberOfPoints; j++) {
switch (points[j].flags & 0x12) { switch (points[j].flags & 0x12) {
case 0x00: case 0x00:
x += ((code[i] << 24) | (code[i + 1] << 16)) >> 16; x += ((code[i] << 24) | (code[i + 1] << 16)) >> 16;
@ -234,7 +237,7 @@ var FontRendererFactory = (function FontRendererFactoryClosure() {
} }
points[j].x = x; points[j].x = x;
} }
for (var j = 0; j < numberOfPoints; j++) { for (j = 0; j < numberOfPoints; j++) {
switch (points[j].flags & 0x24) { switch (points[j].flags & 0x24) {
case 0x00: case 0x00:
y += ((code[i] << 24) | (code[i + 1] << 16)) >> 16; y += ((code[i] << 24) | (code[i + 1] << 16)) >> 16;
@ -251,7 +254,7 @@ var FontRendererFactory = (function FontRendererFactoryClosure() {
} }
var startPoint = 0; var startPoint = 0;
for (var i = 0; i < numberOfContours; i++) { for (i = 0; i < numberOfContours; i++) {
var endPoint = endPtsOfContours[i]; var endPoint = endPtsOfContours[i];
// contours might have implicit points, which is located in the middle // contours might have implicit points, which is located in the middle
// between two neighboring off-curve points // between two neighboring off-curve points
@ -272,7 +275,7 @@ var FontRendererFactory = (function FontRendererFactoryClosure() {
contour.push(p); contour.push(p);
} }
moveTo(contour[0].x, contour[0].y); 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)) { if ((contour[j].flags & 1)) {
lineTo(contour[j].x, contour[j].y); lineTo(contour[j].x, contour[j].y);
} else if ((contour[j + 1].flags & 1)){ } else if ((contour[j + 1].flags & 1)){
@ -311,6 +314,7 @@ var FontRendererFactory = (function FontRendererFactoryClosure() {
while (i < code.length) { while (i < code.length) {
var stackClean = false; var stackClean = false;
var v = code[i++]; var v = code[i++];
var xa, xb, ya, yb, y1, y2, y3, n, subrCode;
switch (v) { switch (v) {
case 1: // hstem case 1: // hstem
stems += stack.length >> 1; stems += stack.length >> 1;
@ -356,15 +360,15 @@ var FontRendererFactory = (function FontRendererFactoryClosure() {
break; break;
case 8: // rrcurveto case 8: // rrcurveto
while (stack.length > 0) { while (stack.length > 0) {
var xa = x + stack.shift(), ya = y + stack.shift(); xa = x + stack.shift(); ya = y + stack.shift();
var xb = xa + stack.shift(), yb = ya + stack.shift(); xb = xa + stack.shift(); yb = ya + stack.shift();
x = xb + stack.shift(); y = yb + stack.shift(); x = xb + stack.shift(); y = yb + stack.shift();
bezierCurveTo(xa, ya, xb, yb, x, y); bezierCurveTo(xa, ya, xb, yb, x, y);
} }
break; break;
case 10: // callsubr case 10: // callsubr
var n = stack.pop() + font.subrsBias; n = stack.pop() + font.subrsBias;
var subrCode = font.subrs[n]; subrCode = font.subrs[n];
if (subrCode) { if (subrCode) {
parse(subrCode); parse(subrCode);
} }
@ -375,44 +379,44 @@ var FontRendererFactory = (function FontRendererFactoryClosure() {
v = code[i++]; v = code[i++];
switch (v) { switch (v) {
case 34: // flex case 34: // flex
var xa = x + stack.shift(); xa = x + stack.shift();
var xb = xa + stack.shift(), y1 = y + stack.shift(); xb = xa + stack.shift(); y1 = y + stack.shift();
x = xb + stack.shift(); x = xb + stack.shift();
bezierCurveTo(xa, y, xb, y1, x, y1); bezierCurveTo(xa, y, xb, y1, x, y1);
var xa = x + stack.shift(); xa = x + stack.shift();
var xb = xa + stack.shift(); xb = xa + stack.shift();
x = xb + stack.shift(); x = xb + stack.shift();
bezierCurveTo(xa, y1, xb, y, x, y); bezierCurveTo(xa, y1, xb, y, x, y);
break; break;
case 35: // flex case 35: // flex
var xa = x + stack.shift(), ya = y + stack.shift(); xa = x + stack.shift(); ya = y + stack.shift();
var xb = xa + stack.shift(), yb = ya + stack.shift(); xb = xa + stack.shift(); yb = ya + stack.shift();
x = xb + stack.shift(); y = yb + stack.shift(); x = xb + stack.shift(); y = yb + stack.shift();
bezierCurveTo(xa, ya, xb, yb, x, y); bezierCurveTo(xa, ya, xb, yb, x, y);
var xa = x + stack.shift(), ya = y + stack.shift(); xa = x + stack.shift(); ya = y + stack.shift();
var xb = xa + stack.shift(), yb = ya + stack.shift(); xb = xa + stack.shift(); yb = ya + stack.shift();
x = xb + stack.shift(); y = yb + stack.shift(); x = xb + stack.shift(); y = yb + stack.shift();
bezierCurveTo(xa, ya, xb, yb, x, y); bezierCurveTo(xa, ya, xb, yb, x, y);
stack.pop(); // fd stack.pop(); // fd
break; break;
case 36: // hflex1 case 36: // hflex1
var xa = x + stack.shift(), y1 = y + stack.shift(); xa = x + stack.shift(); y1 = y + stack.shift();
var xb = xa + stack.shift(), y2 = y1 + stack.shift(); xb = xa + stack.shift(); y2 = y1 + stack.shift();
x = xb + stack.shift(); x = xb + stack.shift();
bezierCurveTo(xa, y1, xb, y2, x, y2); bezierCurveTo(xa, y1, xb, y2, x, y2);
var xa = x + stack.shift(); xa = x + stack.shift();
var xb = xa + stack.shift(), y3 = y2 + stack.shift(); xb = xa + stack.shift(); y3 = y2 + stack.shift();
x = xb + stack.shift(); x = xb + stack.shift();
bezierCurveTo(xa, y2, xb, y3, x, y); bezierCurveTo(xa, y2, xb, y3, x, y);
break; break;
case 37: // flex1 case 37: // flex1
var x0 = x, y0 = y; var x0 = x, y0 = y;
var xa = x + stack.shift(), ya = y + stack.shift(); xa = x + stack.shift(); ya = y + stack.shift();
var xb = xa + stack.shift(), yb = ya + stack.shift(); xb = xa + stack.shift(); yb = ya + stack.shift();
x = xb + stack.shift(); y = yb + stack.shift(); x = xb + stack.shift(); y = yb + stack.shift();
bezierCurveTo(xa, ya, xb, yb, x, y); bezierCurveTo(xa, ya, xb, yb, x, y);
var xa = x + stack.shift(), ya = y + stack.shift(); xa = x + stack.shift(); ya = y + stack.shift();
var xb = xa + stack.shift(), yb = ya + stack.shift(); xb = xa + stack.shift(); yb = ya + stack.shift();
x = xb; y = yb; 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(); x += stack.shift();
@ -474,8 +478,8 @@ var FontRendererFactory = (function FontRendererFactoryClosure() {
break; break;
case 24: // rcurveline case 24: // rcurveline
while (stack.length > 2) { while (stack.length > 2) {
var xa = x + stack.shift(), ya = y + stack.shift(); xa = x + stack.shift(); ya = y + stack.shift();
var xb = xa + stack.shift(), yb = ya + stack.shift(); xb = xa + stack.shift(); yb = ya + stack.shift();
x = xb + stack.shift(); y = yb + stack.shift(); x = xb + stack.shift(); y = yb + stack.shift();
bezierCurveTo(xa, ya, xb, yb, x, y); bezierCurveTo(xa, ya, xb, yb, x, y);
} }
@ -489,8 +493,8 @@ var FontRendererFactory = (function FontRendererFactoryClosure() {
y += stack.shift(); y += stack.shift();
lineTo(x, y); lineTo(x, y);
} }
var xa = x + stack.shift(), ya = y + stack.shift(); xa = x + stack.shift(); ya = y + stack.shift();
var xb = xa + stack.shift(), yb = ya + stack.shift(); xb = xa + stack.shift(); yb = ya + stack.shift();
x = xb + stack.shift(); y = yb + stack.shift(); x = xb + stack.shift(); y = yb + stack.shift();
bezierCurveTo(xa, ya, xb, yb, x, y); bezierCurveTo(xa, ya, xb, yb, x, y);
break; break;
@ -499,8 +503,8 @@ var FontRendererFactory = (function FontRendererFactoryClosure() {
x += stack.shift(); x += stack.shift();
} }
while (stack.length > 0) { while (stack.length > 0) {
var xa = x, ya = y + stack.shift(); xa = x; ya = y + stack.shift();
var xb = xa + stack.shift(), yb = ya + stack.shift(); xb = xa + stack.shift(); yb = ya + stack.shift();
x = xb; y = yb + stack.shift(); x = xb; y = yb + stack.shift();
bezierCurveTo(xa, ya, xb, yb, x, y); bezierCurveTo(xa, ya, xb, yb, x, y);
} }
@ -510,8 +514,8 @@ var FontRendererFactory = (function FontRendererFactoryClosure() {
y += stack.shift(); y += stack.shift();
} }
while (stack.length > 0) { while (stack.length > 0) {
var xa = x + stack.shift(), ya = y; xa = x + stack.shift(); ya = y;
var xb = xa + stack.shift(), yb = ya + stack.shift(); xb = xa + stack.shift(); yb = ya + stack.shift();
x = xb + stack.shift(); y = yb; x = xb + stack.shift(); y = yb;
bezierCurveTo(xa, ya, xb, yb, x, y); bezierCurveTo(xa, ya, xb, yb, x, y);
} }
@ -521,16 +525,16 @@ var FontRendererFactory = (function FontRendererFactoryClosure() {
i += 2; i += 2;
break; break;
case 29: // callgsubr case 29: // callgsubr
var n = stack.pop() + font.gsubrsBias; n = stack.pop() + font.gsubrsBias;
var subrCode = font.gsubrs[n]; subrCode = font.gsubrs[n];
if (subrCode) { if (subrCode) {
parse(subrCode); parse(subrCode);
} }
break; break;
case 30: // vhcurveto case 30: // vhcurveto
while (stack.length > 0) { while (stack.length > 0) {
var xa = x, ya = y + stack.shift(); xa = x; ya = y + stack.shift();
var xb = xa + stack.shift(), yb = ya + stack.shift(); xb = xa + stack.shift(); yb = ya + stack.shift();
x = xb + stack.shift(); x = xb + stack.shift();
y = yb + (stack.length === 1 ? stack.shift() : 0); y = yb + (stack.length === 1 ? stack.shift() : 0);
bezierCurveTo(xa, ya, xb, yb, x, y); bezierCurveTo(xa, ya, xb, yb, x, y);
@ -538,8 +542,8 @@ var FontRendererFactory = (function FontRendererFactoryClosure() {
break; break;
} }
var xa = x + stack.shift(), ya = y; xa = x + stack.shift(); ya = y;
var xb = xa + stack.shift(), yb = ya + stack.shift(); xb = xa + stack.shift(); yb = ya + stack.shift();
y = yb + stack.shift(); y = yb + stack.shift();
x = xb + (stack.length === 1 ? stack.shift() : 0); x = xb + (stack.length === 1 ? stack.shift() : 0);
bezierCurveTo(xa, ya, xb, yb, x, y); bezierCurveTo(xa, ya, xb, yb, x, y);
@ -547,8 +551,8 @@ var FontRendererFactory = (function FontRendererFactoryClosure() {
break; break;
case 31: // hvcurveto case 31: // hvcurveto
while (stack.length > 0) { while (stack.length > 0) {
var xa = x + stack.shift(), ya = y; xa = x + stack.shift(); ya = y;
var xb = xa + stack.shift(), yb = ya + stack.shift(); xb = xa + stack.shift(); yb = ya + stack.shift();
y = yb + stack.shift(); y = yb + stack.shift();
x = xb + (stack.length === 1 ? stack.shift() : 0); x = xb + (stack.length === 1 ? stack.shift() : 0);
bezierCurveTo(xa, ya, xb, yb, x, y); bezierCurveTo(xa, ya, xb, yb, x, y);
@ -556,8 +560,8 @@ var FontRendererFactory = (function FontRendererFactoryClosure() {
break; break;
} }
var xa = x, ya = y + stack.shift(); xa = x; ya = y + stack.shift();
var xb = xa + stack.shift(), yb = ya + stack.shift(); xb = xa + stack.shift(); yb = ya + stack.shift();
x = xb + stack.shift(); x = xb + stack.shift();
y = yb + (stack.length === 1 ? stack.shift() : 0); y = yb + (stack.length === 1 ? stack.shift() : 0);
bezierCurveTo(xa, ya, xb, yb, x, y); 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 decodeMap = this.decode;
var numComps = this.numComps; var numComps = this.numComps;
var decodeAddends, decodeCoefficients;
var decodeAddends = this.decodeAddends; var decodeAddends = this.decodeAddends;
var decodeCoefficients = this.decodeCoefficients; var decodeCoefficients = this.decodeCoefficients;
var max = (1 << bpc) - 1; var max = (1 << bpc) - 1;
var i, ii;
if (bpc === 1) { if (bpc === 1) {
// If the buffer needed decode that means it just needs to be inverted. // 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]); buffer[i] = +!(buffer[i]);
} }
return; return;
} }
var index = 0; 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++) { for (var j = 0; j < numComps; j++) {
buffer[index] = decodeAndClamp(buffer[index], decodeAddends[j], buffer[index] = decodeAndClamp(buffer[index], decodeAddends[j],
decodeCoefficients[j], max); decodeCoefficients[j], max);
@ -308,10 +308,11 @@ var PDFImage = (function PDFImageClosure() {
var rowComps = width * numComps; var rowComps = width * numComps;
var max = (1 << bpc) - 1; var max = (1 << bpc) - 1;
var i = 0, ii, buf;
if (bpc === 1) { if (bpc === 1) {
// Optimization for reading 1 bpc images. // Optimization for reading 1 bpc images.
var i = 0, buf, mask, loop1End, loop2End; var mask, loop1End, loop2End;
for (var j = 0; j < height; j++) { for (var j = 0; j < height; j++) {
loop1End = i + (rowComps & ~7); loop1End = i + (rowComps & ~7);
loop2End = i + rowComps; loop2End = i + rowComps;
@ -342,8 +343,9 @@ var PDFImage = (function PDFImageClosure() {
} }
} else { } else {
// The general case that handles all other bpc values. // The general case that handles all other bpc values.
var bits = 0, buf = 0; var bits = 0;
for (var i = 0, ii = length; i < ii; ++i) { buf = 0;
for (i = 0, ii = length; i < ii; ++i) {
if (i % rowComps === 0) { if (i % rowComps === 0) {
buf = 0; buf = 0;
bits = 0; bits = 0;
@ -367,11 +369,11 @@ var PDFImage = (function PDFImageClosure() {
actualHeight, image) { actualHeight, image) {
var smask = this.smask; var smask = this.smask;
var mask = this.mask; var mask = this.mask;
var alphaBuf; var alphaBuf, sw, sh, i, ii, j;
if (smask) { if (smask) {
var sw = smask.width; sw = smask.width;
var sh = smask.height; sh = smask.height;
alphaBuf = new Uint8Array(sw * sh); alphaBuf = new Uint8Array(sw * sh);
smask.fillGrayBuffer(alphaBuf); smask.fillGrayBuffer(alphaBuf);
if (sw != width || sh != height) { if (sw != width || sh != height) {
@ -380,14 +382,14 @@ var PDFImage = (function PDFImageClosure() {
} }
} else if (mask) { } else if (mask) {
if (mask instanceof PDFImage) { if (mask instanceof PDFImage) {
var sw = mask.width; sw = mask.width;
var sh = mask.height; sh = mask.height;
alphaBuf = new Uint8Array(sw * sh); alphaBuf = new Uint8Array(sw * sh);
mask.numComps = 1; mask.numComps = 1;
mask.fillGrayBuffer(alphaBuf); mask.fillGrayBuffer(alphaBuf);
// Need to invert values in rgbaBuf // 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]; alphaBuf[i] = 255 - alphaBuf[i];
} }
@ -400,10 +402,10 @@ var PDFImage = (function PDFImageClosure() {
// then they should be painted. // then they should be painted.
alphaBuf = new Uint8Array(width * height); alphaBuf = new Uint8Array(width * height);
var numComps = this.numComps; 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 opacity = 0;
var imageOffset = i * numComps; var imageOffset = i * numComps;
for (var j = 0; j < numComps; ++j) { for (j = 0; j < numComps; ++j) {
var color = image[imageOffset + j]; var color = image[imageOffset + j];
var maskOffset = j * 2; var maskOffset = j * 2;
if (color < mask[maskOffset] || color > mask[maskOffset + 1]) { if (color < mask[maskOffset] || color > mask[maskOffset + 1]) {
@ -419,12 +421,12 @@ var PDFImage = (function PDFImageClosure() {
} }
if (alphaBuf) { 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]; rgbaBuf[j] = alphaBuf[i];
} }
} else { } else {
// No mask. // 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; rgbaBuf[j] = 255;
} }
} }
@ -560,18 +562,19 @@ var PDFImage = (function PDFImageClosure() {
var imgArray = this.getImageBytes(height * rowBytes); var imgArray = this.getImageBytes(height * rowBytes);
var comps = this.getComponents(imgArray); var comps = this.getComponents(imgArray);
var i, length;
if (bpc === 1) { if (bpc === 1) {
// inline decoding (= inversion) for 1 bpc images // inline decoding (= inversion) for 1 bpc images
var length = width * height; length = width * height;
if (this.needsDecode) { if (this.needsDecode) {
// invert and scale to {0, 255} // 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; buffer[i] = (comps[i] - 1) & 255;
} }
} else { } else {
// scale to {0, 255} // scale to {0, 255}
for (var i = 0; i < length; ++i) { for (i = 0; i < length; ++i) {
buffer[i] = (-comps[i]) & 255; buffer[i] = (-comps[i]) & 255;
} }
} }
@ -581,10 +584,10 @@ var PDFImage = (function PDFImageClosure() {
if (this.needsDecode) { if (this.needsDecode) {
this.decodeBuffer(comps); this.decodeBuffer(comps);
} }
var length = width * height; length = width * height;
// we aren't using a colorspace so we need to scale the value // we aren't using a colorspace so we need to scale the value
var scale = 255 / ((1 << bpc) - 1); 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; buffer[i] = (scale * comps[i]) | 0;
} }
}, },

View File

@ -237,8 +237,9 @@ var Jbig2Image = (function Jbig2ImageClosure() {
var templateY = new Int8Array(templateLength); var templateY = new Int8Array(templateLength);
var changingTemplateEntries = []; var changingTemplateEntries = [];
var reuseMask = 0, minX = 0, maxX = 0, minY = 0; 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; templateX[k] = template[k].x;
templateY[k] = template[k].y; templateY[k] = template[k].y;
minX = Math.min(minX, template[k].x); minX = Math.min(minX, template[k].x);
@ -260,7 +261,7 @@ var Jbig2Image = (function Jbig2ImageClosure() {
var changingTemplateX = new Int8Array(changingEntriesLength); var changingTemplateX = new Int8Array(changingEntriesLength);
var changingTemplateY = new Int8Array(changingEntriesLength); var changingTemplateY = new Int8Array(changingEntriesLength);
var changingTemplateBit = new Uint16Array(changingEntriesLength); var changingTemplateBit = new Uint16Array(changingEntriesLength);
for (var c = 0; c < changingEntriesLength; c++) { for (c = 0; c < changingEntriesLength; c++) {
k = changingTemplateEntries[c]; k = changingTemplateEntries[c];
changingTemplateX[c] = template[k].x; changingTemplateX[c] = template[k].x;
changingTemplateY[c] = template[k].y; changingTemplateY[c] = template[k].y;
@ -279,7 +280,7 @@ var Jbig2Image = (function Jbig2ImageClosure() {
var decoder = decodingContext.decoder; var decoder = decodingContext.decoder;
var contexts = decodingContext.contextCache.getContexts('GB'); 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++) { for (var i = 0; i < height; i++) {
if (prediction) { if (prediction) {
var sltp = decoder.readBit(contexts, pseudoPixelContext); var sltp = decoder.readBit(contexts, pseudoPixelContext);
@ -346,7 +347,8 @@ var Jbig2Image = (function Jbig2ImageClosure() {
var codingTemplateLength = codingTemplate.length; var codingTemplateLength = codingTemplate.length;
var codingTemplateX = new Int32Array(codingTemplateLength); var codingTemplateX = new Int32Array(codingTemplateLength);
var codingTemplateY = 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; codingTemplateX[k] = codingTemplate[k].x;
codingTemplateY[k] = codingTemplate[k].y; codingTemplateY[k] = codingTemplate[k].y;
} }
@ -358,7 +360,7 @@ var Jbig2Image = (function Jbig2ImageClosure() {
var referenceTemplateLength = referenceTemplate.length; var referenceTemplateLength = referenceTemplate.length;
var referenceTemplateX = new Int32Array(referenceTemplateLength); var referenceTemplateX = new Int32Array(referenceTemplateLength);
var referenceTemplateY = 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; referenceTemplateX[k] = referenceTemplate[k].x;
referenceTemplateY[k] = referenceTemplate[k].y; referenceTemplateY[k] = referenceTemplate[k].y;
} }
@ -383,19 +385,20 @@ var Jbig2Image = (function Jbig2ImageClosure() {
var row = new Uint8Array(width); var row = new Uint8Array(width);
bitmap.push(row); bitmap.push(row);
for (var j = 0; j < width; j++) { for (var j = 0; j < width; j++) {
var i0, j0;
var contextLabel = 0; var contextLabel = 0;
for (var k = 0; k < codingTemplateLength; k++) { for (k = 0; k < codingTemplateLength; k++) {
var i0 = i + codingTemplateY[k], j0 = j + codingTemplateX[k]; i0 = i + codingTemplateY[k];
j0 = j + codingTemplateX[k];
if (i0 < 0 || j0 < 0 || j0 >= width) { if (i0 < 0 || j0 < 0 || j0 >= width) {
contextLabel <<= 1; // out of bound pixel contextLabel <<= 1; // out of bound pixel
} else { } else {
contextLabel = (contextLabel << 1) | bitmap[i0][j0]; contextLabel = (contextLabel << 1) | bitmap[i0][j0];
} }
} }
for (var k = 0; k < referenceTemplateLength; k++) { for (k = 0; k < referenceTemplateLength; k++) {
var i0 = i + referenceTemplateY[k] + offsetY; i0 = i + referenceTemplateY[k] + offsetY;
var j0 = j + referenceTemplateX[k] + offsetX; j0 = j + referenceTemplateX[k] + offsetX;
if (i0 < 0 || i0 >= referenceHeight || j0 < 0 || if (i0 < 0 || i0 >= referenceHeight || j0 < 0 ||
j0 >= referenceWidth) { j0 >= referenceWidth) {
contextLabel <<= 1; // out of bound pixel contextLabel <<= 1; // out of bound pixel
@ -512,8 +515,9 @@ var Jbig2Image = (function Jbig2ImageClosure() {
// Prepare bitmap // Prepare bitmap
var bitmap = []; var bitmap = [];
for (var i = 0; i < height; i++) { var i, row;
var row = new Uint8Array(width); for (i = 0; i < height; i++) {
row = new Uint8Array(width);
if (defaultPixelValue) { if (defaultPixelValue) {
for (var j = 0; j < width; j++) { for (var j = 0; j < width; j++) {
row[j] = defaultPixelValue; row[j] = defaultPixelValue;
@ -526,7 +530,7 @@ var Jbig2Image = (function Jbig2ImageClosure() {
var contextCache = decodingContext.contextCache; var contextCache = decodingContext.contextCache;
var stripT = -decodeInteger(contextCache, 'IADT', decoder); // 6.4.6 var stripT = -decodeInteger(contextCache, 'IADT', decoder); // 6.4.6
var firstS = 0; var firstS = 0;
var i = 0; i = 0;
while (i < numberOfSymbolInstances) { while (i < numberOfSymbolInstances) {
var deltaT = decodeInteger(contextCache, 'IADT', decoder); // 6.4.6 var deltaT = decodeInteger(contextCache, 'IADT', decoder); // 6.4.6
stripT += deltaT; stripT += deltaT;
@ -535,12 +539,12 @@ var Jbig2Image = (function Jbig2ImageClosure() {
firstS += deltaFirstS; firstS += deltaFirstS;
var currentS = firstS; var currentS = firstS;
do { do {
var currentT = stripSize == 1 ? 0 : var currentT = (stripSize == 1 ? 0 :
decodeInteger(contextCache, 'IAIT', decoder); // 6.4.9 decodeInteger(contextCache, 'IAIT', decoder)); // 6.4.9
var t = stripSize * stripT + currentT; var t = stripSize * stripT + currentT;
var symbolId = decodeIAID(contextCache, decoder, symbolCodeLength); var symbolId = decodeIAID(contextCache, decoder, symbolCodeLength);
var applyRefinement = refinement && var applyRefinement = (refinement &&
decodeInteger(contextCache, 'IARI', decoder); decodeInteger(contextCache, 'IARI', decoder));
var symbolBitmap = inputSymbols[symbolId]; var symbolBitmap = inputSymbols[symbolId];
var symbolWidth = symbolBitmap[0].length; var symbolWidth = symbolBitmap[0].length;
var symbolHeight = symbolBitmap.length; var symbolHeight = symbolBitmap.length;
@ -558,25 +562,26 @@ var Jbig2Image = (function Jbig2ImageClosure() {
} }
var offsetT = t - ((referenceCorner & 1) ? 0 : symbolHeight); var offsetT = t - ((referenceCorner & 1) ? 0 : symbolHeight);
var offsetS = currentS - ((referenceCorner & 2) ? symbolWidth : 0); var offsetS = currentS - ((referenceCorner & 2) ? symbolWidth : 0);
var s2, t2, symbolRow;
if (transposed) { if (transposed) {
// Place Symbol Bitmap from T1,S1 // Place Symbol Bitmap from T1,S1
for (var s2 = 0; s2 < symbolHeight; s2++) { for (s2 = 0; s2 < symbolHeight; s2++) {
var row = bitmap[offsetS + s2]; row = bitmap[offsetS + s2];
if (!row) { if (!row) {
continue; continue;
} }
var symbolRow = symbolBitmap[s2]; symbolRow = symbolBitmap[s2];
// To ignore Parts of Symbol bitmap which goes // To ignore Parts of Symbol bitmap which goes
// outside bitmap region // outside bitmap region
var maxWidth = Math.min(width - offsetT, symbolWidth); var maxWidth = Math.min(width - offsetT, symbolWidth);
switch (combinationOperator) { switch (combinationOperator) {
case 0: // OR case 0: // OR
for (var t2 = 0; t2 < maxWidth; t2++) { for (t2 = 0; t2 < maxWidth; t2++) {
row[offsetT + t2] |= symbolRow[t2]; row[offsetT + t2] |= symbolRow[t2];
} }
break; break;
case 2: // XOR case 2: // XOR
for (var t2 = 0; t2 < maxWidth; t2++) { for (t2 = 0; t2 < maxWidth; t2++) {
row[offsetT + t2] ^= symbolRow[t2]; row[offsetT + t2] ^= symbolRow[t2];
} }
break; break;
@ -587,20 +592,20 @@ var Jbig2Image = (function Jbig2ImageClosure() {
} }
currentS += symbolHeight - 1; currentS += symbolHeight - 1;
} else { } else {
for (var t2 = 0; t2 < symbolHeight; t2++) { for (t2 = 0; t2 < symbolHeight; t2++) {
var row = bitmap[offsetT + t2]; row = bitmap[offsetT + t2];
if (!row) { if (!row) {
continue; continue;
} }
var symbolRow = symbolBitmap[t2]; symbolRow = symbolBitmap[t2];
switch (combinationOperator) { switch (combinationOperator) {
case 0: // OR case 0: // OR
for (var s2 = 0; s2 < symbolWidth; s2++) { for (s2 = 0; s2 < symbolWidth; s2++) {
row[offsetS + s2] |= symbolRow[s2]; row[offsetS + s2] |= symbolRow[s2];
} }
break; break;
case 2: // XOR case 2: // XOR
for (var s2 = 0; s2 < symbolWidth; s2++) { for (s2 = 0; s2 < symbolWidth; s2++) {
row[offsetS + s2] ^= symbolRow[s2]; row[offsetS + s2] ^= symbolRow[s2];
} }
break; break;
@ -655,7 +660,8 @@ var Jbig2Image = (function Jbig2ImageClosure() {
var referredToSegmentNumberSize = (segmentHeader.number <= 256 ? 1 : var referredToSegmentNumberSize = (segmentHeader.number <= 256 ? 1 :
(segmentHeader.number <= 65536 ? 2 : 4)); (segmentHeader.number <= 65536 ? 2 : 4));
var referredTo = []; var referredTo = [];
for (var i = 0; i < referredToCount; i++) { var i, ii;
for (i = 0; i < referredToCount; i++) {
var number = (referredToSegmentNumberSize == 1 ? data[position] : var number = (referredToSegmentNumberSize == 1 ? data[position] :
(referredToSegmentNumberSize == 2 ? readUint16(data, position) : (referredToSegmentNumberSize == 2 ? readUint16(data, position) :
readUint32(data, position))); readUint32(data, position)));
@ -690,7 +696,7 @@ var Jbig2Image = (function Jbig2ImageClosure() {
searchPattern[3] = (genericRegionInfo.height >> 16) & 0xFF; searchPattern[3] = (genericRegionInfo.height >> 16) & 0xFF;
searchPattern[4] = (genericRegionInfo.height >> 8) & 0xFF; searchPattern[4] = (genericRegionInfo.height >> 8) & 0xFF;
searchPattern[5] = genericRegionInfo.height & 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; var j = 0;
while (j < searchPatternLength && searchPattern[j] === data[i + j]) { while (j < searchPatternLength && searchPattern[j] === data[i + j]) {
j++; j++;
@ -757,7 +763,7 @@ var Jbig2Image = (function Jbig2ImageClosure() {
var header = segment.header; var header = segment.header;
var data = segment.data, position = segment.start, end = segment.end; var data = segment.data, position = segment.start, end = segment.end;
var args; var args, at, i, atLength;
switch (header.type) { switch (header.type) {
case 0: // SymbolDictionary case 0: // SymbolDictionary
// 7.4.2 Symbol dictionary segment syntax // 7.4.2 Symbol dictionary segment syntax
@ -775,9 +781,9 @@ var Jbig2Image = (function Jbig2ImageClosure() {
dictionary.refinementTemplate = (dictionaryFlags >> 12) & 1; dictionary.refinementTemplate = (dictionaryFlags >> 12) & 1;
position += 2; position += 2;
if (!dictionary.huffman) { if (!dictionary.huffman) {
var atLength = dictionary.template === 0 ? 4 : 1; atLength = dictionary.template === 0 ? 4 : 1;
var at = []; at = [];
for (var i = 0; i < atLength; i++) { for (i = 0; i < atLength; i++) {
at.push({ at.push({
x: readInt8(data, position), x: readInt8(data, position),
y: readInt8(data, position + 1) y: readInt8(data, position + 1)
@ -787,8 +793,8 @@ var Jbig2Image = (function Jbig2ImageClosure() {
dictionary.at = at; dictionary.at = at;
} }
if (dictionary.refinement && !dictionary.refinementTemplate) { if (dictionary.refinement && !dictionary.refinementTemplate) {
var at = []; at = [];
for (var i = 0; i < 2; i++) { for (i = 0; i < 2; i++) {
at.push({ at.push({
x: readInt8(data, position), x: readInt8(data, position),
y: readInt8(data, position + 1) y: readInt8(data, position + 1)
@ -834,8 +840,8 @@ var Jbig2Image = (function Jbig2ImageClosure() {
!!(textRegionHuffmanFlags & 14); !!(textRegionHuffmanFlags & 14);
} }
if (textRegion.refinement && !textRegion.refinementTemplate) { if (textRegion.refinement && !textRegion.refinementTemplate) {
var at = []; at = [];
for (var i = 0; i < 2; i++) { for (i = 0; i < 2; i++) {
at.push({ at.push({
x: readInt8(data, position), x: readInt8(data, position),
y: readInt8(data, position + 1) y: readInt8(data, position + 1)
@ -862,9 +868,9 @@ var Jbig2Image = (function Jbig2ImageClosure() {
genericRegion.template = (genericRegionSegmentFlags >> 1) & 3; genericRegion.template = (genericRegionSegmentFlags >> 1) & 3;
genericRegion.prediction = !!(genericRegionSegmentFlags & 8); genericRegion.prediction = !!(genericRegionSegmentFlags & 8);
if (!genericRegion.mmr) { if (!genericRegion.mmr) {
var atLength = genericRegion.template === 0 ? 4 : 1; atLength = genericRegion.template === 0 ? 4 : 1;
var at = []; at = [];
for (var i = 0; i < atLength; i++) { for (i = 0; i < atLength; i++) {
at.push({ at.push({
x: readInt8(data, position), x: readInt8(data, position),
y: readInt8(data, position + 1) y: readInt8(data, position + 1)
@ -976,12 +982,13 @@ var Jbig2Image = (function Jbig2ImageClosure() {
var buffer = this.buffer; var buffer = this.buffer;
var mask0 = 128 >> (regionInfo.x & 7); var mask0 = 128 >> (regionInfo.x & 7);
var offset0 = regionInfo.y * rowSize + (regionInfo.x >> 3); var offset0 = regionInfo.y * rowSize + (regionInfo.x >> 3);
var i, j, mask, offset;
switch (combinationOperator) { switch (combinationOperator) {
case 0: // OR case 0: // OR
for (var i = 0; i < height; i++) { for (i = 0; i < height; i++) {
var mask = mask0; mask = mask0;
var offset = offset0; offset = offset0;
for (var j = 0; j < width; j++) { for (j = 0; j < width; j++) {
if (bitmap[i][j]) { if (bitmap[i][j]) {
buffer[offset] |= mask; buffer[offset] |= mask;
} }
@ -995,10 +1002,10 @@ var Jbig2Image = (function Jbig2ImageClosure() {
} }
break; break;
case 2: // XOR case 2: // XOR
for (var i = 0; i < height; i++) { for (i = 0; i < height; i++) {
var mask = mask0; mask = mask0;
var offset = offset0; offset = offset0;
for (var j = 0; j < width; j++) { for (j = 0; j < width; j++) {
if (bitmap[i][j]) { if (bitmap[i][j]) {
buffer[offset] ^= mask; buffer[offset] ^= mask;
} }

View File

@ -139,7 +139,7 @@ var JpxImage = (function JpxImageClosure() {
var code = readUint16(data, position); var code = readUint16(data, position);
position += 2; position += 2;
var length = 0, j; var length = 0, j, sqcd, spqcds, spqcdSize, scalarExpounded, tile;
switch (code) { switch (code) {
case 0xFF4F: // Start of codestream (SOC) case 0xFF4F: // Start of codestream (SOC)
context.mainHeader = true; context.mainHeader = true;
@ -181,8 +181,7 @@ var JpxImage = (function JpxImageClosure() {
length = readUint16(data, position); length = readUint16(data, position);
var qcd = {}; var qcd = {};
j = position + 2; j = position + 2;
var sqcd = data[j++]; sqcd = data[j++];
var spqcdSize, scalarExpounded;
switch (sqcd & 0x1F) { switch (sqcd & 0x1F) {
case 0: case 0:
spqcdSize = 8; spqcdSize = 8;
@ -202,7 +201,7 @@ var JpxImage = (function JpxImageClosure() {
qcd.noQuantization = (spqcdSize == 8); qcd.noQuantization = (spqcdSize == 8);
qcd.scalarExpounded = scalarExpounded; qcd.scalarExpounded = scalarExpounded;
qcd.guardBits = sqcd >> 5; qcd.guardBits = sqcd >> 5;
var spqcds = []; spqcds = [];
while (j < length + position) { while (j < length + position) {
var spqcd = {}; var spqcd = {};
if (spqcdSize == 8) { if (spqcdSize == 8) {
@ -234,8 +233,7 @@ var JpxImage = (function JpxImageClosure() {
cqcc = readUint16(data, j); cqcc = readUint16(data, j);
j += 2; j += 2;
} }
var sqcd = data[j++]; sqcd = data[j++];
var spqcdSize, scalarExpounded;
switch (sqcd & 0x1F) { switch (sqcd & 0x1F) {
case 0: case 0:
spqcdSize = 8; spqcdSize = 8;
@ -255,9 +253,9 @@ var JpxImage = (function JpxImageClosure() {
qcc.noQuantization = (spqcdSize == 8); qcc.noQuantization = (spqcdSize == 8);
qcc.scalarExpounded = scalarExpounded; qcc.scalarExpounded = scalarExpounded;
qcc.guardBits = sqcd >> 5; qcc.guardBits = sqcd >> 5;
var spqcds = []; spqcds = [];
while (j < (length + position)) { while (j < (length + position)) {
var spqcd = {}; spqcd = {};
if (spqcdSize == 8) { if (spqcdSize == 8) {
spqcd.epsilon = data[j++] >> 3; spqcd.epsilon = data[j++] >> 3;
spqcd.mu = 0; spqcd.mu = 0;
@ -330,7 +328,7 @@ var JpxImage = (function JpxImageClosure() {
break; break;
case 0xFF90: // Start of tile-part (SOT) case 0xFF90: // Start of tile-part (SOT)
length = readUint16(data, position); length = readUint16(data, position);
var tile = {}; tile = {};
tile.index = readUint16(data, position + 2); tile.index = readUint16(data, position + 2);
tile.length = readUint32(data, position + 4); tile.length = readUint32(data, position + 4);
tile.dataEnd = tile.length + position - 2; tile.dataEnd = tile.length + position - 2;
@ -348,7 +346,7 @@ var JpxImage = (function JpxImageClosure() {
context.currentTile = tile; context.currentTile = tile;
break; break;
case 0xFF93: // Start of data (SOD) case 0xFF93: // Start of data (SOD)
var tile = context.currentTile; tile = context.currentTile;
if (tile.partIndex === 0) { if (tile.partIndex === 0) {
initializeTile(context, tile.index); initializeTile(context, tile.index);
buildPackets(context); buildPackets(context);
@ -409,12 +407,12 @@ var JpxImage = (function JpxImageClosure() {
function calculateTileGrids(context, components) { function calculateTileGrids(context, components) {
var siz = context.SIZ; var siz = context.SIZ;
// Section B.3 Division into tile and tile-components // 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 numXtiles = Math.ceil((siz.Xsiz - siz.XTOsiz) / siz.XTsiz);
var numYtiles = Math.ceil((siz.Ysiz - siz.YTOsiz) / siz.YTsiz); var numYtiles = Math.ceil((siz.Ysiz - siz.YTOsiz) / siz.YTsiz);
for (var q = 0; q < numYtiles; q++) { for (var q = 0; q < numYtiles; q++) {
for (var p = 0; p < numXtiles; p++) { for (var p = 0; p < numXtiles; p++) {
var tile = {}; tile = {};
tile.tx0 = Math.max(siz.XTOsiz + p * siz.XTsiz, siz.XOsiz); tile.tx0 = Math.max(siz.XTOsiz + p * siz.XTsiz, siz.XOsiz);
tile.ty0 = Math.max(siz.YTOsiz + q * siz.YTsiz, siz.YOsiz); tile.ty0 = Math.max(siz.YTOsiz + q * siz.YTsiz, siz.YOsiz);
tile.tx1 = Math.min(siz.XTOsiz + (p + 1) * siz.XTsiz, siz.Xsiz); 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 component = components[i];
var tileComponents = []; var tileComponents = [];
for (var j = 0, jj = tiles.length; j < jj; j++) { 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.tcx0 = Math.ceil(tile.tx0 / component.XRsiz);
tileComponent.tcy0 = Math.ceil(tile.ty0 / component.YRsiz); tileComponent.tcy0 = Math.ceil(tile.ty0 / component.YRsiz);
tileComponent.tcx1 = Math.ceil(tile.tx1 / component.XRsiz); tileComponent.tcx1 = Math.ceil(tile.tx1 / component.XRsiz);
@ -498,9 +497,10 @@ var JpxImage = (function JpxImageClosure() {
var precinctParameters = subband.resolution.precinctParameters; var precinctParameters = subband.resolution.precinctParameters;
var codeblocks = []; var codeblocks = [];
var precincts = []; var precincts = [];
for (var j = cby0; j < cby1; j++) { var i, ii, j, codeblock, precinctNumber;
for (var i = cbx0; i < cbx1; i++) { for (j = cby0; j < cby1; j++) {
var codeblock = { for (i = cbx0; i < cbx1; i++) {
codeblock = {
cbx: i, cbx: i,
cby: j, cby: j,
tbx0: codeblockWidth * i, tbx0: codeblockWidth * i,
@ -515,8 +515,7 @@ var JpxImage = (function JpxImageClosure() {
var pj = Math.floor((codeblock.tby0 - var pj = Math.floor((codeblock.tby0 -
precinctParameters.precinctYOffset) / precinctParameters.precinctYOffset) /
precinctParameters.precinctHeight); precinctParameters.precinctHeight);
var precinctNumber = pj + precinctNumber = pj + pi * precinctParameters.numprecinctswide;
pi * precinctParameters.numprecinctswide;
codeblock.tbx0_ = Math.max(subband.tbx0, codeblock.tbx0); codeblock.tbx0_ = Math.max(subband.tbx0, codeblock.tbx0);
codeblock.tby0_ = Math.max(subband.tby0, codeblock.tby0); codeblock.tby0_ = Math.max(subband.tby0, codeblock.tby0);
codeblock.tbx1_ = Math.min(subband.tbx1, codeblock.tbx1); codeblock.tbx1_ = Math.min(subband.tbx1, codeblock.tbx1);
@ -816,19 +815,20 @@ var JpxImage = (function JpxImageClosure() {
continue; continue;
} }
var layerNumber = packet.layerNumber; var layerNumber = packet.layerNumber;
var queue = []; var queue = [], codeblock;
for (var i = 0, ii = packet.codeblocks.length; i < ii; i++) { 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 precinct = codeblock.precinct;
var codeblockColumn = codeblock.cbx - precinct.cbxMin; var codeblockColumn = codeblock.cbx - precinct.cbxMin;
var codeblockRow = codeblock.cby - precinct.cbyMin; var codeblockRow = codeblock.cby - precinct.cbyMin;
var codeblockIncluded = false; var codeblockIncluded = false;
var firstTimeInclusion = false; var firstTimeInclusion = false;
var valueReady;
if ('included' in codeblock) { if ('included' in codeblock) {
codeblockIncluded = !!readBits(1); codeblockIncluded = !!readBits(1);
} else { } else {
// reading inclusion tree // reading inclusion tree
var precinct = codeblock.precinct; precinct = codeblock.precinct;
var inclusionTree, zeroBitPlanesTree; var inclusionTree, zeroBitPlanesTree;
if ('inclusionTree' in precinct) { if ('inclusionTree' in precinct) {
inclusionTree = precinct.inclusionTree; inclusionTree = precinct.inclusionTree;
@ -845,7 +845,7 @@ var JpxImage = (function JpxImageClosure() {
if (inclusionTree.reset(codeblockColumn, codeblockRow, layerNumber)) { if (inclusionTree.reset(codeblockColumn, codeblockRow, layerNumber)) {
while (true) { while (true) {
if (readBits(1)) { if (readBits(1)) {
var valueReady = !inclusionTree.nextLevel(); valueReady = !inclusionTree.nextLevel();
if (valueReady) { if (valueReady) {
codeblock.included = true; codeblock.included = true;
codeblockIncluded = firstTimeInclusion = true; codeblockIncluded = firstTimeInclusion = true;
@ -866,7 +866,7 @@ var JpxImage = (function JpxImageClosure() {
zeroBitPlanesTree.reset(codeblockColumn, codeblockRow); zeroBitPlanesTree.reset(codeblockColumn, codeblockRow);
while (true) { while (true) {
if (readBits(1)) { if (readBits(1)) {
var valueReady = !zeroBitPlanesTree.nextLevel(); valueReady = !zeroBitPlanesTree.nextLevel();
if (valueReady) { if (valueReady) {
break; break;
} }
@ -894,7 +894,7 @@ var JpxImage = (function JpxImageClosure() {
alignToByte(); alignToByte();
while (queue.length > 0) { while (queue.length > 0) {
var packetItem = queue.shift(); var packetItem = queue.shift();
var codeblock = packetItem.codeblock; codeblock = packetItem.codeblock;
if (!('data' in codeblock)) { if (!('data' in codeblock)) {
codeblock.data = []; codeblock.data = [];
} }
@ -930,14 +930,15 @@ var JpxImage = (function JpxImageClosure() {
// collect data // collect data
var data = codeblock.data, totalLength = 0, codingpasses = 0; var data = codeblock.data, totalLength = 0, codingpasses = 0;
for (var q = 0, qq = data.length; q < qq; q++) { var q, qq, dataItem;
var dataItem = data[q]; for (q = 0, qq = data.length; q < qq; q++) {
dataItem = data[q];
totalLength += dataItem.end - dataItem.start; totalLength += dataItem.end - dataItem.start;
codingpasses += dataItem.codingpasses; codingpasses += dataItem.codingpasses;
} }
var encodedData = new Uint8Array(totalLength), k = 0; var encodedData = new Uint8Array(totalLength), k = 0;
for (var q = 0, qq = data.length; q < qq; q++) { for (q = 0, qq = data.length; q < qq; q++) {
var dataItem = data[q]; dataItem = data[q];
var chunk = dataItem.data.subarray(dataItem.start, dataItem.end); var chunk = dataItem.data.subarray(dataItem.start, dataItem.end);
encodedData.set(chunk, k); encodedData.set(chunk, k);
k += chunk.length; k += chunk.length;
@ -946,7 +947,7 @@ var JpxImage = (function JpxImageClosure() {
var decoder = new ArithmeticDecoder(encodedData, 0, totalLength); var decoder = new ArithmeticDecoder(encodedData, 0, totalLength);
bitModel.setDecoder(decoder); bitModel.setDecoder(decoder);
for (var q = 0; q < codingpasses; q++) { for (q = 0; q < codingpasses; q++) {
switch (currentCodingpassType) { switch (currentCodingpassType) {
case 0: case 0:
bitModel.runSignificancePropogationPass(); bitModel.runSignificancePropogationPass();
@ -972,7 +973,7 @@ var JpxImage = (function JpxImageClosure() {
var bitsDecoded = bitModel.bitsDecoded; var bitsDecoded = bitModel.bitsDecoded;
var magnitudeCorrection = reversible ? 0 : 0.5; var magnitudeCorrection = reversible ? 0 : 0.5;
for (var j = 0; j < blockHeight; j++) { for (var j = 0; j < blockHeight; j++) {
for (var k = 0; k < blockWidth; k++) { for (k = 0; k < blockWidth; k++) {
n = magnitude[position]; n = magnitude[position];
if (n !== 0) { if (n !== 0) {
n = (n + magnitudeCorrection) * delta; n = (n + magnitudeCorrection) * delta;
@ -1068,32 +1069,35 @@ var JpxImage = (function JpxImageClosure() {
for (var i = 0, ii = context.tiles.length; i < ii; i++) { for (var i = 0, ii = context.tiles.length; i < ii; i++) {
var tile = context.tiles[i]; var tile = context.tiles[i];
var result = []; var result = [];
for (var c = 0; c < componentsCount; c++) { var c;
for (c = 0; c < componentsCount; c++) {
var image = transformTile(context, tile, c); var image = transformTile(context, tile, c);
result.push(image); result.push(image);
} }
// Section G.2.2 Inverse multi component transform // 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) { if (tile.codingStyleDefaultParameters.multipleComponentTransform) {
var component0 = tile.components[0]; var component0 = tile.components[0];
if (!component0.codingStyleParameters.reversibleTransformation) { if (!component0.codingStyleParameters.reversibleTransformation) {
// inverse irreversible multiple component transform // inverse irreversible multiple component transform
var y0items = result[0].items; y0items = result[0].items;
var y1items = result[1].items; y1items = result[1].items;
var y2items = result[2].items; y2items = result[2].items;
for (var j = 0, jj = y0items.length; j < jj; ++j) { for (j = 0, jj = y0items.length; j < jj; ++j) {
var y0 = y0items[j] + 0.5, y1 = y1items[j], y2 = y2items[j]; y0 = y0items[j] + 0.5; y1 = y1items[j]; y2 = y2items[j];
y0items[j] = y0 + 1.402 * y2; y0items[j] = y0 + 1.402 * y2;
y1items[j] = y0 - 0.34413 * y1 - 0.71414 * y2; y1items[j] = y0 - 0.34413 * y1 - 0.71414 * y2;
y2items[j] = y0 + 1.772 * y1; y2items[j] = y0 + 1.772 * y1;
} }
} else { } else {
// inverse reversible multiple component transform // inverse reversible multiple component transform
var y0items = result[0].items; y0items = result[0].items;
var y1items = result[1].items; y1items = result[1].items;
var y2items = result[2].items; y2items = result[2].items;
for (var j = 0, jj = y0items.length; j < jj; ++j) { for (j = 0, jj = y0items.length; j < jj; ++j) {
var y0 = y0items[j], y1 = y1items[j], y2 = y2items[j]; y0 = y0items[j]; y1 = y1items[j]; y2 = y2items[j];
var i1 = y0 - ((y2 + y1) >> 2); var i1 = y0 - ((y2 + y1) >> 2);
y1items[j] = i1; y1items[j] = i1;
y0items[j] = y2 + i1; y0items[j] = y2 + i1;
@ -1103,15 +1107,15 @@ var JpxImage = (function JpxImageClosure() {
} }
// To simplify things: shift and clamp output to 8 bit unsigned // To simplify things: shift and clamp output to 8 bit unsigned
for (var c = 0; c < componentsCount; c++) { for (c = 0; c < componentsCount; c++) {
var component = components[c]; component = components[c];
var shift = component.precision - 8; var shift = component.precision - 8;
var tileImage = result[c]; tileImage = result[c];
var items = tileImage.items; items = tileImage.items;
var data = new Uint8Array(items.length); var data = new Uint8Array(items.length);
var low = -(128 << shift); var low = -(128 << shift);
var high = 127 << 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]; var val = items[j];
data[j] = val <= low ? 0 : val >= high ? 255 : (val >> shift) + 128; data[j] = val <= low ? 0 : val >= high ? 255 : (val >> shift) + 128;
} }
@ -1157,9 +1161,9 @@ var JpxImage = (function JpxImageClosure() {
} }
TagTree.prototype = { TagTree.prototype = {
reset: function TagTree_reset(i, j) { reset: function TagTree_reset(i, j) {
var currentLevel = 0, value = 0; var currentLevel = 0, value = 0, level;
while (currentLevel < this.levels.length) { while (currentLevel < this.levels.length) {
var level = this.levels[currentLevel]; level = this.levels[currentLevel];
var index = i + j * level.width; var index = i + j * level.width;
if (index in level.items) { if (index in level.items) {
value = level.items[index]; value = level.items[index];
@ -1171,7 +1175,7 @@ var JpxImage = (function JpxImageClosure() {
currentLevel++; currentLevel++;
} }
currentLevel--; currentLevel--;
var level = this.levels[currentLevel]; level = this.levels[currentLevel];
level.items[level.index] = value; level.items[level.index] = value;
this.currentLevel = currentLevel; this.currentLevel = currentLevel;
delete this.value; delete this.value;
@ -1191,7 +1195,7 @@ var JpxImage = (function JpxImageClosure() {
} }
this.currentLevel = currentLevel; this.currentLevel = currentLevel;
var level = this.levels[currentLevel]; level = this.levels[currentLevel];
level.items[level.index] = value; level.items[level.index] = value;
return true; return true;
} }
@ -1257,7 +1261,7 @@ var JpxImage = (function JpxImageClosure() {
var level = this.levels[levelIndex]; var level = this.levels[levelIndex];
var currentValue = level.items[level.index]; var currentValue = level.items[level.index];
while (--levelIndex >= 0) { while (--levelIndex >= 0) {
var level = this.levels[levelIndex]; level = this.levels[levelIndex];
level.items[level.index] = currentValue; level.items[level.index] = currentValue;
} }
}, },
@ -1272,7 +1276,7 @@ var JpxImage = (function JpxImageClosure() {
} }
this.currentLevel = currentLevel; this.currentLevel = currentLevel;
var level = this.levels[currentLevel]; level = this.levels[currentLevel];
level.items[level.index] = value; level.items[level.index] = value;
return true; return true;
} }
@ -1351,9 +1355,10 @@ var JpxImage = (function JpxImageClosure() {
var width = this.width, height = this.height; var width = this.width, height = this.height;
var left = (column > 0); var left = (column > 0);
var right = (column + 1 < width); var right = (column + 1 < width);
var i;
if (row > 0) { if (row > 0) {
var i = index - width; i = index - width;
if (left) { if (left) {
neighborsSignificance[i - 1] += 0x10; neighborsSignificance[i - 1] += 0x10;
} }
@ -1364,7 +1369,7 @@ var JpxImage = (function JpxImageClosure() {
} }
if (row + 1 < height) { if (row + 1 < height) {
var i = index + width; i = index + width;
if (left) { if (left) {
neighborsSignificance[i - 1] += 0x10; neighborsSignificance[i - 1] += 0x10;
} }
@ -1434,6 +1439,7 @@ var JpxImage = (function JpxImageClosure() {
var coefficentsMagnitude = this.coefficentsMagnitude; var coefficentsMagnitude = this.coefficentsMagnitude;
var coefficentsSign = this.coefficentsSign; var coefficentsSign = this.coefficentsSign;
var contribution, sign0, sign1, significance1; var contribution, sign0, sign1, significance1;
var contextLabel, decoded;
// calculate horizontal contribution // calculate horizontal contribution
significance1 = (column > 0 && coefficentsMagnitude[index - 1] !== 0); significance1 = (column > 0 && coefficentsMagnitude[index - 1] !== 0);
@ -1471,11 +1477,11 @@ var JpxImage = (function JpxImageClosure() {
} }
if (contribution >= 0) { if (contribution >= 0) {
var contextLabel = 9 + contribution; contextLabel = 9 + contribution;
var decoded = this.decoder.readBit(this.contexts, contextLabel); decoded = this.decoder.readBit(this.contexts, contextLabel);
} else { } else {
var contextLabel = 9 - contribution; contextLabel = 9 - contribution;
var decoded = this.decoder.readBit(this.contexts, contextLabel) ^ 1; decoded = this.decoder.readBit(this.contexts, contextLabel) ^ 1;
} }
return decoded; return decoded;
}, },
@ -1552,7 +1558,7 @@ var JpxImage = (function JpxImageClosure() {
neighborsSignificance[index0 + twoRowsDown] === 0 && neighborsSignificance[index0 + twoRowsDown] === 0 &&
neighborsSignificance[index0 + threeRowsDown] === 0); neighborsSignificance[index0 + threeRowsDown] === 0);
var i1 = 0, index = index0; var i1 = 0, index = index0;
var i; var i, sign;
if (allEmpty) { if (allEmpty) {
var hasSignificantCoefficent = var hasSignificantCoefficent =
decoder.readBit(contexts, RUNLENGTH_CONTEXT); decoder.readBit(contexts, RUNLENGTH_CONTEXT);
@ -1568,7 +1574,7 @@ var JpxImage = (function JpxImageClosure() {
i = i0 + i1; i = i0 + i1;
index += i1 * width; index += i1 * width;
var sign = this.decodeSignBit(i, j, index); sign = this.decodeSignBit(i, j, index);
coefficentsSign[index] = sign; coefficentsSign[index] = sign;
coefficentsMagnitude[index] = 1; coefficentsMagnitude[index] = 1;
this.setNeighborsSignificance(i, j, index); this.setNeighborsSignificance(i, j, index);
@ -1595,7 +1601,7 @@ var JpxImage = (function JpxImageClosure() {
var contextLabel = labels[neighborsSignificance[index]]; var contextLabel = labels[neighborsSignificance[index]];
var decision = decoder.readBit(contexts, contextLabel); var decision = decoder.readBit(contexts, contextLabel);
if (decision == 1) { if (decision == 1) {
var sign = this.decodeSignBit(i, j, index); sign = this.decodeSignBit(i, j, index);
coefficentsSign[index] = sign; coefficentsSign[index] = sign;
coefficentsMagnitude[index] = 1; coefficentsMagnitude[index] = 1;
this.setNeighborsSignificance(i, j, index); this.setNeighborsSignificance(i, j, index);
@ -1659,11 +1665,11 @@ var JpxImage = (function JpxImageClosure() {
var width = llWidth + hlWidth; var width = llWidth + hlWidth;
var height = llHeight + lhHeight; var height = llHeight + lhHeight;
var items = new Float32Array(width * height); 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++) { for (i = 0, k = 0; i < llHeight; i++) {
l = i * 2 * width; 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]; items[l] = llItems[k];
} }
} }
@ -1693,12 +1699,12 @@ var JpxImage = (function JpxImageClosure() {
if (width === 1) { if (width === 1) {
// if width = 1, when u0 even keep items as is, when odd divide by 2 // if width = 1, when u0 even keep items as is, when odd divide by 2
if ((u0 & 1) !== 0) { 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; items[k] *= 0.5;
} }
} }
} else { } 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); rowBuffer.set(items.subarray(k, k + width), bufferPadding);
this.extend(rowBuffer, bufferPadding, width); this.extend(rowBuffer, bufferPadding, width);
@ -1721,18 +1727,19 @@ var JpxImage = (function JpxImageClosure() {
for (i = 0; i < numBuffers; i++) { for (i = 0; i < numBuffers; i++) {
colBuffers.push(new Float32Array(height + 2 * bufferPadding)); 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 // Section F.3.5 VER_SR
if (height === 1) { if (height === 1) {
// if height = 1, when v0 even keep items as is, when odd divide by 2 // if height = 1, when v0 even keep items as is, when odd divide by 2
if ((v0 & 1) !== 0) { if ((v0 & 1) !== 0) {
for (var u = 0; u < width; u++) { for (u = 0; u < width; u++) {
items[u] *= 0.5; items[u] *= 0.5;
} }
} }
} else { } 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 we ran out of buffers, copy several image columns at once
if (currentBuffer === 0) { if (currentBuffer === 0) {
numBuffers = Math.min(width - u, numBuffers); numBuffers = Math.min(width - u, numBuffers);
@ -1780,7 +1787,7 @@ var JpxImage = (function JpxImageClosure() {
IrreversibleTransform.prototype.filter = IrreversibleTransform.prototype.filter =
function irreversibleTransformFilter(y, offset, length, i0, x) { function irreversibleTransformFilter(y, offset, length, i0, x) {
var len = length >> 1; var len = length >> 1;
var offset = offset | 0; offset = offset | 0;
var alpha = -1.586134342059924; var alpha = -1.586134342059924;
var beta = -0.052980118572961; var beta = -0.052980118572961;
@ -1788,32 +1795,33 @@ var JpxImage = (function JpxImageClosure() {
var delta = 0.443506852043971; var delta = 0.443506852043971;
var K = 1.230174104914001; var K = 1.230174104914001;
var K_ = 1 / K; var K_ = 1 / K;
var j, n, nn;
// step 1 is combined with step 3 // step 1 is combined with step 3
// step 2 // 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]; x[j] = K_ * y[j];
} }
// step 1 & 3 // 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] - x[j] = K * y[j] -
delta * (x[j - 1] + x[j + 1]); delta * (x[j - 1] + x[j + 1]);
} }
// step 4 // 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]); x[j] -= gamma * (x[j - 1] + x[j + 1]);
} }
// step 5 // 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]); x[j] -= beta * (x[j - 1] + x[j + 1]);
} }
// step 6 // 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]); x[j] -= alpha * (x[j - 1] + x[j + 1]);
} }
}; };
@ -1831,13 +1839,14 @@ var JpxImage = (function JpxImageClosure() {
ReversibleTransform.prototype.filter = ReversibleTransform.prototype.filter =
function reversibleTransformFilter(y, offset, length, i0, x) { function reversibleTransformFilter(y, offset, length, i0, x) {
var len = length >> 1; 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); 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); x[j] = y[j] + ((x[j - 1] + x[j + 1]) >> 1);
} }
}; };

View File

@ -37,10 +37,11 @@ var MurmurHash3_64 = (function MurmurHash3_64Closure (seed) {
MurmurHash3_64.prototype = { MurmurHash3_64.prototype = {
update: function MurmurHash3_64_update(input) { update: function MurmurHash3_64_update(input) {
var useUint32ArrayView = false; var useUint32ArrayView = false;
var i;
if (typeof input == 'string') { if (typeof input == 'string') {
var data = new Uint8Array(input.length * 2); var data = new Uint8Array(input.length * 2);
var length = 0; var length = 0;
for (var i = 0; i < input.length; i++) { for (i = 0; i < input.length; i++) {
var code = input.charCodeAt(i); var code = input.charCodeAt(i);
if (code <= 0xff) { if (code <= 0xff) {
data[length++] = code; data[length++] = code;
@ -78,7 +79,7 @@ var MurmurHash3_64 = (function MurmurHash3_64Closure (seed) {
var C1_LOW = C1 & MASK_LOW; var C1_LOW = C1 & MASK_LOW;
var C2_LOW = C2 & MASK_LOW; var C2_LOW = C2 & MASK_LOW;
for (var i = 0; i < blockCounts; i++) { for (i = 0; i < blockCounts; i++) {
if (i & 1) { if (i & 1) {
k1 = dataUint32[i]; k1 = dataUint32[i];
k1 = (k1 * C1 & MASK_HIGH) | (k1 * C1_LOW & MASK_LOW); k1 = (k1 * C1 & MASK_HIGH) | (k1 * C1_LOW & MASK_LOW);

View File

@ -151,8 +151,9 @@ var Dict = (function DictClosure() {
getAll: function Dict_getAll() { getAll: function Dict_getAll() {
var all = Object.create(null); var all = Object.create(null);
var queue = null; var queue = null;
for (var key in this.map) { var key, obj;
var obj = this.get(key); for (key in this.map) {
obj = this.get(key);
if (obj instanceof Dict) { if (obj instanceof Dict) {
if (isRecursionAllowedFor(obj)) { if (isRecursionAllowedFor(obj)) {
(queue || (queue = [])).push({target: all, key: key, obj: obj}); (queue || (queue = [])).push({target: all, key: key, obj: obj});
@ -178,8 +179,8 @@ var Dict = (function DictClosure() {
continue; continue;
} }
var dereferenced = Object.create(null); var dereferenced = Object.create(null);
for (var key in itemObj.map) { for (key in itemObj.map) {
var obj = itemObj.get(key); obj = itemObj.get(key);
if (obj instanceof Dict) { if (obj instanceof Dict) {
if (isRecursionAllowedFor(obj)) { if (isRecursionAllowedFor(obj)) {
queue.push({target: dereferenced, key: key, obj: obj}); queue.push({target: dereferenced, key: key, obj: obj});
@ -988,13 +989,14 @@ var XRef = (function XRefClosure() {
} }
} }
// reading XRef streams // 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.startXRefQueue.push(xrefStms[i]);
this.readXRef(/* recoveryMode */ true); this.readXRef(/* recoveryMode */ true);
} }
// finding main trailer // finding main trailer
var dict; 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]; stream.pos = trailers[i];
var parser = new Parser(new Lexer(stream), true, null); var parser = new Parser(new Lexer(stream), true, null);
var obj = parser.getObj(); var obj = parser.getObj();
@ -1332,6 +1334,7 @@ var ObjectLoader = (function() {
} }
function addChildren(node, nodesToVisit) { function addChildren(node, nodesToVisit) {
var value;
if (isDict(node) || isStream(node)) { if (isDict(node) || isStream(node)) {
var map; var map;
if (isDict(node)) { if (isDict(node)) {
@ -1340,14 +1343,14 @@ var ObjectLoader = (function() {
map = node.dict.map; map = node.dict.map;
} }
for (var key in map) { for (var key in map) {
var value = map[key]; value = map[key];
if (mayHaveChildren(value)) { if (mayHaveChildren(value)) {
nodesToVisit.push(value); nodesToVisit.push(value);
} }
} }
} else if (isArray(node)) { } else if (isArray(node)) {
for (var i = 0, ii = node.length; i < ii; i++) { for (var i = 0, ii = node.length; i < ii; i++) {
var value = node[i]; value = node[i];
if (mayHaveChildren(value)) { if (mayHaveChildren(value)) {
nodesToVisit.push(value); nodesToVisit.push(value);
} }

View File

@ -192,7 +192,7 @@ var Parser = (function ParserClosure() {
var a = 1; var a = 1;
var b = 0; 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; a = (a + (imageBytes[i] & 0xff)) % 65521;
b = (b + a) % 65521; b = (b + a) % 65521;
} }
@ -261,11 +261,11 @@ var Parser = (function ParserClosure() {
var ENDSTREAM_SIGNATURE_LENGTH = 9; var ENDSTREAM_SIGNATURE_LENGTH = 9;
var ENDSTREAM_SIGNATURE = [0x65, 0x6E, 0x64, 0x73, 0x74, 0x72, 0x65, var ENDSTREAM_SIGNATURE = [0x65, 0x6E, 0x64, 0x73, 0x74, 0x72, 0x65,
0x61, 0x6D]; 0x61, 0x6D];
var skipped = 0, found = false; var skipped = 0, found = false, i, j;
while (stream.pos < stream.end) { while (stream.pos < stream.end) {
var scanBytes = stream.peekBytes(SCAN_BLOCK_SIZE); var scanBytes = stream.peekBytes(SCAN_BLOCK_SIZE);
var scanLength = scanBytes.length - ENDSTREAM_SIGNATURE_LENGTH; var scanLength = scanBytes.length - ENDSTREAM_SIGNATURE_LENGTH;
var found = false, i, j; found = false;
for (i = 0, j = 0; i < scanLength; i++) { for (i = 0, j = 0; i < scanLength; i++) {
var b = scanBytes[i]; var b = scanBytes[i];
if (b !== ENDSTREAM_SIGNATURE[j]) { if (b !== ENDSTREAM_SIGNATURE[j]) {

View File

@ -162,15 +162,16 @@ Shadings.RadialAxial = (function RadialAxialClosure() {
return; return;
} }
var rgbColor;
for (var i = t0; i <= t1; i += step) { 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); var cssColor = Util.makeCssRgb(rgbColor);
colorStops.push([(i - t0) / diff, cssColor]); colorStops.push([(i - t0) / diff, cssColor]);
} }
var background = 'transparent'; var background = 'transparent';
if (dict.has('Background')) { if (dict.has('Background')) {
var rgbColor = cs.getRgb(dict.get('Background'), 0); rgbColor = cs.getRgb(dict.get('Background'), 0);
background = Util.makeCssRgb(rgbColor); background = Util.makeCssRgb(rgbColor);
} }

View File

@ -446,7 +446,8 @@ var FlateStream = (function FlateStreamClosure() {
// find max code length // find max code length
var maxLen = 0; var maxLen = 0;
for (var i = 0; i < n; ++i) { var i;
for (i = 0; i < n; ++i) {
if (lengths[i] > maxLen) { if (lengths[i] > maxLen) {
maxLen = lengths[i]; maxLen = lengths[i];
} }
@ -463,13 +464,13 @@ var FlateStream = (function FlateStreamClosure() {
// bit-reverse the code // bit-reverse the code
var code2 = 0; var code2 = 0;
var t = code; var t = code;
for (var i = 0; i < len; ++i) { for (i = 0; i < len; ++i) {
code2 = (code2 << 1) | (t & 1); code2 = (code2 << 1) | (t & 1);
t >>= 1; t >>= 1;
} }
// fill the table entries // fill the table entries
for (var i = code2; i < size; i += skip) { for (i = code2; i < size; i += skip) {
codes[i] = (len << 16) | val; codes[i] = (len << 16) | val;
} }
++code; ++code;
@ -481,6 +482,7 @@ var FlateStream = (function FlateStreamClosure() {
}; };
FlateStream.prototype.readBlock = function FlateStream_readBlock() { FlateStream.prototype.readBlock = function FlateStream_readBlock() {
var buffer, len;
var str = this.str; var str = this.str;
// read block header // read block header
var hdr = this.getBits(3); var hdr = this.getBits(3);
@ -518,7 +520,7 @@ var FlateStream = (function FlateStreamClosure() {
this.codeSize = 0; this.codeSize = 0;
var bufferLength = this.bufferLength; var bufferLength = this.bufferLength;
var buffer = this.ensureBuffer(bufferLength + blockLen); buffer = this.ensureBuffer(bufferLength + blockLen);
var end = bufferLength + blockLen; var end = bufferLength + blockLen;
this.bufferLength = end; this.bufferLength = end;
if (blockLen === 0) { if (blockLen === 0) {
@ -550,24 +552,26 @@ var FlateStream = (function FlateStreamClosure() {
// build the code lengths code table // build the code lengths code table
var codeLenCodeLengths = new Uint8Array(codeLenCodeMap.length); 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); codeLenCodeLengths[codeLenCodeMap[i]] = this.getBits(3);
} }
var codeLenCodeTab = this.generateHuffmanTable(codeLenCodeLengths); var codeLenCodeTab = this.generateHuffmanTable(codeLenCodeLengths);
// build the literal and distance code tables // build the literal and distance code tables
var len = 0; len = 0;
var i = 0; i = 0;
var codes = numLitCodes + numDistCodes; var codes = numLitCodes + numDistCodes;
var codeLengths = new Uint8Array(codes); var codeLengths = new Uint8Array(codes);
var bitsLength, bitsOffset, what;
while (i < codes) { while (i < codes) {
var code = this.getCode(codeLenCodeTab); var code = this.getCode(codeLenCodeTab);
if (code == 16) { if (code == 16) {
var bitsLength = 2, bitsOffset = 3, what = len; bitsLength = 2; bitsOffset = 3; what = len;
} else if (code == 17) { } else if (code == 17) {
var bitsLength = 3, bitsOffset = 3, what = (len = 0); bitsLength = 3; bitsOffset = 3; what = (len = 0);
} else if (code == 18) { } else if (code == 18) {
var bitsLength = 7, bitsOffset = 11, what = (len = 0); bitsLength = 7; bitsOffset = 11; what = (len = 0);
} else { } else {
codeLengths[i++] = len = code; codeLengths[i++] = len = code;
continue; continue;
@ -587,7 +591,7 @@ var FlateStream = (function FlateStreamClosure() {
error('Unknown block type in flate stream'); error('Unknown block type in flate stream');
} }
var buffer = this.buffer; buffer = this.buffer;
var limit = buffer ? buffer.length : 0; var limit = buffer ? buffer.length : 0;
var pos = this.bufferLength; var pos = this.bufferLength;
while (true) { while (true) {
@ -610,7 +614,7 @@ var FlateStream = (function FlateStreamClosure() {
if (code2 > 0) { if (code2 > 0) {
code2 = this.getBits(code2); code2 = this.getBits(code2);
} }
var len = (code1 & 0xffff) + code2; len = (code1 & 0xffff) + code2;
code1 = this.getCode(distCodeTable); code1 = this.getCode(distCodeTable);
code1 = distDecode[code1]; code1 = distDecode[code1];
code2 = code1 >> 16; code2 = code1 >> 16;
@ -683,9 +687,10 @@ var PredictorStream = (function PredictorStreamClosure() {
var inbuf = 0, outbuf = 0; var inbuf = 0, outbuf = 0;
var inbits = 0, outbits = 0; var inbits = 0, outbits = 0;
var pos = bufferLength; var pos = bufferLength;
var i;
if (bits === 1) { if (bits === 1) {
for (var i = 0; i < rowBytes; ++i) { for (i = 0; i < rowBytes; ++i) {
var c = rawBytes[i]; var c = rawBytes[i];
inbuf = (inbuf << 8) | c; inbuf = (inbuf << 8) | c;
// bitwise addition is exclusive or // bitwise addition is exclusive or
@ -695,7 +700,7 @@ var PredictorStream = (function PredictorStreamClosure() {
inbuf &= 0xFFFF; inbuf &= 0xFFFF;
} }
} else if (bits === 8) { } else if (bits === 8) {
for (var i = 0; i < colors; ++i) { for (i = 0; i < colors; ++i) {
buffer[pos++] = rawBytes[i]; buffer[pos++] = rawBytes[i];
} }
for (; i < rowBytes; ++i) { for (; i < rowBytes; ++i) {
@ -707,7 +712,7 @@ var PredictorStream = (function PredictorStreamClosure() {
var bitMask = (1 << bits) - 1; var bitMask = (1 << bits) - 1;
var j = 0, k = bufferLength; var j = 0, k = bufferLength;
var columns = this.columns; var columns = this.columns;
for (var i = 0; i < columns; ++i) { for (i = 0; i < columns; ++i) {
for (var kk = 0; kk < colors; ++kk) { for (var kk = 0; kk < colors; ++kk) {
if (inbits < bits) { if (inbits < bits) {
inbuf = (inbuf << 8) | (rawBytes[j++] & 0xFF); inbuf = (inbuf << 8) | (rawBytes[j++] & 0xFF);
@ -753,15 +758,15 @@ var PredictorStream = (function PredictorStreamClosure() {
prevRow = new Uint8Array(rowBytes); prevRow = new Uint8Array(rowBytes);
} }
var j = bufferLength; var i, j = bufferLength, up, c;
switch (predictor) { switch (predictor) {
case 0: case 0:
for (var i = 0; i < rowBytes; ++i) { for (i = 0; i < rowBytes; ++i) {
buffer[j++] = rawBytes[i]; buffer[j++] = rawBytes[i];
} }
break; break;
case 1: case 1:
for (var i = 0; i < pixBytes; ++i) { for (i = 0; i < pixBytes; ++i) {
buffer[j++] = rawBytes[i]; buffer[j++] = rawBytes[i];
} }
for (; i < rowBytes; ++i) { for (; i < rowBytes; ++i) {
@ -770,12 +775,12 @@ var PredictorStream = (function PredictorStreamClosure() {
} }
break; break;
case 2: case 2:
for (var i = 0; i < rowBytes; ++i) { for (i = 0; i < rowBytes; ++i) {
buffer[j++] = (prevRow[i] + rawBytes[i]) & 0xFF; buffer[j++] = (prevRow[i] + rawBytes[i]) & 0xFF;
} }
break; break;
case 3: case 3:
for (var i = 0; i < pixBytes; ++i) { for (i = 0; i < pixBytes; ++i) {
buffer[j++] = (prevRow[i] >> 1) + rawBytes[i]; buffer[j++] = (prevRow[i] >> 1) + rawBytes[i];
} }
for (; i < rowBytes; ++i) { for (; i < rowBytes; ++i) {
@ -787,13 +792,13 @@ var PredictorStream = (function PredictorStreamClosure() {
case 4: case 4:
// we need to save the up left pixels values. the simplest way // we need to save the up left pixels values. the simplest way
// is to create a new buffer // is to create a new buffer
for (var i = 0; i < pixBytes; ++i) { for (i = 0; i < pixBytes; ++i) {
var up = prevRow[i]; up = prevRow[i];
var c = rawBytes[i]; c = rawBytes[i];
buffer[j++] = up + c; buffer[j++] = up + c;
} }
for (; i < rowBytes; ++i) { for (; i < rowBytes; ++i) {
var up = prevRow[i]; up = prevRow[i];
var upLeft = prevRow[i - pixBytes]; var upLeft = prevRow[i - pixBytes];
var left = buffer[j - pixBytes]; var left = buffer[j - pixBytes];
var p = left + up - upLeft; var p = left + up - upLeft;
@ -811,7 +816,7 @@ var PredictorStream = (function PredictorStreamClosure() {
pc = -pc; pc = -pc;
} }
var c = rawBytes[i]; c = rawBytes[i];
if (pa <= pb && pa <= pc) { if (pa <= pb && pa <= pc) {
buffer[j++] = left + c; buffer[j++] = left + c;
} else if (pb <= pc) { } else if (pb <= pc) {
@ -951,6 +956,7 @@ var JpxStream = (function JpxStreamClosure() {
var tileTop = tileCompoments[0].top; var tileTop = tileCompoments[0].top;
var dataPosition, sourcePosition, data0, data1, data2, data3, rowFeed; var dataPosition, sourcePosition, data0, data1, data2, data3, rowFeed;
var i, j;
switch (componentsCount) { switch (componentsCount) {
case 1: case 1:
data0 = tileCompoments[0].items; data0 = tileCompoments[0].items;
@ -958,8 +964,8 @@ var JpxStream = (function JpxStreamClosure() {
dataPosition = width * tileTop + tileLeft; dataPosition = width * tileTop + tileLeft;
rowFeed = width - tileWidth; rowFeed = width - tileWidth;
sourcePosition = 0; sourcePosition = 0;
for (var j = 0; j < tileHeight; j++) { for (j = 0; j < tileHeight; j++) {
for (var i = 0; i < tileWidth; i++) { for (i = 0; i < tileWidth; i++) {
data[dataPosition++] = data0[sourcePosition++]; data[dataPosition++] = data0[sourcePosition++];
} }
dataPosition += rowFeed; dataPosition += rowFeed;
@ -973,8 +979,8 @@ var JpxStream = (function JpxStreamClosure() {
dataPosition = (width * tileTop + tileLeft) * 3; dataPosition = (width * tileTop + tileLeft) * 3;
rowFeed = (width - tileWidth) * 3; rowFeed = (width - tileWidth) * 3;
sourcePosition = 0; sourcePosition = 0;
for (var j = 0; j < tileHeight; j++) { for (j = 0; j < tileHeight; j++) {
for (var i = 0; i < tileWidth; i++) { for (i = 0; i < tileWidth; i++) {
data[dataPosition++] = data0[sourcePosition]; data[dataPosition++] = data0[sourcePosition];
data[dataPosition++] = data1[sourcePosition]; data[dataPosition++] = data1[sourcePosition];
data[dataPosition++] = data2[sourcePosition]; data[dataPosition++] = data2[sourcePosition];
@ -992,8 +998,8 @@ var JpxStream = (function JpxStreamClosure() {
dataPosition = (width * tileTop + tileLeft) * 4; dataPosition = (width * tileTop + tileLeft) * 4;
rowFeed = (width - tileWidth) * 4; rowFeed = (width - tileWidth) * 4;
sourcePosition = 0; sourcePosition = 0;
for (var j = 0; j < tileHeight; j++) { for (j = 0; j < tileHeight; j++) {
for (var i = 0; i < tileWidth; i++) { for (i = 0; i < tileWidth; i++) {
data[dataPosition++] = data0[sourcePosition]; data[dataPosition++] = data0[sourcePosition];
data[dataPosition++] = data1[sourcePosition]; data[dataPosition++] = data1[sourcePosition];
data[dataPosition++] = data2[sourcePosition]; data[dataPosition++] = data2[sourcePosition];
@ -1156,18 +1162,19 @@ var Ascii85Stream = (function Ascii85StreamClosure() {
} }
var bufferLength = this.bufferLength, buffer; var bufferLength = this.bufferLength, buffer;
var i;
// special code for z // special code for z
if (c == Z_LOWER_CHAR) { if (c == Z_LOWER_CHAR) {
buffer = this.ensureBuffer(bufferLength + 4); buffer = this.ensureBuffer(bufferLength + 4);
for (var i = 0; i < 4; ++i) { for (i = 0; i < 4; ++i) {
buffer[bufferLength + i] = 0; buffer[bufferLength + i] = 0;
} }
this.bufferLength += 4; this.bufferLength += 4;
} else { } else {
var input = this.input; var input = this.input;
input[0] = c; input[0] = c;
for (var i = 1; i < 5; ++i) { for (i = 1; i < 5; ++i) {
c = str.getByte(); c = str.getByte();
while (Lexer.isSpace(c)) { while (Lexer.isSpace(c)) {
c = str.getByte(); c = str.getByte();
@ -1190,11 +1197,11 @@ var Ascii85Stream = (function Ascii85StreamClosure() {
this.eof = true; this.eof = true;
} }
var t = 0; var t = 0;
for (var i = 0; i < 5; ++i) { for (i = 0; i < 5; ++i) {
t = t * 85 + (input[i] - 0x21); t = t * 85 + (input[i] - 0x21);
} }
for (var i = 3; i >= 0; --i) { for (i = 3; i >= 0; --i) {
buffer[bufferLength + i] = t & 0xFF; buffer[bufferLength + i] = t & 0xFF;
t >>= 8; t >>= 8;
} }
@ -1287,11 +1294,12 @@ var RunLengthStream = (function RunLengthStreamClosure() {
return; return;
} }
var buffer;
var bufferLength = this.bufferLength; var bufferLength = this.bufferLength;
var n = repeatHeader[0]; var n = repeatHeader[0];
if (n < 128) { if (n < 128) {
// copy n bytes // copy n bytes
var buffer = this.ensureBuffer(bufferLength + n + 1); buffer = this.ensureBuffer(bufferLength + n + 1);
buffer[bufferLength++] = repeatHeader[1]; buffer[bufferLength++] = repeatHeader[1];
if (n > 0) { if (n > 0) {
var source = this.str.getBytes(n); var source = this.str.getBytes(n);
@ -1301,7 +1309,7 @@ var RunLengthStream = (function RunLengthStreamClosure() {
} else { } else {
n = 257 - n; n = 257 - n;
var b = repeatHeader[1]; var b = repeatHeader[1];
var buffer = this.ensureBuffer(bufferLength + n + 1); buffer = this.ensureBuffer(bufferLength + n + 1);
for (var i = 0; i < n; i++) { for (var i = 0; i < n; i++) {
buffer[bufferLength++] = b; buffer[bufferLength++] = b;
} }
@ -1851,7 +1859,7 @@ var CCITTFaxStream = (function CCITTFaxStreamClosure() {
var codingLine = this.codingLine; var codingLine = this.codingLine;
var columns = this.columns; var columns = this.columns;
var refPos, blackPixels, bits; var refPos, blackPixels, bits, i;
if (this.outputBits === 0) { if (this.outputBits === 0) {
if (this.eof) { if (this.eof) {
@ -1861,7 +1869,7 @@ var CCITTFaxStream = (function CCITTFaxStreamClosure() {
var code1, code2, code3; var code1, code2, code3;
if (this.nextLine2D) { if (this.nextLine2D) {
for (var i = 0; codingLine[i] < columns; ++i) { for (i = 0; codingLine[i] < columns; ++i) {
refLine[i] = codingLine[i]; refLine[i] = codingLine[i];
} }
refLine[i++] = columns; refLine[i++] = columns;
@ -2063,7 +2071,7 @@ var CCITTFaxStream = (function CCITTFaxStreamClosure() {
this.eatBits(1); this.eatBits(1);
} }
if (this.encoding >= 0) { if (this.encoding >= 0) {
for (var i = 0; i < 4; ++i) { for (i = 0; i < 4; ++i) {
code1 = this.lookBits(12); code1 = this.lookBits(12);
if (code1 != 1) { if (code1 != 1) {
info('bad rtc code: ' + code1); info('bad rtc code: ' + code1);
@ -2114,7 +2122,7 @@ var CCITTFaxStream = (function CCITTFaxStreamClosure() {
codingLine[this.codingPos - 1]); codingLine[this.codingPos - 1]);
} }
} else { } else {
var bits = 8; bits = 8;
c = 0; c = 0;
do { do {
if (this.outputBits > bits) { if (this.outputBits > bits) {

View File

@ -596,8 +596,9 @@ var PDFPageProxy = (function PDFPageProxyClosure() {
_renderPageChunk: function PDFPageProxy_renderPageChunk(operatorListChunk, _renderPageChunk: function PDFPageProxy_renderPageChunk(operatorListChunk,
intent) { intent) {
var intentState = this.intentStates[intent]; var intentState = this.intentStates[intent];
var i, ii;
// Add the new chunk to the current operator list. // Add the new chunk to the current operator list.
for (var i = 0, ii = operatorListChunk.length; i < ii; i++) { for (i = 0, ii = operatorListChunk.length; i < ii; i++) {
intentState.operatorList.fnArray.push(operatorListChunk.fnArray[i]); intentState.operatorList.fnArray.push(operatorListChunk.fnArray[i]);
intentState.operatorList.argsArray.push( intentState.operatorList.argsArray.push(
operatorListChunk.argsArray[i]); operatorListChunk.argsArray[i]);
@ -605,7 +606,7 @@ var PDFPageProxy = (function PDFPageProxyClosure() {
intentState.operatorList.lastChunk = operatorListChunk.lastChunk; intentState.operatorList.lastChunk = operatorListChunk.lastChunk;
// Notify all the rendering tasks there are more operators to be consumed. // Notify all the rendering tasks there are more operators to be consumed.
for (var i = 0; i < intentState.renderTasks.length; i++) { for (i = 0; i < intentState.renderTasks.length; i++) {
intentState.renderTasks[i].operatorListChanged(); intentState.renderTasks[i].operatorListChanged();
} }
@ -886,17 +887,18 @@ var WorkerTransport = (function WorkerTransportClosure() {
var pageIndex = data[1]; var pageIndex = data[1];
var type = data[2]; var type = data[2];
var pageProxy = this.pageCache[pageIndex]; var pageProxy = this.pageCache[pageIndex];
var imageData;
if (pageProxy.objs.hasData(id)) { if (pageProxy.objs.hasData(id)) {
return; return;
} }
switch (type) { switch (type) {
case 'JpegStream': case 'JpegStream':
var imageData = data[3]; imageData = data[3];
loadJpegStream(id, imageData, pageProxy.objs); loadJpegStream(id, imageData, pageProxy.objs);
break; break;
case 'Image': case 'Image':
var imageData = data[3]; imageData = data[3];
pageProxy.objs.resolve(id, imageData); pageProxy.objs.resolve(id, imageData);
// heuristics that will allow not to store large data // heuristics that will allow not to store large data
@ -952,15 +954,16 @@ var WorkerTransport = (function WorkerTransportClosure() {
var tmpCtx = tmpCanvas.getContext('2d'); var tmpCtx = tmpCanvas.getContext('2d');
tmpCtx.drawImage(img, 0, 0); tmpCtx.drawImage(img, 0, 0);
var data = tmpCtx.getImageData(0, 0, width, height).data; var data = tmpCtx.getImageData(0, 0, width, height).data;
var i, j;
if (components == 3) { if (components == 3) {
for (var i = 0, j = 0; i < rgbaLength; i += 4, j += 3) { for (i = 0, j = 0; i < rgbaLength; i += 4, j += 3) {
buf[j] = data[i]; buf[j] = data[i];
buf[j + 1] = data[i + 1]; buf[j + 1] = data[i + 1];
buf[j + 2] = data[i + 2]; buf[j + 2] = data[i + 2];
} }
} else if (components == 1) { } else if (components == 1) {
for (var i = 0, j = 0; i < rgbaLength; i += 4, j++) { for (i = 0, j = 0; i < rgbaLength; i += 4, j++) {
buf[j] = data[i]; buf[j] = data[i];
} }
} }
@ -1003,7 +1006,7 @@ var WorkerTransport = (function WorkerTransportClosure() {
if (pageIndex in this.pagePromises) { if (pageIndex in this.pagePromises) {
return this.pagePromises[pageIndex]; return this.pagePromises[pageIndex];
} }
var promise = new PDFJS.LegacyPromise(); promise = new PDFJS.LegacyPromise();
this.pagePromises[pageIndex] = promise; this.pagePromises[pageIndex] = promise;
this.messageHandler.send('GetPageRequest', { pageIndex: pageIndex }); this.messageHandler.send('GetPageRequest', { pageIndex: pageIndex });
return promise; return promise;

View File

@ -453,13 +453,13 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
var partialChunkHeight = height - fullChunks * fullChunkHeight; var partialChunkHeight = height - fullChunks * fullChunkHeight;
var chunkImgData = ctx.createImageData(width, fullChunkHeight); var chunkImgData = ctx.createImageData(width, fullChunkHeight);
var srcPos = 0; var srcPos = 0, destPos;
var src = imgData.data; var src = imgData.data;
var dest = chunkImgData.data; var dest = chunkImgData.data;
var i, j, thisChunkHeight, elemsInThisChunk;
// There are multiple forms in which the pixel data can be passed, and // There are multiple forms in which the pixel data can be passed, and
// imgData.kind tells us which one this is. // imgData.kind tells us which one this is.
if (imgData.kind === ImageKind.GRAYSCALE_1BPP) { if (imgData.kind === ImageKind.GRAYSCALE_1BPP) {
// Grayscale, 1 bit per pixel (i.e. black-and-white). // Grayscale, 1 bit per pixel (i.e. black-and-white).
var destDataLength = dest.length; var destDataLength = dest.length;
@ -471,11 +471,11 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
var white = 0xFFFFFFFF; var white = 0xFFFFFFFF;
var black = (PDFJS.isLittleEndian || !PDFJS.hasCanvasTypedArrays) ? var black = (PDFJS.isLittleEndian || !PDFJS.hasCanvasTypedArrays) ?
0xFF000000 : 0x000000FF; 0xFF000000 : 0x000000FF;
for (var i = 0; i < totalChunks; i++) { for (i = 0; i < totalChunks; i++) {
var thisChunkHeight = thisChunkHeight =
(i < fullChunks) ? fullChunkHeight : partialChunkHeight; (i < fullChunks) ? fullChunkHeight : partialChunkHeight;
var destPos = 0; destPos = 0;
for (var j = 0; j < thisChunkHeight; j++) { for (j = 0; j < thisChunkHeight; j++) {
var srcDiff = srcLength - srcPos; var srcDiff = srcLength - srcPos;
var k = 0; var k = 0;
var kEnd = (srcDiff > fullSrcDiff) ? width : srcDiff * 8 - 7; var kEnd = (srcDiff > fullSrcDiff) ? width : srcDiff * 8 - 7;
@ -510,29 +510,27 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
ctx.putImageData(chunkImgData, 0, i * fullChunkHeight); ctx.putImageData(chunkImgData, 0, i * fullChunkHeight);
} }
} else if (imgData.kind === ImageKind.RGBA_32BPP) { } else if (imgData.kind === ImageKind.RGBA_32BPP) {
// RGBA, 32-bits per pixel. // RGBA, 32-bits per pixel.
for (var i = 0; i < totalChunks; i++) { for (i = 0; i < totalChunks; i++) {
var thisChunkHeight = thisChunkHeight =
(i < fullChunks) ? fullChunkHeight : partialChunkHeight; (i < fullChunks) ? fullChunkHeight : partialChunkHeight;
var elemsInThisChunk = imgData.width * thisChunkHeight * 4; elemsInThisChunk = imgData.width * thisChunkHeight * 4;
dest.set(src.subarray(srcPos, srcPos + elemsInThisChunk)); dest.set(src.subarray(srcPos, srcPos + elemsInThisChunk));
srcPos += elemsInThisChunk; srcPos += elemsInThisChunk;
ctx.putImageData(chunkImgData, 0, i * fullChunkHeight); ctx.putImageData(chunkImgData, 0, i * fullChunkHeight);
} }
} else if (imgData.kind === ImageKind.RGB_24BPP) { } else if (imgData.kind === ImageKind.RGB_24BPP) {
// RGB, 24-bits per pixel. // RGB, 24-bits per pixel.
for (var i = 0; i < totalChunks; i++) { for (i = 0; i < totalChunks; i++) {
var thisChunkHeight = thisChunkHeight =
(i < fullChunks) ? fullChunkHeight : partialChunkHeight; (i < fullChunks) ? fullChunkHeight : partialChunkHeight;
var elemsInThisChunk = imgData.width * thisChunkHeight * 3; elemsInThisChunk = imgData.width * thisChunkHeight * 3;
var destPos = 0; destPos = 0;
for (var j = 0; j < elemsInThisChunk; j += 3) { for (j = 0; j < elemsInThisChunk; j += 3) {
dest[destPos++] = src[srcPos++]; dest[destPos++] = src[srcPos++];
dest[destPos++] = src[srcPos++]; dest[destPos++] = src[srcPos++];
dest[destPos++] = src[srcPos++]; dest[destPos++] = src[srcPos++];
@ -540,9 +538,8 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
} }
ctx.putImageData(chunkImgData, 0, i * fullChunkHeight); ctx.putImageData(chunkImgData, 0, i * fullChunkHeight);
} }
} else { } else {
error('bad image kind: ' + imgData.kind); error('bad image kind: ' + imgData.kind);
} }
} }
@ -1311,6 +1308,8 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
var glyphsLength = glyphs.length; var glyphsLength = glyphs.length;
var vertical = font.vertical; var vertical = font.vertical;
var defaultVMetrics = font.defaultVMetrics; var defaultVMetrics = font.defaultVMetrics;
var i, glyph, width;
var VERTICAL_TEXT_ROTATION = Math.PI / 2;
if (fontSize === 0) { if (fontSize === 0) {
return; return;
@ -1324,9 +1323,8 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
ctx.scale(textHScale, 1); ctx.scale(textHScale, 1);
for (var i = 0; i < glyphsLength; ++i) { for (i = 0; i < glyphsLength; ++i) {
glyph = glyphs[i];
var glyph = glyphs[i];
if (glyph === null) { if (glyph === null) {
// word break // word break
this.ctx.translate(wordSpacing, 0); this.ctx.translate(wordSpacing, 0);
@ -1342,8 +1340,8 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
this.restore(); this.restore();
var transformed = Util.applyTransform([glyph.width, 0], fontMatrix); var transformed = Util.applyTransform([glyph.width, 0], fontMatrix);
var width = (transformed[0] * fontSize + charSpacing) * width = ((transformed[0] * fontSize + charSpacing) *
current.fontDirection; current.fontDirection);
ctx.translate(width, 0); ctx.translate(width, 0);
current.x += width * textHScale; current.x += width * textHScale;
@ -1371,8 +1369,8 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
ctx.lineWidth = lineWidth; ctx.lineWidth = lineWidth;
var x = 0; var x = 0;
for (var i = 0; i < glyphsLength; ++i) { for (i = 0; i < glyphsLength; ++i) {
var glyph = glyphs[i]; glyph = glyphs[i];
if (glyph === null) { if (glyph === null) {
// word break // word break
x += current.fontDirection * wordSpacing; x += current.fontDirection * wordSpacing;
@ -1387,7 +1385,7 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
vx = -vx * fontSize * current.fontMatrix[0]; vx = -vx * fontSize * current.fontMatrix[0];
var vy = vmetric[2] * fontSize * current.fontMatrix[0]; var vy = vmetric[2] * fontSize * current.fontMatrix[0];
} }
var width = vmetric ? -vmetric[0] : glyph.width; width = vmetric ? -vmetric[0] : glyph.width;
var charWidth = width * fontSize * current.fontMatrix[0] + var charWidth = width * fontSize * current.fontMatrix[0] +
charSpacing * current.fontDirection; charSpacing * current.fontDirection;
var accent = glyph.accent; var accent = glyph.accent;
@ -1509,6 +1507,7 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
this.current.strokeColor = color; this.current.strokeColor = color;
}, },
getColorN_Pattern: function CanvasGraphics_getColorN_Pattern(IR, cs) { getColorN_Pattern: function CanvasGraphics_getColorN_Pattern(IR, cs) {
var pattern;
if (IR[0] == 'TilingPattern') { if (IR[0] == 'TilingPattern') {
var args = IR[1]; var args = IR[1];
var base = cs.base; var base = cs.base;
@ -1518,10 +1517,10 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
color = base.getRgb(args, 0); color = base.getRgb(args, 0);
} }
var pattern = new TilingPattern(IR, color, this.ctx, this.objs, pattern = new TilingPattern(IR, color, this.ctx, this.objs,
this.commonObjs, this.baseTransform); this.commonObjs, this.baseTransform);
} else { } else {
var pattern = getShadingPatternFromIR(IR); pattern = getShadingPatternFromIR(IR);
} }
return pattern; return pattern;
}, },
@ -1999,12 +1998,12 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
var c = currentTransform[2], d = currentTransform[3]; var c = currentTransform[2], d = currentTransform[3];
var heightScale = Math.max(Math.sqrt(c * c + d * d), 1); var heightScale = Math.max(Math.sqrt(c * c + d * d), 1);
var imgToPaint; var imgToPaint, tmpCanvas;
// instanceof HTMLElement does not work in jsdom node.js module // instanceof HTMLElement does not work in jsdom node.js module
if (imgData instanceof HTMLElement || !imgData.data) { if (imgData instanceof HTMLElement || !imgData.data) {
imgToPaint = imgData; imgToPaint = imgData;
} else { } else {
var tmpCanvas = CachedCanvases.getCanvas('inlineImage', width, height); tmpCanvas = CachedCanvases.getCanvas('inlineImage', width, height);
var tmpCtx = tmpCanvas.context; var tmpCtx = tmpCanvas.context;
putBinaryImageData(tmpCtx, imgData); putBinaryImageData(tmpCtx, imgData);
imgToPaint = tmpCanvas.canvas; imgToPaint = tmpCanvas.canvas;
@ -2026,8 +2025,7 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
newHeight = Math.ceil(paintHeight / 2); newHeight = Math.ceil(paintHeight / 2);
heightScale /= paintHeight / newHeight; heightScale /= paintHeight / newHeight;
} }
var tmpCanvas = CachedCanvases.getCanvas(tmpCanvasId, tmpCanvas = CachedCanvases.getCanvas(tmpCanvasId, newWidth, newHeight);
newWidth, newHeight);
tmpCtx = tmpCanvas.context; tmpCtx = tmpCanvas.context;
tmpCtx.clearRect(0, 0, newWidth, newHeight); tmpCtx.clearRect(0, 0, newWidth, newHeight);
tmpCtx.drawImage(imgToPaint, 0, 0, paintWidth, paintHeight, tmpCtx.drawImage(imgToPaint, 0, 0, paintWidth, paintHeight,

View File

@ -117,12 +117,13 @@ var createMeshCanvas = (function createMeshCanvasClosure() {
function drawFigure(data, figure, context) { function drawFigure(data, figure, context) {
var ps = figure.coords; var ps = figure.coords;
var cs = figure.colors; var cs = figure.colors;
var i, ii;
switch (figure.type) { switch (figure.type) {
case 'lattice': case 'lattice':
var verticesPerRow = figure.verticesPerRow; var verticesPerRow = figure.verticesPerRow;
var rows = Math.floor(ps.length / verticesPerRow) - 1; var rows = Math.floor(ps.length / verticesPerRow) - 1;
var cols = verticesPerRow - 1; var cols = verticesPerRow - 1;
for (var i = 0; i < rows; i++) { for (i = 0; i < rows; i++) {
var q = i * verticesPerRow; var q = i * verticesPerRow;
for (var j = 0; j < cols; j++, q++) { for (var j = 0; j < cols; j++, q++) {
drawTriangle(data, context, drawTriangle(data, context,
@ -135,7 +136,7 @@ var createMeshCanvas = (function createMeshCanvasClosure() {
} }
break; break;
case 'triangles': case 'triangles':
for (var i = 0, ii = ps.length; i < ii; i += 3) { for (i = 0, ii = ps.length; i < ii; i += 3) {
drawTriangle(data, context, drawTriangle(data, context,
ps[i], ps[i + 1], ps[i + 2], ps[i], ps[i + 1], ps[i + 2],
cs[i], cs[i + 1], cs[i + 2]); cs[i], cs[i + 1], cs[i + 2]);
@ -176,30 +177,30 @@ var createMeshCanvas = (function createMeshCanvasClosure() {
scaleY: 1 / scaleY scaleY: 1 / scaleY
}; };
var canvas; var canvas, tmpCanvas, i, ii;
if (WebGLUtils.isEnabled) { if (WebGLUtils.isEnabled) {
canvas = WebGLUtils.drawFigures(width, height, backgroundColor, canvas = WebGLUtils.drawFigures(width, height, backgroundColor,
figures, context); figures, context);
// https://bugzilla.mozilla.org/show_bug.cgi?id=972126 // https://bugzilla.mozilla.org/show_bug.cgi?id=972126
var tmpCanvas = CachedCanvases.getCanvas('mesh', width, height, false); tmpCanvas = CachedCanvases.getCanvas('mesh', width, height, false);
tmpCanvas.context.drawImage(canvas, 0, 0); tmpCanvas.context.drawImage(canvas, 0, 0);
canvas = tmpCanvas.canvas; canvas = tmpCanvas.canvas;
} else { } else {
var tmpCanvas = CachedCanvases.getCanvas('mesh', width, height, false); tmpCanvas = CachedCanvases.getCanvas('mesh', width, height, false);
var tmpCtx = tmpCanvas.context; var tmpCtx = tmpCanvas.context;
var data = tmpCtx.createImageData(width, height); var data = tmpCtx.createImageData(width, height);
if (backgroundColor) { if (backgroundColor) {
var bytes = data.data; var bytes = data.data;
for (var i = 0, ii = bytes.length; i < ii; i += 4) { for (i = 0, ii = bytes.length; i < ii; i += 4) {
bytes[i] = backgroundColor[0]; bytes[i] = backgroundColor[0];
bytes[i + 1] = backgroundColor[1]; bytes[i + 1] = backgroundColor[1];
bytes[i + 2] = backgroundColor[2]; bytes[i + 2] = backgroundColor[2];
bytes[i + 3] = 255; bytes[i + 3] = 255;
} }
} }
for (var i = 0; i < figures.length; i++) { for (i = 0; i < figures.length; i++) {
drawFigure(data, figures[i], context); drawFigure(data, figures[i], context);
} }
tmpCtx.putImageData(data, 0, 0); tmpCtx.putImageData(data, 0, 0);
@ -414,7 +415,7 @@ var TilingPattern = (function TilingPatternClosure() {
getPattern: function TilingPattern_getPattern(ctx, owner) { getPattern: function TilingPattern_getPattern(ctx, owner) {
var temporaryPatternCanvas = this.createPatternCanvas(owner); var temporaryPatternCanvas = this.createPatternCanvas(owner);
var ctx = this.ctx; ctx = this.ctx;
ctx.setTransform.apply(ctx, this.baseTransform); ctx.setTransform.apply(ctx, this.baseTransform);
ctx.transform.apply(ctx, this.matrix); ctx.transform.apply(ctx, this.matrix);
this.scaleToContext(); this.scaleToContext();

View File

@ -294,10 +294,11 @@ var WebGLUtils = (function WebGLUtilsClosure() {
// count triangle points // count triangle points
var count = 0; var count = 0;
for (var i = 0, ii = figures.length; i < ii; i++) { var i, ii, rows;
for (i = 0, ii = figures.length; i < ii; i++) {
switch (figures[i].type) { switch (figures[i].type) {
case 'lattice': case 'lattice':
var rows = (figures[i].coords.length / figures[i].verticesPerRow) | 0; rows = (figures[i].coords.length / figures[i].verticesPerRow) | 0;
count += (rows - 1) * (figures[i].verticesPerRow - 1) * 6; count += (rows - 1) * (figures[i].verticesPerRow - 1) * 6;
break; break;
case 'triangles': case 'triangles':
@ -310,12 +311,12 @@ var WebGLUtils = (function WebGLUtilsClosure() {
var colors = new Uint8Array(count * 3); var colors = new Uint8Array(count * 3);
var coordsMap = context.coords, colorsMap = context.colors; var coordsMap = context.coords, colorsMap = context.colors;
var pIndex = 0, cIndex = 0; var pIndex = 0, cIndex = 0;
for (var i = 0, ii = figures.length; i < ii; i++) { for (i = 0, ii = figures.length; i < ii; i++) {
var figure = figures[i], ps = figure.coords, cs = figure.colors; var figure = figures[i], ps = figure.coords, cs = figure.colors;
switch (figure.type) { switch (figure.type) {
case 'lattice': case 'lattice':
var cols = figure.verticesPerRow; var cols = figure.verticesPerRow;
var rows = (ps.length / cols) | 0; rows = (ps.length / cols) | 0;
for (var row = 1; row < rows; row++) { for (var row = 1; row < rows; row++) {
var offset = row * cols + 1; var offset = row * cols + 1;
for (var col = 1; col < cols; col++, offset++) { for (var col = 1; col < cols; col++, offset++) {

View File

@ -112,7 +112,8 @@ var Annotation = (function AnnotationClosure() {
var isInvalid = false; var isInvalid = false;
var numPositive = 0; var numPositive = 0;
for (var i = 0; i < dashArrayLength; i++) { for (var i = 0; i < dashArrayLength; i++) {
if (!(+dashArray[i] >= 0)) { var validNumber = (+dashArray[i] >= 0);
if (!validNumber) {
isInvalid = true; isInvalid = true;
break; break;
} else if (dashArray[i] > 0) { } else if (dashArray[i] > 0) {
@ -673,10 +674,12 @@ var TextAnnotation = (function TextAnnotationClosure() {
var content = document.createElement('div'); var content = document.createElement('div');
content.className = 'annotTextContent'; content.className = 'annotTextContent';
content.setAttribute('hidden', true); content.setAttribute('hidden', true);
var i, ii;
if (item.hasBgColor) { if (item.hasBgColor) {
var color = item.color; var color = item.color;
var rgb = []; var rgb = [];
for (var i = 0; i < 3; ++i) { for (i = 0; i < 3; ++i) {
// Enlighten the color (70%) // Enlighten the color (70%)
var c = Math.round(color[i] * 255); var c = Math.round(color[i] * 255);
rgb[i] = Math.round((255 - c) * 0.7) + c; rgb[i] = Math.round((255 - c) * 0.7) + c;
@ -693,7 +696,7 @@ var TextAnnotation = (function TextAnnotationClosure() {
} else { } else {
var e = document.createElement('span'); var e = document.createElement('span');
var lines = item.content.split(/(?:\r\n?|\n)/); var lines = item.content.split(/(?:\r\n?|\n)/);
for (var i = 0, ii = lines.length; i < ii; ++i) { for (i = 0, ii = lines.length; i < ii; ++i) {
var line = lines[i]; var line = lines[i];
e.appendChild(document.createTextNode(line)); e.appendChild(document.createTextNode(line));
if (i < (ii - 1)) { if (i < (ii - 1)) {

View File

@ -85,10 +85,10 @@ var ColorSpace = (function ColorSpaceClosure() {
var rgbBuf = null; var rgbBuf = null;
var numComponentColors = 1 << bpc; var numComponentColors = 1 << bpc;
var needsResizing = originalHeight != height || originalWidth != width; var needsResizing = originalHeight != height || originalWidth != width;
var i, ii;
if (this.isPassthrough(bpc)) { if (this.isPassthrough(bpc)) {
rgbBuf = comps; rgbBuf = comps;
} else if (this.numComps === 1 && count > numComponentColors && } else if (this.numComps === 1 && count > numComponentColors &&
this.name !== 'DeviceGray' && this.name !== 'DeviceRGB') { this.name !== 'DeviceGray' && this.name !== 'DeviceRGB') {
// Optimization: create a color map when there is just one component and // Optimization: create a color map when there is just one component and
@ -102,18 +102,20 @@ var ColorSpace = (function ColorSpaceClosure() {
// we are reparsing colorspaces too much?). // we are reparsing colorspaces too much?).
var allColors = bpc <= 8 ? new Uint8Array(numComponentColors) : var allColors = bpc <= 8 ? new Uint8Array(numComponentColors) :
new Uint16Array(numComponentColors); new Uint16Array(numComponentColors);
for (var i = 0; i < numComponentColors; i++) { var key;
for (i = 0; i < numComponentColors; i++) {
allColors[i] = i; allColors[i] = i;
} }
var colorMap = new Uint8Array(numComponentColors * 3); var colorMap = new Uint8Array(numComponentColors * 3);
this.getRgbBuffer(allColors, 0, numComponentColors, colorMap, 0, bpc, this.getRgbBuffer(allColors, 0, numComponentColors, colorMap, 0, bpc,
/* alpha01 = */ 0); /* alpha01 = */ 0);
var destPos, rgbPos;
if (!needsResizing) { if (!needsResizing) {
// Fill in the RGB values directly into |dest|. // Fill in the RGB values directly into |dest|.
var destPos = 0; destPos = 0;
for (var i = 0; i < count; ++i) { for (i = 0; i < count; ++i) {
var key = comps[i] * 3; key = comps[i] * 3;
dest[destPos++] = colorMap[key]; dest[destPos++] = colorMap[key];
dest[destPos++] = colorMap[key + 1]; dest[destPos++] = colorMap[key + 1];
dest[destPos++] = colorMap[key + 2]; dest[destPos++] = colorMap[key + 2];
@ -121,9 +123,9 @@ var ColorSpace = (function ColorSpaceClosure() {
} }
} else { } else {
rgbBuf = new Uint8Array(count * 3); rgbBuf = new Uint8Array(count * 3);
var rgbPos = 0; rgbPos = 0;
for (var i = 0; i < count; ++i) { for (i = 0; i < count; ++i) {
var key = comps[i] * 3; key = comps[i] * 3;
rgbBuf[rgbPos++] = colorMap[key]; rgbBuf[rgbPos++] = colorMap[key];
rgbBuf[rgbPos++] = colorMap[key + 1]; rgbBuf[rgbPos++] = colorMap[key + 1];
rgbBuf[rgbPos++] = colorMap[key + 2]; rgbBuf[rgbPos++] = colorMap[key + 2];
@ -146,9 +148,9 @@ var ColorSpace = (function ColorSpaceClosure() {
rgbBuf = PDFImage.resize(rgbBuf, bpc, 3, originalWidth, rgbBuf = PDFImage.resize(rgbBuf, bpc, 3, originalWidth,
originalHeight, width, height); originalHeight, width, height);
} }
var rgbPos = 0; rgbPos = 0;
var destPos = 0; destPos = 0;
for (var i = 0, ii = width * actualHeight; i < ii; i++) { for (i = 0, ii = width * actualHeight; i < ii; i++) {
dest[destPos++] = rgbBuf[rgbPos++]; dest[destPos++] = rgbBuf[rgbPos++];
dest[destPos++] = rgbBuf[rgbPos++]; dest[destPos++] = rgbBuf[rgbPos++];
dest[destPos++] = rgbBuf[rgbPos++]; dest[destPos++] = rgbBuf[rgbPos++];
@ -174,6 +176,7 @@ var ColorSpace = (function ColorSpaceClosure() {
ColorSpace.fromIR = function ColorSpace_fromIR(IR) { ColorSpace.fromIR = function ColorSpace_fromIR(IR) {
var name = isArray(IR) ? IR[0] : IR; var name = isArray(IR) ? IR[0] : IR;
var whitePoint, blackPoint;
switch (name) { switch (name) {
case 'DeviceGrayCS': case 'DeviceGrayCS':
@ -183,8 +186,8 @@ var ColorSpace = (function ColorSpaceClosure() {
case 'DeviceCmykCS': case 'DeviceCmykCS':
return this.singletons.cmyk; return this.singletons.cmyk;
case 'CalGrayCS': case 'CalGrayCS':
var whitePoint = IR[1].WhitePoint; whitePoint = IR[1].WhitePoint;
var blackPoint = IR[1].BlackPoint; blackPoint = IR[1].BlackPoint;
var gamma = IR[1].Gamma; var gamma = IR[1].Gamma;
return new CalGrayCS(whitePoint, blackPoint, gamma); return new CalGrayCS(whitePoint, blackPoint, gamma);
case 'PatternCS': case 'PatternCS':
@ -206,8 +209,8 @@ var ColorSpace = (function ColorSpaceClosure() {
return new AlternateCS(numComps, ColorSpace.fromIR(alt), return new AlternateCS(numComps, ColorSpace.fromIR(alt),
PDFFunction.fromIR(tintFnIR)); PDFFunction.fromIR(tintFnIR));
case 'LabCS': case 'LabCS':
var whitePoint = IR[1].WhitePoint; whitePoint = IR[1].WhitePoint;
var blackPoint = IR[1].BlackPoint; blackPoint = IR[1].BlackPoint;
var range = IR[1].Range; var range = IR[1].Range;
return new LabCS(whitePoint, blackPoint, range); return new LabCS(whitePoint, blackPoint, range);
default: default:
@ -252,6 +255,7 @@ var ColorSpace = (function ColorSpaceClosure() {
} else if (isArray(cs)) { } else if (isArray(cs)) {
mode = cs[0].name; mode = cs[0].name;
this.mode = mode; this.mode = mode;
var numComps, params;
switch (mode) { switch (mode) {
case 'DeviceGray': case 'DeviceGray':
@ -264,14 +268,14 @@ var ColorSpace = (function ColorSpaceClosure() {
case 'CMYK': case 'CMYK':
return 'DeviceCmykCS'; return 'DeviceCmykCS';
case 'CalGray': case 'CalGray':
var params = cs[1].getAll(); params = cs[1].getAll();
return ['CalGrayCS', params]; return ['CalGrayCS', params];
case 'CalRGB': case 'CalRGB':
return 'DeviceRgbCS'; return 'DeviceRgbCS';
case 'ICCBased': case 'ICCBased':
var stream = xref.fetchIfRef(cs[1]); var stream = xref.fetchIfRef(cs[1]);
var dict = stream.dict; var dict = stream.dict;
var numComps = dict.get('N'); numComps = dict.get('N');
if (numComps == 1) { if (numComps == 1) {
return 'DeviceGrayCS'; return 'DeviceGrayCS';
} else if (numComps == 3) { } else if (numComps == 3) {
@ -298,7 +302,7 @@ var ColorSpace = (function ColorSpaceClosure() {
case 'Separation': case 'Separation':
case 'DeviceN': case 'DeviceN':
var name = cs[1]; var name = cs[1];
var numComps = 1; numComps = 1;
if (isName(name)) { if (isName(name)) {
numComps = 1; numComps = 1;
} else if (isArray(name)) { } else if (isArray(name)) {
@ -308,7 +312,7 @@ var ColorSpace = (function ColorSpaceClosure() {
var tintFnIR = PDFFunction.getIR(xref, xref.fetchIfRef(cs[3])); var tintFnIR = PDFFunction.getIR(xref, xref.fetchIfRef(cs[3]));
return ['AlternateCS', numComps, alt, tintFnIR]; return ['AlternateCS', numComps, alt, tintFnIR];
case 'Lab': case 'Lab':
var params = cs[1].getAll(); params = cs[1].getAll();
return ['LabCS', params]; return ['LabCS', params];
default: default:
error('unimplemented color space object "' + mode + '"'); error('unimplemented color space object "' + mode + '"');
@ -403,13 +407,14 @@ var AlternateCS = (function AlternateCSClosure() {
var numComps = this.numComps; var numComps = this.numComps;
var scaled = new Float32Array(numComps); var scaled = new Float32Array(numComps);
for (var i = 0; i < count; i++) { var i, j;
for (var j = 0; j < numComps; j++) { for (i = 0; i < count; i++) {
for (j = 0; j < numComps; j++) {
scaled[j] = src[srcOffset++] * scale; scaled[j] = src[srcOffset++] * scale;
} }
var tinted = tintFn(scaled); var tinted = tintFn(scaled);
if (usesZeroToOneRange) { if (usesZeroToOneRange) {
for (var j = 0; j < baseNumComps; j++) { for (j = 0; j < baseNumComps; j++) {
baseBuf[pos++] = tinted[j] * 255; baseBuf[pos++] = tinted[j] * 255;
} }
} else { } else {

View File

@ -37,20 +37,21 @@ function readCharset(aStream, aCharstrings) {
var format = aStream.getByte(); var format = aStream.getByte();
var count = aCharstrings.length - 1; var count = aCharstrings.length - 1;
var i, sid;
if (format === 0) { if (format === 0) {
charset['.notdef'] = readCharstringEncoding(aCharstrings[0]); charset['.notdef'] = readCharstringEncoding(aCharstrings[0]);
for (var i = 1; i < count + 1; i++) { for (i = 1; i < count + 1; i++) {
var sid = aStream.getByte() << 8 | aStream.getByte(); sid = aStream.getByte() << 8 | aStream.getByte();
charset[CFFStrings[sid]] = readCharstringEncoding(aCharstrings[i]); charset[CFFStrings[sid]] = readCharstringEncoding(aCharstrings[i]);
} }
} else if (format == 1) { } else if (format == 1) {
for (var i = 1; i < count + 1; i++) { for (i = 1; i < count + 1; i++) {
var first = aStream.getByte(); var first = aStream.getByte();
first = (first << 8) | aStream.getByte(); first = (first << 8) | aStream.getByte();
var numLeft = aStream.getByte(); var numLeft = aStream.getByte();
for (var j = 0; j <= numLeft; j++) { for (var j = 0; j <= numLeft; j++) {
var sid = first++; sid = first++;
charset[CFFStrings[sid]] = readCharstringEncoding(aCharstrings[j]); charset[CFFStrings[sid]] = readCharstringEncoding(aCharstrings[j]);
} }
} }
@ -223,7 +224,8 @@ function readFontIndexData(aStream, aIsByte) {
} }
var offsets = []; var offsets = [];
for (var i = 0; i < count + 1; i++) { var i;
for (i = 0; i < count + 1; i++) {
offsets.push(getNextOffset()); offsets.push(getNextOffset());
} }
@ -233,7 +235,7 @@ function readFontIndexData(aStream, aIsByte) {
// Now extract the objects // Now extract the objects
var relativeOffset = aStream.pos; var relativeOffset = aStream.pos;
var objects = []; var objects = [];
for (var i = 0; i < count; i++) { for (i = 0; i < count; i++) {
var offset = offsets[i]; var offset = offsets[i];
aStream.pos = relativeOffset + offset - 1; aStream.pos = relativeOffset + offset - 1;
@ -332,14 +334,15 @@ var Type2Parser = function type2Parser(aFilePath) {
dump('strings: ' + strings); dump('strings: ' + strings);
// Fill up the Strings dictionary with the new unique strings // Fill up the Strings dictionary with the new unique strings
for (var i = 0; i < strings.length; i++) { var i;
for (i = 0; i < strings.length; i++) {
CFFStrings.push(strings[i].join('')); CFFStrings.push(strings[i].join(''));
} }
// Parse the TopDict operator // Parse the TopDict operator
var objects = []; var objects = [];
var count = topDict.length; var count = topDict.length;
for (var i = 0; i < count; i++) { for (i = 0; i < count; i++) {
parseAsToken(topDict[i], CFFDictDataMap); parseAsToken(topDict[i], CFFDictDataMap);
} }
@ -356,7 +359,7 @@ var Type2Parser = function type2Parser(aFilePath) {
aStream.pos = priv.offset; aStream.pos = priv.offset;
var privateDict = []; var privateDict = [];
for (var i = 0; i < priv.size; i++) { for (i = 0; i < priv.size; i++) {
privateDict.push(aStream.getByte()); privateDict.push(aStream.getByte());
} }
dump('privateData:' + privateDict); dump('privateData:' + privateDict);

View File

@ -27,8 +27,9 @@ var PDFFunction = (function PDFFunctionClosure() {
return { return {
getSampleArray: function PDFFunction_getSampleArray(size, outputSize, bps, getSampleArray: function PDFFunction_getSampleArray(size, outputSize, bps,
str) { str) {
var i, ii;
var length = 1; var length = 1;
for (var i = 0, ii = size.length; i < ii; i++) { for (i = 0, ii = size.length; i < ii; i++) {
length *= size[i]; length *= size[i];
} }
length *= outputSize; length *= outputSize;
@ -41,7 +42,7 @@ var PDFFunction = (function PDFFunctionClosure() {
var strBytes = str.getBytes((length * bps + 7) / 8); var strBytes = str.getBytes((length * bps + 7) / 8);
var strIdx = 0; var strIdx = 0;
for (var i = 0; i < length; i++) { for (i = 0; i < length; i++) {
while (codeSize < bps) { while (codeSize < bps) {
codeBuf <<= 8; codeBuf <<= 8;
codeBuf |= strBytes[strIdx++]; codeBuf |= strBytes[strIdx++];
@ -184,13 +185,14 @@ var PDFFunction = (function PDFFunctionClosure() {
var cubeVertices = 1 << m; var cubeVertices = 1 << m;
var cubeN = new Float64Array(cubeVertices); var cubeN = new Float64Array(cubeVertices);
var cubeVertex = new Uint32Array(cubeVertices); var cubeVertex = new Uint32Array(cubeVertices);
for (var j = 0; j < cubeVertices; j++) { var i, j;
for (j = 0; j < cubeVertices; j++) {
cubeN[j] = 1; cubeN[j] = 1;
} }
var k = n, pos = 1; var k = n, pos = 1;
// Map x_i to y_j for 0 <= i < m using the sampled function. // Map x_i to y_j for 0 <= i < m using the sampled function.
for (var i = 0; i < m; ++i) { for (i = 0; i < m; ++i) {
// x_i' = min(max(x_i, Domain_2i), Domain_2i+1) // x_i' = min(max(x_i, Domain_2i), Domain_2i+1)
var domain_2i = domain[i][0]; var domain_2i = domain[i][0];
var domain_2i_1 = domain[i][1]; var domain_2i_1 = domain[i][1];
@ -211,7 +213,7 @@ var PDFFunction = (function PDFFunctionClosure() {
var n1 = e - e0; // (e - e0) / (e1 - e0); var n1 = e - e0; // (e - e0) / (e1 - e0);
var offset0 = e0 * k; var offset0 = e0 * k;
var offset1 = offset0 + k; // e1 * k var offset1 = offset0 + k; // e1 * k
for (var j = 0; j < cubeVertices; j++) { for (j = 0; j < cubeVertices; j++) {
if (j & pos) { if (j & pos) {
cubeN[j] *= n1; cubeN[j] *= n1;
cubeVertex[j] += offset1; cubeVertex[j] += offset1;
@ -226,10 +228,10 @@ var PDFFunction = (function PDFFunctionClosure() {
} }
var y = new Float64Array(n); var y = new Float64Array(n);
for (var j = 0; j < n; ++j) { for (j = 0; j < n; ++j) {
// Sum all cube vertices' samples portions // Sum all cube vertices' samples portions
var rj = 0; var rj = 0;
for (var i = 0; i < cubeVertices; i++) { for (i = 0; i < cubeVertices; i++) {
rj += samples[cubeVertex[i] + j] * cubeN[i]; rj += samples[cubeVertex[i] + j] * cubeN[i];
} }

View File

@ -237,9 +237,10 @@ function combineUrl(baseUrl, url) {
if (/^[a-z][a-z0-9+\-.]*:/i.test(url)) { if (/^[a-z][a-z0-9+\-.]*:/i.test(url)) {
return url; return url;
} }
var i;
if (url.charAt(0) == '/') { if (url.charAt(0) == '/') {
// absolute path // absolute path
var i = baseUrl.indexOf('://'); i = baseUrl.indexOf('://');
if (url.charAt(1) === '/') { if (url.charAt(1) === '/') {
++i; ++i;
} else { } else {
@ -248,7 +249,7 @@ function combineUrl(baseUrl, url) {
return baseUrl.substring(0, i) + url; return baseUrl.substring(0, i) + url;
} else { } else {
// relative path // relative path
var pathLength = baseUrl.length, i; var pathLength = baseUrl.length;
i = baseUrl.lastIndexOf('#'); i = baseUrl.lastIndexOf('#');
pathLength = i >= 0 ? i : pathLength; pathLength = i >= 0 ? i : pathLength;
i = baseUrl.lastIndexOf('?', pathLength); i = baseUrl.lastIndexOf('?', pathLength);
@ -1263,17 +1264,18 @@ var StatTimer = (function StatTimerClosure() {
delete this.started[name]; delete this.started[name];
}, },
toString: function StatTimer_toString() { toString: function StatTimer_toString() {
var i, ii;
var times = this.times; var times = this.times;
var out = ''; var out = '';
// Find the longest name for padding purposes. // Find the longest name for padding purposes.
var longest = 0; var longest = 0;
for (var i = 0, ii = times.length; i < ii; ++i) { for (i = 0, ii = times.length; i < ii; ++i) {
var name = times[i]['name']; var name = times[i]['name'];
if (name.length > longest) { if (name.length > longest) {
longest = name.length; longest = name.length;
} }
} }
for (var i = 0, ii = times.length; i < ii; ++i) { for (i = 0, ii = times.length; i < ii; ++i) {
var span = times[i]; var span = times[i];
var duration = span.end - span.start; var duration = span.end - span.start;
out += rpad(span['name'], ' ', longest) + ' ' + duration + 'ms\n'; out += rpad(span['name'], ' ', longest) + ' ' + duration + 'ms\n';

View File

@ -28,19 +28,20 @@ function downloadFile(file, url, callback, redirects) {
var completed = false; var completed = false;
var protocol = /^https:\/\//.test(url) ? https : http; var protocol = /^https:\/\//.test(url) ? https : http;
protocol.get(url, function (response) { protocol.get(url, function (response) {
var redirectTo;
if (response.statusCode === 301 || response.statusCode === 302 || if (response.statusCode === 301 || response.statusCode === 302 ||
response.statusCode === 307 || response.statusCode === 308) { response.statusCode === 307 || response.statusCode === 308) {
if (redirects > 10) { if (redirects > 10) {
callback('Too many redirects'); callback('Too many redirects');
} }
var redirectTo = response.headers.location; redirectTo = response.headers.location;
redirectTo = require('url').resolve(url, redirectTo); redirectTo = require('url').resolve(url, redirectTo);
downloadFile(file, redirectTo, callback, (redirects || 0) + 1); downloadFile(file, redirectTo, callback, (redirects || 0) + 1);
return; return;
} }
if (response.statusCode === 404 && url.indexOf('web.archive.org') < 0) { if (response.statusCode === 404 && url.indexOf('web.archive.org') < 0) {
// trying waybackmachine // trying waybackmachine
var redirectTo = 'http://web.archive.org/web/' + url; redirectTo = 'http://web.archive.org/web/' + url;
downloadFile(file, redirectTo, callback, (redirects || 0) + 1); downloadFile(file, redirectTo, callback, (redirects || 0) + 1);
return; return;
} }

View File

@ -1,50 +0,0 @@
/* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set shiftwidth=2 tabstop=2 autoindent cindent expandtab: */
/* Copyright 2012 Mozilla Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/* jshint node:true */
'use strict';
module.exports = {
reporter: function reporter(res) {
var len = 0;
var str = '';
res.forEach(function(r) {
var file = r.file;
var err = r.error;
switch (err.code) {
case 'W004': // variable is already defined
case 'W018': // confusing use of !
break;
default:
len++;
str += file + ': line ' + err.line + ', col ' +
err.character + ', ' + err.reason + '\n';
}
});
if (str) {
process.stdout.write(str + '\n' + len + ' error' +
((len === 1) ? '' : 's') + '\n');
process.exit(2);
} else {
process.stdout.write('files checked, no errors found\n');
process.exit(0);
}
}
};

View File

@ -438,10 +438,11 @@ function refTestPostHandler(req, res) {
res.writeHead(200, {'Content-Type': 'text/plain'}); res.writeHead(200, {'Content-Type': 'text/plain'});
res.end(); res.end();
var session;
if (pathname === '/tellMeToQuit') { if (pathname === '/tellMeToQuit') {
// finding by path // finding by path
var browserPath = parsedUrl.query.path; var browserPath = parsedUrl.query.path;
var session = sessions.filter(function (session) { session = sessions.filter(function (session) {
return session.config.path === browserPath; return session.config.path === browserPath;
})[0]; })[0];
monitorBrowserTimeout(session, null); monitorBrowserTimeout(session, null);
@ -463,7 +464,7 @@ function refTestPostHandler(req, res) {
var snapshot = data.snapshot; var snapshot = data.snapshot;
var lastPageNum = data.lastPageNum; var lastPageNum = data.lastPageNum;
var session = getSession(browser); session = getSession(browser);
monitorBrowserTimeout(session, handleSessionTimeout); monitorBrowserTimeout(session, handleSessionTimeout);
var taskResults = session.taskResults[id]; var taskResults = session.taskResults[id];
@ -720,4 +721,4 @@ var host = '127.0.0.1';
var options = parseOptions(); var options = parseOptions();
var stats; var stats;
main(); main();

View File

@ -75,14 +75,15 @@ var stdinBuffer = '', endOfStdin = false, stdinInitialized = false;
var stdinOnLineCallbacks = []; var stdinOnLineCallbacks = [];
function handleStdinBuffer() { function handleStdinBuffer() {
var callback;
if (endOfStdin) { if (endOfStdin) {
if (stdinBuffer && stdinOnLineCallbacks.length > 0) { if (stdinBuffer && stdinOnLineCallbacks.length > 0) {
var callback = stdinOnLineCallbacks.shift(); callback = stdinOnLineCallbacks.shift();
callback(stdinBuffer); callback(stdinBuffer);
stdinBuffer = null; stdinBuffer = null;
} }
while (stdinOnLineCallbacks.length > 0) { while (stdinOnLineCallbacks.length > 0) {
var callback = stdinOnLineCallbacks.shift(); callback = stdinOnLineCallbacks.shift();
callback(); callback();
} }
return; return;
@ -92,7 +93,7 @@ function handleStdinBuffer() {
if (i < 0) { if (i < 0) {
return; return;
} }
var callback = stdinOnLineCallbacks.shift(); callback = stdinOnLineCallbacks.shift();
var result = stdinBuffer.substring(0, i + 1); var result = stdinBuffer.substring(0, i + 1);
stdinBuffer = stdinBuffer.substring(i + 1); stdinBuffer = stdinBuffer.substring(i + 1);
callback(result); callback(result);
@ -143,4 +144,4 @@ exports.confirm = function confirm(message, callback) {
confirm(message, callback); confirm(message, callback);
} }
}); });
}; };

View File

@ -196,7 +196,7 @@ describe('font', function() {
expect(charset.charset[1]).toEqual('exclam'); expect(charset.charset[1]).toEqual('exclam');
// CID font // CID font
var charset = parser.parseCharsets(3, 2, new CFFStrings(), true); charset = parser.parseCharsets(3, 2, new CFFStrings(), true);
expect(charset.charset[1]).toEqual(2); expect(charset.charset[1]).toEqual(2);
}); });
@ -212,7 +212,7 @@ describe('font', function() {
expect(charset.charset).toEqual(['.notdef', 'quoteright', 'parenleft']); expect(charset.charset).toEqual(['.notdef', 'quoteright', 'parenleft']);
// CID font // CID font
var charset = parser.parseCharsets(3, 2, new CFFStrings(), true); charset = parser.parseCharsets(3, 2, new CFFStrings(), true);
expect(charset.charset).toEqual(['.notdef', 8, 9]); expect(charset.charset).toEqual(['.notdef', 8, 9]);
}); });
@ -229,7 +229,7 @@ describe('font', function() {
expect(charset.charset).toEqual(['.notdef', 'quoteright', 'parenleft']); expect(charset.charset).toEqual(['.notdef', 'quoteright', 'parenleft']);
// CID font // CID font
var charset = parser.parseCharsets(3, 2, new CFFStrings(), true); charset = parser.parseCharsets(3, 2, new CFFStrings(), true);
expect(charset.charset).toEqual(['.notdef', 8, 9]); expect(charset.charset).toEqual(['.notdef', 8, 9]);
}); });
@ -349,7 +349,7 @@ describe('font', function() {
var parser = new Type1Parser(stream); var parser = new Type1Parser(stream);
expect(parser.readNumberArray()).toEqual([1, 2]); expect(parser.readNumberArray()).toEqual([1, 2]);
// Variation on spacing. // Variation on spacing.
var stream = new StringStream('[ 1 2 ]'); stream = new StringStream('[ 1 2 ]');
parser = new Type1Parser(stream); parser = new Type1Parser(stream);
expect(parser.readNumberArray()).toEqual([1, 2]); expect(parser.readNumberArray()).toEqual([1, 2]);
}); });

View File

@ -58,17 +58,17 @@ if (typeof PDFJS === 'undefined') {
} }
function TypedArray(arg1) { function TypedArray(arg1) {
var result; var result, i, n;
if (typeof arg1 === 'number') { if (typeof arg1 === 'number') {
result = []; result = [];
for (var i = 0; i < arg1; ++i) { for (i = 0; i < arg1; ++i) {
result[i] = 0; result[i] = 0;
} }
} else if ('slice' in arg1) { } else if ('slice' in arg1) {
result = arg1.slice(0); result = arg1.slice(0);
} else { } else {
result = []; result = [];
for (var i = 0, n = arg1.length; i < n; ++i) { for (i = 0, n = arg1.length; i < n; ++i) {
result[i] = arg1[i]; result[i] = arg1[i];
} }
} }

View File

@ -211,10 +211,11 @@ var StepperManager = (function StepperManagerClosure() {
return stepper; return stepper;
}, },
selectStepper: function selectStepper(pageIndex, selectPanel) { selectStepper: function selectStepper(pageIndex, selectPanel) {
var i;
if (selectPanel) { if (selectPanel) {
this.manager.selectPanel(this); this.manager.selectPanel(this);
} }
for (var i = 0; i < steppers.length; ++i) { for (i = 0; i < steppers.length; ++i) {
var stepper = steppers[i]; var stepper = steppers[i];
if (stepper.pageIndex == pageIndex) { if (stepper.pageIndex == pageIndex) {
stepper.panel.removeAttribute('hidden'); stepper.panel.removeAttribute('hidden');
@ -223,7 +224,7 @@ var StepperManager = (function StepperManagerClosure() {
} }
} }
var options = stepperChooser.options; var options = stepperChooser.options;
for (var i = 0; i < options.length; ++i) { for (i = 0; i < options.length; ++i) {
var option = options[i]; var option = options[i];
option.selected = option.value == pageIndex; option.selected = option.value == pageIndex;
} }
@ -344,7 +345,7 @@ var Stepper = (function StepperClosure() {
var self = this; var self = this;
var chunk = document.createDocumentFragment(); var chunk = document.createDocumentFragment();
var operatorsToDisplay = Math.min(MAX_OPERATORS_COUNT, var operatorsToDisplay = Math.min(MAX_OPERATORS_COUNT,
operatorList.fnArray.length); operatorList.fnArray.length);
for (var i = this.operatorListIdx; i < operatorsToDisplay; i++) { for (var i = this.operatorListIdx; i < operatorsToDisplay; i++) {
var line = c('tr'); var line = c('tr');
line.className = 'line'; line.className = 'line';
@ -369,7 +370,7 @@ var Stepper = (function StepperClosure() {
if (fn in glyphCommands) { if (fn in glyphCommands) {
var glyphIndex = glyphCommands[fn]; var glyphIndex = glyphCommands[fn];
var glyphs = args[glyphIndex]; var glyphs = args[glyphIndex];
var decArgs = args.slice(); decArgs = args.slice();
var newArg; var newArg;
if (fn === 'showSpacedText') { if (fn === 'showSpacedText') {
newArg = []; newArg = [];

View File

@ -348,7 +348,7 @@ var PageView = function pageView(container, id, scale,
var x = 0, y = 0; var x = 0, y = 0;
var width = 0, height = 0, widthScale, heightScale; var width = 0, height = 0, widthScale, heightScale;
var changeOrientation = !!(this.rotation % 180); var changeOrientation = (this.rotation % 180 === 0 ? false : true);
var pageWidth = (changeOrientation ? this.height : this.width) / var pageWidth = (changeOrientation ? this.height : this.width) /
this.scale / CSS_UNITS; this.scale / CSS_UNITS;
var pageHeight = (changeOrientation ? this.width : this.height) / var pageHeight = (changeOrientation ? this.width : this.height) /

View File

@ -639,7 +639,7 @@ var PDFView = {
if (exception && exception.name === 'InvalidPDFException') { if (exception && exception.name === 'InvalidPDFException') {
// change error message also for other builds // change error message also for other builds
var loadingErrorMessage = mozL10n.get('invalid_file_error', null, loadingErrorMessage = mozL10n.get('invalid_file_error', null,
'Invalid or corrupted PDF file.'); 'Invalid or corrupted PDF file.');
//#if B2G //#if B2G
// window.alert(loadingErrorMessage); // window.alert(loadingErrorMessage);
@ -649,7 +649,7 @@ var PDFView = {
if (exception && exception.name === 'MissingPDFException') { if (exception && exception.name === 'MissingPDFException') {
// special message for missing PDF's // special message for missing PDF's
var loadingErrorMessage = mozL10n.get('missing_file_error', null, loadingErrorMessage = mozL10n.get('missing_file_error', null,
'Missing PDF file.'); 'Missing PDF file.');
//#if B2G //#if B2G
@ -1478,10 +1478,11 @@ var PDFView = {
} }
var alertNotReady = false; var alertNotReady = false;
var i, ii;
if (!this.pages.length) { if (!this.pages.length) {
alertNotReady = true; alertNotReady = true;
} else { } else {
for (var i = 0, ii = this.pages.length; i < ii; ++i) { for (i = 0, ii = this.pages.length; i < ii; ++i) {
if (!this.pages[i].pdfPage) { if (!this.pages[i].pdfPage) {
alertNotReady = true; alertNotReady = true;
break; break;
@ -1497,7 +1498,7 @@ var PDFView = {
var body = document.querySelector('body'); var body = document.querySelector('body');
body.setAttribute('data-mozPrintCallback', true); body.setAttribute('data-mozPrintCallback', true);
for (var i = 0, ii = this.pages.length; i < ii; ++i) { for (i = 0, ii = this.pages.length; i < ii; ++i) {
this.pages[i].beforePrint(); this.pages[i].beforePrint();
} }
}, },
@ -1511,14 +1512,15 @@ var PDFView = {
rotatePages: function pdfViewRotatePages(delta) { rotatePages: function pdfViewRotatePages(delta) {
var currentPage = this.pages[this.page - 1]; var currentPage = this.pages[this.page - 1];
var i, l;
this.pageRotation = (this.pageRotation + 360 + delta) % 360; this.pageRotation = (this.pageRotation + 360 + delta) % 360;
for (var i = 0, l = this.pages.length; i < l; i++) { for (i = 0, l = this.pages.length; i < l; i++) {
var page = this.pages[i]; var page = this.pages[i];
page.update(page.scale, this.pageRotation); page.update(page.scale, this.pageRotation);
} }
for (var i = 0, l = this.thumbnails.length; i < l; i++) { for (i = 0, l = this.thumbnails.length; i < l; i++) {
var thumb = this.thumbnails[i]; var thumb = this.thumbnails[i];
thumb.update(this.pageRotation); thumb.update(this.pageRotation);
} }