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

Commit 5cc9348e authored by Seigo Nonaka's avatar Seigo Nonaka
Browse files

Stop returning run width of StaticLayout.Builder.addStyleRun.

The return value of addStyleRun is not used.
By no longer returning run width, the LineBreaker can defer the
style and line breaking calculation.

Bug: 65024629
Test: bit CtsTextTestCases:*
Change-Id: I2c835ff1c58657863da12976e71007c29b1bb039
parent 4cea4304
Loading
Loading
Loading
Loading
+13 −3
Original line number Diff line number Diff line
@@ -156,6 +156,14 @@ class MeasuredText {
        }
    }

    /**
     * Apply the style.
     *
     * If StaticLyaout.Builder is not provided in setPara() method, this method measures the styled
     * text width.
     * If StaticLayout.Builder is provided in setPara() method, this method just passes the style
     * information to native code by calling StaticLayout.Builder.addstyleRun() and returns 0.
     */
    float addStyleRun(TextPaint paint, int len, Paint.FontMetricsInt fm) {
        if (fm != null) {
            paint.getFontMetricsInt(fm);
@@ -169,7 +177,8 @@ class MeasuredText {
            if (mBuilder == null) {
                return paint.getTextRunAdvances(mChars, p, len, p, len, isRtl, mWidths, p);
            } else {
                return mBuilder.addStyleRun(paint, p, p + len, isRtl);
                mBuilder.addStyleRun(paint, p, p + len, isRtl);
                return 0.0f;  // Builder.addStyleRun doesn't return the width.
            }
        }

@@ -182,7 +191,8 @@ class MeasuredText {
                    totalAdvance +=
                            paint.getTextRunAdvances(mChars, q, i - q, q, i - q, isRtl, mWidths, q);
                } else {
                    totalAdvance += mBuilder.addStyleRun(paint, q, i, isRtl);
                    // Builder.addStyleRun doesn't return the width.
                    mBuilder.addStyleRun(paint, q, i, isRtl);
                }
                if (i == e) {
                    break;
@@ -191,7 +201,7 @@ class MeasuredText {
                level = mLevels[i];
            }
        }
        return totalAdvance;
        return totalAdvance;  // If mBuilder is null, the result is zero.
    }

    float addStyleRun(TextPaint paint, MetricAffectingSpan[] spans, int len,
+4 −4
Original line number Diff line number Diff line
@@ -453,10 +453,10 @@ public class StaticLayout extends Layout {
            }
        }

        /* package */ float addStyleRun(TextPaint paint, int start, int end, boolean isRtl) {
        /* package */ void addStyleRun(TextPaint paint, int start, int end, boolean isRtl) {
            Pair<String, long[]> locHyph = getLocaleAndHyphenatorIfChanged(paint);
            return nAddStyleRun(mNativePtr, paint.getNativeInstance(), start, end, isRtl,
                    locHyph.first, locHyph.second);
            nAddStyleRun(mNativePtr, paint.getNativeInstance(), start, end, isRtl, locHyph.first,
                    locHyph.second);
        }

        /* package */ void addReplacementRun(TextPaint paint, int start, int end, float width) {
@@ -1541,7 +1541,7 @@ public class StaticLayout extends Layout {
            @Nullable int[] indents, @Nullable int[] leftPaddings, @Nullable int[] rightPaddings,
            @IntRange(from = 0) int indentsOffset);

    private static native float nAddStyleRun(
    private static native void nAddStyleRun(
            /* non-zero */ long nativePtr, /* non-zero */ long nativePaint,
            @IntRange(from = 0) int start, @IntRange(from = 0) int end, boolean isRtl,
            @Nullable String languageTags, @Nullable long[] hyphenators);
+3 −4
Original line number Diff line number Diff line
@@ -234,7 +234,7 @@ static std::vector<minikin::Hyphenator*> makeHyphenators(JNIEnv* env, jlongArray
}

// Basically similar to Paint.getTextRunAdvances but with C++ interface
static jfloat nAddStyleRun(JNIEnv* env, jclass, jlong nativePtr, jlong nativePaint, jint start,
static void nAddStyleRun(JNIEnv* env, jclass, jlong nativePtr, jlong nativePaint, jint start,
        jint end, jboolean isRtl, jstring langTags, jlongArray hyphenators) {
    minikin::LineBreaker* b = reinterpret_cast<minikin::LineBreaker*>(nativePtr);
    Paint* paint = reinterpret_cast<Paint*>(nativePaint);
@@ -245,9 +245,8 @@ static jfloat nAddStyleRun(JNIEnv* env, jclass, jlong nativePtr, jlong nativePai
            typeface);

    ScopedNullableUtfString langTagsString(env, langTags);
    float result = b->addStyleRun(&minikinPaint, resolvedTypeface->fFontCollection, style, start,
    b->addStyleRun(&minikinPaint, resolvedTypeface->fFontCollection, style, start,
            end, isRtl, langTagsString.get(), makeHyphenators(env, hyphenators));
    return result;
}

static void nAddReplacementRun(JNIEnv* env, jclass, jlong nativePtr,
@@ -268,7 +267,7 @@ static const JNINativeMethod gMethods[] = {
    {"nFreeBuilder", "(J)V", (void*) nFreeBuilder},
    {"nFinishBuilder", "(J)V", (void*) nFinishBuilder},
    {"nSetupParagraph", "(J[CIFIF[IIIIZ[I[I[II)V", (void*) nSetupParagraph},
    {"nAddStyleRun", "(JJIIZLjava/lang/String;[J)F", (void*) nAddStyleRun},
    {"nAddStyleRun", "(JJIIZLjava/lang/String;[J)V", (void*) nAddStyleRun},
    {"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",