Class SubtitleFonts
To fulfill the FCC requirements for closed captions, you need to allow the user to select from different fonts, including "casual", "cursive", "small capitals", and a "serif monospace" font. These fonts are not available on all Android devices and this class allows to load custom fonts bundles with the assets of your Application.
The SDK comes bundles with an AAR file that contains some open fonts to fill the gaps. You can load the AAR by adding it to your apps' build script dependencies:
dependencies{
...
compile 'com.castlabs.player:subtitles-fonts:3.0.5'
...
}
With that module on place, the following fonts will be available:
Font | Type | License |
---|---|---|
MarckScript Regular | Casual | SIL OPEN FONT LICENSE Version 1.1 |
Lobster Two Regular | Cursive | SIL OPEN FONT LICENSE Version 1.1 |
Texgyrecursor Regular | Serif Monospace | GUST Font License Version 1.0 |
Uberlin | Small Capitals Regular | 1001Fonts Free For Commercial Use License (FFC) |
If you want to use different fonts, you can use the set(int, Typeface)
method
to initialize the font cache with different typefaces. This registeres the "normal" typeface
for a given font type. If you want to support styling like bold and italics for these custom
fonts, you need to register the variants as well using
setVariant(Context, int, Typeface, int)
.
- Since:
- 3.1.0
-
Nested Class Summary
-
Field Summary
Modifier and TypeFieldDescriptionstatic final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
-
Method Summary
Modifier and TypeMethodDescriptionstatic void
addCustomFont
(String familyName, Typeface typeface) Register the "normal" variant of a custom font.static Typeface
Get the typeface for the given type.static Typeface
Returns a Typeface that matches the given font family name.static Typeface
getVariant
(Typeface source, int style) Returns a typeface object that best matches the specified existing typeface and the specified Style.static void
Set the typeface for a given typestatic void
setVariant
(Context context, int source, Typeface variant, int variantStyle) Register a typeface variant for the given source typeface.static void
setVariant
(Typeface source, Typeface variant, int variantStyle) Register a typeface variant for the given source typeface.
-
Field Details
-
FONT_DEFAULT
public static final int FONT_DEFAULT- See Also:
-
FONT_SANS_SERIF
public static final int FONT_SANS_SERIF- See Also:
-
FONT_SANS_SERIF_MONOSPACE
public static final int FONT_SANS_SERIF_MONOSPACE- See Also:
-
FONT_SERIF
public static final int FONT_SERIF- See Also:
-
FONT_SERIF_MONOSPACE
public static final int FONT_SERIF_MONOSPACE- See Also:
-
FONT_CASUAL
public static final int FONT_CASUAL- See Also:
-
FONT_CURSIVE
public static final int FONT_CURSIVE- See Also:
-
FONT_SMALL_CAPITALS
public static final int FONT_SMALL_CAPITALS- See Also:
-
-
Method Details
-
get
Get the typeface for the given type. Unless a different variant was registered, this returns the "normal" variant of the given font type.- Parameters:
fontType
- The font typecontext
- The context- Returns:
- The typeface that maps to the given type
-
get
Returns a Typeface that matches the given font family name. If the family name is a generic font family (i.e. from a TTML file), this will return the typeface for the "normal" variant for that generic font. If the family name does not resolve to a generic font, any custom font families are checked. If also not custom font was found that matches the family name, the default typeface will be returned.- Parameters:
familyName
- The family namecontext
- The context- Returns:
- The typeface that best matches the given font family name
-
getVariant
Returns a typeface object that best matches the specified existing typeface and the specified Style. Use this call if you want to pick a new style from the same family of an existing typeface object.- Parameters:
source
- The source typefacestyle
- The style (normal, bold, italic) of the typeface. One ofTypeface.NORMAL
,Typeface.BOLD
,Typeface.ITALIC
, orTypeface.BOLD_ITALIC
- Returns:
- The best matching typeface.
-
setVariant
public static void setVariant(@NonNull Context context, int source, @NonNull Typeface variant, int variantStyle) Register a typeface variant for the given source typeface.- Parameters:
context
- The contextsource
- The source Typefacevariant
- The variant that will be registeredvariantStyle
- The variant styl. One ofTypeface.NORMAL
,Typeface.BOLD
,Typeface.ITALIC
, orTypeface.BOLD_ITALIC
-
setVariant
public static void setVariant(@NonNull Typeface source, @NonNull Typeface variant, int variantStyle) Register a typeface variant for the given source typeface.- Parameters:
source
- The source Typeface. This is the "normal" type and what you registered withset(int, Typeface)
variant
- The variant that will be registeredvariantStyle
- The variant styl. One ofTypeface.NORMAL
,Typeface.BOLD
,Typeface.ITALIC
, orTypeface.BOLD_ITALIC
-
set
Set the typeface for a given type- Parameters:
fontType
- The typetypeface
- The typeface
-
addCustomFont
Register the "normal" variant of a custom font. This is used to add custom font families that might be referenced from styled subtitle formats such as TTML. You should register the "normal" variant of the font here and then eventually add additional variants usingsetVariant(Typeface, Typeface, int)
. Please note that the family name here must be the same name also used in the TTML file that references the custom font.Please note that the generic TTML font types are already recognized by the SDK and there is no need to register them explicitly. This is only required for custom font families.
- Parameters:
familyName
- The family name (has to be the same as in the TTML file)typeface
- The typeface
-