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

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

Unhide getTextRunCursor APIs

This API is necessary for identifying the cursor locations.

Bug: 112327179
Test: atest android.graphics.cts.PaintTest
Change-Id: Ief6770bd622a296ae356094fe3ce58e9c4371088
parent 93890b2e
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -14017,6 +14017,8 @@ package android.graphics {
    method public void getTextPath(char[], int, int, float, float, android.graphics.Path);
    method public void getTextPath(java.lang.String, int, int, float, float, android.graphics.Path);
    method public float getTextRunAdvances(char[], int, int, int, int, boolean, float[], int);
    method public int getTextRunCursor(char[], int, int, boolean, int, int);
    method public int getTextRunCursor(java.lang.CharSequence, int, int, boolean, int, int);
    method public float getTextScaleX();
    method public float getTextSize();
    method public float getTextSkewX();
@@ -14083,6 +14085,11 @@ package android.graphics {
    method public void setWordSpacing(float);
    method public android.graphics.Xfermode setXfermode(android.graphics.Xfermode);
    field public static final int ANTI_ALIAS_FLAG = 1; // 0x1
    field public static final int CURSOR_AFTER = 0; // 0x0
    field public static final int CURSOR_AT = 4; // 0x4
    field public static final int CURSOR_AT_OR_AFTER = 1; // 0x1
    field public static final int CURSOR_AT_OR_BEFORE = 3; // 0x3
    field public static final int CURSOR_BEFORE = 2; // 0x2
    field public static final int DEV_KERN_TEXT_FLAG = 256; // 0x100
    field public static final int DITHER_FLAG = 4; // 0x4
    field public static final int EMBEDDED_BITMAP_TEXT_FLAG = 1024; // 0x400
+1 −1
Original line number Diff line number Diff line
@@ -58,6 +58,6 @@ public interface GraphicsOperations extends CharSequence {
    /**
     * Just like {@link Paint#getTextRunCursor}.
     */
    int getTextRunCursor(int contextStart, int contextEnd, int dir, int offset,
    int getTextRunCursor(int contextStart, int contextEnd, boolean isRtl, int offset,
            int cursorOpt, Paint p);
}
+11 −4
Original line number Diff line number Diff line
@@ -1551,7 +1551,7 @@ public class SpannableStringBuilder implements CharSequence, GetChars, Spannable
     *
     * @param contextStart the start index of the context
     * @param contextEnd the (non-inclusive) end index of the context
     * @param dir either DIRECTION_RTL or DIRECTION_LTR
     * @param dir 1 if the run is RTL, otherwise 0
     * @param offset the cursor position to move from
     * @param cursorOpt how to move the cursor, one of CURSOR_AFTER,
     * CURSOR_AT_OR_AFTER, CURSOR_BEFORE,
@@ -1563,21 +1563,28 @@ public class SpannableStringBuilder implements CharSequence, GetChars, Spannable
    @Deprecated
    public int getTextRunCursor(int contextStart, int contextEnd, int dir, int offset,
            int cursorOpt, Paint p) {
        return getTextRunCursor(contextStart, contextEnd, dir == 1, offset, cursorOpt, p);
    }

    /** @hide */
    @Override
    public int getTextRunCursor(int contextStart, int contextEnd, boolean isRtl, int offset,
            int cursorOpt, Paint p) {

        int ret;

        int contextLen = contextEnd - contextStart;
        if (contextEnd <= mGapStart) {
            ret = p.getTextRunCursor(mText, contextStart, contextLen,
                    dir, offset, cursorOpt);
                    isRtl, offset, cursorOpt);
        } else if (contextStart >= mGapStart) {
            ret = p.getTextRunCursor(mText, contextStart + mGapLength, contextLen,
                    dir, offset + mGapLength, cursorOpt) - mGapLength;
                    isRtl, offset + mGapLength, cursorOpt) - mGapLength;
        } else {
            char[] buf = TextUtils.obtain(contextLen);
            getChars(contextStart, contextEnd, buf, 0);
            ret = p.getTextRunCursor(buf, 0, contextLen,
                    dir, offset - contextStart, cursorOpt) + contextStart;
                    isRtl, offset - contextStart, cursorOpt) + contextStart;
            TextUtils.recycle(buf);
        }

+2 −3
Original line number Diff line number Diff line
@@ -802,14 +802,13 @@ public class TextLine {
            }
        }

        int dir = runIsRtl ? Paint.DIRECTION_RTL : Paint.DIRECTION_LTR;
        int cursorOpt = after ? Paint.CURSOR_AFTER : Paint.CURSOR_BEFORE;
        if (mCharsValid) {
            return wp.getTextRunCursor(mChars, spanStart, spanLimit - spanStart,
                    dir, offset, cursorOpt);
                    runIsRtl, offset, cursorOpt);
        } else {
            return wp.getTextRunCursor(mText, mStart + spanStart,
                    mStart + spanLimit, dir, mStart + offset, cursorOpt) - mStart;
                    mStart + spanLimit, runIsRtl, mStart + offset, cursorOpt) - mStart;
        }
    }

+1 −1
Original line number Diff line number Diff line
@@ -310,7 +310,7 @@ public abstract class BaseKeyListener extends MetaKeyKeyListener
            return len;
        }

        offset = paint.getTextRunCursor(text, offset, len, Paint.DIRECTION_LTR /* not used */,
        offset = paint.getTextRunCursor(text, offset, len, false /* LTR, not used */,
                offset, Paint.CURSOR_AFTER);

        return adjustReplacementSpan(text, offset, false /* move to the end */);
Loading