mirror of
https://github.com/zoriya/react-native-svg.git
synced 2025-12-18 05:00:41 +00:00
Merge pull request #1564 from react-native-svg/fix-clip-rule-android
Fix clipRule in Android #1409
This commit is contained in:
@@ -22,7 +22,6 @@ class ClipPathView extends GroupView {
|
|||||||
|
|
||||||
public ClipPathView(ReactContext reactContext) {
|
public ClipPathView(ReactContext reactContext) {
|
||||||
super(reactContext);
|
super(reactContext);
|
||||||
mClipRule = CLIP_RULE_NONZERO;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -342,11 +342,11 @@ abstract public class VirtualView extends ReactViewGroup {
|
|||||||
ClipPathView mClipNode = (ClipPathView) getSvgView().getDefinedClipPath(mClipPath);
|
ClipPathView mClipNode = (ClipPathView) getSvgView().getDefinedClipPath(mClipPath);
|
||||||
|
|
||||||
if (mClipNode != null) {
|
if (mClipNode != null) {
|
||||||
Path clipPath = mClipNode.mClipRule == CLIP_RULE_EVENODD ? mClipNode.getPath(canvas, paint) :
|
Path clipPath = mClipRule == CLIP_RULE_EVENODD ? mClipNode.getPath(canvas, paint) :
|
||||||
mClipNode.getPath(canvas, paint, Region.Op.UNION);
|
mClipNode.getPath(canvas, paint, Region.Op.UNION);
|
||||||
clipPath.transform(mClipNode.mMatrix);
|
clipPath.transform(mClipNode.mMatrix);
|
||||||
clipPath.transform(mClipNode.mTransform);
|
clipPath.transform(mClipNode.mTransform);
|
||||||
switch (mClipNode.mClipRule) {
|
switch (mClipRule) {
|
||||||
case CLIP_RULE_EVENODD:
|
case CLIP_RULE_EVENODD:
|
||||||
clipPath.setFillType(Path.FillType.EVEN_ODD);
|
clipPath.setFillType(Path.FillType.EVEN_ODD);
|
||||||
break;
|
break;
|
||||||
|
|||||||
@@ -23,7 +23,6 @@
|
|||||||
BOOL _transparent;
|
BOOL _transparent;
|
||||||
RNSVGClipPath *_clipNode;
|
RNSVGClipPath *_clipNode;
|
||||||
CGPathRef _cachedClipPath;
|
CGPathRef _cachedClipPath;
|
||||||
CGImageRef _clipMask;
|
|
||||||
CGFloat canvasWidth;
|
CGFloat canvasWidth;
|
||||||
CGFloat canvasHeight;
|
CGFloat canvasHeight;
|
||||||
CGFloat canvasDiagonal;
|
CGFloat canvasDiagonal;
|
||||||
@@ -250,10 +249,8 @@ CGFloat const RNSVG_DEFAULT_FONT_SIZE = 12;
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
CGPathRelease(_cachedClipPath);
|
CGPathRelease(_cachedClipPath);
|
||||||
CGImageRelease(_clipMask);
|
|
||||||
_cachedClipPath = nil;
|
_cachedClipPath = nil;
|
||||||
_clipPath = clipPath;
|
_clipPath = clipPath;
|
||||||
_clipMask = nil;
|
|
||||||
[self invalidate];
|
[self invalidate];
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -263,10 +260,8 @@ CGFloat const RNSVG_DEFAULT_FONT_SIZE = 12;
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
CGPathRelease(_cachedClipPath);
|
CGPathRelease(_cachedClipPath);
|
||||||
CGImageRelease(_clipMask);
|
|
||||||
_cachedClipPath = nil;
|
_cachedClipPath = nil;
|
||||||
_clipRule = clipRule;
|
_clipRule = clipRule;
|
||||||
_clipMask = nil;
|
|
||||||
[self invalidate];
|
[self invalidate];
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -340,24 +335,6 @@ CGFloat const RNSVG_DEFAULT_FONT_SIZE = 12;
|
|||||||
}
|
}
|
||||||
CGAffineTransform transform = CGAffineTransformConcat(_clipNode.matrix, _clipNode.transforms);
|
CGAffineTransform transform = CGAffineTransformConcat(_clipNode.matrix, _clipNode.transforms);
|
||||||
_cachedClipPath = CGPathCreateCopyByTransformingPath([_clipNode getPath:context], &transform);
|
_cachedClipPath = CGPathCreateCopyByTransformingPath([_clipNode getPath:context], &transform);
|
||||||
if (_clipMask) {
|
|
||||||
CGImageRelease(_clipMask);
|
|
||||||
}
|
|
||||||
if ([_clipNode isSimpleClipPath] || _clipNode.clipRule == kRNSVGCGFCRuleEvenodd) {
|
|
||||||
_clipMask = nil;
|
|
||||||
} else {
|
|
||||||
CGRect bounds = CGContextGetClipBoundingBox(context);
|
|
||||||
CGSize size = bounds.size;
|
|
||||||
|
|
||||||
UIGraphicsBeginImageContextWithOptions(size, NO, 0.0);
|
|
||||||
CGContextRef newContext = UIGraphicsGetCurrentContext();
|
|
||||||
CGContextTranslateCTM(newContext, 0.0, size.height);
|
|
||||||
CGContextScaleCTM(newContext, 1.0, -1.0);
|
|
||||||
|
|
||||||
[_clipNode renderLayerTo:newContext rect:bounds];
|
|
||||||
_clipMask = CGBitmapContextCreateImage(newContext);
|
|
||||||
UIGraphicsEndImageContext();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return _cachedClipPath;
|
return _cachedClipPath;
|
||||||
@@ -368,16 +345,11 @@ CGFloat const RNSVG_DEFAULT_FONT_SIZE = 12;
|
|||||||
CGPathRef clipPath = [self getClipPath:context];
|
CGPathRef clipPath = [self getClipPath:context];
|
||||||
|
|
||||||
if (clipPath) {
|
if (clipPath) {
|
||||||
if (!_clipMask) {
|
CGContextAddPath(context, clipPath);
|
||||||
CGContextAddPath(context, clipPath);
|
if (_clipRule == kRNSVGCGFCRuleEvenodd) {
|
||||||
if (_clipNode.clipRule == kRNSVGCGFCRuleEvenodd) {
|
CGContextEOClip(context);
|
||||||
CGContextEOClip(context);
|
|
||||||
} else {
|
|
||||||
CGContextClip(context);
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
CGRect bounds = CGContextGetClipBoundingBox(context);
|
CGContextClip(context);
|
||||||
CGContextClipToMask(context, bounds, _clipMask);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -604,9 +576,7 @@ CGFloat const RNSVG_DEFAULT_FONT_SIZE = 12;
|
|||||||
{
|
{
|
||||||
CGPathRelease(_cachedClipPath);
|
CGPathRelease(_cachedClipPath);
|
||||||
CGPathRelease(_strokePath);
|
CGPathRelease(_strokePath);
|
||||||
CGImageRelease(_clipMask);
|
|
||||||
CGPathRelease(_path);
|
CGPathRelease(_path);
|
||||||
_clipMask = nil;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|||||||
Reference in New Issue
Block a user