Skip to content

Commit

Permalink
Fix some languages wrapped texts are cut off on android (facebook#25306)
Browse files Browse the repository at this point in the history
Summary:
Fix wrapped some languages (like Japanese, Chinese) texts are cut off on android. This p-r is based on linjson [patch](facebook#25275 (comment)).

- related (maybe)
    - facebook#25297
    - facebook#25275
    - facebook#24837
    - facebook#25155

`setUseLineSpacingFromFallbacks` is recommended to set true on [document](https://developer.android.com/reference/android/text/StaticLayout.Builder#setUseLineSpacingFromFallbacks(boolean))

>For backward compatibility reasons, the default is false, but setting this to true is strongly recommended. It is required to be true if text could be in languages like Burmese or Tibetan where text is typically much taller or deeper than Latin text.

## Changelog

[Android] [Fixed] - Fix some languages wrapped texts are cut off.
Pull Request resolved: facebook#25306

Test Plan:
Set the target SDK to 28 in ``fbsource/fbandroid/java/com/facebook/catalyst/shell/AndroidManifest.xml``:
```
<uses-sdk android:minSdkVersion="16" android:targetSdkVersion="28"/>
```

Insert the following code into Playground.js: P67720709

Start the Catalyst Android app and navigate to the playground:

`buck install -r catalyst`

|Before|After|
|{F163482789}|{F163481060}|

Reviewed By: cpojer

Differential Revision: D15985809

Pulled By: makovkastar

fbshipit-source-id: 0f98760b7a7fe4689fa3fe90ca747e9bf9fc4780
  • Loading branch information
soh335 authored and Hubert Wang committed Nov 1, 2019
1 parent 60cf18f commit 73f3fe0
Showing 1 changed file with 10 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,9 @@ public long measure(
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
builder.setJustificationMode(mJustificationMode);
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
builder.setUseLineSpacingFromFallbacks(true);
}
layout = builder.build();
}

Expand All @@ -134,14 +137,18 @@ public long measure(
new StaticLayout(
text, textPaint, (int) width, alignment, 1.f, 0.f, mIncludeFontPadding);
} else {
layout =
StaticLayout.Builder builder =
StaticLayout.Builder.obtain(text, 0, text.length(), textPaint, (int) width)
.setAlignment(alignment)
.setLineSpacing(0.f, 1.f)
.setIncludePad(mIncludeFontPadding)
.setBreakStrategy(mTextBreakStrategy)
.setHyphenationFrequency(Layout.HYPHENATION_FREQUENCY_NORMAL)
.build();
.setHyphenationFrequency(Layout.HYPHENATION_FREQUENCY_NORMAL);

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
builder.setUseLineSpacingFromFallbacks(true);
}
layout = builder.build();
}
}

Expand Down

0 comments on commit 73f3fe0

Please sign in to comment.