Skip to content

Commit 672fe4e

Browse files
committed
fix: ios basic support for clipPath Ops
1 parent 8dff17d commit 672fe4e

File tree

1 file changed

+26
-2
lines changed

1 file changed

+26
-2
lines changed

Diff for: src/canvas.ios.ts

+26-2
Original file line numberDiff line numberDiff line change
@@ -1495,9 +1495,33 @@ export class Canvas implements ICanvas {
14951495
}
14961496
clipPath(...args) {
14971497
const path = args[0] as Path;
1498+
const op = args[1] as Op;
14981499
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+
}
15011525
// clipPath(path: IPath): boolean;
15021526
// clipPath(path: IPath, op: Op): boolean;
15031527
// clipPath(path: any, op?: any)

0 commit comments

Comments
 (0)