Revert D46501420: Exclude trailing whitespace on measuring text width

Differential Revision:
D46501420

Original commit changeset: fba4acd38747

Original Phabricator Diff: D46501420

fbshipit-source-id: 64c76b96d0e12f9bd7edd4640904de9fce3b44e6
This commit is contained in:
Nick Gerleman 2023-06-08 18:38:55 -07:00 коммит произвёл Facebook GitHub Bot
Родитель 4b54c0b1fa
Коммит 48c0e41d06
5 изменённых файлов: 7 добавлений и 21 удалений

Просмотреть файл

@ -42,14 +42,12 @@ public class FontMetricsUtil {
X_HEIGHT_MEASUREMENT_TEXT, 0, X_HEIGHT_MEASUREMENT_TEXT.length(), xHeightBounds);
double xHeight = xHeightBounds.height() / AMPLIFICATION_FACTOR / dm.density;
for (int i = 0; i < layout.getLineCount(); i++) {
boolean endsWithNewLine = text.charAt(layout.getLineEnd(i) - 1) == '\n';
float lineWidth = endsWithNewLine ? layout.getLineMax(i) : layout.getLineWidth(i);
Rect bounds = new Rect();
layout.getLineBounds(i, bounds);
WritableMap line = Arguments.createMap();
line.putDouble("x", layout.getLineLeft(i) / dm.density);
line.putDouble("y", bounds.top / dm.density);
line.putDouble("width", lineWidth / dm.density);
line.putDouble("width", layout.getLineWidth(i) / dm.density);
line.putDouble("height", bounds.height() / dm.density);
line.putDouble("descender", layout.getLineDescent(i) / dm.density);
line.putDouble("ascender", -layout.getLineAscent(i) / dm.density);

Просмотреть файл

@ -135,9 +135,7 @@ public class ReactTextShadowNode extends ReactBaseTextShadowNode {
layoutWidth = width;
} else {
for (int lineIndex = 0; lineIndex < lineCount; lineIndex++) {
boolean endsWithNewLine = text.charAt(layout.getLineEnd(lineIndex) - 1) == '\n';
float lineWidth =
endsWithNewLine ? layout.getLineMax(lineIndex) : layout.getLineWidth(lineIndex);
float lineWidth = layout.getLineWidth(lineIndex);
if (lineWidth > layoutWidth) {
layoutWidth = lineWidth;
}

Просмотреть файл

@ -267,13 +267,11 @@ public class ReactTextView extends AppCompatTextView implements ReactCompoundVie
// the last offset in the layout will result in an endless loop. Work around
// this bug by avoiding getPrimaryHorizontal in that case.
if (start == text.length() - 1) {
boolean endsWithNewLine = text.charAt(layout.getLineEnd(line) - 1) == '\n';
float lineWidth = endsWithNewLine ? layout.getLineMax(line) : layout.getLineWidth(line);
placeholderHorizontalPosition =
isRtlParagraph
// Equivalent to `layout.getLineLeft(line)` but `getLineLeft` returns incorrect
// values when the paragraph is RTL and `setSingleLine(true)`.
? textViewWidth - (int) lineWidth
? textViewWidth - (int) layout.getLineWidth(line)
: (int) layout.getLineRight(line) - width;
} else {
// The direction of the paragraph may not be exactly the direction the string is heading

Просмотреть файл

@ -407,9 +407,7 @@ public class TextLayoutManager {
calculatedWidth = width;
} else {
for (int lineIndex = 0; lineIndex < calculatedLineCount; lineIndex++) {
boolean endsWithNewLine = text.charAt(layout.getLineEnd(lineIndex) - 1) == '\n';
float lineWidth =
endsWithNewLine ? layout.getLineMax(lineIndex) : layout.getLineWidth(lineIndex);
float lineWidth = layout.getLineWidth(lineIndex);
if (lineWidth > calculatedWidth) {
calculatedWidth = lineWidth;
}
@ -464,13 +462,11 @@ public class TextLayoutManager {
// the last offset in the layout will result in an endless loop. Work around
// this bug by avoiding getPrimaryHorizontal in that case.
if (start == text.length() - 1) {
boolean endsWithNewLine = text.charAt(layout.getLineEnd(line) - 1) == '\n';
float lineWidth = endsWithNewLine ? layout.getLineMax(line) : layout.getLineWidth(line);
placeholderLeftPosition =
isRtlParagraph
// Equivalent to `layout.getLineLeft(line)` but `getLineLeft` returns incorrect
// values when the paragraph is RTL and `setSingleLine(true)`.
? calculatedWidth - lineWidth
? calculatedWidth - layout.getLineWidth(line)
: layout.getLineRight(line) - placeholderWidth;
} else {
// The direction of the paragraph may not be exactly the direction the string is heading

Просмотреть файл

@ -429,9 +429,7 @@ public class TextLayoutManagerMapBuffer {
calculatedWidth = width;
} else {
for (int lineIndex = 0; lineIndex < calculatedLineCount; lineIndex++) {
boolean endsWithNewLine = text.charAt(layout.getLineEnd(lineIndex) - 1) == '\n';
float lineWidth =
endsWithNewLine ? layout.getLineMax(lineIndex) : layout.getLineWidth(lineIndex);
float lineWidth = layout.getLineWidth(lineIndex);
if (lineWidth > calculatedWidth) {
calculatedWidth = lineWidth;
}
@ -486,14 +484,12 @@ public class TextLayoutManagerMapBuffer {
// the last offset in the layout will result in an endless loop. Work around
// this bug by avoiding getPrimaryHorizontal in that case.
if (start == text.length() - 1) {
boolean endsWithNewLine = text.charAt(layout.getLineEnd(line) - 1) == '\n';
float lineWidth = endsWithNewLine ? layout.getLineMax(line) : layout.getLineWidth(line);
placeholderLeftPosition =
isRtlParagraph
// Equivalent to `layout.getLineLeft(line)` but `getLineLeft` returns
// incorrect
// values when the paragraph is RTL and `setSingleLine(true)`.
? calculatedWidth - lineWidth
? calculatedWidth - layout.getLineWidth(line)
: layout.getLineRight(line) - placeholderWidth;
} else {
// The direction of the paragraph may not be exactly the direction the string is