diff options
| author | 2017-02-21 12:18:31 -0800 | |
|---|---|---|
| committer | 2017-03-03 15:34:42 -0800 | |
| commit | 46c6f4c5ea7846fee4e6ef40c035ef2bee1adcbb (patch) | |
| tree | e6253cb71f611b2726e3f25f790acbe3e8c5b2a9 | |
| parent | 195bbc6d5e4e01000eed1ab80a0b7c146c1062ac (diff) | |
Frameworks support for hyphenation for various complex cases
This adds better support for Arabic script languages, Armenian,
Catalan, Hebrew, Kannada, Malayalam, Polish, Tamil, and Telugu by
adding various hyphenation types and edits appropriate for the
locales.
The actual implementations are in Minikin. This CL takes care of the
changes needed in frameworks, to support different end-of-line and
start-of-line hyphen edits.
Two bugs in TextLine.java are also fixed:
1. Where hyphen edits on non-spanned texts were not eliminated in
handleRun() when they should have. This had manifested itself in
double hyphenation in some bidi paragraphs.
2. Some no op assignments and comparions around the change for the
above bug are removed.
Test: thorough manual testing for various cases
Bug: 19756624
Bug: 19950445
Bug: 19955011
Bug: 25623243
Bug: 26154469
Bug: 26154471
Bug: 33387871
Bug: 33560754
Bug: 33752592
Bug: 33754204
Change-Id: I48c047d1f6a75c39a78a6ea38a0a3282f63326ec
| -rw-r--r-- | core/java/android/text/TextLine.java | 22 | ||||
| -rw-r--r-- | graphics/java/android/graphics/Paint.java | 17 | ||||
| -rw-r--r-- | libs/hwui/Android.mk | 1 |
3 files changed, 33 insertions, 7 deletions
diff --git a/core/java/android/text/TextLine.java b/core/java/android/text/TextLine.java index fcff9a2e5fca..756e9a0e2f2a 100644 --- a/core/java/android/text/TextLine.java +++ b/core/java/android/text/TextLine.java @@ -852,6 +852,18 @@ class TextLine { return runIsRtl ? -ret : ret; } + private int adjustHyphenEdit(int start, int limit, int hyphenEdit) { + int result = hyphenEdit; + // Only draw hyphens on first or last run in line. Disable them otherwise. + if (start > 0) { // not the first run + result &= ~Paint.HYPHENEDIT_MASK_START_OF_LINE; + } + if (limit < mLen) { // not the last run + result &= ~Paint.HYPHENEDIT_MASK_END_OF_LINE; + } + return result; + } + /** * Utility function for handling a unidirectional run. The run must not * contain tabs but can contain styles. @@ -893,9 +905,9 @@ class TextLine { if (mSpanned == null) { TextPaint wp = mWorkPaint; wp.set(mPaint); - final int mlimit = measureLimit; + wp.setHyphenEdit(adjustHyphenEdit(start, limit, wp.getHyphenEdit())); return handleText(wp, start, limit, start, limit, runIsRtl, c, x, top, - y, bottom, fmi, needWidth || mlimit < measureLimit, mlimit); + y, bottom, fmi, needWidth, measureLimit); } mMetricAffectingSpanSpanSet.init(mSpanned, mStart + start, mStart + limit); @@ -953,10 +965,8 @@ class TextLine { span.updateDrawState(wp); } - // Only draw hyphen on last run in line - if (jnext < mLen) { - wp.setHyphenEdit(0); - } + wp.setHyphenEdit(adjustHyphenEdit(j, jnext, wp.getHyphenEdit())); + x += handleText(wp, j, jnext, i, inext, runIsRtl, c, x, top, y, bottom, fmi, needWidth || jnext < measureLimit, offset); } diff --git a/graphics/java/android/graphics/Paint.java b/graphics/java/android/graphics/Paint.java index 4ee0c3413968..b1d51ec2d92b 100644 --- a/graphics/java/android/graphics/Paint.java +++ b/graphics/java/android/graphics/Paint.java @@ -340,6 +340,20 @@ public class Paint { private static final int CURSOR_OPT_MAX_VALUE = CURSOR_AT; /** + * Mask for hyphen edits that happen at the end of a line. Keep in sync with the definition in + * Minikin's Hyphenator.h. + * @hide + */ + public static final int HYPHENEDIT_MASK_END_OF_LINE = 0x07; + + /** + * Mask for hyphen edits that happen at the start of a line. Keep in sync with the definition in + * Minikin's Hyphenator.h. + * @hide + */ + public static final int HYPHENEDIT_MASK_START_OF_LINE = 0x03 << 3; + + /** * The Style specifies if the primitive being drawn is filled, stroked, or * both (in the same color). The default is FILL. */ @@ -1540,7 +1554,8 @@ public class Paint { * Set a hyphen edit on the paint (causes a hyphen to be added to text when * measured or drawn). * - * @param hyphen 0 for no edit, 1 for adding a hyphen (other values in future) + * @param hyphen 0 for no edit, 1 for adding a hyphen at the end, etc. + * Definition of various values are in the HyphenEdit class in Minikin's Hyphenator.h. * * @hide */ diff --git a/libs/hwui/Android.mk b/libs/hwui/Android.mk index 9515b8291bb6..ec8d63ecde98 100644 --- a/libs/hwui/Android.mk +++ b/libs/hwui/Android.mk @@ -187,6 +187,7 @@ hwui_c_includes += \ external/skia/src/effects \ external/skia/src/image \ external/skia/src/utils \ + external/icu/icu4c/source/common \ external/harfbuzz_ng/src \ external/freetype/include |