Fix bug #8437358 Clean any ICU related code from TextLayout / Paint and their dependencies
- remove the ICU related methods and update the methods using the "reserved" argument
- update to CTS in another CL too
Change-Id: I5509736568c342d9d17bfeafc17951117ab5d3cc
diff --git a/core/java/android/text/GraphicsOperations.java b/core/java/android/text/GraphicsOperations.java
index 831ccc5..d426d124 100644
--- a/core/java/android/text/GraphicsOperations.java
+++ b/core/java/android/text/GraphicsOperations.java
@@ -58,13 +58,6 @@
int flags, float[] advances, int advancesIndex, Paint paint);
/**
- * Just like {@link Paint#getTextRunAdvances}.
- * @hide
- */
- float getTextRunAdvances(int start, int end, int contextStart, int contextEnd,
- int flags, float[] advances, int advancesIndex, Paint paint, int reserved);
-
- /**
* Just like {@link Paint#getTextRunCursor}.
* @hide
*/
diff --git a/core/java/android/text/SpannableStringBuilder.java b/core/java/android/text/SpannableStringBuilder.java
index 0f30d25..8929930 100644
--- a/core/java/android/text/SpannableStringBuilder.java
+++ b/core/java/android/text/SpannableStringBuilder.java
@@ -1226,35 +1226,6 @@
}
/**
- * Don't call this yourself -- exists for Paint to use internally.
- * {@hide}
- */
- public float getTextRunAdvances(int start, int end, int contextStart, int contextEnd, int flags,
- float[] advances, int advancesPos, Paint p, int reserved) {
-
- float ret;
-
- int contextLen = contextEnd - contextStart;
- int len = end - start;
-
- if (end <= mGapStart) {
- ret = p.getTextRunAdvances(mText, start, len, contextStart, contextLen,
- flags, advances, advancesPos, reserved);
- } else if (start >= mGapStart) {
- ret = p.getTextRunAdvances(mText, start + mGapLength, len,
- contextStart + mGapLength, contextLen, flags, advances, advancesPos, reserved);
- } else {
- char[] buf = TextUtils.obtain(contextLen);
- getChars(contextStart, contextEnd, buf, 0);
- ret = p.getTextRunAdvances(buf, start - contextStart, len,
- 0, contextLen, flags, advances, advancesPos, reserved);
- TextUtils.recycle(buf);
- }
-
- return ret;
- }
-
- /**
* Returns the next cursor position in the run. This avoids placing the cursor between
* surrogates, between characters that form conjuncts, between base characters and combining
* marks, or within a reordering cluster.
diff --git a/core/java/android/widget/TextView.java b/core/java/android/widget/TextView.java
index b084ac4..bd0024b 100644
--- a/core/java/android/widget/TextView.java
+++ b/core/java/android/widget/TextView.java
@@ -8838,16 +8838,6 @@
advancesIndex);
}
- public float getTextRunAdvances(int start, int end, int contextStart,
- int contextEnd, int flags, float[] advances, int advancesIndex,
- Paint p, int reserved) {
- int count = end - start;
- int contextCount = contextEnd - contextStart;
- return p.getTextRunAdvances(mChars, start + mStart, count,
- contextStart + mStart, contextCount, flags, advances,
- advancesIndex, reserved);
- }
-
public int getTextRunCursor(int contextStart, int contextEnd, int flags,
int offset, int cursorOpt, Paint p) {
int contextCount = contextEnd - contextStart;
diff --git a/core/jni/android/graphics/Paint.cpp b/core/jni/android/graphics/Paint.cpp
index 29a36de..90161fd 100644
--- a/core/jni/android/graphics/Paint.cpp
+++ b/core/jni/android/graphics/Paint.cpp
@@ -566,61 +566,23 @@
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___CIIIII_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) {
+ jint flags, 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, flags, advances, advancesIndex);
env->ReleaseCharArrayElements(text, textArray, JNI_ABORT);
return result;
}
- static float getTextRunAdvances__StringIIIII_FII(JNIEnv* env, jobject clazz, SkPaint* paint,
+ static float getTextRunAdvances__StringIIIII_FI(JNIEnv* env, jobject clazz, SkPaint* paint,
jstring text, jint start, jint end, jint contextStart, jint contextEnd, jint flags,
- jfloatArray advances, jint advancesIndex, jint reserved) {
+ 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, flags,
+ advances, advancesIndex);
env->ReleaseStringChars(text, textArray);
return result;
}
@@ -886,10 +848,10 @@
{"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_getTextRunAdvances","(I[CIIIII[FI)F",
+ (void*) SkPaintGlue::getTextRunAdvances___CIIIII_FI},
+ {"native_getTextRunAdvances","(ILjava/lang/String;IIIII[FI)F",
+ (void*) SkPaintGlue::getTextRunAdvances__StringIIIII_FI},
{"native_getTextGlyphs","(ILjava/lang/String;IIIII[C)I",
diff --git a/core/jni/android/graphics/TextLayout.cpp b/core/jni/android/graphics/TextLayout.cpp
index 2beedad..34dc3e8 100644
--- a/core/jni/android/graphics/TextLayout.cpp
+++ b/core/jni/android/graphics/TextLayout.cpp
@@ -80,14 +80,6 @@
}
}
-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);
@@ -111,73 +103,4 @@
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..d58c692 100644
--- a/core/jni/android/graphics/TextLayout.h
+++ b/core/jni/android/graphics/TextLayout.h
@@ -66,10 +66,6 @@
jint count, jint contextCount, jint dirFlags,
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);
@@ -82,9 +78,5 @@
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);
};
} // namespace android