Skip to content

Commit

Permalink
fix fabric issue with newlines
Browse files Browse the repository at this point in the history
  • Loading branch information
Szymon20000 committed Mar 10, 2023
1 parent 4a5eeef commit 2b7bda1
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -393,12 +393,17 @@ public static long measureText(
: UNSET;

int lines = layout.getLineCount();
if (numberOfLines != UNSET && numberOfLines != 0 && numberOfLines > lines && text.length() > 0) {
if (numberOfLines != UNSET && numberOfLines != 0 && numberOfLines >= lines && text.length() > 0) {
int numberOfEmptyLines = numberOfLines - lines;
SpannableStringBuilder ssb = new SpannableStringBuilder();

// for some reason a newline on end causes issues with computing height so we add a character
if (text.toString().endsWith("\n")) {
ssb.append("A");
}

for (int i = 0; i < numberOfEmptyLines; ++i) {
ssb.append("\n");
ssb.append("\nA");
}

Object[] spans = text.getSpans(0, 0, Object.class);
Expand All @@ -419,7 +424,7 @@ public static long measureText(
}


if (numberOfLines != UNSET && numberOfLines != 0 && numberOfLines <= lines) {
if (numberOfLines != UNSET && numberOfLines != 0) {
maximumNumberOfLines = numberOfLines;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -417,8 +417,13 @@ public static long measureText(
int numberOfEmptyLines = numberOfLines - lines;
SpannableStringBuilder ssb = new SpannableStringBuilder();

// for some reason a newline on end causes issues with computing height so we add a character
if (text.toString().endsWith("\n")) {
ssb.append("A");
}

for (int i = 0; i < numberOfEmptyLines; ++i) {
ssb.append("\n");
ssb.append("\nA");
}

Object[] spans = text.getSpans(0, 0, Object.class);
Expand All @@ -438,7 +443,7 @@ public static long measureText(
hyphenationFrequency);
}

if (numberOfLines != UNSET && numberOfLines != 0 && numberOfLines <= lines) {
if (numberOfLines != UNSET && numberOfLines != 0) {
maximumNumberOfLines = numberOfLines;
}

Expand Down

0 comments on commit 2b7bda1

Please sign in to comment.