Package com.castlabs.android.subtitles
Class SubtitleFonts
- java.lang.Object
-
- com.castlabs.android.subtitles.SubtitleFonts
-
public final class SubtitleFonts extends Object
This class contains static helpers and functions to manage additional fonts for subtitles and closed captions. 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:
With that module on place, the following fonts will be available:dependencies{ ... compile 'com.castlabs.player:subtitles-fonts:3.0.5' ... }
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) 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 usingsetVariant(Context, int, Typeface, int)
.- Since:
- 3.1.0
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interface
SubtitleFonts.SubtitleFont
-
Field Summary
Fields Modifier and Type Field Description static int
FONT_CASUAL
static int
FONT_CURSIVE
static int
FONT_DEFAULT
static int
FONT_SANS_SERIF
static int
FONT_SANS_SERIF_MONOSPACE
static int
FONT_SERIF
static int
FONT_SERIF_MONOSPACE
static int
FONT_SMALL_CAPITALS
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static void
addCustomFont(String familyName, Typeface typeface)
Register the "normal" variant of a custom font.static Typeface
get(int fontType, Context context)
Get the typeface for the given type.static Typeface
get(String familyName, Context context)
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(int fontType, Typeface typeface)
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 Detail
-
FONT_DEFAULT
public static final int FONT_DEFAULT
- See Also:
- Constant Field Values
-
FONT_SANS_SERIF
public static final int FONT_SANS_SERIF
- See Also:
- Constant Field Values
-
FONT_SANS_SERIF_MONOSPACE
public static final int FONT_SANS_SERIF_MONOSPACE
- See Also:
- Constant Field Values
-
FONT_SERIF
public static final int FONT_SERIF
- See Also:
- Constant Field Values
-
FONT_SERIF_MONOSPACE
public static final int FONT_SERIF_MONOSPACE
- See Also:
- Constant Field Values
-
FONT_CASUAL
public static final int FONT_CASUAL
- See Also:
- Constant Field Values
-
FONT_CURSIVE
public static final int FONT_CURSIVE
- See Also:
- Constant Field Values
-
FONT_SMALL_CAPITALS
public static final int FONT_SMALL_CAPITALS
- See Also:
- Constant Field Values
-
-
Method Detail
-
get
@NonNull public static Typeface get(int fontType, @NonNull Context context)
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
public static Typeface get(@NonNull String familyName, @NonNull Context context)
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
public static Typeface getVariant(Typeface source, int style)
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
public static void set(int fontType, Typeface typeface)
Set the typeface for a given type- Parameters:
fontType
- The typetypeface
- The typeface
-
addCustomFont
public static void addCustomFont(@NonNull String familyName, @NonNull Typeface typeface)
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
-
-