Package com.castlabs.subtitles.presentation

# Class SubtitleFonts

java.lang.Object
com.castlabs.subtitles.presentation.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:

         dependencies{
             ...
             compile 'com.castlabs.player:subtitles-fonts:3.0.5'
             ...
         }

With that module on place, the following fonts will be available:

Additional Fonts in the Subtitles-Fonts module
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

  Nested Classes
  Modifier and Type
  Class
  Description
  `static @interface`
  `SubtitleFonts.SubtitleFont`

- ## Field Summary

  Fields
  Modifier and Type
  Field
  Description
  `static final int`
  `FONT_CASUAL`
  `static final int`
  `FONT_CURSIVE`
  `static final int`
  `FONT_DEFAULT`
  `static final int`
  `FONT_SANS_SERIF`
  `static final int`
  `FONT_SANS_SERIF_MONOSPACE`
  `static final int`
  `FONT_SERIF`
  `static final int`
  `FONT_SERIF_MONOSPACE`
  `static final int`
  `FONT_SMALL_CAPITALS`

- ## Method Summary

  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 type
  `static 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.

  ### Methods inherited from class java.lang.Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Field Details

  - ### 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 Details

  - ### 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 type
      `context` - 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 name
      `context` - 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 typeface
      `style` - The style (normal, bold, italic) of the typeface. One of `Typeface.NORMAL`, `Typeface.BOLD`, `Typeface.ITALIC`, or `Typeface.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 context
      `source` - The source Typeface
      `variant` - The variant that will be registered
      `variantStyle` - The variant styl. One of `Typeface.NORMAL`, `Typeface.BOLD`, `Typeface.ITALIC`, or `Typeface.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 with `set(int, Typeface)`
      `variant` - The variant that will be registered
      `variantStyle` - The variant styl. One of `Typeface.NORMAL`, `Typeface.BOLD`, `Typeface.ITALIC`, or `Typeface.BOLD_ITALIC`

  - ### set

    public static void set(int fontType, Typeface typeface)
    Set the typeface for a given type
    Parameters:
      `fontType` - The type
      `typeface` - 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 using `setVariant(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