mirror of
https://github.com/zoriya/react-native-svg.git
synced 2026-06-04 15:44:24 +00:00
Fix text-anchor subtree advance/extent calculation for letter-spacing
Related to https://github.com/react-native-community/react-native-svg/issues/570
This commit is contained in:
@@ -19,7 +19,7 @@ import javax.annotation.Nullable;
|
||||
class GlyphContext {
|
||||
|
||||
// Current stack (one per node push/pop)
|
||||
private final ArrayList<FontData> mFontContext = new ArrayList<>();
|
||||
final ArrayList<FontData> mFontContext = new ArrayList<>();
|
||||
|
||||
// Unique input attribute lists (only added if node sets a value)
|
||||
private final ArrayList<SVGLength[]> mXsContext = new ArrayList<>();
|
||||
|
||||
@@ -146,6 +146,7 @@ class TSpanView extends TextView {
|
||||
String disableDiscretionaryLigatures = "'liga' 0, 'clig' 0, 'dlig' 0, 'hlig' 0, 'cala' 0, ";
|
||||
paint.setFontFeatureSettings(defaultFeatures + disableDiscretionaryLigatures + font.fontFeatureSettings);
|
||||
}
|
||||
paint.setLetterSpacing((float)(letterSpacing / (font.fontSize * mScale)));
|
||||
}
|
||||
|
||||
return paint.measureText(line);
|
||||
@@ -610,7 +611,7 @@ class TSpanView extends TextView {
|
||||
// this will just retrieve the bounding rect for 'x'
|
||||
paint.getTextBounds("x", 0, 1, bounds);
|
||||
int xHeight = bounds.height();
|
||||
baselineShift = xHeight / 2;
|
||||
baselineShift = xHeight / 2.0;
|
||||
break;
|
||||
|
||||
case central:
|
||||
@@ -738,7 +739,6 @@ class TSpanView extends TextView {
|
||||
final Matrix end = new Matrix();
|
||||
|
||||
final float[] startPointMatrixData = new float[9];
|
||||
final float[] midPointMatrixData = new float[9];
|
||||
final float[] endPointMatrixData = new float[9];
|
||||
|
||||
emoji.clear();
|
||||
@@ -1008,6 +1008,9 @@ class TSpanView extends TextView {
|
||||
paint.setTypeface(typeface);
|
||||
paint.setTextSize((float) fontSize);
|
||||
paint.setTextAlign(Paint.Align.LEFT);
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
||||
paint.setLetterSpacing(0);
|
||||
}
|
||||
|
||||
// Do these have any effect for anyone? Not for me (@msand) at least.
|
||||
// paint.setUnderlineText(underlineText);
|
||||
|
||||
@@ -213,23 +213,17 @@ class TextView extends GroupView {
|
||||
|
||||
TextView getTextAnchorRoot() {
|
||||
GlyphContext gc = getTextRootGlyphContext();
|
||||
FontData font = gc.getFont();
|
||||
TextProperties.TextAnchor textAnchor = font.textAnchor;
|
||||
if (textAnchor == TextProperties.TextAnchor.start) {
|
||||
return this;
|
||||
}
|
||||
ArrayList<FontData> font = gc.mFontContext;
|
||||
TextView node = this;
|
||||
ViewParent parent = this.getParent();
|
||||
if (parent instanceof TextView) {
|
||||
TextView parentText = (TextView)parent;
|
||||
GlyphContext parentGc = parentText.getGlyphContext();
|
||||
FontData parentFont = parentGc.getFont();
|
||||
if (parentFont.textAnchor == TextProperties.TextAnchor.start) {
|
||||
return this;
|
||||
} else {
|
||||
return parentText.getTextAnchorRoot();
|
||||
for (int i = font.size() - 1; i >= 0; i--) {
|
||||
if (!(parent instanceof TextView) || font.get(i).textAnchor == TextProperties.TextAnchor.start) {
|
||||
return node;
|
||||
}
|
||||
node = (TextView) parent;
|
||||
parent = node.getParent();
|
||||
}
|
||||
return this;
|
||||
return node;
|
||||
}
|
||||
|
||||
double getSubtreeTextChunksTotalAdvance(Paint paint) {
|
||||
@@ -240,7 +234,7 @@ class TextView extends GroupView {
|
||||
for (int i = 0; i < getChildCount(); i++) {
|
||||
View child = getChildAt(i);
|
||||
if (child instanceof TextView) {
|
||||
TextView text = (TextView)child;
|
||||
TextView text = (TextView) child;
|
||||
advance += text.getSubtreeTextChunksTotalAdvance(paint);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user