Loading api/current.txt +9 −9 Original line number Original line Diff line number Diff line Loading @@ -15190,7 +15190,7 @@ package android.graphics.drawable.shapes { package android.graphics.fonts { package android.graphics.fonts { public class Font { public final class Font { method public android.graphics.fonts.FontVariationAxis[] getAxes(); method public android.graphics.fonts.FontVariationAxis[] getAxes(); method public int getTtcIndex(); method public int getTtcIndex(); method public int getWeight(); method public int getWeight(); Loading @@ -15208,12 +15208,12 @@ package android.graphics.fonts { public static class Font.Builder { public static class Font.Builder { ctor public Font.Builder(java.nio.ByteBuffer); ctor public Font.Builder(java.nio.ByteBuffer); ctor public Font.Builder(java.io.File) throws java.io.IOException; ctor public Font.Builder(java.io.File); ctor public Font.Builder(java.io.FileDescriptor) throws java.io.IOException; ctor public Font.Builder(java.io.FileDescriptor); ctor public Font.Builder(java.io.FileDescriptor, long, long) throws java.io.IOException; ctor public Font.Builder(java.io.FileDescriptor, long, long); ctor public Font.Builder(android.content.res.AssetManager, java.lang.String) throws java.io.IOException; ctor public Font.Builder(android.content.res.AssetManager, java.lang.String); ctor public Font.Builder(android.content.res.Resources, int) throws java.io.IOException; ctor public Font.Builder(android.content.res.Resources, int); method public android.graphics.fonts.Font build(); method public android.graphics.fonts.Font build() throws java.io.IOException; method public android.graphics.fonts.Font.Builder setFontVariationSettings(java.lang.String); method public android.graphics.fonts.Font.Builder setFontVariationSettings(java.lang.String); method public android.graphics.fonts.Font.Builder setFontVariationSettings(android.graphics.fonts.FontVariationAxis[]); method public android.graphics.fonts.Font.Builder setFontVariationSettings(android.graphics.fonts.FontVariationAxis[]); method public android.graphics.fonts.Font.Builder setItalic(boolean); method public android.graphics.fonts.Font.Builder setItalic(boolean); Loading @@ -15221,9 +15221,9 @@ package android.graphics.fonts { method public android.graphics.fonts.Font.Builder setWeight(int); method public android.graphics.fonts.Font.Builder setWeight(int); } } public class FontFamily { public final class FontFamily { method public android.graphics.fonts.Font getFont(int); method public android.graphics.fonts.Font getFont(int); method public int getFontCount(); method public int getSize(); } } public static class FontFamily.Builder { public static class FontFamily.Builder { graphics/java/android/graphics/fonts/Font.java +54 −17 Original line number Original line Diff line number Diff line Loading @@ -36,11 +36,13 @@ import java.io.FileNotFoundException; import java.io.IOException; import java.io.IOException; import java.nio.ByteBuffer; import java.nio.ByteBuffer; import java.nio.channels.FileChannel; import java.nio.channels.FileChannel; import java.util.Arrays; import java.util.Objects; /** /** * A font class can be used for creating FontFamily. * A font class can be used for creating FontFamily. */ */ public class Font { public final class Font { private static final String TAG = "Font"; private static final String TAG = "Font"; private static final int NOT_SPECIFIED = -1; private static final int NOT_SPECIFIED = -1; Loading Loading @@ -109,6 +111,7 @@ public class Font { private @IntRange(from = -1, to = 1) int mItalic = NOT_SPECIFIED; private @IntRange(from = -1, to = 1) int mItalic = NOT_SPECIFIED; private @IntRange(from = 0) int mTtcIndex = 0; private @IntRange(from = 0) int mTtcIndex = 0; private @Nullable FontVariationAxis[] mAxes = null; private @Nullable FontVariationAxis[] mAxes = null; private @Nullable IOException mException; /** /** * Constructs a builder with a byte buffer. * Constructs a builder with a byte buffer. Loading @@ -132,11 +135,13 @@ public class Font { * * * @param path a file path to the font file * @param path a file path to the font file */ */ public Builder(@NonNull File path) throws IOException { public Builder(@NonNull File path) { Preconditions.checkNotNull(path, "path can not be null"); Preconditions.checkNotNull(path, "path can not be null"); try (FileInputStream fis = new FileInputStream(path)) { try (FileInputStream fis = new FileInputStream(path)) { final FileChannel fc = fis.getChannel(); final FileChannel fc = fis.getChannel(); mBuffer = fc.map(FileChannel.MapMode.READ_ONLY, 0, fc.size()); mBuffer = fc.map(FileChannel.MapMode.READ_ONLY, 0, fc.size()); } catch (IOException e) { mException = e; } } } } Loading @@ -145,7 +150,7 @@ public class Font { * * * @param fd a file descriptor * @param fd a file descriptor */ */ public Builder(@NonNull FileDescriptor fd) throws IOException { public Builder(@NonNull FileDescriptor fd) { this(fd, 0, -1); this(fd, 0, -1); } } Loading @@ -157,11 +162,13 @@ public class Font { * @param size a size of the font data. If -1 is passed, use until end of the file. * @param size a size of the font data. If -1 is passed, use until end of the file. */ */ public Builder(@NonNull FileDescriptor fd, @IntRange(from = 0) long offset, public Builder(@NonNull FileDescriptor fd, @IntRange(from = 0) long offset, @IntRange(from = -1) long size) throws IOException { @IntRange(from = -1) long size) { try (FileInputStream fis = new FileInputStream(fd)) { try (FileInputStream fis = new FileInputStream(fd)) { final FileChannel fc = fis.getChannel(); final FileChannel fc = fis.getChannel(); size = (size == -1) ? fc.size() - offset : size; size = (size == -1) ? fc.size() - offset : size; mBuffer = fc.map(FileChannel.MapMode.READ_ONLY, offset, size); mBuffer = fc.map(FileChannel.MapMode.READ_ONLY, offset, size); } catch (IOException e) { mException = e; } } } } Loading @@ -171,15 +178,17 @@ public class Font { * @param am the application's asset manager * @param am the application's asset manager * @param path the file name of the font data in the asset directory * @param path the file name of the font data in the asset directory */ */ public Builder(@NonNull AssetManager am, @NonNull String path) throws IOException { public Builder(@NonNull AssetManager am, @NonNull String path) { final long nativeAsset = nGetNativeAsset(am, path, true /* is asset */, 0 /* cookie */); final long nativeAsset = nGetNativeAsset(am, path, true /* is asset */, 0 /* cookie */); if (nativeAsset == 0) { if (nativeAsset == 0) { throw new FileNotFoundException("Unable to open " + path); mException = new FileNotFoundException("Unable to open " + path); return; } } final ByteBuffer b = nGetAssetBuffer(nativeAsset); final ByteBuffer b = nGetAssetBuffer(nativeAsset); sAssetByteBufferRegistroy.registerNativeAllocation(b, nativeAsset); sAssetByteBufferRegistroy.registerNativeAllocation(b, nativeAsset); if (b == null) { if (b == null) { throw new FileNotFoundException(path + " not found"); mException = new FileNotFoundException(path + " not found"); return; } } mBuffer = b; mBuffer = b; } } Loading @@ -192,25 +201,29 @@ public class Font { * @param res the resource of this application. * @param res the resource of this application. * @param resId the resource ID of font file. * @param resId the resource ID of font file. */ */ public Builder(@NonNull Resources res, int resId) throws IOException { public Builder(@NonNull Resources res, int resId) { final TypedValue value = new TypedValue(); final TypedValue value = new TypedValue(); res.getValue(resId, value, true); res.getValue(resId, value, true); if (value.string == null) { if (value.string == null) { throw new FileNotFoundException(resId + " not found"); mException = new FileNotFoundException(resId + " not found"); return; } } final String str = value.string.toString(); final String str = value.string.toString(); if (str.toLowerCase().endsWith(".xml")) { if (str.toLowerCase().endsWith(".xml")) { throw new FileNotFoundException(resId + " must be font file."); mException = new FileNotFoundException(resId + " must be font file."); return; } } final long nativeAsset = nGetNativeAsset(res.getAssets(), str, false /* is asset */, final long nativeAsset = nGetNativeAsset(res.getAssets(), str, false /* is asset */, value.assetCookie); value.assetCookie); if (nativeAsset == 0) { if (nativeAsset == 0) { throw new FileNotFoundException("Unable to open " + str); mException = new FileNotFoundException("Unable to open " + str); return; } } final ByteBuffer b = nGetAssetBuffer(nativeAsset); final ByteBuffer b = nGetAssetBuffer(nativeAsset); sAssetByteBufferRegistroy.registerNativeAllocation(b, nativeAsset); sAssetByteBufferRegistroy.registerNativeAllocation(b, nativeAsset); if (b == null) { if (b == null) { throw new FileNotFoundException(str + " not found"); mException = new FileNotFoundException(str + " not found"); return; } } mBuffer = b; mBuffer = b; } } Loading Loading @@ -347,7 +360,7 @@ public class Font { * @return this builder * @return this builder */ */ public @NonNull Builder setFontVariationSettings(@Nullable FontVariationAxis[] axes) { public @NonNull Builder setFontVariationSettings(@Nullable FontVariationAxis[] axes) { mAxes = axes; mAxes = axes == null ? null : axes.clone(); return this; return this; } } Loading @@ -355,7 +368,10 @@ public class Font { * Creates the font based on the configured values. * Creates the font based on the configured values. * @return the Font object * @return the Font object */ */ public @Nullable Font build() { public @Nullable Font build() throws IOException { if (mException != null) { throw new IOException("Failed to read font contents", mException); } if (mWeight == NOT_SPECIFIED || mItalic == NOT_SPECIFIED) { if (mWeight == NOT_SPECIFIED || mItalic == NOT_SPECIFIED) { final int packed = FontFileUtil.analyzeStyle(mBuffer, mTtcIndex, mAxes); final int packed = FontFileUtil.analyzeStyle(mBuffer, mTtcIndex, mAxes); if (FontFileUtil.isSuccess(packed)) { if (FontFileUtil.isSuccess(packed)) { Loading @@ -378,7 +394,7 @@ public class Font { } } } } final long ptr = nBuild(builderPtr, mBuffer, mWeight, italic, mTtcIndex); final long ptr = nBuild(builderPtr, mBuffer, mWeight, italic, mTtcIndex); final Font font = new Font(ptr, mWeight, italic, mTtcIndex, mAxes); final Font font = new Font(ptr, mBuffer, mWeight, italic, mTtcIndex, mAxes); sFontRegistory.registerNativeAllocation(font, ptr); sFontRegistory.registerNativeAllocation(font, ptr); return font; return font; } } Loading @@ -405,6 +421,7 @@ public class Font { } } private final long mNativePtr; // address of the shared ptr of minikin::Font private final long mNativePtr; // address of the shared ptr of minikin::Font private final @NonNull ByteBuffer mBuffer; private final @IntRange(from = 0, to = 1000) int mWeight; private final @IntRange(from = 0, to = 1000) int mWeight; private final boolean mItalic; private final boolean mItalic; private final @IntRange(from = 0) int mTtcIndex; private final @IntRange(from = 0) int mTtcIndex; Loading @@ -413,8 +430,10 @@ public class Font { /** /** * Use Builder instead * Use Builder instead */ */ private Font(long nativePtr, @IntRange(from = 0, to = 1000) int weight, boolean italic, private Font(long nativePtr, @NonNull ByteBuffer buffer, @IntRange(from = 0, to = 1000) int weight, boolean italic, @IntRange(from = 0) int ttcIndex, @Nullable FontVariationAxis[] axes) { @IntRange(from = 0) int ttcIndex, @Nullable FontVariationAxis[] axes) { mBuffer = buffer; mWeight = weight; mWeight = weight; mItalic = italic; mItalic = italic; mNativePtr = nativePtr; mNativePtr = nativePtr; Loading Loading @@ -462,7 +481,7 @@ public class Font { * @return font variation settings * @return font variation settings */ */ public @Nullable FontVariationAxis[] getAxes() { public @Nullable FontVariationAxis[] getAxes() { return mAxes; return mAxes == null ? null : mAxes.clone(); } } /** @hide */ /** @hide */ Loading @@ -470,6 +489,24 @@ public class Font { return mNativePtr; return mNativePtr; } } @Override public boolean equals(@Nullable Object o) { if (o == this) { return true; } if (o == null || !(o instanceof Font)) { return false; } Font f = (Font) o; return f.mWeight == mWeight && f.mItalic == mItalic && f.mTtcIndex == mTtcIndex && Arrays.equals(f.mAxes, mAxes) && f.mBuffer.equals(mBuffer); } @Override public int hashCode() { return Objects.hash(mWeight, mItalic, mTtcIndex, mAxes, mBuffer); } @Override @Override public String toString() { public String toString() { return "Font {weight=" + mWeight + ", italic=" + mItalic + "}"; return "Font {weight=" + mWeight + ", italic=" + mItalic + "}"; Loading graphics/java/android/graphics/fonts/FontFamily.java +2 −2 Original line number Original line Diff line number Diff line Loading @@ -57,7 +57,7 @@ import java.util.HashSet; * </p> * </p> * * */ */ public class FontFamily { public final class FontFamily { private static final String TAG = "FontFamily"; private static final String TAG = "FontFamily"; /** /** Loading Loading @@ -170,7 +170,7 @@ public class FontFamily { * * * @return the number of fonts registered in this family. * @return the number of fonts registered in this family. */ */ public int getFontCount() { public int getSize() { return mFonts.size(); return mFonts.size(); } } Loading graphics/java/android/graphics/fonts/FontVariationAxis.java +18 −0 Original line number Original line Diff line number Diff line Loading @@ -22,6 +22,7 @@ import android.annotation.UnsupportedAppUsage; import android.text.TextUtils; import android.text.TextUtils; import java.util.ArrayList; import java.util.ArrayList; import java.util.Objects; import java.util.regex.Pattern; import java.util.regex.Pattern; /** /** Loading Loading @@ -186,5 +187,22 @@ public final class FontVariationAxis { } } return TextUtils.join(",", axes); return TextUtils.join(",", axes); } } @Override public boolean equals(@Nullable Object o) { if (o == this) { return true; } if (o == null || !(o instanceof FontVariationAxis)) { return false; } FontVariationAxis axis = (FontVariationAxis) o; return axis.mTag == mTag && axis.mStyleValue == mStyleValue; } @Override public int hashCode() { return Objects.hash(mTag, mStyleValue); } } } graphics/java/android/graphics/fonts/SystemFonts.java +11 −6 Original line number Original line Diff line number Diff line Loading @@ -169,12 +169,17 @@ public class SystemFonts { } } } } final Font font = new Font.Builder(buffer) final Font font; try { font = new Font.Builder(buffer) .setWeight(fontConfig.getWeight()) .setWeight(fontConfig.getWeight()) .setItalic(fontConfig.isItalic()) .setItalic(fontConfig.isItalic()) .setTtcIndex(fontConfig.getTtcIndex()) .setTtcIndex(fontConfig.getTtcIndex()) .setFontVariationSettings(fontConfig.getAxes()) .setFontVariationSettings(fontConfig.getAxes()) .build(); .build(); } catch (IOException e) { throw new RuntimeException(e); // Never reaches here } if (b == null) { if (b == null) { b = new FontFamily.Builder(font); b = new FontFamily.Builder(font); Loading Loading
api/current.txt +9 −9 Original line number Original line Diff line number Diff line Loading @@ -15190,7 +15190,7 @@ package android.graphics.drawable.shapes { package android.graphics.fonts { package android.graphics.fonts { public class Font { public final class Font { method public android.graphics.fonts.FontVariationAxis[] getAxes(); method public android.graphics.fonts.FontVariationAxis[] getAxes(); method public int getTtcIndex(); method public int getTtcIndex(); method public int getWeight(); method public int getWeight(); Loading @@ -15208,12 +15208,12 @@ package android.graphics.fonts { public static class Font.Builder { public static class Font.Builder { ctor public Font.Builder(java.nio.ByteBuffer); ctor public Font.Builder(java.nio.ByteBuffer); ctor public Font.Builder(java.io.File) throws java.io.IOException; ctor public Font.Builder(java.io.File); ctor public Font.Builder(java.io.FileDescriptor) throws java.io.IOException; ctor public Font.Builder(java.io.FileDescriptor); ctor public Font.Builder(java.io.FileDescriptor, long, long) throws java.io.IOException; ctor public Font.Builder(java.io.FileDescriptor, long, long); ctor public Font.Builder(android.content.res.AssetManager, java.lang.String) throws java.io.IOException; ctor public Font.Builder(android.content.res.AssetManager, java.lang.String); ctor public Font.Builder(android.content.res.Resources, int) throws java.io.IOException; ctor public Font.Builder(android.content.res.Resources, int); method public android.graphics.fonts.Font build(); method public android.graphics.fonts.Font build() throws java.io.IOException; method public android.graphics.fonts.Font.Builder setFontVariationSettings(java.lang.String); method public android.graphics.fonts.Font.Builder setFontVariationSettings(java.lang.String); method public android.graphics.fonts.Font.Builder setFontVariationSettings(android.graphics.fonts.FontVariationAxis[]); method public android.graphics.fonts.Font.Builder setFontVariationSettings(android.graphics.fonts.FontVariationAxis[]); method public android.graphics.fonts.Font.Builder setItalic(boolean); method public android.graphics.fonts.Font.Builder setItalic(boolean); Loading @@ -15221,9 +15221,9 @@ package android.graphics.fonts { method public android.graphics.fonts.Font.Builder setWeight(int); method public android.graphics.fonts.Font.Builder setWeight(int); } } public class FontFamily { public final class FontFamily { method public android.graphics.fonts.Font getFont(int); method public android.graphics.fonts.Font getFont(int); method public int getFontCount(); method public int getSize(); } } public static class FontFamily.Builder { public static class FontFamily.Builder {
graphics/java/android/graphics/fonts/Font.java +54 −17 Original line number Original line Diff line number Diff line Loading @@ -36,11 +36,13 @@ import java.io.FileNotFoundException; import java.io.IOException; import java.io.IOException; import java.nio.ByteBuffer; import java.nio.ByteBuffer; import java.nio.channels.FileChannel; import java.nio.channels.FileChannel; import java.util.Arrays; import java.util.Objects; /** /** * A font class can be used for creating FontFamily. * A font class can be used for creating FontFamily. */ */ public class Font { public final class Font { private static final String TAG = "Font"; private static final String TAG = "Font"; private static final int NOT_SPECIFIED = -1; private static final int NOT_SPECIFIED = -1; Loading Loading @@ -109,6 +111,7 @@ public class Font { private @IntRange(from = -1, to = 1) int mItalic = NOT_SPECIFIED; private @IntRange(from = -1, to = 1) int mItalic = NOT_SPECIFIED; private @IntRange(from = 0) int mTtcIndex = 0; private @IntRange(from = 0) int mTtcIndex = 0; private @Nullable FontVariationAxis[] mAxes = null; private @Nullable FontVariationAxis[] mAxes = null; private @Nullable IOException mException; /** /** * Constructs a builder with a byte buffer. * Constructs a builder with a byte buffer. Loading @@ -132,11 +135,13 @@ public class Font { * * * @param path a file path to the font file * @param path a file path to the font file */ */ public Builder(@NonNull File path) throws IOException { public Builder(@NonNull File path) { Preconditions.checkNotNull(path, "path can not be null"); Preconditions.checkNotNull(path, "path can not be null"); try (FileInputStream fis = new FileInputStream(path)) { try (FileInputStream fis = new FileInputStream(path)) { final FileChannel fc = fis.getChannel(); final FileChannel fc = fis.getChannel(); mBuffer = fc.map(FileChannel.MapMode.READ_ONLY, 0, fc.size()); mBuffer = fc.map(FileChannel.MapMode.READ_ONLY, 0, fc.size()); } catch (IOException e) { mException = e; } } } } Loading @@ -145,7 +150,7 @@ public class Font { * * * @param fd a file descriptor * @param fd a file descriptor */ */ public Builder(@NonNull FileDescriptor fd) throws IOException { public Builder(@NonNull FileDescriptor fd) { this(fd, 0, -1); this(fd, 0, -1); } } Loading @@ -157,11 +162,13 @@ public class Font { * @param size a size of the font data. If -1 is passed, use until end of the file. * @param size a size of the font data. If -1 is passed, use until end of the file. */ */ public Builder(@NonNull FileDescriptor fd, @IntRange(from = 0) long offset, public Builder(@NonNull FileDescriptor fd, @IntRange(from = 0) long offset, @IntRange(from = -1) long size) throws IOException { @IntRange(from = -1) long size) { try (FileInputStream fis = new FileInputStream(fd)) { try (FileInputStream fis = new FileInputStream(fd)) { final FileChannel fc = fis.getChannel(); final FileChannel fc = fis.getChannel(); size = (size == -1) ? fc.size() - offset : size; size = (size == -1) ? fc.size() - offset : size; mBuffer = fc.map(FileChannel.MapMode.READ_ONLY, offset, size); mBuffer = fc.map(FileChannel.MapMode.READ_ONLY, offset, size); } catch (IOException e) { mException = e; } } } } Loading @@ -171,15 +178,17 @@ public class Font { * @param am the application's asset manager * @param am the application's asset manager * @param path the file name of the font data in the asset directory * @param path the file name of the font data in the asset directory */ */ public Builder(@NonNull AssetManager am, @NonNull String path) throws IOException { public Builder(@NonNull AssetManager am, @NonNull String path) { final long nativeAsset = nGetNativeAsset(am, path, true /* is asset */, 0 /* cookie */); final long nativeAsset = nGetNativeAsset(am, path, true /* is asset */, 0 /* cookie */); if (nativeAsset == 0) { if (nativeAsset == 0) { throw new FileNotFoundException("Unable to open " + path); mException = new FileNotFoundException("Unable to open " + path); return; } } final ByteBuffer b = nGetAssetBuffer(nativeAsset); final ByteBuffer b = nGetAssetBuffer(nativeAsset); sAssetByteBufferRegistroy.registerNativeAllocation(b, nativeAsset); sAssetByteBufferRegistroy.registerNativeAllocation(b, nativeAsset); if (b == null) { if (b == null) { throw new FileNotFoundException(path + " not found"); mException = new FileNotFoundException(path + " not found"); return; } } mBuffer = b; mBuffer = b; } } Loading @@ -192,25 +201,29 @@ public class Font { * @param res the resource of this application. * @param res the resource of this application. * @param resId the resource ID of font file. * @param resId the resource ID of font file. */ */ public Builder(@NonNull Resources res, int resId) throws IOException { public Builder(@NonNull Resources res, int resId) { final TypedValue value = new TypedValue(); final TypedValue value = new TypedValue(); res.getValue(resId, value, true); res.getValue(resId, value, true); if (value.string == null) { if (value.string == null) { throw new FileNotFoundException(resId + " not found"); mException = new FileNotFoundException(resId + " not found"); return; } } final String str = value.string.toString(); final String str = value.string.toString(); if (str.toLowerCase().endsWith(".xml")) { if (str.toLowerCase().endsWith(".xml")) { throw new FileNotFoundException(resId + " must be font file."); mException = new FileNotFoundException(resId + " must be font file."); return; } } final long nativeAsset = nGetNativeAsset(res.getAssets(), str, false /* is asset */, final long nativeAsset = nGetNativeAsset(res.getAssets(), str, false /* is asset */, value.assetCookie); value.assetCookie); if (nativeAsset == 0) { if (nativeAsset == 0) { throw new FileNotFoundException("Unable to open " + str); mException = new FileNotFoundException("Unable to open " + str); return; } } final ByteBuffer b = nGetAssetBuffer(nativeAsset); final ByteBuffer b = nGetAssetBuffer(nativeAsset); sAssetByteBufferRegistroy.registerNativeAllocation(b, nativeAsset); sAssetByteBufferRegistroy.registerNativeAllocation(b, nativeAsset); if (b == null) { if (b == null) { throw new FileNotFoundException(str + " not found"); mException = new FileNotFoundException(str + " not found"); return; } } mBuffer = b; mBuffer = b; } } Loading Loading @@ -347,7 +360,7 @@ public class Font { * @return this builder * @return this builder */ */ public @NonNull Builder setFontVariationSettings(@Nullable FontVariationAxis[] axes) { public @NonNull Builder setFontVariationSettings(@Nullable FontVariationAxis[] axes) { mAxes = axes; mAxes = axes == null ? null : axes.clone(); return this; return this; } } Loading @@ -355,7 +368,10 @@ public class Font { * Creates the font based on the configured values. * Creates the font based on the configured values. * @return the Font object * @return the Font object */ */ public @Nullable Font build() { public @Nullable Font build() throws IOException { if (mException != null) { throw new IOException("Failed to read font contents", mException); } if (mWeight == NOT_SPECIFIED || mItalic == NOT_SPECIFIED) { if (mWeight == NOT_SPECIFIED || mItalic == NOT_SPECIFIED) { final int packed = FontFileUtil.analyzeStyle(mBuffer, mTtcIndex, mAxes); final int packed = FontFileUtil.analyzeStyle(mBuffer, mTtcIndex, mAxes); if (FontFileUtil.isSuccess(packed)) { if (FontFileUtil.isSuccess(packed)) { Loading @@ -378,7 +394,7 @@ public class Font { } } } } final long ptr = nBuild(builderPtr, mBuffer, mWeight, italic, mTtcIndex); final long ptr = nBuild(builderPtr, mBuffer, mWeight, italic, mTtcIndex); final Font font = new Font(ptr, mWeight, italic, mTtcIndex, mAxes); final Font font = new Font(ptr, mBuffer, mWeight, italic, mTtcIndex, mAxes); sFontRegistory.registerNativeAllocation(font, ptr); sFontRegistory.registerNativeAllocation(font, ptr); return font; return font; } } Loading @@ -405,6 +421,7 @@ public class Font { } } private final long mNativePtr; // address of the shared ptr of minikin::Font private final long mNativePtr; // address of the shared ptr of minikin::Font private final @NonNull ByteBuffer mBuffer; private final @IntRange(from = 0, to = 1000) int mWeight; private final @IntRange(from = 0, to = 1000) int mWeight; private final boolean mItalic; private final boolean mItalic; private final @IntRange(from = 0) int mTtcIndex; private final @IntRange(from = 0) int mTtcIndex; Loading @@ -413,8 +430,10 @@ public class Font { /** /** * Use Builder instead * Use Builder instead */ */ private Font(long nativePtr, @IntRange(from = 0, to = 1000) int weight, boolean italic, private Font(long nativePtr, @NonNull ByteBuffer buffer, @IntRange(from = 0, to = 1000) int weight, boolean italic, @IntRange(from = 0) int ttcIndex, @Nullable FontVariationAxis[] axes) { @IntRange(from = 0) int ttcIndex, @Nullable FontVariationAxis[] axes) { mBuffer = buffer; mWeight = weight; mWeight = weight; mItalic = italic; mItalic = italic; mNativePtr = nativePtr; mNativePtr = nativePtr; Loading Loading @@ -462,7 +481,7 @@ public class Font { * @return font variation settings * @return font variation settings */ */ public @Nullable FontVariationAxis[] getAxes() { public @Nullable FontVariationAxis[] getAxes() { return mAxes; return mAxes == null ? null : mAxes.clone(); } } /** @hide */ /** @hide */ Loading @@ -470,6 +489,24 @@ public class Font { return mNativePtr; return mNativePtr; } } @Override public boolean equals(@Nullable Object o) { if (o == this) { return true; } if (o == null || !(o instanceof Font)) { return false; } Font f = (Font) o; return f.mWeight == mWeight && f.mItalic == mItalic && f.mTtcIndex == mTtcIndex && Arrays.equals(f.mAxes, mAxes) && f.mBuffer.equals(mBuffer); } @Override public int hashCode() { return Objects.hash(mWeight, mItalic, mTtcIndex, mAxes, mBuffer); } @Override @Override public String toString() { public String toString() { return "Font {weight=" + mWeight + ", italic=" + mItalic + "}"; return "Font {weight=" + mWeight + ", italic=" + mItalic + "}"; Loading
graphics/java/android/graphics/fonts/FontFamily.java +2 −2 Original line number Original line Diff line number Diff line Loading @@ -57,7 +57,7 @@ import java.util.HashSet; * </p> * </p> * * */ */ public class FontFamily { public final class FontFamily { private static final String TAG = "FontFamily"; private static final String TAG = "FontFamily"; /** /** Loading Loading @@ -170,7 +170,7 @@ public class FontFamily { * * * @return the number of fonts registered in this family. * @return the number of fonts registered in this family. */ */ public int getFontCount() { public int getSize() { return mFonts.size(); return mFonts.size(); } } Loading
graphics/java/android/graphics/fonts/FontVariationAxis.java +18 −0 Original line number Original line Diff line number Diff line Loading @@ -22,6 +22,7 @@ import android.annotation.UnsupportedAppUsage; import android.text.TextUtils; import android.text.TextUtils; import java.util.ArrayList; import java.util.ArrayList; import java.util.Objects; import java.util.regex.Pattern; import java.util.regex.Pattern; /** /** Loading Loading @@ -186,5 +187,22 @@ public final class FontVariationAxis { } } return TextUtils.join(",", axes); return TextUtils.join(",", axes); } } @Override public boolean equals(@Nullable Object o) { if (o == this) { return true; } if (o == null || !(o instanceof FontVariationAxis)) { return false; } FontVariationAxis axis = (FontVariationAxis) o; return axis.mTag == mTag && axis.mStyleValue == mStyleValue; } @Override public int hashCode() { return Objects.hash(mTag, mStyleValue); } } }
graphics/java/android/graphics/fonts/SystemFonts.java +11 −6 Original line number Original line Diff line number Diff line Loading @@ -169,12 +169,17 @@ public class SystemFonts { } } } } final Font font = new Font.Builder(buffer) final Font font; try { font = new Font.Builder(buffer) .setWeight(fontConfig.getWeight()) .setWeight(fontConfig.getWeight()) .setItalic(fontConfig.isItalic()) .setItalic(fontConfig.isItalic()) .setTtcIndex(fontConfig.getTtcIndex()) .setTtcIndex(fontConfig.getTtcIndex()) .setFontVariationSettings(fontConfig.getAxes()) .setFontVariationSettings(fontConfig.getAxes()) .build(); .build(); } catch (IOException e) { throw new RuntimeException(e); // Never reaches here } if (b == null) { if (b == null) { b = new FontFamily.Builder(font); b = new FontFamily.Builder(font); Loading