Package com.github.tommyettinger.textra
Class Font.FontFamily
java.lang.Object
com.github.tommyettinger.textra.Font.FontFamily
- Enclosing class:
- Font
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
Modifier and TypeFieldDescriptionfinal Font[]
Stores this Font and up to 15 other connected Fonts that can be switched between using [@Name] syntax.final CaseInsensitiveIntMap
Stores the names of Fonts (or aliases for those Fonts) as keys, mapped to ints between 0 and 15 inclusive. -
Constructor Summary
ConstructorDescriptionCreates 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 theFont.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 (allowingArray
to sometimes be used to get the items for fonts).FontFamily
(Font.FontFamily other) Copy constructor for another FontFamily.FontFamily
(FWSkin skin) 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 (allowingArray
to sometimes be used to get the items for aliases and fonts). -
Method Summary
Modifier and TypeMethodDescriptionGets the corresponding Font for a name/alias, or null if it was not found.void
resizeDistanceFields
(float width, float height) CallsFont.resizeDistanceField(float, float)
on each Font in this FontFamily.void
resizeDistanceFields
(float width, float height, com.badlogic.gdx.utils.viewport.Viewport viewport) CallsFont.resizeDistanceField(float, float, Viewport)
on each Font in this FontFamily.
-
Field Details
-
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
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 inconnected
. 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
Creates a FontFamily given an array of Font values, using theFont.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 byFont.setName(String)
-
FontFamily
Creates a FontFamily given an array of Font values that and offset/length values for those arrays (allowingArray
to sometimes be used to get the items for fonts). This uses theFont.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 indexlength
- how many items to use from fonts, if that many are provided
-
FontFamily
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 theFont.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
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 (allowingArray
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 theFont.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 indexlength
- how many items to use from aliases and fonts, if that many are provided
-
FontFamily
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 theFont.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 theBitmapFont.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 asFont.DistanceFieldType.STANDARD
). But, if you use aFWSkin
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
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 theFont.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 aSkin
variable, this constructor will not be used, instead choosingFontFamily(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
Copy constructor for another FontFamily. Font items inconnected
will not be copied, and the same references will be used.- Parameters:
other
- another, non-null, FontFamily to copy into this.
-
-
Method Details
-
get
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) CallsFont.resizeDistanceField(float, float)
on each Font in this FontFamily.- Parameters:
width
- the new window width; usually a parameter inApplicationListener.resize(int, int)
height
- the new window height; usually a parameter inApplicationListener.resize(int, int)
-
resizeDistanceFields
public void resizeDistanceFields(float width, float height, com.badlogic.gdx.utils.viewport.Viewport viewport) CallsFont.resizeDistanceField(float, float, Viewport)
on each Font in this FontFamily.- Parameters:
width
- the new window width; usually a parameter inApplicationListener.resize(int, int)
height
- the new window height; usually a parameter inApplicationListener.resize(int, int)
viewport
- the current Viewport, after it has been updated usingViewport.update(int, int)
-