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. You can generate SDF fonts with Hiero or [a related tool](https://github.com/libgdx/libgdx/wiki/Distance-field-fonts#using-distance-fields-for-arbitrary-images) that is part of libGDX; MSDF fonts are harder to generate, but possible using a tool like Glamer. Note that SDF and non-distance-field fonts can be created with kerning information, but currently MSDF fonts cannot, making MSDF a better choice for monospace fonts than variable-width ones.
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.
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 or Font.DistanceFieldType.MSDF, 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 bold mode, as a long.
    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.
    Determines how colors are looked up by name; defaults to using Colors.
    Which GlyphRegion to display if a char isn't found in mapping.
    A Font.DistanceFieldType that should be Font.DistanceFieldType.STANDARD for most fonts, and can be Font.DistanceFieldType.SDF or Font.DistanceFieldType.MSDF if you know you have a font made to be used with one of those rendering techniques.
    float
    When distanceField is Font.DistanceFieldType.SDF or Font.DistanceFieldType.MSDF, this determines how much the edges of the glyphs should be aliased sharply (higher values) or anti-aliased softly (lower values).
    If non-null, may contain connected Font values and names/aliases to look them up with using [@Name] syntax.
    boolean
    If true, this is a fixed-width (monospace) font; if false, this is probably a variable-width font.
    com.badlogic.gdx.utils.IntIntMap
    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.
    static final long
    Bit flag for oblique mode, as a long.
    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.
    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.
    com.badlogic.gdx.graphics.glutils.ShaderProgram
    The ShaderProgram used to render this font, as used by enableShader(Batch).
    char
    A char that will be used to draw solid blocks with drawBlocks(Batch, int[][], float, float).
    static final long
    Bit flag for strikethrough mode, as a long.
    static final long
    Bit flag for subscript mode, as a long.
    static final long
    Two-bit flag for superscript mode, as a long.
    static final long
    Bit flag for underline mode, as a long.
    static final String
    The standard libGDX vertex shader source, which is also used by the MSDF shader.
  • Constructor Summary

    Constructors
    Constructor
    Description
    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(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 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, 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, 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 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.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, 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, String textureName)
    Constructs a Font by reading in the given .fnt file and the given Texture by filename.
    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.
  • Method Summary

    Modifier and Type
    Method
    Description
    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 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
    applyColor(long glyph, int color)
    Replaces the section of glyph that stores its color with the given RGBA8888 int color.
    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.
    Measures the actual width that the given Line will use when drawn.
    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.
    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
    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, 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.
    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.
    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 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.
    Gets the ColorLookup this uses to look up colors by name.
    float
    Gets the "crispness" multiplier for distance field fonts (SDF and MSDF).
    static boolean
    isLowerCase(char c)
    Returns true if c is a lower-case letter, or false otherwise.
    static boolean
    isUpperCase(char c)
    Returns true if c is an upper-case letter, or false otherwise.
    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(String fntName, float xAdjust, float yAdjust, float widthAdjust, float heightAdjust)
    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
    loadSad(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.
    long
    markupGlyph(char 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.
    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.
    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
    resizeDistanceField(int width, int height)
    Given the new width and height for a window, this attempts to adjust the actualCrispness of an SDF or MSDF font so that it will display cleanly at a different size.
    scale(float horizontal, float vertical)
    Scales the font by the given horizontal and vertical multipliers.
    scaleTo(float width, float height)
    Scales the font so that it will have the given width and height.
    void
    Unlikely to be used in most games, 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).
    Sets the FontFamily this can use to switch fonts using [@Name] syntax.
    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.
    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 scaleX as if drawing.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, 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, int, int, int, int)), though they must map to a char.
    • 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

      public Font.DistanceFieldType distanceField
      A Font.DistanceFieldType that should be Font.DistanceFieldType.STANDARD for most fonts, and can be Font.DistanceFieldType.SDF or Font.DistanceFieldType.MSDF 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(int, int) for a convenience method to handle window-resizing sharply.
    • 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.IntIntMap 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 an int associated with it, which applies to the x-position of the later char.
    • actualCrispness

      public float actualCrispness
      When distanceField is Font.DistanceFieldType.SDF or Font.DistanceFieldType.MSDF, 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(int, int) 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 or Font.DistanceFieldType.MSDF, 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(int, int) 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.
    • solidBlock

      public char solidBlock
      A char that will be used to draw solid blocks with drawBlocks(Batch, int[][], float, float). The glyph that corresponds to this char should be a maximum-size block of solid white pixels in most cases. Because Glamer (which generated many of the knownFonts here) places a solid block at character 0, this defaults to u0000 .
    • 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 Colors.
    • 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:
    • vertexShader

      public static final String vertexShader
      The standard libGDX vertex shader source, which is also used by the MSDF shader.
      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.
      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 to one created by DistanceFieldFont.createDistanceFieldShader() if distanceField is set to 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(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, 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, 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.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(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.
      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.
      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(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:
      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
  • Method Details

    • isLowerCase

      public static boolean isLowerCase(char c)
      Returns true if c is a lower-case letter, or false otherwise. Similar to Character.isLowerCase(char), but should actually work on GWT.
      Parameters:
      c - a char to check
      Returns:
      true if c is a lower-case letter, or false otherwise.
    • isUpperCase

      public static boolean isUpperCase(char c)
      Returns true if c is an upper-case letter, or false otherwise. Similar to Character.isUpperCase(char), but should actually work on GWT.
      Parameters:
      c - a char to check
      Returns:
      true if c is an upper-case letter, or false otherwise.
    • getColorLookup

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

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

      protected void loadFNT(String fntName, float xAdjust, float yAdjust, float widthAdjust, float heightAdjust)
      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:
      fntName - the file name of the .fnt file; can be internal or local
      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
    • loadSad

      protected void loadSad(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)
    • 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 IntIntMap.get(int, int) 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 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
    • 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
    • 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 and Font.DistanceFieldType.MSDF 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 or Font.DistanceFieldType.MSDF 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
    • getCrispness

      public float getCrispness()
      Gets the "crispness" multiplier for distance field fonts (SDF and MSDF). This is usually 1.0 unless it has been changed. The default value is 1.0; 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(int, int) 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). The default value is 1.0; 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(int, int) to affect the working crispness value.
      Parameters:
      crispness - a float multiplier to be applied to the working crispness; 1.0 is the default
      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. Using lower values for multiplier will make the font look softer and fuzzier, while higher values will make it 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(int, int) to affect the working crispness value.
      Parameters:
      multiplier - a float multiplier to be applied to the working crispness multiplier
      Returns:
      this Font, for chaining
    • 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 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); .
      Parameters:
      batch - the Batch to instruct to use the appropriate shader for this font; should usually be a SpriteBatch
    • 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 char u0000 by default, or at solidBlock if you have set that field; Glamer produces fonts that have a block at u0000 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 Batch.draw(Texture, float[], int, int) to draw each rectangle with minimal overhead, and this also means it is unaffected by the batch color. 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 Batch.draw(Texture, float[], int, int) to draw each rectangle with minimal overhead, and this also means it is unaffected by the batch color. 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)
    • 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:
      • [[ escapes a literal left bracket.
      • [] 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.
      • [%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 number of glyphs drawn
    • 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 number of glyphs drawn
    • 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 number of glyphs drawn
    • 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 number of glyphs drawn
    • xAdvance

      public static float xAdvance(Font font, float scale, 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 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 Line calculateSize(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
    • 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
      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. A common way of getting a Layout is with Layout.POOL.obtain(); you can free the Layout when you are done using it with Pool.free(Object) on Layout.POOL. 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:
      • [[ escapes a literal left bracket.
      • [] 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.
      • [%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 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 appendTo using drawGlyphs(Batch, Layout, float, float).
      Parameters:
      text - text with markup
      appendTo - a Layout that stores one or more Line objects, carrying color, style, chars, and size
      Returns:
      appendTo, for chaining
    • markupGlyph

      public long markupGlyph(char 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:
      • [] 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).
      • [%], with no number just after it, resets scale to 100% (this usually has no effect here).
      • [@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 is equivalent to calling the static markupGlyph(char, String, ColorLookup) and giving it this Font's colorLookup value.
      Parameters:
      chr - a single char to apply markup to
      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 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:
      • [] 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).
      • [%], with no number just after it, resets scale to 100% (this usually has no effect here).
      • [@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.GdxColorLookup.INSTANCE is often perfectly fine. 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.GdxColorLookup.INSTANCE) 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:
      • [] 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).
      • [%], with no number just after it, resets scale to 100% (this usually has no effect here).
      • [@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.GdxColorLookup.INSTANCE is often perfectly fine. 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.GdxColorLookup.INSTANCE) 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)
    • 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
    • resizeDistanceField

      public void resizeDistanceField(int width, int height)
      Given the new width and height for a window, this attempts to adjust the actualCrispness of an SDF or MSDF 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 is a suggestion for what to call in your ApplicationListener.resize(int, int) method for each SDF or MSDF font you have currently rendering.
      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)
    • 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.
      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.
      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
    • 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 scale with the given float multiplier, rounded to a multiple of 0.25 and wrapped to within 0.0 to 3.75, both inclusive.
      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