Skip to content

Commit

Permalink
fix(android): native method scaling and getScreenCTM offset
Browse files Browse the repository at this point in the history
  • Loading branch information
msand committed Oct 4, 2019
1 parent 8687a3d commit f3e0b19
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions android/src/main/java/com/horcrux/svg/RNSVGRenderableManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,8 @@ public void isPointInStroke(int tag, ReadableMap options, Callback successCallba
public void getTotalLength(int tag, Callback successCallback) {
RenderableView svg = RenderableViewManager.getRenderableViewByTag(tag);
PathMeasure pm = new PathMeasure(svg.getPath(null, null), false);
successCallback.invoke(pm.getLength());
float scale = svg.mScale;
successCallback.invoke(pm.getLength() / scale);
}

@SuppressWarnings("unused")
Expand All @@ -119,8 +120,9 @@ public void getPointAtLength(int tag, ReadableMap options, Callback successCallb
pm.getPosTan(Math.max(0, Math.min(length, pathLength)), pos, tan);
double angle = Math.atan2(tan[1], tan[0]);
WritableMap result = Arguments.createMap();
result.putDouble("x", pos[0]);
result.putDouble("y", pos[1]);
float scale = svg.mScale;
result.putDouble("x", pos[0] / scale);
result.putDouble("y", pos[1] / scale);
result.putDouble("angle", angle);
successCallback.invoke(result);
}
Expand Down Expand Up @@ -152,10 +154,11 @@ public void getBBox(int tag, ReadableMap options, Callback successCallback) {
}
}
WritableMap result = Arguments.createMap();
result.putDouble("x", bounds.left);
result.putDouble("y", bounds.top);
result.putDouble("width", bounds.width());
result.putDouble("height", bounds.height());
float scale = svg.mScale;
result.putDouble("x", bounds.left / scale);
result.putDouble("y", bounds.top / scale);
result.putDouble("width", bounds.width() / scale);
result.putDouble("height", bounds.height() / scale);
successCallback.invoke(result);
}

Expand Down Expand Up @@ -185,15 +188,16 @@ public void getCTM(int tag, Callback successCallback) {
public void getScreenCTM(int tag, Callback successCallback) {
RenderableView svg = RenderableViewManager.getRenderableViewByTag(tag);
Matrix screenCTM = svg.mCTM;
SvgView root = svg.getSvgView();
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]);
result.putDouble("f", values[Matrix.MTRANS_Y]);
result.putDouble("e", values[Matrix.MTRANS_X] + root.getLeft());
result.putDouble("f", values[Matrix.MTRANS_Y] + root.getTop());
successCallback.invoke(result);
}
}

0 comments on commit f3e0b19

Please sign in to comment.