Class Font

java.lang.Object
com.github.tommyettinger.textra.Font
All Implemented Interfaces:
com.badlogic.gdx.utils.Disposable

public class Font extends Object implements com.badlogic.gdx.utils.Disposable
A replacement for libGDX's BitmapFont class, supporting additional markup to allow styling text with various effects. This includes the commonly-requested "faux bold" and oblique mode using one font image; you don't need a bold and italic/oblique image separate from the book face. This also supports underline, strikethrough, subscript/superscript (and "midscript," for a height between the two), color markup, scale/size markup, and the option to switch to other Fonts from a family of several.
A Font represents either one size of a "standard" bitmap font (which can be drawn scaled up or down), or many sizes of a distance field font (using either the commonly-used SDF format or newer MSDF format). The same class is used for standard, SDF, and MSDF fonts, but you call enableShader(Batch) before rendering with SDF or MSDF fonts, and can switch back to a normal SpriteBatch shader with batch.setShader(null);. The TextraLabel and TypingLabel classes handle the calls to enableShader() for you. You don't have to use SDF or MSDF fonts, but they can scale more cleanly. MSDF looks the sharpest in general, but SDF can display inline with emoji or other colorful icons, without changing the shader. "Standard" fonts look the best when mixing different Fonts in one piece of text, and also have the best compatibility with emoji and other icons. There's also the Font.DistanceFieldType.SDF_OUTLINE distance field mode, which you can change an SDF font to use; it draws fairly sharply, but also adds a thick black outline around everything that uses SDF.
You can generate SDF fonts with Hiero or a related tool that is part of libGDX; MSDF fonts need a different tool, like maltaisn's msdf-gdx-gen (good for fonts with few chars) or fontwriter (recommended, but Windows-only). Using fontwriter means you get Structured JSON Font files instead of AngelCode BMFont files; these can be loaded with Font(String, TextureRegion, float, float, float, float, boolean, boolean). Structured JSON Fonts can be SDF, MSDF, standard (no distance field), or some other kinds of font; the information about this is stored in the font. You can also load a libGDX BitmapFont with a Structured JSON Font using the BitmapFontSupport class. If you want a .fnt file instead for an MSDF font, msdf-gdx-gen does work, but has an uneven baseline if you put too many chars in a font, or use too small of a texture size.
This interacts with the Layout class, with a Layout referencing a Font, and various methods in Font taking a Layout. You usually want to have a Layout for any text you draw repeatedly, and draw that Layout each frame with drawGlyphs(Batch, Layout, float, float, int) or a similar method.
The TypingLabel class has its own markup that generally has an equivalent for all the markup options here. This class has some special behavior for both the square-bracket markup used here and the curly-bracket markup used by TypingLabel, even if the markup isn't actually used in a TypingLabel. In particular, anything in curly brackets is ignored and left alone when markup() is called, and is not considered part of the size of the Layout. Anything inside single curly braces is not rendered here, though it may be interpreted by TypingLabel if you use a Layout this produces there. You should escape both square brackets with [[ and curly braces with {{ if you intend them to appear. You can change the behavior of curly braces by setting omitCurlyBraces to false; this will make curly braces and their contents parse as normal text (the default setting is true). If curly braces have a special meaning in some other markup you use, like I18N bundles, you can change a curly-brace tag such as {RESET} to [-RESET], with the - at the start making it ignored by markup here but usable to TypingLabel.
Most things this can draw can be drawn with a rotation, and usually an origin can be specified (where it makes sense). The rotation can't be configured from markup, but the widgets that understand this class, like TextraLabel and TypingLabel, can have their rotation set using the standard scene2d.ui method Actor.setRotation(float), and then they will request the correct rotation from this class. This is different from Label, which ignores rotation!
There are some features here that cannot be used purely from markup, such as per-character rotation and smooth scaling, but these can be used by TypingLabel and its Effect assortment.
See Also:
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static enum 
    Defines what types of distance field font this can use and render.
    static class 
    Holds up to 16 Font values, accessible by index or by name, that markup can switch between while rendering.
    static class 
    Describes the region of a glyph in a larger TextureRegion, carrying a little more info about the offsets that apply to where the glyph is rendered.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    float
    When distanceField is Font.DistanceFieldType.SDF, Font.DistanceFieldType.MSDF, or Font.DistanceFieldType.SDF_OUTLINE, this determines how much the edges of the glyphs should be aliased sharply (higher values) or anti-aliased softly (lower values).
    static final long
    Bit flag for alternate mode, as a long.
    static final long
    Bit flag for matching alternate modes, as a long.
    static final long
    Bit flag for black outline mode, as a long.
    static final long
    Bit flag for bold mode, as a long.
    float
    A multiplier that applies to the distance bold text will stretch away from the original glyph outline.
    float
    When makeGridGlyphs is passed as true to a constructor here, box drawing and other block elements will be drawn using a solid block GlyphRegion that is stretched and moved to form various lines and blocks.
    float
    Refers to the largest height of any glyph in the font, after scaling.
    float
    Only actually refers to a "cell" when isMono is true; otherwise refers to the largest width of any glyph in the font, after scaling.
    static final regexodus.Replacer
    A RegExodus Replacer that replaces any CJK ideographic characters with themselves plus a zero-width space after.
    Determines how colors are looked up by name; defaults to using ColorUtils.describe(String).
    Which GlyphRegion to display if a char isn't found in mapping.
    float
    How far the unscaled font descends below the baseline, typically as a negative number (not always).
     
    float
    When distanceField is Font.DistanceFieldType.SDF, Font.DistanceFieldType.MSDF, or Font.DistanceFieldType.SDF_OUTLINE, this determines how much the edges of the glyphs should be aliased sharply (higher values) or anti-aliased softly (lower values).
    static final long
    Bit flag for drop shadow mode, as a long.
    boolean
    If true (the default), square bracket markup functions as documented in markup(String, Layout).
    static final long
    Bit flag for error mode, shown as a red wiggly-underline, as a long.
    If non-null, may contain connected Font values and names/aliases to look them up with using [@Name] syntax.
    float
    Precise adjustment for the x-position of "fancy lines" such as error, warning, and note effects, affecting the left side of the line.
    float
    Precise adjustment for the y-position of "fancy lines" such as error, warning, and note effects, affecting the bottom side of the line.
    float
    The height-adjustment this Font was initialized with, or 0 if there was none given.
    float
    An adjustment added to the Font.GlyphRegion.offsetX of any inline images added with addAtlas(TextureAtlas, String, String, float, float, float) (or its overloads).
    float
    An adjustment added to the Font.GlyphRegion.offsetY of any inline images added with addAtlas(TextureAtlas, String, String, float, float, float) (or its overloads).
    float
    An adjustment added to the xAdvance(com.github.tommyettinger.textra.Font, float, long) of any inline images added with addAtlas(TextureAtlas, String, String, float, float, float) (or its overloads).
    boolean
    By default, this doesn't do anything; subclasses can override handleIntegerPosition(float) to try to do something different with it.
    boolean
    If true, this is a fixed-width (monospace) font; if false, this is probably a variable-width font.
    static final long
    Bit flag for "jostle" mode, as a long.
    com.badlogic.gdx.utils.IntFloatMap
    Unlikely to be used externally, this is one way of storing the kerning information that some fonts have.
    com.badlogic.gdx.utils.IntMap<Font.GlyphRegion>
    Maps char keys (stored as ints) to their corresponding Font.GlyphRegion values.
    static final long
    Bit flag for midscript mode, as a long.
    static final String
    Fragment shader source meant for MSDF fonts.
    The name of the Font, for display purposes.
    Optional; maps the names of TextureRegions to the indices they use in mapping, and usually assigned by addAtlas(TextureAtlas).
    com.badlogic.gdx.utils.IntMap<String>
    Optional; a reversed form of nameLookup that allows you to get the printable name for a given char code.
    static final long
    Bit flag for note mode, shown as a blue wavy-underline, as a long.
    static final long
    Bit flag for oblique mode, as a long.
    float
    A multiplier that applies to the horizontal movement associated with oblique text (which is similar to italic).
    boolean
    If true (the default), any text inside matching curly braces, plus the curly braces themselves, will be ignored during rendering and not displayed.
    float
    Refers to the largest height of any glyph in the font, before any scaling.
    float
    Only actually refers to a "cell" when isMono is true; otherwise refers to the largest width of any glyph in the font, before any scaling.
    float
    A multiplier that applies to the distance the "blacken" and "whiten" outlines will stretch away from the original glyph edge.
    float
    The color black, as a packed float using the default RGBA color space.
    float
    The color to use for ERROR's underline, as a packed float using the default RGBA color space.
    float
    The color to use for NOTE's underline, as a packed float using the default RGBA color space.
    float
    The color to use for DROP_SHADOW, as a packed float using the default RGBA color space.
    float
    The color to use for WARN's underline, as a packed float using the default RGBA color space.
    float
    The color white, as a packed float using the default RGBA color space.
    com.badlogic.gdx.utils.Array<com.badlogic.gdx.graphics.g2d.TextureRegion>
    The larger TextureRegions that Font.GlyphRegion images are pulled from; these could be whole Textures or be drawn from a TextureAtlas that the font shares with other images.
    float
    Scale multiplier for width.
    float
    Scale multiplier for height.
    static final String
    A modified version of the fragment shader for SDF fonts from DistanceFieldFont, this draws a moderately thick black outline around each glyph, with the outline respecting the transparency of the glyph (unlike BLACK_OUTLINE mode).
    static final String
    A modified version of the fragment shader for SDF fonts from DistanceFieldFont, now supporting RGB colors other than white (but with limited support for partial transparency).
    com.badlogic.gdx.graphics.glutils.ShaderProgram
    The ShaderProgram used to render this font, as used by enableShader(Batch).
    static final long
    Bit flag for shiny mode, as a long.
    static final long
    Bit flag for small caps mode, as a long.
    char
    A char that will be used to draw solid blocks with drawBlocks(Batch, int[][], float, float), and to draw box-drawing/block-element characters if makeGridGlyphs is true in the constructor.
    float
    Precise adjustment for the strikethrough's y-size, affecting how thick the strikethrough is from bottom to top.
    float
    Precise adjustment for the strikethrough's x-size, affecting the extra strikethrough drawn to the right of the strikethrough.
    static final long
    Bit flag for strikethrough mode, as a long.
    float
    Precise adjustment for the strikethrough's x-position, affecting the left side of the strikethrough.
    float
    Precise adjustment for the strikethrough's y-position, affecting the bottom side of the strikethrough.
    static final long
    Bit flag for subscript mode, as a long.
    static final long
    Two-bit flag for superscript mode, as a long.
    float
    Precise adjustment for the underline's y-size, affecting how thick the underline is from bottom to top.
    float
    Precise adjustment for the underline's x-size, affecting the extra underline drawn to the right of the underline.
    static final long
    Bit flag for underline mode, as a long.
    float
    Precise adjustment for the underline's x-position, affecting the left side of the underline.
    float
    Precise adjustment for the underline's y-position, affecting the bottom side of the underline.
    static final String
    The standard libGDX vertex shader source, which is also used by the SDF and MSDF shaders.
    static final long
    Bit flag for warning mode, shown as a yellow barred-underline, as a long.
    static final long
    Bit flag for white outline mode, as a long.
    com.badlogic.gdx.graphics.Texture
    A white square Texture, typically 3x3, that can be used as a backup in case a Font doesn't have a solid block character available to it already (such as for many Fonts created from BitmapFonts).
    float
    The width-adjustment this Font was initialized with, or 0 if there was none given.
    float
    The x-adjustment this Font was initialized with, or 0 if there was none given.
    float
    The y-adjustment this Font was initialized with, or 0 if there was none given.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Constructs a Font from a newly-created default BitmapFont, as by BitmapFont(), passing it to Font(BitmapFont, float, float, float, float).
    Font(com.badlogic.gdx.files.FileHandle jsonHandle, com.badlogic.gdx.graphics.g2d.TextureRegion textureRegion, boolean ignoredStructuredJsonFlag)
    Creates a Font from a "Structured JSON" file produced by Chlumsky's msdf-atlas-gen tool, and uses it to assemble the many Font.GlyphRegions this has for each glyph.
    Font(com.badlogic.gdx.files.FileHandle jsonHandle, com.badlogic.gdx.graphics.g2d.TextureRegion textureRegion, float xAdjust, float yAdjust, float widthAdjust, float heightAdjust, boolean makeGridGlyphs, boolean ignoredStructuredJsonFlag)
    Creates a Font from a "Structured JSON" file produced by Chlumsky's msdf-atlas-gen tool, and uses it to assemble the many Font.GlyphRegions this has for each glyph.
    Font(com.badlogic.gdx.files.FileHandle fntHandle, com.badlogic.gdx.graphics.g2d.TextureRegion textureRegion, Font.DistanceFieldType distanceField, float xAdjust, float yAdjust, float widthAdjust, float heightAdjust, boolean makeGridGlyphs)
    Constructs a font based off of an AngelCode BMFont .fnt file and the given TextureRegion that holds all of its glyphs, with the specified distance field effect.
    Font(com.badlogic.gdx.files.FileHandle fntHandle, com.badlogic.gdx.utils.Array<com.badlogic.gdx.graphics.g2d.TextureRegion> textureRegions, Font.DistanceFieldType distanceField, float xAdjust, float yAdjust, float widthAdjust, float heightAdjust, boolean makeGridGlyphs)
    Constructs a font based off of an AngelCode BMFont .fnt file, with the given TextureRegion Array and specified distance field effect.
    Font(com.badlogic.gdx.files.FileHandle fntHandle, Font.DistanceFieldType distanceField, float xAdjust, float yAdjust, float widthAdjust, float heightAdjust, boolean makeGridGlyphs)
    Constructs a new Font by reading in a .fnt file from the given FileHandle and loading any images specified in that file.
    Font(com.badlogic.gdx.graphics.g2d.BitmapFont bmFont)
    Constructs a new Font from the existing BitmapFont, using its same Textures and TextureRegions for glyphs, and without a distance field effect or any adjustments to position except for a y offset equal to BitmapFont.getDescent().
    Font(com.badlogic.gdx.graphics.g2d.BitmapFont bmFont, float xAdjust, float yAdjust, float widthAdjust, float heightAdjust)
    Constructs a new Font from the existing BitmapFont, using its same Textures and TextureRegions for glyphs, and without a distance field effect.
    Font(com.badlogic.gdx.graphics.g2d.BitmapFont bmFont, Font.DistanceFieldType distanceField, float xAdjust, float yAdjust, float widthAdjust, float heightAdjust)
    Constructs a new Font from the existing BitmapFont, using its same Textures and TextureRegions for glyphs, and with the specified distance field effect.
    Font(com.badlogic.gdx.graphics.g2d.BitmapFont bmFont, Font.DistanceFieldType distanceField, float xAdjust, float yAdjust, float widthAdjust, float heightAdjust, boolean makeGridGlyphs)
    Constructs a new Font from the existing BitmapFont, using its same Textures and TextureRegions for glyphs, and with the specified distance field effect.
    Font(Font toCopy)
    Copy constructor; does not copy the font's shader or colorLookup, if it has them (it uses the same reference for the new Font), but will fully copy everything else.
    Font(String fntName)
    Constructs a Font by reading in the given .fnt file and loading any images it specifies.
    Font(String jsonName, boolean ignoredStructuredJsonFlag)
    Creates a Font from a "Structured JSON" file produced by Chlumsky's msdf-atlas-gen tool, and uses it to assemble the many Font.GlyphRegions this has for each glyph.
    Font(String fntName, float xAdjust, float yAdjust, float widthAdjust, float heightAdjust)
    Constructs a new Font by reading in a .fnt file with the given name (an internal handle is tried first, then a local handle) and loading any images specified in that file.
    Font(String jsonName, com.badlogic.gdx.graphics.g2d.TextureRegion textureRegion, boolean makeGridGlyphs, boolean ignoredStructuredJsonFlag)
    Creates a Font from a "Structured JSON" file produced by Chlumsky's msdf-atlas-gen tool, and uses it to assemble the many Font.GlyphRegions this has for each glyph.
    Font(String fntName, com.badlogic.gdx.graphics.g2d.TextureRegion textureRegion, float xAdjust, float yAdjust, float widthAdjust, float heightAdjust)
    Constructs a font using the given TextureRegion that holds all of its glyphs, with no distance field effect.
    Font(String jsonName, com.badlogic.gdx.graphics.g2d.TextureRegion textureRegion, float xAdjust, float yAdjust, float widthAdjust, float heightAdjust, boolean makeGridGlyphs, boolean ignoredStructuredJsonFlag)
    Creates a Font from a "Structured JSON" file produced by Chlumsky's msdf-atlas-gen tool, and uses it to assemble the many Font.GlyphRegions this has for each glyph.
    Font(String fntName, com.badlogic.gdx.graphics.g2d.TextureRegion textureRegion, Font.DistanceFieldType distanceField, float xAdjust, float yAdjust, float widthAdjust, float heightAdjust)
    Constructs a font based off of an AngelCode BMFont .fnt file and the given TextureRegion that holds all of its glyphs, with the specified distance field effect.
    Font(String fntName, com.badlogic.gdx.graphics.g2d.TextureRegion textureRegion, Font.DistanceFieldType distanceField, float xAdjust, float yAdjust, float widthAdjust, float heightAdjust, boolean makeGridGlyphs)
    Constructs a font based off of an AngelCode BMFont .fnt file and the given TextureRegion that holds all of its glyphs, with the specified distance field effect.
    Font(String fntName, com.badlogic.gdx.utils.Array<com.badlogic.gdx.graphics.g2d.TextureRegion> textureRegions, float xAdjust, float yAdjust, float widthAdjust, float heightAdjust)
    Constructs a font based off of an AngelCode BMFont .fnt file and the given TextureRegion Array, with no distance field effect.
    Font(String fntName, com.badlogic.gdx.utils.Array<com.badlogic.gdx.graphics.g2d.TextureRegion> textureRegions, Font.DistanceFieldType distanceField, float xAdjust, float yAdjust, float widthAdjust, float heightAdjust)
    Constructs a font based off of an AngelCode BMFont .fnt file, with the given TextureRegion Array and specified distance field effect.
    Font(String fntName, com.badlogic.gdx.utils.Array<com.badlogic.gdx.graphics.g2d.TextureRegion> textureRegions, Font.DistanceFieldType distanceField, float xAdjust, float yAdjust, float widthAdjust, float heightAdjust, boolean makeGridGlyphs)
    Constructs a font based off of an AngelCode BMFont .fnt file, with the given TextureRegion Array and specified distance field effect.
    Font(String fntName, Font.DistanceFieldType distanceField)
    Constructs a Font by reading in the given .fnt file and loading any images it specifies.
    Font(String fntName, Font.DistanceFieldType distanceField, float xAdjust, float yAdjust, float widthAdjust, float heightAdjust)
    Constructs a new Font by reading in a .fnt file with the given name (an internal handle is tried first, then a local handle) and loading any images specified in that file.
    Font(String fntName, Font.DistanceFieldType distanceField, float xAdjust, float yAdjust, float widthAdjust, float heightAdjust, boolean makeGridGlyphs)
    Constructs a new Font by reading in a .fnt file with the given name (an internal handle is tried first, then a local handle) and loading any images specified in that file.
    Font(String fntName, String textureName)
    Constructs a Font by reading in the given .fnt file and the given Texture by filename.
    Font(String prefix, String fntName, boolean ignoredSadConsoleFlag)
    Constructs a new Font by reading in a SadConsole .font file with the given name (an internal handle is tried first, then a local handle) and loading any images specified in that file.
    Font(String fntName, String textureName, float xAdjust, float yAdjust, float widthAdjust, float heightAdjust)
    Constructs a new Font by reading in a Texture from the given named path (internal is tried, then local), and no distance field effect.
    Font(String fntName, String textureName, Font.DistanceFieldType distanceField)
    Constructs a Font by reading in the given .fnt file and the given Texture by filename.
    Font(String fntName, String textureName, Font.DistanceFieldType distanceField, float xAdjust, float yAdjust, float widthAdjust, float heightAdjust)
    Constructs a new Font by reading in a Texture from the given named path (internal is tried, then local), and the specified distance field effect.
    Font(String fntName, String textureName, Font.DistanceFieldType distanceField, float xAdjust, float yAdjust, float widthAdjust, float heightAdjust, boolean makeGridGlyphs)
    Constructs a new Font by reading in a Texture from the given named path (internal is tried, then local), and the specified distance field effect.
  • Method Summary

    Modifier and Type
    Method
    Description
    addAtlas(com.badlogic.gdx.graphics.g2d.TextureAtlas atlas)
    Adds all items in atlas to the private use area of mapping, and stores their names, so they can be looked up with [+saxophone] syntax (which is often the same as the [+🎷] syntax).
    addAtlas(com.badlogic.gdx.graphics.g2d.TextureAtlas atlas, float offsetXChange, float offsetYChange, float xAdvanceChange)
    Adds all items in atlas to the private use area of mapping, and stores their names, so they can be looked up with [+saxophone] syntax (which is often the same as the [+🎷] syntax).
    addAtlas(com.badlogic.gdx.graphics.g2d.TextureAtlas atlas, String prepend, String append, float offsetXChange, float offsetYChange, float xAdvanceChange)
    Adds all items in atlas to the private use area of mapping, and stores their names, so they can be looked up with [+saxophone] syntax (which is often the same as the [+🎷] syntax).
    addImage(String character, com.badlogic.gdx.graphics.g2d.TextureRegion region)
    Makes this Font "learn" a new mapping from a char (typically an emoji in a String for character) to a TextureRegion.
    addImage(String character, com.badlogic.gdx.graphics.g2d.TextureRegion region, float offsetX, float offsetY, float xAdvance)
    Makes this Font "learn" a new mapping from a char (typically an emoji in a String for character) to a TextureRegion, allowing any offsets on x or y to be specified as well as the amount of horizontal space the resulting GlyphRegion should use.
    adjustCellWidth(float multiplier)
    Multiplies the width used by each glyph in a monospaced font by multiplier without changing the size of any characters.
    adjustLineHeight(float multiplier)
    Multiplies the line height by multiplier without changing the size of any characters.
    static long
    applyChar(long glyph, char c)
    Replaces the section of glyph that stores its char with the given other char.
    static long
    applyColor(long glyph, int color)
    Replaces the section of glyph that stores its color with the given RGBA8888 int color.
    static long
    applyMode(long glyph, long modeFlags)
    Replaces the section of glyph that stores its alternate mode (which is the same section that stores its scale) with the given bit flags representing a mode (or lack of one).
    static long
    applyScale(long glyph, float scale)
    Replaces the section of glyph that stores its scale with the given float multiplier, rounded to a multiple of 0.25 and wrapped to within 0.0 to 3.75, both inclusive.
    static long
    applyStyle(long glyph, long style)
    Replaces the section of glyph that stores its style with the given long bits.You can get the bit constants with BOLD, OBLIQUE, UNDERLINE, STRIKETHROUGH, SUBSCRIPT, MIDSCRIPT, and SUPERSCRIPT.
    int
    Gets the char that might be associated with name in at Atlas added to this (see addAtlas(TextureAtlas), or returns the int -1 if the name could not be found.
    float
    Given a Layout that uses this Font, this will recalculate the width and height of each Line in layout, changing the values in layout if they are incorrect.
    float
    Measures the actual width that the given Line will use when drawn, and sets it into the Line's Line.width field.
    float
    calculateXAdvances(Line line, com.badlogic.gdx.utils.FloatArray advances)
    Not meant for general use; calculates the x-positions before every glyph in line, including invisible ones.
    static void
     
    void
    Releases all resources of this object.
    void
    drawBlocks(com.badlogic.gdx.graphics.g2d.Batch batch, char blockChar, int[][] colors, float x, float y)
    Draws a grid made of rectangular blocks of int colors (typically RGBA) at the given x,y position in world space.
    void
    drawBlocks(com.badlogic.gdx.graphics.g2d.Batch batch, int[][] colors, float x, float y)
    Draws a grid made of rectangular blocks of int colors (typically RGBA) at the given x,y position in world space.
    protected void
    drawBlockSequence(com.badlogic.gdx.graphics.g2d.Batch batch, float[] sequence, com.badlogic.gdx.graphics.g2d.TextureRegion block, float color, float x, float y, float width, float height, float rotation)
    An internal method that draws blocks in a sequence specified by a float[], with the block usually solidBlock (but not always).
    protected void
    drawBlockSequence(com.badlogic.gdx.graphics.g2d.Batch batch, float[] sequence, com.badlogic.gdx.graphics.g2d.TextureRegion block, float color, float x, float y, float width, float height, float rotation, float breadth)
    An internal method that draws blocks in a sequence specified by a float[], with the block usually solidBlock (but not always).
    protected void
    drawFancyLine(com.badlogic.gdx.graphics.g2d.Batch batch, long mode, float x, float y, float width, float xPx, float yPx, float rotation)
    An internal method that draws blocks in a sequence specified by a mode, with the block always solidBlock.
    float
    drawGlyph(com.badlogic.gdx.graphics.g2d.Batch batch, long glyph, float x, float y)
    Draws the specified glyph with a Batch at the given x, y position.
    float
    drawGlyph(com.badlogic.gdx.graphics.g2d.Batch batch, long glyph, float x, float y, float rotation)
    Draws the specified glyph with a Batch at the given x, y position and with the specified counterclockwise rotation, measured in degrees.
    float
    drawGlyph(com.badlogic.gdx.graphics.g2d.Batch batch, long glyph, float x, float y, float rotation, float sizingX, float sizingY)
    Draws the specified glyph with a Batch at the given x, y position, with the specified counterclockwise rotation, measured in degrees, and with the specified x and y sizing/scaling, which are meant to be treated independently of the incremental scales in a glyph, and can be smooth.
    float
    drawGlyph(com.badlogic.gdx.graphics.g2d.Batch batch, long glyph, float x, float y, float rotation, float sizingX, float sizingY, int backgroundColor)
    Draws the specified glyph with a Batch at the given x, y position, with the specified counterclockwise rotation, measured in degrees, and with the specified x and y sizing/scaling, which are meant to be treated independently of the incremental scales in a glyph, and can be smooth.
    float
    drawGlyphs(com.badlogic.gdx.graphics.g2d.Batch batch, Layout glyphs, float x, float y)
    Draws the specified Layout of glyphs with a Batch at a given x, y position, drawing the full layout.
    float
    drawGlyphs(com.badlogic.gdx.graphics.g2d.Batch batch, Layout glyphs, float x, float y, int align)
    Draws the specified Layout of glyphs with a Batch at a given x, y position, using align to determine how to position the text.
    float
    drawGlyphs(com.badlogic.gdx.graphics.g2d.Batch batch, Layout glyphs, float x, float y, int align, float rotation, float originX, float originY)
    Draws the specified Layout of glyphs with a Batch at a given x, y position, rotated using dedegrees around the given origin point, using align to determine how to position the text.
    float
    drawGlyphs(com.badlogic.gdx.graphics.g2d.Batch batch, Line glyphs, float x, float y)
    Draws the specified Line of glyphs with a Batch at a given x, y position, drawing the full Line using left alignment.
    float
    drawGlyphs(com.badlogic.gdx.graphics.g2d.Batch batch, Line glyphs, float x, float y, int align)
    Draws the specified Line of glyphs with a Batch at a given x, y position, using align to determine how to position the text.
    float
    drawGlyphs(com.badlogic.gdx.graphics.g2d.Batch batch, Line glyphs, float x, float y, int align, float rotation, float originX, float originY)
    Draws the specified Line of glyphs with a Batch at a given x, y position, rotated using degrees around the given origin point, using align to determine how to position the text.
    int
    drawMarkupText(com.badlogic.gdx.graphics.g2d.Batch batch, String text, float x, float y)
    Draws the specified text at the given x,y position (in world space), parsing an extension of libGDX markup and using it to determine color, size, position, shape, strikethrough, underline, case, and scale of the given CharSequence.
    void
    drawText(com.badlogic.gdx.graphics.g2d.Batch batch, CharSequence text, float x, float y)
    Draws the specified text at the given x,y position (in world space) with a white foreground.
    void
    drawText(com.badlogic.gdx.graphics.g2d.Batch batch, CharSequence text, float x, float y, int color)
    Draws the specified text at the given x,y position (in world space) with the given foreground color.
    protected void
    drawVertices(com.badlogic.gdx.graphics.g2d.Batch batch, com.badlogic.gdx.graphics.Texture texture, float[] vertices)
    Given a 20-item float array (almost always vertices in this class) and a Texture to draw (part of), this draws some part of the Texture using the given Batch.
    void
    enableShader(com.badlogic.gdx.graphics.g2d.Batch batch)
    Must be called before drawing anything with an SDF or MSDF font; does not need to be called for other fonts unless you are mixing them with SDF/MSDF fonts or other shaders.
    static char
    extractChar(long glyph)
    Given a glyph as a long, this returns the char it displays.
    static int
    extractColor(long glyph)
    Given a glyph as a long, this returns the RGBA8888 color it uses.
    static long
    extractMode(long glyph)
    Given a glyph as a long, this returns the bit flags for the current mode, if alternate mode is enabled.
    static float
    extractScale(long glyph)
    Given a glyph as a long, this returns the float multiplier it uses for scale.
    static long
    extractStyle(long glyph)
    Given a glyph as a long, this returns the style bits it uses.
    fitCell(float width, float height, boolean center)
    Fits all chars into cells width by height in size, and optionally centers them in their cells.
    float
     
    float
    When makeGridGlyphs is passed as true to a constructor here, box drawing and other block elements will be drawn using a solid block GlyphRegion that is stretched and moved to form various lines and blocks.
    Gets the ColorLookup this uses to look up colors by name.
    float
    Gets the "crispness" multiplier for distance field fonts (SDF and MSDF).
    float
     
    A Font.DistanceFieldType that should be Font.DistanceFieldType.STANDARD for most fonts, and can be Font.DistanceFieldType.SDF, Font.DistanceFieldType.MSDF, or Font.DistanceFieldType.SDF_OUTLINE if you know you have a font made to be used with one of those rendering techniques.
    Gets the FontFamily this can use to switch fonts using [@Name] syntax.
    float
     
    float
     
    float
     
    float
     
    float
     
     
    float
     
    float
     
    long
    getStoredState(String name, long fallback)
    Looks up the given name in the stored states and returns the associated formatting state, or fallback if the name was not present.
    float
     
    float
     
    float
     
    float
     
    protected boolean
     
    protected float
    Currently, this is only an extension point for code that wants to ensure integer positions; it does nothing on its own other than return its argument unchanged.
    static String
    Inserts a zero-width space character (Unicode U+200B) after every CJK ideographic character in text.
    int
    kerningPair(char first, char second)
    Assembles two chars into a kerning pair that can be looked up as a key in kerning.
    protected void
    loadFNT(com.badlogic.gdx.files.FileHandle fntHandle, float xAdjust, float yAdjust, float widthAdjust, float heightAdjust, boolean makeGridGlyphs)
    The gritty parsing code that pulls relevant info from an AngelCode BMFont .fnt file and uses it to assemble the many Font.GlyphRegions this has for each glyph.
    protected void
    loadJSON(com.badlogic.gdx.files.FileHandle jsonHandle, com.badlogic.gdx.graphics.g2d.TextureRegion textureRegion, float xAdjust, float yAdjust, float widthAdjust, float heightAdjust, boolean makeGridGlyphs)
    The bulk of the loading code for Structured JSON fonts.
    protected void
    loadSad(String prefix, String fntName)
    The parsing code that pulls relevant info from a SadConsole .font configuration file and uses it to assemble the many Font.GlyphRegions this has for each glyph.
    markup(String text, Layout appendTo)
    Reads markup from text, along with the chars to receive markup, processes it, and appends into appendTo, which is a Layout holding one or more Lines.
    static long
    markupGlyph(char chr, String markup, ColorLookup colorLookup)
    Reads markup from markup, processes it, and applies it to the given char chr; returns a long in the format used for styled glyphs here.
    static long
    markupGlyph(char chr, String markup, ColorLookup colorLookup, Font.FontFamily family)
    Reads markup from markup, processes it, and applies it to the given char chr; returns a long in the format used for styled glyphs here.
    long
    markupGlyph(int chr, String markup)
    Reads markup from markup, processes it, and applies it to the given char chr; returns a long in the format used for styled glyphs here.
    long
    Reads markup from markup and processes it until it has a single complete glyph; returns that glyph as a long in the format used for styled glyphs here.
    float
    Measures the actual width that the given Line will use when drawn.
    multiplyCrispness(float multiplier)
    Takes the "crispness" multiplier for distance field fonts (SDF and MSDF) and multiplies it by another multiplier.
    void
    pauseDistanceFieldShader(com.badlogic.gdx.graphics.g2d.Batch batch)
    If a distance field font needs to have its distance field effect disabled temporarily (such as to draw an icon or emoji), you can call this just before you start drawing the non-distance-field images.
    When the targetWidth of a Layout changes, you can use this to cause the text to be placed according to the new width, and wrap if needed.
    void
    Removes the formatting state with the given name if it is present, or does nothing if the name is not present.
    void
    resizeDistanceField(float width, float height)
    Important; must be called in ApplicationListener.resize(int, int) on each SDF, MSDF, or SDF_OUTLINE font you have currently rendering! This allows the distance field to appear as correct and crisp-outlined as it should be; without this, the distance field will probably not look very sharp at all.
    void
    resizeDistanceField(float width, float height, com.badlogic.gdx.utils.viewport.Viewport viewport)
    Important; must be called in ApplicationListener.resize(int, int) on each SDF, MSDF, or SDF_OUTLINE font you have currently rendering! This allows the distance field to appear as correct and crisp-outlined as it should be; without this, the distance field will probably not look very sharp at all.
    void
    resumeDistanceFieldShader(com.badlogic.gdx.graphics.g2d.Batch batch)
    If a distance field font needs to be drawn with a different size, different crispness, or a different Texture altogether (such as to draw an icon or emoji), you can call this just before you start drawing distance field text with this Font.
    scale(float both)
    Scales the font by the given multiplier, applying it both horizontally and vertically.
    scale(float horizontal, float vertical)
    Scales the font by the given horizontal and vertical multipliers.
    scaleHeightTo(float height)
    Scales the font so that it will have the given height, keeping the current aspect ratio.
    scaleTo(float width, float height)
    Scales the font so that it will have the given width and height.
    setBoldStrength(float boldStrength)
     
    setBoxDrawingBreadth(float boxDrawingBreadth)
    When makeGridGlyphs is passed as true to a constructor here, box drawing and other block elements will be drawn using a solid block GlyphRegion that is stretched and moved to form various lines and blocks.
    Unlikely to be used in most games (meant more for other libraries), this allows changing how colors are looked up by name (or built) given a ColorLookup interface implementation.
    setCrispness(float crispness)
    Sets the "crispness" multiplier for distance field fonts (SDF and MSDF).
    setDescent(float descent)
     
    Sets this Font's distance field type; this should be Font.DistanceFieldType.STANDARD for most fonts (meaning it is a normal bitmap font with no distance field effect), but specially-made fonts can use Font.DistanceFieldType.SDF or Font.DistanceFieldType.MSDF to get smoother scaling and/or sharper edges.
    Sets the FontFamily this can use to switch fonts using [@Name] syntax.
    setFancyLinePosition(float x, float y)
    Sets both the "fancy line" metric adjustments for position, only changing fancyX and fancyY.
    setInlineImageMetrics(float offsetX, float offsetY, float xAdvance)
    Sets the adjustments added to the metric for inline images added with addAtlas(TextureAtlas) (or its overloads).
    setLineMetrics(float x, float y, float length, float breadth)
    Sets both the underline and strikethrough metric adjustments with the same values, as if you called both setUnderlineMetrics(float, float, float, float) and setStrikethroughMetrics(float, float, float, float) with identical parameters.
     
    setObliqueStrength(float obliqueStrength)
     
    setOutlineStrength(float outlineStrength)
     
    setStrikethroughMetrics(float strikeX, float strikeY, float strikeLength, float strikeBreadth)
     
    setStrikethroughPosition(float strikeX, float strikeY)
     
    Calls setTextureFilter(Texture.TextureFilter, Texture.TextureFilter) with Texture.TextureFilter.Linear for both min and mag filters.
    setTextureFilter(com.badlogic.gdx.graphics.Texture.TextureFilter minFilter, com.badlogic.gdx.graphics.Texture.TextureFilter magFilter)
    Sets the texture filters on each Texture that holds a TextureRegion used by the font to the given minFilter and magFilter.
    setUnderlineMetrics(float underX, float underY, float underLength, float underBreadth)
     
    setUnderlinePosition(float underX, float underY)
     
    void
    storeState(String name, long formatted)
    Evaluates markup to get a formatting state and stores it for later usage with "[ name]" syntax and the given name.
    void
    storeState(String name, String markup)
    Evaluates markup to get a formatting state and stores it for later usage with "[ name]" syntax and the given name.
     
    useIntegerPositions(boolean integer)
    A no-op unless this is a subclass that overrides handleIntegerPosition(float).
    float
    xAdvance(long glyph)
    Gets the distance to advance the cursor after drawing glyph, scaled by scaleX as if drawing.
    static float
    xAdvance(Font font, float scale, long glyph)
    Gets the distance to advance the cursor after drawing glyph, scaled by scale as if drawing.

    Methods inherited from class java.lang.Object

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

    • mapping

      public com.badlogic.gdx.utils.IntMap<Font.GlyphRegion> mapping
      Maps char keys (stored as ints) to their corresponding Font.GlyphRegion values. You can add arbitrary images to this mapping if you create appropriate GlyphRegion values (as with GlyphRegion(TextureRegion, float, float, float, float)), though they must map to a char.
    • nameLookup

      public CaseInsensitiveIntMap nameLookup
      Optional; maps the names of TextureRegions to the indices they use in mapping, and usually assigned by addAtlas(TextureAtlas). The keys in this map are case-insensitive.
    • namesByCharCode

      public com.badlogic.gdx.utils.IntMap<String> namesByCharCode
      Optional; a reversed form of nameLookup that allows you to get the printable name for a given char code. This is usually assigned by addAtlas(TextureAtlas).
      If multiple names are registered for the same char, the first one registered takes priority, unless the second name starts with an "astral plane" char such as an emoji. In the common use case of KnownFonts.addEmoji(Font), this means the printable names are all emoji.
    • defaultValue

      public Font.GlyphRegion defaultValue
      Which GlyphRegion to display if a char isn't found in mapping. May be null to show a space by default.
    • parents

      public com.badlogic.gdx.utils.Array<com.badlogic.gdx.graphics.g2d.TextureRegion> parents
      The larger TextureRegions that Font.GlyphRegion images are pulled from; these could be whole Textures or be drawn from a TextureAtlas that the font shares with other images.
    • distanceField

      protected Font.DistanceFieldType distanceField
    • isMono

      public boolean isMono
      If true, this is a fixed-width (monospace) font; if false, this is probably a variable-width font. This affects some rendering decisions Font makes, such as whether subscript chars should take up half-width (for variable fonts) or full-width (for monospace).
    • kerning

      public com.badlogic.gdx.utils.IntFloatMap kerning
      Unlikely to be used externally, this is one way of storing the kerning information that some fonts have. Kerning can improve the appearance of variable-width fonts, and is always null for monospace fonts. This uses a combination of two chars as a key (the earlier char is in the upper 16 bits, and the later char is in the lower 16 bits). Each such combination that has a special kerning value (not the default 0) has a float associated with it, which applies to the x-position of the later char.
    • actualCrispness

      public float actualCrispness
      When distanceField is Font.DistanceFieldType.SDF, Font.DistanceFieldType.MSDF, or Font.DistanceFieldType.SDF_OUTLINE, this determines how much the edges of the glyphs should be aliased sharply (higher values) or anti-aliased softly (lower values). The default value is 1. This is set internally by resizeDistanceField(float, float) using distanceFieldCrispness as a multiplier; when you want to have a change to crispness persist, use that other field.
    • distanceFieldCrispness

      public float distanceFieldCrispness
      When distanceField is Font.DistanceFieldType.SDF, Font.DistanceFieldType.MSDF, or Font.DistanceFieldType.SDF_OUTLINE, this determines how much the edges of the glyphs should be aliased sharply (higher values) or anti-aliased softly (lower values). The default value is 1. This is used as a persistent multiplier that can be configured per-font, whereas actualCrispness is the working value that changes often but is influenced by this one. This variable is used by resizeDistanceField(float, float) to affect the working crispness value.
    • cellWidth

      public float cellWidth
      Only actually refers to a "cell" when isMono is true; otherwise refers to the largest width of any glyph in the font, after scaling.
    • cellHeight

      public float cellHeight
      Refers to the largest height of any glyph in the font, after scaling.
    • originalCellWidth

      public float originalCellWidth
      Only actually refers to a "cell" when isMono is true; otherwise refers to the largest width of any glyph in the font, before any scaling.
    • originalCellHeight

      public float originalCellHeight
      Refers to the largest height of any glyph in the font, before any scaling.
    • scaleX

      public float scaleX
      Scale multiplier for width.
    • scaleY

      public float scaleY
      Scale multiplier for height.
    • descent

      public float descent
      How far the unscaled font descends below the baseline, typically as a negative number (not always).
    • solidBlock

      public char solidBlock
      A char that will be used to draw solid blocks with drawBlocks(Batch, int[][], float, float), and to draw box-drawing/block-element characters if makeGridGlyphs is true in the constructor. The glyph that corresponds to this char should be a 1x1 pixel block of solid white pixels in most cases. Because there is already a solid block in Unicode, this defaults to that Unicode glyph, at u2588 . There is also a test in TextraTypist, BlockStamper, that can place a tiny solid block in the lower-right corner and use that for this purpose. You can check if a .fnt file has a solid block present by searching for char id=9608 (9608 is the decimal way to write 0x2588).
    • family

      public Font.FontFamily family
      If non-null, may contain connected Font values and names/aliases to look them up with using [@Name] syntax.
    • colorLookup

      public ColorLookup colorLookup
      Determines how colors are looked up by name; defaults to using ColorUtils.describe(String).
    • integerPosition

      public boolean integerPosition
      By default, this doesn't do anything; subclasses can override handleIntegerPosition(float) to try to do something different with it. BitmapFont in libGDX defaults to having integer positions enabled, and there they actually do something (lock the font positions to integer world units). When world units aren't equivalent to on-screen pixels, BitmapFont's behavior leads to severe glitches in font appearance, so usually we aren't missing much by not using this behavior.
    • obliqueStrength

      public float obliqueStrength
      A multiplier that applies to the horizontal movement associated with oblique text (which is similar to italic). The default is 1.0f, which is fairly strong for some fonts, and some styles look better with a smaller value. A value of 0.0f will make oblique text look like regular text. A negative value will tip the angle backwards, so the top will be to the left of the bottom.
    • boldStrength

      public float boldStrength
      A multiplier that applies to the distance bold text will stretch away from the original glyph outline. The bold effect is achieved here by drawing the same GlyphRegion multiple times, separated to the left and right by a small distance. By reducing boldStrength to between 0.0 and 1.0, you can reduce the weight of bold text, but increasing boldStrength does not usually work well.
    • outlineStrength

      public float outlineStrength
      A multiplier that applies to the distance the "blacken" and "whiten" outlines will stretch away from the original glyph edge. The outline effects are achieved here by drawing the same GlyphRegion multiple times, in a grid of duplicate draws each a small distance apart. By reducing outlineStrength to between 0.0 and 1.0, you can reduce the thickness of outlines at large font sizes, or by increasing outlineStrength above 1.0, you can make the outlines more visible with smaller font sizes.
    • boxDrawingBreadth

      public float boxDrawingBreadth
      When makeGridGlyphs is passed as true to a constructor here, box drawing and other block elements will be drawn using a solid block GlyphRegion that is stretched and moved to form various lines and blocks. Setting this field to something other than 1 affects how wide the lines are for box drawing characters only; this is acts as a multiplier on the original width of a line. Normal box drawing lines such as those in β”Œ are 0.1f of a cell across. Thick lines such as those in ┏ are 0.2f of a cell across. Double lines such as those in β•” are two normal lines, 0.1f of a cell apart; double lines are not affected by this field.
    • name

      public String name
      The name of the Font, for display purposes. This is not necessarily the same as the name of the font used in any particular Font.FontFamily.
    • whiteBlock

      public com.badlogic.gdx.graphics.Texture whiteBlock
      A white square Texture, typically 3x3, that can be used as a backup in case a Font doesn't have a solid block character available to it already (such as for many Fonts created from BitmapFonts). This will be null unless it becomes needed, and will be disposed if this Font is.
    • BOLD

      public static final long BOLD
      Bit flag for bold mode, as a long.
      See Also:
    • OBLIQUE

      public static final long OBLIQUE
      Bit flag for oblique mode, as a long.
      See Also:
    • UNDERLINE

      public static final long UNDERLINE
      Bit flag for underline mode, as a long.
      See Also:
    • STRIKETHROUGH

      public static final long STRIKETHROUGH
      Bit flag for strikethrough mode, as a long.
      See Also:
    • SUBSCRIPT

      public static final long SUBSCRIPT
      Bit flag for subscript mode, as a long.
      See Also:
    • MIDSCRIPT

      public static final long MIDSCRIPT
      Bit flag for midscript mode, as a long.
      See Also:
    • SUPERSCRIPT

      public static final long SUPERSCRIPT
      Two-bit flag for superscript mode, as a long. This can also be checked to see if it is non-zero, which it will be if any of SUBSCRIPT, MIDSCRIPT, or SUPERSCRIPT are enabled.
      See Also:
    • ALTERNATE

      public static final long ALTERNATE
      Bit flag for alternate mode, as a long. The behavior of the scale bits changes if alternate mode is enabled.
      See Also:
    • ALTERNATE_MODES_MASK

      public static final long ALTERNATE_MODES_MASK
      Bit flag for matching alternate modes, as a long. If a glyph is masked with this ((glyph & ALTERNATE_MODES_MASK)), and that equals one of the alternate mode bit flags exactly (BLACK_OUTLINE, WHITE_OUTLINE, DROP_SHADOW, and so on), then that mode is enabled. This does not match SMALL_CAPS, because small caps mode can be enabled separately from the outline/shadow/etc. modes.
      You should generally check both this mask and SMALL_CAPS because as modes are added, there could be a mode that requires SMALL_CAPS to be disabled and, when a glyph is masked with this field, that mask to be exactly equal to ALTERNATE. In other words, that is a case where the alternate bit flag is enabled, but all the bits that normally affect it are disabled.
      See Also:
    • SMALL_CAPS

      public static final long SMALL_CAPS
      Bit flag for small caps mode, as a long. This only has its intended effect if alternate mode is enabled. This can overlap with other alternate modes, but cannot be used at the same time as scaling. If ALTERNATE is set, and bits 20 (small caps), 21, 22, and 23 are all not set, then a special mode is enabled, JOSTLE, which moves affected characters around in a stationary random pattern.
      See Also:
    • JOSTLE

      public static final long JOSTLE
      Bit flag for "jostle" mode, as a long. This moves characters around in a stationary random pattern, but keeps their existing metrics (width and height). This only has its intended effect if alternate mode is enabled and SMALL_CAPS is disabled. This cannot be used at the same time as scaling, and cannot overlap with other alternate modes. This requires ALTERNATE to be set, but bits 20 (small caps), 21, 22, and 23 to all be not set.
      See Also:
    • BLACK_OUTLINE

      public static final long BLACK_OUTLINE
      Bit flag for black outline mode, as a long. This only has its intended effect if alternate mode is enabled. This can overlap with SMALL_CAPS, but cannot be used at the same time as scaling. This can be configured to use a different color in place of black by changing PACKED_BLACK.
      See Also:
    • WHITE_OUTLINE

      public static final long WHITE_OUTLINE
      Bit flag for white outline mode, as a long. This only has its intended effect if alternate mode is enabled. If the Font being outlined uses some other color in its texture, this will draw the outline in the color used by the outer edge of each glyph drawn. For images in an atlas, like KnownFonts.addEmoji(Font), this will typically color the outline in the same color used by the edge of the image. This can be avoided by tinting the glyph with a darker color and still using this white outline. This can overlap with SMALL_CAPS, but cannot be used at the same time as scaling. This can be configured to use a different color in place of white by changing PACKED_WHITE.
      See Also:
    • DROP_SHADOW

      public static final long DROP_SHADOW
      Bit flag for drop shadow mode, as a long. This only has its intended effect if alternate mode is enabled. This can overlap with SMALL_CAPS, but cannot be used at the same time as scaling.
      See Also:
    • SHINY

      public static final long SHINY
      Bit flag for shiny mode, as a long. This only has its intended effect if alternate mode is enabled. This can overlap with SMALL_CAPS, but cannot be used at the same time as scaling.
      See Also:
    • ERROR

      public static final long ERROR
      Bit flag for error mode, shown as a red wiggly-underline, as a long. This only has its intended effect if alternate mode is enabled. This can overlap with SMALL_CAPS, but cannot be used at the same time as scaling. This can be configured to use a different color in place of red by changing PACKED_ERROR_COLOR.
      See Also:
    • WARN

      public static final long WARN
      Bit flag for warning mode, shown as a yellow barred-underline, as a long. This only has its intended effect if alternate mode is enabled. This can overlap with SMALL_CAPS, but cannot be used at the same time as scaling. This can be configured to use a different color in place of yellow by changing PACKED_WARN_COLOR.
      See Also:
    • NOTE

      public static final long NOTE
      Bit flag for note mode, shown as a blue wavy-underline, as a long. This only has its intended effect if alternate mode is enabled. This can overlap with SMALL_CAPS, but cannot be used at the same time as scaling. This can be configured to use a different color in place of blue by changing PACKED_NOTE_COLOR.
      See Also:
    • PACKED_BLACK

      public float PACKED_BLACK
      The color black, as a packed float using the default RGBA color space. This can be edited for Fonts that either use a different color space, or want to use a different color in place of black for effects like BLACK_OUTLINE.
    • PACKED_WHITE

      public float PACKED_WHITE
      The color white, as a packed float using the default RGBA color space. This can be edited for Fonts that either use a different color space, or want to use a different color in place of white for effects like WHITE_OUTLINE and SHINY.
    • PACKED_ERROR_COLOR

      public float PACKED_ERROR_COLOR
      The color to use for ERROR's underline, as a packed float using the default RGBA color space. Defaults to red. This can be edited for Fonts that either use a different color space, or want to use a different color in place of red for ERROR. In RGBA8888 format, this is the color 0xFF0000FF. You can generate packed float colors using Color.toFloatBits() or NumberUtils.intToFloatColor(int), among other methods. Make sure that the order the method expects RGBA channels is what you provide.
    • PACKED_WARN_COLOR

      public float PACKED_WARN_COLOR
      The color to use for WARN's underline, as a packed float using the default RGBA color space. Defaults to yellow or gold. This can be edited for Fonts that either use a different color space, or want to use a different color in place of yellow for WARN. In RGBA8888 format, this is the color 0xFFD510FF. You can generate packed float colors using Color.toFloatBits() or NumberUtils.intToFloatColor(int), among other methods. Make sure that the order the method expects RGBA channels is what you provide.
    • PACKED_NOTE_COLOR

      public float PACKED_NOTE_COLOR
      The color to use for NOTE's underline, as a packed float using the default RGBA color space. Defaults to blue. This can be edited for Fonts that either use a different color space, or want to use a different color in place of blue for NOTE. In RGBA8888 format, this is the color 0x3088B8FF. You can generate packed float colors using Color.toFloatBits() or NumberUtils.intToFloatColor(int), among other methods. Make sure that the order the method expects RGBA channels is what you provide.
    • PACKED_SHADOW_COLOR

      public float PACKED_SHADOW_COLOR
      The color to use for DROP_SHADOW, as a packed float using the default RGBA color space. Defaults to 13% lightness, 50% alpha gray. This can be edited for Fonts that either use a different color space, or want to use a different color in place of half-transparent dark gray for DROP_SHADOW. In RGBA8888 format, this is the color 0x2121217E. You can generate packed float colors using Color.toFloatBits() or NumberUtils.intToFloatColor(int), among other methods. Make sure that the order the method expects RGBA channels is what you provide.
    • xAdjust

      public float xAdjust
      The x-adjustment this Font was initialized with, or 0 if there was none given. This is not meant to affect appearance after a Font has been constructed, but is meant to allow some introspection into what values a Font was given at construction-time.
    • yAdjust

      public float yAdjust
      The y-adjustment this Font was initialized with, or 0 if there was none given. This is not meant to affect appearance after a Font has been constructed, but is meant to allow some introspection into what values a Font was given at construction-time.
    • widthAdjust

      public float widthAdjust
      The width-adjustment this Font was initialized with, or 0 if there was none given. This is not meant to affect appearance after a Font has been constructed, but is meant to allow some introspection into what values a Font was given at construction-time.
    • heightAdjust

      public float heightAdjust
      The height-adjustment this Font was initialized with, or 0 if there was none given. This is not meant to affect appearance after a Font has been constructed, but is meant to allow some introspection into what values a Font was given at construction-time.
    • underX

      public float underX
      Precise adjustment for the underline's x-position, affecting the left side of the underline. Normally, because underlines continue into any underline for the next glyph, decreasing underX should be accompanied by increasing underLength by a similar amount.
      This is a "Zen" metric, which means it is measured in fractions of cellWidth or cellHeight (as appropriate), and only affects one value.
    • underY

      public float underY
      Precise adjustment for the underline's y-position, affecting the bottom side of the underline.
      This is a "Zen" metric, which means it is measured in fractions of cellWidth or cellHeight (as appropriate), and only affects one value.
    • underLength

      public float underLength
      Precise adjustment for the underline's x-size, affecting the extra underline drawn to the right of the underline. Normally, because underlines continue into any underline for the next glyph, decreasing underX should be accompanied by increasing underLength by a similar amount.
      This is a "Zen" metric, which means it is measured in fractions of cellWidth or cellHeight (as appropriate), and only affects one value.
    • underBreadth

      public float underBreadth
      Precise adjustment for the underline's y-size, affecting how thick the underline is from bottom to top.
      This is a "Zen" metric, which means it is measured in fractions of cellWidth or cellHeight (as appropriate), and only affects one value.
    • strikeX

      public float strikeX
      Precise adjustment for the strikethrough's x-position, affecting the left side of the strikethrough. Normally, because strikethrough continues into any strikethrough for the next glyph, decreasing strikeX should be accompanied by increasing strikeLength by a similar amount.
      This is a "Zen" metric, which means it is measured in fractions of cellWidth or cellHeight (as appropriate), and only affects one value.
    • strikeY

      public float strikeY
      Precise adjustment for the strikethrough's y-position, affecting the bottom side of the strikethrough.
      This is a "Zen" metric, which means it is measured in fractions of cellWidth or cellHeight (as appropriate), and only affects one value.
    • strikeLength

      public float strikeLength
      Precise adjustment for the strikethrough's x-size, affecting the extra strikethrough drawn to the right of the strikethrough. Normally, because strikethrough continues into any strikethrough for the next glyph, decreasing strikeX should be accompanied by increasing strikeLength by a similar amount.
      This is a "Zen" metric, which means it is measured in fractions of cellWidth or cellHeight (as appropriate), and only affects one value.
    • strikeBreadth

      public float strikeBreadth
      Precise adjustment for the strikethrough's y-size, affecting how thick the strikethrough is from bottom to top.
      This is a "Zen" metric, which means it is measured in fractions of cellWidth or cellHeight (as appropriate), and only affects one value.
    • fancyX

      public float fancyX
      Precise adjustment for the x-position of "fancy lines" such as error, warning, and note effects, affecting the left side of the line.
      This is a "Zen" metric, which means it is measured in fractions of cellWidth or cellHeight (as appropriate), and only affects one value.
    • fancyY

      public float fancyY
      Precise adjustment for the y-position of "fancy lines" such as error, warning, and note effects, affecting the bottom side of the line.
      This is a "Zen" metric, which means it is measured in fractions of cellWidth or cellHeight (as appropriate), and only affects one value.
    • inlineImageOffsetX

      public float inlineImageOffsetX
      An adjustment added to the Font.GlyphRegion.offsetX of any inline images added with addAtlas(TextureAtlas, String, String, float, float, float) (or its overloads). This is meant as a guess for how square inline images, such as emoji, may need to be moved around to fit correctly on a line. If you have multiple atlases added to one font, you should probably use the addAtlas(TextureAtlas, float, float, float) overload that allows adding additional adjustments if one atlas isn't quite right.
      Changing offsetXChange with a positive value moves all GlyphRegions to the right.
    • inlineImageOffsetY

      public float inlineImageOffsetY
      An adjustment added to the Font.GlyphRegion.offsetY of any inline images added with addAtlas(TextureAtlas, String, String, float, float, float) (or its overloads). This is meant as a guess for how square inline images, such as emoji, may need to be moved around to fit correctly on a line. If you have multiple atlases added to one font, you should probably use the addAtlas(TextureAtlas, float, float, float) overload that allows adding additional adjustments if one atlas isn't quite right.
      Changing offsetYChange with a positive value moves all GlyphRegions down (this is possibly unexpected).
    • inlineImageXAdvance

      public float inlineImageXAdvance
      An adjustment added to the xAdvance(com.github.tommyettinger.textra.Font, float, long) of any inline images added with addAtlas(TextureAtlas, String, String, float, float, float) (or its overloads). This is meant as a guess for how square inline images, such as emoji, may need to be moved around to fit correctly on a line. If you have multiple atlases added to one font, you should probably use the addAtlas(TextureAtlas, float, float, float) overload that allows adding additional adjustments if one atlas isn't quite right.
      Changing xAdvanceChange with a positive value will shrink all GlyphRegions (this is probably unexpected).
    • omitCurlyBraces

      public boolean omitCurlyBraces
      If true (the default), any text inside matching curly braces, plus the curly braces themselves, will be ignored during rendering and not displayed. If false, curly braces and their contents are treated as normal text. Note that regardless of this setting, you can use the [-TAG] syntax instead of {TAG} to produce a tag that TypingLabel can read, even though Font itself wouldn't do anything with TAG there.
    • enableSquareBrackets

      public boolean enableSquareBrackets
      If true (the default), square bracket markup functions as documented in markup(String, Layout). If false, square brackets and their contents are treated as normal text.
    • CJK_SPACE_INSERTER

      public static final regexodus.Replacer CJK_SPACE_INSERTER
      A RegExodus Replacer that replaces any CJK ideographic characters with themselves plus a zero-width space after. Meant to be used via insertZeroWidthSpacesInCJK(CharSequence), but can be used on its own.
    • vertexShader

      public static final String vertexShader
      The standard libGDX vertex shader source, which is also used by the SDF and MSDF shaders.
      See Also:
    • sdfFragmentShader

      public static final String sdfFragmentShader
      A modified version of the fragment shader for SDF fonts from DistanceFieldFont, now supporting RGB colors other than white (but with limited support for partial transparency). This is automatically used when enableShader(Batch) is called and the distanceField is Font.DistanceFieldType.SDF. This shader can be used with inline images, but won't behave 100% correctly if they use partial transparency, such as to anti-alias edges.
      See Also:
    • sdfBlackOutlineFragmentShader

      public static final String sdfBlackOutlineFragmentShader
      A modified version of the fragment shader for SDF fonts from DistanceFieldFont, this draws a moderately thick black outline around each glyph, with the outline respecting the transparency of the glyph (unlike BLACK_OUTLINE mode). This also supports RGB colors other than white (but with limited support for partial transparency). This is automatically used when enableShader(Batch) is called and the distanceField is Font.DistanceFieldType.SDF_OUTLINE. This shader can be used with inline images, but won't behave 100% correctly if they use partial transparency, such as to anti-alias edges.
      See Also:
    • msdfFragmentShader

      public static final String msdfFragmentShader
      Fragment shader source meant for MSDF fonts. This is automatically used when enableShader(Batch) is called and the distanceField is Font.DistanceFieldType.MSDF. This shader will almost always fail to work correctly with inline images.
      This is mostly derived from msdf-gdx, which is Apache 2.0-licensed.
      See Also:
    • shader

      public com.badlogic.gdx.graphics.glutils.ShaderProgram shader
      The ShaderProgram used to render this font, as used by enableShader(Batch). If this is null, the font will be rendered with the Batch's default shader. It may be set to a custom ShaderProgram if distanceField is set to Font.DistanceFieldType.MSDF or Font.DistanceFieldType.SDF. It can be set to a user-defined ShaderProgram; if it is meant to render MSDF or SDF fonts, then the ShaderProgram should have a uniform float u_smoothing; that will be set by enableShader(Batch). Values passed to u_smoothing can vary a lot, depending on how the font was initially created, its current scale, and its actualCrispness field. You can also use a user-defined ShaderProgram with a font using Font.DistanceFieldType.STANDARD, which may be easier and can use any uniforms you normally could with a ShaderProgram, since enableShader() won't change any of the uniforms.
  • Constructor Details

    • Font

      public Font()
      Constructs a Font from a newly-created default BitmapFont, as by BitmapFont(), passing it to Font(BitmapFont, float, float, float, float). This means this constructor will always produce a Font based on 15-point Liberation Sans, with a shadow effect applied to all chars. The shadow may cause some effects, such as bold and strikethrough, to look incorrect, so this is mostly useful for testing. Note, you can add a shadow effect to any of the fonts in KnownFonts by using the [%?shadow] mode, so you don't typically need or want the shadow to be applied to the font beforehand.
    • Font

      public Font(String fntName)
      Constructs a Font by reading in the given .fnt file and loading any images it specifies. Tries an internal handle first, then a local handle. Does not use a distance field effect.
      Parameters:
      fntName - the file path and name to a .fnt file this will load
    • Font

      public Font(String fntName, Font.DistanceFieldType distanceField)
      Constructs a Font by reading in the given .fnt file and loading any images it specifies. Tries an internal handle first, then a local handle. Uses the specified distance field effect.
      Parameters:
      fntName - the file path and name to a .fnt file this will load
      distanceField - determines how edges are drawn; if unsure, you should use Font.DistanceFieldType.STANDARD
    • Font

      public Font(String fntName, String textureName)
      Constructs a Font by reading in the given .fnt file and the given Texture by filename. Tries an internal handle first, then a local handle. Does not use a distance field effect.
      Parameters:
      fntName - the file path and name to a .fnt file this will load
    • Font

      public Font(String fntName, String textureName, Font.DistanceFieldType distanceField)
      Constructs a Font by reading in the given .fnt file and the given Texture by filename. Tries an internal handle first, then a local handle. Uses the specified distance field effect.
      Parameters:
      fntName - the file path and name to a .fnt file this will load
      distanceField - determines how edges are drawn; if unsure, you should use Font.DistanceFieldType.STANDARD
    • Font

      public Font(Font toCopy)
      Copy constructor; does not copy the font's shader or colorLookup, if it has them (it uses the same reference for the new Font), but will fully copy everything else.
      Parameters:
      toCopy - another Font to copy
    • Font

      public Font(String fntName, float xAdjust, float yAdjust, float widthAdjust, float heightAdjust)
      Constructs a new Font by reading in a .fnt file with the given name (an internal handle is tried first, then a local handle) and loading any images specified in that file. No distance field effect is used. This allows globally adjusting the x and y positions of glyphs in the font, as well as globally adjusting the horizontal and vertical space glyphs take up. Changing these adjustments by small values can drastically improve the appearance of text, but has to be manually edited; every font is quite different. If you want to add empty space around each character, you can add approximately the normal originalCellWidth to widthAdjust and about half that to xAdjust; this can be used to make the glyphs fit in square cells.
      Parameters:
      fntName - the path and filename of a .fnt file this will load; may be internal or local
      xAdjust - how many pixels to offset each character's x-position by, moving to the right
      yAdjust - how many pixels to offset each character's y-position by, moving up
      widthAdjust - how many pixels to add to the used width of each character, using more to the right
      heightAdjust - how many pixels to add to the used height of each character, using more above
    • Font

      public Font(String fntName, Font.DistanceFieldType distanceField, float xAdjust, float yAdjust, float widthAdjust, float heightAdjust)
      Constructs a new Font by reading in a .fnt file with the given name (an internal handle is tried first, then a local handle) and loading any images specified in that file. The specified distance field effect is used. This allows globally adjusting the x and y positions of glyphs in the font, as well as globally adjusting the horizontal and vertical space glyphs take up. Changing these adjustments by small values can drastically improve the appearance of text, but has to be manually edited; every font is quite different. If you want to add empty space around each character, you can add approximately the normal originalCellWidth to widthAdjust and about half that to xAdjust; this can be used to make the glyphs fit in square cells.
      Parameters:
      fntName - the path and filename of a .fnt file this will load; may be internal or local
      distanceField - determines how edges are drawn; if unsure, you should use Font.DistanceFieldType.STANDARD
      xAdjust - how many pixels to offset each character's x-position by, moving to the right
      yAdjust - how many pixels to offset each character's y-position by, moving up
      widthAdjust - how many pixels to add to the used width of each character, using more to the right
      heightAdjust - how many pixels to add to the used height of each character, using more above
    • Font

      public Font(String fntName, Font.DistanceFieldType distanceField, float xAdjust, float yAdjust, float widthAdjust, float heightAdjust, boolean makeGridGlyphs)
      Constructs a new Font by reading in a .fnt file with the given name (an internal handle is tried first, then a local handle) and loading any images specified in that file. The specified distance field effect is used. This allows globally adjusting the x and y positions of glyphs in the font, as well as globally adjusting the horizontal and vertical space glyphs take up. Changing these adjustments by small values can drastically improve the appearance of text, but has to be manually edited; every font is quite different. If you want to add empty space around each character, you can add approximately the normal originalCellWidth to widthAdjust and about half that to xAdjust; this can be used to make the glyphs fit in square cells.
      Parameters:
      fntName - the path and filename of a .fnt file this will load; may be internal or local
      distanceField - determines how edges are drawn; if unsure, you should use Font.DistanceFieldType.STANDARD
      xAdjust - how many pixels to offset each character's x-position by, moving to the right
      yAdjust - how many pixels to offset each character's y-position by, moving up
      widthAdjust - how many pixels to add to the used width of each character, using more to the right
      heightAdjust - how many pixels to add to the used height of each character, using more above
      makeGridGlyphs - true if this should use its own way of rendering box-drawing/block-element glyphs, ignoring any in the font file
    • Font

      public Font(com.badlogic.gdx.files.FileHandle fntHandle, Font.DistanceFieldType distanceField, float xAdjust, float yAdjust, float widthAdjust, float heightAdjust, boolean makeGridGlyphs)
      Constructs a new Font by reading in a .fnt file from the given FileHandle and loading any images specified in that file. The specified distance field effect is used. This allows globally adjusting the x and y positions of glyphs in the font, as well as globally adjusting the horizontal and vertical space glyphs take up. Changing these adjustments by small values can drastically improve the appearance of text, but has to be manually edited; every font is quite different. If you want to add empty space around each character, you can add approximately the normal originalCellWidth to widthAdjust and about half that to xAdjust; this can be used to make the glyphs fit in square cells.
      Parameters:
      fntHandle - the FileHandle holding the path to a .fnt file
      distanceField - determines how edges are drawn; if unsure, you should use Font.DistanceFieldType.STANDARD
      xAdjust - how many pixels to offset each character's x-position by, moving to the right
      yAdjust - how many pixels to offset each character's y-position by, moving up
      widthAdjust - how many pixels to add to the used width of each character, using more to the right
      heightAdjust - how many pixels to add to the used height of each character, using more above
      makeGridGlyphs - true if this should use its own way of rendering box-drawing/block-element glyphs, ignoring any in the font file
    • Font

      public Font(String fntName, String textureName, float xAdjust, float yAdjust, float widthAdjust, float heightAdjust)
      Constructs a new Font by reading in a Texture from the given named path (internal is tried, then local), and no distance field effect. This allows globally adjusting the x and y positions of glyphs in the font, as well as globally adjusting the horizontal and vertical space glyphs take up. Changing these adjustments by small values can drastically improve the appearance of text, but has to be manually edited; every font is quite different. If you want to add empty space around each character, you can add approximately the normal originalCellWidth to widthAdjust and about half that to xAdjust; this can be used to make the glyphs fit in square cells.
      Parameters:
      fntName - the path and filename of a .fnt file this will load; may be internal or local
      textureName - the path and filename of a texture file this will load; may be internal or local
      xAdjust - how many pixels to offset each character's x-position by, moving to the right
      yAdjust - how many pixels to offset each character's y-position by, moving up
      widthAdjust - how many pixels to add to the used width of each character, using more to the right
      heightAdjust - how many pixels to add to the used height of each character, using more above
    • Font

      public Font(String fntName, String textureName, Font.DistanceFieldType distanceField, float xAdjust, float yAdjust, float widthAdjust, float heightAdjust)
      Constructs a new Font by reading in a Texture from the given named path (internal is tried, then local), and the specified distance field effect. This allows globally adjusting the x and y positions of glyphs in the font, as well as globally adjusting the horizontal and vertical space glyphs take up. Changing these adjustments by small values can drastically improve the appearance of text, but has to be manually edited; every font is quite different. If you want to add empty space around each character, you can add approximately the normal originalCellWidth to widthAdjust and about half that to xAdjust; this can be used to make the glyphs fit in square cells.
      Parameters:
      fntName - the path and filename of a .fnt file this will load; may be internal or local
      textureName - the path and filename of a texture file this will load; may be internal or local
      distanceField - determines how edges are drawn; if unsure, you should use Font.DistanceFieldType.STANDARD
      xAdjust - how many pixels to offset each character's x-position by, moving to the right
      yAdjust - how many pixels to offset each character's y-position by, moving up
      widthAdjust - how many pixels to add to the used width of each character, using more to the right
      heightAdjust - how many pixels to add to the used height of each character, using more above
    • Font

      public Font(String fntName, String textureName, Font.DistanceFieldType distanceField, float xAdjust, float yAdjust, float widthAdjust, float heightAdjust, boolean makeGridGlyphs)
      Constructs a new Font by reading in a Texture from the given named path (internal is tried, then local), and the specified distance field effect. This allows globally adjusting the x and y positions of glyphs in the font, as well as globally adjusting the horizontal and vertical space glyphs take up. Changing these adjustments by small values can drastically improve the appearance of text, but has to be manually edited; every font is quite different. If you want to add empty space around each character, you can add approximately the normal originalCellWidth to widthAdjust and about half that to xAdjust; this can be used to make the glyphs fit in square cells.
      Parameters:
      fntName - the path and filename of a .fnt file this will load; may be internal or local
      textureName - the path and filename of a texture file this will load; may be internal or local
      distanceField - determines how edges are drawn; if unsure, you should use Font.DistanceFieldType.STANDARD
      xAdjust - how many pixels to offset each character's x-position by, moving to the right
      yAdjust - how many pixels to offset each character's y-position by, moving up
      widthAdjust - how many pixels to add to the used width of each character, using more to the right
      heightAdjust - how many pixels to add to the used height of each character, using more above
      makeGridGlyphs - true if this should use its own way of rendering box-drawing/block-element glyphs, ignoring any in the font file
    • Font

      public Font(String fntName, com.badlogic.gdx.graphics.g2d.TextureRegion textureRegion, float xAdjust, float yAdjust, float widthAdjust, float heightAdjust)
      Constructs a font using the given TextureRegion that holds all of its glyphs, with no distance field effect. This allows globally adjusting the x and y positions of glyphs in the font, as well as globally adjusting the horizontal and vertical space glyphs take up. Changing these adjustments by small values can drastically improve the appearance of text, but has to be manually edited; every font is quite different. If you want to add empty space around each character, you can add approximately the normal originalCellWidth to widthAdjust and about half that to xAdjust; this can be used to make the glyphs fit in square cells.
      Parameters:
      fntName - the path and filename of a .fnt file this will load; may be internal or local
      textureRegion - an existing TextureRegion, typically inside a larger TextureAtlas
      xAdjust - how many pixels to offset each character's x-position by, moving to the right
      yAdjust - how many pixels to offset each character's y-position by, moving up
      widthAdjust - how many pixels to add to the used width of each character, using more to the right
      heightAdjust - how many pixels to add to the used height of each character, using more above
    • Font

      public Font(String fntName, com.badlogic.gdx.graphics.g2d.TextureRegion textureRegion, Font.DistanceFieldType distanceField, float xAdjust, float yAdjust, float widthAdjust, float heightAdjust)
      Constructs a font based off of an AngelCode BMFont .fnt file and the given TextureRegion that holds all of its glyphs, with the specified distance field effect. This allows globally adjusting the x and y positions of glyphs in the font, as well as globally adjusting the horizontal and vertical space glyphs take up. Changing these adjustments by small values can drastically improve the appearance of text, but has to be manually edited; every font is quite different. If you want to add empty space around each character, you can add approximately the normal originalCellWidth to widthAdjust and about half that to xAdjust; this can be used to make the glyphs fit in square cells.
      Parameters:
      fntName - the path and filename of a .fnt file this will load; may be internal or local
      textureRegion - an existing TextureRegion, typically inside a larger TextureAtlas
      distanceField - determines how edges are drawn; if unsure, you should use Font.DistanceFieldType.STANDARD
      xAdjust - how many pixels to offset each character's x-position by, moving to the right
      yAdjust - how many pixels to offset each character's y-position by, moving up
      widthAdjust - how many pixels to add to the used width of each character, using more to the right
      heightAdjust - how many pixels to add to the used height of each character, using more above
    • Font

      public Font(String fntName, com.badlogic.gdx.graphics.g2d.TextureRegion textureRegion, Font.DistanceFieldType distanceField, float xAdjust, float yAdjust, float widthAdjust, float heightAdjust, boolean makeGridGlyphs)
      Constructs a font based off of an AngelCode BMFont .fnt file and the given TextureRegion that holds all of its glyphs, with the specified distance field effect. This allows globally adjusting the x and y positions of glyphs in the font, as well as globally adjusting the horizontal and vertical space glyphs take up. Changing these adjustments by small values can drastically improve the appearance of text, but has to be manually edited; every font is quite different. If you want to add empty space around each character, you can add approximately the normal originalCellWidth to widthAdjust and about half that to xAdjust; this can be used to make the glyphs fit in square cells.
      Parameters:
      fntName - the path and filename of a .fnt file this will load; may be internal or local
      textureRegion - an existing TextureRegion, typically inside a larger TextureAtlas
      distanceField - determines how edges are drawn; if unsure, you should use Font.DistanceFieldType.STANDARD
      xAdjust - how many pixels to offset each character's x-position by, moving to the right
      yAdjust - how many pixels to offset each character's y-position by, moving up
      widthAdjust - how many pixels to add to the used width of each character, using more to the right
      heightAdjust - how many pixels to add to the used height of each character, using more above
      makeGridGlyphs - true if this should use its own way of rendering box-drawing/block-element glyphs, ignoring any in the font file
    • Font

      public Font(com.badlogic.gdx.files.FileHandle fntHandle, com.badlogic.gdx.graphics.g2d.TextureRegion textureRegion, Font.DistanceFieldType distanceField, float xAdjust, float yAdjust, float widthAdjust, float heightAdjust, boolean makeGridGlyphs)
      Constructs a font based off of an AngelCode BMFont .fnt file and the given TextureRegion that holds all of its glyphs, with the specified distance field effect. This allows globally adjusting the x and y positions of glyphs in the font, as well as globally adjusting the horizontal and vertical space glyphs take up. Changing these adjustments by small values can drastically improve the appearance of text, but has to be manually edited; every font is quite different. If you want to add empty space around each character, you can add approximately the normal originalCellWidth to widthAdjust and about half that to xAdjust; this can be used to make the glyphs fit in square cells.
      Parameters:
      fntHandle - the FileHandle holding the path to a .fnt file
      textureRegion - an existing TextureRegion, typically inside a larger TextureAtlas
      distanceField - determines how edges are drawn; if unsure, you should use Font.DistanceFieldType.STANDARD
      xAdjust - how many pixels to offset each character's x-position by, moving to the right
      yAdjust - how many pixels to offset each character's y-position by, moving up
      widthAdjust - how many pixels to add to the used width of each character, using more to the right
      heightAdjust - how many pixels to add to the used height of each character, using more above
      makeGridGlyphs - true if this should use its own way of rendering box-drawing/block-element glyphs, ignoring any in the font file
    • Font

      public Font(String fntName, com.badlogic.gdx.utils.Array<com.badlogic.gdx.graphics.g2d.TextureRegion> textureRegions, float xAdjust, float yAdjust, float widthAdjust, float heightAdjust)
      Constructs a font based off of an AngelCode BMFont .fnt file and the given TextureRegion Array, with no distance field effect. This allows globally adjusting the x and y positions of glyphs in the font, as well as globally adjusting the horizontal and vertical space glyphs take up. Changing these adjustments by small values can drastically improve the appearance of text, but has to be manually edited; every font is quite different. If you want to add empty space around each character, you can add approximately the normal originalCellWidth to widthAdjust and about half that to xAdjust; this can be used to make the glyphs fit in square cells.
      Parameters:
      fntName - the path and filename of a .fnt file this will load; may be internal or local
      textureRegions - an Array of TextureRegions that will be used in order as the .fnt file uses more pages
      xAdjust - how many pixels to offset each character's x-position by, moving to the right
      yAdjust - how many pixels to offset each character's y-position by, moving up
      widthAdjust - how many pixels to add to the used width of each character, using more to the right
      heightAdjust - how many pixels to add to the used height of each character, using more above
    • Font

      public Font(String fntName, com.badlogic.gdx.utils.Array<com.badlogic.gdx.graphics.g2d.TextureRegion> textureRegions, Font.DistanceFieldType distanceField, float xAdjust, float yAdjust, float widthAdjust, float heightAdjust)
      Constructs a font based off of an AngelCode BMFont .fnt file, with the given TextureRegion Array and specified distance field effect. This allows globally adjusting the x and y positions of glyphs in the font, as well as globally adjusting the horizontal and vertical space glyphs take up. Changing these adjustments by small values can drastically improve the appearance of text, but has to be manually edited; every font is quite different. If you want to add empty space around each character, you can add approximately the normal originalCellWidth to widthAdjust and about half that to xAdjust; this can be used to make the glyphs fit in square cells.
      Parameters:
      fntName - the path and filename of a .fnt file this will load; may be internal or local
      textureRegions - an Array of TextureRegions that will be used in order as the .fnt file uses more pages
      distanceField - determines how edges are drawn; if unsure, you should use Font.DistanceFieldType.STANDARD
      xAdjust - how many pixels to offset each character's x-position by, moving to the right
      yAdjust - how many pixels to offset each character's y-position by, moving up
      widthAdjust - how many pixels to add to the used width of each character, using more to the right
      heightAdjust - how many pixels to add to the used height of each character, using more above
    • Font

      public Font(String fntName, com.badlogic.gdx.utils.Array<com.badlogic.gdx.graphics.g2d.TextureRegion> textureRegions, Font.DistanceFieldType distanceField, float xAdjust, float yAdjust, float widthAdjust, float heightAdjust, boolean makeGridGlyphs)
      Constructs a font based off of an AngelCode BMFont .fnt file, with the given TextureRegion Array and specified distance field effect. This allows globally adjusting the x and y positions of glyphs in the font, as well as globally adjusting the horizontal and vertical space glyphs take up. Changing these adjustments by small values can drastically improve the appearance of text, but has to be manually edited; every font is quite different. If you want to add empty space around each character, you can add approximately the normal originalCellWidth to widthAdjust and about half that to xAdjust; this can be used to make the glyphs fit in square cells.
      Parameters:
      fntName - the path and filename of a .fnt file this will load; may be internal or local
      textureRegions - an Array of TextureRegions that will be used in order as the .fnt file uses more pages
      distanceField - determines how edges are drawn; if unsure, you should use Font.DistanceFieldType.STANDARD
      xAdjust - how many pixels to offset each character's x-position by, moving to the right
      yAdjust - how many pixels to offset each character's y-position by, moving up
      widthAdjust - how many pixels to add to the used width of each character, using more to the right
      heightAdjust - how many pixels to add to the used height of each character, using more above
      makeGridGlyphs - true if this should use its own way of rendering box-drawing/block-element glyphs, ignoring any in the font file
    • Font

      public Font(com.badlogic.gdx.files.FileHandle fntHandle, com.badlogic.gdx.utils.Array<com.badlogic.gdx.graphics.g2d.TextureRegion> textureRegions, Font.DistanceFieldType distanceField, float xAdjust, float yAdjust, float widthAdjust, float heightAdjust, boolean makeGridGlyphs)
      Constructs a font based off of an AngelCode BMFont .fnt file, with the given TextureRegion Array and specified distance field effect. This allows globally adjusting the x and y positions of glyphs in the font, as well as globally adjusting the horizontal and vertical space glyphs take up. Changing these adjustments by small values can drastically improve the appearance of text, but has to be manually edited; every font is quite different. If you want to add empty space around each character, you can add approximately the normal originalCellWidth to widthAdjust and about half that to xAdjust; this can be used to make the glyphs fit in square cells.
      Parameters:
      fntHandle - the FileHandle holding the path to a .fnt file
      textureRegions - an Array of TextureRegions that will be used in order as the .fnt file uses more pages
      distanceField - determines how edges are drawn; if unsure, you should use Font.DistanceFieldType.STANDARD
      xAdjust - how many pixels to offset each character's x-position by, moving to the right
      yAdjust - how many pixels to offset each character's y-position by, moving up
      widthAdjust - how many pixels to add to the used width of each character, using more to the right
      heightAdjust - how many pixels to add to the used height of each character, using more above
      makeGridGlyphs - true if this should use its own way of rendering box-drawing/block-element glyphs, ignoring any in the font file
    • Font

      public Font(com.badlogic.gdx.graphics.g2d.BitmapFont bmFont)
      Constructs a new Font from the existing BitmapFont, using its same Textures and TextureRegions for glyphs, and without a distance field effect or any adjustments to position except for a y offset equal to BitmapFont.getDescent().
      Parameters:
      bmFont - an existing BitmapFont that will be copied in almost every way this can
    • Font

      public Font(com.badlogic.gdx.graphics.g2d.BitmapFont bmFont, float xAdjust, float yAdjust, float widthAdjust, float heightAdjust)
      Constructs a new Font from the existing BitmapFont, using its same Textures and TextureRegions for glyphs, and without a distance field effect. Adds a value to yAdjust equal to BitmapFont.getDescent().
      Parameters:
      bmFont - an existing BitmapFont that will be copied in almost every way this can
      xAdjust - how many pixels to offset each character's x-position by, moving to the right
      yAdjust - how many pixels to offset each character's y-position by, moving up
      widthAdjust - how many pixels to add to the used width of each character, using more to the right
      heightAdjust - how many pixels to add to the used height of each character, using more above
    • Font

      public Font(com.badlogic.gdx.graphics.g2d.BitmapFont bmFont, Font.DistanceFieldType distanceField, float xAdjust, float yAdjust, float widthAdjust, float heightAdjust)
      Constructs a new Font from the existing BitmapFont, using its same Textures and TextureRegions for glyphs, and with the specified distance field effect. Adds a value to yAdjust equal to BitmapFont.getDescent().
      Parameters:
      bmFont - an existing BitmapFont that will be copied in almost every way this can
      distanceField - determines how edges are drawn; if unsure, you should use Font.DistanceFieldType.STANDARD
      xAdjust - how many pixels to offset each character's x-position by, moving to the right
      yAdjust - how many pixels to offset each character's y-position by, moving up
      widthAdjust - how many pixels to add to the used width of each character, using more to the right
      heightAdjust - how many pixels to add to the used height of each character, using more above
    • Font

      public Font(com.badlogic.gdx.graphics.g2d.BitmapFont bmFont, Font.DistanceFieldType distanceField, float xAdjust, float yAdjust, float widthAdjust, float heightAdjust, boolean makeGridGlyphs)
      Constructs a new Font from the existing BitmapFont, using its same Textures and TextureRegions for glyphs, and with the specified distance field effect. Adds a value to yAdjust equal to BitmapFont.getDescent().
      Parameters:
      bmFont - an existing BitmapFont that will be copied in almost every way this can
      distanceField - determines how edges are drawn; if unsure, you should use Font.DistanceFieldType.STANDARD
      xAdjust - how many pixels to offset each character's x-position by, moving to the right
      yAdjust - how many pixels to offset each character's y-position by, moving up
      widthAdjust - how many pixels to add to the used width of each character, using more to the right
      heightAdjust - how many pixels to add to the used height of each character, using more above
      makeGridGlyphs - true if this should use its own way of rendering box-drawing/block-element glyphs, ignoring any in the font file
    • Font

      public Font(String prefix, String fntName, boolean ignoredSadConsoleFlag)
      Constructs a new Font by reading in a SadConsole .font file with the given name (an internal handle is tried first, then a local handle) and loading any images specified in that file. This never uses a distance field effect, and always tries to load one image by the path specified in the .font file.
      Parameters:
      prefix - a String to prepend to any filenames looked up for this Font (typically a .font file and a .png file)
      fntName - the path and filename of a .font file this will load; may be internal or local
      ignoredSadConsoleFlag - the value is ignored here; the presence of this parameter says to load a SadConsole .font file
    • Font

      public Font(String jsonName, boolean ignoredStructuredJsonFlag)
      Creates a Font from a "Structured JSON" file produced by Chlumsky's msdf-atlas-gen tool, and uses it to assemble the many Font.GlyphRegions this has for each glyph. Reads the distance field type from the JSON. This always tries to load a PNG file with the same filename as (and different extension from) the JSON file, trying an internal file path first, and a local file path if that fails. No matter what extension the JSON font uses, this will be able to load it (so this can load compressed .dat fonts as well as .json or .js). This always makes grid glyphs.
      The msdf-atlas-gen tool can actually produce MSDF, SDF, PSDF, and "soft masked" (standard) fonts. It can't produce AngelCode BMFont .fnt files, but the JSON it can produce is fairly full-featured. Its handling of metrics seems significantly better than the tools that work with AngelCode BMFont .fnt files, so all the fonts in KnownFonts use JSON. A specialized version of msdf-atlas-gen that only writes structured JSON files (and optimizes the files at the right size) is available at fontwriter (Windows-only, for now).
      Parameters:
      jsonName - the name of a structured JSON font file this will load from an internal or local file handle (tried in that order)
      ignoredStructuredJsonFlag - only present to distinguish this from other constructors; ignored
    • Font

      public Font(String jsonName, com.badlogic.gdx.graphics.g2d.TextureRegion textureRegion, boolean makeGridGlyphs, boolean ignoredStructuredJsonFlag)
      Creates a Font from a "Structured JSON" file produced by Chlumsky's msdf-atlas-gen tool, and uses it to assemble the many Font.GlyphRegions this has for each glyph. Reads the distance field type from the JSON.
      The msdf-atlas-gen tool can actually produce MSDF, SDF, PSDF, and "soft masked" (standard) fonts. It can't produce AngelCode BMFont .fnt files, but the JSON it can produce is fairly full-featured. Its handling of metrics seems significantly better than the tools that work with AngelCode BMFont .fnt files, so all the fonts in KnownFonts use JSON. A specialized version of msdf-atlas-gen that only writes structured JSON files (and optimizes the files at the right size) is available at fontwriter (Windows-only, for now).
      Parameters:
      jsonName - the name of a structured JSON font file this will load from an internal or local file handle (tried in that order)
      textureRegion - a non-null TextureRegion, often taking up all of a Texture, that stores the images of the glyphs
      makeGridGlyphs - true if this should use its own way of rendering box-drawing/block-element glyphs, ignoring any in the font file
      ignoredStructuredJsonFlag - only present to distinguish this from other constructors; ignored
    • Font

      public Font(String jsonName, com.badlogic.gdx.graphics.g2d.TextureRegion textureRegion, float xAdjust, float yAdjust, float widthAdjust, float heightAdjust, boolean makeGridGlyphs, boolean ignoredStructuredJsonFlag)
      Creates a Font from a "Structured JSON" file produced by Chlumsky's msdf-atlas-gen tool, and uses it to assemble the many Font.GlyphRegions this has for each glyph. Reads the distance field type from the JSON.
      The msdf-atlas-gen tool can actually produce MSDF, SDF, PSDF, and "soft masked" (standard) fonts. It can't produce AngelCode BMFont .fnt files, but the JSON it can produce is fairly full-featured. Its handling of metrics seems significantly better than the tools that work with AngelCode BMFont .fnt files, so all the fonts in KnownFonts use JSON. A specialized version of msdf-atlas-gen that only writes structured JSON files (and optimizes the files at the right size) is available at fontwriter (Windows-only, for now).
      Parameters:
      jsonName - the name of a structured JSON font file this will load from an internal or local file handle (tried in that order)
      textureRegion - a non-null TextureRegion, often taking up all of a Texture, that stores the images of the glyphs
      xAdjust - how many pixels to offset each character's x-position by, moving to the right
      yAdjust - how many pixels to offset each character's y-position by, moving up
      widthAdjust - how many pixels to add to the used width of each character, using more to the right
      heightAdjust - how many pixels to add to the used height of each character, using more above
      makeGridGlyphs - true if this should use its own way of rendering box-drawing/block-element glyphs, ignoring any in the font file
      ignoredStructuredJsonFlag - only present to distinguish this from other constructors; ignored
    • Font

      public Font(com.badlogic.gdx.files.FileHandle jsonHandle, com.badlogic.gdx.graphics.g2d.TextureRegion textureRegion, boolean ignoredStructuredJsonFlag)
      Creates a Font from a "Structured JSON" file produced by Chlumsky's msdf-atlas-gen tool, and uses it to assemble the many Font.GlyphRegions this has for each glyph. Reads the distance field type from the JSON.
      The msdf-atlas-gen tool can actually produce MSDF, SDF, PSDF, and "soft masked" (standard) fonts. It can't produce AngelCode BMFont .fnt files, but the JSON it can produce is fairly full-featured. Its handling of metrics seems significantly better than the tools that work with AngelCode BMFont .fnt files, so all the fonts in KnownFonts use JSON. A specialized version of msdf-atlas-gen that only writes structured JSON files (and optimizes the files at the right size) is available at fontwriter (Windows-only, for now).
      Parameters:
      jsonHandle - the FileHandle of a structured JSON font file
      textureRegion - a non-null TextureRegion, often taking up all of a Texture, that stores the images of the glyphs
      ignoredStructuredJsonFlag - only present to distinguish this from other constructors; ignored
    • Font

      public Font(com.badlogic.gdx.files.FileHandle jsonHandle, com.badlogic.gdx.graphics.g2d.TextureRegion textureRegion, float xAdjust, float yAdjust, float widthAdjust, float heightAdjust, boolean makeGridGlyphs, boolean ignoredStructuredJsonFlag)
      Creates a Font from a "Structured JSON" file produced by Chlumsky's msdf-atlas-gen tool, and uses it to assemble the many Font.GlyphRegions this has for each glyph. Reads the distance field type from the JSON.
      The msdf-atlas-gen tool can actually produce MSDF, SDF, PSDF, and "soft masked" (standard) fonts. It can't produce AngelCode BMFont .fnt files, but the JSON it can produce is fairly full-featured. Its handling of metrics seems significantly better than the tools that work with AngelCode BMFont .fnt files, so all the fonts in KnownFonts use JSON. A specialized version of msdf-atlas-gen that only writes structured JSON files (and optimizes the files at the right size) is available at fontwriter (Windows-only, for now).
      Parameters:
      jsonHandle - the FileHandle of a structured JSON font file
      textureRegion - a non-null TextureRegion, often taking up all of a Texture, that stores the images of the glyphs
      xAdjust - how many pixels to offset each character's x-position by, moving to the right
      yAdjust - how many pixels to offset each character's y-position by, moving up
      widthAdjust - how many pixels to add to the used width of each character, using more to the right
      heightAdjust - how many pixels to add to the used height of each character, using more above
      makeGridGlyphs - true if this should use its own way of rendering box-drawing/block-element glyphs, ignoring any in the font file
      ignoredStructuredJsonFlag - only present to distinguish this from other constructors; ignored
  • Method Details

    • insertZeroWidthSpacesInCJK

      public static String insertZeroWidthSpacesInCJK(CharSequence text)
      Inserts a zero-width space character (Unicode U+200B) after every CJK ideographic character in text. This is meant to create word breaks where there might otherwise be none, to allow breaking lines up how at least written Chinese expects them to be broken up. This assumes there won't be any ideograms in color markup or effects, and won't add zero-width spaces to Latin, Greek, Cyrillic, or other non-CJK languages.
      The zero-width space character is automatically added to every Font that defines a normal space character (U+0020), and is literally a modified version of space that has zero width. This definition is allowed to overwrite an existing zero-width space character, but both should be invisible and have zero width (plus, not many fonts have a zero-width space without this modification).
      Parameters:
      text - a CharSequence such as a String, typically containing CJK ideograms
      Returns:
      a String where every CJK char has a zero-width space (U+200B) appended after it
    • getColorLookup

      public ColorLookup getColorLookup()
      Gets the ColorLookup this uses to look up colors by name.
      Returns:
      a ColorLookup implementation
    • setColorLookup

      public Font setColorLookup(ColorLookup lookup)
      Unlikely to be used in most games (meant more for other libraries), this allows changing how colors are looked up by name (or built) given a ColorLookup interface implementation.
      Parameters:
      lookup - a non-null ColorLookup
      Returns:
      this, for chaining
    • loadFNT

      protected void loadFNT(com.badlogic.gdx.files.FileHandle fntHandle, float xAdjust, float yAdjust, float widthAdjust, float heightAdjust, boolean makeGridGlyphs)
      The gritty parsing code that pulls relevant info from an AngelCode BMFont .fnt file and uses it to assemble the many Font.GlyphRegions this has for each glyph.
      Parameters:
      fntHandle - the FileHandle holding the path to a .fnt file
      xAdjust - added to the x-position for each glyph in the font
      yAdjust - added to the y-position for each glyph in the font
      widthAdjust - added to the glyph width for each glyph in the font
      heightAdjust - added to the glyph height for each glyph in the font
      makeGridGlyphs - true if this should use its own way of rendering box-drawing/block-element glyphs, ignoring any in the font file
    • loadSad

      protected void loadSad(String prefix, String fntName)
      The parsing code that pulls relevant info from a SadConsole .font configuration file and uses it to assemble the many Font.GlyphRegions this has for each glyph.
      Parameters:
      fntName - the name of a font file this will load from an internal or local file handle (tried in that order)
    • loadJSON

      protected void loadJSON(com.badlogic.gdx.files.FileHandle jsonHandle, com.badlogic.gdx.graphics.g2d.TextureRegion textureRegion, float xAdjust, float yAdjust, float widthAdjust, float heightAdjust, boolean makeGridGlyphs)
      The bulk of the loading code for Structured JSON fonts.
      Parameters:
      jsonHandle - the FileHandle of a structured JSON font file
      textureRegion - a non-null TextureRegion, often taking up all of a Texture, that stores the images of the glyphs
      xAdjust - how many pixels to offset each character's x-position by, moving to the right
      yAdjust - how many pixels to offset each character's y-position by, moving up
      widthAdjust - how many pixels to add to the used width of each character, using more to the right
      heightAdjust - how many pixels to add to the used height of each character, using more above
      makeGridGlyphs - true if this should use its own way of rendering box-drawing/block-element glyphs, ignoring any in the font file
    • getDistanceField

      public Font.DistanceFieldType getDistanceField()
      A Font.DistanceFieldType that should be Font.DistanceFieldType.STANDARD for most fonts, and can be Font.DistanceFieldType.SDF, Font.DistanceFieldType.MSDF, or Font.DistanceFieldType.SDF_OUTLINE if you know you have a font made to be used with one of those rendering techniques. See distanceFieldCrispness for one way to configure SDF and MSDF fonts, and resizeDistanceField(float, float) for an important method to handle window-resizing correctly.
    • setDistanceField

      public Font setDistanceField(Font.DistanceFieldType distanceField)
      Sets this Font's distance field type; this should be Font.DistanceFieldType.STANDARD for most fonts (meaning it is a normal bitmap font with no distance field effect), but specially-made fonts can use Font.DistanceFieldType.SDF or Font.DistanceFieldType.MSDF to get smoother scaling and/or sharper edges. Fonts compatible with SDF can use Font.DistanceFieldType.SDF_OUTLINE to show a black outline around all glyphs in the font.
      Parameters:
      distanceField - a DistanceFieldType enum constant; if null, this will be treated as Font.DistanceFieldType.STANDARD
      Returns:
      this, for chaining
    • kerningPair

      public int kerningPair(char first, char second)
      Assembles two chars into a kerning pair that can be looked up as a key in kerning. This is unlikely to be used by most user code, but can be useful for anything that's digging deeply into the internals here. If you give such a pair to kerning's IntFloatMap.get(int, float) method, you'll get the amount of extra space (in the same unit the font uses) this will insert between first and second.
      Parameters:
      first - the first char
      second - the second char
      Returns:
      a kerning pair that can be looked up in kerning
    • scale

      public Font scale(float both)
      Scales the font by the given multiplier, applying it both horizontally and vertically.
      Parameters:
      both - how much to multiply the width and height of each glyph by
      Returns:
      this Font, for chaining
    • scale

      public Font scale(float horizontal, float vertical)
      Scales the font by the given horizontal and vertical multipliers.
      Parameters:
      horizontal - how much to multiply the width of each glyph by
      vertical - how much to multiply the height of each glyph by
      Returns:
      this Font, for chaining
    • scaleTo

      public Font scaleTo(float width, float height)
      Scales the font so that it will have the given width and height.
      Parameters:
      width - the target width of the font, in world units
      height - the target height of the font, in world units
      Returns:
      this Font, for chaining
    • scaleHeightTo

      public Font scaleHeightTo(float height)
      Scales the font so that it will have the given height, keeping the current aspect ratio.
      Parameters:
      height - the target height of the font, in world units
      Returns:
      this Font, for chaining
    • adjustLineHeight

      public Font adjustLineHeight(float multiplier)
      Multiplies the line height by multiplier without changing the size of any characters. This can cut off the tops of letters if the multiplier is too small.
      Parameters:
      multiplier - will be applied to cellHeight and originalCellHeight
      Returns:
      this Font, for chaining
    • adjustCellWidth

      public Font adjustCellWidth(float multiplier)
      Multiplies the width used by each glyph in a monospaced font by multiplier without changing the size of any characters.
      Parameters:
      multiplier - will be applied to cellWidth and originalCellWidth
      Returns:
      this Font, for chaining
    • fitCell

      public Font fitCell(float width, float height, boolean center)
      Fits all chars into cells width by height in size, and optionally centers them in their cells. This sets isMono to true, and kerning to null. If you call scaleTo(float, float) after this, you will need to call fitCell() again to update cell size.
      Parameters:
      width - the target width of a cell, in world units
      height - the target height of a cell, in world units
      center - if true, this will center every glyph in its cell
      Returns:
      this Font, for chaining
    • getUnderlineX

      public float getUnderlineX()
    • getUnderlineY

      public float getUnderlineY()
    • setUnderlinePosition

      public Font setUnderlinePosition(float underX, float underY)
    • setUnderlineMetrics

      public Font setUnderlineMetrics(float underX, float underY, float underLength, float underBreadth)
    • getStrikethroughX

      public float getStrikethroughX()
    • getStrikethroughY

      public float getStrikethroughY()
    • setStrikethroughPosition

      public Font setStrikethroughPosition(float strikeX, float strikeY)
    • setStrikethroughMetrics

      public Font setStrikethroughMetrics(float strikeX, float strikeY, float strikeLength, float strikeBreadth)
    • setLineMetrics

      public Font setLineMetrics(float x, float y, float length, float breadth)
      Sets both the underline and strikethrough metric adjustments with the same values, as if you called both setUnderlineMetrics(float, float, float, float) and setStrikethroughMetrics(float, float, float, float) with identical parameters. This does not affect "fancy lines" (the zigzag lines produced by error, warning, and note effects).
      This affects "Zen" metrics, which means it is measured in fractions of cellWidth or cellHeight (as appropriate), and each metric only affects one value (even though this sets two metrics for each parameter).
      Parameters:
      x - adjustment for the underline and strikethrough x-position, affecting the left side of each line
      y - adjustment for the underline and strikethrough y-position, affecting the bottom side of each line
      length - adjustment for the underline and strikethrough x-size, affecting the extra part drawn to the right of each line
      breadth - adjustment for the underline and strikethrough y-size, affecting how thick each line is from bottom to top
      Returns:
      this, for chaining
    • getFancyLineX

      public float getFancyLineX()
    • getFancyLineY

      public float getFancyLineY()
    • setFancyLinePosition

      public Font setFancyLinePosition(float x, float y)
      Sets both the "fancy line" metric adjustments for position, only changing fancyX and fancyY. "Fancy lines" are the zigzag lines produced by error, warning, and note effects. This does not change the normal underline or the strikethrough styles.
      This affects "Zen" metrics, which means it is measured in fractions of cellWidth or cellHeight (as appropriate), and each metric only affects one value (even though this sets two metrics for each parameter).
      Parameters:
      x - adjustment for the "fancy line" x-position, affecting the left side of each line
      y - adjustment for the "fancy line" y-position, affecting the bottom side of each line
      Returns:
      this, for chaining
    • getInlineImageOffsetX

      public float getInlineImageOffsetX()
    • getInlineImageOffsetY

      public float getInlineImageOffsetY()
    • getInlineImageXAdvance

      public float getInlineImageXAdvance()
    • setInlineImageMetrics

      public Font setInlineImageMetrics(float offsetX, float offsetY, float xAdvance)
      Sets the adjustments added to the metric for inline images added with addAtlas(TextureAtlas) (or its overloads).
      Changing offsetX with a positive value moves all GlyphRegions to the right. Changing offsetY with a positive value moves all GlyphRegions down (this is possibly unexpected). Changing xAdvance with a positive value will shrink all GlyphRegions (this is probably unexpected).
      Parameters:
      offsetX - will be added to the Font.GlyphRegion.offsetX of each added glyph; positive change moves a GlyphRegion to the right
      offsetY - will be added to the Font.GlyphRegion.offsetY of each added glyph; positive change moves a GlyphRegion down
      xAdvance - will be added to the xAdvance(com.github.tommyettinger.textra.Font, float, long) of each added glyph; positive change shrinks a GlyphRegion due to how size is calculated
      Returns:
      this Font, for chaining
    • setTextureFilter

      public Font setTextureFilter()
      Calls setTextureFilter(Texture.TextureFilter, Texture.TextureFilter) with Texture.TextureFilter.Linear for both min and mag filters. This is the most common usage for setting the texture filters, and is appropriate when you have a large TextureRegion holding the font and you normally downscale it. This is automatically done for Font.DistanceFieldType.SDF, Font.DistanceFieldType.MSDF, and Font.DistanceFieldType.SDF_OUTLINE fonts, but you may also want to use it for Font.DistanceFieldType.STANDARD fonts when downscaling (they can look terrible if the default Texture.TextureFilter.Nearest filter is used). Note that this sets the filter on every Texture that holds a TextureRegion used by the font, so it may affect the filter on other parts of an atlas.
      Returns:
      this, for chaining
    • setTextureFilter

      public Font setTextureFilter(com.badlogic.gdx.graphics.Texture.TextureFilter minFilter, com.badlogic.gdx.graphics.Texture.TextureFilter magFilter)
      Sets the texture filters on each Texture that holds a TextureRegion used by the font to the given minFilter and magFilter. You may want to use this to set a font using Font.DistanceFieldType.STANDARD to use a better TextureFilter for smooth downscaling, like Texture.TextureFilter.MipMapLinearLinear or just Texture.TextureFilter.Linear. You might, for some reason, want to set a font using Font.DistanceFieldType.SDF, Font.DistanceFieldType.MSDF, or Font.DistanceFieldType.SDF_OUTLINE to use TextureFilters other than its default Texture.TextureFilter.Linear. Note that this may affect the filter on other parts of an atlas.
      Returns:
      this, for chaining
    • useIntegerPositions

      public Font useIntegerPositions(boolean integer)
      A no-op unless this is a subclass that overrides handleIntegerPosition(float).
      Parameters:
      integer - usually ignored
      Returns:
      this for chaining
    • getDescent

      public float getDescent()
    • setDescent

      public Font setDescent(float descent)
    • getName

      public String getName()
    • setName

      public Font setName(String name)
    • getObliqueStrength

      public float getObliqueStrength()
    • setObliqueStrength

      public Font setObliqueStrength(float obliqueStrength)
    • getBoldStrength

      public float getBoldStrength()
    • setBoldStrength

      public Font setBoldStrength(float boldStrength)
    • getOutlineStrength

      public float getOutlineStrength()
    • setOutlineStrength

      public Font setOutlineStrength(float outlineStrength)
    • getBoxDrawingBreadth

      public float getBoxDrawingBreadth()
      When makeGridGlyphs is passed as true to a constructor here, box drawing and other block elements will be drawn using a solid block GlyphRegion that is stretched and moved to form various lines and blocks. Setting this field to something other than 1 affects how wide the lines are for box drawing characters only; this is acts as a multiplier on the original width of a line. Normal box drawing lines such as those in β”Œ are 0.1f of a cell across. Thick lines such as those in ┏ are 0.2f of a cell across. Double lines such as those in β•” are two normal lines, 0.1f of a cell apart; double lines are not affected by this field.
      Returns:
      the current box drawing breadth multiplier, which defaults to 1
    • setBoxDrawingBreadth

      public Font setBoxDrawingBreadth(float boxDrawingBreadth)
      When makeGridGlyphs is passed as true to a constructor here, box drawing and other block elements will be drawn using a solid block GlyphRegion that is stretched and moved to form various lines and blocks. Setting this field to something other than 1 affects how wide the lines are for box drawing characters only; this is acts as a multiplier on the original width of a line. Normal box drawing lines such as those in β”Œ are 0.1f of a cell across. Thick lines such as those in ┏ are 0.2f of a cell across. Double lines such as those in β•” are two normal lines, 0.1f of a cell apart; double lines are not affected by this field.
      Parameters:
      boxDrawingBreadth - the new float value to use for the box drawing breadth multiplier
      Returns:
      this, for chaining
    • getFamily

      public Font.FontFamily getFamily()
      Gets the FontFamily this can use to switch fonts using [@Name] syntax. If the family is null, only the current Font will be used.
      Returns:
      the current FontFamily this Font uses, or null if this does not have one
    • setFamily

      public Font setFamily(Font.FontFamily family)
      Sets the FontFamily this can use to switch fonts using [@Name] syntax. If family is null, only the current Font will be used.
      Parameters:
      family - a Font.FontFamily that may be null or shared with other Fonts.
      Returns:
      this, for chaining
    • getCrispness

      public float getCrispness()
      Gets the "crispness" multiplier for distance field fonts (SDF and MSDF). There is no default value, because this depends on how an individual distance field font was created. Typical values range from 1.5 to 4.5 . Lower values look softer and fuzzier, while higher values look sharper and possibly more jagged. This is used as a persistent multiplier that can be configured per-font, whereas actualCrispness is the working value that changes often but is influenced by this one. This variable is used by resizeDistanceField(float, float) to affect the working crispness value.
      Returns:
      the current crispness multiplier, as a float
    • setCrispness

      public Font setCrispness(float crispness)
      Sets the "crispness" multiplier for distance field fonts (SDF and MSDF). There is no default value, because this depends on how an individual distance field font was created. Typical values range from 1.5 to 4.5 . Lower values look softer and fuzzier, while higher values look sharper and possibly more jagged. This is used as a persistent multiplier that can be configured per-font, whereas actualCrispness is the working value that changes often but is influenced by this one. This variable is used by resizeDistanceField(float, float) to affect the working crispness value. Changing the crispness does nothing unless you also resize the distance field, for each font you are rendering. So make sure to call resizeDistanceField(float, float) in resize() !
      Parameters:
      crispness - a float multiplier to be applied to the working crispness; often between 1.5 and 4.5
      Returns:
      this Font, for chaining
    • multiplyCrispness

      public Font multiplyCrispness(float multiplier)
      Takes the "crispness" multiplier for distance field fonts (SDF and MSDF) and multiplies it by another multiplier. There is no default value for crispness, because this depends on how an individual distance field font was created. Typical values range from 1.5 to 4.5 . Lower values look softer and fuzzier, while higher values look sharper and possibly more jagged. This affects a persistent multiplier that can be configured per-font, whereas actualCrispness is the working value that changes often but is influenced by this one. The variable this affects is used by resizeDistanceField(float, float) to affect the working crispness value. Changing the crispness does nothing unless you also resize the distance field, for each font you are rendering. So make sure to call resizeDistanceField(float, float) in resize() !
      Parameters:
      multiplier - a float multiplier to be applied to the working crispness multiplier
      Returns:
      this Font, for chaining
    • addImage

      public Font addImage(String character, com.badlogic.gdx.graphics.g2d.TextureRegion region, float offsetX, float offsetY, float xAdvance)
      Makes this Font "learn" a new mapping from a char (typically an emoji in a String for character) to a TextureRegion, allowing any offsets on x or y to be specified as well as the amount of horizontal space the resulting GlyphRegion should use. The most common way to call this uses a String containing one emoji character, because those are relatively easy to enter with a clear result. Because most emoji are technically more than one Java char, we only use the last char in character, which usually is a value that only overlaps with a private-use area character (and most of those are unused). Some emoji glyphs require more characters than normal, such as any with human skin tones. These won't be handled well... You may want to use the [+scientist, dark skin tone] or [+πŸ§‘πŸΏβ€πŸ”¬] syntax for multipart emoji when you actually have an atlas full of emoji to draw from, such as the one used by KnownFonts.addEmoji(Font).
      Parameters:
      character - a String containing at least one character; only the last char (not codepoint) will be used
      region - the TextureRegion to associate with the given character
      offsetX - the x offset to position the drawn TextureRegion at, with positive offset moving right
      offsetY - the y offset to position the drawn TextureRegion at, with positive offset moving up
      xAdvance - how much horizontal space the GlyphRegion should take up
      Returns:
      this Font, for chaining
    • addImage

      public Font addImage(String character, com.badlogic.gdx.graphics.g2d.TextureRegion region)
      Makes this Font "learn" a new mapping from a char (typically an emoji in a String for character) to a TextureRegion. The GlyphRegion that will be placed into mapping will have 0 for its offsetX and offsetY, and its xAdvance will be the same as region's TextureRegion.getRegionWidth(). The most common way to call this uses a String containing one emoji character, because those are relatively easy to enter with a clear result. Because most emoji are technically more than one Java char, we only use the last char in character, which usually is a value that only overlaps with a private-use area character (and most of those are unused). Some emoji glyphs require more characters than normal, such as any with human skin tones. These won't be handled well... You may want to use the [+scientist, dark skin tone] or [+πŸ§‘πŸΏβ€πŸ”¬] syntax for multipart emoji when you actually have an atlas full of emoji to draw from, such as the one used by KnownFonts.addEmoji(Font).
      Parameters:
      character - a String containing at least one character; only the last char (not codepoint) will be used
      region - the TextureRegion to associate with the given character
      Returns:
      this Font, for chaining
    • addAtlas

      public Font addAtlas(com.badlogic.gdx.graphics.g2d.TextureAtlas atlas)
      Adds all items in atlas to the private use area of mapping, and stores their names, so they can be looked up with [+saxophone] syntax (which is often the same as the [+🎷] syntax). The names of TextureRegions in the atlas are treated as case-insensitive, like some file systems. There are possible emoji atlases here. This may be useful if you have your own atlas, but for Twemoji in particular, you can use KnownFonts.addEmoji(Font) and the Twemoji files in the knownFonts folder.
      Parameters:
      atlas - a TextureAtlas that shouldn't have more than 6144 names; all of it will be used
      Returns:
      this Font, for chaining
    • addAtlas

      public Font addAtlas(com.badlogic.gdx.graphics.g2d.TextureAtlas atlas, float offsetXChange, float offsetYChange, float xAdvanceChange)
      Adds all items in atlas to the private use area of mapping, and stores their names, so they can be looked up with [+saxophone] syntax (which is often the same as the [+🎷] syntax). The names of TextureRegions in the atlas are treated as case-insensitive, like some file systems. There are possible emoji atlases here. This may be useful if you have your own atlas, but for Twemoji in particular, you can use KnownFonts.addEmoji(Font) and the Twemoji files in the knownFonts folder. This overload allows specifying adjustments to the font-like properties of each GlyphRegion added, which may be useful if images from a particular atlas show up with an incorrect position or have the wrong spacing.
      Changing offsetXChange with a positive value moves all GlyphRegions to the right. Changing offsetYChange with a positive value moves all GlyphRegions down (this is possibly unexpected). Changing xAdvanceChange with a positive value will shrink all GlyphRegions (this is probably unexpected). Each of the metric changes has a variable from this Font added to it; inlineImageOffsetX, inlineImageOffsetY, and inlineImageXAdvance all are added in here.
      Parameters:
      atlas - a TextureAtlas that shouldn't have more than 6144 names; all of it will be used
      offsetXChange - will be added to the Font.GlyphRegion.offsetX of each added glyph; positive change moves a GlyphRegion to the right
      offsetYChange - will be added to the Font.GlyphRegion.offsetY of each added glyph; positive change moves a GlyphRegion down
      xAdvanceChange - will be added to the xAdvance(com.github.tommyettinger.textra.Font, float, long) of each added glyph; positive change shrinks a GlyphRegion due to how size is calculated
      Returns:
      this Font, for chaining
    • addAtlas

      public Font addAtlas(com.badlogic.gdx.graphics.g2d.TextureAtlas atlas, String prepend, String append, float offsetXChange, float offsetYChange, float xAdvanceChange)
      Adds all items in atlas to the private use area of mapping, and stores their names, so they can be looked up with [+saxophone] syntax (which is often the same as the [+🎷] syntax). The names of TextureRegions in the atlas are treated as case-insensitive, like some file systems. There are possible emoji atlases here. This may be useful if you have your own atlas, but for Twemoji in particular, you can use KnownFonts.addEmoji(Font) and the Twemoji files in the knownFonts folder. This overload allows specifying adjustments to the font-like properties of each GlyphRegion added, which may be useful if images from a particular atlas show up with an incorrect position or have the wrong spacing. It also allows specifying a String to prepend and to append that will be prepended and appended to each name, respectively. Either or both of the Strings to prepend and append may be empty (or equivalently here, null).
      Changing offsetXChange with a positive value moves all GlyphRegions to the right. Changing offsetYChange with a positive value moves all GlyphRegions down (this is possibly unexpected). Changing xAdvanceChange with a positive value will shrink all GlyphRegions (this is probably unexpected). Each of the metric changes has a variable from this Font added to it; inlineImageOffsetX, inlineImageOffsetY, and inlineImageXAdvance all are added in here.
      Parameters:
      atlas - a TextureAtlas that shouldn't have more than 6144 names; all of it will be used
      prepend - will be prepended before each name in the atlas; if null, will be treated as ""
      append - will be appended after each name in the atlas; if null, will be treated as ""
      offsetXChange - will be added to the Font.GlyphRegion.offsetX of each added glyph; positive change moves a GlyphRegion to the right
      offsetYChange - will be added to the Font.GlyphRegion.offsetY of each added glyph; positive change moves a GlyphRegion down
      xAdvanceChange - will be added to the xAdvance(com.github.tommyettinger.textra.Font, float, long) of each added glyph; positive change shrinks a GlyphRegion due to how size is calculated
      Returns:
      this Font, for chaining
    • atlasLookup

      public int atlasLookup(String name)
      Gets the char that might be associated with name in at Atlas added to this (see addAtlas(TextureAtlas), or returns the int -1 if the name could not be found. This will only return a negative result if the name was not found. This can be useful to look up complex names, such as emoji entered by a user, and get the char that can be used to render such an emoji. The name is treated as case-insensitive. If you are certain a name is present, you can cast the result immediately to a char to use it normally.
      Parameters:
      name - a name from a TextureAtlas added to this Font, looked up as case-insensitive
      Returns:
      the char that the given name is associated with, as an int in the char range if found, or -1 otherwise
    • enableShader

      public void enableShader(com.badlogic.gdx.graphics.g2d.Batch batch)
      Must be called before drawing anything with an SDF or MSDF font; does not need to be called for other fonts unless you are mixing them with SDF/MSDF fonts or other shaders. This also resets the Batch color to white, in case it had been left with a different setting before. If this Font is not an SDF or MSDF font, then this resets batch's shader to the default (using batch.setShader(null)).
      This is called automatically for TextraLabel and TypingLabel if it hasn't been called already. You may still want to call this automatically for those cases if you have multiple such Labels that use the same Font; in that case, you can draw several Labels without ending the current batch. You do need to set the shader back to whatever you use for other items before you draw those, typically with batch.setShader(null); .
      Like all distance field code here, this is dependent on calling resizeDistanceField(float, float) in your ApplicationListener.resize(int, int) method, since that allows the distance field to be scaled correctly to the screen. Without calling resizeDistanceField(), distance field fonts will look terrible.
      Parameters:
      batch - the Batch to instruct to use the appropriate shader for this font; should usually be a SpriteBatch
    • resumeDistanceFieldShader

      public void resumeDistanceFieldShader(com.badlogic.gdx.graphics.g2d.Batch batch)
      If a distance field font needs to be drawn with a different size, different crispness, or a different Texture altogether (such as to draw an icon or emoji), you can call this just before you start drawing distance field text with this Font. You should only call this when you just changed something that affects how distance fields are drawn, which primarily means actualCrispness, cellHeight, originalCellHeight, cellWidth, or originalCellWidth, and also includes Texture changes to non-distance-field Textures. This should not be called immediately after enableShader(Batch), since they do similar things. This does nothing if this font is not a distance field font. It also does nothing if batch's shader is different from the shader this Font uses. Otherwise, this flushes batch and sets a uniform ("u_smoothing") to a value calculated with the ratio of current cell size to original (unscaled) cell size.
      Typically, if you call pauseDistanceFieldShader(Batch), you call this method later to resume drawing with a distance field. This is usually done automatically by TextraLabel and TypingLabel.
      Like all distance field code here, this is dependent on calling resizeDistanceField(float, float) in your ApplicationListener.resize(int, int) method, since that allows the distance field to be scaled correctly to the screen. Without calling resizeDistanceField(), distance field fonts will look terrible.
      Parameters:
      batch - a Batch that should be running (between Batch.begin() and Batch.end())
    • pauseDistanceFieldShader

      public void pauseDistanceFieldShader(com.badlogic.gdx.graphics.g2d.Batch batch)
      If a distance field font needs to have its distance field effect disabled temporarily (such as to draw an icon or emoji), you can call this just before you start drawing the non-distance-field images. You should only call this just before drawing from a non-distance-field Texture. This flushes batch and sets a uniform ("u_smoothing") to 0, unless that uniform was already 0 (then this doesn't flush, or do anything).
      You can resume using the distance field by calling resumeDistanceFieldShader(Batch). This is usually done automatically by TextraLabel and TypingLabel.
      Like all distance field code here, this is dependent on calling resizeDistanceField(float, float) in your ApplicationListener.resize(int, int) method, since that allows the distance field to be scaled correctly to the screen. Without calling resizeDistanceField(), distance field fonts will look terrible.
      Parameters:
      batch - a Batch that should be running (between Batch.begin() and Batch.end())
    • drawText

      public void drawText(com.badlogic.gdx.graphics.g2d.Batch batch, CharSequence text, float x, float y)
      Draws the specified text at the given x,y position (in world space) with a white foreground.
      Parameters:
      batch - typically a SpriteBatch
      text - typically a String, but this can also be a StringBuilder or some custom class
      x - the x position in world space to start drawing the text at (lower left corner)
      y - the y position in world space to start drawing the text at (lower left corner)
    • drawText

      public void drawText(com.badlogic.gdx.graphics.g2d.Batch batch, CharSequence text, float x, float y, int color)
      Draws the specified text at the given x,y position (in world space) with the given foreground color.
      Parameters:
      batch - typically a SpriteBatch
      text - typically a String, but this can also be a StringBuilder or some custom class
      x - the x position in world space to start drawing the text at (lower left corner)
      y - the y position in world space to start drawing the text at (lower left corner)
      color - an int color; typically this is RGBA, but custom shaders or Batches can use other kinds of color
    • drawBlocks

      public void drawBlocks(com.badlogic.gdx.graphics.g2d.Batch batch, int[][] colors, float x, float y)
      Draws a grid made of rectangular blocks of int colors (typically RGBA) at the given x,y position in world space. This is only useful for monospace fonts. This assumes there is a full-block character at solidBlock, so you should have set that field; most fonts in KnownFonts have a solid block char set already. The colors parameter should be a rectangular 2D array, and because any colors that are the default int value 0 will be treated as transparent RGBA values, if a value is not assigned to a slot in the array then nothing will be drawn there. The 2D array is treated as [x][y] indexed here. This is usually called before other methods that draw foreground text.
      Internally, this uses drawVertices(Batch, Texture, float[]) to draw each rectangle with minimal overhead, and this also means it is unaffected by the batch color unless drawVertices was overridden. If you want to alter the colors using a shader, the shader will receive each color in colors as its a_color attribute, the same as if it was passed via the batch color.
      If you want to change the alpha of the colors array, you can use ColorUtils.multiplyAllAlpha(int[][], float).
      Parameters:
      batch - typically a SpriteBatch
      colors - a 2D rectangular array of int colors (typically RGBA)
      x - the x position in world space to draw the text at (lower left corner)
      y - the y position in world space to draw the text at (lower left corner)
    • drawBlocks

      public void drawBlocks(com.badlogic.gdx.graphics.g2d.Batch batch, char blockChar, int[][] colors, float x, float y)
      Draws a grid made of rectangular blocks of int colors (typically RGBA) at the given x,y position in world space. This is only useful for monospace fonts. The blockChar should visually be represented by a very large block, occupying all of a monospaced cell. The colors parameter should be a rectangular 2D array, and because any colors that are the default int value 0 will be treated as transparent RGBA values, if a value is not assigned to a slot in the array then nothing will be drawn there. The 2D array is treated as [x][y] indexed here. This is usually called before other methods that draw foreground text.
      Internally, this uses drawVertices(Batch, Texture, float[]) to draw each rectangle with minimal overhead, and this also means it is unaffected by the batch color unless drawVertices was overridden. If you want to alter the colors using a shader, the shader will receive each color in colors as its a_color attribute, the same as if it was passed via the batch color.
      If you want to change the alpha of the colors array, you can use ColorUtils.multiplyAllAlpha(int[][], float).
      Parameters:
      batch - typically a SpriteBatch
      blockChar - a char that renders as a full block, occupying an entire monospaced cell with a color
      colors - a 2D rectangular array of int colors (typically RGBA)
      x - the x position in world space to draw the text at (lower left corner)
      y - the y position in world space to draw the text at (lower left corner)
    • drawBlockSequence

      protected void drawBlockSequence(com.badlogic.gdx.graphics.g2d.Batch batch, float[] sequence, com.badlogic.gdx.graphics.g2d.TextureRegion block, float color, float x, float y, float width, float height, float rotation)
      An internal method that draws blocks in a sequence specified by a float[], with the block usually solidBlock (but not always). This is somewhat complicated; the sequence is typically drawn directly from BlockUtils. Draws block at the given width and height, in the given packed color, rotating by the specified amount in degrees.
      Parameters:
      batch - typically a SpriteBatch
      sequence - a sequence of instructions in groups of 4: starting x, starting y, width to draw, height to draw
      block - the TextureRegion to use as a block for drawing; usually solidBlock
      color - the color as a packed float
      x - the x position to draw at
      y - the y position to draw at
      width - the width of one cell for the purposes of sequence instructions
      height - the height of one cell for the purposes of sequence instructions
      rotation - the rotation in degrees to use for the cell of blocks, with the origin in the center of the cell
    • drawBlockSequence

      protected void drawBlockSequence(com.badlogic.gdx.graphics.g2d.Batch batch, float[] sequence, com.badlogic.gdx.graphics.g2d.TextureRegion block, float color, float x, float y, float width, float height, float rotation, float breadth)
      An internal method that draws blocks in a sequence specified by a float[], with the block usually solidBlock (but not always). This is somewhat complicated; the sequence is typically drawn directly from BlockUtils. Draws block at the given width and height, in the given packed color, rotating by the specified amount in degrees. This overload also allows specifying a breadth multiplier for box drawing character lines, which can help match the aesthetic of a given font. The breadth multiplier only affects box drawing characters, but not any with double lines, nor does it affect block elements.
      Parameters:
      batch - typically a SpriteBatch
      sequence - a sequence of instructions in groups of 4: starting x, starting y, width to draw, height to draw
      block - the TextureRegion to use as a block for drawing; usually solidBlock
      color - the color as a packed float
      x - the x position to draw at
      y - the y position to draw at
      width - the width of one cell for the purposes of sequence instructions
      height - the height of one cell for the purposes of sequence instructions
      rotation - the rotation in degrees to use for the cell of blocks, with the origin in the center of the cell
      breadth - a multiplier applied only to the size of box-drawing characters going across the line(s); breadth changes are not performed if this is 1
    • drawFancyLine

      protected void drawFancyLine(com.badlogic.gdx.graphics.g2d.Batch batch, long mode, float x, float y, float width, float xPx, float yPx, float rotation)
      An internal method that draws blocks in a sequence specified by a mode, with the block always solidBlock. Draws the solidBlock at a very small size (determined by xPx and yPx, which are usually sized to one pixel each), repeating in a pattern to fill the given width and part of the given height, in the given packed color, rotating by the specified amount in degrees.
      Parameters:
      batch - typically a SpriteBatch
      mode - currently must be ERROR, WARN, or NOTE, determining the pattern
      x - the x position to draw at
      y - the y position to draw at
      width - the width of one cell in world units
      xPx - the width of one pixel, approximately, in world units
      yPx - the height of one pixel, approximately, in world units
      rotation - the rotation in degrees to use for the cell of blocks, with the origin in the center of the cell
    • drawMarkupText

      public int drawMarkupText(com.badlogic.gdx.graphics.g2d.Batch batch, String text, float x, float y)
      Draws the specified text at the given x,y position (in world space), parsing an extension of libGDX markup and using it to determine color, size, position, shape, strikethrough, underline, case, and scale of the given CharSequence. The text drawn will start as white, with the normal size as by cellWidth and cellHeight, normal case, and without bold, italic, superscript, subscript, strikethrough, or underline. Markup starts with [; the next non-letter character determines what that piece of markup toggles. Markup this knows:
      • [] undoes the most-recently-applied format change.
      • [ ] clears all markup to the initial state without any applied.
      • [(label)] temporarily stores the current formatting state as label.
      • [ label] re-applies the formatting state stored as label, if there is one.
      • [[ escapes a literal left bracket, producing it without changing state.
      • [+name], where name is the name of a TextureRegion from an atlas added to this Font with addAtlas(TextureAtlas), produces the corresponding TextureRegion (scaled when drawn) without changing state. If no atlas has been added, this emits a + character instead.
      • [*] toggles bold mode.
      • [/] toggles italic (technically, oblique) mode.
      • [^] toggles superscript mode (and turns off subscript or midscript mode).
      • [=] toggles midscript mode (and turns off superscript or subscript mode).
      • [.] toggles subscript mode (and turns off superscript or midscript mode).
      • [_] toggles underline mode.
      • [~] toggles strikethrough mode.
      • [!] toggles all upper case mode.
      • [,] toggles all lower case mode.
      • [;] toggles capitalize each word mode.
      • [%P], where P is a percentage from 0 to 375, changes the scale to that percentage (rounded to the nearest 25% mark).
      • [%], with no number just after it, resets scale to 100%.
      • [@Name], where Name is a key in family, changes the current Font used for rendering to the Font in this.family by that name. This is ignored if family is null.
      • [@], with no text just after it, resets the font to this one (which should be item 0 in family, if family is non-null).
      • [#HHHHHHHH], where HHHHHHHH is a hex RGB888 or RGBA8888 int color, changes the color.
      • [COLORNAME], where "COLORNAME" is a typically-upper-case color name that will be looked up with getColorLookup(), changes the color. The name can optionally be preceded by |, which allows looking up colors with names that contain punctuation.

      Parsing markup for a full screen every frame typically isn't necessary, and you may want to store the most recent glyphs by calling markup(String, Layout) and render its result with drawGlyphs(Batch, Layout, float, float) every frame.
      Parameters:
      batch - typically a SpriteBatch
      text - typically a String with markup, but this can also be a StringBuilder or some custom class
      x - the x position in world space to start drawing the text at (lower left corner)
      y - the y position in world space to start drawing the text at (lower left corner)
      Returns:
      the number of glyphs drawn
    • drawGlyphs

      public float drawGlyphs(com.badlogic.gdx.graphics.g2d.Batch batch, Layout glyphs, float x, float y)
      Draws the specified Layout of glyphs with a Batch at a given x, y position, drawing the full layout.
      Parameters:
      batch - typically a SpriteBatch
      glyphs - typically returned as part of markup(String, Layout)
      x - the x position in world space to start drawing the glyph at (lower left corner)
      y - the y position in world space to start drawing the glyph at (lower left corner)
      Returns:
      the total distance in world units all drawn Lines use up from left to right
    • drawGlyphs

      public float drawGlyphs(com.badlogic.gdx.graphics.g2d.Batch batch, Layout glyphs, float x, float y, int align)
      Draws the specified Layout of glyphs with a Batch at a given x, y position, using align to determine how to position the text. Typically, align is Align.left, Align.center, or Align.right, which make the given x,y point refer to the lower-left corner, center-bottom edge point, or lower-right corner, respectively.
      Parameters:
      batch - typically a SpriteBatch
      glyphs - typically returned by markup(String, Layout)
      x - the x position in world space to start drawing the glyph at (where this is depends on align)
      y - the y position in world space to start drawing the glyph at (where this is depends on align)
      align - an Align constant; if Align.left, x and y refer to the lower left corner
      Returns:
      the total distance in world units all drawn Lines use up from left to right
    • drawGlyphs

      public float drawGlyphs(com.badlogic.gdx.graphics.g2d.Batch batch, Layout glyphs, float x, float y, int align, float rotation, float originX, float originY)
      Draws the specified Layout of glyphs with a Batch at a given x, y position, rotated using dedegrees around the given origin point, using align to determine how to position the text. Typically, align is Align.left, Align.center, or Align.right, but it can have a vertical component as well.
      Parameters:
      batch - typically a SpriteBatch
      glyphs - typically returned by markup(String, Layout)
      x - the x position in world space to start drawing the glyph at (where this is depends on align)
      y - the y position in world space to start drawing the glyph at (where this is depends on align)
      align - an Align constant; if Align.left, x and y refer to the left edge of the first Line
      rotation - measured in degrees counterclockwise, typically 0-360, and applied to the whole Layout
      originX - the x position in world space of the point to rotate around
      originY - the y position in world space of the point to rotate around
      Returns:
      the total distance in world units all drawn Lines use up from lines along the given rotation
    • drawGlyphs

      public float drawGlyphs(com.badlogic.gdx.graphics.g2d.Batch batch, Line glyphs, float x, float y)
      Draws the specified Line of glyphs with a Batch at a given x, y position, drawing the full Line using left alignment.
      Parameters:
      batch - typically a SpriteBatch
      glyphs - typically returned as part of markup(String, Layout)
      x - the x position in world space to start drawing the glyph at (lower left corner)
      y - the y position in world space to start drawing the glyph at (lower left corner)
      Returns:
      the distance in world units the drawn Line uses, left to right
    • drawGlyphs

      public float drawGlyphs(com.badlogic.gdx.graphics.g2d.Batch batch, Line glyphs, float x, float y, int align)
      Draws the specified Line of glyphs with a Batch at a given x, y position, using align to determine how to position the text. Typically, align is Align.left, Align.center, or Align.right, which make the given x,y point refer to the lower-left corner, center-bottom edge point, or lower-right corner, respectively.
      Parameters:
      batch - typically a SpriteBatch
      glyphs - typically returned as part of markup(String, Layout)
      x - the x position in world space to start drawing the glyph at (where this is depends on align)
      y - the y position in world space to start drawing the glyph at (where this is depends on align)
      align - an Align constant; if Align.left, x and y refer to the lower left corner
      Returns:
      the distance in world units the drawn Line uses, left to right
    • drawGlyphs

      public float drawGlyphs(com.badlogic.gdx.graphics.g2d.Batch batch, Line glyphs, float x, float y, int align, float rotation, float originX, float originY)
      Draws the specified Line of glyphs with a Batch at a given x, y position, rotated using degrees around the given origin point, using align to determine how to position the text. Typically, align is Align.left, Align.center, or Align.right, but it can have a vertical component as well.
      Parameters:
      batch - typically a SpriteBatch
      glyphs - typically returned as part of markup(String, Layout)
      x - the x position in world space to start drawing the glyph at (where this is depends on align)
      y - the y position in world space to start drawing the glyph at (where this is depends on align)
      align - an Align constant; if Align.left, x and y refer to the lower left corner
      rotation - measured in degrees counterclockwise and applied to the whole Line
      originX - the x position in world space of the point to rotate around
      originY - the y position in world space of the point to rotate around
      Returns:
      the distance in world units the drawn Line uses up out of a line along the given rotation
    • xAdvance

      public static float xAdvance(Font font, float scale, long glyph)
      Gets the distance to advance the cursor after drawing glyph, scaled by scale as if drawing. This handles monospaced fonts correctly and ensures that for variable-width fonts, subscript, midscript, and superscript halve the advance amount. This does not consider kerning, if the font has it. If the glyph is fully transparent, this does not draw it at all, and treats its x advance as 0. This version of xAdvance does not read the scale information from glyph, and instead takes it from the scale parameter. This takes a Font to allow for families to swap out the current font for a different one.
      Parameters:
      font - the Font object to use to measure
      scale - the scale to draw the glyph at, usually scaleX and possibly adjusted by per-glyph scaling
      glyph - a long encoding the color, style information, and char of a glyph, as from a Line
      Returns:
      the (possibly non-integer) amount to advance the cursor when you draw the given glyph, not counting kerning
    • xAdvance

      public float xAdvance(long glyph)
      Gets the distance to advance the cursor after drawing glyph, scaled by scaleX as if drawing. This handles monospaced fonts correctly and ensures that for variable-width fonts, subscript, midscript, and superscript halve the advance amount. This does not consider kerning, if the font has it. If the glyph is fully transparent, this does not draw it at all, and treats its x advance as 0. This only uses the current font, and will not consider swapped-out fonts from a family.
      Parameters:
      glyph - a long encoding the color, style information, and char of a glyph, as from a Line
      Returns:
      the (possibly non-integer) amount to advance the cursor when you draw the given glyph, not counting kerning
    • measureWidth

      public float measureWidth(Line line)
      Measures the actual width that the given Line will use when drawn.
      Parameters:
      line - a Line, as from inside a Layout
      Returns:
      the width in world units
    • calculateSize

      public float calculateSize(Line line)
      Measures the actual width that the given Line will use when drawn, and sets it into the Line's Line.width field.
      Parameters:
      line - a Line, as from inside a Layout
      Returns:
      the width in world units
    • calculateSize

      public float calculateSize(Layout layout)
      Given a Layout that uses this Font, this will recalculate the width and height of each Line in layout, changing the values in layout if they are incorrect. This returns the total width of the measured Layout. Most usage will not necessarily need the return value; either this is called to fix incorrect size information on a Layout, or the Layout this modifies will be queried for its Layout.getWidth() and/or Layout.getHeight().
      Parameters:
      layout - a Layout object that may have the width and height of its lines modified (its content won't change)
      Returns:
      the total width of the measured Layout, as a float
    • calculateXAdvances

      public float calculateXAdvances(Line line, com.badlogic.gdx.utils.FloatArray advances)
      Not meant for general use; calculates the x-positions before every glyph in line, including invisible ones. Clears advances and fills it with the never-decreasing position values.
      Parameters:
      line - a Line to measure the contents
      advances - will be cleared and refilled with the positions of each glyph in line
      Returns:
      the x-position after the last glyph
    • handleIntegerPosition

      protected float handleIntegerPosition(float p)
      Currently, this is only an extension point for code that wants to ensure integer positions; it does nothing on its own other than return its argument unchanged. See integerPosition for more.
      Parameters:
      p - a float that could be rounded (it will not be unless this is overridden)
      Returns:
      unless overridden, p without changes
    • drawGlyph

      public float drawGlyph(com.badlogic.gdx.graphics.g2d.Batch batch, long glyph, float x, float y)
      Draws the specified glyph with a Batch at the given x, y position. The glyph contains multiple types of data all packed into one long: the bottom 16 bits store a char, the roughly 16 bits above that store formatting (bold, underline, superscript, etc.), and the remaining upper 32 bits store color as RGBA.
      Parameters:
      batch - typically a SpriteBatch
      glyph - a long storing a char, format, and color; typically part of a longer formatted text as a LongArray
      x - the x position in world space to start drawing the glyph at (lower left corner)
      y - the y position in world space to start drawing the glyph at (lower left corner)
      Returns:
      the distance in world units the drawn glyph uses up for width, as in a line of text
    • drawGlyph

      public float drawGlyph(com.badlogic.gdx.graphics.g2d.Batch batch, long glyph, float x, float y, float rotation)
      Draws the specified glyph with a Batch at the given x, y position and with the specified counterclockwise rotation, measured in degrees. The glyph contains multiple types of data all packed into one long: the bottom 16 bits store a char, the roughly 16 bits above that store formatting (bold, underline, superscript, etc.), and the remaining upper 32 bits store color as RGBA. Rotation is not stored in the long glyph; it may change frequently or as part of an animation.
      Parameters:
      batch - typically a SpriteBatch
      glyph - a long storing a char, format, and color; typically part of a longer formatted text as a LongList
      x - the x position in world space to start drawing the glyph at (lower left corner)
      y - the y position in world space to start drawing the glyph at (lower left corner)
      rotation - what angle to rotate the glyph, measured in degrees counterclockwise
      Returns:
      the distance in world units the drawn glyph uses up for width, as in a line of text along the given rotation
    • drawGlyph

      public float drawGlyph(com.badlogic.gdx.graphics.g2d.Batch batch, long glyph, float x, float y, float rotation, float sizingX, float sizingY)
      Draws the specified glyph with a Batch at the given x, y position, with the specified counterclockwise rotation, measured in degrees, and with the specified x and y sizing/scaling, which are meant to be treated independently of the incremental scales in a glyph, and can be smooth. The glyph contains multiple types of data all packed into one long: the bottom 16 bits store a char, the roughly 16 bits above that store formatting (bold, underline, superscript, etc.), and the remaining upper 32 bits store color as RGBA. Rotation is not stored in the long glyph; it may change frequently or as part of an animation. Sizing isn't part of the glyph either, and is meant to be handled by Effects in TypingLabel, and does not affect the text metrics.
      Parameters:
      batch - typically a SpriteBatch
      glyph - a long storing a char, format, and color; typically part of a longer formatted text as a LongList
      x - the x position in world space to start drawing the glyph at (lower left corner)
      y - the y position in world space to start drawing the glyph at (lower left corner)
      rotation - what angle to rotate the glyph, measured in degrees counterclockwise
      sizingX - the multiple for the glyph to be stretched on x, where 1 is "no change"; does not affect metrics
      sizingY - the multiple for the glyph to be stretched on y, where 1 is "no change"; does not affect metrics
      Returns:
      the distance in world units the drawn glyph uses up for width, as in a line of text along the given rotation
    • drawGlyph

      public float drawGlyph(com.badlogic.gdx.graphics.g2d.Batch batch, long glyph, float x, float y, float rotation, float sizingX, float sizingY, int backgroundColor)
      Draws the specified glyph with a Batch at the given x, y position, with the specified counterclockwise rotation, measured in degrees, and with the specified x and y sizing/scaling, which are meant to be treated independently of the incremental scales in a glyph, and can be smooth. The glyph contains multiple types of data all packed into one long: the bottom 16 bits store a char, the roughly 16 bits above that store formatting (bold, underline, superscript, etc.), and the remaining upper 32 bits store color as RGBA. Rotation is not stored in the long glyph; it may change frequently or as part of an animation. Sizing isn't part of the glyph either, and is meant to be handled by Effects in TypingLabel, and does not affect the text metrics.
      Parameters:
      batch - typically a SpriteBatch
      glyph - a long storing a char, format, and color; typically part of a longer formatted text as a LongList
      x - the x position in world space to start drawing the glyph at (lower left corner)
      y - the y position in world space to start drawing the glyph at (lower left corner)
      rotation - what angle to rotate the glyph, measured in degrees counterclockwise
      sizingX - the multiple for the glyph to be stretched on x, where 1 is "no change"; does not affect metrics
      sizingY - the multiple for the glyph to be stretched on y, where 1 is "no change"; does not affect metrics
      backgroundColor - an RGBA8888 color to use for a block background behind the glyph; won't be drawn if 0
      Returns:
      the distance in world units the drawn glyph uses up for width, as in a line of text along the given rotation
    • markup

      public Layout markup(String text, Layout appendTo)
      Reads markup from text, along with the chars to receive markup, processes it, and appends into appendTo, which is a Layout holding one or more Lines. This parses an extension of libGDX markup and uses it to determine color, size, position, shape, strikethrough, underline, case, and scale of the given CharSequence. It also reads typing markup, for effects, but passes it through without changing it and without considering it for line wrapping or text position.
      The text drawn will start in appendTo's Layout.baseColor, which is usually white, with the normal size as determined by the font's metrics and scale (scaleX and scaleY), normal case, and without bold, italic, superscript, subscript, strikethrough, or underline. Markup starts with [; the next character determines what that piece of markup toggles. Markup this knows:
      • [] undoes the most-recently-applied format change.
      • [ ] clears all markup to the initial state without any applied.
      • [(label)] temporarily stores the current formatting state as label.
      • [ label] re-applies the formatting state stored as label, if there is one.
      • [[ escapes a literal left bracket, producing it without changing state.
      • [+name], where name is the name of a TextureRegion from an atlas added to this Font with addAtlas(TextureAtlas), produces the corresponding TextureRegion (scaled when drawn) without changing state. If no atlas has been added, this emits undefined character(s) instead.
      • [*] toggles bold mode.
      • [/] toggles italic (technically, oblique) mode.
      • [^] toggles superscript mode (and turns off subscript or midscript mode).
      • [=] toggles midscript mode (and turns off superscript or subscript mode).
      • [.] toggles subscript mode (and turns off superscript or midscript mode).
      • [_] toggles underline mode.
      • [~] toggles strikethrough mode.
      • [!] toggles all upper case mode.
      • [,] toggles all lower case mode.
      • [;] toggles capitalize each word mode.
      • [%P], where P is a percentage from 0 to 375, changes the scale to that percentage (rounded to the nearest 25% mark). This also disables any alternate mode.
      • [%?MODE], where MODE can be (case-insensitive) one of "black outline", "white outline", "shiny", "drop shadow"/"shadow", "error", "warn", "note", or "jostle", will disable scaling and enable that alternate mode. If MODE is empty or not recognized, this considers it equivalent to "jostle".
      • [%^MODE], where MODE can be (case-insensitive) one of "black outline", "white outline", "shiny", "drop shadow"/"shadow", "error", "warn", "note", or "small caps", will disable scaling and enable that alternate mode along with small caps mode at the same time. If MODE is empty or not recognized, this considers it equivalent to "small caps" (without another mode).
      • [%], with no number just after it, resets scale to 100% and disables any alternate mode.
      • [@Name], where Name is a key in family, changes the current Font used for rendering to the Font in this.family by that name. This is ignored if family is null.
      • [@], with no text just after it, resets the font to this one (which should be item 0 in family, if family is non-null).
      • [#HHHHHHHH], where HHHHHHHH is a hex RGB888 or RGBA8888 int color, changes the color.
      • [COLORNAME], where "COLORNAME" is a color name or description that will be looked up in getColorLookup(), changes the color. By default this can receive ALL_CAPS names from Colors in libGDX, any names from Palette, or mixes of one or more color names with adjectives like "dark". The name can optionally be preceded by |, which allows looking up colors with names that contain punctuation. This doesn't do much if using the default ColorLookup, ColorLookup.DESCRIPTIVE, because it only evaluates ASCII letters, and treats everything else as a separator.
      You can render appendTo using drawGlyphs(Batch, Layout, float, float).
      Parameters:
      text - text, typically with square-bracket markup
      appendTo - a Layout that stores one or more Line objects, carrying color, style, chars, and size
      Returns:
      appendTo, for chaining
    • handleEllipsis

      protected boolean handleEllipsis(Layout appendTo)
    • markupGlyph

      public long markupGlyph(int chr, String markup)
      Reads markup from markup, processes it, and applies it to the given char chr; returns a long in the format used for styled glyphs here. This parses an extension of libGDX markup and uses it to determine color, size, position, shape, strikethrough, underline, case, and scale of the given char. The char drawn will start in white, with the normal size as determined by the font's metrics and scale (scaleX and scaleY), normal case, and without bold, italic, superscript, subscript, strikethrough, or underline. Markup starts with [; the next character determines what that piece of markup toggles. Markup this knows:
      • [] undoes the most-recently-applied format change.
      • [ ] clears all markup to the initial state without any applied.
      • [*] toggles bold mode.
      • [/] toggles italic (technically, oblique) mode.
      • [^] toggles superscript mode (and turns off subscript or midscript mode).
      • [=] toggles midscript mode (and turns off superscript or subscript mode).
      • [.] toggles subscript mode (and turns off superscript or midscript mode).
      • [_] toggles underline mode.
      • [~] toggles strikethrough mode.
      • [!] toggles all upper case mode.
      • [,] toggles all lower case mode.
      • [;] toggles capitalize each word mode (this is the same as upper case mode here).
      • [%P], where P is a percentage from 0 to 375, changes the scale to that percentage (rounded to the nearest 25% mark). This also disables any alternate mode.
      • [%?MODE], where MODE can be (case-insensitive) one of "black outline", "white outline", "shiny", "drop shadow"/"shadow", "error", "warn", "note", or "jostle", will disable scaling and enable that alternate mode. If MODE is empty or not recognized, this considers it equivalent to "jostle".
      • [%^MODE], where MODE can be (case-insensitive) one of "black outline", "white outline", "shiny", "drop shadow"/"shadow", "error", "warn", "note", or "small caps", will disable scaling and enable that alternate mode along with small caps mode at the same time. If MODE is empty or not recognized, this considers it equivalent to "small caps" (without another mode).
      • [%], with no number just after it, resets scale to 100% and disables any alternate mode.
      • [@Name], where Name is a key in family, changes the current Font used for rendering to the Font in this.family by that name. This is ignored if family is null.
      • [@], with no text just after it, resets the font to this one (which should be item 0 in family, if family is non-null).
      • [#HHHHHHHH], where HHHHHHHH is a hex RGB888 or RGBA8888 int color, changes the color.
      • [COLORNAME], where "COLORNAME" is a typically-upper-case color name that will be looked up in getColorLookup(), changes the color. The name can optionally be preceded by |, which allows looking up colors with names that contain punctuation.
      This does not automatically understand the [+πŸ”¬] syntax; you can use atlasLookup(String) to get the internal character code that refers to an atlas glyph such as an emoji, or you can just use markupGlyph(String) with that plus-sign syntax to enter the character.
      You can render the result using drawGlyph(Batch, long, float, float). It is recommended that you avoid calling this method every frame, because the color lookups usually allocate some memory, and because this can usually be stored for later without needing repeated computation.
      This is equivalent to calling markupGlyph(String) using a placeholder character (or none) and changing the returned glyph to use chr using applyChar(long, char).
      Parameters:
      chr - a single char to apply markup to; may also be a character code from atlasLookup(String)
      markup - a String containing only markup syntax, like "[*][_][RED]" for bold underline in red
      Returns:
      a long that encodes the given char with the specified markup
    • markupGlyph

      public long markupGlyph(String markup)
      Reads markup from markup and processes it until it has a single complete glyph; returns that glyph as a long in the format used for styled glyphs here. This parses an extension of libGDX markup and uses it to determine color, size, position, shape, strikethrough, underline, case, and scale of the given char. This overload works even if the glyph is from an atlas (see addAtlas(TextureAtlas), as long as the atlas was added to this Font. As such, this can be useful to get an emoji or similar character with markup, using the [+πŸ‘ΈπŸ½] syntax to produce the one char.
      The char drawn will start in white, with the normal size as determined by the font's metrics and scale (scaleX and scaleY), normal case, and without bold, italic, superscript, subscript, strikethrough, or underline. Markup starts with [; the next character determines what that piece of markup toggles. Markup this knows:
      • [] undoes the most-recently-applied format change.
      • [ ] clears all markup to the initial state without any applied.
      • [*] toggles bold mode.
      • [/] toggles italic (technically, oblique) mode.
      • [^] toggles superscript mode (and turns off subscript or midscript mode).
      • [=] toggles midscript mode (and turns off superscript or subscript mode).
      • [.] toggles subscript mode (and turns off superscript or midscript mode).
      • [_] toggles underline mode.
      • [~] toggles strikethrough mode.
      • [!] toggles all upper case mode.
      • [,] toggles all lower case mode.
      • [;] toggles capitalize each word mode (this is the same as upper case mode here).
      • [%P], where P is a percentage from 0 to 375, changes the scale to that percentage (rounded to the nearest 25% mark). This also disables any alternate mode.
      • [%?MODE], where MODE can be (case-insensitive) one of "black outline", "white outline", "shiny", "drop shadow"/"shadow", "error", "warn", "note", or "jostle", will disable scaling and enable that alternate mode. If MODE is empty or not recognized, this considers it equivalent to "jostle".
      • [%^MODE], where MODE can be (case-insensitive) one of "black outline", "white outline", "shiny", "drop shadow"/"shadow", "error", "warn", "note", or "small caps", will disable scaling and enable that alternate mode along with small caps mode at the same time. If MODE is empty or not recognized, this considers it equivalent to "small caps" (without another mode).
      • [%], with no number just after it, resets scale to 100% and disables any alternate mode.
      • [@Name], where Name is a key in family, changes the current Font used for rendering to the Font in this.family by that name. This is ignored if family is null.
      • [@], with no text just after the @, resets the font to this one (which should be item 0 in family, if family is non-null).
      • [#HHHHHHHH], where HHHHHHHH is a hex RGB888 or RGBA8888 int color, changes the color.
      • [COLORNAME], where "COLORNAME" is a typically-upper-case color name that will be looked up in ColorLookup.DESCRIPTIVE, changes the color. The name can optionally be preceded by |, which allows looking up colors with names that contain punctuation.
      You can render the result using drawGlyph(Batch, long, float, float). It is recommended that you avoid calling this method every frame, because the color lookups usually allocate some memory, and because this can usually be stored for later without needing repeated computation.
      This is not static; it can depend on the current Font's FontFamily, ColorLookup, and any atlases added to it.
      Parameters:
      markup - a String containing markup syntax and one char, like "[*][RED]G" for a bold, red 'G'
      Returns:
      a long that encodes the given char with the specified markup
    • markupGlyph

      public static long markupGlyph(char chr, String markup, ColorLookup colorLookup)
      Reads markup from markup, processes it, and applies it to the given char chr; returns a long in the format used for styled glyphs here. This parses an extension of libGDX markup and uses it to determine color, size, position, shape, strikethrough, underline, case, and scale of the given char. The char drawn will start in white, with the normal size as determined by the font's metrics and scale (scaleX and scaleY), normal case, and without bold, italic, superscript, subscript, strikethrough, or underline. Markup starts with [; the next character determines what that piece of markup toggles. Markup this knows:
      • [] undoes the most-recently-applied format change.
      • [ ] clears all markup to the initial state without any applied.
      • [*] toggles bold mode.
      • [/] toggles italic (technically, oblique) mode.
      • [^] toggles superscript mode (and turns off subscript or midscript mode).
      • [=] toggles midscript mode (and turns off superscript or subscript mode).
      • [.] toggles subscript mode (and turns off superscript or midscript mode).
      • [_] toggles underline mode.
      • [~] toggles strikethrough mode.
      • [!] toggles all upper case mode.
      • [,] toggles all lower case mode.
      • [;] toggles capitalize each word mode (this is the same as upper case mode here).
      • [%P], where P is a percentage from 0 to 375, changes the scale to that percentage (rounded to the nearest 25% mark). This also disables any alternate mode.
      • [%?MODE], where MODE can be (case-insensitive) one of "black outline", "white outline", "shiny", "drop shadow"/"shadow", "error", "warn", "note", or "jostle", will disable scaling and enable that alternate mode. If MODE is empty or not recognized, this considers it equivalent to "jostle".
      • [%^MODE], where MODE can be (case-insensitive) one of "black outline", "white outline", "shiny", "drop shadow"/"shadow", "error", "warn", "note", or "small caps", will disable scaling and enable that alternate mode along with small caps mode at the same time. If MODE is empty or not recognized, this considers it equivalent to "small caps" (without another mode).
      • [%], with no number just after it, resets scale to 100% and disables any alternate mode.
      • [@Name], where Name is a key in family, changes the current Font used for rendering to the Font in this.family by that name. This is ignored if family is null.
      • [@], with no text just after it, resets the font to this one (which should be item 0 in family, if family is non-null).
      • [#HHHHHHHH], where HHHHHHHH is a hex RGB888 or RGBA8888 int color, changes the color.
      • [COLORNAME], where "COLORNAME" is a typically-upper-case color name that will be looked up in getColorLookup(), changes the color. The name can optionally be preceded by |, which allows looking up colors with names that contain punctuation.
      You can render the result using drawGlyph(Batch, long, float, float). It is recommended that you avoid calling this method every frame, because the color lookups usually allocate some memory, and because this can usually be stored for later without needing repeated computation.
      This takes a ColorLookup so that it can look up colors given a name or description; if you don't know what to use, then ColorLookup.DESCRIPTIVE is the default elsewhere. Because this is static, it does not need a Font to be involved.
      Parameters:
      chr - a single char to apply markup to
      markup - a String containing only markup syntax, like "[*][_][RED]" for bold underline in red
      colorLookup - a ColorLookup (often a method reference or ColorLookup.DESCRIPTIVE) to get colors from textual names or descriptions
      Returns:
      a long that encodes the given char with the specified markup
    • markupGlyph

      public static long markupGlyph(char chr, String markup, ColorLookup colorLookup, Font.FontFamily family)
      Reads markup from markup, processes it, and applies it to the given char chr; returns a long in the format used for styled glyphs here. This parses an extension of libGDX markup and uses it to determine color, size, position, shape, strikethrough, underline, case, and scale of the given char. The char drawn will start in white, with the normal size as determined by the font's metrics and scale (scaleX and scaleY), normal case, and without bold, italic, superscript, subscript, strikethrough, or underline. Markup starts with [; the next character determines what that piece of markup toggles. Markup this knows:
      • [] undoes the most-recently-applied format change.
      • [ ] clears all markup to the initial state without any applied.
      • [*] toggles bold mode.
      • [/] toggles italic (technically, oblique) mode.
      • [^] toggles superscript mode (and turns off subscript or midscript mode).
      • [=] toggles midscript mode (and turns off superscript or subscript mode).
      • [.] toggles subscript mode (and turns off superscript or midscript mode).
      • [_] toggles underline mode.
      • [~] toggles strikethrough mode.
      • [!] toggles all upper case mode.
      • [,] toggles all lower case mode.
      • [;] toggles capitalize each word mode (this is the same as upper case mode here).
      • [%P], where P is a percentage from 0 to 375, changes the scale to that percentage (rounded to the nearest 25% mark). This also disables any alternate mode.
      • [%?MODE], where MODE can be (case-insensitive) one of "black outline", "white outline", "shiny", "drop shadow"/"shadow", "error", "warn", "note", or "jostle", will disable scaling and enable that alternate mode. If MODE is empty or not recognized, this considers it equivalent to "jostle".
      • [%^MODE], where MODE can be (case-insensitive) one of "black outline", "white outline", "shiny", "drop shadow"/"shadow", "error", "warn", "note", or "small caps", will disable scaling and enable that alternate mode along with small caps mode at the same time. If MODE is empty or not recognized, this considers it equivalent to "small caps" (without another mode).
      • [%], with no number just after it, resets scale to 100% and disables any alternate mode.
      • [@Name], where Name is a key in family, changes the current Font used for rendering to the Font in this.family by that name. This is ignored if family is null.
      • [@], with no text just after it, resets the font to this one (which should be item 0 in family, if family is non-null).
      • [#HHHHHHHH], where HHHHHHHH is a hex RGB888 or RGBA8888 int color, changes the color.
      • [COLORNAME], where "COLORNAME" is a typically-upper-case color name that will be looked up in getColorLookup(), changes the color. The name can optionally be preceded by |, which allows looking up colors with names that contain punctuation.
      You can render the result using drawGlyph(Batch, long, float, float). It is recommended that you avoid calling this method every frame, because the color lookups usually allocate some memory, and because this can usually be stored for later without needing repeated computation.
      This takes a ColorLookup so that it can look up colors given a name or description; if you don't know what to use, then ColorLookup.DESCRIPTIVE is the default elsewhere. Because this is static, it does not need a Font to be involved.
      Parameters:
      chr - a single char to apply markup to
      markup - a String containing only markup syntax, like "[*][_][RED]" for bold underline in red
      colorLookup - a ColorLookup (often a method reference or ColorLookup.DESCRIPTIVE) to get colors from textual names or descriptions
      Returns:
      a long that encodes the given char with the specified markup
    • regenerateLayout

      public Layout regenerateLayout(Layout changing)
      When the targetWidth of a Layout changes, you can use this to cause the text to be placed according to the new width, and wrap if needed. This doesn't allocate as much as markup(String, Layout), if at all, but may eat up newlines if called repeatedly.
      Parameters:
      changing - a Layout that will be modified in-place
      Returns:
      changing, after modifications
    • storeState

      public void storeState(String name, String markup)
      Evaluates markup to get a formatting state and stores it for later usage with "[ name]" syntax and the given name. Where "[ ]" will reset state to its starting value, "[ name]" will restore a previously saved state. States can be stored with this method (which will associate the named state with this Font, and will be copied with it), or temporarily stored in a markup String using "[(name)]".
      Parameters:
      name - a non-null String to associate a formatting state with
      markup - markup (with or without a char in it) that will be applied when this formatting state is used
    • storeState

      public void storeState(String name, long formatted)
      Evaluates markup to get a formatting state and stores it for later usage with "[ name]" syntax and the given name. Where "[ ]" will reset state to its starting value, "[ name]" will restore a previously saved state. States can be stored with this method (which will associate the named state with this Font, and will be copied with it), or temporarily stored in a markup String using "[(name)]".
      Parameters:
      name - a non-null String to associate a formatting state with
      formatted - any (ignored) character that will have its formatting stored for later usage
    • getStoredState

      public long getStoredState(String name, long fallback)
      Looks up the given name in the stored states and returns the associated formatting state, or fallback if the name was not present. A suggestion for fallback is to use 'N', since a valid formatting state won't have any character data, and 'N' only has character data.
      Parameters:
      name - a non-null String to look up in the stored states
      fallback - a formatting state or character to return if the given name is not found (often 'N'
      Returns:
      the formatting state associated with name (if found), or fallback (if not found)
    • removeStoredState

      public void removeStoredState(String name)
      Removes the formatting state with the given name if it is present, or does nothing if the name is not present.
      Parameters:
      name - the name of the formatting state to remove
    • resizeDistanceField

      public void resizeDistanceField(float width, float height)
      Important; must be called in ApplicationListener.resize(int, int) on each SDF, MSDF, or SDF_OUTLINE font you have currently rendering! This allows the distance field to appear as correct and crisp-outlined as it should be; without this, the distance field will probably not look very sharp at all. This doesn't need to be called every frame, only in resize().
      Given the new width and height for a window, this attempts to adjust the actualCrispness of an SDF/MSDF/SDF_OUTLINE font so that it will display cleanly at a different size. This uses this font's distanceFieldCrispness as a multiplier applied after calculating the initial crispness.
      If you use a viewport that significantly zooms in or out, you should multiply width by viewport.getScreenWidth() / viewport.getWorldWidth(), and similarly multiply height by the corresponding screen height divided by world height. This can avoid the distance fields looking extremely blurry or boxy when one world unit covers many pixels, or too aliased and jagged in the opposite case.Typically, in your ApplicationListener.resize(int, int) method, you call Viewport.update(int, int) (or the overload that can center the camera, if needed), and then call this or another method that resizes distance fields on each Font you are currently using.
      If you load all or most of your Font instances via a FWSkin, you can use FWSkin.resizeDistanceFields(float, float) to resize all Fonts loaded by the Skin at once. You can also resize all distance fields in a FontFamily using Font.FontFamily.resizeDistanceFields(float, float).
      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)
    • resizeDistanceField

      public void resizeDistanceField(float width, float height, com.badlogic.gdx.utils.viewport.Viewport viewport)
      Important; must be called in ApplicationListener.resize(int, int) on each SDF, MSDF, or SDF_OUTLINE font you have currently rendering! This allows the distance field to appear as correct and crisp-outlined as it should be; without this, the distance field will probably not look very sharp at all. This doesn't need to be called every frame, only in resize(). This overload also uses a Viewport to better configure heavily-zoomed Fonts. It does not change the Viewport.
      Given the new width and height for a window, this attempts to adjust the actualCrispness of an SDF/MSDF/SDF_OUTLINE font so that it will display cleanly at a different size. This uses this font's distanceFieldCrispness as a multiplier applied after calculating the initial crispness.
      This handles scaling based on the given Viewport as well as based on the given width and height. This means you do not need to consider the manual changes suggested for the other overload, resizeDistanceField(float, float). The given Viewport must have been updated with the proper width and height for your application window before passing it here. Typically, in your ApplicationListener.resize(int, int) method, you call Viewport.update(int, int) (or the overload that can center the camera, if needed), and then call this or another method that resizes distance fields on each Font you are currently using.
      If you load all or most of your Font instances via a FWSkin, you can use FWSkin.resizeDistanceFields(float, float, Viewport) to resize all Fonts loaded by the Skin at once. You can also resize all distance fields in a FontFamily using Font.FontFamily.resizeDistanceFields(float, float, Viewport).
      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)
    • extractColor

      public static int extractColor(long glyph)
      Given a glyph as a long, this returns the RGBA8888 color it uses.
      Parameters:
      glyph - a glyph as a long, as used by Layout and Line
      Returns:
      the int color used by the given glyph, as RGBA8888
    • applyColor

      public static long applyColor(long glyph, int color)
      Replaces the section of glyph that stores its color with the given RGBA8888 int color.
      Parameters:
      glyph - a glyph as a long, as used by Layout and Line
      color - the int color to use, as an RGBA8888 int
      Returns:
      another long glyph that uses the specified color
    • extractStyle

      public static long extractStyle(long glyph)
      Given a glyph as a long, this returns the style bits it uses. You can cross-reference these with BOLD, OBLIQUE, UNDERLINE, STRIKETHROUGH, SUBSCRIPT, MIDSCRIPT, and SUPERSCRIPT.
      Parameters:
      glyph - a glyph as a long, as used by Layout and Line
      Returns:
      the style bits used by the given glyph
    • applyStyle

      public static long applyStyle(long glyph, long style)
      Replaces the section of glyph that stores its style with the given long bits.You can get the bit constants with BOLD, OBLIQUE, UNDERLINE, STRIKETHROUGH, SUBSCRIPT, MIDSCRIPT, and SUPERSCRIPT. Because only a small section is used from style, you can pass an existing styled glyph as the second parameter to copy its style information into glyph.
      Parameters:
      glyph - a glyph as a long, as used by Layout and Line
      style - the long style bits to use, which should usually be bits from the aforementioned constants
      Returns:
      another long glyph that uses the specified style
    • extractScale

      public static float extractScale(long glyph)
      Given a glyph as a long, this returns the float multiplier it uses for scale. If alternate mode is enabled, then this always returns 1.0f , because scale is ignored when alternate mode is on.
      Parameters:
      glyph - a glyph as a long, as used by Layout and Line
      Returns:
      the float scale used by the given glyph, from 0.0f to 3.75f
    • applyScale

      public static long applyScale(long glyph, float scale)
      Replaces the section of glyph that stores its scale with the given float multiplier, rounded to a multiple of 0.25 and wrapped to within 0.0 to 3.75, both inclusive. This also disables alternate mode, enabling scaling.
      Parameters:
      glyph - a glyph as a long, as used by Layout and Line
      scale - the float scale to use, which should be between 0.0 and 3.75, both inclusive
      Returns:
      another long glyph that uses the specified scale
    • extractMode

      public static long extractMode(long glyph)
      Given a glyph as a long, this returns the bit flags for the current mode, if alternate mode is enabled. The flags may include SMALL_CAPS separately from any other flags except for JOSTLE (SMALL_CAPS and JOSTLE cannot overlap). To check whether a given mode is present, use one of:
      • (extractMode(glyph) & ALTERNATE_MODES_MASK) == BLACK_OUTLINE
      • (extractMode(glyph) & ALTERNATE_MODES_MASK) == WHITE_OUTLINE
      • (extractMode(glyph) & ALTERNATE_MODES_MASK) == DROP_SHADOW
      • (extractMode(glyph) & ALTERNATE_MODES_MASK) == SHINY
      • (extractMode(glyph) & ALTERNATE_MODES_MASK) == ERROR
      • (extractMode(glyph) & ALTERNATE_MODES_MASK) == WARN
      • (extractMode(glyph) & ALTERNATE_MODES_MASK) == NOTE
      • (extractMode(glyph) & SMALL_CAPS) == SMALL_CAPS
      • (extractMode(glyph) & (ALTERNATE_MODES_MASK | SMALL_CAPS)) == JOSTLE
      The last constant of each line is the mode that line checks for. Each constant is defined in Font. If alternate mode is not enabled, this always returns 0.
      Parameters:
      glyph - a glyph as a long, as used by Layout and Line
      Returns:
      the bit flags for the current alternate mode, if enabled; see docs
    • applyMode

      public static long applyMode(long glyph, long modeFlags)
      Replaces the section of glyph that stores its alternate mode (which is the same section that stores its scale) with the given bit flags representing a mode (or lack of one). These bit flags are generally obtained using extractMode(long), though you could acquire or create them in any number of ways.
      Parameters:
      glyph - a glyph as a long, as used by Layout and Line
      modeFlags - bit flags typically obtained from extractMode(long)
      Returns:
      another long glyph that uses the specified mode
    • extractChar

      public static char extractChar(long glyph)
      Given a glyph as a long, this returns the char it displays. This automatically corrects the placeholder char u0002 to the glyph it displays as, '['.
      Parameters:
      glyph - a glyph as a long, as used by Layout and Line
      Returns:
      the char used by the given glyph
    • applyChar

      public static long applyChar(long glyph, char c)
      Replaces the section of glyph that stores its char with the given other char. You can enter the character '[' by using the char (char)2, or possibly by using an actual '[' char. This last option is untested and unrecommended, but may have uses if you are willing to dig deep into the internals here.
      Parameters:
      glyph - a glyph as a long, as used by Layout and Line
      c - the char to use
      Returns:
      another long glyph that uses the specified char
    • dispose

      public void dispose()
      Releases all resources of this object.
      Specified by:
      dispose in interface com.badlogic.gdx.utils.Disposable
    • clearStatic

      public static void clearStatic()
      Clears TypingConfig.GLOBAL_VARS and calls TypingConfig.initializeGlobalVars(). This can be useful if you target Android and you use Activity.finish(), or some other way of ending an app that does not clear static values. Consider calling this if you encounter different (buggy) behavior on the second launch of an Android app vs. the first launch. It is not needed on desktop JVMs or GWT. This only could be needed if you add different items to TypingConfig.GLOBAL_VARS on different runs of your Android app.
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • debugString

      public String debugString()
    • drawVertices

      protected void drawVertices(com.badlogic.gdx.graphics.g2d.Batch batch, com.badlogic.gdx.graphics.Texture texture, float[] vertices)
      Given a 20-item float array (almost always vertices in this class) and a Texture to draw (part of), this draws some part of the Texture using the given Batch. This is used internally to wrap around calls to Batch.draw(Texture, float[], int, int).
      This is an extension point so Batch implementations that use more attributes than SpriteBatch can still make use of Font. If not overridden, this will act exactly like calling batch.draw(texture, vertices, 0, 20);.
      The format this should generally expect for vertices is the same as what a single Sprite would draw with SpriteBatch. There are 4 sections in each array, each with 5 floats corresponding to one vertex on a quad. Font only ever assigns one color (as a packed float, such as from Color.toFloatBits()) to all four vertices, but overriding classes don't necessarily need to do this. Where x and y define the lower-left vertex position, width and height are the axis-aligned dimensions of the quad, color is a packed float, and u/v/u2/v2 are the UV coordinates to use from texture, the format looks like:
               vertices[0] = x;
               vertices[1] = y;
               vertices[2] = color;
               vertices[3] = u;
               vertices[4] = v;
      
               vertices[5] = x;
               vertices[6] = y + height;
               vertices[7] = color;
               vertices[8] = u;
               vertices[9] = v2;
      
               vertices[10] = x + width;
               vertices[11] = y + height;
               vertices[12] = color;
               vertices[13] = u2;
               vertices[14] = v2;
      
               vertices[15] = x + width;
               vertices[16] = y;
               vertices[17] = color;
               vertices[18] = u2;
               vertices[19] = v;
       

      When a custom Font overrides this to handle a Batch with one extra attribute per-vertex, the custom Font should have a 24-item float array and copy data from vertices to its own 24-item float array, then pass that larger array to Batch.draw(Texture, float[], int, int).
      Parameters:
      batch - a Batch, which should be a SpriteBatch (or a compatible Batch) unless this was overridden
      texture - a Texture to draw (part of)
      vertices - a 20-item float array organized into 5-float sections per-vertex