@@ -302,8 +302,8 @@ export class RectF extends Rect {}
302
302
303
303
export class Matrix implements IMatrix {
304
304
_transform : CGAffineTransform ;
305
- constructor ( ) {
306
- this . _transform = CGAffineTransformIdentity ;
305
+ constructor ( transform ? ) {
306
+ this . _transform = transform || CGAffineTransformIdentity ;
307
307
}
308
308
mapRect ( rect : Rect ) {
309
309
rect . cgRect = CGRectApplyAffineTransform ( rect . cgRect , this . _transform ) ;
@@ -793,7 +793,20 @@ export class Path implements IPath {
793
793
console . error ( 'Method not implemented:' , 'setLastPoint' ) ;
794
794
}
795
795
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
+ }
797
810
}
798
811
moveTo ( x : number , y : number ) : void {
799
812
CGPathMoveToPoint ( this . _path , null , x , y ) ;
@@ -835,7 +848,7 @@ export class Path implements IPath {
835
848
CGPathAddEllipseInRect ( this . _path , null , rect ) ;
836
849
}
837
850
isInverseFillType ( ) : boolean {
838
- return false ;
851
+ return this . _fillType === FillType . INVERSE_EVEN_ODD || this . _fillType === FillType . INVERSE_EVEN_ODD ;
839
852
}
840
853
set ( path : Path ) : void {
841
854
this . _path = CGPathCreateMutableCopy ( path . _path ) ;
@@ -1524,13 +1537,7 @@ export class Canvas implements ICanvas {
1524
1537
@paint
1525
1538
drawPath ( path : Path , paint : Paint ) : void {
1526
1539
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 ( ) ) ;
1534
1541
}
1535
1542
clipOutPath ( path : IPath ) : boolean {
1536
1543
console . error ( 'Method not implemented:' , 'clipOutPath' ) ;
@@ -1769,33 +1776,29 @@ export class Canvas implements ICanvas {
1769
1776
CGContextClipToRect ( ctx , rect ) ;
1770
1777
return true ;
1771
1778
}
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
- }
1783
1779
private _drawPath ( paint : Paint , ctx , path ?) {
1784
1780
let bPath : UIBezierPath ;
1785
1781
if ( path instanceof UIBezierPath ) {
1786
1782
bPath = path ;
1787
1783
path = bPath . CGPath ;
1788
1784
}
1789
- if ( paint . shader && ! path ) {
1790
- path = CGContextCopyPath ( ctx ) ;
1791
- }
1792
- if ( paint . pathEffect instanceof DashPathEffect ) {
1785
+ function createBPath ( ) {
1793
1786
if ( ! bPath ) {
1794
1787
if ( ! path ) {
1795
1788
path = CGContextCopyPath ( ctx ) ;
1796
1789
}
1797
1790
bPath = UIBezierPath . bezierPathWithCGPath ( path ) ;
1798
1791
}
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 ( ) ;
1799
1802
const intervals = paint . pathEffect . intervals ;
1800
1803
const length = intervals . length ;
1801
1804
bPath . setLineDashCountPhase ( FloatConstructor . from ( intervals ) as any , length , paint . pathEffect . phase ) ;
@@ -1835,11 +1838,19 @@ export class Canvas implements ICanvas {
1835
1838
}
1836
1839
if ( paint . style === Style . FILL ) {
1837
1840
// 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
+ }
1839
1846
} else if ( paint . style === Style . STROKE ) {
1840
1847
CGContextDrawPath ( ctx , CGPathDrawingMode . kCGPathStroke ) ;
1841
1848
} 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
+ }
1843
1854
}
1844
1855
}
1845
1856
}
0 commit comments