2 * Copyright (C) 2017 The Android Open Source Project
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 import static java.lang.annotation.RetentionPolicy.SOURCE;
21 import android.annotation.IntDef;
22 import android.annotation.NonNull;
23 import android.annotation.Nullable;
24 import android.graphics.fonts.FontVariationAxis;
25 import android.net.Uri;
27 import java.lang.annotation.Retention;
31 * Font configuration descriptions for System fonts.
34 public final class FontConfig {
35 private final @NonNull Family[] mFamilies;
36 private final @NonNull Alias[] mAliases;
38 public FontConfig(@NonNull Family[] families, @NonNull Alias[] aliases) {
44 * Returns the ordered list of families included in the system fonts.
46 public @NonNull Family[] getFamilies() {
51 * Returns the list of aliases defined for the font families in the system fonts.
53 public @NonNull Alias[] getAliases() {
58 * Class that holds information about a Font.
60 public static final class Font {
61 private final @NonNull String mFontName;
62 private final int mTtcIndex;
63 private final @NonNull FontVariationAxis[] mAxes;
64 private final int mWeight;
65 private final boolean mIsItalic;
67 private final String mFallbackFor;
72 public Font(@NonNull String fontName, int ttcIndex, @NonNull FontVariationAxis[] axes,
73 int weight, boolean isItalic, String fallbackFor) {
79 mFallbackFor = fallbackFor;
83 * Returns the name associated by the system to this font.
85 public @NonNull String getFontName() {
90 * Returns the index to be used to access this font when accessing a TTC file.
92 public int getTtcIndex() {
97 * Returns the list of axes associated to this font.
99 public @NonNull FontVariationAxis[] getAxes() {
104 * Returns the weight value for this font.
106 public int getWeight() {
111 * Returns whether this font is italic.
113 public boolean isItalic() {
118 * Returns the content uri associated to this font.
120 * You can reach to the font contents by calling {@link
121 * android.content.ContentResolver#openInputStream}.
123 public @Nullable Uri getUri() {
127 public void setUri(@NonNull Uri uri) {
131 public String getFallbackFor() {
137 * Class that holds information about a Font alias.
139 public static final class Alias {
140 private final @NonNull String mName;
141 private final @NonNull String mToName;
142 private final int mWeight;
144 public Alias(@NonNull String name, @NonNull String toName, int weight) {
151 * Returns the new name for the alias.
153 public @NonNull String getName() {
158 * Returns the existing name to which this alias points to.
160 public @NonNull String getToName() {
165 * Returns the weight associated with this alias.
167 public int getWeight() {
173 * Class that holds information about a Font family.
175 public static final class Family {
176 private final @NonNull String mName;
177 private final @NonNull Font[] mFonts;
178 private final @NonNull String mLanguage;
182 @IntDef({VARIANT_DEFAULT, VARIANT_COMPACT, VARIANT_ELEGANT})
183 public @interface Variant {}
186 * Value for font variant.
188 * Indicates the font has no variant attribute.
190 public static final int VARIANT_DEFAULT = 0;
193 * Value for font variant.
195 * Indicates the font is for compact variant.
196 * @see android.graphics.Paint#setElegantTextHeight
198 public static final int VARIANT_COMPACT = 1;
201 * Value for font variant.
203 * Indiates the font is for elegant variant.
204 * @see android.graphics.Paint#setElegantTextHeight
206 public static final int VARIANT_ELEGANT = 2;
208 // Must be same with Minikin's variant values.
209 // See frameworks/minikin/include/minikin/FontFamily.h
210 private final @Variant int mVariant;
212 public Family(@NonNull String name, @NonNull Font[] fonts, @NonNull String language,
213 @Variant int variant) {
216 mLanguage = language;
221 * Returns the name given by the system to this font family.
223 public @Nullable String getName() {
228 * Returns the list of fonts included in this family.
230 public @Nullable Font[] getFonts() {
235 * Returns the language for this family. May be null.
237 public @Nullable String getLanguage() {
242 * Returns the font variant for this family, e.g. "elegant" or "compact". May be null.
244 public @Variant int getVariant() {