Merge "Revert "Always suppress font error during resource loading""
This commit is contained in:
committed by
Android (Google) Code Review
commit
8ae1fcaf8d
@@ -34,6 +34,7 @@ import android.graphics.fonts.FontFamily;
|
||||
import android.graphics.fonts.FontStyle;
|
||||
import android.graphics.fonts.FontVariationAxis;
|
||||
import android.net.Uri;
|
||||
import android.os.Build.VERSION_CODES;
|
||||
import android.os.CancellationSignal;
|
||||
import android.os.Handler;
|
||||
import android.os.HandlerThread;
|
||||
@@ -641,35 +642,25 @@ public class FontsContract {
|
||||
continue;
|
||||
}
|
||||
try {
|
||||
Font font = null;
|
||||
try {
|
||||
font = new Font.Builder(buffer)
|
||||
final Font font = new Font.Builder(buffer)
|
||||
.setWeight(fontInfo.getWeight())
|
||||
.setSlant(fontInfo.isItalic()
|
||||
? FontStyle.FONT_SLANT_ITALIC : FontStyle.FONT_SLANT_UPRIGHT)
|
||||
.setTtcIndex(fontInfo.getTtcIndex())
|
||||
.setFontVariationSettings(fontInfo.getAxes())
|
||||
.build();
|
||||
} catch (IllegalArgumentException e) {
|
||||
// The exception happens if the unsupported font is passed. We suppress this
|
||||
// exception and just ignore this font here since there is no way of
|
||||
// resolving this issue by users during inflating layout.
|
||||
Log.w(TAG, "Ignoring font file since failed to create font object."
|
||||
+ " The font file is not supported on this platform.");
|
||||
continue;
|
||||
}
|
||||
if (familyBuilder == null) {
|
||||
familyBuilder = new FontFamily.Builder(font);
|
||||
} else {
|
||||
try {
|
||||
familyBuilder.addFont(font);
|
||||
} catch (IllegalArgumentException e) {
|
||||
// The exception happens if the same style font is added to the family.
|
||||
// We suppress this exception and just ignore this font here since there is
|
||||
// no way of resolving this issue by users during inflating layout.
|
||||
Log.w(TAG,
|
||||
"Ignoring font file since the same style font is already added.");
|
||||
continue;
|
||||
if (context.getApplicationInfo().targetSdkVersion <= VERSION_CODES.P) {
|
||||
// Surpress the IllegalArgumentException for keeping the backward
|
||||
// compatibility.
|
||||
continue;
|
||||
}
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
} catch (IOException e) {
|
||||
|
||||
@@ -33,12 +33,12 @@ import android.graphics.fonts.FontStyle;
|
||||
import android.graphics.fonts.FontVariationAxis;
|
||||
import android.graphics.fonts.SystemFonts;
|
||||
import android.os.Build;
|
||||
import android.os.Build.VERSION_CODES;
|
||||
import android.os.ParcelFileDescriptor;
|
||||
import android.provider.FontRequest;
|
||||
import android.provider.FontsContract;
|
||||
import android.text.FontConfig;
|
||||
import android.util.Base64;
|
||||
import android.util.Log;
|
||||
import android.util.LongSparseArray;
|
||||
import android.util.LruCache;
|
||||
import android.util.SparseArray;
|
||||
@@ -48,6 +48,7 @@ import com.android.internal.annotations.VisibleForTesting;
|
||||
import com.android.internal.util.Preconditions;
|
||||
|
||||
import dalvik.annotation.optimization.CriticalNative;
|
||||
import dalvik.system.VMRuntime;
|
||||
|
||||
import libcore.util.NativeAllocationRegistry;
|
||||
|
||||
@@ -262,29 +263,18 @@ public class Typeface {
|
||||
? FontStyle.FONT_SLANT_ITALIC : FontStyle.FONT_SLANT_UPRIGHT);
|
||||
}
|
||||
|
||||
Font font = null;
|
||||
try {
|
||||
font = fontBuilder.build();
|
||||
} catch (IllegalArgumentException e) {
|
||||
// The exception happens if the unsupported font is passed. We suppress this
|
||||
// exception and just ignore this font here since there is no way of
|
||||
// resolving this issue by users during inflating layout.
|
||||
Log.w(TAG, "Ignoring font file since failed to create font object."
|
||||
+ " The font file is not supported on this platform.");
|
||||
continue;
|
||||
}
|
||||
if (familyBuilder == null) {
|
||||
familyBuilder = new FontFamily.Builder(font);
|
||||
familyBuilder = new FontFamily.Builder(fontBuilder.build());
|
||||
} else {
|
||||
try {
|
||||
familyBuilder.addFont(font);
|
||||
familyBuilder.addFont(fontBuilder.build());
|
||||
} catch (IllegalArgumentException e) {
|
||||
// The exception happens if the same style is added to the family.
|
||||
// We suppress this exception and just ignore this font here since there is
|
||||
// no way of resolving this issue by users during inflating layout.
|
||||
Log.w(TAG,
|
||||
"Ignoring font file since the same style font is already added.");
|
||||
continue;
|
||||
if (VMRuntime.getRuntime().getTargetSdkVersion() <= VERSION_CODES.P) {
|
||||
// Surpress the IllegalArgumentException for keeping the backward
|
||||
// compatibility.
|
||||
continue;
|
||||
}
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -354,10 +354,6 @@ public final class Font {
|
||||
|
||||
/**
|
||||
* Creates the font based on the configured values.
|
||||
*
|
||||
* If the font is not supported by the platform, this function will fail with
|
||||
* {@link IllegalArgumentException}.
|
||||
*
|
||||
* @return the Font object
|
||||
*/
|
||||
public @NonNull Font build() throws IOException {
|
||||
|
||||
Reference in New Issue
Block a user