mirror of
https://github.com/zoriya/react-native-svg.git
synced 2026-06-01 14:15:03 +00:00
Implement correct calculation of fontSize from ancestors.
This commit is contained in:
@@ -35,6 +35,7 @@ class GlyphContext {
|
||||
private ArrayList<ArrayList<Float>> mDeltaYsContext = new ArrayList<>();
|
||||
private ArrayList<ReadableMap> mFontContext = new ArrayList<>();
|
||||
private ArrayList<Float> mRotationContext = new ArrayList<>();
|
||||
private ArrayList<GroupShadowNode> mNodes = new ArrayList<>();
|
||||
private ArrayList<Float> mRotations = new ArrayList<>();
|
||||
private @Nonnull PointF mCurrentLocation = new PointF();
|
||||
private ArrayList<Float> mDeltaXs = new ArrayList<>();
|
||||
@@ -55,7 +56,7 @@ class GlyphContext {
|
||||
mScale = scale;
|
||||
}
|
||||
|
||||
void pushContext(@Nullable ReadableMap font) {
|
||||
void pushContext(GroupShadowNode node, @Nullable ReadableMap font) {
|
||||
mRotationsContext.add(mRotations);
|
||||
mRotationContext.add(mRotation);
|
||||
mDeltaXsContext.add(mDeltaXs);
|
||||
@@ -63,11 +64,12 @@ class GlyphContext {
|
||||
mXPositionsContext.add(mXs);
|
||||
mYPositionsContext.add(mYs);
|
||||
mFontContext.add(font);
|
||||
mNodes.add(node);
|
||||
mContextLength++;
|
||||
top++;
|
||||
}
|
||||
|
||||
void pushContext(@Nullable ReadableMap font, @Nullable ReadableArray rotate, @Nullable ReadableArray deltaX, @Nullable ReadableArray deltaY, @Nullable String positionX, @Nullable String positionY) {
|
||||
void pushContext(TextShadowNode node, @Nullable ReadableMap font, @Nullable ReadableArray rotate, @Nullable ReadableArray deltaX, @Nullable ReadableArray deltaY, @Nullable String positionX, @Nullable String positionY) {
|
||||
if (positionX != null) {
|
||||
mXs = new ArrayList<>(Arrays.asList(positionX.trim().split("\\s+")));
|
||||
}
|
||||
@@ -99,6 +101,7 @@ class GlyphContext {
|
||||
mXPositionsContext.add(mXs);
|
||||
mYPositionsContext.add(mYs);
|
||||
mFontContext.add(font);
|
||||
mNodes.add(node);
|
||||
mContextLength++;
|
||||
top++;
|
||||
}
|
||||
@@ -117,6 +120,7 @@ class GlyphContext {
|
||||
mDeltaYsContext.remove(mContextLength);
|
||||
|
||||
mFontContext.remove(mContextLength);
|
||||
mNodes.remove(mContextLength);
|
||||
|
||||
if (mContextLength != 0) {
|
||||
mRotations = mRotationsContext.get(top);
|
||||
@@ -225,6 +229,10 @@ class GlyphContext {
|
||||
}
|
||||
}
|
||||
|
||||
if (top > -1) {
|
||||
return mNodes.get(0).getFontSizeFromParentContext();
|
||||
}
|
||||
|
||||
return DEFAULT_FONT_SIZE;
|
||||
}
|
||||
|
||||
|
||||
@@ -48,7 +48,7 @@ class GroupShadowNode extends RenderableShadowNode {
|
||||
}
|
||||
|
||||
protected void pushGlyphContext() {
|
||||
getTextRoot().getGlyphContext().pushContext(mFont);
|
||||
getTextRoot().getGlyphContext().pushContext(this, mFont);
|
||||
}
|
||||
|
||||
protected void popGlyphContext() {
|
||||
|
||||
@@ -178,6 +178,6 @@ class TextShadowNode extends GroupShadowNode {
|
||||
|
||||
@Override
|
||||
protected void pushGlyphContext() {
|
||||
getTextRoot().getGlyphContext().pushContext(mFont, mRotate, mDeltaX, mDeltaY, mPositionX, mPositionY);
|
||||
getTextRoot().getGlyphContext().pushContext(this, mFont, mRotate, mDeltaX, mDeltaY, mPositionX, mPositionY);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -51,6 +51,7 @@ public abstract class VirtualNode extends LayoutShadowNode {
|
||||
|
||||
private SvgViewShadowNode mSvgShadowNode;
|
||||
private Path mCachedClipPath;
|
||||
private GroupShadowNode mParentTextRoot;
|
||||
private GroupShadowNode mTextRoot;
|
||||
|
||||
public VirtualNode() {
|
||||
@@ -70,6 +71,37 @@ public abstract class VirtualNode extends LayoutShadowNode {
|
||||
return shadowNode;
|
||||
}
|
||||
|
||||
GroupShadowNode getParentTextRoot() {
|
||||
GroupShadowNode shadowNode = getParentShadowNode(GroupShadowNode.class);
|
||||
if (shadowNode == null) {
|
||||
return getParentShadowNode(TextShadowNode.class);
|
||||
}
|
||||
return shadowNode;
|
||||
}
|
||||
|
||||
@android.support.annotation.Nullable
|
||||
private GroupShadowNode getParentShadowNode(Class shadowNodeClass) {
|
||||
ReactShadowNode node = this.getParent();
|
||||
if (mParentTextRoot == null) {
|
||||
while (node != null) {
|
||||
if (node.getClass() == shadowNodeClass) {
|
||||
mParentTextRoot = (GroupShadowNode)node;
|
||||
break;
|
||||
}
|
||||
|
||||
ReactShadowNode parent = node.getParent();
|
||||
|
||||
if (!(parent instanceof VirtualNode)) {
|
||||
node = null;
|
||||
} else {
|
||||
node = parent;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return mParentTextRoot;
|
||||
}
|
||||
|
||||
@android.support.annotation.Nullable
|
||||
private GroupShadowNode getShadowNode(Class shadowNodeClass) {
|
||||
VirtualNode node = this;
|
||||
@@ -101,6 +133,14 @@ public abstract class VirtualNode extends LayoutShadowNode {
|
||||
return root.getGlyphContext().getFontSize();
|
||||
}
|
||||
|
||||
double getFontSizeFromParentContext() {
|
||||
GroupShadowNode root = getParentTextRoot();
|
||||
if (root == null) {
|
||||
return DEFAULT_FONT_SIZE;
|
||||
}
|
||||
return root.getGlyphContext().getFontSize();
|
||||
}
|
||||
|
||||
public abstract void draw(Canvas canvas, Paint paint, float opacity);
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user