OSDN Git Service

Reset FontMetrics at each new measurement in BoringLayout
authorSiyamed Sinir <siyamed@google.com>
Tue, 29 Mar 2016 18:56:53 +0000 (11:56 -0700)
committerSiyamed Sinir <siyamed@google.com>
Thu, 31 Mar 2016 00:17:05 +0000 (17:17 -0700)
Reset FontMetrics object used in BoringLayout.isBoring to get updated
and correct FontMetrics as a result of measurement.

Bug: 26704088
Change-Id: If77b0edba8dc4b5b1738a802c5f49e112e47b4f2

core/java/android/text/BoringLayout.java

index a1bc2d1..328fe99 100644 (file)
@@ -300,6 +300,8 @@ public class BoringLayout extends Layout implements TextUtils.EllipsizeCallback
             Metrics fm = metrics;
             if (fm == null) {
                 fm = new Metrics();
+            } else {
+                fm.reset();
             }
 
             TextLine line = TextLine.obtain();
@@ -414,8 +416,6 @@ public class BoringLayout extends Layout implements TextUtils.EllipsizeCallback
         mEllipsizedCount = end - start;
     }
 
-    private static final char FIRST_RIGHT_TO_LEFT = '\u0590';
-
     private String mDirect;
     private Paint mPaint;
 
@@ -430,5 +430,14 @@ public class BoringLayout extends Layout implements TextUtils.EllipsizeCallback
         @Override public String toString() {
             return super.toString() + " width=" + width;
         }
+
+        private void reset() {
+            top = 0;
+            bottom = 0;
+            ascent = 0;
+            descent = 0;
+            width = 0;
+            leading = 0;
+        }
     }
 }