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

Commit 18c9aa3e authored by Seigo Nonaka's avatar Seigo Nonaka
Browse files

Add Canvas.drawTextRun(MeasuredText)

This API is needed to port PrecomputedText in support library.

Bug: 112327179
Test: atest CtsWidgetTestCases
Test: atest CtsGraphicsTestCases
Test: atest CtsTextTestCases
Change-Id: Ib3aa4cc9e486bdcf6e4cbbfa75c0d2cf6960e982
parent ce871128
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -13533,6 +13533,7 @@ package android.graphics {
    method public void drawTextOnPath(java.lang.String, android.graphics.Path, float, float, android.graphics.Paint);
    method public void drawTextRun(char[], int, int, int, int, float, float, boolean, android.graphics.Paint);
    method public void drawTextRun(java.lang.CharSequence, int, int, int, int, float, float, boolean, android.graphics.Paint);
    method public void drawTextRun(android.graphics.text.MeasuredText, int, int, int, int, float, float, boolean, android.graphics.Paint);
    method public void drawVertices(android.graphics.Canvas.VertexMode, int, float[], int, float[], int, int[], int, short[], int, int, android.graphics.Paint);
    method public void enableZ();
    method public boolean getClipBounds(android.graphics.Rect);
+15 −8
Original line number Diff line number Diff line
@@ -22,6 +22,7 @@ import android.annotation.Nullable;
import android.annotation.Size;
import android.annotation.UnsupportedAppUsage;
import android.graphics.Canvas.VertexMode;
import android.graphics.text.MeasuredText;
import android.text.GraphicsOperations;
import android.text.MeasuredParagraph;
import android.text.PrecomputedText;
@@ -542,14 +543,12 @@ public abstract class BaseCanvas {
                    final int paraStart = pt.getParagraphStart(paraIndex);
                    final MeasuredParagraph mp = pt.getMeasuredParagraph(paraIndex);
                    // Only support the text in the same paragraph.
                    nDrawTextRun(mNativeCanvasWrapper,
                            mp.getChars(),
                    drawTextRun(mp.getMeasuredText(),
                                start - paraStart,
                            end - start,
                                end - paraStart,
                                contextStart - paraStart,
                            contextEnd - contextStart,
                            x, y, isRtl, paint.getNativeInstance(),
                            mp.getMeasuredText().getNativePtr());
                                contextEnd - paraStart,
                                x, y, isRtl, paint);
                    return;
                }
            }
@@ -564,6 +563,14 @@ public abstract class BaseCanvas {
        }
    }

    public void drawTextRun(@NonNull MeasuredText measuredText, int start, int end,
            int contextStart, int contextEnd, float x, float y, boolean isRtl,
            @NonNull Paint paint) {
        nDrawTextRun(mNativeCanvasWrapper, measuredText.getChars(), start, end - start,
                contextStart, contextEnd - contextStart, x, y, isRtl, paint.getNativeInstance(),
                measuredText.getNativePtr());
    }

    public void drawVertices(@NonNull VertexMode mode, int vertexCount, @NonNull float[] verts,
            int vertOffset, @Nullable float[] texs, int texOffset, @Nullable int[] colors,
            int colorOffset, @Nullable short[] indices, int indexOffset, int indexCount,
+14 −6
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@ import android.annotation.ColorInt;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.Size;
import android.graphics.text.MeasuredText;
import android.text.GraphicsOperations;
import android.text.MeasuredParagraph;
import android.text.PrecomputedText;
@@ -513,14 +514,12 @@ public class BaseRecordingCanvas extends Canvas {
                    final int paraStart = pt.getParagraphStart(paraIndex);
                    final MeasuredParagraph mp = pt.getMeasuredParagraph(paraIndex);
                    // Only support if the target is in the same paragraph.
                    nDrawTextRun(mNativeCanvasWrapper,
                            mp.getChars(),
                    drawTextRun(mp.getMeasuredText(),
                            start - paraStart,
                            end - start,
                            end - paraStart,
                            contextStart - paraStart,
                            contextEnd - contextStart,
                            x, y, isRtl, paint.getNativeInstance(),
                            mp.getMeasuredText().getNativePtr());
                            contextEnd - paraStart,
                            x, y, isRtl, paint);
                    return;
                }
            }
@@ -535,6 +534,15 @@ public class BaseRecordingCanvas extends Canvas {
        }
    }

    @Override
    public void drawTextRun(@NonNull MeasuredText measuredText, int start, int end,
            int contextStart, int contextEnd, float x, float y, boolean isRtl,
            @NonNull Paint paint) {
        nDrawTextRun(mNativeCanvasWrapper, measuredText.getChars(), start, end - start,
                contextStart, contextEnd - contextStart, x, y, isRtl, paint.getNativeInstance(),
                measuredText.getNativePtr());
    }

    @Override
    public final void drawVertices(@NonNull VertexMode mode, int vertexCount,
            @NonNull float[] verts, int vertOffset, @Nullable float[] texs, int texOffset,
+28 −1
Original line number Diff line number Diff line
@@ -22,6 +22,7 @@ import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.Size;
import android.annotation.UnsupportedAppUsage;
import android.graphics.text.MeasuredText;
import android.os.Build;

import dalvik.annotation.optimization.CriticalNative;
@@ -2106,7 +2107,8 @@ public class Canvas extends BaseCanvas {
     * the text next to it.
     * <p>
     * All text outside the range {@code contextStart..contextEnd} is ignored. The text between
     * {@code start} and {@code end} will be laid out and drawn.
     * {@code start} and {@code end} will be laid out and drawn. The context range is useful for
     * contextual shaping, e.g. Kerning, Arabic contextural form.
     * <p>
     * The direction of the run is explicitly specified by {@code isRtl}. Thus, this method is
     * suitable only for runs of a single direction. Alignment of the text is as determined by the
@@ -2134,6 +2136,31 @@ public class Canvas extends BaseCanvas {
        super.drawTextRun(text, start, end, contextStart, contextEnd, x, y, isRtl, paint);
    }

    /**
     * Draw a run of text, all in a single direction, with optional context for complex text
     * shaping.
     * <p>
     * See {@link #drawTextRun(CharSequence, int, int, int, int, float, float, boolean, Paint)} for
     * more details. This method uses a {@link MeasuredText} rather than CharSequence to represent
     * the string.
     *
     * @param text the text to render
     * @param start the start of the text to render. Data before this position can be used for
     *            shaping context.
     * @param end the end of the text to render. Data at or after this position can be used for
     *            shaping context.
     * @param contextStart the index of the start of the shaping context
     * @param contextEnd the index of the end of the shaping context
     * @param x the x position at which to draw the text
     * @param y the y position at which to draw the text
     * @param isRtl whether the run is in RTL direction
     * @param paint the paint
     */
    public void drawTextRun(@NonNull MeasuredText text, int start, int end, int contextStart,
            int contextEnd, float x, float y, boolean isRtl, @NonNull Paint paint) {
        super.drawTextRun(text, start, end, contextStart, contextEnd, x, y, isRtl, paint);
    }

    /**
     * Draw the array of vertices, interpreted as triangles (based on mode). The verts array is
     * required, and specifies the x,y pairs for each vertex. If texs is non-null, then it is used