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

Commit f18fadb7 authored by Seigo Nonaka's avatar Seigo Nonaka Committed by Android (Google) Code Review
Browse files

Merge "Move maximum weight constant from Typeface to Font and make it public"

parents 3005995a a8fab8ac
Loading
Loading
Loading
Loading
+2 −0
Original line number Original line Diff line number Diff line
@@ -15244,7 +15244,9 @@ package android.graphics.fonts {
    field public static final int FONT_WEIGHT_EXTRA_BOLD = 800; // 0x320
    field public static final int FONT_WEIGHT_EXTRA_BOLD = 800; // 0x320
    field public static final int FONT_WEIGHT_EXTRA_LIGHT = 200; // 0xc8
    field public static final int FONT_WEIGHT_EXTRA_LIGHT = 200; // 0xc8
    field public static final int FONT_WEIGHT_LIGHT = 300; // 0x12c
    field public static final int FONT_WEIGHT_LIGHT = 300; // 0x12c
    field public static final int FONT_WEIGHT_MAX = 1000; // 0x3e8
    field public static final int FONT_WEIGHT_MEDIUM = 500; // 0x1f4
    field public static final int FONT_WEIGHT_MEDIUM = 500; // 0x1f4
    field public static final int FONT_WEIGHT_MIN = 1; // 0x1
    field public static final int FONT_WEIGHT_NORMAL = 400; // 0x190
    field public static final int FONT_WEIGHT_NORMAL = 400; // 0x190
    field public static final int FONT_WEIGHT_SEMI_BOLD = 600; // 0x258
    field public static final int FONT_WEIGHT_SEMI_BOLD = 600; // 0x258
    field public static final int FONT_WEIGHT_THIN = 100; // 0x64
    field public static final int FONT_WEIGHT_THIN = 100; // 0x64
+4 −3
Original line number Original line Diff line number Diff line
@@ -63,6 +63,7 @@ import android.graphics.Rect;
import android.graphics.RectF;
import android.graphics.RectF;
import android.graphics.Typeface;
import android.graphics.Typeface;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.Drawable;
import android.graphics.fonts.Font;
import android.graphics.fonts.FontVariationAxis;
import android.graphics.fonts.FontVariationAxis;
import android.icu.text.DecimalFormatSymbols;
import android.icu.text.DecimalFormatSymbols;
import android.os.AsyncTask;
import android.os.AsyncTask;
@@ -2068,7 +2069,7 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
     */
     */
    private void setTypefaceFromAttrs(@Nullable Typeface typeface, @Nullable String familyName,
    private void setTypefaceFromAttrs(@Nullable Typeface typeface, @Nullable String familyName,
            @XMLTypefaceAttr int typefaceIndex, @Typeface.Style int style,
            @XMLTypefaceAttr int typefaceIndex, @Typeface.Style int style,
            @IntRange(from = -1, to = Typeface.MAX_WEIGHT) int weight) {
            @IntRange(from = -1, to = Font.FONT_WEIGHT_MAX) int weight) {
        if (typeface == null && familyName != null) {
        if (typeface == null && familyName != null) {
            // Lookup normal Typeface from system font map.
            // Lookup normal Typeface from system font map.
            final Typeface normalTypeface = Typeface.create(familyName, Typeface.NORMAL);
            final Typeface normalTypeface = Typeface.create(familyName, Typeface.NORMAL);
@@ -2095,9 +2096,9 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
    }
    }


    private void resolveStyleAndSetTypeface(@NonNull Typeface typeface, @Typeface.Style int style,
    private void resolveStyleAndSetTypeface(@NonNull Typeface typeface, @Typeface.Style int style,
            @IntRange(from = -1, to = Typeface.MAX_WEIGHT) int weight) {
            @IntRange(from = -1, to = Font.FONT_WEIGHT_MAX) int weight) {
        if (weight >= 0) {
        if (weight >= 0) {
            weight = Math.min(Typeface.MAX_WEIGHT, weight);
            weight = Math.min(Font.FONT_WEIGHT_MAX, weight);
            final boolean italic = (style & Typeface.ITALIC) != 0;
            final boolean italic = (style & Typeface.ITALIC) != 0;
            setTypeface(Typeface.create(typeface, weight, italic));
            setTypeface(Typeface.create(typeface, weight, italic));
        } else {
        } else {
+1 −7
Original line number Original line Diff line number Diff line
@@ -148,13 +148,7 @@ public class Typeface {
    @UnsupportedAppUsage
    @UnsupportedAppUsage
    private @Style int mStyle = 0;
    private @Style int mStyle = 0;


    /**
    private @IntRange(from = 0, to = android.graphics.fonts.Font.FONT_WEIGHT_MAX) int mWeight = 0;
     * A maximum value for the weight value.
     * @hide
     */
    public static final int MAX_WEIGHT = 1000;

    private @IntRange(from = 0, to = MAX_WEIGHT) int mWeight = 0;


    // Value for weight and italic. Indicates the value is resolved by font metadata.
    // Value for weight and italic. Indicates the value is resolved by font metadata.
    // Must be the same as the C++ constant in core/jni/android/graphics/FontFamily.cpp
    // Must be the same as the C++ constant in core/jni/android/graphics/FontFamily.cpp
+14 −2
Original line number Original line Diff line number Diff line
@@ -50,6 +50,11 @@ public final class Font {
    private static final int STYLE_ITALIC = 1;
    private static final int STYLE_ITALIC = 1;
    private static final int STYLE_NORMAL = 0;
    private static final int STYLE_NORMAL = 0;


    /**
     * A minimum weight value for the font
     */
    public static final int FONT_WEIGHT_MIN = 1;

    /**
    /**
     * A font weight value for the thin weight
     * A font weight value for the thin weight
     */
     */
@@ -95,6 +100,11 @@ public final class Font {
     */
     */
    public static final int FONT_WEIGHT_BLACK = 900;
    public static final int FONT_WEIGHT_BLACK = 900;


    /**
     * A maximum weight value for the font
     */
    public static final int FONT_WEIGHT_MAX = 1000;

    /**
    /**
     * A builder class for creating new Font.
     * A builder class for creating new Font.
     */
     */
@@ -322,8 +332,9 @@ public final class Font {
         * @param weight a weight value
         * @param weight a weight value
         * @return this builder
         * @return this builder
         */
         */
        public @NonNull Builder setWeight(@IntRange(from = 1, to = 1000) int weight) {
        public @NonNull Builder setWeight(
            Preconditions.checkArgument(1 <= weight && weight <= 1000);
                @IntRange(from = FONT_WEIGHT_MIN, to = FONT_WEIGHT_MAX) int weight) {
            Preconditions.checkArgument(FONT_WEIGHT_MIN <= weight && weight <= FONT_WEIGHT_MAX);
            mWeight = weight;
            mWeight = weight;
            return this;
            return this;
        }
        }
@@ -403,6 +414,7 @@ public final class Font {
                    mItalic = STYLE_NORMAL;
                    mItalic = STYLE_NORMAL;
                }
                }
            }
            }
            mWeight = Math.max(FONT_WEIGHT_MIN, Math.min(FONT_WEIGHT_MAX, mWeight));
            final boolean italic = (mItalic == STYLE_ITALIC);
            final boolean italic = (mItalic == STYLE_ITALIC);
            final long builderPtr = nInitBuilder();
            final long builderPtr = nInitBuilder();
            if (mAxes != null) {
            if (mAxes != null) {