From 1149cdc84b77d0cbe3c44a7ec6abd29fc63913b5 Mon Sep 17 00:00:00 2001 From: Raph Levien Date: Wed, 24 Jun 2015 09:36:31 -0700 Subject: [PATCH] Make measureText(String, int, int) not use context The measureText method when applied to a string should just measure the substring, rather than treat the entire string as context. It was less likely to cause problems than the similar issues with char arrays, but still wrong. This patch makes the behavior consistent. Bug: 20087437 Change-Id: I1c6e07a694b151f4fb097edae8e271805e996d06 --- core/jni/android/graphics/Paint.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/core/jni/android/graphics/Paint.cpp b/core/jni/android/graphics/Paint.cpp index d14fc0f7e3fb6..b9fd65f0116c7 100644 --- a/core/jni/android/graphics/Paint.cpp +++ b/core/jni/android/graphics/Paint.cpp @@ -606,7 +606,9 @@ public: Layout layout; TypefaceImpl* typeface = getNativeTypeface(env, jpaint); - MinikinUtils::doLayout(&layout, paint, bidiFlags, typeface, textArray, start, count, textLength); + // Only the substring is used for measurement, so no additional context is passed in. This + // behavior is consistent between char[] and String specializations. + MinikinUtils::doLayout(&layout, paint, bidiFlags, typeface, textArray + start, 0, count, count); width = layout.getAdvance(); env->ReleaseStringChars(text, textArray);