@@ -494,19 +494,19 @@ export class Matrix implements IMatrix {
494
494
return CGAffineTransformIsIdentity ( this . mTransform ) ;
495
495
}
496
496
// public toString(): string {
497
- // return NSStringFromCGAffineTransform(this._transform );
497
+ // return NSStringFromCGAffineTransform(this.mTransform );
498
498
// }
499
499
public preTranslate ( tx : number , ty : number ) : boolean {
500
500
return this . preConcat ( CGAffineTransformMakeTranslation ( tx , ty ) ) ;
501
501
}
502
502
public setValues ( values : number [ ] ) : void {
503
503
this . mTransform = CGAffineTransformMake ( values [ 0 ] , values [ 3 ] , values [ 1 ] , values [ 4 ] , values [ 2 ] , values [ 5 ] ) ;
504
- // this._transform .a = values[0];
505
- // this._transform .c = values[1];
506
- // this._transform .tx = values[2];
507
- // this._transform .b = values[3];
508
- // this._transform .d = values[4];
509
- // this._transform .ty = values[5];
504
+ // this.mTransform .a = values[0];
505
+ // this.mTransform .c = values[1];
506
+ // this.mTransform .tx = values[2];
507
+ // this.mTransform .b = values[3];
508
+ // this.mTransform .d = values[4];
509
+ // this.mTransform .ty = values[5];
510
510
}
511
511
public invert ( output : IMatrix ) : boolean {
512
512
( output as Matrix ) . mTransform = CGAffineTransformInvert ( this . mTransform ) ;
@@ -549,7 +549,13 @@ export class DashPathEffect extends PathEffect {
549
549
export class Path implements IPath {
550
550
private mPath : any ;
551
551
private mBPath ?: UIBezierPath ;
552
- mFillType : FillType ;
552
+ private mFillType : FillType ;
553
+
554
+ constructor ( ) {
555
+ this . mPath = CGPathCreateMutable ( ) ;
556
+ this . mFillType = FillType . WINDING ;
557
+ // this._path = UIBezierPath.bezierPath();
558
+ }
553
559
554
560
getOrCreateBPath ( ) {
555
561
if ( ! this . mBPath ) {
@@ -577,11 +583,6 @@ export class Path implements IPath {
577
583
this . mBPath = bPath ;
578
584
// this._path = this._bPath.CGPath;
579
585
}
580
- constructor ( ) {
581
- this . mPath = CGPathCreateMutable ( ) ;
582
- this . mFillType = FillType . WINDING ;
583
- // this._path = UIBezierPath.bezierPath();
584
- }
585
586
computeBounds ( rect : RectF , exact : boolean ) {
586
587
if ( this . mBPath ) {
587
588
rect . cgRect = this . mBPath . bounds ;
@@ -1693,30 +1694,42 @@ export class Canvas implements ICanvas {
1693
1694
const path = args [ 0 ] as Path ;
1694
1695
const op = args [ 1 ] as Op ;
1695
1696
const ctx = this . ctx ;
1697
+
1698
+ let clipCGPath ;
1699
+
1696
1700
if ( op !== undefined ) {
1697
1701
const cgPath = ctx . path ;
1698
- let clipPath = cgPath ? UIBezierPath . bezierPathWithCGPath ( cgPath ) : UIBezierPath . bezierPathWithRect ( CGRectMake ( 0 , 0 , this . mWidth , this . mHeight ) ) ;
1702
+ let clipBPath = cgPath ? UIBezierPath . bezierPathWithCGPath ( cgPath ) : UIBezierPath . bezierPathWithRect ( CGRectMake ( 0 , 0 , this . mWidth , this . mHeight ) ) ;
1703
+
1699
1704
if ( op === Op . DIFFERENCE ) {
1700
- clipPath . appendPath ( path . getOrCreateBPath ( ) . bezierPathByReversingPath ( ) ) ;
1705
+ clipBPath . appendPath ( path . getOrCreateBPath ( ) . bezierPathByReversingPath ( ) ) ;
1701
1706
} else if ( op === Op . REVERSE_DIFFERENCE ) {
1702
- clipPath = clipPath . bezierPathByReversingPath ( ) ;
1703
- clipPath . appendPath ( path . getOrCreateBPath ( ) ) ;
1707
+ clipBPath = clipBPath . bezierPathByReversingPath ( ) ;
1708
+ clipBPath . appendPath ( path . getOrCreateBPath ( ) ) ;
1704
1709
} else if ( op === Op . UNION ) {
1705
- clipPath . appendPath ( path . getOrCreateBPath ( ) ) ;
1710
+ clipBPath . appendPath ( path . getOrCreateBPath ( ) ) ;
1706
1711
} else if ( op === Op . REPLACE ) {
1707
1712
CGContextResetClip ( ctx ) ;
1708
- clipPath = path . getOrCreateBPath ( ) ;
1713
+ clipBPath = path . getOrCreateBPath ( ) ;
1709
1714
} else if ( op === Op . INTERSECT ) {
1710
1715
console . error ( 'clipPath Op.INTERSECT not implemented yet' ) ;
1711
1716
} else if ( op === Op . XOR ) {
1712
1717
console . error ( 'clipPath Op.INTERSECT not implemented yet' ) ;
1713
1718
}
1714
- CGContextAddPath ( ctx , clipPath . CGPath ) ;
1715
- CGContextClip ( ctx ) ;
1719
+
1720
+ clipCGPath = clipBPath . CGPath ;
1721
+ } else {
1722
+ clipCGPath = path . getCGPath ( ) ;
1723
+ }
1724
+
1725
+ CGContextAddPath ( ctx , clipCGPath ) ;
1726
+
1727
+ if ( path . getFillType ( ) === FillType . EVEN_ODD || path . getFillType ( ) === FillType . INVERSE_EVEN_ODD ) {
1728
+ CGContextEOClip ( ctx ) ;
1716
1729
} else {
1717
- CGContextAddPath ( ctx , path . getCGPath ( ) ) ;
1718
1730
CGContextClip ( ctx ) ;
1719
1731
}
1732
+
1720
1733
// clipPath(path: IPath): boolean;
1721
1734
// clipPath(path: IPath, op: Op): boolean;
1722
1735
// clipPath(path: any, op?: any)
@@ -1908,30 +1921,38 @@ export class Canvas implements ICanvas {
1908
1921
CGContextClipToRect ( ctx , rect ) ;
1909
1922
return true ;
1910
1923
}
1911
- private _drawPath ( paint : Paint , ctx , path ?) {
1924
+ private _drawPath ( paint : Paint , ctx , path ?: Path | UIBezierPath ) {
1912
1925
let bPath : UIBezierPath ;
1913
1926
let cgPath ;
1927
+ let fillType : FillType ;
1928
+
1914
1929
if ( path instanceof Path ) {
1915
1930
bPath = path . getBPath ( ) ;
1916
1931
cgPath = path . getCGPath ( ) ;
1917
- } else if ( path instanceof UIBezierPath ) {
1918
- bPath = path ;
1919
- cgPath = bPath . CGPath ;
1932
+ fillType = path . getFillType ( ) ;
1920
1933
} else {
1921
- cgPath = path ;
1934
+ if ( path instanceof UIBezierPath ) {
1935
+ bPath = path ;
1936
+ cgPath = bPath . CGPath ;
1937
+ } else {
1938
+ cgPath = path ;
1939
+ }
1940
+ fillType = FillType . WINDING ;
1922
1941
}
1923
- function createBPath ( ) {
1942
+
1943
+ const createBPath = ( ) => {
1924
1944
if ( ! bPath ) {
1925
1945
if ( ! cgPath ) {
1926
1946
cgPath = CGContextCopyPath ( ctx ) ;
1927
1947
}
1928
1948
bPath = UIBezierPath . bezierPathWithCGPath ( cgPath ) ;
1929
1949
}
1930
- }
1950
+ } ;
1951
+
1931
1952
if ( paint . shader && ! cgPath ) {
1932
1953
cgPath = CGContextCopyPath ( ctx ) ;
1933
1954
}
1934
- if ( path && ( path . _fillType === FillType . INVERSE_WINDING || path . _fillType === FillType . INVERSE_EVEN_ODD ) ) {
1955
+ if ( fillType === FillType . INVERSE_WINDING || fillType === FillType . INVERSE_EVEN_ODD ) {
1935
1956
createBPath ( ) ;
1936
1957
bPath = bPath . bezierPathByReversingPath ( ) ;
1937
1958
cgPath = bPath . CGPath ;
@@ -1977,15 +1998,15 @@ export class Canvas implements ICanvas {
1977
1998
}
1978
1999
if ( paint . style === Style . FILL ) {
1979
2000
// CGContextFillPath(ctx);
1980
- if ( path && ( path . _fillType === FillType . EVEN_ODD || path . _fillType === FillType . INVERSE_EVEN_ODD ) ) {
2001
+ if ( fillType === FillType . EVEN_ODD || fillType === FillType . INVERSE_EVEN_ODD ) {
1981
2002
CGContextDrawPath ( ctx , CGPathDrawingMode . kCGPathEOFill ) ;
1982
2003
} else {
1983
2004
CGContextDrawPath ( ctx , CGPathDrawingMode . kCGPathFill ) ;
1984
2005
}
1985
2006
} else if ( paint . style === Style . STROKE ) {
1986
2007
CGContextDrawPath ( ctx , CGPathDrawingMode . kCGPathStroke ) ;
1987
2008
} else {
1988
- if ( path && ( path . _fillType === FillType . EVEN_ODD || path . _fillType === FillType . INVERSE_EVEN_ODD ) ) {
2009
+ if ( fillType === FillType . EVEN_ODD || fillType === FillType . INVERSE_EVEN_ODD ) {
1989
2010
CGContextDrawPath ( ctx , CGPathDrawingMode . kCGPathEOFillStroke ) ;
1990
2011
} else {
1991
2012
CGContextDrawPath ( ctx , CGPathDrawingMode . kCGPathFillStroke ) ;
0 commit comments