568 static jfloat measureText_StringI(JNIEnv* env, jobject jpaint, jstring text, jint bidiFlags) {
569 NPE_CHECK_RETURN_ZERO(env, jpaint);
570 NPE_CHECK_RETURN_ZERO(env, text);
571
572 size_t textLength = env->GetStringLength(text);
573 if (textLength == 0) {
574 return 0;
575 }
576
577 const jchar* textArray = env->GetStringChars(text, NULL);
578 Paint* paint = GraphicsJNI::getNativePaint(env, jpaint);
579 jfloat width = 0;
580
581 Layout layout;
582 TypefaceImpl* typeface = GraphicsJNI::getNativeTypeface(env, jpaint);
583 MinikinUtils::doLayout(&layout, paint, bidiFlags, typeface, textArray, 0, textLength, textLength);
584 width = layout.getAdvance();
585
586 env->ReleaseStringChars(text, textArray);
587 return width;
588 }
383 android::TypefaceImpl* GraphicsJNI::getNativeTypeface(JNIEnv* env, jobject paint) {
384 SkASSERT(env);
385 SkASSERT(paint);
386 SkASSERT(env->IsInstanceOf(paint, gPaint_class));
387 jlong typefaceHandle = env->GetLongField(paint, gPaint_nativeTypefaceID);
388 android::TypefaceImpl* p = reinterpret_cast<android::TypefaceImpl*>(typefaceHandle);
389 return p;
390 }
169 static jclass gPaint_class;
170 static jfieldID gPaint_nativeInstanceID;
171 static jfieldID gPaint_nativeTypefaceID;
691 int register_android_graphics_Graphics(JNIEnv* env)
692 {
693 jmethodID m;
694 jclass c;
731 gPaint_class = make_globalref(env, "android/graphics/Paint");
732 gPaint_nativeInstanceID = getFieldIDCheck(env, gPaint_class, "mNativePaint", "J");
733 gPaint_nativeTypefaceID = getFieldIDCheck(env, gPaint_class, "mNativeTypeface", "J");
754 return 0;
755 }