/* * Copyright (C) 2018 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package android.graphics.fonts; import android.annotation.IntDef; import android.annotation.IntRange; import android.annotation.NonNull; import android.annotation.Nullable; import com.android.internal.util.Preconditions; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.util.Objects; /** * A font style object. * * This class represents a single font style which is a pair of weight value and slant value. * Here are common font styles examples: *
*
*
* final FontStyle NORMAL = new FontStyle(FONT_WEIGHT_NORMAL, FONT_SLANT_UPRIGHT);
* final FontStyle BOLD = new FontStyle(FONT_WEIGHT_BOLD, FONT_SLANT_UPRIGHT);
* final FontStyle ITALIC = new FontStyle(FONT_WEIGHT_NORMAL, FONT_SLANT_ITALIC);
* final FontStyle BOLD_ITALIC = new FontStyle(FONT_WEIGHT_BOLD, FONT_SLANT_ITALIC);
*
*
*
*
*/
public final class FontStyle {
private static final String TAG = "FontStyle";
/**
* A default value when font weight is unspecified
*/
public static final int FONT_WEIGHT_UNSPECIFIED = -1;
/**
* A minimum weight value for the font
*/
public static final int FONT_WEIGHT_MIN = 1;
/**
* A font weight value for the thin weight
*/
public static final int FONT_WEIGHT_THIN = 100;
/**
* A font weight value for the extra-light weight
*/
public static final int FONT_WEIGHT_EXTRA_LIGHT = 200;
/**
* A font weight value for the light weight
*/
public static final int FONT_WEIGHT_LIGHT = 300;
/**
* A font weight value for the normal weight
*/
public static final int FONT_WEIGHT_NORMAL = 400;
/**
* A font weight value for the medium weight
*/
public static final int FONT_WEIGHT_MEDIUM = 500;
/**
* A font weight value for the semi-bold weight
*/
public static final int FONT_WEIGHT_SEMI_BOLD = 600;
/**
* A font weight value for the bold weight.
*/
public static final int FONT_WEIGHT_BOLD = 700;
/**
* A font weight value for the extra-bold weight
*/
public static final int FONT_WEIGHT_EXTRA_BOLD = 800;
/**
* A font weight value for the black weight
*/
public static final int FONT_WEIGHT_BLACK = 900;
/**
* A maximum weight value for the font
*/
public static final int FONT_WEIGHT_MAX = 1000;
/**
* A font slant value for upright
*/
public static final int FONT_SLANT_UPRIGHT = 0;
/**
* A font slant value for italic
*/
public static final int FONT_SLANT_ITALIC = 1;
// TODO: Support FONT_SLANT_OBLIQUE
/** @hide */
@IntDef(prefix = { "FONT_SLANT_" }, value = {
FONT_SLANT_UPRIGHT,
FONT_SLANT_ITALIC
})
@Retention(RetentionPolicy.SOURCE)
public @interface FontSlant {}
private final @IntRange(from = 0, to = 1000) int mWeight;
private final @FontSlant int mSlant;
// TODO: Support width
public FontStyle() {
mWeight = FONT_WEIGHT_NORMAL;
mSlant = FONT_SLANT_UPRIGHT;
}
/**
* Create FontStyle with specific weight and italic
*
* *
Value | *Name | *Android Definition | *
---|---|---|
100 | *Thin | *{@link FontStyle#FONT_WEIGHT_THIN} | *
200 | *Extra Light (Ultra Light) | *{@link FontStyle#FONT_WEIGHT_EXTRA_LIGHT} | *
300 | *Light | *{@link FontStyle#FONT_WEIGHT_LIGHT} | *
400 | *Normal (Regular) | *{@link FontStyle#FONT_WEIGHT_NORMAL} | *
500 | *Medium | *{@link FontStyle#FONT_WEIGHT_MEDIUM} | *
600 | *Semi Bold (Demi Bold) | *{@link FontStyle#FONT_WEIGHT_SEMI_BOLD} | *
700 | *Bold | *{@link FontStyle#FONT_WEIGHT_BOLD} | *
800 | *Extra Bold (Ultra Bold) | *{@link FontStyle#FONT_WEIGHT_EXTRA_BOLD} | *
900 | *Black (Heavy) | *{@link FontStyle#FONT_WEIGHT_BLACK} | *