Typeface.CustomFallbackBuilder
public
static
final
class
Typeface.CustomFallbackBuilder
extends Object
| java.lang.Object | |
| ↳ | android.graphics.Typeface.CustomFallbackBuilder |
A builder class for creating new Typeface instance. There are two font fallback mechanisms, custom font fallback and system font fallback. The custom font fallback is a simple ordered list. The text renderer tries to see if it can render a character with the first font and if that font does not support the character, try next one and so on. It will keep trying until end of the custom fallback chain. The maximum length of the custom fallback chain is 64. The system font fallback is a system pre-defined fallback chain. The system fallback is processed only when no matching font is found in the custom font fallback.
Examples, 1) Create Typeface from single ttf file.
Font font = new Font.Builder("your_font_file.ttf").build();
FontFamily family = new FontFamily.Builder(font).build();
Typeface typeface = new Typeface.CustomFallbackBuilder(family).build();
Font regularFont = new Font.Builder("regular.ttf").build();
Font boldFont = new Font.Builder("bold.ttf").build();
FontFamily family = new FontFamily.Builder(regularFont)
.addFont(boldFont).build();
Typeface typeface = new Typeface.CustomFallbackBuilder(family)
.setWeight(Font.FONT_WEIGHT_BOLD) // Set bold style as the default style.
// If the font family doesn't have bold style font,
// system will select the closest font.
.build();
Font font = new Font.Builder("your_font_file.ttf").build();
FontFamily family = new FontFamily.Builder(font).build();
Typeface typeface = new Typeface.CustomFallbackBuilder(family)
.setSystemFallback("serif") // Set serif font family as the fallback.
.build();
Font font = new Font.Builder("English.ttf").build();
FontFamily family = new FontFamily.Builder(font).build();
Font fallbackFont = new Font.Builder("Arabic.ttf").build();
FontFamily fallbackFamily = new FontFamily.Builder(fallbackFont).build();
Typeface typeface = new Typeface.CustomFallbackBuilder(family)
.addCustomFallback(fallbackFamily) // Specify fallback family.
.setSystemFallback("serif") // Set serif font family as the fallback.
.build();
Summary
Public constructors | |
|---|---|
CustomFallbackBuilder(FontFamily family)
Constructs a builder with a font family. |
|
Public methods | |
|---|---|
Typeface.CustomFallbackBuilder
|
addCustomFallback(FontFamily family)
Append a font family to the end of the custom font fallback. |
Typeface
|
build( |