From 5389209a64debc4b9242232b2fa51403e33aea35 Mon Sep 17 00:00:00 2001 From: Mikael Sand Date: Sun, 31 Mar 2019 18:48:57 +0300 Subject: [PATCH] [iOS] Fix clipRule="evenodd" https://github.com/react-native-community/react-native-svg/issues/983 --- ios/RNSVGNode.m | 38 ++++---------------------------------- 1 file changed, 4 insertions(+), 34 deletions(-) diff --git a/ios/RNSVGNode.m b/ios/RNSVGNode.m index 7d491e21..66d2507a 100644 --- a/ios/RNSVGNode.m +++ b/ios/RNSVGNode.m @@ -23,7 +23,6 @@ BOOL _transparent; RNSVGClipPath *_clipNode; CGPathRef _cachedClipPath; - CGImageRef _clipMask; CGFloat canvasWidth; CGFloat canvasHeight; CGFloat canvasDiagonal; @@ -225,10 +224,8 @@ CGFloat const RNSVG_DEFAULT_FONT_SIZE = 12; return; } CGPathRelease(_cachedClipPath); - CGImageRelease(_clipMask); _cachedClipPath = nil; _clipPath = clipPath; - _clipMask = nil; [self invalidate]; } @@ -238,10 +235,8 @@ CGFloat const RNSVG_DEFAULT_FONT_SIZE = 12; return; } CGPathRelease(_cachedClipPath); - CGImageRelease(_clipMask); _cachedClipPath = nil; _clipRule = clipRule; - _clipMask = nil; [self invalidate]; } @@ -287,24 +282,6 @@ CGFloat const RNSVG_DEFAULT_FONT_SIZE = 12; CGPathRelease(_cachedClipPath); } _cachedClipPath = CGPathRetain([_clipNode getPath:context]); - if (_clipMask) { - CGImageRelease(_clipMask); - } - if ([_clipNode isSimpleClipPath]) { - _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; @@ -315,16 +292,11 @@ CGFloat const RNSVG_DEFAULT_FONT_SIZE = 12; CGPathRef clipPath = [self getClipPath:context]; if (clipPath) { - if (!_clipMask) { - CGContextAddPath(context, clipPath); - if (_clipNode.clipRule == kRNSVGCGFCRuleEvenodd) { - CGContextEOClip(context); - } else { - CGContextClip(context); - } + CGContextAddPath(context, clipPath); + if (_clipNode.clipRule == kRNSVGCGFCRuleEvenodd) { + CGContextEOClip(context); } else { - CGRect bounds = CGContextGetClipBoundingBox(context); - CGContextClipToMask(context, bounds, _clipMask); + CGContextClip(context); } } } @@ -551,9 +523,7 @@ CGFloat const RNSVG_DEFAULT_FONT_SIZE = 12; { CGPathRelease(_cachedClipPath); CGPathRelease(_strokePath); - CGImageRelease(_clipMask); CGPathRelease(_path); - _clipMask = nil; } @end