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

Commit 4798c445 authored by Anish Athalye's avatar Anish Athalye Committed by Android (Google) Code Review
Browse files

Merge "Make LeadingMarginSpan2 behavior more consistent" into lmp-dev

parents 8599a335 ab08c6d3
Loading
Loading
Loading
Loading
+22 −13
Original line number Diff line number Diff line
@@ -273,16 +273,22 @@ public abstract class Layout {
                // Draw all leading margin spans.  Adjust left or right according
                // to the paragraph direction of the line.
                final int length = spans.length;
                boolean useFirstLineMargin = isFirstParaLine;
                for (int n = 0; n < length; n++) {
                    if (spans[n] instanceof LeadingMarginSpan2) {
                        int count = ((LeadingMarginSpan2) spans[n]).getLeadingMarginLineCount();
                        int startLine = getLineForOffset(sp.getSpanStart(spans[n]));
                        // if there is more than one LeadingMarginSpan2, use
                        // the count that is greatest
                        if (i < startLine + count) {
                            useFirstLineMargin = true;
                            break;
                        }
                    }
                }
                for (int n = 0; n < length; n++) {
                    if (spans[n] instanceof LeadingMarginSpan) {
                        LeadingMarginSpan margin = (LeadingMarginSpan) spans[n];
                        boolean useFirstLineMargin = isFirstParaLine;
                        if (margin instanceof LeadingMarginSpan2) {
                            int count = ((LeadingMarginSpan2) margin).getLeadingMarginLineCount();
                            int startLine = getLineForOffset(sp.getSpanStart(margin));
                            useFirstLineMargin = i < startLine + count;
                        }

                        if (dir == DIR_RIGHT_TO_LEFT) {
                            margin.drawLeadingMargin(canvas, paint, right, dir, ltop,
                                                     lbaseline, lbottom, buf,
@@ -1535,15 +1541,18 @@ public abstract class Layout {
        boolean isFirstParaLine = lineStart == 0 ||
            spanned.charAt(lineStart - 1) == '\n';

        for (int i = 0; i < spans.length; i++) {
            LeadingMarginSpan span = spans[i];
        boolean useFirstLineMargin = isFirstParaLine;
            if (span instanceof LeadingMarginSpan2) {
                int spStart = spanned.getSpanStart(span);
        for (int i = 0; i < spans.length; i++) {
            if (spans[i] instanceof LeadingMarginSpan2) {
                int spStart = spanned.getSpanStart(spans[i]);
                int spanLine = getLineForOffset(spStart);
                int count = ((LeadingMarginSpan2)span).getLeadingMarginLineCount();
                useFirstLineMargin = line < spanLine + count;
                int count = ((LeadingMarginSpan2) spans[i]).getLeadingMarginLineCount();
                // if there is more than one LeadingMarginSpan2, use the count that is greatest
                useFirstLineMargin |= line < spanLine + count;
            }
        }
        for (int i = 0; i < spans.length; i++) {
            LeadingMarginSpan span = spans[i];
            margin += span.getLeadingMargin(useFirstLineMargin);
        }

+3 −4
Original line number Diff line number Diff line
@@ -201,13 +201,12 @@ public class StaticLayout extends Layout {
                    restWidth -= sp[i].getLeadingMargin(false);

                    // LeadingMarginSpan2 is odd.  The count affects all
                    // leading margin spans, not just this particular one,
                    // and start from the top of the span, not the top of the
                    // paragraph.
                    // leading margin spans, not just this particular one
                    if (lms instanceof LeadingMarginSpan2) {
                        LeadingMarginSpan2 lms2 = (LeadingMarginSpan2) lms;
                        int lmsFirstLine = getLineForOffset(spanned.getSpanStart(lms2));
                        firstWidthLineLimit = lmsFirstLine + lms2.getLeadingMarginLineCount();
                        firstWidthLineLimit = Math.max(firstWidthLineLimit,
                                lmsFirstLine + lms2.getLeadingMarginLineCount());
                    }
                }

+15 −8
Original line number Diff line number Diff line
@@ -28,6 +28,9 @@ import android.text.TextUtils;
 * margin spans on a single paragraph; they will be rendered in order, each
 * adding its margin to the ones before it. The leading margin is on the right
 * for lines in a right-to-left paragraph.
 * <p>
 * LeadingMarginSpans should be attached from the first character to the last
 * character of a single paragraph.
 */
public interface LeadingMarginSpan
extends ParagraphStyle
@@ -69,18 +72,22 @@ extends ParagraphStyle


    /**
     * An extended version of {@link LeadingMarginSpan}, which allows
     * the implementor to specify the number of lines of text to which
     * this object is attached that the "first line of paragraph" margin
     * width will be applied to.
     * An extended version of {@link LeadingMarginSpan}, which allows the
     * implementor to specify the number of lines of the paragraph to which
     * this object is attached that the "first line of paragraph" margin width
     * will be applied to.
     * <p>
     * There should only be one LeadingMarginSpan2 per paragraph. The leading
     * margin line count affects all LeadingMarginSpans in the paragraph,
     * adjusting the number of lines to which the first line margin is applied.
     * <p>
     * As with LeadingMarginSpans, LeadingMarginSpan2s should be attached from
     * the beginning to the end of a paragraph.
     */
    public interface LeadingMarginSpan2 extends LeadingMarginSpan, WrapTogetherSpan {
        /**
         * Returns the number of lines of text to which this object is
         * Returns the number of lines of the paragraph to which this object is
         * attached that the "first line" margin will apply to.
         * Note that if this returns N, the first N lines of the region,
         * not the first N lines of each paragraph, will be given the
         * special margin width.
         */
        public int getLeadingMarginLineCount();
    };