@@ -567,6 +567,54 @@ static void android_view_GLES20Canvas_drawTextRun(JNIEnv* env, jobject clazz,
567567 env->ReleaseStringChars (text, textArray);
568568}
569569
570+ static void renderPosText (OpenGLRenderer* renderer, const jchar* text, int count,
571+ const jfloat* positions, jint dirFlags, SkPaint* paint) {
572+ sp<TextLayoutCacheValue> value;
573+ #if USE_TEXT_LAYOUT_CACHE
574+ value = TextLayoutCache::getInstance ().getValue (paint, text, 0 , count, count, dirFlags);
575+ if (value == NULL ) {
576+ ALOGE (" Cannot get TextLayoutCache value for text = '%s'" ,
577+ String8 (text, count).string ());
578+ return ;
579+ }
580+ #else
581+ value = new TextLayoutCacheValue (count);
582+ TextLayoutEngine::getInstance ().computeValues (value.get (), paint,
583+ text, 0 , count, count, dirFlags);
584+ #endif
585+
586+ const jchar* glyphs = value->getGlyphs ();
587+ size_t glyphsCount = value->getGlyphsCount ();
588+ int bytesCount = glyphsCount * sizeof (jchar);
589+
590+ renderer->drawPosText ((const char *) glyphs, bytesCount,
591+ count < int (glyphsCount) ? count : glyphsCount, positions, paint);
592+ }
593+
594+ static void android_view_GLES20Canvas_drawPosTextArray (JNIEnv* env, jobject clazz,
595+ OpenGLRenderer* renderer, jcharArray text, jint index, jint count,
596+ jfloatArray pos, SkPaint* paint) {
597+ jchar* textArray = env->GetCharArrayElements (text, NULL );
598+ jfloat* positions = env->GetFloatArrayElements (pos, NULL );
599+
600+ renderPosText (renderer, textArray + index, count, positions, kBidi_LTR , paint);
601+
602+ env->ReleaseFloatArrayElements (pos, positions, JNI_ABORT);
603+ env->ReleaseCharArrayElements (text, textArray, JNI_ABORT);
604+ }
605+
606+ static void android_view_GLES20Canvas_drawPosText (JNIEnv* env, jobject clazz,
607+ OpenGLRenderer* renderer, jstring text, jint start, jint end,
608+ jfloatArray pos, SkPaint* paint) {
609+ const jchar* textArray = env->GetStringChars (text, NULL );
610+ jfloat* positions = env->GetFloatArrayElements (pos, NULL );
611+
612+ renderPosText (renderer, textArray + start, end - start, positions, kBidi_LTR , paint);
613+
614+ env->ReleaseFloatArrayElements (pos, positions, JNI_ABORT);
615+ env->ReleaseStringChars (text, textArray);
616+ }
617+
570618// ----------------------------------------------------------------------------
571619// Display lists
572620// ----------------------------------------------------------------------------
@@ -830,6 +878,10 @@ static JNINativeMethod gMethods[] = {
830878 { " nDrawTextRun" , " (ILjava/lang/String;IIIIFFII)V" ,
831879 (void *) android_view_GLES20Canvas_drawTextRun },
832880
881+ { " nDrawPosText" , " (I[CII[FI)V" , (void *) android_view_GLES20Canvas_drawPosTextArray },
882+ { " nDrawPosText" , " (ILjava/lang/String;II[FI)V" ,
883+ (void *) android_view_GLES20Canvas_drawPosText },
884+
833885 { " nGetClipBounds" , " (ILandroid/graphics/Rect;)Z" ,
834886 (void *) android_view_GLES20Canvas_getClipBounds },
835887
0 commit comments