Class Font.FontFamily

java.lang.Object
com.github.tommyettinger.textra.Font.FontFamily
Enclosing class:
Font

public static class Font.FontFamily extends Object
Holds up to 16 Font values, accessible by index or by name, that markup can switch between while rendering. This uses the [@Name] syntax. It is suggested that multiple Font objects share the same FontFamily so users can have the same names mean the same fonts reliably.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    final Font[]
    Stores this Font and up to 15 other connected Fonts that can be switched between using [@Name] syntax.
    Stores the names of Fonts (or aliases for those Fonts) as keys, mapped to ints between 0 and 15 inclusive.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Creates a FontFamily that only allows staying on the same font, unless later configured otherwise.
    FontFamily(com.badlogic.gdx.scenes.scene2d.ui.Skin skin)
    Constructs a FontFamily given a Skin that defines one or more BitmapFont items.
    FontFamily(com.badlogic.gdx.utils.OrderedMap<String,Font> map)
    Constructs a FontFamily given an OrderedMap of String keys (names of Fonts) to Font values (the Fonts that can be switched between).
    FontFamily(Font[] fonts)
    Creates a FontFamily given an array of Font values, using the Font.name of each Font as its alias.
    FontFamily(Font[] fonts, int offset, int length)
    Creates a FontFamily given an array of Font values that and offset/length values for those arrays (allowing Array to sometimes be used to get the items for fonts).
    Copy constructor for another FontFamily.
    Constructs a FontFamily given a FWSkin that defines one or more Font items.
    FontFamily(String[] aliases, Font[] fonts)
    Creates a FontFamily given an array of String names and a (almost-always same-sized) array of Font values that those names will refer to.
    FontFamily(String[] aliases, Font[] fonts, int offset, int length)
    Creates a FontFamily given an array of String names, a (almost-always same-sized) array of Font values that those names will refer to, and offset/length values for those arrays (allowing Array to sometimes be used to get the items for aliases and fonts).
  • Method Summary

    Modifier and Type
    Method
    Description
    get(String name)
    Gets the corresponding Font for a name/alias, or null if it was not found.
    void
    resizeDistanceFields(float width, float height)
    Calls Font.resizeDistanceField(float, float) on each Font in this FontFamily.
    void
    resizeDistanceFields(float width, float height, com.badlogic.gdx.utils.viewport.Viewport viewport)
    Calls Font.resizeDistanceField(float, float, Viewport) on each Font in this FontFamily.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • connected

      public final Font[] connected
      Stores this Font and up to 15 other connected Fonts that can be switched between using [@Name] syntax. If an item is null and this tries to switch to it, the font does not change.
    • fontAliases

      public final CaseInsensitiveIntMap fontAliases
      Stores the names of Fonts (or aliases for those Fonts) as keys, mapped to ints between 0 and 15 inclusive. The int values that this map keeps are stored in long glyphs and looked up as indices in connected. This map is case-insensitive when comparing keys or getting their values.
  • Constructor Details

    • FontFamily

      public FontFamily()
      Creates a FontFamily that only allows staying on the same font, unless later configured otherwise.
    • FontFamily

      public FontFamily(Font[] fonts)
      Creates a FontFamily given an array of Font values, using the Font.name of each Font as its alias. This allows switching to different fonts using the [@Name] syntax. This also registers aliases for the Strings "0" through up to "15" to refer to the Font values with the same indices (it can register fewer aliases than up to "15" if there are fewer than 16 Fonts). You should avoid using more than 16 fonts here.
      Parameters:
      fonts - a non-null array of Font values that should each have their name set (as by Font.setName(String)
    • FontFamily

      public FontFamily(Font[] fonts, int offset, int length)
      Creates a FontFamily given an array of Font values that and offset/length values for those arrays (allowing Array to sometimes be used to get the items for fonts). This uses the Font.name of each Font as its alias. This allows switching to different fonts using the [@Name] syntax. This registers aliases for the Strings "0" through up to "15" to refer to the Font values with the same indices (it can register fewer aliases than up to "15" if there are fewer than 16 Fonts). You should avoid using more than 16 fonts here.
      Parameters:
      fonts - an array of Font values that should have the same length as aliases (no more than 16)
      offset - where to start accessing fonts, as a non-negative index
      length - how many items to use from fonts, if that many are provided
    • FontFamily

      public FontFamily(String[] aliases, Font[] fonts)
      Creates a FontFamily given an array of String names and a (almost-always same-sized) array of Font values that those names will refer to. This allows switching to different fonts using the [@Name] syntax. This registers aliases for the Strings "0" through up to "15" to refer to the Font values with the same indices (it can register fewer aliases than up to "15" if there are fewer than 16 Fonts). It also registers the Font.name of each Font as an alias. You should avoid using more than 16 fonts here. You should avoid using more than 16 fonts with this.
      Parameters:
      aliases - a non-null array of up to 16 String names to use for fonts (individual items may be null)
      fonts - a non-null array of Font values that should have the same length as aliases (no more than 16)
    • FontFamily

      public FontFamily(String[] aliases, Font[] fonts, int offset, int length)
      Creates a FontFamily given an array of String names, a (almost-always same-sized) array of Font values that those names will refer to, and offset/length values for those arrays (allowing Array to sometimes be used to get the items for aliases and fonts). This allows switching to different fonts using the [@Name] syntax. This registers aliases for the Strings "0" through up to "15" to refer to the Font values with the same indices (it can register fewer aliases than up to "15" if there are fewer than 16 Fonts). It also registers the Font.name of each Font as an alias. You should avoid using more than 16 fonts here.
      Parameters:
      aliases - an array of up to 16 String names to use for fonts (individual items may be null)
      fonts - an array of Font values that should have the same length as aliases (no more than 16)
      offset - where to start accessing aliases and fonts, as a non-negative index
      length - how many items to use from aliases and fonts, if that many are provided
    • FontFamily

      public FontFamily(com.badlogic.gdx.utils.OrderedMap<String,Font> map)
      Constructs a FontFamily given an OrderedMap of String keys (names of Fonts) to Font values (the Fonts that can be switched between). This registers the Strings "0" up to "15" to be aliases for the Fonts with those indices in the map. It also registers the Font.name of each Font as an alias. This only uses up to the first 16 keys of map.
      Parameters:
      map - an OrderedMap of String keys to Font values
    • FontFamily

      public FontFamily(com.badlogic.gdx.scenes.scene2d.ui.Skin skin)
      Constructs a FontFamily given a Skin that defines one or more BitmapFont items. The name in the Skin file for each font is one way you will be able to access fonts from this family. You can also use the BitmapFont.BitmapFontData.name of a BitmapFont in the Skin as an alias, or the essentially-randomly-chosen index of the BitmapFont in the order this encountered it. Note that this constructor does not handle distance field fonts (it treats all fonts as Font.DistanceFieldType.STANDARD). But, if you use a FWSkin instead of a Skin, it will try to load Fonts instead of BitmapFonts, and Font supports distance fields.
      Parameters:
      skin - a non-null Skin that defines one or more BitmapFont items
    • FontFamily

      public FontFamily(FWSkin skin)
      Constructs a FontFamily given a FWSkin that defines one or more Font items. The name in the Skin file for each font is one way you will be able to access fonts from this family. You can also use the Font.name of a Font in the Skin as an alias, or the essentially-randomly-chosen index of the Font in the order this encountered it. Note that if you store an FWSkin in a Skin variable, this constructor will not be used, instead choosing FontFamily(Skin), and that constructor doesn't handle any distance field fonts correctly.
      Parameters:
      skin - a non-null FWSkin or subclass that defines one or more Font items
    • FontFamily

      public FontFamily(Font.FontFamily other)
      Copy constructor for another FontFamily. Font items in connected will not be copied, and the same references will be used.
      Parameters:
      other - another, non-null, FontFamily to copy into this.
  • Method Details

    • get

      public Font get(String name)
      Gets the corresponding Font for a name/alias, or null if it was not found.
      Parameters:
      name - a name or alias for a font, such as "Gentium" or "2"
      Returns:
      the Font corresponding to the given name, or null if not found
    • resizeDistanceFields

      public void resizeDistanceFields(float width, float height)
      Calls Font.resizeDistanceField(float, float) on each Font in this FontFamily.
      Parameters:
      width - the new window width; usually a parameter in ApplicationListener.resize(int, int)
      height - the new window height; usually a parameter in ApplicationListener.resize(int, int)
    • resizeDistanceFields

      public void resizeDistanceFields(float width, float height, com.badlogic.gdx.utils.viewport.Viewport viewport)
      Calls Font.resizeDistanceField(float, float, Viewport) on each Font in this FontFamily.
      Parameters:
      width - the new window width; usually a parameter in ApplicationListener.resize(int, int)
      height - the new window height; usually a parameter in ApplicationListener.resize(int, int)
      viewport - the current Viewport, after it has been updated using Viewport.update(int, int)