Skip to content

Commit

Permalink
fix: getScreenCTM calculation
Browse files Browse the repository at this point in the history
  • Loading branch information
msand committed Oct 5, 2019
1 parent f3e0b19 commit 5c5072d
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -189,15 +189,16 @@ public void getScreenCTM(int tag, Callback successCallback) {
RenderableView svg = RenderableViewManager.getRenderableViewByTag(tag);
Matrix screenCTM = svg.mCTM;
SvgView root = svg.getSvgView();
float scale = svg.mScale;
float[] values = new float[9];
screenCTM.getValues(values);
WritableMap result = Arguments.createMap();
result.putDouble("a", values[Matrix.MSCALE_X]);
result.putDouble("b", values[Matrix.MSKEW_Y]);
result.putDouble("c", values[Matrix.MSKEW_X]);
result.putDouble("d", values[Matrix.MSCALE_Y]);
result.putDouble("e", values[Matrix.MTRANS_X] + root.getLeft());
result.putDouble("f", values[Matrix.MTRANS_Y] + root.getTop());
result.putDouble("e", values[Matrix.MTRANS_X] + root.getLeft() / scale);
result.putDouble("f", values[Matrix.MTRANS_Y] + root.getTop() / scale);
successCallback.invoke(result);
}
}
1 change: 1 addition & 0 deletions ios/Elements/RNSVGSvgView.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
@property (nonatomic, assign) CGRect boundingBox;
@property (nonatomic, assign) CGAffineTransform initialCTM;
@property (nonatomic, assign) CGAffineTransform invInitialCTM;
@property (nonatomic, assign) CGAffineTransform viewBoxTransform;



Expand Down
1 change: 0 additions & 1 deletion ios/Elements/RNSVGSvgView.m
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ @implementation RNSVGSvgView
NSMutableDictionary<NSString *, RNSVGPainter *> *_painters;
NSMutableDictionary<NSString *, RNSVGNode *> *_markers;
NSMutableDictionary<NSString *, RNSVGNode *> *_masks;
CGAffineTransform _viewBoxTransform;
CGAffineTransform _invviewBoxTransform;
bool rendered;
}
Expand Down
33 changes: 16 additions & 17 deletions ios/ViewManagers/RNSVGRenderableManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -226,12 +226,12 @@ - (void)withTag:(nonnull NSNumber *)reactTag success:(RNSVGSuccessBlock)successB
callback(
@[
@{
@"a":n(ctm.a),
@"b":n(ctm.b),
@"c":n(ctm.c),
@"d":n(ctm.d),
@"e":n(ctm.tx),
@"f":n(ctm.ty)
@"a":@(ctm.a),
@"b":@(ctm.b),
@"c":@(ctm.c),
@"d":@(ctm.d),
@"e":@(ctm.tx),
@"f":@(ctm.ty)
}
]
);
Expand All @@ -242,25 +242,24 @@ - (void)withTag:(nonnull NSNumber *)reactTag success:(RNSVGSuccessBlock)successB
attempt:0];
}

static NSNumber *n(CGFloat af) {
return [NSNumber numberWithDouble:af];
}

RCT_EXPORT_METHOD(getScreenCTM:(nonnull NSNumber *)reactTag callback:(RCTResponseSenderBlock)callback)
{
[self
withTag:reactTag
success:^(RNSVGRenderable *svg){
CGAffineTransform ctm = svg.screenCTM;
RNSVGSvgView* root = svg.svgView;
CGAffineTransform viewbox = [root getViewBoxTransform];
CGAffineTransform ctm = CGAffineTransformConcat(svg.ctm, viewbox);
CGPoint offset = [root convertPoint:CGPointZero toView:svg.window];
callback(
@[
@{
@"a":n(ctm.a),
@"b":n(ctm.b),
@"c":n(ctm.c),
@"d":n(ctm.d),
@"e":n(ctm.tx),
@"f":n(ctm.ty)
@"a":@(ctm.a),
@"b":@(ctm.b),
@"c":@(ctm.c),
@"d":@(ctm.d),
@"e":@(ctm.tx + offset.x),
@"f":@(ctm.ty + offset.y)
}
]
);
Expand Down

0 comments on commit 5c5072d

Please sign in to comment.