Used symbolic constants

This commit is contained in:
sbarman 2011-06-20 13:38:27 -07:00
parent 9d286d789e
commit 9419a0d4b8

29
pdf.js
View File

@ -2033,6 +2033,9 @@ var CanvasGraphics = (function() {
const NORMAL_CLIP = {}; const NORMAL_CLIP = {};
const EO_CLIP = {}; const EO_CLIP = {};
// Used for tiling patterns
const PAINT_TYPE = [null, "colored", "uncolored"];
constructor.prototype = { constructor.prototype = {
translateFont: function(fontDict, xref, resources) { translateFont: function(fontDict, xref, resources) {
var descriptor = xref.fetch(fontDict.get("FontDescriptor")); var descriptor = xref.fetch(fontDict.get("FontDescriptor"));
@ -2461,12 +2464,13 @@ var CanvasGraphics = (function() {
error("Unable to find pattern resource"); error("Unable to find pattern resource");
var pattern = xref.fetchIfRef(patternRes.get(patternName.name)); var pattern = xref.fetchIfRef(patternRes.get(patternName.name));
var type = pattern.dict.get("PatternType"); const types = [null, this.tilingFill];
if (type === 1) var typeNum = pattern.dict.get("PatternType");
this.tilingFill(pattern); var patternFn = types[typeNum];
else if (!patternFn)
error("Unhandled pattern type"); error("Unhandled pattern type");
patternFn.call(this, pattern);
} }
} else { } else {
// TODO real impl // TODO real impl
@ -2492,15 +2496,15 @@ var CanvasGraphics = (function() {
this.save(); this.save();
var dict = pattern.dict; var dict = pattern.dict;
var ctx = this.ctx;
var paintType = dict.get("PaintType"); var paintType = PAINT_TYPE[dict.get("PaintType")];
if (paintType == 2) { if (paintType == "colored") {
error("Unsupported paint type");
} else {
// should go to default for color space // should go to default for color space
var ctx = this.ctx;
ctx.fillStyle = this.makeCssRgb(1, 1, 1); ctx.fillStyle = this.makeCssRgb(1, 1, 1);
ctx.strokeStyle = this.makeCssRgb(0, 0, 0); ctx.strokeStyle = this.makeCssRgb(0, 0, 0);
} else {
error("Unsupported paint type");
} }
TODO("TilingType"); TODO("TilingType");
@ -2524,7 +2528,7 @@ var CanvasGraphics = (function() {
// set the new canvas element context as the graphics context // set the new canvas element context as the graphics context
var tmpCtx = tmpCanvas.getContext("2d"); var tmpCtx = tmpCanvas.getContext("2d");
var savedCtx = this.ctx; var savedCtx = ctx;
this.ctx = tmpCtx; this.ctx = tmpCtx;
// normalize transform matrix so each step // normalize transform matrix so each step
@ -2663,9 +2667,6 @@ var CanvasGraphics = (function() {
// Canvas only allows gradients to be drawn in a rectangle // Canvas only allows gradients to be drawn in a rectangle
// The following bug should allow us to remove this. // The following bug should allow us to remove this.
// https://bugzilla.mozilla.org/show_bug.cgi?id=664884 // https://bugzilla.mozilla.org/show_bug.cgi?id=664884
//
// Also, larg numbers seem to cause overflow which causes
// nothing to be drawn.
this.ctx.fillRect(-1e10, -1e10, 2e10, 2e10); this.ctx.fillRect(-1e10, -1e10, 2e10, 2e10);
}, },