Class Font.FontFamily

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

public static class Font.FontFamily
extends java.lang.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
    Font[] connected
    Stores this Font and up to 15 other connected Fonts that can be switched between using [@Name] syntax.
    CaseInsensitiveIntMap fontAliases
    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
    FontFamily()
    Creates a FontFamily that only allows staying on the same font, unless later configured otherwise.
    FontFamily​(com.badlogic.gdx.scenes.scene2d.ui.Skin skin)  
    FontFamily​(com.badlogic.gdx.utils.OrderedMap<java.lang.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).
    FontFamily​(Font.FontFamily other)
    Copy constructor for another FontFamily.
    FontFamily​(java.lang.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​(java.lang.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
    Font get​(java.lang.String name)
    Gets the corresponding Font for a name/alias, or null if it was not found.

    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​(java.lang.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​(java.lang.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<java.lang.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)
    • 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​(java.lang.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