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

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

Change TabStop type from int to float

This is from API council feedback.

Bug: 124794899
Test: atest CtsTextTestCases
Test: atest CtsGraphicsTestCases
Change-Id: Ifa95f87067239cca9c0791bf079045e4f645c3ad
parent 36ad7638
Loading
Loading
Loading
Loading
+3 −3
Original line number Diff line number Diff line
@@ -15914,13 +15914,13 @@ package android.graphics.text {
  public static class LineBreaker.ParagraphConstraints {
    ctor public LineBreaker.ParagraphConstraints();
    method @Px @IntRange(from=0) public int getDefaultTabStop();
    method @Px @FloatRange(from=0) public float getDefaultTabStop();
    method @Px @FloatRange(from=0.0f) public float getFirstWidth();
    method @Px @IntRange(from=0) public int getFirstWidthLineCount();
    method @Nullable public int[] getTabStops();
    method @Nullable public float[] getTabStops();
    method @Px @FloatRange(from=0.0f) public float getWidth();
    method public void setIndent(@Px @FloatRange(from=0.0f) float, @Px @IntRange(from=0) int);
    method public void setTabStops(@Nullable int[], @Px @IntRange(from=0) int);
    method public void setTabStops(@Nullable float[], @Px @FloatRange(from=0) float);
    method public void setWidth(@Px @FloatRange(from=0.0f) float);
  }
+14 −11
Original line number Diff line number Diff line
@@ -2180,26 +2180,26 @@ public abstract class Layout {
     */
    @VisibleForTesting(visibility = VisibleForTesting.Visibility.PACKAGE)
    public static class TabStops {
        private int[] mStops;
        private float[] mStops;
        private int mNumStops;
        private int mIncrement;
        private float mIncrement;

        public TabStops(int increment, Object[] spans) {
        public TabStops(float increment, Object[] spans) {
            reset(increment, spans);
        }

        void reset(int increment, Object[] spans) {
        void reset(float increment, Object[] spans) {
            this.mIncrement = increment;

            int ns = 0;
            if (spans != null) {
                int[] stops = this.mStops;
                float[] stops = this.mStops;
                for (Object o : spans) {
                    if (o instanceof TabStopSpan) {
                        if (stops == null) {
                            stops = new int[10];
                            stops = new float[10];
                        } else if (ns == stops.length) {
                            int[] nstops = new int[ns * 2];
                            float[] nstops = new float[ns * 2];
                            for (int i = 0; i < ns; ++i) {
                                nstops[i] = stops[i];
                            }
@@ -2221,9 +2221,9 @@ public abstract class Layout {
        float nextTab(float h) {
            int ns = this.mNumStops;
            if (ns > 0) {
                int[] stops = this.mStops;
                float[] stops = this.mStops;
                for (int i = 0; i < ns; ++i) {
                    int stop = stops[i];
                    float stop = stops[i];
                    if (stop > h) {
                        return stop;
                    }
@@ -2232,7 +2232,10 @@ public abstract class Layout {
            return nextDefaultStop(h, mIncrement);
        }

        public static float nextDefaultStop(float h, int inc) {
        /**
         * Returns the position of next tab stop.
         */
        public static float nextDefaultStop(float h, float inc) {
            return ((int) ((h + inc) / inc)) * inc;
        }
    }
@@ -2570,7 +2573,7 @@ public abstract class Layout {
        ALIGN_RIGHT,
    }

    private static final int TAB_INCREMENT = 20;
    private static final float TAB_INCREMENT = 20;

    /** @hide */
    @VisibleForTesting(visibility = VisibleForTesting.Visibility.PACKAGE)
+4 −4
Original line number Diff line number Diff line
@@ -737,14 +737,14 @@ public class StaticLayout extends Layout {
                }
            }
            // tab stop locations
            int[] variableTabStops = null;
            float[] variableTabStops = null;
            if (spanned != null) {
                TabStopSpan[] spans = getParagraphSpans(spanned, paraStart,
                        paraEnd, TabStopSpan.class);
                if (spans.length > 0) {
                    int[] stops = new int[spans.length];
                    float[] stops = new float[spans.length];
                    for (int i = 0; i < spans.length; i++) {
                        stops[i] = spans[i].getTabStop();
                        stops[i] = (float) spans[i].getTabStop();
                    }
                    Arrays.sort(stops, 0, stops.length);
                    variableTabStops = stops;
@@ -1396,7 +1396,7 @@ public class StaticLayout extends Layout {
    private static final int TAB_MASK   = 0x20000000;
    private static final int HYPHEN_MASK = 0xFF;

    private static final int TAB_INCREMENT = 20; // same as Layout, but that's private
    private static final float TAB_INCREMENT = 20; // same as Layout, but that's private

    private static final char CHAR_NEW_LINE = '\n';

+5 −5
Original line number Diff line number Diff line
@@ -80,13 +80,13 @@ static jlong nComputeLineBreaks(JNIEnv* env, jclass, jlong nativePtr,
        jfloat firstWidth,
        jint firstWidthLineCount,
        jfloat restWidth,
        jintArray variableTabStops,
        jint defaultTabStop,
        jfloatArray variableTabStops,
        jfloat defaultTabStop,
        jint indentsOffset) {
    minikin::android::StaticLayoutNative* builder = toNative(nativePtr);

    ScopedCharArrayRO text(env, javaText);
    ScopedNullableIntArrayRO tabStops(env, variableTabStops);
    ScopedNullableFloatArrayRO tabStops(env, variableTabStops);

    minikin::U16StringPiece u16Text(text.get(), length);
    minikin::MeasuredText* measuredText = reinterpret_cast<minikin::MeasuredText*>(measuredTextPtr);
@@ -151,8 +151,8 @@ static const JNINativeMethod gMethods[] = {
        "F"  // firstWidth
        "I"  // firstWidthLineCount
        "F"  // restWidth
        "[I"  // variableTabStops
        "I"  // defaultTabStop
        "[F"  // variableTabStops
        "F"  // defaultTabStop
        "I"  // indentsOffset
        ")J", (void*) nComputeLineBreaks},

+10 −10
Original line number Diff line number Diff line
@@ -248,8 +248,8 @@ public class LineBreaker {
        private @FloatRange(from = 0.0f) float mWidth = 0;
        private @FloatRange(from = 0.0f) float mFirstWidth = 0;
        private @IntRange(from = 0) int mFirstWidthLineCount = 0;
        private @Nullable int[] mVariableTabStops = null;
        private @IntRange(from = 0) int mDefaultTabStop = 0;
        private @Nullable float[] mVariableTabStops = null;
        private @FloatRange(from = 0) float mDefaultTabStop = 0;

        public ParagraphConstraints() {}

@@ -284,8 +284,8 @@ public class LineBreaker {
         * @see #getTabStops()
         * @see #getDefaultTabStop()
         */
        public void setTabStops(@Nullable int[] tabStops,
                @Px @IntRange(from = 0) int defaultTabStop) {
        public void setTabStops(@Nullable float[] tabStops,
                @Px @FloatRange(from = 0) float defaultTabStop) {
            mVariableTabStops = tabStops;
            mDefaultTabStop = defaultTabStop;
        }
@@ -320,18 +320,18 @@ public class LineBreaker {
        /**
         * Returns the array of tab stops in pixels.
         *
         * @see #setTabStops(int[], int)
         * @see #setTabStops(float[], int)
         */
        public @Nullable int[] getTabStops() {
        public @Nullable float[] getTabStops() {
            return mVariableTabStops;
        }

        /**
         * Returns the default tab stops in pixels.
         *
         * @see #setTabStop(int[], int)
         * @see #setTabStop(float[], int)
         */
        public @Px @IntRange(from = 0) int getDefaultTabStop() {
        public @Px @FloatRange(from = 0) float getDefaultTabStop() {
            return mDefaultTabStop;
        }
    }
@@ -497,8 +497,8 @@ public class LineBreaker {
            @FloatRange(from = 0.0f) float firstWidth,
            @IntRange(from = 0) int firstWidthLineCount,
            @FloatRange(from = 0.0f) float restWidth,
            @Nullable int[] variableTabStops,
            int defaultTabStop,
            @Nullable float[] variableTabStops,
            float defaultTabStop,
            @IntRange(from = 0) int indentsOffset);

    // Result accessors