diff --git a/ios/Brushes/RNSVGBrush.h b/ios/Brushes/RNSVGBrush.h index 7ffe6c89..28269eb7 100644 --- a/ios/Brushes/RNSVGBrush.h +++ b/ios/Brushes/RNSVGBrush.h @@ -35,6 +35,6 @@ * be clipped. * @abstract */ -- (void)paint:(CGContextRef)context opacity:(CGFloat)opacity painter:(RNSVGPainter *)painter; +- (void)paint:(CGContextRef)context opacity:(CGFloat)opacity painter:(RNSVGPainter *)painter bounds:(CGRect)bounds; @end diff --git a/ios/Brushes/RNSVGPainter.h b/ios/Brushes/RNSVGPainter.h index 51347e9e..0f52a4b8 100644 --- a/ios/Brushes/RNSVGPainter.h +++ b/ios/Brushes/RNSVGPainter.h @@ -14,7 +14,7 @@ - (instancetype)initWithPointsArray:(NSArray *)pointsArray NS_DESIGNATED_INITIALIZER; -- (void)paint:(CGContextRef)context; +- (void)paint:(CGContextRef)context bounds:(CGRect)bounds; - (void)setUnits:(RNSVGUnits)unit; diff --git a/ios/Brushes/RNSVGPainter.m b/ios/Brushes/RNSVGPainter.m index 1ba21880..1ac93f26 100644 --- a/ios/Brushes/RNSVGPainter.m +++ b/ios/Brushes/RNSVGPainter.m @@ -66,20 +66,20 @@ RCT_NOT_IMPLEMENTED(- (instancetype)init) _colors = colors; } -- (void)paint:(CGContextRef)context +- (void)paint:(CGContextRef)context bounds:(CGRect)bounds { if (_type == kRNSVGLinearGradient) { - [self paintLinearGradient:context]; + [self paintLinearGradient:context bounds:(CGRect)bounds]; } else if (_type == kRNSVGRadialGradient) { - [self paintRidialGradient:context]; + [self paintRidialGradient:context bounds:(CGRect)bounds]; } else if (_type == kRNSVGPattern) { // todo: } } -- (CGRect)getPaintRect:(CGContextRef)context +- (CGRect)getPaintRect:(CGContextRef)context bounds:(CGRect)bounds { - CGRect rect = _useObjectBoundingBox ? CGContextGetClipBoundingBox(context) : _userSpaceBoundingBox; + CGRect rect = _useObjectBoundingBox ? bounds : _userSpaceBoundingBox; float height = CGRectGetHeight(rect); float width = CGRectGetWidth(rect); float x = 0.0; @@ -93,13 +93,13 @@ RCT_NOT_IMPLEMENTED(- (instancetype)init) return CGRectMake(x, y, width, height); } -- (void)paintLinearGradient:(CGContextRef)context +- (void)paintLinearGradient:(CGContextRef)context bounds:(CGRect)bounds { CGGradientRef gradient = CGGradientRetain([RCTConvert RNSVGCGGradient:_colors offset:0]); CGGradientDrawingOptions extendOptions = kCGGradientDrawsBeforeStartLocation | kCGGradientDrawsAfterEndLocation; - CGRect rect = [self getPaintRect:context]; + CGRect rect = [self getPaintRect:context bounds:bounds]; float height = CGRectGetHeight(rect); float width = CGRectGetWidth(rect); float offsetX = CGRectGetMinX(rect); @@ -124,12 +124,12 @@ RCT_NOT_IMPLEMENTED(- (instancetype)init) CGGradientRelease(gradient); } -- (void)paintRidialGradient:(CGContextRef)context +- (void)paintRidialGradient:(CGContextRef)context bounds:(CGRect)bounds { CGGradientRef gradient = CGGradientRetain([RCTConvert RNSVGCGGradient:_colors offset:0]); CGGradientDrawingOptions extendOptions = kCGGradientDrawsBeforeStartLocation | kCGGradientDrawsAfterEndLocation; - CGRect rect = [self getPaintRect:context]; + CGRect rect = [self getPaintRect:context bounds:bounds]; float height = CGRectGetHeight(rect); float width = CGRectGetWidth(rect); float offsetX = CGRectGetMinX(rect); diff --git a/ios/Brushes/RNSVGPainterBrush.m b/ios/Brushes/RNSVGPainterBrush.m index 8b1b5d50..08d061ee 100644 --- a/ios/Brushes/RNSVGPainterBrush.m +++ b/ios/Brushes/RNSVGPainterBrush.m @@ -21,22 +21,22 @@ self.class, NSStringFromSelector(_cmd), array); return nil; } - + self.brushRef = [array objectAtIndex:1]; } return self; } -- (void)paint:(CGContextRef)context opacity:(CGFloat)opacity painter:(RNSVGPainter *)painter +- (void)paint:(CGContextRef)context opacity:(CGFloat)opacity painter:(RNSVGPainter *)painter bounds:(CGRect)bounds { BOOL transparency = opacity < 1; if (transparency) { CGContextSetAlpha(context, opacity); CGContextBeginTransparencyLayer(context, NULL); } - - [painter paint:context]; - + + [painter paint:context bounds:(CGRect)bounds]; + if (transparency) { CGContextEndTransparencyLayer(context); } diff --git a/ios/RNSVGRenderable.m b/ios/RNSVGRenderable.m index c584ae1a..3fb427b9 100644 --- a/ios/RNSVGRenderable.m +++ b/ios/RNSVGRenderable.m @@ -211,6 +211,7 @@ [self.fill paint:context opacity:self.fillOpacity painter:[self.svgView getDefinedPainter:self.fill.brushRef] + bounds:pathBounding ]; CGContextRestoreGState(context); @@ -256,6 +257,7 @@ [self.stroke paint:context opacity:self.strokeOpacity painter:[self.svgView getDefinedPainter:self.stroke.brushRef] + bounds:pathBounding ]; return; }