Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit e9f4ab5d authored by Seigo Nonaka's avatar Seigo Nonaka
Browse files

Remove StaticLayout.addMeasuredRun

StaticLayout.addMeasuredRun is used if the TextPaint is subclassed.
However, developers can't do almost anything by subclassing TextPaint
since most of default things are done in native code. So we don't need to
support this tricky case anymore.

Bug: 65024629
Bug: 67009717
Test: bit FrameworksCoreTests:android.text.StaticLayoutLineBreakingTest
Change-Id: I290b8b7d3e1fcff7be78e4bd1e620d6c188a10ad
parent 9c99f325
Loading
Loading
Loading
Loading
+8 −22
Original line number Diff line number Diff line
@@ -165,40 +165,26 @@ class MeasuredText {
            paint.getFontMetricsInt(fm);
        }

        int p = mPos;
        final int p = mPos;
        mPos = p + len;

        // try to do widths measurement in native code, but use Java if paint has been subclassed
        // FIXME: may want to eliminate special case for subclass
        float[] widths = null;
        if (mBuilder == null || paint.getClass() != TextPaint.class) {
            widths = mWidths;
        }
        if (mEasy) {
            boolean isRtl = mDir != Layout.DIR_LEFT_TO_RIGHT;
            float width = 0;
            if (widths != null) {
                width = paint.getTextRunAdvances(mChars, p, len, p, len, isRtl, widths, p);
                if (mBuilder != null) {
                    mBuilder.addMeasuredRun(paint, p, p + len, widths);
                }
            final boolean isRtl = mDir != Layout.DIR_LEFT_TO_RIGHT;
            if (mBuilder == null) {
                return paint.getTextRunAdvances(mChars, p, len, p, len, isRtl, mWidths, p);
            } else {
                width = mBuilder.addStyleRun(paint, p, p + len, isRtl);
                return mBuilder.addStyleRun(paint, p, p + len, isRtl);
            }
            return width;
        }

        float totalAdvance = 0;
        int level = mLevels[p];
        for (int q = p, i = p + 1, e = p + len;; ++i) {
            if (i == e || mLevels[i] != level) {
                boolean isRtl = (level & 0x1) != 0;
                if (widths != null) {
                final boolean isRtl = (level & 0x1) != 0;
                if (mBuilder == null) {
                    totalAdvance +=
                            paint.getTextRunAdvances(mChars, q, i - q, q, i - q, isRtl, widths, q);
                    if (mBuilder != null) {
                        mBuilder.addMeasuredRun(paint, q, i, widths);
                    }
                            paint.getTextRunAdvances(mChars, q, i - q, q, i - q, isRtl, mWidths, q);
                } else {
                    totalAdvance += mBuilder.addStyleRun(paint, q, i, isRtl);
                }
+0 −10
Original line number Diff line number Diff line
@@ -431,7 +431,6 @@ public class StaticLayout extends Layout {
         * Then, for each run within the paragraph:
         *  - one of the following, depending on the type of run:
         *    + addStyleRun (a text run, to be measured in native code)
         *    + addMeasuredRun (a run already measured in Java, passed into native code)
         *    + addReplacementRun (a replacement run, width is given)
         *
         * After measurement, nGetWidths() is valid if the widths are needed (eg for ellipsis).
@@ -460,11 +459,6 @@ public class StaticLayout extends Layout {
                    locHyph.first, locHyph.second);
        }

        /* package */ void addMeasuredRun(TextPaint paint, int start, int end, float[] widths) {
            Pair<String, long[]> locHyph = getLocaleAndHyphenatorIfChanged(paint);
            nAddMeasuredRun(mNativePtr, start, end, widths, locHyph.first, locHyph.second);
        }

        /* package */ void addReplacementRun(TextPaint paint, int start, int end, float width) {
            Pair<String, long[]> locHyph = getLocaleAndHyphenatorIfChanged(paint);
            nAddReplacementRun(mNativePtr, start, end, width, locHyph.first, locHyph.second);
@@ -1552,10 +1546,6 @@ public class StaticLayout extends Layout {
            @IntRange(from = 0) int start, @IntRange(from = 0) int end, boolean isRtl,
            @Nullable String languageTags, @Nullable long[] hyphenators);

    private static native void nAddMeasuredRun(/* non-zero */ long nativePtr,
            @IntRange(from = 0) int start, @IntRange(from = 0) int end, @NonNull float[] widths,
            @Nullable String languageTags, @Nullable long[] hyphenators);

    private static native void nAddReplacementRun(/* non-zero */ long nativePtr,
            @IntRange(from = 0) int start, @IntRange(from = 0) int end,
            @FloatRange(from = 0.0f) float width, @Nullable String languageTags,
+0 −12
Original line number Diff line number Diff line
@@ -250,17 +250,6 @@ static jfloat nAddStyleRun(JNIEnv* env, jclass, jlong nativePtr, jlong nativePai
    return result;
}

// Accept width measurements for the run, passed in from Java
static void nAddMeasuredRun(JNIEnv* env, jclass, jlong nativePtr,
        jint start, jint end, jfloatArray widths, jstring langTags, jlongArray hyphenators) {
    minikin::LineBreaker* b = reinterpret_cast<minikin::LineBreaker*>(nativePtr);
    env->GetFloatArrayRegion(widths, start, end - start, b->charWidths() + start);

    ScopedNullableUtfString langTagsString(env, langTags);
    b->addStyleRun(nullptr, nullptr, minikin::FontStyle{}, start, end, false,
            langTagsString.get(), makeHyphenators(env, hyphenators));
}

static void nAddReplacementRun(JNIEnv* env, jclass, jlong nativePtr,
        jint start, jint end, jfloat width, jstring langTags, jlongArray hyphenators) {
    minikin::LineBreaker* b = reinterpret_cast<minikin::LineBreaker*>(nativePtr);
@@ -280,7 +269,6 @@ static const JNINativeMethod gMethods[] = {
    {"nFinishBuilder", "(J)V", (void*) nFinishBuilder},
    {"nSetupParagraph", "(J[CIFIF[IIIIZ[I[I[II)V", (void*) nSetupParagraph},
    {"nAddStyleRun", "(JJIIZLjava/lang/String;[J)F", (void*) nAddStyleRun},
    {"nAddMeasuredRun", "(JII[FLjava/lang/String;[J)V", (void*) nAddMeasuredRun},
    {"nAddReplacementRun", "(JIIFLjava/lang/String;[J)V", (void*) nAddReplacementRun},
    {"nGetWidths", "(J[F)V", (void*) nGetWidths},
    {"nComputeLineBreaks", "(JLandroid/text/StaticLayout$LineBreaks;[I[F[F[F[II)I",