summaryrefslogtreecommitdiffstats
path: root/tools/layoutlib/bridge/src/android/graphics/Paint_Delegate.java
diff options
context:
space:
mode:
authorDeepanshu Gupta <deepanshu@google.com>2014-06-05 22:38:00 +0000
committerAndroid (Google) Code Review <android-gerrit@google.com>2014-06-05 22:38:00 +0000
commite872209986475f36a694dbc6b5ee14831b4b8203 (patch)
tree105712fc83d2979a72431684b1841803a61c2958 /tools/layoutlib/bridge/src/android/graphics/Paint_Delegate.java
parentedfaa50864f11670ef96ea8d33b2c63dbe20f17a (diff)
parenta19b8c111b6961f20e1fc9132c62d1fd7f98bafe (diff)
downloadframeworks_base-e872209986475f36a694dbc6b5ee14831b4b8203.zip
frameworks_base-e872209986475f36a694dbc6b5ee14831b4b8203.tar.gz
frameworks_base-e872209986475f36a694dbc6b5ee14831b4b8203.tar.bz2
Merge "LayoutLib: Add assertions for typeface." into lmp-preview-dev
Diffstat (limited to 'tools/layoutlib/bridge/src/android/graphics/Paint_Delegate.java')
-rw-r--r--tools/layoutlib/bridge/src/android/graphics/Paint_Delegate.java22
1 files changed, 16 insertions, 6 deletions
diff --git a/tools/layoutlib/bridge/src/android/graphics/Paint_Delegate.java b/tools/layoutlib/bridge/src/android/graphics/Paint_Delegate.java
index d6e97f5..6ee307e 100644
--- a/tools/layoutlib/bridge/src/android/graphics/Paint_Delegate.java
+++ b/tools/layoutlib/bridge/src/android/graphics/Paint_Delegate.java
@@ -93,6 +93,8 @@ public class Paint_Delegate {
private Locale mLocale = Locale.getDefault();
+ // Used only to assert invariants.
+ public long mNativeTypeface;
// ---- Public Helper methods ----
@@ -888,6 +890,7 @@ public class Paint_Delegate {
}
delegate.mTypeface = Typeface_Delegate.getDelegate(typeface);
+ delegate.mNativeTypeface = typeface;
delegate.updateFontObject();
return typeface;
}
@@ -966,15 +969,10 @@ public class Paint_Delegate {
}
@LayoutlibDelegate
- /*package*/ static float native_getTextRunAdvances(long native_object,
- long native_typeface /*ignored*/,
+ /*package*/ static float native_getTextRunAdvances(long native_object, long native_typeface,
char[] text, int index, int count, int contextIndex, int contextCount,
int flags, float[] advances, int advancesIndex) {
- // native_typeface is passed here since Framework's old implementation did not have the
- // typeface object associated with the Paint. Since, we follow the new framework way,
- // we store the typeface with the paint and use it directly.
-
if (advances != null)
for (int i = advancesIndex; i< advancesIndex+count; i++)
advances[i]=0;
@@ -983,6 +981,12 @@ public class Paint_Delegate {
if (delegate == null) {
return 0.f;
}
+
+ // native_typeface is passed here since Framework's old implementation did not have the
+ // typeface object associated with the Paint. Since, we follow the new framework way,
+ // we store the typeface with the paint and use it directly.
+ assert (native_typeface == delegate.mNativeTypeface);
+
boolean isRtl = isRtl(flags);
int limit = index + count;
@@ -1054,6 +1058,10 @@ public class Paint_Delegate {
if (delegate == null) {
return;
}
+
+ // assert that the typeface passed is actually the one that we had stored.
+ assert (native_typeface == delegate.mNativeTypeface);
+
delegate.measureText(text, index, count, isRtl(bidiFlags)).roundOut(bounds);
}
@@ -1080,6 +1088,7 @@ public class Paint_Delegate {
mJoin = paint.mJoin;
mTextAlign = paint.mTextAlign;
mTypeface = paint.mTypeface;
+ mNativeTypeface = paint.mNativeTypeface;
mStrokeWidth = paint.mStrokeWidth;
mStrokeMiter = paint.mStrokeMiter;
mTextSize = paint.mTextSize;
@@ -1103,6 +1112,7 @@ public class Paint_Delegate {
mJoin = Paint.Join.MITER.nativeInt;
mTextAlign = 0;
mTypeface = Typeface_Delegate.getDelegate(Typeface.sDefaults[0].native_instance);
+ mNativeTypeface = 0;
mStrokeWidth = 1.f;
mStrokeMiter = 4.f;
mTextSize = 20.f;