Merge branch '07254bb0a5'

This commit is contained in:
notmasteryet 2011-09-15 22:16:09 -05:00
commit f57972d925
11 changed files with 77 additions and 63 deletions

4
pdf.js
View File

@ -6061,8 +6061,8 @@ var PDFImage = (function() {
this.decode = dict.get('Decode', 'D');
var mask = xref.fetchIfRef(image.dict.get('Mask'));
var smask = xref.fetchIfRef(image.dict.get('SMask'));
var mask = xref.fetchIfRef(dict.get('Mask'));
var smask = xref.fetchIfRef(dict.get('SMask'));
if (mask) {
TODO('masked images');

View File

@ -8,6 +8,7 @@
'use strict';
var appPath, browser, canvas, currentTaskIdx, manifest, stdout;
var inFlightRequests = 0;
function queryParams() {
var qs = window.location.search.substring(1);
@ -42,7 +43,8 @@ function load() {
if (r.readyState == 4) {
log('done\n');
manifest = JSON.parse(r.responseText);
currentTaskIdx = 0, nextTask();
currentTaskIdx = 0;
nextTask();
}
};
r.send(null);
@ -73,7 +75,8 @@ function nextTask() {
failure = 'load PDF doc : ' + e.toString();
}
task.pageNum = 1, nextPage(task, failure);
task.pageNum = 1;
nextPage(task, failure);
}
};
r.send(null);
@ -89,7 +92,8 @@ function nextPage(task, loadError) {
if (!task.pdfDoc) {
sendTaskResult(canvas.toDataURL('image/png'), task, failure);
log('done' + (failure ? ' (failed !: ' + failure + ')' : '') + '\n');
++currentTaskIdx, nextTask();
++currentTaskIdx;
nextTask();
return;
}
@ -98,7 +102,8 @@ function nextPage(task, loadError) {
log(' Round ' + (1 + task.round) + '\n');
task.pageNum = 1;
} else {
++currentTaskIdx, nextTask();
++currentTaskIdx;
nextTask();
return;
}
}
@ -123,7 +128,7 @@ function nextPage(task, loadError) {
page.startRendering(
ctx,
function(e) {
snapshotCurrentPage(page, task, (!failure && e) ?
snapshotCurrentPage(task, (!failure && e) ?
('render : ' + e) : failure);
}
);
@ -135,11 +140,11 @@ function nextPage(task, loadError) {
if (failure) {
// Skip right to snapshotting if there was a failure, since the
// fonts might be in an inconsistent state.
snapshotCurrentPage(page, task, failure);
snapshotCurrentPage(task, failure);
}
}
function snapshotCurrentPage(page, task, failure) {
function snapshotCurrentPage(task, failure) {
log('done, snapshotting... ');
sendTaskResult(canvas.toDataURL('image/png'), task, failure);
@ -149,7 +154,8 @@ function snapshotCurrentPage(page, task, failure) {
var backoff = (inFlightRequests > 0) ? inFlightRequests * 10 : 0;
setTimeout(
function() {
++task.pageNum, nextPage(task);
++task.pageNum;
nextPage(task);
},
backoff
);
@ -182,7 +188,6 @@ function done() {
}
}
var inFlightRequests = 0;
function sendTaskResult(snapshot, task, failure) {
var result = { browser: browser,
id: task.id,
@ -201,7 +206,7 @@ function sendTaskResult(snapshot, task, failure) {
if (r.readyState == 4) {
inFlightRequests--;
}
}
};
document.getElementById('inFlightCount').innerHTML = inFlightRequests++;
r.send(JSON.stringify(result));
}

View File

@ -560,7 +560,7 @@ var CFFDictDataMap = {
'18': {
name: 'ExpansionFactor'
},
'9': {
'19': {
name: 'initialRandomSeed'
},
'20': {

View File

@ -69,7 +69,7 @@ function readCharstringEncoding(aString) {
} else if (value <= 31) {
token = CFFEncodingMap[value];
} else if (value < 247) {
token = parseInt(value) - 139;
token = parseInt(value, 10) - 139;
} else if (value < 251) {
token = ((value - 247) * 256) + aString[i++] + 108;
} else if (value < 255) {
@ -113,7 +113,7 @@ function readFontDictData(aString, aMap) {
while (!parsed) {
var byte = aString[i++];
var nibbles = [parseInt(byte / 16), parseInt(byte % 16)];
var nibbles = [parseInt(byte / 16, 10), parseInt(byte % 16, 10)];
for (var j = 0; j < nibbles.length; j++) {
var nibble = nibbles[j];
switch (nibble) {
@ -144,7 +144,7 @@ function readFontDictData(aString, aMap) {
} else if (value <= 31) {
token = aMap[value];
} else if (value <= 246) {
token = parseInt(value) - 139;
token = parseInt(value, 10) - 139;
} else if (value <= 250) {
token = ((value - 247) * 256) + aString[i++] + 108;
} else if (value <= 254) {
@ -193,7 +193,7 @@ function readFontIndexData(aStream, aIsByte) {
}
error(offsize + ' is not a valid offset size');
return null;
};
}
var offsets = [];
for (var i = 0; i < count + 1; i++)
@ -236,7 +236,7 @@ var Type2Parser = function(aFilePath) {
function dump(aStr) {
if (debug)
log(aStr);
};
}
function parseAsToken(aString, aMap) {
var decoded = readFontDictData(aString, aMap);
@ -277,7 +277,7 @@ var Type2Parser = function(aFilePath) {
}
}
}
};
}
this.parse = function(aStream) {
font.set('major', aStream.getByte());
@ -353,7 +353,7 @@ var Type2Parser = function(aFilePath) {
aStream.pos = charsetEntry;
var charset = readCharset(aStream, charStrings);
}
}
};
};
/*

View File

@ -1,6 +1,8 @@
/* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set shiftwidth=2 tabstop=2 autoindent cindent expandtab: */
'use strict';
// Checking if the typed arrays are supported
(function() {
if (typeof Uint8Array !== 'undefined')
@ -10,8 +12,9 @@
return this.slice(start, end);
}
function set_(array, offset) {
if (arguments.length < 2) offset = 0;
function set_function(array, offset) {
if (arguments.length < 2)
offset = 0;
for (var i = 0, n = array.length; i < n; ++i, ++offset)
this[offset] = array[i] & 0xFF;
}
@ -19,15 +22,17 @@
function TypedArray(arg1) {
var result;
if (typeof arg1 === 'number') {
result = new Array(arg1);
for (var i = 0; i < arg1; ++i)
result[i] = 0;
result = [];
for (var i = 0; i < arg1; ++i)
result[i] = 0;
} else
result = arg1.slice(0);
result = arg1.slice(0);
result.subarray = subarray;
result.buffer = result;
result.byteLength = result.length;
result.set = set_;
result.set = set_function;
if (typeof arg1 === 'object' && arg1.buffer)
result.buffer = arg1.buffer;

View File

@ -98,7 +98,7 @@ var PDFView = {
},
get page() {
return parseInt(document.location.hash.substring(1)) || 1;
return parseInt(document.location.hash.substring(1), 10) || 1;
},
open: function(url, scale) {
@ -170,7 +170,7 @@ var PDFView = {
}
this.setScale(scale || kDefaultScale, true);
this.page = parseInt(document.location.hash.substring(1)) || 1;
this.page = parseInt(document.location.hash.substring(1), 10) || 1;
this.pagesRefMap = pagesRefMap;
this.destinations = pdf.catalog.destinations;
if (pdf.catalog.documentOutline) {
@ -209,7 +209,7 @@ var PDFView = {
var currentHeight = kBottomMargin;
var windowTop = window.pageYOffset;
for (var i = 1; i <= pages.length; i++) {
for (var i = 1; i <= pages.length; ++i) {
var page = pages[i - 1];
var pageHeight = page.height * page.scale + kBottomMargin;
if (currentHeight + pageHeight > windowTop)
@ -219,10 +219,11 @@ var PDFView = {
}
var windowBottom = window.pageYOffset + window.innerHeight;
for (; i <= pages.length && currentHeight < windowBottom; i++) {
var page = pages[i - 1];
visiblePages.push({ id: page.id, y: currentHeight, view: page });
currentHeight += page.height * page.scale + kBottomMargin;
for (; i <= pages.length && currentHeight < windowBottom; ++i) {
var singlePage = pages[i - 1];
visiblePages.push({ id: singlePage.id, y: currentHeight,
view: singlePage });
currentHeight += singlePage.height * singlePage.scale + kBottomMargin;
}
return visiblePages;
@ -256,13 +257,13 @@ var PageView = function(container, content, id, width, height,
div.removeAttribute('data-loaded');
};
function setupLinks(canvas, content, scale) {
function setupLinks(content, scale) {
function bindLink(link, dest) {
link.onclick = function() {
if (dest)
PDFView.navigateTo(dest);
return false;
}
};
}
var links = content.getLinks();
for (var i = 0; i < links.length; i++) {
@ -283,8 +284,6 @@ var PageView = function(container, content, id, width, height,
var width = 0, height = 0, widthScale, heightScale;
var scale = 0;
switch (dest[1].name) {
default:
return;
case 'XYZ':
x = dest[2];
y = dest[3];
@ -315,6 +314,8 @@ var PageView = function(container, content, id, width, height,
height / kCssUnits;
scale = Math.min(widthScale, heightScale);
break;
default:
return;
}
var boundingRect = [
@ -369,7 +370,7 @@ var PageView = function(container, content, id, width, height,
stats.begin = Date.now();
this.content.startRendering(ctx, this.updateStats);
setupLinks(canvas, this.content, this.scale);
setupLinks(this.content, this.scale);
div.setAttribute('data-loaded', true);
return true;

View File

@ -39,7 +39,7 @@ function GradientProxy(cmdQueue, x0, y0, x1, y1) {
cmdQueue.push(['$createLinearGradient', [x0, y0, x1, y1]]);
this.addColorStop = function(i, rgba) {
cmdQueue.push(['$addColorStop', [i, rgba]]);
}
};
}
// Really simple PatternProxy.
@ -72,7 +72,7 @@ function CanvasProxy(width, height) {
throw 'CanvasProxy can only provide a 2d context.';
}
return ctx;
}
};
// Expose only the minimum of the canvas object - there is no dom to do
// more here.
@ -127,7 +127,7 @@ function CanvasProxy(width, height) {
return function() {
// console.log("funcCall", name)
cmdQueue.push([name, Array.prototype.slice.call(arguments)]);
}
};
}
var name;
for (var i = 0; i < ctxFunc.length; i++) {
@ -139,11 +139,11 @@ function CanvasProxy(width, height) {
ctx.createPattern = function(object, kind) {
return new PatternProxy(cmdQueue, object, kind);
}
};
ctx.createLinearGradient = function(x0, y0, x1, y1) {
return new GradientProxy(cmdQueue, x0, y0, x1, y1);
}
};
ctx.getImageData = function(x, y, w, h) {
return {
@ -151,11 +151,11 @@ function CanvasProxy(width, height) {
height: h,
data: Uint8ClampedArray(w * h * 4)
};
}
};
ctx.putImageData = function(data, x, y, width, height) {
cmdQueue.push(['$putImageData', [data, x, y, width, height]]);
}
};
ctx.drawImage = function(image, x, y, width, height,
sx, sy, swidth, sheight) {
@ -168,7 +168,7 @@ function CanvasProxy(width, height) {
} else {
throw 'unkown type to drawImage';
}
}
};
// Setup property access to `ctx`.
var ctxProp = {
@ -195,14 +195,14 @@ function CanvasProxy(width, height) {
function buildGetter(name) {
return function() {
return ctx['$' + name];
}
};
}
function buildSetter(name) {
return function(value) {
cmdQueue.push(['$', name, value]);
return ctx['$' + name] = value;
}
return (ctx['$' + name] = value);
};
}
// Setting the value to `stroke|fillStyle` needs special handling, as it
@ -215,9 +215,9 @@ function CanvasProxy(width, height) {
cmdQueue.push(['$' + name + 'Pattern', [value.id]]);
} else {
cmdQueue.push(['$', name, value]);
return ctx['$' + name] = value;
return (ctx['$' + name] = value);
}
}
};
}
for (var name in ctxProp) {

View File

@ -58,7 +58,7 @@ FontWorker.prototype = {
'fonts': function(data) {
// console.log("got processed fonts from worker", Object.keys(data));
for (name in data) {
for (var name in data) {
// Update the encoding property.
var font = Fonts.lookup(name);
font.properties = {
@ -176,7 +176,7 @@ function WorkerPDFDoc(canvas) {
// Copy over the imageData.
var len = imageRealData.length;
while (len--)
imgRealData[len] = imageRealData[len];
imgRealData[len] = imageRealData[len];
this.putImageData(imgData, x, y);
},
@ -273,7 +273,7 @@ function WorkerPDFDoc(canvas) {
},
'pdf_num_pages': function(data) {
this.numPages = parseInt(data);
this.numPages = parseInt(data, 10);
if (this.loadCallback) {
this.loadCallback();
}
@ -302,8 +302,8 @@ function WorkerPDFDoc(canvas) {
'setup_page': function(data) {
var size = data.split(',');
var canvas = this.canvas, ctx = this.ctx;
canvas.width = parseInt(size[0]);
canvas.height = parseInt(size[1]);
canvas.width = parseInt(size[0], 10);
canvas.height = parseInt(size[1], 10);
},
'fonts': function(data) {
@ -397,7 +397,7 @@ WorkerPDFDoc.prototype.open = function(url, callback) {
};
WorkerPDFDoc.prototype.showPage = function(numPage) {
this.numPage = parseInt(numPage);
this.numPage = parseInt(numPage, 10);
console.log('=== start rendering page ' + numPage + ' ===');
console.time('>>> total page display time:');
this.worker.postMessage(numPage);
@ -407,11 +407,12 @@ WorkerPDFDoc.prototype.showPage = function(numPage) {
};
WorkerPDFDoc.prototype.nextPage = function() {
if (this.numPage == this.numPages) return;
this.showPage(++this.numPage);
if (this.numPage != this.numPages)
this.showPage(++this.numPage);
};
WorkerPDFDoc.prototype.prevPage = function() {
if (this.numPage == 1) return;
this.showPage(--this.numPage);
if (this.numPage != 1)
this.showPage(--this.numPage);
};

View File

@ -25,3 +25,4 @@ var console = {
this.log('Timer:', name, Date.now() - time);
}
};

View File

@ -64,3 +64,4 @@ this.onmessage = function(event) {
throw 'Unkown action from worker: ' + data.action;
}
};

View File

@ -58,7 +58,7 @@ onmessage = function(event) {
console.time('compile');
// Let's try to render the first page...
var page = pdfDocument.getPage(parseInt(data));
var page = pdfDocument.getPage(parseInt(data, 10));
var pdfToCssUnitsCoef = 96.0 / 72.0;
var pageWidth = (page.mediaBox[2] - page.mediaBox[0]) * pdfToCssUnitsCoef;