From 9863f67469794af8b63666126e5d60b4eed7cdeb Mon Sep 17 00:00:00 2001 From: Seigo Nonaka Date: Wed, 14 Dec 2016 17:56:10 +0900 Subject: [PATCH] Fix getLineExtent for hyphen width. Need to set hyphen edit before measuring line. Bug: 33388205 Test: Manually done Change-Id: I32b1639d03ddd9bddb1f3ab34b577544ae358a6a --- core/java/android/text/Layout.java | 4 ++ .../coretests/src/android/widget/TextViewTest.java | 56 ++++++++++++++++++++++ 2 files changed, 60 insertions(+) diff --git a/core/java/android/text/Layout.java b/core/java/android/text/Layout.java index fd6fc7dc0860..3cb81b0a250f 100644 --- a/core/java/android/text/Layout.java +++ b/core/java/android/text/Layout.java @@ -1092,8 +1092,10 @@ public abstract class Layout { int dir = getParagraphDirection(line); TextLine tl = TextLine.obtain(); + mPaint.setHyphenEdit(getHyphen(line)); tl.set(mPaint, mText, start, end, dir, directions, hasTabs, tabStops); float width = tl.metrics(null); + mPaint.setHyphenEdit(0); TextLine.recycle(tl); return width; } @@ -1114,8 +1116,10 @@ public abstract class Layout { int dir = getParagraphDirection(line); TextLine tl = TextLine.obtain(); + mPaint.setHyphenEdit(getHyphen(line)); tl.set(mPaint, mText, start, end, dir, directions, hasTabs, tabStops); float width = tl.metrics(null); + mPaint.setHyphenEdit(0); TextLine.recycle(tl); return width; } diff --git a/core/tests/coretests/src/android/widget/TextViewTest.java b/core/tests/coretests/src/android/widget/TextViewTest.java index 3ccbf17c815e..8989462a916d 100644 --- a/core/tests/coretests/src/android/widget/TextViewTest.java +++ b/core/tests/coretests/src/android/widget/TextViewTest.java @@ -18,17 +18,23 @@ package android.widget; import android.app.Activity; import android.content.Intent; +import android.graphics.Paint; import android.platform.test.annotations.Presubmit; import android.test.ActivityInstrumentationTestCase2; import android.test.suitebuilder.annotation.SmallTest; import android.text.GetChars; +import android.text.Layout; import android.text.Selection; import android.text.Spannable; +import android.util.Log; +import android.view.View; +import java.util.Locale; /** * TextViewTest tests {@link TextView}. */ public class TextViewTest extends ActivityInstrumentationTestCase2 { + private static final String TAG = "TextViewTest"; private TextView mTextView; public TextViewTest() { @@ -169,4 +175,54 @@ public class TextViewTest extends ActivityInstrumentationTestCase2 withoutHyphenLength); + } + assertTrue("Hyphenation must happen on TextView narrower than the word width", + hyphenationHappend); + } } -- 2.11.0