mirror of
https://github.com/zoriya/react-native-svg.git
synced 2026-05-25 12:03:27 +00:00
Refactor, optimize.
This commit is contained in:
@@ -19,7 +19,6 @@ class FontData {
|
||||
private static final String WORD_SPACING = "wordSpacing";
|
||||
private static final String LETTER_SPACING = "letterSpacing";
|
||||
private static final String TEXT_DECORATION = "textDecoration";
|
||||
private static final String ALIGNMENT_BASELINE = "alignmentBaseline";
|
||||
|
||||
final double fontSize;
|
||||
|
||||
|
||||
@@ -122,18 +122,8 @@ class TSpanShadowNode extends TextShadowNode {
|
||||
is adjusted to take into account various horizontal alignment text properties and
|
||||
attributes, such as a ‘dx’ attribute value on a ‘tspan’ element.
|
||||
*/
|
||||
double offset;
|
||||
final TextAnchor textAnchor = font.textAnchor;
|
||||
final double textMeasure = paint.measureText(line);
|
||||
if (textAnchor == TextAnchor.start) {
|
||||
offset = 0;
|
||||
} else {
|
||||
if (textAnchor == TextAnchor.middle) {
|
||||
offset = -textMeasure / 2;
|
||||
} else {
|
||||
offset = -textMeasure;
|
||||
}
|
||||
}
|
||||
double offset = getTextAnchorOffset(font.textAnchor, textMeasure);
|
||||
|
||||
double distance = 0;
|
||||
PathMeasure pm = null;
|
||||
@@ -144,9 +134,7 @@ class TSpanShadowNode extends TextShadowNode {
|
||||
if (distance == 0) {
|
||||
return path;
|
||||
}
|
||||
final double size = gc.getFontSize();
|
||||
final String startOffset = textPath.getStartOffset();
|
||||
offset += PropHelper.fromRelative(startOffset, distance, 0, mScale, size);
|
||||
offset += getAbsoluteStartOffset(distance, gc.getFontSize(), textPath.getStartOffset());
|
||||
/*
|
||||
TextPathSpacing spacing = textPath.getSpacing();
|
||||
if (spacing == TextPathSpacing.auto) {
|
||||
@@ -305,6 +293,13 @@ class TSpanShadowNode extends TextShadowNode {
|
||||
}
|
||||
}
|
||||
|
||||
Matrix start = new Matrix();
|
||||
Matrix mid = new Matrix();
|
||||
Matrix end = new Matrix();
|
||||
|
||||
float[] startPointMatrixData = new float[9];
|
||||
float[] endPointMatrixData = new float[9];
|
||||
|
||||
final char[] chars = line.toCharArray();
|
||||
for (int index = 0; index < length; index++) {
|
||||
char currentChar = chars[index];
|
||||
@@ -342,13 +337,6 @@ class TSpanShadowNode extends TextShadowNode {
|
||||
double dy = gc.nextDeltaY();
|
||||
double r = gc.nextRotation();
|
||||
|
||||
Matrix start = new Matrix();
|
||||
Matrix mid = new Matrix();
|
||||
Matrix end = new Matrix();
|
||||
|
||||
float[] startPointMatrixData = new float[9];
|
||||
float[] endPointMatrixData = new float[9];
|
||||
|
||||
double startpoint = offset + x + dx - charWidth;
|
||||
|
||||
if (textPath != null) {
|
||||
@@ -448,6 +436,24 @@ class TSpanShadowNode extends TextShadowNode {
|
||||
return path;
|
||||
}
|
||||
|
||||
private double getAbsoluteStartOffset(double distance, double size, String startOffset) {
|
||||
return PropHelper.fromRelative(startOffset, distance, 0, mScale, size);
|
||||
}
|
||||
|
||||
private double getTextAnchorOffset(TextAnchor textAnchor, double textMeasure) {
|
||||
switch (textAnchor) {
|
||||
default:
|
||||
case start:
|
||||
return 0;
|
||||
|
||||
case middle:
|
||||
return -textMeasure / 2;
|
||||
|
||||
case end:
|
||||
return -textMeasure;
|
||||
}
|
||||
}
|
||||
|
||||
private void applyTextPropertiesToPaint(Paint paint, FontData font) {
|
||||
AssetManager assetManager = getThemedContext().getResources().getAssets();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user