implement even-odd fill/clip

This commit is contained in:
Chris Jones 2011-06-03 22:52:27 -05:00
parent 92aa46cf81
commit 2f8d80677b
2 changed files with 20 additions and 3 deletions

21
pdf.js
View File

@ -2229,8 +2229,9 @@ var CanvasGraphics = (function() {
this.consumePath();
},
eoFill: function() {
TODO("even-odd fill");
var savedFillRule = this.setEOFillRule();
this.fill();
this.restoreFillRule(savedFillRule);
},
fillStroke: function() {
this.ctx.fill();
@ -2434,10 +2435,15 @@ var CanvasGraphics = (function() {
consumePath: function() {
if (this.pendingClip) {
var savedFillRule = null;
if (this.pendingClip == EO_CLIP)
TODO("even-odd clipping");
savedFillRule = this.setEOFillRule();
this.ctx.clip();
this.pendingClip = null;
if (savedFillRule !== null)
this.restoreFillRule(savedFillRule);
}
this.ctx.beginPath();
},
@ -2445,6 +2451,17 @@ var CanvasGraphics = (function() {
var ri = (255 * r) | 0, gi = (255 * g) | 0, bi = (255 * b) | 0;
return "rgb("+ ri +","+ gi +","+ bi +")";
},
// We generally keep the canvas context set for
// nonzero-winding, and just set evenodd for the operations
// that need them.
setEOFillRule: function() {
var savedFillRule = this.ctx.mozFillRule;
this.ctx.mozFillRule = "evenodd";
return savedFillRule;
},
restoreFillRule: function(rule) {
this.ctx.mozFillRule = rule;
}
};
return constructor;

View File

@ -40,7 +40,7 @@ function load() {
canvas.mozOpaque = true;
pageDisplay = document.getElementById("pageNumber");
infoDisplay = document.getElementById("info");
open("compressed.tracemonkey-pldi-09.pdf");
open("uncompressed.tracemonkey-pldi-09.pdf");
}
function open(url) {