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 a "faux bold" and oblique mode using one font image; you don't need a bold and italic/oblique image separate from the book face.
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);. You don't have to use SDF or MSDF fonts, but they 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.
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.
See Also:
The markup() method's documentation covers all the markup tags.
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static class 
    Defines what types of distance field font this can use and render.
    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
    static 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.
     
     
    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).
    boolean
     
    com.badlogic.gdx.utils.IntIntMap
     
    com.badlogic.gdx.utils.IntMap<Font.GlyphRegion>
     
    static long
     
    static String
    Fragment shader source meant for MSDF fonts.
    static 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>
     
    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).
    static long
     
    static long
     
    static long
     
    static long
     
    static 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, 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 classpath 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 classpath 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 classpath), 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 classpath), and the specified distance field effect.
  • Method Summary

    Modifier and Type
    Method
    Description
    adjustLineHeight​(float multiplier)
    Multiplies the line height by multiplier without changing the size of any characters.
    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, and case 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.
    Gets the ColorLookup this uses to look up colors by name.
    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 TextureRegions 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.
    float
    measureWidth​(Line line)
    Measures the actual width that the given Line will use when drawn.
    regenerateLayout​(Layout changing)
     
    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.
    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.

    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
    • defaultValue

      public Font.GlyphRegion defaultValue
    • parents

      public com.badlogic.gdx.utils.Array<com.badlogic.gdx.graphics.g2d.TextureRegion> parents
    • distanceField

      public Font.DistanceFieldType distanceField
    • isMono

      public boolean isMono
    • kerning

      public com.badlogic.gdx.utils.IntIntMap kerning
    • 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.
    • 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.
    • colorLookup

      public ColorLookup colorLookup
      Determines how colors are looked up by name; defaults to using Colors.
    • BOLD

      public static final long BOLD
      See Also:
      Constant Field Values
    • OBLIQUE

      public static final long OBLIQUE
      See Also:
      Constant Field Values
    • UNDERLINE

      public static final long UNDERLINE
      See Also:
      Constant Field Values
    • STRIKETHROUGH

      public static final long STRIKETHROUGH
      See Also:
      Constant Field Values
    • SUBSCRIPT

      public static final long SUBSCRIPT
      See Also:
      Constant Field Values
    • MIDSCRIPT

      public static final long MIDSCRIPT
      See Also:
      Constant Field Values
    • SUPERSCRIPT

      public static final long SUPERSCRIPT
      See Also:
      Constant Field Values
    • vertexShader

      public static final String vertexShader
      The standard libGDX vertex shader source, which is also used by the MSDF shader.
      See Also:
      Constant Field Values
    • 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:
      Constant Field Values
    • 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 distanceFieldCrispness 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 classpath handle) and loading any images specified in that file. No distance field effect is used.
      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 classpath handle) and loading any images specified in that file. The specified distance field effect is used.
      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 classpath), and no distance field effect.
      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 classpath), and the specified distance field effect.
      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.
      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.
      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.
      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.
      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
  • Method Details

    • 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
    • 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.
    • 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 TextureRegions 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
    • 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. 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
    • 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
    • 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; Glamer produces fonts that have this 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. 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.
      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. 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.
      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, and case 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.
      • [#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 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.
      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
    • 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 Pools.obtain(Layout.class); you can free the Layout when you are done using it with Pools.free(Object). This parses an extension of libGDX markup and uses it to determine color, size, position, shape, strikethrough, underline, and case 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 as 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.
      • [#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
    • regenerateLayout

      public Layout regenerateLayout(Layout changing)
    • dispose

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