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

Commit d70b2373 authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Add TestApi for verifying drawing offset" into main

parents 05020fbd d7da9b5c
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -3696,6 +3696,10 @@ package android.text {
    field @NonNull public static final android.os.Parcelable.Creator<android.text.FontConfig.NamedFamilyList> CREATOR;
  }

  public abstract class Layout {
    method @FlaggedApi("com.android.text.flags.fix_shift_drawing_amount_test_api") public void drawText(@NonNull android.graphics.Canvas, int, int, @Nullable java.util.function.BiConsumer<java.lang.Integer,java.lang.Integer>);
  }

  public class MeasuredParagraph {
    method @FlaggedApi("com.android.text.flags.no_break_no_hyphenation_span") @NonNull public static android.text.MeasuredParagraph buildForStaticLayoutTest(@NonNull android.text.TextPaint, @Nullable android.graphics.text.LineBreakConfig, @NonNull CharSequence, @IntRange(from=0) int, @IntRange(from=0) int, @NonNull android.text.TextDirectionHeuristic, int, boolean, @Nullable android.text.MeasuredParagraph.StyleRunCallback);
  }
+18 −0
Original line number Diff line number Diff line
@@ -28,6 +28,7 @@ import android.annotation.IntRange;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.SuppressLint;
import android.annotation.TestApi;
import android.compat.annotation.UnsupportedAppUsage;
import android.graphics.BlendMode;
import android.graphics.Canvas;
@@ -61,6 +62,7 @@ import java.text.BreakIterator;
import java.util.Arrays;
import java.util.List;
import java.util.Locale;
import java.util.function.BiConsumer;

/**
 * A base class that manages text layout in visual elements on
@@ -782,6 +784,16 @@ public abstract class Layout {
     */
    @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553)
    public void drawText(Canvas canvas, int firstLine, int lastLine) {
        drawText(canvas, firstLine, lastLine, null);
    }

    /**
     * @hide
     */
    @FlaggedApi(com.android.text.flags.Flags.FLAG_FIX_SHIFT_DRAWING_AMOUNT_TEST_API)
    @TestApi
    public void drawText(@NonNull Canvas canvas, int firstLine, int lastLine,
            @Nullable BiConsumer<Integer, Integer> drawOffsetCallback) {
        int previousLineBottom = getLineTop(firstLine);
        int previousLineEnd = getLineStart(firstLine);
        ParagraphStyle[] spans = NO_PARA_SPANS;
@@ -942,6 +954,9 @@ public abstract class Layout {
            if (directions == DIRS_ALL_LEFT_TO_RIGHT && !mSpannedText && !hasTab && !justify) {
                // XXX: assumes there's nothing additional to be done
                canvas.drawText(buf, start, end, x, lbaseline, paint);
                if (drawOffsetCallback != null) {
                    drawOffsetCallback.accept(x, lbaseline);
                }
            } else {
                tl.set(paint, buf, start, end, dir, directions, hasTab, tabStops,
                        getEllipsisStart(lineNum),
@@ -951,6 +966,9 @@ public abstract class Layout {
                    tl.justify(mJustificationMode, right - left - indentWidth);
                }
                tl.draw(canvas, x, ltop, lbaseline, lbottom);
                if (drawOffsetCallback != null) {
                    drawOffsetCallback.accept(x, ltop);
                }
            }
        }

+7 −0
Original line number Diff line number Diff line
@@ -263,3 +263,10 @@ flag {
  bug: "434885800"

}

flag {
  name: "fix_shift_drawing_amount_test_api"
  namespace: "text"
  description: "Fixing shift_drawing_offset_for_start_overhang that had an issue."
  bug: "434885800"
}