summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Seigo Nonaka <nona@google.com> 2020-10-19 23:14:04 -0700
committer Seigo Nonaka <nona@google.com> 2020-10-19 23:31:35 -0700
commit170e0949f3c67decaa67d3fcce6a9776268691ff (patch)
treedc52a8c628df2c8f25088f7181b29678fa17cc25
parent276718dee090fd9613c6149dee89e87619f97ee5 (diff)
Fix wrong offset of BiDi text by TextShaper
This CL includes: - Fix relative offset of BidiRun by reviving width calculation in TextLine. - Fix bidi level buffer offset. It shuold be relative to the substring, but the absolute offset was passed. - Removed paint argument from PositionedGlyph which is not used. Bug: 171275519 Test: atest android.graphics.text.cts.TextRunShaperTest Test: atest android.text.cts.TextShaperTest Change-Id: I36949089d744bdfae61995210b2051866a7510ac
-rw-r--r--core/java/android/text/TextLine.java3
-rw-r--r--core/java/android/text/TextShaper.java6
-rw-r--r--graphics/java/android/graphics/text/PositionedGlyphs.java3
-rw-r--r--graphics/java/android/graphics/text/TextRunShaper.java6
4 files changed, 11 insertions, 7 deletions
diff --git a/core/java/android/text/TextLine.java b/core/java/android/text/TextLine.java
index 4471056e23dd..6318c4757bce 100644
--- a/core/java/android/text/TextLine.java
+++ b/core/java/android/text/TextLine.java
@@ -931,7 +931,8 @@ public class TextLine {
float totalWidth = 0;
final int numDecorations = decorations == null ? 0 : decorations.size();
- if (needWidth || (c != null && (wp.bgColor != 0 || numDecorations != 0 || runIsRtl))) {
+ if (needWidth || ((c != null || consumer != null) && (wp.bgColor != 0
+ || numDecorations != 0 || runIsRtl))) {
totalWidth = getRunAdvance(wp, start, end, contextStart, contextEnd, runIsRtl, offset);
}
diff --git a/core/java/android/text/TextShaper.java b/core/java/android/text/TextShaper.java
index dd2570401b3e..02fd7b4470f0 100644
--- a/core/java/android/text/TextShaper.java
+++ b/core/java/android/text/TextShaper.java
@@ -198,6 +198,10 @@ public class TextShaper {
/**
* Shape multi-styled text.
*
+ * In the LTR context, the shape result will go from left to right, thus you may want to draw
+ * glyphs from left most position of the canvas. In the RTL context, the shape result will go
+ * from right to left, thus you may want to draw glyphs from right most position of the canvas.
+ *
* @param text a styled text.
* @param start a start index of shaping target in the text.
* @param count a length of shaping target in the text.
@@ -215,7 +219,7 @@ public class TextShaper {
try {
tl.set(paint, text, start, start + count,
mp.getParagraphDir(),
- mp.getDirections(start, start + count),
+ mp.getDirections(0, count),
false /* tabstop is not supported */,
null,
-1, -1 // ellipsis is not supported.
diff --git a/graphics/java/android/graphics/text/PositionedGlyphs.java b/graphics/java/android/graphics/text/PositionedGlyphs.java
index ecbc45c54d85..c2de0acebca9 100644
--- a/graphics/java/android/graphics/text/PositionedGlyphs.java
+++ b/graphics/java/android/graphics/text/PositionedGlyphs.java
@@ -170,9 +170,8 @@ public final class PositionedGlyphs {
* @hide
*
* @param layoutPtr the address of native layout object.
- * @param paint a paint object
*/
- public PositionedGlyphs(long layoutPtr, @NonNull Paint paint, float xOffset, float yOffset) {
+ public PositionedGlyphs(long layoutPtr, float xOffset, float yOffset) {
mLayoutPtr = layoutPtr;
int glyphCount = nGetGlyphCount(layoutPtr);
mFonts = new ArrayList<>(glyphCount);
diff --git a/graphics/java/android/graphics/text/TextRunShaper.java b/graphics/java/android/graphics/text/TextRunShaper.java
index b73436e36ae0..8459e7bfe191 100644
--- a/graphics/java/android/graphics/text/TextRunShaper.java
+++ b/graphics/java/android/graphics/text/TextRunShaper.java
@@ -72,7 +72,7 @@ public class TextRunShaper {
return new PositionedGlyphs(
nativeShapeTextRun(text, start, count, contextStart, contextCount, isRtl,
paint.getNativeInstance()),
- paint, xOffset, yOffset);
+ xOffset, yOffset);
}
/**
@@ -104,7 +104,7 @@ public class TextRunShaper {
nativeShapeTextRun(
(String) text, start, count, contextStart, contextCount, isRtl,
paint.getNativeInstance()),
- paint, xOffset, yOffset);
+ xOffset, yOffset);
} else {
char[] buf = new char[contextCount];
TextUtils.getChars(text, contextStart, contextStart + contextCount, buf, 0);
@@ -112,7 +112,7 @@ public class TextRunShaper {
nativeShapeTextRun(
buf, start - contextStart, count,
0, contextCount, isRtl, paint.getNativeInstance()),
- paint, xOffset, yOffset);
+ xOffset, yOffset);
}
}