@@ -302,8 +302,8 @@ export class RectF extends Rect {}
302302
303303export class Matrix implements IMatrix {
304304 _transform : CGAffineTransform ;
305- constructor ( ) {
306- this . _transform = CGAffineTransformIdentity ;
305+ constructor ( transform ? ) {
306+ this . _transform = transform || CGAffineTransformIdentity ;
307307 }
308308 mapRect ( rect : Rect ) {
309309 rect . cgRect = CGRectApplyAffineTransform ( rect . cgRect , this . _transform ) ;
@@ -793,7 +793,20 @@ export class Path implements IPath {
793793 console . error ( 'Method not implemented:' , 'setLastPoint' ) ;
794794 }
795795 toggleInverseFillType ( ) : void {
796- console . error ( 'Method not implemented:' , 'toggleInverseFillType' ) ;
796+ switch ( this . _fillType ) {
797+ case FillType . EVEN_ODD :
798+ this . _fillType = FillType . INVERSE_EVEN_ODD ;
799+ break ;
800+ case FillType . INVERSE_EVEN_ODD :
801+ this . _fillType = FillType . EVEN_ODD ;
802+ break ;
803+ case FillType . WINDING :
804+ this . _fillType = FillType . INVERSE_WINDING ;
805+ break ;
806+ case FillType . INVERSE_WINDING :
807+ this . _fillType = FillType . WINDING ;
808+ break ;
809+ }
797810 }
798811 moveTo ( x : number , y : number ) : void {
799812 CGPathMoveToPoint ( this . _path , null , x , y ) ;
@@ -835,7 +848,7 @@ export class Path implements IPath {
835848 CGPathAddEllipseInRect ( this . _path , null , rect ) ;
836849 }
837850 isInverseFillType ( ) : boolean {
838- return false ;
851+ return this . _fillType === FillType . INVERSE_EVEN_ODD || this . _fillType === FillType . INVERSE_EVEN_ODD ;
839852 }
840853 set ( path : Path ) : void {
841854 this . _path = CGPathCreateMutableCopy ( path . _path ) ;
@@ -1524,13 +1537,7 @@ export class Canvas implements ICanvas {
15241537 @paint
15251538 drawPath ( path : Path , paint : Paint ) : void {
15261539 const ctx = this . ctx ;
1527- if ( path . _fillType === FillType . EVEN_ODD ) {
1528- CGContextBeginPath ( ctx ) ;
1529- CGContextAddPath ( ctx , path . getCGPath ( ) ) ;
1530- this . _drawEOFPath ( paint , ctx ) ;
1531- } else {
1532- this . _drawPath ( paint , ctx , path . getBPath ( ) || path . getCGPath ( ) ) ;
1533- }
1540+ this . _drawPath ( paint , ctx , path . getBPath ( ) || path . getCGPath ( ) ) ;
15341541 }
15351542 clipOutPath ( path : IPath ) : boolean {
15361543 console . error ( 'Method not implemented:' , 'clipOutPath' ) ;
@@ -1769,33 +1776,29 @@ export class Canvas implements ICanvas {
17691776 CGContextClipToRect ( ctx , rect ) ;
17701777 return true ;
17711778 }
1772- private _drawEOFPath ( paint : Paint , ctx ) {
1773- if ( paint . style === Style . FILL ) {
1774- CGContextEOFillPath ( ctx ) ;
1775- } else if ( paint . style === Style . STROKE ) {
1776- CGContextDrawPath ( ctx , CGPathDrawingMode . kCGPathStroke ) ;
1777- } else {
1778- CGContextEOFillPath ( ctx ) ;
1779- CGContextDrawPath ( ctx , CGPathDrawingMode . kCGPathStroke ) ;
1780- }
1781- paint . drawShader ( ctx ) ;
1782- }
17831779 private _drawPath ( paint : Paint , ctx , path ?) {
17841780 let bPath : UIBezierPath ;
17851781 if ( path instanceof UIBezierPath ) {
17861782 bPath = path ;
17871783 path = bPath . CGPath ;
17881784 }
1789- if ( paint . shader && ! path ) {
1790- path = CGContextCopyPath ( ctx ) ;
1791- }
1792- if ( paint . pathEffect instanceof DashPathEffect ) {
1785+ function createBPath ( ) {
17931786 if ( ! bPath ) {
17941787 if ( ! path ) {
17951788 path = CGContextCopyPath ( ctx ) ;
17961789 }
17971790 bPath = UIBezierPath . bezierPathWithCGPath ( path ) ;
17981791 }
1792+ }
1793+ if ( paint . shader && ! path ) {
1794+ path = CGContextCopyPath ( ctx ) ;
1795+ }
1796+ if ( path . _fillType === FillType . INVERSE_WINDING || path . _fillType === FillType . INVERSE_EVEN_ODD ) {
1797+ createBPath ( ) ;
1798+ bPath = bPath . bezierPathByReversingPath ( ) ;
1799+ }
1800+ if ( paint . pathEffect instanceof DashPathEffect ) {
1801+ createBPath ( ) ;
17991802 const intervals = paint . pathEffect . intervals ;
18001803 const length = intervals . length ;
18011804 bPath . setLineDashCountPhase ( FloatConstructor . from ( intervals ) as any , length , paint . pathEffect . phase ) ;
@@ -1835,11 +1838,19 @@ export class Canvas implements ICanvas {
18351838 }
18361839 if ( paint . style === Style . FILL ) {
18371840 // CGContextFillPath(ctx);
1838- CGContextDrawPath ( ctx , CGPathDrawingMode . kCGPathFill ) ;
1841+ if ( path . _fillType === FillType . EVEN_ODD || path . _fillType === FillType . INVERSE_EVEN_ODD ) {
1842+ CGContextDrawPath ( ctx , CGPathDrawingMode . kCGPathEOFill ) ;
1843+ } else {
1844+ CGContextDrawPath ( ctx , CGPathDrawingMode . kCGPathFill ) ;
1845+ }
18391846 } else if ( paint . style === Style . STROKE ) {
18401847 CGContextDrawPath ( ctx , CGPathDrawingMode . kCGPathStroke ) ;
18411848 } else {
1842- CGContextDrawPath ( ctx , CGPathDrawingMode . kCGPathFillStroke ) ;
1849+ if ( path . _fillType === FillType . EVEN_ODD || path . _fillType === FillType . INVERSE_EVEN_ODD ) {
1850+ CGContextDrawPath ( ctx , CGPathDrawingMode . kCGPathEOFillStroke ) ;
1851+ } else {
1852+ CGContextDrawPath ( ctx , CGPathDrawingMode . kCGPathFillStroke ) ;
1853+ }
18431854 }
18441855 }
18451856 }
0 commit comments