cleaned up fetchIfRef, changed switch-case to array lookup, changed IsFunction to IsPDFFunction
This commit is contained in:
parent
b7360823a2
commit
0f2d4c7011
78
pdf.js
78
pdf.js
@ -617,7 +617,7 @@ function IsRef(v) {
|
|||||||
return v instanceof Ref;
|
return v instanceof Ref;
|
||||||
}
|
}
|
||||||
|
|
||||||
function IsFunction(v) {
|
function IsPDFFunction(v) {
|
||||||
var fnDict;
|
var fnDict;
|
||||||
if (typeof v != "object")
|
if (typeof v != "object")
|
||||||
return false;
|
return false;
|
||||||
@ -1911,18 +1911,16 @@ var CanvasGraphics = (function() {
|
|||||||
|
|
||||||
// Shading
|
// Shading
|
||||||
shadingFill: function(entryRef) {
|
shadingFill: function(entryRef) {
|
||||||
var shadingRes = this.res.get("Shading");
|
|
||||||
if (!shadingRes)
|
|
||||||
return;
|
|
||||||
|
|
||||||
var xref = this.xref;
|
var xref = this.xref;
|
||||||
shadingRes = xref.fetchIfRef(shadingRes);
|
var res = this.res;
|
||||||
var shading = shadingRes.get(entryRef.name);
|
|
||||||
|
var shadingRes = xref.fetchIfRef(res.get("Shading"));
|
||||||
|
if (!shadingRes)
|
||||||
|
error("No shading resource found");
|
||||||
|
|
||||||
|
var shading = xref.fetchIfRef(shadingRes.get(entryRef.name));
|
||||||
if (!shading)
|
if (!shading)
|
||||||
return;
|
error("No shading object found");
|
||||||
shading = xref.fetchIfRef(shading);
|
|
||||||
if (!shading)
|
|
||||||
return;
|
|
||||||
|
|
||||||
this.save();
|
this.save();
|
||||||
|
|
||||||
@ -1940,22 +1938,14 @@ var CanvasGraphics = (function() {
|
|||||||
if (background)
|
if (background)
|
||||||
TODO("handle background colors");
|
TODO("handle background colors");
|
||||||
|
|
||||||
var type = shading.get("ShadingType");
|
const types = [null, this.fillFunctionShading,
|
||||||
switch (type) {
|
this.fillAxialShading, this.fillRadialShading];
|
||||||
case 1:
|
|
||||||
this.fillFunctionShading(shading);
|
var typeNum = shading.get("ShadingType");
|
||||||
break;
|
var fillFn = types[typeNum];
|
||||||
case 2:
|
if (!fillFn)
|
||||||
this.fillAxialShading(shading);
|
error("Unknown type of shading");
|
||||||
break;
|
fillFn.apply(this, [shading]);
|
||||||
case 3:
|
|
||||||
this.fillRadialShading(shading);
|
|
||||||
break;
|
|
||||||
case 4: case 5: case 6: case 7:
|
|
||||||
TODO("shading fill type "+ type);
|
|
||||||
default:
|
|
||||||
malformed("Unknown shading type "+ type);
|
|
||||||
}
|
|
||||||
|
|
||||||
this.restore();
|
this.restore();
|
||||||
},
|
},
|
||||||
@ -1981,7 +1971,7 @@ var CanvasGraphics = (function() {
|
|||||||
fnObj = this.xref.fetchIfRef(fnObj);
|
fnObj = this.xref.fetchIfRef(fnObj);
|
||||||
if (IsArray(fnObj))
|
if (IsArray(fnObj))
|
||||||
error("No support for array of functions");
|
error("No support for array of functions");
|
||||||
else if (!IsFunction(fnObj))
|
else if (!IsPDFFunction(fnObj))
|
||||||
error("Invalid function");
|
error("Invalid function");
|
||||||
fn = new PDFFunction(this.xref, fnObj);
|
fn = new PDFFunction(this.xref, fnObj);
|
||||||
|
|
||||||
@ -1990,12 +1980,14 @@ var CanvasGraphics = (function() {
|
|||||||
|
|
||||||
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]);
|
||||||
gradient.addColorStop(i, this.makeCssRgb.apply(this,c));
|
gradient.addColorStop(i, this.makeCssRgb.apply(this, c));
|
||||||
}
|
}
|
||||||
|
|
||||||
this.ctx.fillStyle = gradient;
|
this.ctx.fillStyle = gradient;
|
||||||
|
|
||||||
// HACK to draw the gradient onto an infinite rectangle
|
// HACK to draw the gradient onto an infinite rectangle.
|
||||||
|
// PDF gradients are drawn across the entire image while
|
||||||
|
// Canvas only allows gradients to be drawn in a rectangle
|
||||||
this.ctx.fillRect(-1e10, -1e10, 2e10, 2e10);
|
this.ctx.fillRect(-1e10, -1e10, 2e10, 2e10);
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -2316,24 +2308,16 @@ var PDFFunction = (function() {
|
|||||||
if (!dict)
|
if (!dict)
|
||||||
dict = fn;
|
dict = fn;
|
||||||
|
|
||||||
var type = dict.get("FunctionType");
|
const types = [this.constructSampled, null,
|
||||||
|
this.constructInterpolated, this.constructStiched,
|
||||||
switch(type) {
|
this.constructPostScript];
|
||||||
case 0:
|
|
||||||
this.constructSampled(fn, dict);
|
var typeNum = dict.get("FunctionType");
|
||||||
break;
|
var typeFn = types[typeNum];
|
||||||
case 2:
|
if (!typeFn)
|
||||||
this.constructInterpolated();
|
|
||||||
break;
|
|
||||||
case 3:
|
|
||||||
this.constructStiched();
|
|
||||||
break;
|
|
||||||
case 4:
|
|
||||||
this.constructPostScript();
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
error("Unknown type of function");
|
error("Unknown type of function");
|
||||||
}
|
|
||||||
|
typeFn.apply(this, [fn, dict]);
|
||||||
};
|
};
|
||||||
|
|
||||||
constructor.prototype = {
|
constructor.prototype = {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user