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

Commit cb5499c8 authored by Raph Levien's avatar Raph Levien
Browse files

Use getRunAdvance to position cursor

TextLine used to use getTextRunAdvances on a substring to compute a
cursor position, but this had a number of problems, especially when
the substring is a wider than the full string (as can happen in
certain Tamil ligatures).

This patch changes the implementation to use getRunAdvance, which was
explicitly designed for this use case.

We should also change Layout.getHorizontal to use the dual
getOffsetForAdvance, but that's basically a performance optimization,
the functionality should be basically equivalent.

Bug: 21125816
Change-Id: I669b85eaecfbf6f7aa6c6a9dddbf1a210eb94571
parent f981ea95
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -1121,6 +1121,7 @@ public abstract class Layout {
     * closest to the specified horizontal position.
     */
    public int getOffsetForHorizontal(int line, float horiz) {
        // TODO: use Paint.getOffsetForAdvance to avoid binary search
        int max = getLineEnd(line) - 1;
        int min = getLineStart(line);
        Directions dirs = getLineDirections(line);
+4 −6
Original line number Diff line number Diff line
@@ -739,16 +739,14 @@ class TextLine {

        float ret = 0;

        int contextLen = contextEnd - contextStart;
        if (needWidth || (c != null && (wp.bgColor != 0 || wp.underlineColor != 0 || runIsRtl))) {
            if (mCharsValid) {
                ret = wp.getTextRunAdvances(mChars, start, runLen,
                        contextStart, contextLen, runIsRtl, null, 0);
                ret = wp.getRunAdvance(mChars, start, contextEnd, contextStart, contextEnd,
                        runIsRtl, end);
            } else {
                int delta = mStart;
                ret = wp.getTextRunAdvances(mText, delta + start,
                        delta + end, delta + contextStart, delta + contextEnd,
                        runIsRtl, null, 0);
                ret = wp.getRunAdvance(mText, delta + start, delta + contextEnd,
                        delta + contextStart, delta + contextEnd, runIsRtl, delta + end);
            }
        }