Improve naming

This commit is contained in:
Mikael Sand
2017-07-23 07:45:58 +03:00
parent 8f62650bac
commit 99995056a9
@@ -114,8 +114,8 @@ class TSpanShadowNode extends TextShadowNode {
} }
private Path getLinePath(String line, Paint paint) { private Path getLinePath(String line, Paint paint) {
int length = line.length(); final int length = line.length();
Path path = new Path(); final Path path = new Path();
if (length == 0) { if (length == 0) {
return path; return path;
@@ -128,17 +128,17 @@ class TSpanShadowNode extends TextShadowNode {
double offset = 0; double offset = 0;
double distance = 0; double distance = 0;
double renderMethodScaling = 1; double renderMethodScaling = 1;
double textMeasure = paint.measureText(line); final double textMeasure = paint.measureText(line);
PathMeasure pm = null; PathMeasure pm = null;
if (textPath != null) { if (textPath != null) {
pm = new PathMeasure(textPath.getPath(), false); pm = new PathMeasure(textPath.getPath(), false);
distance = pm.getLength(); distance = pm.getLength();
double size = gc.getFontSize(); final double size = gc.getFontSize();
String startOffset = textPath.getStartOffset(); final String startOffset = textPath.getStartOffset();
offset = PropHelper.fromRelative(startOffset, distance, 0, mScale, size); offset = PropHelper.fromRelative(startOffset, distance, 0, mScale, size);
// String spacing = textPath.getSpacing(); // spacing = "auto | exact" // String spacing = textPath.getSpacing(); // spacing = "auto | exact"
String method = textPath.getMethod(); // method = "align | stretch" final String method = textPath.getMethod(); // method = "align | stretch"
if (STRETCH.equals(method)) { if (STRETCH.equals(method)) {
renderMethodScaling = distance / textMeasure; renderMethodScaling = distance / textMeasure;
} }
@@ -153,12 +153,12 @@ class TSpanShadowNode extends TextShadowNode {
double dy; double dy;
Path glyph; Path glyph;
double width;
Matrix matrix; Matrix matrix;
String current; String current;
double glyphWidth;
String previous = ""; String previous = "";
double previousWidth = 0; double previousGlyphWidth = 0;
char[] chars = line.toCharArray(); final char[] chars = line.toCharArray();
/* /*
* *
@@ -180,15 +180,15 @@ class TSpanShadowNode extends TextShadowNode {
* *
* */ * */
boolean hasKerning = font.hasKey(PROP_KERNING); final boolean hasKerning = font.hasKey(PROP_KERNING);
double kerning = hasKerning ? font.getDouble(PROP_KERNING) * mScale : DEFAULT_KERNING; double kerning = hasKerning ? font.getDouble(PROP_KERNING) * mScale : DEFAULT_KERNING;
boolean autoKerning = !hasKerning; final boolean autoKerning = !hasKerning;
double wordSpacing = font.hasKey(PROP_WORD_SPACING) ? final double wordSpacing = font.hasKey(PROP_WORD_SPACING) ?
font.getDouble(PROP_WORD_SPACING) * mScale font.getDouble(PROP_WORD_SPACING) * mScale
: DEFAULT_WORD_SPACING; : DEFAULT_WORD_SPACING;
double letterSpacing = font.hasKey(PROP_LETTER_SPACING) ? final double letterSpacing = font.hasKey(PROP_LETTER_SPACING) ?
font.getDouble(PROP_LETTER_SPACING) * mScale font.getDouble(PROP_LETTER_SPACING) * mScale
: DEFAULT_LETTER_SPACING; : DEFAULT_LETTER_SPACING;
@@ -197,19 +197,20 @@ class TSpanShadowNode extends TextShadowNode {
final char currentChar = chars[index]; final char currentChar = chars[index];
current = String.valueOf(currentChar); current = String.valueOf(currentChar);
paint.getTextPath(current, 0, 1, 0, 0, glyph); paint.getTextPath(current, 0, 1, 0, 0, glyph);
width = paint.measureText(current) * renderMethodScaling; glyphWidth = paint.measureText(current) * renderMethodScaling;
if (autoKerning) { if (autoKerning) {
double both = paint.measureText(previous + current) * renderMethodScaling; double bothGlyphWidth = paint.measureText(previous + current) * renderMethodScaling;
kerning = both - previousWidth - width; kerning = bothGlyphWidth - previousGlyphWidth - glyphWidth;
previousWidth = width; previousGlyphWidth = glyphWidth;
previous = current; previous = current;
} }
boolean isWordSeparator = currentChar == ' '; final boolean isWordSeparator = currentChar == ' ';
double wordSpace = isWordSeparator ? wordSpacing : 0; final double wordSpace = isWordSeparator ? wordSpacing : 0;
final double advance = glyphWidth + kerning + wordSpace + letterSpacing;
x = gc.nextX(width + kerning + wordSpace + letterSpacing); x = gc.nextX(advance);
y = gc.nextY(); y = gc.nextY();
dx = gc.nextDeltaX(); dx = gc.nextDeltaX();
dy = gc.nextDeltaY(); dy = gc.nextDeltaY();
@@ -217,11 +218,11 @@ class TSpanShadowNode extends TextShadowNode {
matrix = new Matrix(); matrix = new Matrix();
double xSum = offset + x + dx - width; final double glyphStart = offset + x + dx - glyphWidth;
if (textPath != null) { if (textPath != null) {
double halfway = width / 2; double halfGlyphWidth = glyphWidth / 2;
double midpoint = xSum + halfway; double midpoint = glyphStart + halfGlyphWidth;
if (midpoint > distance) { if (midpoint > distance) {
break; break;
@@ -232,11 +233,11 @@ class TSpanShadowNode extends TextShadowNode {
assert pm != null; assert pm != null;
pm.getMatrix((float) midpoint, matrix, POSITION_MATRIX_FLAG | TANGENT_MATRIX_FLAG); pm.getMatrix((float) midpoint, matrix, POSITION_MATRIX_FLAG | TANGENT_MATRIX_FLAG);
matrix.preTranslate((float) -halfway, (float) dy); matrix.preTranslate((float) -halfGlyphWidth, (float) dy);
matrix.preScale((float) renderMethodScaling, (float) renderMethodScaling); matrix.preScale((float) renderMethodScaling, (float) renderMethodScaling);
matrix.postTranslate(0, (float) y); matrix.postTranslate(0, (float) y);
} else { } else {
matrix.setTranslate((float) xSum, (float) (y + dy)); matrix.setTranslate((float) glyphStart, (float) (y + dy));
} }
matrix.preRotate((float) r); matrix.preRotate((float) r);