mirror of
https://github.com/zoriya/react-native-svg.git
synced 2026-06-04 23:54:53 +00:00
Fix accumulation of dx/dy and push/pop of y in GlyphContext.
This commit is contained in:
@@ -29,7 +29,9 @@ public class GlyphContext {
|
|||||||
private ArrayList<ArrayList<Float>> mDeltaXContext;
|
private ArrayList<ArrayList<Float>> mDeltaXContext;
|
||||||
private ArrayList<ArrayList<Float>> mDeltaYContext;
|
private ArrayList<ArrayList<Float>> mDeltaYContext;
|
||||||
private ArrayList<Float> mXContext;
|
private ArrayList<Float> mXContext;
|
||||||
|
private ArrayList<Float> mYContext;
|
||||||
private @Nonnull PointF mCurrentLocation;
|
private @Nonnull PointF mCurrentLocation;
|
||||||
|
private @Nonnull PointF mCurrentDelta;
|
||||||
private float mScale;
|
private float mScale;
|
||||||
private float mWidth;
|
private float mWidth;
|
||||||
private float mHeight;
|
private float mHeight;
|
||||||
@@ -41,12 +43,14 @@ public class GlyphContext {
|
|||||||
mWidth = width;
|
mWidth = width;
|
||||||
mHeight = height;
|
mHeight = height;
|
||||||
mCurrentLocation = new PointF();
|
mCurrentLocation = new PointF();
|
||||||
|
mCurrentDelta = new PointF();
|
||||||
mFontContext = new ArrayList<>();
|
mFontContext = new ArrayList<>();
|
||||||
mLocationContext = new ArrayList<>();
|
mLocationContext = new ArrayList<>();
|
||||||
mDeltaContext = new ArrayList<>();
|
mDeltaContext = new ArrayList<>();
|
||||||
mDeltaXContext = new ArrayList<>();
|
mDeltaXContext = new ArrayList<>();
|
||||||
mDeltaYContext = new ArrayList<>();
|
mDeltaYContext = new ArrayList<>();
|
||||||
mXContext = new ArrayList<>();
|
mXContext = new ArrayList<>();
|
||||||
|
mYContext = new ArrayList<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void pushContext(@Nullable ReadableMap font, @Nullable ReadableArray deltaX, @Nullable ReadableArray deltaY, @Nullable String positionX, @Nullable String positionY) {
|
public void pushContext(@Nullable ReadableMap font, @Nullable ReadableArray deltaX, @Nullable ReadableArray deltaY, @Nullable String positionX, @Nullable String positionY) {
|
||||||
@@ -61,40 +65,48 @@ public class GlyphContext {
|
|||||||
}
|
}
|
||||||
|
|
||||||
mLocationContext.add(location);
|
mLocationContext.add(location);
|
||||||
mDeltaContext.add(new PointF(0, 0));
|
mDeltaContext.add(mCurrentDelta);
|
||||||
mFontContext.add(font);
|
mFontContext.add(font);
|
||||||
mDeltaXContext.add(getFloatArrayListFromReadableArray(deltaX));
|
mDeltaXContext.add(getFloatArrayListFromReadableArray(deltaX));
|
||||||
mDeltaYContext.add(getFloatArrayListFromReadableArray(deltaY));
|
mDeltaYContext.add(getFloatArrayListFromReadableArray(deltaY));
|
||||||
mXContext.add(location.x);
|
mXContext.add(location.x);
|
||||||
|
mYContext.add(location.y);
|
||||||
|
|
||||||
|
mCurrentDelta = clonePointF(mCurrentDelta);
|
||||||
mCurrentLocation = clonePointF(location);
|
mCurrentLocation = clonePointF(location);
|
||||||
mContextLength++;
|
mContextLength++;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void popContext() {
|
public void popContext() {
|
||||||
float x = mXContext.get(mContextLength - 1);
|
float x = mXContext.get(mContextLength - 1);
|
||||||
|
float y = mYContext.get(mContextLength - 1);
|
||||||
mFontContext.remove(mContextLength - 1);
|
mFontContext.remove(mContextLength - 1);
|
||||||
mLocationContext.remove(mContextLength - 1);
|
mLocationContext.remove(mContextLength - 1);
|
||||||
mDeltaContext.remove(mContextLength - 1);
|
mDeltaContext.remove(mContextLength - 1);
|
||||||
mDeltaXContext.remove(mContextLength - 1);
|
mDeltaXContext.remove(mContextLength - 1);
|
||||||
mDeltaYContext.remove(mContextLength - 1);
|
mDeltaYContext.remove(mContextLength - 1);
|
||||||
mXContext.remove(mContextLength - 1);
|
mXContext.remove(mContextLength - 1);
|
||||||
|
mYContext.remove(mContextLength - 1);
|
||||||
|
|
||||||
mContextLength--;
|
mContextLength--;
|
||||||
|
|
||||||
if (mContextLength != 0) {
|
if (mContextLength != 0) {
|
||||||
mXContext.set(mContextLength - 1, x);
|
mXContext.set(mContextLength - 1, x);
|
||||||
|
mYContext.set(mContextLength - 1, y);
|
||||||
PointF lastLocation = mLocationContext.get(mContextLength - 1);
|
PointF lastLocation = mLocationContext.get(mContextLength - 1);
|
||||||
|
PointF lastDelta = mDeltaContext.get(mContextLength - 1);
|
||||||
mCurrentLocation = clonePointF(lastLocation);
|
mCurrentLocation = clonePointF(lastLocation);
|
||||||
|
mCurrentDelta = clonePointF(lastDelta);
|
||||||
mCurrentLocation.x = lastLocation.x = x;
|
mCurrentLocation.x = lastLocation.x = x;
|
||||||
|
mCurrentLocation.y = lastLocation.y = y;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public PointF getNextGlyphPoint(float offset, float glyphWidth) {
|
public PointF getNextGlyphPoint(float offset, float glyphWidth) {
|
||||||
mXContext.set(mXContext.size() - 1, mCurrentLocation.x + offset + glyphWidth);
|
mXContext.set(mXContext.size() - 1, mCurrentLocation.x + offset + glyphWidth);
|
||||||
|
mYContext.set(mYContext.size() - 1, mCurrentLocation.y);
|
||||||
|
|
||||||
return new PointF(mCurrentLocation.x + offset, mCurrentLocation.y);
|
return new PointF(mCurrentLocation.x + offset, mCurrentLocation.y);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public PointF getNextGlyphDelta() {
|
public PointF getNextGlyphDelta() {
|
||||||
|
|||||||
@@ -114,8 +114,7 @@ public class TSpanShadowNode extends TextShadowNode {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
matrix.preTranslate(0, glyphDelta.y);
|
matrix.postTranslate(0, glyphPoint.y + glyphDelta.y);
|
||||||
matrix.postTranslate(0, glyphPoint.y);
|
|
||||||
} else {
|
} else {
|
||||||
matrix.setTranslate(glyphPoint.x + glyphDelta.x, glyphPoint.y + glyphDelta.y);
|
matrix.setTranslate(glyphPoint.x + glyphDelta.x, glyphPoint.y + glyphDelta.y);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user