Cleaned up code, renamed PDFFunction class

This commit is contained in:
sbarman 2011-06-14 13:49:50 -07:00
parent aa6d9f75a3
commit b7360823a2

15
pdf.js
View File

@ -1961,7 +1961,9 @@ var CanvasGraphics = (function() {
}, },
fillAxialShading: function(sh) { fillAxialShading: function(sh) {
var cds = sh.get("Coords"); var coordsArr = sh.get("Coords");
var x0 = coordsArr[0], y0 = coordsArr[1],
x1 = coordsArr[2], y1 = coordsArr[3];
var t0 = 0.0, t1 = 1.0; var t0 = 0.0, t1 = 1.0;
if (sh.has("Domain")) { if (sh.has("Domain")) {
@ -1981,17 +1983,14 @@ var CanvasGraphics = (function() {
error("No support for array of functions"); error("No support for array of functions");
else if (!IsFunction(fnObj)) else if (!IsFunction(fnObj))
error("Invalid function"); error("Invalid function");
fn = new Function(this.xref, fnObj); fn = new PDFFunction(this.xref, fnObj);
var gradient = this.ctx.createLinearGradient(cds[0], cds[1], cds[2], cds[3]); var gradient = this.ctx.createLinearGradient(x0, y0, x1, y1);
var step = (t1 - t0) / 10; var step = (t1 - t0) / 10;
for (var i = t0; i <= t1; i += step) { for (var i = t0; i <= t1; i += step) {
var c = fn.func([i]); var c = fn.func([i]);
var clength = c.length; gradient.addColorStop(i, this.makeCssRgb.apply(this,c));
for (var j = 0; j < clength; ++j)
c[j] = Math.round(c[j] * 255);
gradient.addColorStop(i, "rgb("+c[0] + "," + c[1] + "," + c[2] + ")");
} }
this.ctx.fillStyle = gradient; this.ctx.fillStyle = gradient;
@ -2311,7 +2310,7 @@ var ColorSpace = (function() {
return constructor; return constructor;
})(); })();
var Function = (function() { var PDFFunction = (function() {
function constructor(xref, fn) { function constructor(xref, fn) {
var dict = fn.dict; var dict = fn.dict;
if (!dict) if (!dict)