Skip to content

Commit

Permalink
fix: replace transforms with just matrix
Browse files Browse the repository at this point in the history
  • Loading branch information
jakex7 committed Nov 28, 2024
1 parent cc455ca commit 585b65e
Show file tree
Hide file tree
Showing 9 changed files with 17 additions and 33 deletions.
3 changes: 1 addition & 2 deletions apple/Elements/RNSVGForeignObject.mm
Original file line number Diff line number Diff line change
Expand Up @@ -160,9 +160,8 @@ - (void)renderGroupTo:(CGContextRef)context rect:(CGRect)rect
self.ctm = svgToClientTransform;
self.screenCTM = current;

CGAffineTransform transform = CGAffineTransformConcat(self.matrix, self.transforms);
CGPoint mid = CGPointMake(CGRectGetMidX(bounds), CGRectGetMidY(bounds));
CGPoint center = CGPointApplyAffineTransform(mid, transform);
CGPoint center = CGPointApplyAffineTransform(mid, self.matrix);

self.bounds = bounds;
if (!isnan(center.x) && !isnan(center.y)) {
Expand Down
7 changes: 2 additions & 5 deletions apple/Elements/RNSVGGroup.mm
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,8 @@ - (void)renderGroupTo:(CGContextRef)context rect:(CGRect)rect
self.ctm = svgToClientTransform;
self.screenCTM = current;

CGAffineTransform transform = CGAffineTransformConcat(self.matrix, self.transforms);
CGPoint mid = CGPointMake(CGRectGetMidX(bounds), CGRectGetMidY(bounds));
CGPoint center = CGPointApplyAffineTransform(mid, transform);
CGPoint center = CGPointApplyAffineTransform(mid, self.matrix);

self.bounds = bounds;
if (!isnan(center.x) && !isnan(center.y)) {
Expand All @@ -163,7 +162,6 @@ - (void)setupGlyphContext:(CGContextRef)context
}
#endif // macOS]
clipBounds = CGRectApplyAffineTransform(clipBounds, self.matrix);
clipBounds = CGRectApplyAffineTransform(clipBounds, self.transforms);
CGFloat width = CGRectGetWidth(clipBounds);
CGFloat height = CGRectGetHeight(clipBounds);

Expand Down Expand Up @@ -200,7 +198,7 @@ - (CGPathRef)getPath:(CGContextRef)context
CGMutablePathRef __block path = CGPathCreateMutable();
[self traverseSubviews:^(RNSVGNode *node) {
if ([node isKindOfClass:[RNSVGNode class]] && ![node isKindOfClass:[RNSVGMask class]]) {
CGAffineTransform transform = CGAffineTransformConcat(node.matrix, node.transforms);
CGAffineTransform transform = node.matrix;
CGPathAddPath(path, &transform, [node getPath:context]);
CGPathAddPath(path, &transform, [node markerPath]);
node.dirty = false;
Expand All @@ -216,7 +214,6 @@ - (CGPathRef)getPath:(CGContextRef)context
- (RNSVGPlatformView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event
{
CGPoint transformed = CGPointApplyAffineTransform(point, self.invmatrix);
transformed = CGPointApplyAffineTransform(transformed, self.invTransform);

if (!CGRectContainsPoint(self.pathBounds, transformed)) {
return nil;
Expand Down
3 changes: 1 addition & 2 deletions apple/Elements/RNSVGImage.mm
Original file line number Diff line number Diff line change
Expand Up @@ -356,9 +356,8 @@ - (void)renderLayerTo:(CGContextRef)context rect:(CGRect)rect
self.ctm = svgToClientTransform;
self.screenCTM = current;

CGAffineTransform transform = CGAffineTransformConcat(self.matrix, self.transforms);
CGPoint mid = CGPointMake(CGRectGetMidX(bounds), CGRectGetMidY(bounds));
CGPoint center = CGPointApplyAffineTransform(mid, transform);
CGPoint center = CGPointApplyAffineTransform(mid, self.matrix);

self.bounds = bounds;
if (!isnan(center.x) && !isnan(center.y)) {
Expand Down
4 changes: 1 addition & 3 deletions apple/Elements/RNSVGUse.mm
Original file line number Diff line number Diff line change
Expand Up @@ -176,9 +176,8 @@ - (void)renderLayerTo:(CGContextRef)context rect:(CGRect)rect
self.ctm = svgToClientTransform;
self.screenCTM = current;

CGAffineTransform transform = CGAffineTransformConcat(self.matrix, self.transforms);
CGPoint mid = CGPointMake(CGRectGetMidX(bounds), CGRectGetMidY(bounds));
CGPoint center = CGPointApplyAffineTransform(mid, transform);
CGPoint center = CGPointApplyAffineTransform(mid, self.matrix);

self.bounds = bounds;
if (!isnan(center.x) && !isnan(center.y)) {
Expand All @@ -190,7 +189,6 @@ - (void)renderLayerTo:(CGContextRef)context rect:(CGRect)rect
- (RNSVGPlatformView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event
{
CGPoint transformed = CGPointApplyAffineTransform(point, self.invmatrix);
transformed = CGPointApplyAffineTransform(transformed, self.invTransform);
RNSVGNode const *definedTemplate = [self.svgView getDefinedTemplate:self.href];
if (event) {
self.active = NO;
Expand Down
4 changes: 2 additions & 2 deletions apple/RNSVGNode.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,7 @@ extern CGFloat const RNSVG_DEFAULT_FONT_SIZE;
@property (nonatomic, assign) CGAffineTransform ctm;
@property (nonatomic, assign) CGAffineTransform screenCTM;
@property (nonatomic, assign) CGAffineTransform matrix;
@property (nonatomic, assign) CGAffineTransform transforms;
@property (nonatomic, assign) CGAffineTransform invmatrix;
@property (nonatomic, assign) CGAffineTransform invTransform;
@property (nonatomic, assign) BOOL active;
@property (nonatomic, assign) BOOL dirty;
@property (nonatomic, assign) BOOL merging;
Expand Down Expand Up @@ -148,4 +146,6 @@ extern CGFloat const RNSVG_DEFAULT_FONT_SIZE;

- (CGFloat)getCanvasHeight;

- (void)setTransforms:(CGAffineTransform)transforms;

@end
12 changes: 3 additions & 9 deletions apple/RNSVGNode.mm
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@ - (instancetype)init
self.opaque = false;
#endif
self.matrix = CGAffineTransformIdentity;
self.transforms = CGAffineTransformIdentity;
self.invTransform = CGAffineTransformIdentity;
_merging = false;
_dirty = false;
}
Expand Down Expand Up @@ -250,11 +248,11 @@ - (void)setMatrix:(CGAffineTransform)matrix

- (void)setTransforms:(CGAffineTransform)transforms
{
if (CGAffineTransformEqualToTransform(transforms, _transforms)) {
if (CGAffineTransformEqualToTransform(transforms, _matrix)) {
return;
}

_transforms = transforms;
_matrix = transforms;
[self invalidate];
}

Expand Down Expand Up @@ -377,7 +375,7 @@ - (CGPathRef)getClipPath:(CGContextRef)context
if (_cachedClipPath) {
CGPathRelease(_cachedClipPath);
}
CGAffineTransform transform = CGAffineTransformConcat(_clipNode.matrix, _clipNode.transforms);
CGAffineTransform transform = CGAffineTransformConcat(_clipNode.matrix, _clipNode.matrix);
_cachedClipPath = CGPathCreateCopyByTransformingPath([_clipNode getPath:context], &transform);
}

Expand Down Expand Up @@ -630,8 +628,6 @@ - (void)prepareForRecycle
self.opaque = false;
#endif
self.matrix = CGAffineTransformIdentity;
self.transforms = CGAffineTransformIdentity;
self.invTransform = CGAffineTransformIdentity;
_merging = false;
_dirty = false;

Expand All @@ -652,9 +648,7 @@ - (void)prepareForRecycle
_ctm = CGAffineTransformIdentity;
_screenCTM = CGAffineTransformIdentity;
_matrix = CGAffineTransformIdentity;
_transforms = CGAffineTransformIdentity;
_invmatrix = CGAffineTransformIdentity;
_invTransform = CGAffineTransformIdentity;
_active = NO;
_skip = NO;
if (_markerPath) {
Expand Down
5 changes: 1 addition & 4 deletions apple/RNSVGRenderable.mm
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,6 @@ - (void)renderTo:(CGContextRef)context rect:(CGRect)rect
// This needs to be painted on a layer before being composited.
CGContextSaveGState(context);
CGContextConcatCTM(context, self.matrix);
CGContextConcatCTM(context, self.transforms);
CGContextSetAlpha(context, self.opacity);

[self beginTransparencyLayer:context];
Expand Down Expand Up @@ -530,8 +529,7 @@ - (void)renderLayerTo:(CGContextRef)context rect:(CGRect)rect
}

CGAffineTransform vbmatrix = self.svgView.getViewBoxTransform;
CGAffineTransform transform = CGAffineTransformConcat(self.matrix, self.transforms);
CGAffineTransform matrix = CGAffineTransformConcat(transform, vbmatrix);
CGAffineTransform matrix = CGAffineTransformConcat(self.matrix, vbmatrix);

CGRect bounds = CGRectMake(0, 0, CGRectGetWidth(clientRect), CGRectGetHeight(clientRect));
CGPoint mid = CGPointMake(CGRectGetMidX(pathBounds), CGRectGetMidY(pathBounds));
Expand Down Expand Up @@ -687,7 +685,6 @@ - (RNSVGPlatformView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event
}

CGPoint transformed = CGPointApplyAffineTransform(point, self.invmatrix);
transformed = CGPointApplyAffineTransform(transformed, self.invTransform);

if (!CGRectContainsPoint(self.pathBounds, transformed) && !CGRectContainsPoint(self.markerBounds, transformed)) {
return nil;
Expand Down
11 changes: 6 additions & 5 deletions apple/Utils/RNSVGFabricConversions.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,12 @@ void setCommonNodeProps(const T &nodeProps, RNSVGNode *node)
nodeProps.matrix.at(4),
nodeProps.matrix.at(5));
}
auto newTransform = nodeProps.resolveTransform(MinimalLayoutMetrics);
CATransform3D transform3d = RCTCATransform3DFromTransformMatrix(newTransform);
CGAffineTransform transform = CATransform3DGetAffineTransform(transform3d);
node.invTransform = CGAffineTransformInvert(transform);
node.transforms = transform;
if (nodeProps.transform.operations.size() > 0) {
auto newTransform = nodeProps.resolveTransform(MinimalLayoutMetrics);
CATransform3D transform3d = RCTCATransform3DFromTransformMatrix(newTransform);
CGAffineTransform transform = CATransform3DGetAffineTransform(transform3d);
node.transforms = transform;
}
node.mask = RCTNSStringFromStringNilIfEmpty(nodeProps.mask);
node.markerStart = RCTNSStringFromStringNilIfEmpty(nodeProps.markerStart);
node.markerMid = RCTNSStringFromStringNilIfEmpty(nodeProps.markerMid);
Expand Down
1 change: 0 additions & 1 deletion apple/ViewManagers/RNSVGNodeManager.mm
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ - (RNSVGPlatformView *)view
{
CATransform3D transform3d = json ? [RCTConvert CATransform3D:json] : defaultView.layer.transform;
CGAffineTransform transform = CATransform3DGetAffineTransform(transform3d);
view.invTransform = CGAffineTransformInvert(transform);
view.transforms = transform;
}
RCT_EXPORT_VIEW_PROPERTY(mask, NSString)
Expand Down

0 comments on commit 585b65e

Please sign in to comment.