@@ -1495,9 +1495,33 @@ export class Canvas implements ICanvas {
1495
1495
}
1496
1496
clipPath ( ...args ) {
1497
1497
const path = args [ 0 ] as Path ;
1498
+ const op = args [ 1 ] as Op ;
1498
1499
const ctx = this . ctx ;
1499
- CGContextAddPath ( ctx , path . getCGPath ( ) ) ;
1500
- CGContextClip ( ctx ) ;
1500
+ if ( op !== undefined ) {
1501
+ const cgPath = ctx . path ;
1502
+ let clipPath = cgPath ? UIBezierPath . bezierPathWithCGPath ( cgPath ) : UIBezierPath . bezierPathWithRect ( CGRectMake ( 0 , 0 , this . _width , this . _height ) ) ;
1503
+ if ( op === Op . DIFFERENCE ) {
1504
+ clipPath . appendPath ( path . getOrCreateBPath ( ) . bezierPathByReversingPath ( ) ) ;
1505
+
1506
+ } else if ( op === Op . REVERSE_DIFFERENCE ) {
1507
+ clipPath = clipPath . bezierPathByReversingPath ( ) ;
1508
+ clipPath . appendPath ( path . getOrCreateBPath ( ) ) ;
1509
+ } else if ( op === Op . UNION ) {
1510
+ clipPath . appendPath ( path . getOrCreateBPath ( ) ) ;
1511
+ } else if ( op === Op . REPLACE ) {
1512
+ CGContextResetClip ( ctx ) ;
1513
+ clipPath = path . getOrCreateBPath ( ) ;
1514
+ } else if ( op === Op . INTERSECT ) {
1515
+ console . error ( 'clipPath Op.INTERSECT not implemented yet' ) ;
1516
+ } else if ( op === Op . XOR ) {
1517
+ console . error ( 'clipPath Op.INTERSECT not implemented yet' ) ;
1518
+ }
1519
+ CGContextAddPath ( ctx , clipPath . CGPath ) ;
1520
+ CGContextClip ( ctx ) ;
1521
+ } else {
1522
+ CGContextAddPath ( ctx , path . getCGPath ( ) ) ;
1523
+ CGContextClip ( ctx ) ;
1524
+ }
1501
1525
// clipPath(path: IPath): boolean;
1502
1526
// clipPath(path: IPath, op: Op): boolean;
1503
1527
// clipPath(path: any, op?: any)
0 commit comments