Skip to content

Commit 08360c5

Browse files
committed
fix(ui-canvas): iOS drawPath and clipPath ignored fill rule
1 parent 4a47422 commit 08360c5

File tree

1 file changed

+35
-21
lines changed

1 file changed

+35
-21
lines changed

src/ui-canvas/canvas.ios.ts

Lines changed: 35 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -494,19 +494,19 @@ export class Matrix implements IMatrix {
494494
return CGAffineTransformIsIdentity(this.mTransform);
495495
}
496496
// public toString(): string {
497-
// return NSStringFromCGAffineTransform(this._transform);
497+
// return NSStringFromCGAffineTransform(this.mTransform);
498498
// }
499499
public preTranslate(tx: number, ty: number): boolean {
500500
return this.preConcat(CGAffineTransformMakeTranslation(tx, ty));
501501
}
502502
public setValues(values: number[]): void {
503503
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];
510510
}
511511
public invert(output: IMatrix): boolean {
512512
(output as Matrix).mTransform = CGAffineTransformInvert(this.mTransform);
@@ -1693,30 +1693,42 @@ export class Canvas implements ICanvas {
16931693
const path = args[0] as Path;
16941694
const op = args[1] as Op;
16951695
const ctx = this.ctx;
1696+
1697+
let clipCGPath;
1698+
16961699
if (op !== undefined) {
16971700
const cgPath = ctx.path;
1698-
let clipPath = cgPath ? UIBezierPath.bezierPathWithCGPath(cgPath) : UIBezierPath.bezierPathWithRect(CGRectMake(0, 0, this.mWidth, this.mHeight));
1701+
let clipBPath = cgPath ? UIBezierPath.bezierPathWithCGPath(cgPath) : UIBezierPath.bezierPathWithRect(CGRectMake(0, 0, this.mWidth, this.mHeight));
1702+
16991703
if (op === Op.DIFFERENCE) {
1700-
clipPath.appendPath(path.getOrCreateBPath().bezierPathByReversingPath());
1704+
clipBPath.appendPath(path.getOrCreateBPath().bezierPathByReversingPath());
17011705
} else if (op === Op.REVERSE_DIFFERENCE) {
1702-
clipPath = clipPath.bezierPathByReversingPath();
1703-
clipPath.appendPath(path.getOrCreateBPath());
1706+
clipBPath = clipBPath.bezierPathByReversingPath();
1707+
clipBPath.appendPath(path.getOrCreateBPath());
17041708
} else if (op === Op.UNION) {
1705-
clipPath.appendPath(path.getOrCreateBPath());
1709+
clipBPath.appendPath(path.getOrCreateBPath());
17061710
} else if (op === Op.REPLACE) {
17071711
CGContextResetClip(ctx);
1708-
clipPath = path.getOrCreateBPath();
1712+
clipBPath = path.getOrCreateBPath();
17091713
} else if (op === Op.INTERSECT) {
17101714
console.error('clipPath Op.INTERSECT not implemented yet');
17111715
} else if (op === Op.XOR) {
17121716
console.error('clipPath Op.INTERSECT not implemented yet');
17131717
}
1714-
CGContextAddPath(ctx, clipPath.CGPath);
1715-
CGContextClip(ctx);
1718+
1719+
clipCGPath = clipBPath.CGPath;
1720+
} else {
1721+
clipCGPath = path.getCGPath();
1722+
}
1723+
1724+
CGContextAddPath(ctx, clipCGPath);
1725+
1726+
if (path.getFillType() === FillType.EVEN_ODD || path.getFillType() === FillType.INVERSE_EVEN_ODD) {
1727+
CGContextEOClip(ctx);
17161728
} else {
1717-
CGContextAddPath(ctx, path.getCGPath());
17181729
CGContextClip(ctx);
17191730
}
1731+
17201732
// clipPath(path: IPath): boolean;
17211733
// clipPath(path: IPath, op: Op): boolean;
17221734
// clipPath(path: any, op?: any)
@@ -1920,18 +1932,20 @@ export class Canvas implements ICanvas {
19201932
} else {
19211933
cgPath = path;
19221934
}
1923-
function createBPath() {
1935+
1936+
const createBPath = () => {
19241937
if (!bPath) {
19251938
if (!cgPath) {
19261939
cgPath = CGContextCopyPath(ctx);
19271940
}
19281941
bPath = UIBezierPath.bezierPathWithCGPath(cgPath);
19291942
}
1930-
}
1943+
};
1944+
19311945
if (paint.shader && !cgPath) {
19321946
cgPath = CGContextCopyPath(ctx);
19331947
}
1934-
if (path && (path._fillType === FillType.INVERSE_WINDING || path._fillType === FillType.INVERSE_EVEN_ODD)) {
1948+
if (path && (path.getFillType() === FillType.INVERSE_WINDING || path.getFillType() === FillType.INVERSE_EVEN_ODD)) {
19351949
createBPath();
19361950
bPath = bPath.bezierPathByReversingPath();
19371951
cgPath = bPath.CGPath;
@@ -1977,15 +1991,15 @@ export class Canvas implements ICanvas {
19771991
}
19781992
if (paint.style === Style.FILL) {
19791993
// CGContextFillPath(ctx);
1980-
if (path && (path._fillType === FillType.EVEN_ODD || path._fillType === FillType.INVERSE_EVEN_ODD)) {
1994+
if (path && (path.getFillType() === FillType.EVEN_ODD || path.getFillType() === FillType.INVERSE_EVEN_ODD)) {
19811995
CGContextDrawPath(ctx, CGPathDrawingMode.kCGPathEOFill);
19821996
} else {
19831997
CGContextDrawPath(ctx, CGPathDrawingMode.kCGPathFill);
19841998
}
19851999
} else if (paint.style === Style.STROKE) {
19862000
CGContextDrawPath(ctx, CGPathDrawingMode.kCGPathStroke);
19872001
} else {
1988-
if (path && (path._fillType === FillType.EVEN_ODD || path._fillType === FillType.INVERSE_EVEN_ODD)) {
2002+
if (path && (path.getFillType() === FillType.EVEN_ODD || path.getFillType() === FillType.INVERSE_EVEN_ODD)) {
19892003
CGContextDrawPath(ctx, CGPathDrawingMode.kCGPathEOFillStroke);
19902004
} else {
19912005
CGContextDrawPath(ctx, CGPathDrawingMode.kCGPathFillStroke);

0 commit comments

Comments
 (0)