@@ -226,6 +226,7 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
226
226
this .current = new CanvasExtraState ();
227
227
this .stateStack = [];
228
228
this .pendingClip = null ;
229
+ this .pendingEOFill = false ;
229
230
this .res = null ;
230
231
this .xobjs = null ;
231
232
this .commonObjs = commonObjs ;
@@ -706,23 +707,43 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
706
707
consumePath = typeof consumePath !== 'undefined' ? consumePath : true ;
707
708
var ctx = this .ctx ;
708
709
var fillColor = this .current .fillColor ;
710
+ var needRestore = false ;
709
711
710
712
if (fillColor && fillColor .hasOwnProperty ('type' ) &&
711
713
fillColor .type === 'Pattern' ) {
712
714
ctx .save ();
713
715
ctx .fillStyle = fillColor .getPattern (ctx );
714
- ctx .fill ();
715
- ctx .restore ();
716
+ needRestore = true ;
717
+ }
718
+
719
+ if (this .pendingEOFill ) {
720
+ if ('mozFillRule' in this .ctx ) {
721
+ this .ctx .mozFillRule = 'evenodd' ;
722
+ this .ctx .fill ();
723
+ this .ctx .mozFillRule = 'nonzero' ;
724
+ } else {
725
+ try {
726
+ this .ctx .fill ('evenodd' );
727
+ } catch (ex ) {
728
+ // shouldn't really happen, but browsers might think differently
729
+ this .ctx .fill ();
730
+ }
731
+ }
732
+ this .pendingEOFill = false ;
716
733
} else {
717
- ctx .fill ();
734
+ this . ctx .fill ();
718
735
}
719
- if (consumePath )
736
+
737
+ if (needRestore ) {
738
+ ctx .restore ();
739
+ }
740
+ if (consumePath ) {
720
741
this .consumePath ();
742
+ }
721
743
},
722
744
eoFill : function CanvasGraphics_eoFill () {
723
- var savedFillRule = this . setEOFillRule () ;
745
+ this . pendingEOFill = true ;
724
746
this .fill ();
725
- this .restoreFillRule (savedFillRule );
726
747
},
727
748
fillStroke : function CanvasGraphics_fillStroke () {
728
749
this .fill (false );
@@ -731,19 +752,17 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
731
752
this .consumePath ();
732
753
},
733
754
eoFillStroke : function CanvasGraphics_eoFillStroke () {
734
- var savedFillRule = this . setEOFillRule () ;
755
+ this . pendingEOFill = true ;
735
756
this .fillStroke ();
736
- this .restoreFillRule (savedFillRule );
737
757
},
738
758
closeFillStroke : function CanvasGraphics_closeFillStroke () {
739
759
this .closePath ();
740
760
this .fillStroke ();
741
761
},
742
762
closeEOFillStroke : function CanvasGraphics_closeEOFillStroke () {
743
- var savedFillRule = this . setEOFillRule () ;
763
+ this . pendingEOFill = true ;
744
764
this .closePath ();
745
765
this .fillStroke ();
746
- this .restoreFillRule (savedFillRule );
747
766
},
748
767
endPath : function CanvasGraphics_endPath () {
749
768
this .consumePath ();
@@ -1707,29 +1726,26 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
1707
1726
1708
1727
consumePath : function CanvasGraphics_consumePath () {
1709
1728
if (this .pendingClip ) {
1710
- var savedFillRule = null ;
1711
- if (this .pendingClip == EO_CLIP )
1712
- savedFillRule = this .setEOFillRule ();
1713
-
1714
- this .ctx .clip ();
1715
-
1729
+ if (this .pendingClip == EO_CLIP ) {
1730
+ if ('mozFillRule' in this .ctx ) {
1731
+ this .ctx .mozFillRule = 'evenodd' ;
1732
+ this .ctx .clip ();
1733
+ this .ctx .mozFillRule = 'nonzero' ;
1734
+ } else {
1735
+ try {
1736
+ this .ctx .clip ('evenodd' );
1737
+ } catch (ex ) {
1738
+ // shouldn't really happen, but browsers might think differently
1739
+ this .ctx .clip ();
1740
+ }
1741
+ }
1742
+ } else {
1743
+ this .ctx .clip ();
1744
+ }
1716
1745
this .pendingClip = null ;
1717
- if (savedFillRule !== null )
1718
- this .restoreFillRule (savedFillRule );
1719
1746
}
1720
1747
this .ctx .beginPath ();
1721
1748
},
1722
- // We generally keep the canvas context set for
1723
- // nonzero-winding, and just set evenodd for the operations
1724
- // that need them.
1725
- setEOFillRule : function CanvasGraphics_setEOFillRule () {
1726
- var savedFillRule = this .ctx .mozFillRule ;
1727
- this .ctx .mozFillRule = 'evenodd' ;
1728
- return savedFillRule ;
1729
- },
1730
- restoreFillRule : function CanvasGraphics_restoreFillRule (rule ) {
1731
- this .ctx .mozFillRule = rule ;
1732
- },
1733
1749
getSinglePixelWidth : function CanvasGraphics_getSinglePixelWidth (scale ) {
1734
1750
var inverse = this .ctx .mozCurrentTransformInverse ;
1735
1751
// max of the current horizontal and vertical scale
0 commit comments