diff options
| author | Raph Levien <raph@google.com> | 2015-07-01 14:39:31 -0700 |
|---|---|---|
| committer | Raph Levien <raph@google.com> | 2015-07-01 15:53:23 -0700 |
| commit | 2ea5290ffb9efe0a7c187fb1177ef8ecd089803c (patch) | |
| tree | 867c693c303249bac0d7805622d497bbe5386b49 /core/java/android/text/Layout.java | |
| parent | f22e2e3998db9bcfdac5d1c524b0c02e7da7f86d (diff) | |
Fix problems with StaticLayout indentation
The implementation of indendataion had two issues. First, the indent
pattern would restart on a new paragraph, which created problems when
a multi-paragraph text would flow into a shape. Second, the indents
didn't affect drawing position, which is ok for centered text but not
most of the other alignments. This patch fixes both.
Bug: 21904268
Change-Id: I53a3eb1c192fc0f8f0beace304832eed61b38497
Diffstat (limited to 'core/java/android/text/Layout.java')
| -rw-r--r-- | core/java/android/text/Layout.java | 29 |
1 files changed, 19 insertions, 10 deletions
diff --git a/core/java/android/text/Layout.java b/core/java/android/text/Layout.java index f7027f9e20b8..d82213857ac0 100644 --- a/core/java/android/text/Layout.java +++ b/core/java/android/text/Layout.java @@ -385,21 +385,22 @@ public abstract class Layout { int x; if (align == Alignment.ALIGN_NORMAL) { if (dir == DIR_LEFT_TO_RIGHT) { - x = left; + x = left + getIndentAdjust(lineNum, Alignment.ALIGN_LEFT); } else { - x = right; + x = right + getIndentAdjust(lineNum, Alignment.ALIGN_RIGHT); } } else { int max = (int)getLineExtent(lineNum, tabStops, false); if (align == Alignment.ALIGN_OPPOSITE) { if (dir == DIR_LEFT_TO_RIGHT) { - x = right - max; + x = right - max + getIndentAdjust(lineNum, Alignment.ALIGN_RIGHT); } else { - x = left - max; + x = left - max + getIndentAdjust(lineNum, Alignment.ALIGN_LEFT); } } else { // Alignment.ALIGN_CENTER max = max & ~1; - x = (right + left - max) >> 1; + x = ((right + left - max) >> 1) + + getIndentAdjust(lineNum, Alignment.ALIGN_CENTER); } } @@ -545,9 +546,9 @@ public abstract class Layout { int x; if (align == Alignment.ALIGN_NORMAL) { if (dir == DIR_LEFT_TO_RIGHT) { - x = left; + x = left + getIndentAdjust(line, Alignment.ALIGN_LEFT); } else { - x = right; + x = right + getIndentAdjust(line, Alignment.ALIGN_RIGHT); } } else { TabStops tabStops = null; @@ -565,14 +566,14 @@ public abstract class Layout { int max = (int)getLineExtent(line, tabStops, false); if (align == Alignment.ALIGN_OPPOSITE) { if (dir == DIR_LEFT_TO_RIGHT) { - x = right - max; + x = right - max + getIndentAdjust(line, Alignment.ALIGN_RIGHT); } else { // max is negative here - x = left - max; + x = left - max + getIndentAdjust(line, Alignment.ALIGN_LEFT); } } else { // Alignment.ALIGN_CENTER max = max & ~1; - x = (left + right - max) >> 1; + x = (left + right - max) >> 1 + getIndentAdjust(line, Alignment.ALIGN_CENTER); } } return x; @@ -745,6 +746,14 @@ public abstract class Layout { return 0; } + /** + * Returns the left indent for a line. + * + * @hide + */ + public int getIndentAdjust(int line, Alignment alignment) { + return 0; + } /** * Returns true if the character at offset and the preceding character |
