From 0fd92e30ea374916fb4415d1bfbf27f742f2396a Mon Sep 17 00:00:00 2001 From: Horcrux Date: Wed, 27 Jul 2016 16:22:31 +0800 Subject: [PATCH] fix transform bug --- ios/Elements/RNSVGGroup.m | 2 +- ios/RNSVGNode.m | 85 ++++++++++++++++++++------------------- ios/RNSVGRenderable.m | 2 +- 3 files changed, 45 insertions(+), 44 deletions(-) diff --git a/ios/Elements/RNSVGGroup.m b/ios/Elements/RNSVGGroup.m index ede44aac..5ebfbcbb 100644 --- a/ios/Elements/RNSVGGroup.m +++ b/ios/Elements/RNSVGGroup.m @@ -29,7 +29,7 @@ { CGMutablePathRef path = CGPathCreateMutable(); for (RNSVGNode *node in self.subviews) { - CGAffineTransform transform = node.matrix; + CGAffineTransform transform = node.transform; CGPathAddPath(path, &transform, [node getPath:context]); } return (CGPathRef)CFAutorelease(path); diff --git a/ios/RNSVGNode.m b/ios/RNSVGNode.m index 45add964..a5d0b349 100644 --- a/ios/RNSVGNode.m +++ b/ios/RNSVGNode.m @@ -71,48 +71,10 @@ - (void)setMatrix:(CGAffineTransform)matrix { - _matrix = matrix; + self.transform = matrix; [self invalidate]; } -- (void)beginTransparencyLayer:(CGContextRef)context -{ - if (_transparent) { - CGContextBeginTransparencyLayer(context, NULL); - } -} - -- (void)endTransparencyLayer:(CGContextRef)context -{ - if (_transparent) { - CGContextEndTransparencyLayer(context); - } -} - -- (void)renderTo:(CGContextRef)context -{ - float opacity = self.opacity; - - // This needs to be painted on a layer before being composited. - CGContextSaveGState(context); - CGContextConcatCTM(context, self.matrix); - CGContextSetAlpha(context, opacity); - - [self beginTransparencyLayer:context]; - [self renderClip:context]; - [self renderLayerTo:context]; - [self endTransparencyLayer:context]; - - CGContextRestoreGState(context); -} - -- (void)renderClip:(CGContextRef)context -{ - if (self.clipPathRef) { - self.clipPath = [[[self getSvgView] getDefinedClipPath:self.clipPathRef] getPath:context]; - } -} - - (void)setClipPath:(CGPathRef)clipPath { if (_clipPath == clipPath) { @@ -133,10 +95,42 @@ _clipPathRef = clipPathRef; } -- (CGPathRef)getPath: (CGContextRef) context +- (void)beginTransparencyLayer:(CGContextRef)context { - // abstract - return (CGPathRef)CFAutorelease(CGPathCreateMutable()); + if (_transparent) { + CGContextBeginTransparencyLayer(context, NULL); + } +} + +- (void)endTransparencyLayer:(CGContextRef)context +{ + if (_transparent) { + CGContextEndTransparencyLayer(context); + } +} + +- (void)renderTo:(CGContextRef)context +{ + float opacity = self.opacity; + + // This needs to be painted on a layer before being composited. + CGContextSaveGState(context); + CGContextConcatCTM(context, self.transform); + CGContextSetAlpha(context, opacity); + + [self beginTransparencyLayer:context]; + [self renderClip:context]; + [self renderLayerTo:context]; + [self endTransparencyLayer:context]; + + CGContextRestoreGState(context); +} + +- (void)renderClip:(CGContextRef)context +{ + if (self.clipPathRef) { + self.clipPath = [[[self getSvgView] getDefinedClipPath:self.clipPathRef] getPath:context]; + } } - (void)clip:(CGContextRef)context @@ -153,6 +147,13 @@ } } +- (CGPathRef)getPath: (CGContextRef) context +{ + // abstract + return nil; +} + + - (void)renderLayerTo:(CGContextRef)context { // abstract diff --git a/ios/RNSVGRenderable.m b/ios/RNSVGRenderable.m index 0e8f9419..b9d64e69 100644 --- a/ios/RNSVGRenderable.m +++ b/ios/RNSVGRenderable.m @@ -121,7 +121,7 @@ // This is a terminal with only one painting. Therefore we don't need to paint this // off-screen. We can just composite it straight onto the buffer. CGContextSaveGState(context); - CGContextConcatCTM(context, self.matrix); + CGContextConcatCTM(context, self.transform); CGContextSetAlpha(context, self.opacity); [self renderClip:context]; [self renderLayerTo:context];