Fix unintended line break with default font scale.

fork-5.53.8
Rashad Sookram 2022-02-17 12:09:41 -05:00 zatwierdzone przez Greyson Parrelli
rodzic 265283fea5
commit 9f1deda220
1 zmienionych plików z 4 dodań i 4 usunięć

Wyświetl plik

@ -186,16 +186,16 @@ public class EmojiTextView extends AppCompatTextView {
} }
/** /**
* Starting from API 30, there can be a rounding error in text layout when a non-default font * Starting from API 30, there can be a rounding error in text layout when a non-zero letter
* scale is used. This causes a line break to be inserted where there shouldn't be one. Force the * spacing is used. This causes a line break to be inserted where there shouldn't be one. Force
* width to be larger to work around this problem. * the width to be larger to work around this problem.
* https://issuetracker.google.com/issues/173574230 * https://issuetracker.google.com/issues/173574230
* *
* @param widthMeasureSpec the original measure spec passed to {@link #onMeasure(int, int)} * @param widthMeasureSpec the original measure spec passed to {@link #onMeasure(int, int)}
* @return the measure spec with the workaround, or the original one. * @return the measure spec with the workaround, or the original one.
*/ */
private int applyWidthMeasureRoundingFix(int widthMeasureSpec) { private int applyWidthMeasureRoundingFix(int widthMeasureSpec) {
if (Build.VERSION.SDK_INT >= 30 && Math.abs(getResources().getConfiguration().fontScale - 1f) > 0.01f) { if (Build.VERSION.SDK_INT >= 30 && getLetterSpacing() > 0) {
CharSequence text = getText(); CharSequence text = getText();
if (text != null) { if (text != null) {
int widthSpecMode = MeasureSpec.getMode(widthMeasureSpec); int widthSpecMode = MeasureSpec.getMode(widthMeasureSpec);