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

Commit 43e45eb9 authored by Eran Mizrahi's avatar Eran Mizrahi Committed by Eyad Aboulouz
Browse files

-Adds RTL (Right-To-Left) support for all RTL languages

-Paragraphs containing RTL text are consistently aligned to the right and text is measured correctly when reshaped
-Supports reshaping (connecting) of standard Arabic letters, including Farsi, Kurdish, Turkish and Urdu
-Supports reshaping of supplement Arabic letters used in languages such as Farsi and Urdu
-Mirroring of symetric symbols such as '(' and ')' when surrouded by RTL text
-Tested by several Arabic native speakers

By Eyad Aboulouz.

Change-Id: Ifd3e24cde0c68c97245e97cf41b71c3701078e48
parent 1c2b1998
Loading
Loading
Loading
Loading
+22 −0
Original line number Diff line number Diff line
@@ -44,5 +44,27 @@ package android.text;
        return result;
    }

    /**
     * @author: Eyad Aboulouz
     * Bidi text reordering and reshaping by by calling native reorderReshapeBidiText function
     * @param chs
     * @param reshapedChs
     * @param off
     * @param len
     * @return int
     */
    public static int reorderAndReshapeBidiText(char[] chs, char[] outputChs, int off, int len) {

        if (chs == null)
            throw new NullPointerException();

        if (off < 0 || len < 0 || off + len > chs.length)
            throw new IndexOutOfBoundsException();

        return reorderReshapeBidiText(chs, outputChs, off, len);
    }

    private native static int runBidi(int dir, char[] chs, byte[] chInfo, int n, boolean haveInfo);

    private native static int reorderReshapeBidiText(char[] chs, char[] outputChs, int off, int len);
}
 No newline at end of file
+2 −2
Original line number Diff line number Diff line
@@ -366,7 +366,7 @@ public abstract class Layout {
                    Assert.assertTrue(dir == DIR_LEFT_TO_RIGHT);
                    Assert.assertNotNull(c);
                }
                c.drawText(buf, start, end, x, lbaseline, paint,false);
                c.drawText(buf, start, end, x, lbaseline, paint);
            } else {
                drawText(c, buf, start, end, dir, directions,
                    x, ltop, lbaseline, lbottom, paint, mWorkPaint,
+3 −3
Original line number Diff line number Diff line
@@ -1042,14 +1042,14 @@ implements CharSequence, GetChars, Spannable, Editable, Appendable,
        checkRange("drawText", start, end);

        if (end <= mGapStart) {
            c.drawText(mText, start, end - start, x, y, p,true);
            c.drawText(mText, start, end - start, x, y, p);
        } else if (start >= mGapStart) {
            c.drawText(mText, start + mGapLength, end - start, x, y, p,true);
            c.drawText(mText, start + mGapLength, end - start, x, y, p);
        } else {
            char[] buf = TextUtils.obtain(end - start);

            getChars(start, end, buf, 0);
            c.drawText(buf, 0, end - start, x, y, p,true);
            c.drawText(buf, 0, end - start, x, y, p);
            TextUtils.recycle(buf);
        }
    }
+6 −4
Original line number Diff line number Diff line
@@ -267,12 +267,13 @@ extends Layout
                // Do mirroring for right-to-left segments

                for (int i = 0; i < n; i++) {
                    if (chdirs[i] == Character.DIRECTIONALITY_RIGHT_TO_LEFT) {
                    if (chdirs[i] == Character.DIRECTIONALITY_RIGHT_TO_LEFT ||
                        chdirs[i] == Character.DIRECTIONALITY_RIGHT_TO_LEFT_ARABIC) {
                        int j;

                        for (j = i; j < n; j++) {
                            if (chdirs[j] !=
                                Character.DIRECTIONALITY_RIGHT_TO_LEFT)
                            if (chdirs[j] != Character.DIRECTIONALITY_RIGHT_TO_LEFT &&
                                chdirs[j] != Character.DIRECTIONALITY_RIGHT_TO_LEFT_ARABIC)
                                break;
                        }

@@ -650,7 +651,8 @@ extends Layout
            // Heuristic - LTR unless paragraph contains any RTL chars
            dir = DIR_LEFT_TO_RIGHT;
            for (int j = 0; j < n; j++) {
                if (chInfo[j] == Character.DIRECTIONALITY_RIGHT_TO_LEFT) {
                if (chInfo[j] == Character.DIRECTIONALITY_RIGHT_TO_LEFT ||
                    chInfo[j] == Character.DIRECTIONALITY_RIGHT_TO_LEFT_ARABIC) {
                    dir = DIR_RIGHT_TO_LEFT;
                    break;
                }
+41 −31
Original line number Diff line number Diff line
@@ -87,7 +87,12 @@ public class Styled
            int tmpstart, tmpend;

            if (runIsRtl) {
                // if the text has RTL characters then it will be reversed when mirrored:
                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);

                tmpstart = 0;
                // XXX: assumes getReverse doesn't change the length of the text
                tmpend = end - start;
@@ -129,7 +134,7 @@ public class Styled
                    }

                    canvas.drawText(tmp, tmpstart, tmpend,
                                    x - ret, y + workPaint.baselineShift, workPaint,false);
                                    x - ret, y + workPaint.baselineShift, workPaint);
                } else {
                    if (needWidth) {
                        if (!haveWidth) {
@@ -139,7 +144,7 @@ public class Styled
                    }

                    canvas.drawText(tmp, tmpstart, tmpend,
                                    x, y + workPaint.baselineShift, workPaint,false);
                                    x, y + workPaint.baselineShift, workPaint);
                }
            } else {
                if (needWidth && !haveWidth) {
@@ -253,7 +258,12 @@ public class Styled
            float ret = 0;

            if (runIsRtl) {
                CharSequence tmp = TextUtils.getReverse(text, start, end);
                CharSequence tmp;
                // if the text has RTL characters then it will be reversed when mirrored:
                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);
                // XXX: this assumes getReverse doesn't tweak the length of
                // the text
                int tmpend = end - start;
@@ -263,13 +273,13 @@ public class Styled

                if (canvas != null)
                    canvas.drawText(tmp, 0, tmpend,
                                    x - ret, y, paint,false);
                                    x - ret, y, paint);
            } else {
                if (needWidth)
                    ret = paint.measureText(text, start, end);

                if (canvas != null)
                    canvas.drawText(text, start, end, x, y, paint,false);
                    canvas.drawText(text, start, end, x, y, paint);
            }

            if (fmi != null) {
Loading