From bd901dee317d10c6a921922c3d7d788b90306c82 Mon Sep 17 00:00:00 2001 From: Fabrice Di Meglio Date: Fri, 20 Jan 2012 17:41:55 -0800 Subject: Fix bug #5846413 "phone" keyboard layout is broken on master - was a subtle regression introduced when fixing bug #5753006 - as we are now using SkPaint::kGlyphID_TextEncoding (glyph encoding) instead of SkPaint::kUTF16_TextEncoding (UTF16 encoding), we need to force the UTF16 encoding in some cases that are NOT going thru the TextLayoutCache / Harfbuzz shaping - fix also breakText() the same way - also clean some old comment - Warning: depends also on a CL from Skia for having getBaseGlyphCount() "const" Change-Id: I3d1fc87f070884876c679b33541f810fbfb5df3f --- core/jni/android/graphics/Canvas.cpp | 3 --- core/jni/android/graphics/Paint.cpp | 36 +++++++++++++++++++++++---- core/jni/android/graphics/TextLayoutCache.cpp | 10 ++++---- core/jni/android/graphics/TextLayoutCache.h | 10 ++++---- 4 files changed, 41 insertions(+), 18 deletions(-) diff --git a/core/jni/android/graphics/Canvas.cpp b/core/jni/android/graphics/Canvas.cpp index 3e9ab86486b8..c8b725a7337a 100644 --- a/core/jni/android/graphics/Canvas.cpp +++ b/core/jni/android/graphics/Canvas.cpp @@ -776,9 +776,6 @@ public: static void doDrawGlyphs(SkCanvas* canvas, const jchar* glyphArray, int index, int count, jfloat x, jfloat y, int flags, SkPaint* paint) { - // TODO: need to suppress this code after the GL renderer is modified for not - // copying the paint - // Beware: this needs Glyph encoding (already done on the Paint constructor) canvas->drawText(glyphArray + index * 2, count * 2, x, y, *paint); } diff --git a/core/jni/android/graphics/Paint.cpp b/core/jni/android/graphics/Paint.cpp index 9f3238abc9b5..9bcfa5f7ad2c 100644 --- a/core/jni/android/graphics/Paint.cpp +++ b/core/jni/android/graphics/Paint.cpp @@ -466,7 +466,8 @@ public: jchar* glyphsArray = env->GetCharArrayElements(glyphs, NULL); TextLayoutCacheValue value(contextCount); - TextLayoutEngine::getInstance().computeValues(&value, paint, text, start, count, contextCount, flags); + TextLayoutEngine::getInstance().computeValues(&value, paint, text, start, count, + contextCount, flags); const jchar* shapedGlyphs = value.getGlyphs(); size_t glyphsCount = value.getGlyphsCount(); memcpy(glyphsArray, shapedGlyphs, sizeof(jchar) * glyphsCount); @@ -673,13 +674,25 @@ public: } } - static int breakText(JNIEnv* env, const SkPaint& paint, const jchar text[], + static int breakText(JNIEnv* env, SkPaint& paint, const jchar text[], int count, float maxWidth, jfloatArray jmeasured, SkPaint::TextBufferDirection tbd) { - SkASSERT(paint.getTextEncoding() == SkPaint::kUTF16_TextEncoding); + sp value; +#if USE_TEXT_LAYOUT_CACHE + value = TextLayoutCache::getInstance().getValue(&paint, text, 0, count, + count, paint.getFlags()); + if (value == NULL) { + ALOGE("Cannot get TextLayoutCache value for text = '%s'", + String8(text, count).string()); + } +#else + value = new TextLayoutCacheValue(count); + TextLayoutEngine::getInstance().computeValues(value.get(), &paint, + reinterpret_cast(text), 0, count, count, paint.getFlags()); +#endif SkScalar measured; - size_t bytes = paint.breakText(text, count << 1, + size_t bytes = paint.breakText(value->getGlyphs(), value->getGlyphsCount() << 1, SkFloatToScalar(maxWidth), &measured, tbd); SkASSERT((bytes & 1) == 0); @@ -743,7 +756,20 @@ public: SkRect r; SkIRect ir; - paint.measureText(text, count << 1, &r); + sp value; +#if USE_TEXT_LAYOUT_CACHE + value = TextLayoutCache::getInstance().getValue(&paint, text, 0, count, + count, paint.getFlags()); + if (value == NULL) { + ALOGE("Cannot get TextLayoutCache value for text = '%s'", + String8(text, count).string()); + } +#else + value = new TextLayoutCacheValue(count); + TextLayoutEngine::getInstance().computeValues(value.get(), &paint, + reinterpret_cast(text), 0, count, count, paint.getFlags()); +#endif + paint.measureText(value->getGlyphs(), value->getGlyphsCount() << 1, &r); r.roundOut(&ir); GraphicsJNI::irect_to_jrect(ir, env, bounds); } diff --git a/core/jni/android/graphics/TextLayoutCache.cpp b/core/jni/android/graphics/TextLayoutCache.cpp index d26f563519ad..71c283a73e75 100644 --- a/core/jni/android/graphics/TextLayoutCache.cpp +++ b/core/jni/android/graphics/TextLayoutCache.cpp @@ -93,7 +93,7 @@ void TextLayoutCache::clear() { /* * Caching */ -sp TextLayoutCache::getValue(SkPaint* paint, +sp TextLayoutCache::getValue(const SkPaint* paint, const jchar* text, jint start, jint count, jint contextCount, jint dirFlags) { AutoMutex _l(mLock); nsecs_t startTime = 0; @@ -360,7 +360,7 @@ TextLayoutEngine::~TextLayoutEngine() { // we don't bother at the moment } -void TextLayoutEngine::computeValues(TextLayoutCacheValue* value, SkPaint* paint, const UChar* chars, +void TextLayoutEngine::computeValues(TextLayoutCacheValue* value, const SkPaint* paint, const UChar* chars, size_t start, size_t count, size_t contextCount, int dirFlags) { computeValues(paint, chars, start, count, contextCount, dirFlags, @@ -371,7 +371,7 @@ void TextLayoutEngine::computeValues(TextLayoutCacheValue* value, SkPaint* paint #endif } -void TextLayoutEngine::computeValues(SkPaint* paint, const UChar* chars, +void TextLayoutEngine::computeValues(const SkPaint* paint, const UChar* chars, size_t start, size_t count, size_t contextCount, int dirFlags, Vector* const outAdvances, jfloat* outTotalAdvance, Vector* const outGlyphs) { @@ -513,7 +513,7 @@ static void logGlyphs(HB_ShaperItem shaperItem) { } } -void TextLayoutEngine::computeRunValues(SkPaint* paint, const UChar* chars, +void TextLayoutEngine::computeRunValues(const SkPaint* paint, const UChar* chars, size_t count, bool isRTL, Vector* const outAdvances, jfloat* outTotalAdvance, Vector* const outGlyphs) { @@ -719,7 +719,7 @@ void TextLayoutEngine::computeRunValues(SkPaint* paint, const UChar* chars, } -size_t TextLayoutEngine::shapeFontRun(SkPaint* paint, bool isRTL) { +size_t TextLayoutEngine::shapeFontRun(const SkPaint* paint, bool isRTL) { // Reset kerning mShaperItem.kerning_applied = false; diff --git a/core/jni/android/graphics/TextLayoutCache.h b/core/jni/android/graphics/TextLayoutCache.h index 510aa18f6788..956e8cac3dd9 100644 --- a/core/jni/android/graphics/TextLayoutCache.h +++ b/core/jni/android/graphics/TextLayoutCache.h @@ -179,7 +179,7 @@ public: */ void operator()(TextLayoutCacheKey& text, sp& desc); - sp getValue(SkPaint* paint, const jchar* text, jint start, jint count, + sp getValue(const SkPaint* paint, const jchar* text, jint start, jint count, jint contextCount, jint dirFlags); /** @@ -224,7 +224,7 @@ public: TextLayoutEngine(); virtual ~TextLayoutEngine(); - void computeValues(TextLayoutCacheValue* value, SkPaint* paint, const UChar* chars, + void computeValues(TextLayoutCacheValue* value, const SkPaint* paint, const UChar* chars, size_t start, size_t count, size_t contextCount, int dirFlags); private: @@ -273,14 +273,14 @@ private: */ UnicodeString mBuffer; - size_t shapeFontRun(SkPaint* paint, bool isRTL); + size_t shapeFontRun(const SkPaint* paint, bool isRTL); - void computeValues(SkPaint* paint, const UChar* chars, + void computeValues(const SkPaint* paint, const UChar* chars, size_t start, size_t count, size_t contextCount, int dirFlags, Vector* const outAdvances, jfloat* outTotalAdvance, Vector* const outGlyphs); - void computeRunValues(SkPaint* paint, const UChar* chars, + void computeRunValues(const SkPaint* paint, const UChar* chars, size_t count, bool isRTL, Vector* const outAdvances, jfloat* outTotalAdvance, Vector* const outGlyphs); -- cgit v1.2.3-59-g8ed1b