diff options
author | Fabrice Di Meglio <fdimeglio@google.com> | 2013-02-13 19:11:50 +0000 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2013-02-13 19:11:50 +0000 |
commit | 0c33ecd209d884a9a2b9ad807cb798583b890a08 (patch) | |
tree | dd4b807023a4a71399d106221387176d360cc8c0 /core/jni/android | |
parent | 9cabb366917ec91d3dc1329ff7ea7c98c89399bb (diff) | |
parent | 6d9fe5bd22b531bfce69b146254a4791c76acddc (diff) | |
download | frameworks_base-0c33ecd209d884a9a2b9ad807cb798583b890a08.zip frameworks_base-0c33ecd209d884a9a2b9ad807cb798583b890a08.tar.gz frameworks_base-0c33ecd209d884a9a2b9ad807cb798583b890a08.tar.bz2 |
Merge "Clean Paint.mBidiFlags as it is no longer used"
Diffstat (limited to 'core/jni/android')
-rw-r--r-- | core/jni/android/graphics/Canvas.cpp | 52 | ||||
-rw-r--r-- | core/jni/android/graphics/Paint.cpp | 148 | ||||
-rw-r--r-- | core/jni/android/graphics/TextLayout.cpp | 114 | ||||
-rw-r--r-- | core/jni/android/graphics/TextLayout.h | 29 | ||||
-rw-r--r-- | core/jni/android/graphics/TextLayoutCache.cpp | 193 | ||||
-rw-r--r-- | core/jni/android/graphics/TextLayoutCache.h | 11 |
6 files changed, 158 insertions, 389 deletions
diff --git a/core/jni/android/graphics/Canvas.cpp b/core/jni/android/graphics/Canvas.cpp index 7208c57..1f1f28f 100644 --- a/core/jni/android/graphics/Canvas.cpp +++ b/core/jni/android/graphics/Canvas.cpp @@ -727,35 +727,35 @@ public: static void drawText___CIIFFIPaint(JNIEnv* env, jobject, SkCanvas* canvas, jcharArray text, int index, int count, - jfloat x, jfloat y, int flags, SkPaint* paint) { + jfloat x, jfloat y, SkPaint* paint) { jchar* textArray = env->GetCharArrayElements(text, NULL); - drawTextWithGlyphs(canvas, textArray + index, 0, count, x, y, flags, paint); + drawTextWithGlyphs(canvas, textArray + index, 0, count, x, y, paint); env->ReleaseCharArrayElements(text, textArray, JNI_ABORT); } static void drawText__StringIIFFIPaint(JNIEnv* env, jobject, SkCanvas* canvas, jstring text, int start, int end, - jfloat x, jfloat y, int flags, SkPaint* paint) { + jfloat x, jfloat y, SkPaint* paint) { const jchar* textArray = env->GetStringChars(text, NULL); - drawTextWithGlyphs(canvas, textArray, start, end, x, y, flags, paint); + drawTextWithGlyphs(canvas, textArray, start, end, x, y, paint); env->ReleaseStringChars(text, textArray); } static void drawTextWithGlyphs(SkCanvas* canvas, const jchar* textArray, int start, int end, - jfloat x, jfloat y, int flags, SkPaint* paint) { + jfloat x, jfloat y, SkPaint* paint) { jint count = end - start; - drawTextWithGlyphs(canvas, textArray + start, 0, count, count, x, y, flags, paint); + drawTextWithGlyphs(canvas, textArray + start, 0, count, count, x, y, paint); } static void drawTextWithGlyphs(SkCanvas* canvas, const jchar* textArray, int start, int count, int contextCount, - jfloat x, jfloat y, int flags, SkPaint* paint) { + jfloat x, jfloat y, SkPaint* paint) { sp<TextLayoutValue> value = TextLayoutEngine::getInstance().getValue(paint, - textArray, start, count, contextCount, flags); + textArray, start, count, contextCount); if (value == NULL) { return; } @@ -766,7 +766,7 @@ public: x -= value->getTotalAdvance(); } paint->setTextAlign(SkPaint::kLeft_Align); - doDrawGlyphsPos(canvas, value->getGlyphs(), value->getPos(), 0, value->getGlyphsCount(), x, y, flags, paint); + doDrawGlyphsPos(canvas, value->getGlyphs(), value->getPos(), 0, value->getGlyphsCount(), x, y, paint); doDrawTextDecorations(canvas, x, y, value->getTotalAdvance(), paint); paint->setTextAlign(align); } @@ -808,14 +808,8 @@ static void doDrawTextDecorations(SkCanvas* canvas, jfloat x, jfloat y, jfloat l } } - static void doDrawGlyphs(SkCanvas* canvas, const jchar* glyphArray, int index, int count, - jfloat x, jfloat y, int flags, SkPaint* paint) { - // Beware: this needs Glyph encoding (already done on the Paint constructor) - canvas->drawText(glyphArray + index * 2, count * 2, x, y, *paint); - } - static void doDrawGlyphsPos(SkCanvas* canvas, const jchar* glyphArray, const jfloat* posArray, - int index, int count, jfloat x, jfloat y, int flags, SkPaint* paint) { + int index, int count, jfloat x, jfloat y, SkPaint* paint) { SkPoint* posPtr = new SkPoint[count]; for (int indx = 0; indx < count; indx++) { posPtr[indx].fX = SkFloatToScalar(x + posArray[indx * 2]); @@ -832,7 +826,7 @@ static void doDrawTextDecorations(SkCanvas* canvas, jfloat x, jfloat y, jfloat l jchar* chars = env->GetCharArrayElements(text, NULL); drawTextWithGlyphs(canvas, chars + contextIndex, index - contextIndex, - count, contextCount, x, y, dirFlags, paint); + count, contextCount, x, y, paint); env->ReleaseCharArrayElements(text, chars, JNI_ABORT); } @@ -845,7 +839,7 @@ static void doDrawTextDecorations(SkCanvas* canvas, jfloat x, jfloat y, jfloat l jint contextCount = contextEnd - contextStart; const jchar* chars = env->GetStringChars(text, NULL); drawTextWithGlyphs(canvas, chars + contextStart, start - contextStart, - count, contextCount, x, y, dirFlags, paint); + count, contextCount, x, y, paint); env->ReleaseStringChars(text, chars); } @@ -908,21 +902,19 @@ static void doDrawTextDecorations(SkCanvas* canvas, jfloat x, jfloat y, jfloat l static void drawTextOnPath___CIIPathFFPaint(JNIEnv* env, jobject, SkCanvas* canvas, jcharArray text, int index, int count, - SkPath* path, jfloat hOffset, jfloat vOffset, jint bidiFlags, SkPaint* paint) { + SkPath* path, jfloat hOffset, jfloat vOffset, SkPaint* paint) { jchar* textArray = env->GetCharArrayElements(text, NULL); - TextLayout::drawTextOnPath(paint, textArray + index, count, bidiFlags, hOffset, vOffset, - path, canvas); + TextLayout::drawTextOnPath(paint, textArray + index, count, hOffset, vOffset, path, canvas); env->ReleaseCharArrayElements(text, textArray, 0); } static void drawTextOnPath__StringPathFFPaint(JNIEnv* env, jobject, SkCanvas* canvas, jstring text, SkPath* path, - jfloat hOffset, jfloat vOffset, jint bidiFlags, SkPaint* paint) { + jfloat hOffset, jfloat vOffset, SkPaint* paint) { const jchar* text_ = env->GetStringChars(text, NULL); int count = env->GetStringLength(text); - TextLayout::drawTextOnPath(paint, text_, count, bidiFlags, hOffset, vOffset, - path, canvas); + TextLayout::drawTextOnPath(paint, text_, count, hOffset, vOffset, path, canvas); env->ReleaseStringChars(text, text_); } @@ -1031,21 +1023,21 @@ static JNINativeMethod gCanvasMethods[] = { (void*)SkCanvasGlue::drawBitmapMesh}, {"nativeDrawVertices", "(III[FI[FI[II[SIII)V", (void*)SkCanvasGlue::drawVertices}, - {"native_drawText","(I[CIIFFII)V", + {"native_drawText","(I[CIIFFI)V", (void*) SkCanvasGlue::drawText___CIIFFIPaint}, - {"native_drawText","(ILjava/lang/String;IIFFII)V", + {"native_drawText","(ILjava/lang/String;IIFFI)V", (void*) SkCanvasGlue::drawText__StringIIFFIPaint}, - {"native_drawTextRun","(I[CIIIIFFII)V", + {"native_drawTextRun","(I[CIIIIFFI)V", (void*) SkCanvasGlue::drawTextRun___CIIIIFFIPaint}, - {"native_drawTextRun","(ILjava/lang/String;IIIIFFII)V", + {"native_drawTextRun","(ILjava/lang/String;IIIIFFI)V", (void*) SkCanvasGlue::drawTextRun__StringIIIIFFIPaint}, {"native_drawPosText","(I[CII[FI)V", (void*) SkCanvasGlue::drawPosText___CII_FPaint}, {"native_drawPosText","(ILjava/lang/String;[FI)V", (void*) SkCanvasGlue::drawPosText__String_FPaint}, - {"native_drawTextOnPath","(I[CIIIFFII)V", + {"native_drawTextOnPath","(I[CIIIFFI)V", (void*) SkCanvasGlue::drawTextOnPath___CIIPathFFPaint}, - {"native_drawTextOnPath","(ILjava/lang/String;IFFII)V", + {"native_drawTextOnPath","(ILjava/lang/String;IFFI)V", (void*) SkCanvasGlue::drawTextOnPath__StringPathFFPaint}, {"native_drawPicture", "(II)V", (void*) SkCanvasGlue::drawPicture}, diff --git a/core/jni/android/graphics/Paint.cpp b/core/jni/android/graphics/Paint.cpp index 29a36de..e830492 100644 --- a/core/jni/android/graphics/Paint.cpp +++ b/core/jni/android/graphics/Paint.cpp @@ -401,7 +401,7 @@ public: jfloat result = 0; TextLayout::getTextRunAdvances(paint, textArray, index, count, textLength, - paint->getFlags(), NULL /* dont need all advances */, &result); + NULL /* dont need all advances */, &result); env->ReleaseCharArrayElements(text, const_cast<jchar*>(textArray), JNI_ABORT); return result; @@ -426,7 +426,7 @@ public: jfloat width = 0; TextLayout::getTextRunAdvances(paint, textArray, start, count, textLength, - paint->getFlags(), NULL /* dont need all advances */, &width); + NULL /* dont need all advances */, &width); env->ReleaseStringChars(text, textArray); return width; @@ -446,7 +446,7 @@ public: jfloat width = 0; TextLayout::getTextRunAdvances(paint, textArray, 0, textLength, textLength, - paint->getFlags(), NULL /* dont need all advances */, &width); + NULL /* dont need all advances */, &width); env->ReleaseStringChars(text, textArray); return width; @@ -473,7 +473,7 @@ public: jfloat* widthsArray = autoWidths.ptr(); TextLayout::getTextRunAdvances(paint, text, 0, count, count, - paint->getFlags(), widthsArray, NULL /* dont need totalAdvance */); + widthsArray, NULL /* dont need totalAdvance */); return count; } @@ -494,48 +494,8 @@ public: return count; } - static int doTextGlyphs(JNIEnv* env, SkPaint* paint, const jchar* text, jint start, jint count, - jint contextCount, jint flags, jcharArray glyphs) { - NPE_CHECK_RETURN_ZERO(env, paint); - NPE_CHECK_RETURN_ZERO(env, text); - - if ((start | count | contextCount) < 0 || contextCount < count || !glyphs) { - doThrowAIOOBE(env); - return 0; - } - if (count == 0) { - return 0; - } - size_t glypthsLength = env->GetArrayLength(glyphs); - if ((size_t)count > glypthsLength) { - doThrowAIOOBE(env); - return 0; - } - - jchar* glyphsArray = env->GetCharArrayElements(glyphs, NULL); - - sp<TextLayoutValue> value = TextLayoutEngine::getInstance().getValue(paint, - text, start, count, contextCount, flags); - const jchar* shapedGlyphs = value->getGlyphs(); - size_t glyphsCount = value->getGlyphsCount(); - memcpy(glyphsArray, shapedGlyphs, sizeof(jchar) * glyphsCount); - - env->ReleaseCharArrayElements(glyphs, glyphsArray, JNI_ABORT); - return glyphsCount; - } - - static int getTextGlyphs__StringIIIII_C(JNIEnv* env, jobject clazz, SkPaint* paint, - jstring text, jint start, jint end, jint contextStart, jint contextEnd, jint flags, - jcharArray glyphs) { - const jchar* textArray = env->GetStringChars(text, NULL); - int count = doTextGlyphs(env, paint, textArray + contextStart, start - contextStart, - end - start, contextEnd - contextStart, flags, glyphs); - env->ReleaseStringChars(text, textArray); - return count; - } - static jfloat doTextRunAdvances(JNIEnv *env, SkPaint *paint, const jchar *text, - jint start, jint count, jint contextCount, jint flags, + jint start, jint count, jint contextCount, jfloatArray advances, jint advancesIndex) { NPE_CHECK_RETURN_ZERO(env, paint); NPE_CHECK_RETURN_ZERO(env, text); @@ -557,7 +517,7 @@ public: jfloat advancesArray[count]; jfloat totalAdvance = 0; - TextLayout::getTextRunAdvances(paint, text, start, count, contextCount, flags, + TextLayout::getTextRunAdvances(paint, text, start, count, contextCount, advancesArray, &totalAdvance); if (advances != NULL) { @@ -566,61 +526,23 @@ public: return totalAdvance; } - static jfloat doTextRunAdvancesICU(JNIEnv *env, SkPaint *paint, const jchar *text, - jint start, jint count, jint contextCount, jint flags, - jfloatArray advances, jint advancesIndex) { - NPE_CHECK_RETURN_ZERO(env, paint); - NPE_CHECK_RETURN_ZERO(env, text); - - if ((start | count | contextCount | advancesIndex) < 0 || contextCount < count) { - doThrowAIOOBE(env); - return 0; - } - if (count == 0) { - return 0; - } - if (advances) { - size_t advancesLength = env->GetArrayLength(advances); - if ((size_t)count > advancesLength) { - doThrowAIOOBE(env); - return 0; - } - } - - jfloat advancesArray[count]; - jfloat totalAdvance = 0; - - TextLayout::getTextRunAdvancesICU(paint, text, start, count, contextCount, flags, - advancesArray, totalAdvance); - - if (advances != NULL) { - env->SetFloatArrayRegion(advances, advancesIndex, count, advancesArray); - } - return totalAdvance; - } - - static float getTextRunAdvances___CIIIII_FII(JNIEnv* env, jobject clazz, SkPaint* paint, + static float getTextRunAdvances___CIIII_FI(JNIEnv* env, jobject clazz, SkPaint* paint, jcharArray text, jint index, jint count, jint contextIndex, jint contextCount, - jint flags, jfloatArray advances, jint advancesIndex, jint reserved) { + jfloatArray advances, jint advancesIndex) { jchar* textArray = env->GetCharArrayElements(text, NULL); - jfloat result = (reserved == 0) ? - doTextRunAdvances(env, paint, textArray + contextIndex, index - contextIndex, - count, contextCount, flags, advances, advancesIndex) : - doTextRunAdvancesICU(env, paint, textArray + contextIndex, index - contextIndex, - count, contextCount, flags, advances, advancesIndex); + jfloat result = doTextRunAdvances(env, paint, textArray + contextIndex, + index - contextIndex, count, contextCount, advances, advancesIndex); env->ReleaseCharArrayElements(text, textArray, JNI_ABORT); return result; } - static float getTextRunAdvances__StringIIIII_FII(JNIEnv* env, jobject clazz, SkPaint* paint, - jstring text, jint start, jint end, jint contextStart, jint contextEnd, jint flags, - jfloatArray advances, jint advancesIndex, jint reserved) { + static float getTextRunAdvances__StringIIII_FI(JNIEnv* env, jobject clazz, SkPaint* paint, + jstring text, jint start, jint end, jint contextStart, jint contextEnd, + jfloatArray advances, jint advancesIndex) { const jchar* textArray = env->GetStringChars(text, NULL); - jfloat result = (reserved == 0) ? - doTextRunAdvances(env, paint, textArray + contextStart, start - contextStart, - end - start, contextEnd - contextStart, flags, advances, advancesIndex) : - doTextRunAdvancesICU(env, paint, textArray + contextStart, start - contextStart, - end - start, contextEnd - contextStart, flags, advances, advancesIndex); + jfloat result = doTextRunAdvances(env, paint, textArray + contextStart, + start - contextStart, end - start, contextEnd - contextStart, + advances, advancesIndex); env->ReleaseStringChars(text, textArray); return result; } @@ -629,7 +551,7 @@ public: jint count, jint flags, jint offset, jint opt) { jfloat scalarArray[count]; - TextLayout::getTextRunAdvances(paint, text, start, count, start + count, flags, + TextLayout::getTextRunAdvances(paint, text, start, count, start + count, scalarArray, NULL /* dont need totalAdvance */); jint pos = offset - start; @@ -688,21 +610,21 @@ public: } static void getTextPath(JNIEnv* env, SkPaint* paint, const jchar* text, jint count, - jint bidiFlags, jfloat x, jfloat y, SkPath *path) { - TextLayout::getTextPath(paint, text, count, bidiFlags, x, y, path); + jfloat x, jfloat y, SkPath *path) { + TextLayout::getTextPath(paint, text, count, x, y, path); } - static void getTextPath___C(JNIEnv* env, jobject clazz, SkPaint* paint, jint bidiFlags, + static void getTextPath___C(JNIEnv* env, jobject clazz, SkPaint* paint, jcharArray text, int index, int count, jfloat x, jfloat y, SkPath* path) { const jchar* textArray = env->GetCharArrayElements(text, NULL); - getTextPath(env, paint, textArray + index, count, bidiFlags, x, y, path); + getTextPath(env, paint, textArray + index, count, x, y, path); env->ReleaseCharArrayElements(text, const_cast<jchar*>(textArray), JNI_ABORT); } - static void getTextPath__String(JNIEnv* env, jobject clazz, SkPaint* paint, jint bidiFlags, + static void getTextPath__String(JNIEnv* env, jobject clazz, SkPaint* paint, jstring text, int start, int end, jfloat x, jfloat y, SkPath* path) { const jchar* textArray = env->GetStringChars(text, NULL); - getTextPath(env, paint, textArray + start, end - start, bidiFlags, x, y, path); + getTextPath(env, paint, textArray + start, end - start, x, y, path); env->ReleaseStringChars(text, textArray); } @@ -726,7 +648,7 @@ public: int count, float maxWidth, jfloatArray jmeasured, SkPaint::TextBufferDirection tbd) { sp<TextLayoutValue> value = TextLayoutEngine::getInstance().getValue(&paint, - text, 0, count, count, paint.getFlags()); + text, 0, count, count); if (value == NULL) { return 0; } @@ -798,7 +720,7 @@ public: SkIRect ir; sp<TextLayoutValue> value = TextLayoutEngine::getInstance().getValue(&paint, - text, 0, count, count, paint.getFlags()); + text, 0, count, count); if (value == NULL) { return; } @@ -886,19 +808,15 @@ static JNINativeMethod methods[] = { {"native_breakText","(Ljava/lang/String;ZF[F)I", (void*) SkPaintGlue::breakTextS}, {"native_getTextWidths","(I[CII[F)I", (void*) SkPaintGlue::getTextWidths___CII_F}, {"native_getTextWidths","(ILjava/lang/String;II[F)I", (void*) SkPaintGlue::getTextWidths__StringII_F}, - {"native_getTextRunAdvances","(I[CIIIII[FII)F", - (void*) SkPaintGlue::getTextRunAdvances___CIIIII_FII}, - {"native_getTextRunAdvances","(ILjava/lang/String;IIIII[FII)F", - (void*) SkPaintGlue::getTextRunAdvances__StringIIIII_FII}, - - - {"native_getTextGlyphs","(ILjava/lang/String;IIIII[C)I", - (void*) SkPaintGlue::getTextGlyphs__StringIIIII_C}, - {"native_getTextRunCursor", "(I[CIIIII)I", (void*) SkPaintGlue::getTextRunCursor___C}, - {"native_getTextRunCursor", "(ILjava/lang/String;IIIII)I", + {"native_getTextRunAdvances","(I[CIIII[FI)F", + (void*) SkPaintGlue::getTextRunAdvances___CIIII_FI}, + {"native_getTextRunAdvances","(ILjava/lang/String;IIII[FI)F", + (void*) SkPaintGlue::getTextRunAdvances__StringIIII_FI}, + {"native_getTextRunCursor", "(I[CIIII)I", (void*) SkPaintGlue::getTextRunCursor___C}, + {"native_getTextRunCursor", "(ILjava/lang/String;IIII)I", (void*) SkPaintGlue::getTextRunCursor__String}, - {"native_getTextPath","(II[CIIFFI)V", (void*) SkPaintGlue::getTextPath___C}, - {"native_getTextPath","(IILjava/lang/String;IIFFI)V", (void*) SkPaintGlue::getTextPath__String}, + {"native_getTextPath","(I[CIIFFI)V", (void*) SkPaintGlue::getTextPath___C}, + {"native_getTextPath","(ILjava/lang/String;IIFFI)V", (void*) SkPaintGlue::getTextPath__String}, {"nativeGetStringBounds", "(ILjava/lang/String;IILandroid/graphics/Rect;)V", (void*) SkPaintGlue::getStringBounds }, {"nativeGetCharArrayBounds", "(I[CIILandroid/graphics/Rect;)V", diff --git a/core/jni/android/graphics/TextLayout.cpp b/core/jni/android/graphics/TextLayout.cpp index 2beedad..b77236c 100644 --- a/core/jni/android/graphics/TextLayout.cpp +++ b/core/jni/android/graphics/TextLayout.cpp @@ -28,33 +28,13 @@ namespace android { -// Returns true if we might need layout. If bidiFlags force LTR, assume no layout, if -// bidiFlags indicate there probably is RTL, assume we do, otherwise scan the text -// looking for a character >= the first RTL character in unicode and assume we do if -// we find one. -bool TextLayout::needsLayout(const jchar* text, jint len, jint bidiFlags) { - if (bidiFlags == kBidi_Force_LTR) { - return false; - } - if ((bidiFlags == kBidi_RTL) || (bidiFlags == kBidi_Default_RTL) || - bidiFlags == kBidi_Force_RTL) { - return true; - } - for (int i = 0; i < len; ++i) { - if (text[i] >= UNICODE_FIRST_RTL_CHAR) { - return true; - } - } - return false; -} - // Draws or gets the path of a paragraph of text on a single line, running bidi and shaping. // This will draw if canvas is not null, otherwise path must be non-null and it will create // a path representing the text that would have been drawn. void TextLayout::handleText(SkPaint *paint, const jchar* text, jsize len, - jint bidiFlags, jfloat x, jfloat y, SkPath *path) { + jfloat x, jfloat y, SkPath *path) { sp<TextLayoutValue> value = TextLayoutEngine::getInstance().getValue(paint, - text, 0, len, len, bidiFlags); + text, 0, len, len); if (value == NULL) { return ; } @@ -65,10 +45,10 @@ void TextLayout::handleText(SkPaint *paint, const jchar* text, jsize len, } void TextLayout::getTextRunAdvances(SkPaint* paint, const jchar* chars, jint start, - jint count, jint contextCount, jint dirFlags, + jint count, jint contextCount, jfloat* resultAdvances, jfloat* resultTotalAdvance) { sp<TextLayoutValue> value = TextLayoutEngine::getInstance().getValue(paint, - chars, start, count, contextCount, dirFlags); + chars, start, count, contextCount); if (value == NULL) { return ; } @@ -80,29 +60,20 @@ void TextLayout::getTextRunAdvances(SkPaint* paint, const jchar* chars, jint sta } } -void TextLayout::getTextRunAdvancesICU(SkPaint* paint, const jchar* chars, jint start, - jint count, jint contextCount, jint dirFlags, - jfloat* resultAdvances, jfloat& resultTotalAdvance) { - // Compute advances and return them - computeAdvancesWithICU(paint, chars, start, count, contextCount, dirFlags, - resultAdvances, &resultTotalAdvance); -} - void TextLayout::getTextPath(SkPaint *paint, const jchar *text, jsize len, - jint bidiFlags, jfloat x, jfloat y, SkPath *path) { - handleText(paint, text, len, bidiFlags, x, y, path); + jfloat x, jfloat y, SkPath *path) { + handleText(paint, text, len, x, y, path); } - void TextLayout::drawTextOnPath(SkPaint* paint, const jchar* text, int count, - int bidiFlags, jfloat hOffset, jfloat vOffset, + jfloat hOffset, jfloat vOffset, SkPath* path, SkCanvas* canvas) { SkScalar h_ = SkFloatToScalar(hOffset); SkScalar v_ = SkFloatToScalar(vOffset); sp<TextLayoutValue> value = TextLayoutEngine::getInstance().getValue(paint, - text, 0, count, count, bidiFlags); + text, 0, count, count); if (value == NULL) { return; } @@ -111,73 +82,4 @@ void TextLayout::drawTextOnPath(SkPaint* paint, const jchar* text, int count, canvas->drawTextOnPathHV(value->getGlyphs(), value->getGlyphsCount() * 2, *path, h_, v_, *paint); } -void TextLayout::computeAdvancesWithICU(SkPaint* paint, const UChar* chars, - size_t start, size_t count, size_t contextCount, int dirFlags, - jfloat* outAdvances, jfloat* outTotalAdvance) { - SkAutoSTMalloc<CHAR_BUFFER_SIZE, jchar> tempBuffer(contextCount); - jchar* buffer = tempBuffer.get(); - SkScalar* scalarArray = (SkScalar*)outAdvances; - - // this is where we'd call harfbuzz - // for now we just use ushape.c - size_t widths; - const jchar* text; - if (dirFlags & 0x1) { // rtl, call arabic shaping in case - UErrorCode status = U_ZERO_ERROR; - // Use fixed length since we need to keep start and count valid - u_shapeArabic(chars, contextCount, buffer, contextCount, - U_SHAPE_LENGTH_FIXED_SPACES_NEAR | - U_SHAPE_TEXT_DIRECTION_LOGICAL | U_SHAPE_LETTERS_SHAPE | - U_SHAPE_X_LAMALEF_SUB_ALTERNATE, &status); - // we shouldn't fail unless there's an out of memory condition, - // in which case we're hosed anyway - for (int i = start, e = i + count; i < e; ++i) { - if (buffer[i] == UNICODE_NOT_A_CHAR) { - buffer[i] = UNICODE_ZWSP; // zero-width-space for skia - } - } - text = buffer + start; - widths = paint->getTextWidths(text, count << 1, scalarArray); - } else { - text = chars + start; - widths = paint->getTextWidths(text, count << 1, scalarArray); - } - - jfloat totalAdvance = 0; - if (widths < count) { -#if DEBUG_ADVANCES - ALOGD("ICU -- count=%d", widths); -#endif - // Skia operates on code points, not code units, so surrogate pairs return only - // one value. Expand the result so we have one value per UTF-16 code unit. - - // Note, skia's getTextWidth gets confused if it encounters a surrogate pair, - // leaving the remaining widths zero. Not nice. - for (size_t i = 0, p = 0; i < widths; ++i) { - totalAdvance += outAdvances[p++] = SkScalarToFloat(scalarArray[i]); - if (p < count && - text[p] >= UNICODE_FIRST_LOW_SURROGATE && - text[p] < UNICODE_FIRST_PRIVATE_USE && - text[p-1] >= UNICODE_FIRST_HIGH_SURROGATE && - text[p-1] < UNICODE_FIRST_LOW_SURROGATE) { - outAdvances[p++] = 0; - } -#if DEBUG_ADVANCES - ALOGD("icu-adv = %f - total = %f", outAdvances[i], totalAdvance); -#endif - } - } else { -#if DEBUG_ADVANCES - ALOGD("ICU -- count=%d", count); -#endif - for (size_t i = 0; i < count; i++) { - totalAdvance += outAdvances[i] = SkScalarToFloat(scalarArray[i]); -#if DEBUG_ADVANCES - ALOGD("icu-adv = %f - total = %f", outAdvances[i], totalAdvance); -#endif - } - } - *outTotalAdvance = totalAdvance; -} - } diff --git a/core/jni/android/graphics/TextLayout.h b/core/jni/android/graphics/TextLayout.h index a0f9402..fa388c8 100644 --- a/core/jni/android/graphics/TextLayout.h +++ b/core/jni/android/graphics/TextLayout.h @@ -42,17 +42,6 @@ namespace android { #define USE_TEXT_LAYOUT_CACHE 1 enum { - kBidi_LTR = 0, - kBidi_RTL = 1, - kBidi_Default_LTR = 2, - kBidi_Default_RTL = 3, - kBidi_Force_LTR = 4, - kBidi_Force_RTL = 5, - - kBidi_Mask = 0x7 -}; - -enum { kDirection_LTR = 0, kDirection_RTL = 1, @@ -63,28 +52,18 @@ class TextLayout { public: static void getTextRunAdvances(SkPaint* paint, const jchar* chars, jint start, - jint count, jint contextCount, jint dirFlags, + jint count, jint contextCount, jfloat* resultAdvances, jfloat* resultTotalAdvance); - static void getTextRunAdvancesICU(SkPaint* paint, const jchar* chars, jint start, - jint count, jint contextCount, jint dirFlags, - jfloat* resultAdvances, jfloat& resultTotalAdvance); - static void getTextPath(SkPaint* paint, const jchar* text, jsize len, - jint bidiFlags, jfloat x, jfloat y, SkPath* path); + jfloat x, jfloat y, SkPath* path); static void drawTextOnPath(SkPaint* paint, const jchar* text, jsize len, - int bidiFlags, jfloat hOffset, jfloat vOffset, + jfloat hOffset, jfloat vOffset, SkPath* path, SkCanvas* canvas); private: - static bool needsLayout(const jchar* text, jint len, jint bidiFlags); - static void handleText(SkPaint* paint, const jchar* text, jsize len, - int bidiFlags, jfloat x, jfloat y, SkPath* path); - - static void computeAdvancesWithICU(SkPaint* paint, const UChar* chars, - size_t start, size_t count, size_t contextCount, int dirFlags, - jfloat* outAdvances, jfloat* outTotalAdvance); + jfloat x, jfloat y, SkPath* path); }; } // namespace android diff --git a/core/jni/android/graphics/TextLayoutCache.cpp b/core/jni/android/graphics/TextLayoutCache.cpp index 1ace23e..1a8612e 100644 --- a/core/jni/android/graphics/TextLayoutCache.cpp +++ b/core/jni/android/graphics/TextLayoutCache.cpp @@ -87,7 +87,7 @@ void TextLayoutCache::purgeCaches() { * Caching */ sp<TextLayoutValue> TextLayoutCache::getValue(const SkPaint* paint, - const jchar* text, jint start, jint count, jint contextCount, jint dirFlags) { + const jchar* text, jint start, jint count, jint contextCount) { AutoMutex _l(mLock); nsecs_t startTime = 0; if (mDebugEnabled) { @@ -95,7 +95,7 @@ sp<TextLayoutValue> TextLayoutCache::getValue(const SkPaint* paint, } // Create the key - TextLayoutCacheKey key(paint, text, start, count, contextCount, dirFlags); + TextLayoutCacheKey key(paint, text, start, count, contextCount); // Get value from cache if possible sp<TextLayoutValue> value = mCache.get(key); @@ -111,7 +111,7 @@ sp<TextLayoutValue> TextLayoutCache::getValue(const SkPaint* paint, // Compute advances and store them mShaper->computeValues(value.get(), paint, reinterpret_cast<const UChar*>(key.getText()), start, count, - size_t(contextCount), int(dirFlags)); + size_t(contextCount)); if (mDebugEnabled) { value->setElapsedTime(systemTime(SYSTEM_TIME_MONOTONIC) - startTime); @@ -218,14 +218,13 @@ void TextLayoutCache::dumpCacheStats() { * TextLayoutCacheKey */ TextLayoutCacheKey::TextLayoutCacheKey(): start(0), count(0), contextCount(0), - dirFlags(0), typeface(NULL), textSize(0), textSkewX(0), textScaleX(0), flags(0), + typeface(NULL), textSize(0), textSkewX(0), textScaleX(0), flags(0), hinting(SkPaint::kNo_Hinting), variant(SkPaint::kDefault_Variant), language() { } TextLayoutCacheKey::TextLayoutCacheKey(const SkPaint* paint, const UChar* text, - size_t start, size_t count, size_t contextCount, int dirFlags) : - start(start), count(count), contextCount(contextCount), - dirFlags(dirFlags) { + size_t start, size_t count, size_t contextCount) : + start(start), count(count), contextCount(contextCount) { textCopy.setTo(text, contextCount); typeface = paint->getTypeface(); textSize = paint->getTextSize(); @@ -242,7 +241,6 @@ TextLayoutCacheKey::TextLayoutCacheKey(const TextLayoutCacheKey& other) : start(other.start), count(other.count), contextCount(other.contextCount), - dirFlags(other.dirFlags), typeface(other.typeface), textSize(other.textSize), textSkewX(other.textSkewX), @@ -281,9 +279,6 @@ int TextLayoutCacheKey::compare(const TextLayoutCacheKey& lhs, const TextLayoutC deltaInt = lhs.hinting - rhs.hinting; if (deltaInt != 0) return (deltaInt); - deltaInt = lhs.dirFlags - rhs.dirFlags; - if (deltaInt) return (deltaInt); - deltaInt = lhs.variant - rhs.variant; if (deltaInt) return (deltaInt); @@ -359,9 +354,9 @@ TextLayoutShaper::~TextLayoutShaper() { } void TextLayoutShaper::computeValues(TextLayoutValue* value, const SkPaint* paint, const UChar* chars, - size_t start, size_t count, size_t contextCount, int dirFlags) { + size_t start, size_t count, size_t contextCount) { - computeValues(paint, chars, start, count, contextCount, dirFlags, + computeValues(paint, chars, start, count, contextCount, &value->mAdvances, &value->mTotalAdvance, &value->mGlyphs, &value->mPos); #if DEBUG_ADVANCES ALOGD("Advances - start = %d, count = %d, contextCount = %d, totalAdvance = %f", start, count, @@ -370,7 +365,7 @@ void TextLayoutShaper::computeValues(TextLayoutValue* value, const SkPaint* pain } void TextLayoutShaper::computeValues(const SkPaint* paint, const UChar* chars, - size_t start, size_t count, size_t contextCount, int dirFlags, + size_t start, size_t count, size_t contextCount, Vector<jfloat>* const outAdvances, jfloat* outTotalAdvance, Vector<jchar>* const outGlyphs, Vector<jfloat>* const outPos) { *outTotalAdvance = 0; @@ -378,110 +373,94 @@ void TextLayoutShaper::computeValues(const SkPaint* paint, const UChar* chars, return; } - UBiDiLevel bidiReq = 0; - bool forceLTR = false; - bool forceRTL = false; - - switch (dirFlags & kBidi_Mask) { - case kBidi_LTR: bidiReq = 0; break; // no ICU constant, canonical LTR level - case kBidi_RTL: bidiReq = 1; break; // no ICU constant, canonical RTL level - case kBidi_Default_LTR: bidiReq = UBIDI_DEFAULT_LTR; break; - case kBidi_Default_RTL: bidiReq = UBIDI_DEFAULT_RTL; break; - case kBidi_Force_LTR: forceLTR = true; break; // every char is LTR - case kBidi_Force_RTL: forceRTL = true; break; // every char is RTL - } - + UBiDiLevel bidiReq = UBIDI_DEFAULT_LTR; bool useSingleRun = false; - bool isRTL = forceRTL; - if (forceLTR || forceRTL) { - useSingleRun = true; - } else { - UBiDi* bidi = ubidi_open(); - if (bidi) { - UErrorCode status = U_ZERO_ERROR; + bool isRTL = false; + + UBiDi* bidi = ubidi_open(); + if (bidi) { + UErrorCode status = U_ZERO_ERROR; #if DEBUG_GLYPHS - ALOGD("******** ComputeValues -- start"); - ALOGD(" -- string = '%s'", String8(chars + start, count).string()); - ALOGD(" -- start = %d", start); - ALOGD(" -- count = %d", count); - ALOGD(" -- contextCount = %d", contextCount); - ALOGD(" -- bidiReq = %d", bidiReq); + ALOGD("******** ComputeValues -- start"); + ALOGD(" -- string = '%s'", String8(chars + start, count).string()); + ALOGD(" -- start = %d", start); + ALOGD(" -- count = %d", count); + ALOGD(" -- contextCount = %d", contextCount); + ALOGD(" -- bidiReq = %d", bidiReq); #endif - ubidi_setPara(bidi, chars, contextCount, bidiReq, NULL, &status); - if (U_SUCCESS(status)) { - int paraDir = ubidi_getParaLevel(bidi) & kDirection_Mask; // 0 if ltr, 1 if rtl - ssize_t rc = ubidi_countRuns(bidi, &status); + ubidi_setPara(bidi, chars, contextCount, bidiReq, NULL, &status); + if (U_SUCCESS(status)) { + int paraDir = ubidi_getParaLevel(bidi) & kDirection_Mask; // 0 if ltr, 1 if rtl + ssize_t rc = ubidi_countRuns(bidi, &status); #if DEBUG_GLYPHS - ALOGD(" -- dirFlags = %d", dirFlags); - ALOGD(" -- paraDir = %d", paraDir); - ALOGD(" -- run-count = %d", int(rc)); + ALOGD(" -- paraDir = %d", paraDir); + ALOGD(" -- run-count = %d", int(rc)); #endif - if (U_SUCCESS(status) && rc == 1) { - // Normal case: one run, status is ok - isRTL = (paraDir == 1); - useSingleRun = true; - } else if (!U_SUCCESS(status) || rc < 1) { - ALOGW("Need to force to single run -- string = '%s'," - " status = %d, rc = %d", - String8(chars + start, count).string(), status, int(rc)); - isRTL = (paraDir == 1); - useSingleRun = true; - } else { - int32_t end = start + count; - for (size_t i = 0; i < size_t(rc); ++i) { - int32_t startRun = -1; - int32_t lengthRun = -1; - UBiDiDirection runDir = ubidi_getVisualRun(bidi, i, &startRun, &lengthRun); - - if (startRun == -1 || lengthRun == -1) { - // Something went wrong when getting the visual run, need to clear - // already computed data before doing a single run pass - ALOGW("Visual run is not valid"); - outGlyphs->clear(); - outAdvances->clear(); - outPos->clear(); - *outTotalAdvance = 0; - isRTL = (paraDir == 1); - useSingleRun = true; - break; - } - - if (startRun >= end) { - continue; - } - int32_t endRun = startRun + lengthRun; - if (endRun <= int32_t(start)) { - continue; - } - if (startRun < int32_t(start)) { - startRun = int32_t(start); - } - if (endRun > end) { - endRun = end; - } - - lengthRun = endRun - startRun; - isRTL = (runDir == UBIDI_RTL); + if (U_SUCCESS(status) && rc == 1) { + // Normal case: one run, status is ok + isRTL = (paraDir == 1); + useSingleRun = true; + } else if (!U_SUCCESS(status) || rc < 1) { + ALOGW("Need to force to single run -- string = '%s'," + " status = %d, rc = %d", + String8(chars + start, count).string(), status, int(rc)); + isRTL = (paraDir == 1); + useSingleRun = true; + } else { + int32_t end = start + count; + for (size_t i = 0; i < size_t(rc); ++i) { + int32_t startRun = -1; + int32_t lengthRun = -1; + UBiDiDirection runDir = ubidi_getVisualRun(bidi, i, &startRun, &lengthRun); + + if (startRun == -1 || lengthRun == -1) { + // Something went wrong when getting the visual run, need to clear + // already computed data before doing a single run pass + ALOGW("Visual run is not valid"); + outGlyphs->clear(); + outAdvances->clear(); + outPos->clear(); + *outTotalAdvance = 0; + isRTL = (paraDir == 1); + useSingleRun = true; + break; + } + + if (startRun >= end) { + continue; + } + int32_t endRun = startRun + lengthRun; + if (endRun <= int32_t(start)) { + continue; + } + if (startRun < int32_t(start)) { + startRun = int32_t(start); + } + if (endRun > end) { + endRun = end; + } + + lengthRun = endRun - startRun; + isRTL = (runDir == UBIDI_RTL); #if DEBUG_GLYPHS - ALOGD("Processing Bidi Run = %d -- run-start = %d, run-len = %d, isRTL = %d", - i, startRun, lengthRun, isRTL); + ALOGD("Processing Bidi Run = %d -- run-start = %d, run-len = %d, isRTL = %d", + i, startRun, lengthRun, isRTL); #endif - computeRunValues(paint, chars, startRun, lengthRun, contextCount, isRTL, - outAdvances, outTotalAdvance, outGlyphs, outPos); + computeRunValues(paint, chars, startRun, lengthRun, contextCount, isRTL, + outAdvances, outTotalAdvance, outGlyphs, outPos); - } } - } else { - ALOGW("Cannot set Para"); - useSingleRun = true; - isRTL = (bidiReq = 1) || (bidiReq = UBIDI_DEFAULT_RTL); } - ubidi_close(bidi); } else { - ALOGW("Cannot ubidi_open()"); + ALOGW("Cannot set Para"); useSingleRun = true; isRTL = (bidiReq = 1) || (bidiReq = UBIDI_DEFAULT_RTL); } + ubidi_close(bidi); + } else { + ALOGW("Cannot ubidi_open()"); + useSingleRun = true; + isRTL = (bidiReq = 1) || (bidiReq = UBIDI_DEFAULT_RTL); } // Default single run case @@ -918,11 +897,11 @@ TextLayoutEngine::~TextLayoutEngine() { } sp<TextLayoutValue> TextLayoutEngine::getValue(const SkPaint* paint, const jchar* text, - jint start, jint count, jint contextCount, jint dirFlags) { + jint start, jint count, jint contextCount) { sp<TextLayoutValue> value; #if USE_TEXT_LAYOUT_CACHE value = mTextLayoutCache->getValue(paint, text, start, count, - contextCount, dirFlags); + contextCount); if (value == NULL) { ALOGE("Cannot get TextLayoutCache value for text = '%s'", String8(text + start, count).string()); @@ -930,7 +909,7 @@ sp<TextLayoutValue> TextLayoutEngine::getValue(const SkPaint* paint, const jchar #else value = new TextLayoutValue(count); mShaper->computeValues(value.get(), paint, - reinterpret_cast<const UChar*>(text), start, count, contextCount, dirFlags); + reinterpret_cast<const UChar*>(text), start, count, contextCount); #endif return value; } diff --git a/core/jni/android/graphics/TextLayoutCache.h b/core/jni/android/graphics/TextLayoutCache.h index 704c773..29805ee 100644 --- a/core/jni/android/graphics/TextLayoutCache.h +++ b/core/jni/android/graphics/TextLayoutCache.h @@ -71,7 +71,7 @@ public: TextLayoutCacheKey(); TextLayoutCacheKey(const SkPaint* paint, const UChar* text, size_t start, size_t count, - size_t contextCount, int dirFlags); + size_t contextCount); TextLayoutCacheKey(const TextLayoutCacheKey& other); @@ -98,7 +98,6 @@ private: size_t start; size_t count; size_t contextCount; - int dirFlags; SkTypeface* typeface; SkScalar textSize; SkScalar textSkewX; @@ -182,7 +181,7 @@ public: virtual ~TextLayoutShaper(); void computeValues(TextLayoutValue* value, const SkPaint* paint, const UChar* chars, - size_t start, size_t count, size_t contextCount, int dirFlags); + size_t start, size_t count, size_t contextCount); void purgeCaches(); @@ -216,7 +215,7 @@ private: size_t shapeFontRun(const SkPaint* paint); void computeValues(const SkPaint* paint, const UChar* chars, - size_t start, size_t count, size_t contextCount, int dirFlags, + size_t start, size_t count, size_t contextCount, Vector<jfloat>* const outAdvances, jfloat* outTotalAdvance, Vector<jchar>* const outGlyphs, Vector<jfloat>* const outPos); @@ -253,7 +252,7 @@ public: void operator()(TextLayoutCacheKey& text, sp<TextLayoutValue>& desc); sp<TextLayoutValue> getValue(const SkPaint* paint, const jchar* text, jint start, - jint count, jint contextCount, jint dirFlags); + jint count, jint contextCount); /** * Clear the cache @@ -305,7 +304,7 @@ public: * the call. Be careful of this when doing optimization. **/ sp<TextLayoutValue> getValue(const SkPaint* paint, const jchar* text, jint start, - jint count, jint contextCount, jint dirFlags); + jint count, jint contextCount); void purgeCaches(); |