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

Commit 9901bda2 authored by Eyad Aboulouz's avatar Eyad Aboulouz
Browse files

RTL bug fixes:

1) LTR text followed by RTL could become accidently reversed if the LTR text
contains a nuetral character, such as a symbol
Examples: http://www.test.com RTL -> com.test.www://http RTL

2) Fixes an issue where (LTR) RTL -> RTL (LTR)  (i.e. the left-to-right is positioned
incorrectly)

3) Fixes an issue where RTL 2001 -> RTL 1002  (i.e. digits reversed)

Change-Id: I5baa3cd3afdf19b681f83dbde90fd132ab1d15dd
parent 338dd9dd
Loading
Loading
Loading
Loading
+2 −6
Original line number Diff line number Diff line
@@ -740,8 +740,7 @@ extends Layout
            // add condition if the separator is a space
            else if (isSpace && prev != SOR &&
                            (   next == Character.DIRECTIONALITY_EUROPEAN_NUMBER
                             || next == Character.DIRECTIONALITY_ARABIC_NUMBER
                             || next == Character.DIRECTIONALITY_OTHER_NEUTRALS) ) {
                             || next == Character.DIRECTIONALITY_ARABIC_NUMBER  ) ) {
                chInfo[j] = SOR;
                for (int k=j+1; k < n; ++k) {
                    if (chInfo[k] == Character.DIRECTIONALITY_LEFT_TO_RIGHT) {
@@ -827,8 +826,6 @@ extends Layout
            } else if (d == Character.DIRECTIONALITY_EUROPEAN_NUMBER ||
                       d == Character.DIRECTIONALITY_ARABIC_NUMBER) {
                cur = Character.DIRECTIONALITY_LEFT_TO_RIGHT;
            } else if (d == Character.DIRECTIONALITY_OTHER_NEUTRALS) {
               chInfo[j] = cur = SOR;
            } else {
                byte dd = SOR;
                int k;
@@ -837,8 +834,7 @@ extends Layout
                    dd = chInfo[k];

                    if (dd == Character.DIRECTIONALITY_LEFT_TO_RIGHT ||
                        dd == Character.DIRECTIONALITY_RIGHT_TO_LEFT ||
                        dd == Character.DIRECTIONALITY_OTHER_NEUTRALS) {
                        dd == Character.DIRECTIONALITY_RIGHT_TO_LEFT) {
                        break;
                    }
                    if (dd == Character.DIRECTIONALITY_EUROPEAN_NUMBER ||
+4 −3
Original line number Diff line number Diff line
@@ -91,7 +91,7 @@ public class Styled
                if (TextUtils.hasRTLCharacters(text,start,end))
                    tmp = text.subSequence(start,end);
                else // otherwise we need to reverse it here:
                    tmp = TextUtils.getReverse(text, start, end);
                    tmp = TextUtils.getMirror(text, start, end);

                tmpstart = 0;
                // XXX: assumes getReverse doesn't change the length of the text
@@ -263,7 +263,8 @@ public class Styled
                if (TextUtils.hasRTLCharacters(text,start,end))
                    tmp = text.subSequence(start,end);
                else // otherwise we need to reverse it here:
                    tmp = TextUtils.getReverse(text, start, end);
                    tmp = TextUtils.getMirror(text, start, end);

                // XXX: this assumes getReverse doesn't tweak the length of
                // the text
                int tmpend = end - start;
+45 −1
Original line number Diff line number Diff line
@@ -534,6 +534,50 @@ public class TextUtils {
        private int mEnd;
    }

    public static CharSequence getMirror(CharSequence source,
                                          int start, int end) {
        return new Mirrorer(source, start, end);
    }

    private static class Mirrorer
    implements CharSequence, GetChars
    {
        public Mirrorer(CharSequence source, int start, int end) {
            mSource = source;
            mStart = start;
            mEnd = end;
        }

        public int length() {
            return mEnd - mStart;
        }

        public CharSequence subSequence(int start, int end) {
            char[] buf = new char[end - start];

            getChars(start, end, buf, 0);
            return new String(buf);
        }

        public String toString() {
            return subSequence(0, length()).toString();
        }

        public char charAt(int off) {
            return AndroidCharacter.getMirror(mSource.charAt(mEnd - 1 - off));
        }

        public void getChars(int start, int end, char[] dest, int destoff) {
            TextUtils.getChars(mSource, start + mStart, end + mStart,
                               dest, destoff);
            AndroidCharacter.mirror(dest, 0, end - start);
        }

        private CharSequence mSource;
        private int mStart;
        private int mEnd;
    }

    /** @hide */
    public static final int ALIGNMENT_SPAN = 1;
    /** @hide */
+0 −2
Original line number Diff line number Diff line
@@ -73,8 +73,6 @@ static jint reorderReshapeBidiText (JNIEnv* env, jclass c, jcharArray srcArray,

    UBiDi *para = ubidi_openSized(n, 0, &status);

    ubidi_setReorderingMode(para, UBIDI_REORDER_INVERSE_LIKE_DIRECT);

    jchar* src = env->GetCharArrayElements(srcArray, NULL);

    if (src != NULL && para != NULL && U_SUCCESS(status)) {