summaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
Diffstat (limited to 'core')
-rw-r--r--core/java/android/view/GLES20Canvas.java28
-rw-r--r--core/jni/android_view_GLES20Canvas.cpp52
2 files changed, 78 insertions, 2 deletions
diff --git a/core/java/android/view/GLES20Canvas.java b/core/java/android/view/GLES20Canvas.java
index 700d3df..761a788 100644
--- a/core/java/android/view/GLES20Canvas.java
+++ b/core/java/android/view/GLES20Canvas.java
@@ -945,14 +945,38 @@ class GLES20Canvas extends HardwareCanvas {
@Override
public void drawPosText(char[] text, int index, int count, float[] pos, Paint paint) {
- // TODO: Implement
+ if (index < 0 || index + count > text.length || count * 2 > pos.length) {
+ throw new IndexOutOfBoundsException();
+ }
+
+ int modifiers = setupModifiers(paint);
+ try {
+ nDrawPosText(mRenderer, text, index, count, pos, paint.mNativePaint);
+ } finally {
+ if (modifiers != MODIFIER_NONE) nResetModifiers(mRenderer, modifiers);
+ }
}
+ private static native void nDrawPosText(int renderer, char[] text, int index, int count,
+ float[] pos, int paint);
+
@Override
public void drawPosText(String text, float[] pos, Paint paint) {
- // TODO: Implement
+ if (text.length() * 2 > pos.length) {
+ throw new ArrayIndexOutOfBoundsException();
+ }
+
+ int modifiers = setupModifiers(paint);
+ try {
+ nDrawPosText(mRenderer, text, 0, text.length(), pos, paint.mNativePaint);
+ } finally {
+ if (modifiers != MODIFIER_NONE) nResetModifiers(mRenderer, modifiers);
+ }
}
+ private static native void nDrawPosText(int renderer, String text, int start, int end,
+ float[] pos, int paint);
+
@Override
public void drawRect(float left, float top, float right, float bottom, Paint paint) {
int modifiers = setupModifiers(paint);
diff --git a/core/jni/android_view_GLES20Canvas.cpp b/core/jni/android_view_GLES20Canvas.cpp
index c8251bf..3bf28eb 100644
--- a/core/jni/android_view_GLES20Canvas.cpp
+++ b/core/jni/android_view_GLES20Canvas.cpp
@@ -567,6 +567,54 @@ static void android_view_GLES20Canvas_drawTextRun(JNIEnv* env, jobject clazz,
env->ReleaseStringChars(text, textArray);
}
+static void renderPosText(OpenGLRenderer* renderer, const jchar* text, int count,
+ const jfloat* positions, jint dirFlags, SkPaint* paint) {
+ sp<TextLayoutCacheValue> value;
+#if USE_TEXT_LAYOUT_CACHE
+ value = TextLayoutCache::getInstance().getValue(paint, text, 0, count, count, dirFlags);
+ if (value == NULL) {
+ ALOGE("Cannot get TextLayoutCache value for text = '%s'",
+ String8(text, count).string());
+ return;
+ }
+#else
+ value = new TextLayoutCacheValue(count);
+ TextLayoutEngine::getInstance().computeValues(value.get(), paint,
+ text, 0, count, count, dirFlags);
+#endif
+
+ const jchar* glyphs = value->getGlyphs();
+ size_t glyphsCount = value->getGlyphsCount();
+ int bytesCount = glyphsCount * sizeof(jchar);
+
+ renderer->drawPosText((const char*) glyphs, bytesCount,
+ count < int(glyphsCount) ? count : glyphsCount, positions, paint);
+}
+
+static void android_view_GLES20Canvas_drawPosTextArray(JNIEnv* env, jobject clazz,
+ OpenGLRenderer* renderer, jcharArray text, jint index, jint count,
+ jfloatArray pos, SkPaint* paint) {
+ jchar* textArray = env->GetCharArrayElements(text, NULL);
+ jfloat* positions = env->GetFloatArrayElements(pos, NULL);
+
+ renderPosText(renderer, textArray + index, count, positions, kBidi_LTR, paint);
+
+ env->ReleaseFloatArrayElements(pos, positions, JNI_ABORT);
+ env->ReleaseCharArrayElements(text, textArray, JNI_ABORT);
+}
+
+static void android_view_GLES20Canvas_drawPosText(JNIEnv* env, jobject clazz,
+ OpenGLRenderer* renderer, jstring text, jint start, jint end,
+ jfloatArray pos, SkPaint* paint) {
+ const jchar* textArray = env->GetStringChars(text, NULL);
+ jfloat* positions = env->GetFloatArrayElements(pos, NULL);
+
+ renderPosText(renderer, textArray + start, end - start, positions, kBidi_LTR, paint);
+
+ env->ReleaseFloatArrayElements(pos, positions, JNI_ABORT);
+ env->ReleaseStringChars(text, textArray);
+}
+
// ----------------------------------------------------------------------------
// Display lists
// ----------------------------------------------------------------------------
@@ -830,6 +878,10 @@ static JNINativeMethod gMethods[] = {
{ "nDrawTextRun", "(ILjava/lang/String;IIIIFFII)V",
(void*) android_view_GLES20Canvas_drawTextRun },
+ { "nDrawPosText", "(I[CII[FI)V", (void*) android_view_GLES20Canvas_drawPosTextArray },
+ { "nDrawPosText", "(ILjava/lang/String;II[FI)V",
+ (void*) android_view_GLES20Canvas_drawPosText },
+
{ "nGetClipBounds", "(ILandroid/graphics/Rect;)Z",
(void*) android_view_GLES20Canvas_getClipBounds },