OSDN Git Service

Fix Layout.isRtlCharAt
authorRaph Levien <raph@google.com>
Thu, 4 Sep 2014 19:47:03 +0000 (12:47 -0700)
committerRaph Levien <raph@google.com>
Thu, 4 Sep 2014 19:47:03 +0000 (12:47 -0700)
We weren't getting correct results from Layout.isRtlCharAt, because it
was only testing half of the correct predicate for whether the argument
was inside the run. This patch restores the correct predicate.

Bug: 17381011
Change-Id: Ib0a77cc182f4ca4bfe824e85b7aff7268f465d73

core/java/android/text/Layout.java

index 7dce348..2b53c48 100644 (file)
@@ -727,10 +727,9 @@ public abstract class Layout {
         int[] runs = dirs.mDirections;
         int lineStart = getLineStart(line);
         for (int i = 0; i < runs.length; i += 2) {
-            int start = lineStart + (runs[i] & RUN_LENGTH_MASK);
-            // No need to test the end as an offset after the last run should return the value
-            // corresponding of the last run
-            if (offset >= start) {
+            int start = lineStart + runs[i];
+            int limit = start + (runs[i+1] & RUN_LENGTH_MASK);
+            if (offset >= start && offset < limit) {
                 int level = (runs[i+1] >>> RUN_LEVEL_SHIFT) & RUN_LEVEL_MASK;
                 return ((level & 1) != 0);
             }