Loading core/tests/coretests/src/android/graphics/TypefaceSystemFallbackTest.java +3 −3 Original line number Diff line number Diff line Loading @@ -44,7 +44,7 @@ import java.io.InputStream; import java.nio.charset.Charset; import java.nio.file.Files; import java.nio.file.StandardCopyOption; import java.util.HashSet; import java.util.ArrayList; import java.util.Locale; @SmallTest Loading Loading @@ -112,7 +112,7 @@ public class TypefaceSystemFallbackTest { private static void buildSystemFallback(String xml, ArrayMap<String, Typeface> fontMap, ArrayMap<String, FontFamily[]> fallbackMap) { final HashSet<Font> availableFonts = new HashSet<>(); final ArrayList<Font> availableFonts = new ArrayList<>(); try (FileOutputStream fos = new FileOutputStream(TEST_FONTS_XML)) { fos.write(xml.getBytes(Charset.forName("UTF-8"))); } catch (IOException e) { Loading @@ -127,7 +127,7 @@ public class TypefaceSystemFallbackTest { public void testBuildSystemFallback() { final ArrayMap<String, Typeface> fontMap = new ArrayMap<>(); final ArrayMap<String, FontFamily[]> fallbackMap = new ArrayMap<>(); final HashSet<Font> availableFonts = new HashSet<>(); final ArrayList<Font> availableFonts = new ArrayList<>(); final FontConfig.Alias[] aliases = SystemFonts.buildSystemFallback(SYSTEM_FONTS_XML, SYSTEM_FONT_DIR, fallbackMap, availableFonts); Loading core/tests/coretests/src/android/text/FontFallbackSetup.java +2 −2 Original line number Diff line number Diff line Loading @@ -33,7 +33,7 @@ import java.io.InputStream; import java.nio.charset.Charset; import java.nio.file.Files; import java.nio.file.StandardCopyOption; import java.util.HashSet; import java.util.ArrayList; public class FontFallbackSetup implements AutoCloseable { private final String[] mTestFontFiles; Loading Loading @@ -76,7 +76,7 @@ public class FontFallbackSetup implements AutoCloseable { } final ArrayMap<String, FontFamily[]> fallbackMap = new ArrayMap<>(); final HashSet<Font> availableFonts = new HashSet<>(); final ArrayList<Font> availableFonts = new ArrayList<>(); final FontConfig.Alias[] aliases = SystemFonts.buildSystemFallback(testFontsXml, mTestFontsDir, fallbackMap, availableFonts); Typeface.initSystemDefaultTypefaces(mFontMap, fallbackMap, aliases); Loading graphics/java/android/graphics/fonts/Font.java +6 −6 Original line number Diff line number Diff line Loading @@ -119,7 +119,7 @@ public final class Font { private @Nullable ByteBuffer mBuffer; private @Nullable File mFile; private @NonNull LocaleList mLocaleList = LocaleList.getEmptyLocaleList(); private @NonNull String mLocaleList = ""; private @IntRange(from = -1, to = 1000) int mWeight = NOT_SPECIFIED; private @IntRange(from = -1, to = 1) int mItalic = NOT_SPECIFIED; private @IntRange(from = 0) int mTtcIndex = 0; Loading Loading @@ -150,7 +150,7 @@ public final class Font { * @hide */ public Builder(@NonNull ByteBuffer buffer, @NonNull File path, @NonNull LocaleList localeList) { @NonNull String localeList) { this(buffer); mFile = path; mLocaleList = localeList; Loading Loading @@ -457,7 +457,7 @@ public final class Font { private final boolean mItalic; private final @IntRange(from = 0) int mTtcIndex; private final @Nullable FontVariationAxis[] mAxes; private final @NonNull LocaleList mLocaleList; private final @NonNull String mLocaleList; /** * Use Builder instead Loading @@ -465,7 +465,7 @@ public final class Font { private Font(long nativePtr, @NonNull ByteBuffer buffer, @Nullable File file, @IntRange(from = 0, to = 1000) int weight, boolean italic, @IntRange(from = 0) int ttcIndex, @Nullable FontVariationAxis[] axes, @NonNull LocaleList localeList) { @NonNull String localeList) { mBuffer = buffer; mFile = file; mWeight = weight; Loading Loading @@ -546,7 +546,7 @@ public final class Font { * @return a locale list */ public @NonNull LocaleList getLocaleList() { return mLocaleList; return LocaleList.forLanguageTags(mLocaleList); } /** @hide */ Loading Loading @@ -580,7 +580,7 @@ public final class Font { + ", italic=" + mItalic + ", ttcIndex=" + mTtcIndex + ", axes=" + FontVariationAxis.toFontVariationSettings(mAxes) + ", localeList=" + mLocaleList.toLanguageTags() + ", localeList=" + mLocaleList + ", buffer=" + mBuffer + "}"; } Loading graphics/java/android/graphics/fonts/SystemFonts.java +10 −10 Original line number Diff line number Diff line Loading @@ -19,7 +19,6 @@ package android.graphics.fonts; import android.annotation.NonNull; import android.annotation.Nullable; import android.graphics.FontListParser; import android.os.LocaleList; import android.text.FontConfig; import android.util.ArrayMap; import android.util.Log; Loading Loading @@ -54,7 +53,7 @@ public class SystemFonts { private static final Map<String, FontFamily[]> sSystemFallbackMap; private static final FontConfig.Alias[] sAliases; private static final Set<Font> sAvailableFonts; private static final List<Font> sAvailableFonts; /** * Returns all available font files in the system. Loading @@ -63,7 +62,9 @@ public class SystemFonts { * @return an array of system fonts */ public static @NonNull Set<Font> getAvailableFonts() { return sAvailableFonts; HashSet<Font> set = new HashSet<>(); set.addAll(sAvailableFonts); return set; } /** Loading Loading @@ -114,7 +115,7 @@ public class SystemFonts { @NonNull ArrayMap<String, ArrayList<FontFamily>> fallbackMap, @NonNull Map<String, ByteBuffer> cache, @NonNull String fontDir, @NonNull HashSet<Font> availableFonts) { @NonNull ArrayList<Font> availableFonts) { final String languageTags = xmlFamily.getLanguages(); final int variant = xmlFamily.getVariant(); Loading Loading @@ -170,13 +171,12 @@ public class SystemFonts { @FontConfig.Family.Variant int variant, @NonNull Map<String, ByteBuffer> cache, @NonNull String fontDir, @NonNull HashSet<Font> availableFonts) { @NonNull ArrayList<Font> availableFonts) { if (fonts.size() == 0) { return null; } FontFamily.Builder b = null; final LocaleList localeList = LocaleList.forLanguageTags(languageTags); for (int i = 0; i < fonts.size(); i++) { final FontConfig.Font fontConfig = fonts.get(i); final String fullPath = fontDir + fontConfig.getFontName(); Loading @@ -194,7 +194,7 @@ public class SystemFonts { final Font font; try { font = new Font.Builder(buffer, new File(fullPath), localeList) font = new Font.Builder(buffer, new File(fullPath), languageTags) .setWeight(fontConfig.getWeight()) .setItalic(fontConfig.isItalic()) .setTtcIndex(fontConfig.getTtcIndex()) Loading Loading @@ -228,7 +228,7 @@ public class SystemFonts { public static FontConfig.Alias[] buildSystemFallback(@NonNull String xmlPath, @NonNull String fontDir, @NonNull ArrayMap<String, FontFamily[]> fallbackMap, @NonNull HashSet<Font> availableFonts) { @NonNull ArrayList<Font> availableFonts) { try { final FileInputStream fontsIn = new FileInputStream(xmlPath); final FontConfig fontConfig = FontListParser.parse(fontsIn); Loading Loading @@ -284,11 +284,11 @@ public class SystemFonts { static { final ArrayMap<String, FontFamily[]> systemFallbackMap = new ArrayMap<>(); final HashSet<Font> availableFonts = new HashSet<>(); final ArrayList<Font> availableFonts = new ArrayList<>(); sAliases = buildSystemFallback("/system/etc/fonts.xml", "/system/fonts/", systemFallbackMap, availableFonts); sSystemFallbackMap = Collections.unmodifiableMap(systemFallbackMap); sAvailableFonts = Collections.unmodifiableSet(availableFonts); sAvailableFonts = Collections.unmodifiableList(availableFonts); } } Loading
core/tests/coretests/src/android/graphics/TypefaceSystemFallbackTest.java +3 −3 Original line number Diff line number Diff line Loading @@ -44,7 +44,7 @@ import java.io.InputStream; import java.nio.charset.Charset; import java.nio.file.Files; import java.nio.file.StandardCopyOption; import java.util.HashSet; import java.util.ArrayList; import java.util.Locale; @SmallTest Loading Loading @@ -112,7 +112,7 @@ public class TypefaceSystemFallbackTest { private static void buildSystemFallback(String xml, ArrayMap<String, Typeface> fontMap, ArrayMap<String, FontFamily[]> fallbackMap) { final HashSet<Font> availableFonts = new HashSet<>(); final ArrayList<Font> availableFonts = new ArrayList<>(); try (FileOutputStream fos = new FileOutputStream(TEST_FONTS_XML)) { fos.write(xml.getBytes(Charset.forName("UTF-8"))); } catch (IOException e) { Loading @@ -127,7 +127,7 @@ public class TypefaceSystemFallbackTest { public void testBuildSystemFallback() { final ArrayMap<String, Typeface> fontMap = new ArrayMap<>(); final ArrayMap<String, FontFamily[]> fallbackMap = new ArrayMap<>(); final HashSet<Font> availableFonts = new HashSet<>(); final ArrayList<Font> availableFonts = new ArrayList<>(); final FontConfig.Alias[] aliases = SystemFonts.buildSystemFallback(SYSTEM_FONTS_XML, SYSTEM_FONT_DIR, fallbackMap, availableFonts); Loading
core/tests/coretests/src/android/text/FontFallbackSetup.java +2 −2 Original line number Diff line number Diff line Loading @@ -33,7 +33,7 @@ import java.io.InputStream; import java.nio.charset.Charset; import java.nio.file.Files; import java.nio.file.StandardCopyOption; import java.util.HashSet; import java.util.ArrayList; public class FontFallbackSetup implements AutoCloseable { private final String[] mTestFontFiles; Loading Loading @@ -76,7 +76,7 @@ public class FontFallbackSetup implements AutoCloseable { } final ArrayMap<String, FontFamily[]> fallbackMap = new ArrayMap<>(); final HashSet<Font> availableFonts = new HashSet<>(); final ArrayList<Font> availableFonts = new ArrayList<>(); final FontConfig.Alias[] aliases = SystemFonts.buildSystemFallback(testFontsXml, mTestFontsDir, fallbackMap, availableFonts); Typeface.initSystemDefaultTypefaces(mFontMap, fallbackMap, aliases); Loading
graphics/java/android/graphics/fonts/Font.java +6 −6 Original line number Diff line number Diff line Loading @@ -119,7 +119,7 @@ public final class Font { private @Nullable ByteBuffer mBuffer; private @Nullable File mFile; private @NonNull LocaleList mLocaleList = LocaleList.getEmptyLocaleList(); private @NonNull String mLocaleList = ""; private @IntRange(from = -1, to = 1000) int mWeight = NOT_SPECIFIED; private @IntRange(from = -1, to = 1) int mItalic = NOT_SPECIFIED; private @IntRange(from = 0) int mTtcIndex = 0; Loading Loading @@ -150,7 +150,7 @@ public final class Font { * @hide */ public Builder(@NonNull ByteBuffer buffer, @NonNull File path, @NonNull LocaleList localeList) { @NonNull String localeList) { this(buffer); mFile = path; mLocaleList = localeList; Loading Loading @@ -457,7 +457,7 @@ public final class Font { private final boolean mItalic; private final @IntRange(from = 0) int mTtcIndex; private final @Nullable FontVariationAxis[] mAxes; private final @NonNull LocaleList mLocaleList; private final @NonNull String mLocaleList; /** * Use Builder instead Loading @@ -465,7 +465,7 @@ public final class Font { private Font(long nativePtr, @NonNull ByteBuffer buffer, @Nullable File file, @IntRange(from = 0, to = 1000) int weight, boolean italic, @IntRange(from = 0) int ttcIndex, @Nullable FontVariationAxis[] axes, @NonNull LocaleList localeList) { @NonNull String localeList) { mBuffer = buffer; mFile = file; mWeight = weight; Loading Loading @@ -546,7 +546,7 @@ public final class Font { * @return a locale list */ public @NonNull LocaleList getLocaleList() { return mLocaleList; return LocaleList.forLanguageTags(mLocaleList); } /** @hide */ Loading Loading @@ -580,7 +580,7 @@ public final class Font { + ", italic=" + mItalic + ", ttcIndex=" + mTtcIndex + ", axes=" + FontVariationAxis.toFontVariationSettings(mAxes) + ", localeList=" + mLocaleList.toLanguageTags() + ", localeList=" + mLocaleList + ", buffer=" + mBuffer + "}"; } Loading
graphics/java/android/graphics/fonts/SystemFonts.java +10 −10 Original line number Diff line number Diff line Loading @@ -19,7 +19,6 @@ package android.graphics.fonts; import android.annotation.NonNull; import android.annotation.Nullable; import android.graphics.FontListParser; import android.os.LocaleList; import android.text.FontConfig; import android.util.ArrayMap; import android.util.Log; Loading Loading @@ -54,7 +53,7 @@ public class SystemFonts { private static final Map<String, FontFamily[]> sSystemFallbackMap; private static final FontConfig.Alias[] sAliases; private static final Set<Font> sAvailableFonts; private static final List<Font> sAvailableFonts; /** * Returns all available font files in the system. Loading @@ -63,7 +62,9 @@ public class SystemFonts { * @return an array of system fonts */ public static @NonNull Set<Font> getAvailableFonts() { return sAvailableFonts; HashSet<Font> set = new HashSet<>(); set.addAll(sAvailableFonts); return set; } /** Loading Loading @@ -114,7 +115,7 @@ public class SystemFonts { @NonNull ArrayMap<String, ArrayList<FontFamily>> fallbackMap, @NonNull Map<String, ByteBuffer> cache, @NonNull String fontDir, @NonNull HashSet<Font> availableFonts) { @NonNull ArrayList<Font> availableFonts) { final String languageTags = xmlFamily.getLanguages(); final int variant = xmlFamily.getVariant(); Loading Loading @@ -170,13 +171,12 @@ public class SystemFonts { @FontConfig.Family.Variant int variant, @NonNull Map<String, ByteBuffer> cache, @NonNull String fontDir, @NonNull HashSet<Font> availableFonts) { @NonNull ArrayList<Font> availableFonts) { if (fonts.size() == 0) { return null; } FontFamily.Builder b = null; final LocaleList localeList = LocaleList.forLanguageTags(languageTags); for (int i = 0; i < fonts.size(); i++) { final FontConfig.Font fontConfig = fonts.get(i); final String fullPath = fontDir + fontConfig.getFontName(); Loading @@ -194,7 +194,7 @@ public class SystemFonts { final Font font; try { font = new Font.Builder(buffer, new File(fullPath), localeList) font = new Font.Builder(buffer, new File(fullPath), languageTags) .setWeight(fontConfig.getWeight()) .setItalic(fontConfig.isItalic()) .setTtcIndex(fontConfig.getTtcIndex()) Loading Loading @@ -228,7 +228,7 @@ public class SystemFonts { public static FontConfig.Alias[] buildSystemFallback(@NonNull String xmlPath, @NonNull String fontDir, @NonNull ArrayMap<String, FontFamily[]> fallbackMap, @NonNull HashSet<Font> availableFonts) { @NonNull ArrayList<Font> availableFonts) { try { final FileInputStream fontsIn = new FileInputStream(xmlPath); final FontConfig fontConfig = FontListParser.parse(fontsIn); Loading Loading @@ -284,11 +284,11 @@ public class SystemFonts { static { final ArrayMap<String, FontFamily[]> systemFallbackMap = new ArrayMap<>(); final HashSet<Font> availableFonts = new HashSet<>(); final ArrayList<Font> availableFonts = new ArrayList<>(); sAliases = buildSystemFallback("/system/etc/fonts.xml", "/system/fonts/", systemFallbackMap, availableFonts); sSystemFallbackMap = Collections.unmodifiableMap(systemFallbackMap); sAvailableFonts = Collections.unmodifiableSet(availableFonts); sAvailableFonts = Collections.unmodifiableList(availableFonts); } }