Permalink
Browse files

Switch to eoFIll and eoClip

Changed implementation so it now uses eoFill and eoClip instead of the fill rule
  • Loading branch information...
1 parent 7d9938d commit 8e80b086376013a5438087714a4d2abb6fe67de1 @cabanier committed Jan 7, 2013
Showing with 25 additions and 24 deletions.
  1. +25 −24 src/canvas.js
  2. BIN test/pdfs/winding.pdf
View
@@ -645,10 +645,23 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
if (consumePath)
this.consumePath();
},
- eoFill: function CanvasGraphics_eoFill() {
- var savedFillRule = this.setEOFillRule();
- this.fill();
- this.restoreFillRule(savedFillRule);
+
+ eoFill: function CanvasGraphics_eoFill(consumePath) {
+ consumePath = typeof consumePath !== 'undefined' ? consumePath : true;
+ var ctx = this.ctx;
+ var fillColor = this.current.fillColor;
+
+ if (fillColor && fillColor.hasOwnProperty('type') &&
+ fillColor.type === 'Pattern') {
+ ctx.save();
+ ctx.fillStyle = fillColor.getPattern(ctx);
+ ctx.eoFill();
+ ctx.restore();
+ } else {
+ ctx.eoFill();
+ }
+ if (consumePath)
+ this.consumePath();
},
fillStroke: function CanvasGraphics_fillStroke() {
this.fill(false);
@@ -657,19 +670,18 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
this.consumePath();
},
eoFillStroke: function CanvasGraphics_eoFillStroke() {
- var savedFillRule = this.setEOFillRule();
- this.fillStroke();
- this.restoreFillRule(savedFillRule);
+ this.eoFill(false);
+ this.stroke(false);
+
+ this.consumePath();
},
closeFillStroke: function CanvasGraphics_closeFillStroke() {
this.closePath();
this.fillStroke();
},
closeEOFillStroke: function CanvasGraphics_closeEOFillStroke() {
- var savedFillRule = this.setEOFillRule();
this.closePath();
- this.fillStroke();
- this.restoreFillRule(savedFillRule);
+ this.eoFillStroke();
},
endPath: function CanvasGraphics_endPath() {
this.consumePath();
@@ -1427,27 +1439,16 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
if (this.pendingClip) {
var savedFillRule = null;
if (this.pendingClip == EO_CLIP)
- savedFillRule = this.setEOFillRule();
-
- this.ctx.clip();
+ this.ctx.eoClip();
+ else
+ this.ctx.clip();
this.pendingClip = null;
if (savedFillRule !== null)
this.restoreFillRule(savedFillRule);
}
this.ctx.beginPath();
},
- // We generally keep the canvas context set for
- // nonzero-winding, and just set evenodd for the operations
- // that need them.
- setEOFillRule: function CanvasGraphics_setEOFillRule() {
- var savedFillRule = this.ctx.mozFillRule;
- this.ctx.mozFillRule = 'evenodd';
- return savedFillRule;
- },
- restoreFillRule: function CanvasGraphics_restoreFillRule(rule) {
- this.ctx.mozFillRule = rule;
- },
getSinglePixelWidth: function CanvasGraphics_getSinglePixelWidth(scale) {
var inverse = this.ctx.mozCurrentTransformInverse;
// max of the current horizontal and vertical scale
View
Binary file not shown.

0 comments on commit 8e80b08

Please sign in to comment.