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

Commit 5d74b1c7 authored by Roozbeh Pournader's avatar Roozbeh Pournader
Browse files

Pass advances to Minikin for calculating getTextRunCursor

Previously, the getTextRunCursor() implementation in Minikin ignored
the font and just used the characters in the buffer in order to
determine cursor positions. Now we calculate the advances beforehand
in order to find potential Indic clusters.

Test: Manually tested some Tamil sequences
Bug: 35721792
Change-Id: I2500bd4c2c9d07bb6c965b2d41e04853886a7391
parent 64e93531
Loading
Loading
Loading
Loading
+22 −14
Original line number Original line Diff line number Diff line
@@ -239,30 +239,38 @@ namespace PaintGlue {
        return result;
        return result;
    }
    }


    static jint doTextRunCursor(JNIEnv *env, Paint* paint, const jchar *text, jint start,
    static jint doTextRunCursor(JNIEnv *env, Paint* paint, Typeface* typeface, const jchar *text,
            jint count, jint flags, jint offset, jint opt) {
            jint start, jint count, jint dir, jint offset, jint opt) {
        minikin::GraphemeBreak::MoveOpt moveOpt = minikin::GraphemeBreak::MoveOpt(opt);
        minikin::GraphemeBreak::MoveOpt moveOpt = minikin::GraphemeBreak::MoveOpt(opt);
        size_t result = minikin::GraphemeBreak::getTextRunCursor(text, start, count, offset,
        int bidiFlags = dir == 1 ? minikin::kBidi_Force_RTL : minikin::kBidi_Force_LTR;
                moveOpt);
        std::unique_ptr<float[]> advancesArray(new float[count]);
        MinikinUtils::measureText(paint, bidiFlags, typeface, text, start, count, start + count,
                advancesArray.get());
        size_t result = minikin::GraphemeBreak::getTextRunCursor(advancesArray.get(), text,
                start, count, offset, moveOpt);
        return static_cast<jint>(result);
        return static_cast<jint>(result);
    }
    }


    static jint getTextRunCursor___C(JNIEnv* env, jobject clazz, jlong paintHandle, jcharArray text,
    static jint getTextRunCursor___C(JNIEnv* env, jobject clazz, jlong paintHandle,
            jint contextStart, jint contextCount, jint dir, jint offset, jint cursorOpt) {
            jlong typefaceHandle, jcharArray text, jint contextStart, jint contextCount, jint dir,
            jint offset, jint cursorOpt) {
        Paint* paint = reinterpret_cast<Paint*>(paintHandle);
        Paint* paint = reinterpret_cast<Paint*>(paintHandle);
        Typeface* typeface = reinterpret_cast<Typeface*>(typefaceHandle);
        jchar* textArray = env->GetCharArrayElements(text, nullptr);
        jchar* textArray = env->GetCharArrayElements(text, nullptr);
        jint result = doTextRunCursor(env, paint, textArray, contextStart, contextCount, dir,
        jint result = doTextRunCursor(env, paint, typeface, textArray,
                offset, cursorOpt);
                contextStart, contextCount, dir, offset, cursorOpt);
        env->ReleaseCharArrayElements(text, textArray, JNI_ABORT);
        env->ReleaseCharArrayElements(text, textArray, JNI_ABORT);
        return result;
        return result;
    }
    }


    static jint getTextRunCursor__String(JNIEnv* env, jobject clazz, jlong paintHandle, jstring text,
    static jint getTextRunCursor__String(JNIEnv* env, jobject clazz, jlong paintHandle,
            jint contextStart, jint contextEnd, jint dir, jint offset, jint cursorOpt) {
            jlong typefaceHandle, jstring text, jint contextStart, jint contextEnd, jint dir,
            jint offset, jint cursorOpt) {
        Paint* paint = reinterpret_cast<Paint*>(paintHandle);
        Paint* paint = reinterpret_cast<Paint*>(paintHandle);
        Typeface* typeface = reinterpret_cast<Typeface*>(typefaceHandle);
        const jchar* textArray = env->GetStringChars(text, nullptr);
        const jchar* textArray = env->GetStringChars(text, nullptr);
        jint result = doTextRunCursor(env, paint, textArray, contextStart,
        jint result = doTextRunCursor(env, paint, typeface, textArray,
                contextEnd - contextStart, dir, offset, cursorOpt);
                contextStart, contextEnd - contextStart, dir, offset, cursorOpt);
        env->ReleaseStringChars(text, textArray);
        env->ReleaseStringChars(text, textArray);
        return result;
        return result;
    }
    }
@@ -983,8 +991,8 @@ static const JNINativeMethod methods[] = {
    {"nGetTextAdvances","(JJLjava/lang/String;IIIII[FI)F",
    {"nGetTextAdvances","(JJLjava/lang/String;IIIII[FI)F",
            (void*) PaintGlue::getTextAdvances__StringIIIII_FI},
            (void*) PaintGlue::getTextAdvances__StringIIIII_FI},


    {"nGetTextRunCursor", "(J[CIIIII)I", (void*) PaintGlue::getTextRunCursor___C},
    {"nGetTextRunCursor", "(JJ[CIIIII)I", (void*) PaintGlue::getTextRunCursor___C},
    {"nGetTextRunCursor", "(JLjava/lang/String;IIIII)I",
    {"nGetTextRunCursor", "(JJLjava/lang/String;IIIII)I",
            (void*) PaintGlue::getTextRunCursor__String},
            (void*) PaintGlue::getTextRunCursor__String},
    {"nGetTextPath", "(JJI[CIIFFJ)V", (void*) PaintGlue::getTextPath___C},
    {"nGetTextPath", "(JJI[CIIFFJ)V", (void*) PaintGlue::getTextPath___C},
    {"nGetTextPath", "(JJILjava/lang/String;IIFFJ)V", (void*) PaintGlue::getTextPath__String},
    {"nGetTextPath", "(JJILjava/lang/String;IIFFJ)V", (void*) PaintGlue::getTextPath__String},
+4 −4
Original line number Original line Diff line number Diff line
@@ -2294,7 +2294,7 @@ public class Paint {
            throw new IndexOutOfBoundsException();
            throw new IndexOutOfBoundsException();
        }
        }


        return nGetTextRunCursor(mNativePaint, text,
        return nGetTextRunCursor(mNativePaint, mNativeTypeface, text,
                contextStart, contextLength, dir, offset, cursorOpt);
                contextStart, contextLength, dir, offset, cursorOpt);
    }
    }


@@ -2380,7 +2380,7 @@ public class Paint {
            throw new IndexOutOfBoundsException();
            throw new IndexOutOfBoundsException();
        }
        }


        return nGetTextRunCursor(mNativePaint, text,
        return nGetTextRunCursor(mNativePaint, mNativeTypeface, text,
                contextStart, contextEnd, dir, offset, cursorOpt);
                contextStart, contextEnd, dir, offset, cursorOpt);
    }
    }


@@ -2686,9 +2686,9 @@ public class Paint {
    private static native float nGetTextAdvances(long paintPtr, long typefacePtr,
    private static native float nGetTextAdvances(long paintPtr, long typefacePtr,
            String text, int start, int end, int contextStart, int contextEnd,
            String text, int start, int end, int contextStart, int contextEnd,
            int bidiFlags, float[] advances, int advancesIndex);
            int bidiFlags, float[] advances, int advancesIndex);
    private native int nGetTextRunCursor(long paintPtr, char[] text,
    private native int nGetTextRunCursor(long paintPtr, long typefacePtr, char[] text,
            int contextStart, int contextLength, int dir, int offset, int cursorOpt);
            int contextStart, int contextLength, int dir, int offset, int cursorOpt);
    private native int nGetTextRunCursor(long paintPtr, String text,
    private native int nGetTextRunCursor(long paintPtr, long typefacePtr, String text,
            int contextStart, int contextEnd, int dir, int offset, int cursorOpt);
            int contextStart, int contextEnd, int dir, int offset, int cursorOpt);
    private static native void nGetTextPath(long paintPtr, long typefacePtr,
    private static native void nGetTextPath(long paintPtr, long typefacePtr,
            int bidiFlags, char[] text, int index, int count, float x, float y, long path);
            int bidiFlags, char[] text, int index, int count, float x, float y, long path);