Browse Source

Merge branch 'master' into hmm

sbarman 14 years ago
parent
commit
881af4695e
  1. 71
      pdf.js
  2. 28
      test/driver.js

71
pdf.js

@ -4149,7 +4149,11 @@ var CanvasExtraState = (function() { @@ -4149,7 +4149,11 @@ var CanvasExtraState = (function() {
constructor.prototype = {
clone: function canvasextra_clone() {
return Object.create(this);
}
},
setCurrentPoint: function canvasextra_setCurrentPoint(x, y) {
this.x = x;
this.y = y;
},
};
return constructor;
})();
@ -4276,18 +4280,24 @@ var CanvasGraphics = (function() { @@ -4276,18 +4280,24 @@ var CanvasGraphics = (function() {
// Path
moveTo: function(x, y) {
this.ctx.moveTo(x, y);
this.current.setCurrentPoint(x, y);
},
lineTo: function(x, y) {
this.ctx.lineTo(x, y);
this.current.setCurrentPoint(x, y);
},
curveTo: function(x1, y1, x2, y2, x3, y3) {
this.ctx.bezierCurveTo(x1, y1, x2, y2, x3, y3);
this.current.setCurrentPoint(x3, y3);
},
curveTo2: function(x2, y2, x3, y3) {
TODO("'v' operator: need current point in gfx context");
var current = this.current;
this.ctx.bezierCurveTo(current.x, current.y, x2, y2, x3, y3);
current.setCurrentPoint(x3, y3);
},
curveTo3: function(x1, y1, x3, y3) {
this.curveTo(x1, y1, x3, y3, x3, y3);
this.current.setCurrentPoint(x3, y3);
},
closePath: function() {
this.ctx.closePath();
@ -5704,7 +5714,7 @@ var PDFFunction = (function() { @@ -5704,7 +5714,7 @@ var PDFFunction = (function() {
if (!typeFn)
error('Unknown type of function');
typeFn.call(this, fn, dict);
typeFn.call(this, fn, dict, xref);
};
constructor.prototype = {
@ -5849,9 +5859,58 @@ var PDFFunction = (function() { @@ -5849,9 +5859,58 @@ var PDFFunction = (function() {
return out;
}
},
constructStiched: function() {
TODO('unhandled type of function');
this.func = function() { return [255, 105, 180]; }
constructStiched: function(fn, dict, xref) {
var domain = dict.get('Domain');
var range = dict.get('Range');
if (!domain)
error('No domain');
var inputSize = domain.length / 2;
if (inputSize != 1)
error('Bad domain for stiched function');
var fnRefs = dict.get('Functions');
var fns = [];
for (var i = 0, ii = fnRefs.length; i < ii; ++i)
fns.push(new PDFFunction(xref, xref.fetchIfRef(fnRefs[i])));
var bounds = dict.get('Bounds');
var encode = dict.get('Encode');
this.func = function(args) {
var clip = function(v, min, max) {
if (v > max)
v = max;
else if (v < min)
v = min;
return v;
}
// clip to domain
var v = clip(args[0], domain[0], domain[1]);
// calulate which bound the value is in
for (var i = 0, ii = bounds.length; i < ii; ++i) {
if (v < bounds[i])
break;
}
// encode value into domain of function
var dmin = domain[0];
if (i > 0)
dmin = bounds[i - 1];
var dmax = domain[1];
if (i < bounds.length)
dmax = bounds[i];
var rmin = encode[2 * i];
var rmax = encode[2 * i + 1];
var v2 = rmin + (v - dmin) * (rmax - rmin) / (dmax - dmin);
// call the appropropriate function
return fns[i].func([v2]);
}
},
constructPostScript: function() {
TODO('unhandled type of function');

28
test/driver.js

@ -80,10 +80,19 @@ function nextTask() { @@ -80,10 +80,19 @@ function nextTask() {
}
function isLastPage(task) {
return (!task.pdfDoc || (task.pageNum > task.pdfDoc.numPages));
return (task.pageNum > task.pdfDoc.numPages);
}
function nextPage(task, loadError) {
var failure = loadError || '';
if (!task.pdfDoc) {
sendTaskResult(canvas.toDataURL('image/png'), task, failure);
log('done' + (failure ? ' (failed !: ' + failure + ')' : '') + '\n');
++currentTaskIdx, nextTask();
return;
}
if (isLastPage(task)) {
if (++task.round < task.rounds) {
log(' Round ' + (1 + task.round) + '\n');
@ -94,15 +103,13 @@ function nextPage(task, loadError) { @@ -94,15 +103,13 @@ function nextPage(task, loadError) {
}
}
var failure = loadError || '';
var ctx = null;
var page = null;
if (!failure) {
try {
log(' loading page ' + task.pageNum + '/' + task.pdfDoc.numPages +
'... ');
ctx = canvas.getContext('2d');
var ctx = canvas.getContext('2d');
page = task.pdfDoc.getPage(task.pageNum);
var pdfToCssUnitsCoef = 96.0 / 72.0;
@ -118,7 +125,8 @@ function nextPage(task, loadError) { @@ -118,7 +125,8 @@ function nextPage(task, loadError) {
function(e) {
snapshotCurrentPage(page, task, (!failure && e) ?
('render : ' + e) : failure);
});
}
);
} catch (e) {
failure = 'page setup : ' + e.toString();
}
@ -139,7 +147,8 @@ function snapshotCurrentPage(page, task, failure) { @@ -139,7 +147,8 @@ function snapshotCurrentPage(page, task, failure) {
// Set up the next request
var backoff = (inFlightRequests > 0) ? inFlightRequests * 10 : 0;
setTimeout(function() {
setTimeout(
function() {
++task.pageNum, nextPage(task);
},
backoff
@ -154,7 +163,8 @@ function sendQuitRequest() { @@ -154,7 +163,8 @@ function sendQuitRequest() {
function quitApp() {
log('Done !');
document.body.innerHTML = 'Tests are finished. <h1>CLOSE ME!</h1>';
document.body.innerHTML = 'Tests are finished. <h1>CLOSE ME!</h1>' +
document.body.innerHTML;
if (window.SpecialPowers) {
SpecialPowers.quitApplication();
} else {
@ -176,7 +186,7 @@ var inFlightRequests = 0; @@ -176,7 +186,7 @@ var inFlightRequests = 0;
function sendTaskResult(snapshot, task, failure) {
var result = { browser: browser,
id: task.id,
numPages: task.pdfDoc.numPages,
numPages: task.pdfDoc ? task.pdfDoc.numPages : 0,
failure: failure,
file: task.file,
round: task.round,

Loading…
Cancel
Save