From b39d89735b8d88669c779b6a8549a179fd0f6f44 Mon Sep 17 00:00:00 2001 From: Fabrice Di Meglio Date: Mon, 18 Apr 2011 18:33:48 -0700 Subject: [PATCH] Use Harfbuzz for Canvas drawText APIs Change-Id: I661d5e9e0bbe9a859e7a000cb161994d29add099 --- core/jni/android/graphics/Canvas.cpp | 39 ++++++++++++++++++++++++++-- 1 file changed, 37 insertions(+), 2 deletions(-) diff --git a/core/jni/android/graphics/Canvas.cpp b/core/jni/android/graphics/Canvas.cpp index 207c72fa173e8..310f02f971697 100644 --- a/core/jni/android/graphics/Canvas.cpp +++ b/core/jni/android/graphics/Canvas.cpp @@ -743,7 +743,11 @@ public: jcharArray text, int index, int count, jfloat x, jfloat y, int flags, SkPaint* paint) { jchar* textArray = env->GetCharArrayElements(text, NULL); +#if RTL_USE_HARFBUZZ + drawTextWithGlyphs(canvas, textArray + index, 0, count, x, y, flags, paint); +#else TextLayout::drawText(paint, textArray + index, count, flags, x, y, canvas); +#endif env->ReleaseCharArrayElements(text, textArray, JNI_ABORT); } @@ -752,7 +756,11 @@ public: int start, int end, jfloat x, jfloat y, int flags, SkPaint* paint) { const jchar* textArray = env->GetStringChars(text, NULL); +#if RTL_USE_HARFBUZZ + drawTextWithGlyphs(canvas, textArray, start, end, x, y, flags, paint); +#else TextLayout::drawText(paint, textArray + start, end - start, flags, x, y, canvas); +#endif env->ReleaseStringChars(text, textArray); } @@ -781,6 +789,23 @@ public: x, y, flags, paint); } + static void drawTextWithGlyphs(SkCanvas* canvas, const jchar* textArray, + int start, int count, int contextCount, + jfloat x, jfloat y, int flags, SkPaint* paint) { + + sp value = gTextLayoutCache.getValue( + paint, textArray, start, count, contextCount, flags); + if (value == NULL) { + LOGE("drawTextWithGlyphs -- cannot get Cache value"); + return ; + } +#if DEBUG_GLYPHS + logGlyphs(value); +#endif + doDrawGlyphs(canvas, value->getGlyphs(), 0, value->getGlyphsCount(), + x, y, flags, paint); + } + static void drawTextWithGlyphs___CIIFFIPaint(JNIEnv* env, jobject, SkCanvas* canvas, jcharArray text, int index, int count, jfloat x, jfloat y, int flags, SkPaint* paint) { @@ -831,8 +856,13 @@ public: jfloat x, jfloat y, int dirFlags, SkPaint* paint) { jchar* chars = env->GetCharArrayElements(text, NULL); +#if RTL_USE_HARFBUZZ + drawTextWithGlyphs(canvas, chars + contextIndex, index - contextIndex, + count, contextCount, x, y, dirFlags, paint); +#else TextLayout::drawTextRun(paint, chars + contextIndex, index - contextIndex, - count, contextCount, dirFlags, x, y, canvas); + count, contextCount, dirFlags, x, y, canvas); +#endif env->ReleaseCharArrayElements(text, chars, JNI_ABORT); } @@ -844,8 +874,13 @@ public: jint count = end - start; jint contextCount = contextEnd - contextStart; const jchar* chars = env->GetStringChars(text, NULL); +#if RTL_USE_HARFBUZZ + drawTextWithGlyphs(canvas, chars + contextStart, start - contextStart, + count, contextCount, x, y, dirFlags, paint); +#else TextLayout::drawTextRun(paint, chars + contextStart, start - contextStart, - count, contextCount, dirFlags, x, y, canvas); + count, contextCount, dirFlags, x, y, canvas); +#endif env->ReleaseStringChars(text, chars); }