Class Font

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

public class Font
extends java.lang.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 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.
Most things this can draw can be drawn with a rotation, and usually an origin can be specified (where it makes sense). The rotation can't be configured from markup, but the widgets that understand this class, like TextraLabel and TypingLabel, can have their rotation set using the standard scene2d.ui method Actor.setRotation(float), and then they will request the correct rotation from this class. This is different from Label, which ignores rotation!
There are some features here that cannot be used purely from markup, such as per-character rotation and smooth scaling, but these can be used by TypingLabel and its Effect assortment.
See Also:
The markup() method's documentation covers all the markup tags.
  • Nested Class Summary

    Nested Classes
    Modifier and Type Class Description
    static class  Font.DistanceFieldType
    Defines what types of distance field font this can use and render.
    static class  Font.FontFamily
    Holds up to 16 Font values, accessible by index or by name, that markup can switch between while rendering.
    static class  Font.GlyphRegion
    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 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).
    static long ALTERNATE
    Bit flag for alternate mode, as a long.
    static long ALTERNATE_MODES_MASK
    Bit flag for matching alternate modes, as a long.
    static long BLACK_OUTLINE
    Bit flag for black outline mode, as a long.
    static long BOLD
    Bit flag for bold mode, as a long.
    float boldStrength
    A multiplier that applies to the distance bold text will stretch away from the original glyph outline.
    float cellHeight
    Refers to the largest height of any glyph in the font, after scaling.
    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.
    ColorLookup colorLookup
    Determines how colors are looked up by name; defaults to using ColorUtils.describe(String).
    Font.GlyphRegion defaultValue
    Which GlyphRegion to display if a char isn't found in mapping.
    float descent
    How far the unscaled font descends below the baseline, typically as a negative number (not always).
    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.
    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).
    static long DROP_SHADOW
    Bit flag for drop shadow mode, as a long.
    static long ERROR
    Bit flag for error mode, shown as a red wiggly-underline, as a long.
    Font.FontFamily family
    If non-null, may contain connected Font values and names/aliases to look them up with using [@Name] syntax.
    float heightAdjust
    The height-adjustment this Font was initialized with, or 0 if there was none given.
    float inlineImageOffsetX
    An adjustment added to the Font.GlyphRegion.offsetX of any inline images added with addAtlas(TextureAtlas, String, String, float, float, float) (or its overloads).
    float inlineImageOffsetY
    An adjustment added to the Font.GlyphRegion.offsetY of any inline images added with addAtlas(TextureAtlas, String, String, float, float, float) (or its overloads).
    float inlineImageXAdvance
    An adjustment added to the xAdvance(com.github.tommyettinger.textra.Font, float, long) of any inline images added with addAtlas(TextureAtlas, String, String, float, float, float) (or its overloads).
    boolean integerPosition
    If true, this will always use integers for x and y position (rounding), which can help some fonts look more clear.
    boolean isMono
    If true, this is a fixed-width (monospace) font; if false, this is probably a variable-width font.
    static long JOSTLE
    Bit flag for "jostle" mode, as a long.
    com.badlogic.gdx.utils.IntFloatMap kerning
    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> mapping
    Maps char keys (stored as ints) to their corresponding Font.GlyphRegion values.
    static long MIDSCRIPT
    Bit flag for midscript mode, as a long.
    static java.lang.String msdfFragmentShader
    Fragment shader source meant for MSDF fonts.
    java.lang.String name
    The name of the Font, for display purposes.
    CaseInsensitiveIntMap nameLookup
    Optional; maps the names of TextureRegions to the indices they use in mapping, and usually assigned by addAtlas(TextureAtlas).
    com.badlogic.gdx.utils.IntMap<java.lang.String> namesByCharCode
    Optional; a reversed form of nameLookup that allows you to get the printable name for a given char code.
    static long NOTE
    Bit flag for note mode, shown as a blue wavy-underline, as a long.
    static long OBLIQUE
    Bit flag for oblique mode, as a long.
    float obliqueStrength
    A multiplier that applies to the horizontal movement associated with oblique text (which is similar to italic).
    float originalCellHeight
    Refers to the largest height of any glyph in the font, before any scaling.
    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.
    float PACKED_BLACK
    The color black, as a packed float using the default RGBA color space.
    float PACKED_ERROR_COLOR
    The color to use for ERROR's underline, as a packed float using the default RGBA color space.
    float PACKED_NOTE_COLOR
    The color to use for NOTE's underline, as a packed float using the default RGBA color space.
    float PACKED_WARN_COLOR
    The color to use for WARN's underline, as a packed float using the default RGBA color space.
    float PACKED_WHITE
    The color white, as a packed float using the default RGBA color space.
    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.
    float scaleX
    Scale multiplier for width.
    float scaleY
    Scale multiplier for height.
    static java.lang.String sdfFragmentShader  
    com.badlogic.gdx.graphics.glutils.ShaderProgram shader
    The ShaderProgram used to render this font, as used by enableShader(Batch).
    static long SHINY
    Bit flag for shiny mode, as a long.
    static long SMALL_CAPS
    Bit flag for small caps mode, as a long.
    char solidBlock
    A char that will be used to draw solid blocks with drawBlocks(Batch, int[][], float, float), and to draw box-drawing/block-element characters if makeGridGlyphs is true in the constructor.
    float strikeBreadth
    Precise adjustment for the strikethrough's y-size, affecting how thick the strikethrough is from bottom to top.
    float strikeLength
    Precise adjustment for the strikethrough's x-size, affecting the extra strikethrough drawn to the right of the strikethrough.
    static long STRIKETHROUGH
    Bit flag for strikethrough mode, as a long.
    float strikeX
    Precise adjustment for the strikethrough's x-position, affecting the left side of the strikethrough.
    float strikeY
    Precise adjustment for the strikethrough's y-position, affecting the bottom side of the strikethrough.
    static long SUBSCRIPT
    Bit flag for subscript mode, as a long.
    static long SUPERSCRIPT
    Two-bit flag for superscript mode, as a long.
    float underBreadth
    Precise adjustment for the underline's y-size, affecting how thick the underline is from bottom to top.
    float underLength
    Precise adjustment for the underline's x-size, affecting the extra underline drawn to the right of the underline.
    static long UNDERLINE
    Bit flag for underline mode, as a long.
    float underX
    Precise adjustment for the underline's x-position, affecting the left side of the underline.
    float underY
    Precise adjustment for the underline's y-position, affecting the bottom side of the underline.
    static java.lang.String vertexShader
    The standard libGDX vertex shader source, which is also used by the MSDF shader.
    static long WARN
    Bit flag for warning mode, shown as a yellow barred-underline, as a long.
    static long WHITE_OUTLINE
    Bit flag for white outline mode, as a long.
    com.badlogic.gdx.graphics.Texture whiteBlock
    A white square Texture, typically 3x3, that can be used as a backup in case a Font doesn't have a solid block character available to it already (such as for many Fonts created from BitmapFonts).
    float widthAdjust
    The width-adjustment this Font was initialized with, or 0 if there was none given.
    float xAdjust
    The x-adjustment this Font was initialized with, or 0 if there was none given.
    float yAdjust
    The y-adjustment this Font was initialized with, or 0 if there was none given.
  • Constructor Summary

    Constructors
    Constructor Description
    Font()
    Constructs a Font from a newly-created default BitmapFont, as by BitmapFont(), passing it to Font(BitmapFont, float, float, float, float).
    Font​(com.badlogic.gdx.graphics.g2d.BitmapFont bmFont)
    Constructs a new Font from the existing BitmapFont, using its same Textures and TextureRegions for glyphs, and without a distance field effect or any adjustments to position except for a y offset equal to BitmapFont.getDescent().
    Font​(com.badlogic.gdx.graphics.g2d.BitmapFont bmFont, float xAdjust, float yAdjust, float widthAdjust, float heightAdjust)
    Constructs a new Font from the existing BitmapFont, using its same Textures and TextureRegions for glyphs, and without a distance field effect.
    Font​(com.badlogic.gdx.graphics.g2d.BitmapFont bmFont, Font.DistanceFieldType distanceField, float xAdjust, float yAdjust, float widthAdjust, float heightAdjust)
    Constructs a new Font from the existing BitmapFont, using its same Textures and TextureRegions for glyphs, and with the specified distance field effect.
    Font​(com.badlogic.gdx.graphics.g2d.BitmapFont bmFont, Font.DistanceFieldType distanceField, float xAdjust, float yAdjust, float widthAdjust, float heightAdjust, boolean makeGridGlyphs)
    Constructs a new Font from the existing BitmapFont, using its same Textures and TextureRegions for glyphs, and with the specified distance field effect.
    Font​(Font toCopy)
    Copy constructor; does not copy the font's shader or colorLookup, if it has them (it uses the same reference for the new Font), but will fully copy everything else.
    Font​(java.lang.String fntName)
    Constructs a Font by reading in the given .fnt file and loading any images it specifies.
    Font​(java.lang.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​(java.lang.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​(java.lang.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​(java.lang.String fntName, com.badlogic.gdx.graphics.g2d.TextureRegion textureRegion, Font.DistanceFieldType distanceField, float xAdjust, float yAdjust, float widthAdjust, float heightAdjust, boolean makeGridGlyphs)
    Constructs a font based off of an AngelCode BMFont .fnt file and the given TextureRegion that holds all of its glyphs, with the specified distance field effect.
    Font​(java.lang.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​(java.lang.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​(java.lang.String fntName, com.badlogic.gdx.utils.Array<com.badlogic.gdx.graphics.g2d.TextureRegion> textureRegions, Font.DistanceFieldType distanceField, float xAdjust, float yAdjust, float widthAdjust, float heightAdjust, boolean makeGridGlyphs)
    Constructs a font based off of an AngelCode BMFont .fnt file, with the given TextureRegion Array and specified distance field effect.
    Font​(java.lang.String fntName, Font.DistanceFieldType distanceField)
    Constructs a Font by reading in the given .fnt file and loading any images it specifies.
    Font​(java.lang.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​(java.lang.String fntName, Font.DistanceFieldType distanceField, float xAdjust, float yAdjust, float widthAdjust, float heightAdjust, boolean makeGridGlyphs)
    Constructs a new Font by reading in a .fnt file with the given name (an internal handle is tried first, then a local handle) and loading any images specified in that file.
    Font​(java.lang.String fntName, java.lang.String textureName)
    Constructs a Font by reading in the given .fnt file and the given Texture by filename.
    Font​(java.lang.String prefix, java.lang.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​(java.lang.String fntName, java.lang.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​(java.lang.String fntName, java.lang.String textureName, Font.DistanceFieldType distanceField)
    Constructs a Font by reading in the given .fnt file and the given Texture by filename.
    Font​(java.lang.String fntName, java.lang.String textureName, Font.DistanceFieldType distanceField, float xAdjust, float yAdjust, float widthAdjust, float heightAdjust)
    Constructs a new Font by reading in a Texture from the given named path (internal is tried, then local), and the specified distance field effect.
    Font​(java.lang.String fntName, java.lang.String textureName, Font.DistanceFieldType distanceField, float xAdjust, float yAdjust, float widthAdjust, float heightAdjust, boolean makeGridGlyphs)
    Constructs a new Font by reading in a Texture from the given named path (internal is tried, then local), and the specified distance field effect.
  • Method Summary

    Modifier and Type Method Description
    Font addAtlas​(com.badlogic.gdx.graphics.g2d.TextureAtlas atlas)
    Adds all items in atlas to the private use area of mapping, and stores their names, so they can be looked up with [+saxophone] syntax (which is often the same as the [+🎷] syntax).
    Font addAtlas​(com.badlogic.gdx.graphics.g2d.TextureAtlas atlas, float offsetXChange, float offsetYChange, float xAdvanceChange)
    Adds all items in atlas to the private use area of mapping, and stores their names, so they can be looked up with [+saxophone] syntax (which is often the same as the [+🎷] syntax).
    Font addAtlas​(com.badlogic.gdx.graphics.g2d.TextureAtlas atlas, java.lang.String prepend, java.lang.String append, float offsetXChange, float offsetYChange, float xAdvanceChange)
    Adds all items in atlas to the private use area of mapping, and stores their names, so they can be looked up with [+saxophone] syntax (which is often the same as the [+🎷] syntax).
    Font addImage​(java.lang.String character, com.badlogic.gdx.graphics.g2d.TextureRegion region)
    Makes this Font "learn" a new mapping from a char (typically an emoji in a String for character) to a TextureRegion.
    Font addImage​(java.lang.String character, com.badlogic.gdx.graphics.g2d.TextureRegion region, float offsetX, float offsetY, float xAdvance)
    Makes this Font "learn" a new mapping from a char (typically an emoji in a String for character) to a TextureRegion, allowing any offsets on x or y to be specified as well as the amount of horizontal space the resulting GlyphRegion should use.
    Font adjustCellWidth​(float multiplier)
    Multiplies the width used by each glyph in a monospaced font by multiplier without changing the size of any characters.
    Font adjustLineHeight​(float multiplier)
    Multiplies the line height by multiplier without changing the size of any characters.
    static long applyChar​(long glyph, char c)
    Replaces the section of glyph that stores its char with the given other char.
    static long applyColor​(long glyph, int color)
    Replaces the section of glyph that stores its color with the given RGBA8888 int color.
    static long applyMode​(long glyph, long modeFlags)
    Replaces the section of glyph that stores its alternate mode (which is the same section that stores its scale) with the given bit flags representing a mode (or lack of one).
    static long applyScale​(long glyph, float scale)
    Replaces the section of glyph that stores its scale with the given float multiplier, rounded to a multiple of 0.25 and wrapped to within 0.0 to 3.75, both inclusive.
    static long applyStyle​(long glyph, long style)
    Replaces the section of glyph that stores its style with the given long bits.You can get the bit constants with BOLD, OBLIQUE, UNDERLINE, STRIKETHROUGH, SUBSCRIPT, MIDSCRIPT, and SUPERSCRIPT.
    int atlasLookup​(java.lang.String name)
    Gets the char that might be associated with name in at Atlas added to this (see addAtlas(TextureAtlas), or returns the int -1 if the name could not be found.
    float calculateSize​(Layout layout)
    Given a Layout that uses this Font, this will recalculate the width and height of each Line in layout, changing the values in layout if they are incorrect.
    float calculateSize​(Line line)
    Measures the actual width that the given Line will use when drawn, and sets it into the Line's Line.width field.
    float calculateXAdvances​(Line line, com.badlogic.gdx.utils.FloatArray advances)
    Not meant for general use; calculates the x-positions before every glyph in line, including invisible ones.
    static void clearStatic()
    java.lang.String debugString()  
    void dispose()
    Releases all resources of this object.
    void drawBlocks​(com.badlogic.gdx.graphics.g2d.Batch batch, char blockChar, int[][] colors, float x, float y)
    Draws a grid made of rectangular blocks of int colors (typically RGBA) at the given x,y position in world space.
    void drawBlocks​(com.badlogic.gdx.graphics.g2d.Batch batch, int[][] colors, float x, float y)
    Draws a grid made of rectangular blocks of int colors (typically RGBA) at the given x,y position in world space.
    protected void drawBlockSequence​(com.badlogic.gdx.graphics.g2d.Batch batch, float[] sequence, com.badlogic.gdx.graphics.g2d.TextureRegion block, float color, float x, float y)
    An internal method that draws blocks in a sequence specified by a float[], with the block usually solidBlock (but not always).
    protected void drawBlockSequence​(com.badlogic.gdx.graphics.g2d.Batch batch, float[] sequence, com.badlogic.gdx.graphics.g2d.TextureRegion block, float color, float x, float y, float width, float height)
    An internal method that draws blocks in a sequence specified by a float[], with the block usually solidBlock (but not always).
    protected void drawBlockSequence​(com.badlogic.gdx.graphics.g2d.Batch batch, float[] sequence, com.badlogic.gdx.graphics.g2d.TextureRegion block, float color, float x, float y, float width, float height, float rotation)
    An internal method that draws blocks in a sequence specified by a float[], with the block usually solidBlock (but not always).
    protected void drawFancyLine​(com.badlogic.gdx.graphics.g2d.Batch batch, long mode, float x, float y, float width, float xPx, float yPx, float rotation)
    An internal method that draws blocks in a sequence specified by a mode, with the block always solidBlock.
    float drawGlyph​(com.badlogic.gdx.graphics.g2d.Batch batch, long glyph, float x, float y)
    Draws the specified glyph with a Batch at the given x, y position.
    float drawGlyph​(com.badlogic.gdx.graphics.g2d.Batch batch, long glyph, float x, float y, float rotation)
    Draws the specified glyph with a Batch at the given x, y position and with the specified counterclockwise rotation, measured in degrees.
    float drawGlyph​(com.badlogic.gdx.graphics.g2d.Batch batch, long glyph, float x, float y, float rotation, float sizingX, float sizingY)
    Draws the specified glyph with a Batch at the given x, y position, with the specified counterclockwise rotation, measured in degrees, and with the specified x and y sizing/scaling, which are meant to be treated independently of the incremental scales in a glyph, and can be smooth.
    float drawGlyph​(com.badlogic.gdx.graphics.g2d.Batch batch, long glyph, float x, float y, float rotation, float sizingX, float sizingY, int backgroundColor)
    Draws the specified glyph with a Batch at the given x, y position, with the specified counterclockwise rotation, measured in degrees, and with the specified x and y sizing/scaling, which are meant to be treated independently of the incremental scales in a glyph, and can be smooth.
    float drawGlyphs​(com.badlogic.gdx.graphics.g2d.Batch batch, Layout glyphs, float x, float y)
    Draws the specified Layout of glyphs with a Batch at a given x, y position, drawing the full layout.
    float drawGlyphs​(com.badlogic.gdx.graphics.g2d.Batch batch, Layout glyphs, float x, float y, int align)
    Draws the specified Layout of glyphs with a Batch at a given x, y position, using align to determine how to position the text.
    float drawGlyphs​(com.badlogic.gdx.graphics.g2d.Batch batch, Layout glyphs, float x, float y, int align, float rotation, float originX, float originY)
    Draws the specified Layout of glyphs with a Batch at a given x, y position, rotated using dedegrees around the given origin point, using align to determine how to position the text.
    float drawGlyphs​(com.badlogic.gdx.graphics.g2d.Batch batch, Line glyphs, float x, float y)
    Draws the specified Line of glyphs with a Batch at a given x, y position, drawing the full Line using left alignment.
    float drawGlyphs​(com.badlogic.gdx.graphics.g2d.Batch batch, Line glyphs, float x, float y, int align)
    Draws the specified Line of glyphs with a Batch at a given x, y position, using align to determine how to position the text.
    float drawGlyphs​(com.badlogic.gdx.graphics.g2d.Batch batch, Line glyphs, float x, float y, int align, float rotation, float originX, float originY)
    Draws the specified Line of glyphs with a Batch at a given x, y position, rotated using degrees around the given origin point, using align to determine how to position the text.
    int drawMarkupText​(com.badlogic.gdx.graphics.g2d.Batch batch, java.lang.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, java.lang.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, java.lang.CharSequence text, float x, float y, int color)
    Draws the specified text at the given x,y position (in world space) with the given foreground color.
    protected void drawVertices​(com.badlogic.gdx.graphics.g2d.Batch batch, com.badlogic.gdx.graphics.Texture texture, float[] vertices)
    Given a 20-item float array (almost always vertices in this class) and a Texture to draw (part of), this draws some part of the Texture using the given Batch.
    void enableShader​(com.badlogic.gdx.graphics.g2d.Batch batch)
    Must be called before drawing anything with an SDF or MSDF font; does not need to be called for other fonts unless you are mixing them with SDF/MSDF fonts or other shaders.
    static char extractChar​(long glyph)
    Given a glyph as a long, this returns the char it displays.
    static int extractColor​(long glyph)
    Given a glyph as a long, this returns the RGBA8888 color it uses.
    static long extractMode​(long glyph)
    Given a glyph as a long, this returns the bit flags for the current mode, if alternate mode is enabled.
    static float extractScale​(long glyph)
    Given a glyph as a long, this returns the float multiplier it uses for scale.
    static long extractStyle​(long glyph)
    Given a glyph as a long, this returns the style bits it uses.
    Font fitCell​(float width, float height, boolean center)
    Fits all chars into cells width by height in size, and optionally centers them in their cells.
    static float floatFromDec​(java.lang.CharSequence cs, int start, int end)
    Reads in a CharSequence containing only decimal digits (0-9) with an optional sign at the start and an optional decimal point anywhere in the CharSequence, and returns the float they represent, reading until it encounters the end of the sequence or any invalid char, then returning the result if valid, or 0 if nothing could be read.
    ColorLookup getColorLookup()
    Gets the ColorLookup this uses to look up colors by name.
    float getCrispness()
    Gets the "crispness" multiplier for distance field fonts (SDF and MSDF).
    float getDescent()  
    float getInlineImageOffsetX()  
    float getInlineImageOffsetY()  
    float getInlineImageXAdvance()  
    java.lang.String getName()  
    float getStrikethroughX()  
    float getStrikethroughY()  
    float getUnderlineX()  
    float getUnderlineY()  
    protected boolean handleEllipsis​(Layout appendTo)  
    protected float handleIntegerPosition​(float p)
    If integerPosition is true, this returns p rounded to the nearest int; otherwise this just returns p unchanged.
    static int intFromDec​(java.lang.CharSequence cs, int start, int end)
    Reads in a CharSequence containing only decimal digits (0-9) with an optional sign at the start and returns the int they represent, reading at most 10 characters (11 if there is a sign) and returning the result if valid, or 0 if nothing could be read.
    static int intFromHex​(java.lang.CharSequence cs, int start, int end)
    Reads in a CharSequence containing only hex digits (only 0-9, a-f, and A-F) with an optional sign at the start and returns the long they represent, reading at most 16 characters (17 if there is a sign) and returning the result if valid, or 0 if nothing could be read.
    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​(java.lang.String fntName, float xAdjust, float yAdjust, float widthAdjust, float heightAdjust, boolean makeGridGlyphs)
    The gritty parsing code that pulls relevant info from an AngelCode BMFont .fnt file and uses it to assemble the many Font.GlyphRegions this has for each glyph.
    protected void loadSad​(java.lang.String prefix, java.lang.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.
    static long longFromHex​(java.lang.CharSequence cs, int start, int end)
    Reads in a CharSequence containing only hex digits (only 0-9, a-f, and A-F) with an optional sign at the start and returns the long they represent, reading at most 16 characters (17 if there is a sign) and returning the result if valid, or 0 if nothing could be read.
    Layout markup​(java.lang.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, java.lang.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, java.lang.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, java.lang.String markup, ColorLookup colorLookup, Font.FontFamily family)
    Reads markup from markup, processes it, and applies it to the given char chr; returns a long in the format used for styled glyphs here.
    long markupGlyph​(java.lang.String markup)
    Reads markup from markup and processes it until it has a single complete glyph; returns that glyph as a long in the format used for styled glyphs here.
    float measureWidth​(Line line)
    Measures the actual width that the given Line will use when drawn.
    Font multiplyCrispness​(float multiplier)
    Takes the "crispness" multiplier for distance field fonts (SDF and MSDF) and multiplies it by another multiplier.
    Layout regenerateLayout​(Layout changing)
    When the targetWidth of a Layout changes, you can use this to cause the text to be placed according to the new width, and wrap if needed.
    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.
    static java.lang.String safeSubstring​(java.lang.String source, int beginIndex, int endIndex)
    Like String.substring(int, int) but returns "" instead of throwing any sort of Exception.
    Font scale​(float horizontal, float vertical)
    Scales the font by the given horizontal and vertical multipliers.
    Font scaleTo​(float width, float height)
    Scales the font so that it will have the given width and height.
    Font setColorLookup​(ColorLookup lookup)
    Unlikely to be used in most games (meant more for other libraries), this allows changing how colors are looked up by name (or built) given a ColorLookup interface implementation.
    Font setCrispness​(float crispness)
    Sets the "crispness" multiplier for distance field fonts (SDF and MSDF).
    Font setDescent​(float descent)  
    Font setFamily​(Font.FontFamily family)
    Sets the FontFamily this can use to switch fonts using [@Name] syntax.
    Font setInlineImageMetrics​(float offsetX, float offsetY, float xAdvance)
    Sets the adjustments added to the metric for inline images added with addAtlas(TextureAtlas) (or its overloads).
    Font setLineMetrics​(float x, float y, float length, float breadth)
    Sets both the underline and strikethrough metric adjustments with the same values, as if you called both setUnderlineMetrics(float, float, float, float) and setStrikethroughMetrics(float, float, float, float) with identical parameters.
    Font setName​(java.lang.String name)  
    Font setStrikethroughMetrics​(float strikeX, float strikeY, float strikeLength, float strikeBreadth)  
    Font setStrikethroughPosition​(float strikeX, float strikeY)  
    Font setTextureFilter()
    Calls setTextureFilter(Texture.TextureFilter, Texture.TextureFilter) with Texture.TextureFilter.Linear for both min and mag filters.
    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.
    Font setUnderlineMetrics​(float underX, float underY, float underLength, float underBreadth)  
    Font setUnderlinePosition​(float underX, float underY)  
    java.lang.String toString()  
    Font useIntegerPositions​(boolean integer)  
    float xAdvance​(long glyph)
    Gets the distance to advance the cursor after drawing glyph, scaled by scaleX as if drawing.
    static float xAdvance​(Font font, float scale, long glyph)
    Gets the distance to advance the cursor after drawing glyph, scaled by scale as if drawing.

    Methods inherited from class java.lang.Object

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

    • mapping

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

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

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

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

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

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

      public float actualCrispness
      When distanceField is Font.DistanceFieldType.SDF 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.
    • descent

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

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

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

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

      public boolean integerPosition
      If true, this will always use integers for x and y position (rounding), which can help some fonts look more clear. However, if your world units are measured so that one world unit covers several pixels, then having this enabled can cause bizarre-looking visual glitches involving stretched or disappearing glyphs. This defaults to false, unlike what libGDX BitmapFont defaults to.
    • obliqueStrength

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

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

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

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

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

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

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

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

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

      public static final long MIDSCRIPT
      Bit flag for midscript mode, as a long.
      See Also:
      Constant Field Values
    • 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:
      Constant Field Values
    • ALTERNATE

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      public static final java.lang.String vertexShader
      The standard libGDX vertex shader source, which is also used by the MSDF shader.
      See Also:
      Constant Field Values
    • sdfFragmentShader

      public static final java.lang.String sdfFragmentShader
      See Also:
      Constant Field Values
    • msdfFragmentShader

      public static final java.lang.String msdfFragmentShader
      Fragment shader source meant for MSDF fonts. This is automatically used when enableShader(Batch) is called and the distanceField is Font.DistanceFieldType.MSDF.
      This is mostly derived from msdf-gdx, which is Apache 2.0-licensed.
      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 Font.DistanceFieldType.SDF. It can be set to a user-defined ShaderProgram; if it is meant to render MSDF or SDF fonts, then the ShaderProgram should have a uniform float u_smoothing; that will be set by enableShader(Batch). Values passed to u_smoothing can vary a lot, depending on how the font was initially created, its current scale, and its actualCrispness field. You can also use a user-defined ShaderProgram with a font using Font.DistanceFieldType.STANDARD, which may be easier and can use any uniforms you normally could with a ShaderProgram, since enableShader() won't change any of the uniforms.
  • Constructor Details

    • Font

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

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

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

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

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

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

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

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

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

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

    • longFromHex

      public static long longFromHex​(java.lang.CharSequence cs, int start, int end)
      Reads in a CharSequence containing only hex digits (only 0-9, a-f, and A-F) with an optional sign at the start and returns the long they represent, reading at most 16 characters (17 if there is a sign) and returning the result if valid, or 0 if nothing could be read. The leading sign can be '+' or '-' if present. This can also represent negative numbers as they are printed by such methods as String.format given %x in the formatting string; that is, if the first char of a 16-char (or longer) CharSequence is a hex digit 8 or higher, then the whole number represents a negative number, using two's complement and so on. This means "FFFFFFFFFFFFFFFF" would return the long -1 when passed to this, though you could also simply use "-1 ". If you use both '-' at the start and have the most significant digit as 8 or higher, such as with "-FFFFFFFFFFFFFFFF", then both indicate a negative number, but the digits will be processed first (producing -1) and then the whole thing will be multiplied by -1 to flip the sign again (returning 1).
      Should be fairly close to Java 8's Long.parseUnsignedLong method, which is an odd omission from earlier JDKs. This doesn't throw on invalid input, though, instead returning 0 if the first char is not a hex digit, or stopping the parse process early if a non-hex-digit char is read before end is reached. If the parse is stopped early, this behaves as you would expect for a number with fewer digits, and simply doesn't fill the larger places.
      Parameters:
      cs - a CharSequence, such as a String, containing only hex digits with an optional sign (no 0x at the start)
      start - the (inclusive) first character position in cs to read
      end - the (exclusive) last character position in cs to read (this stops after 16 characters if end is too large)
      Returns:
      the long that cs represents
    • intFromHex

      public static int intFromHex​(java.lang.CharSequence cs, int start, int end)
      Reads in a CharSequence containing only hex digits (only 0-9, a-f, and A-F) with an optional sign at the start and returns the long they represent, reading at most 16 characters (17 if there is a sign) and returning the result if valid, or 0 if nothing could be read. The leading sign can be '+' or '-' if present. This can also represent negative numbers as they are printed by such methods as String.format given %x in the formatting string; that is, if the first char of a 16-char (or longer) CharSequence is a hex digit 8 or higher, then the whole number represents a negative number, using two's complement and so on. This means "FFFFFFFFFFFFFFFF" would return the long -1 when passed to this, though you could also simply use "-1 ". If you use both '-' at the start and have the most significant digit as 8 or higher, such as with "-FFFFFFFFFFFFFFFF", then both indicate a negative number, but the digits will be processed first (producing -1) and then the whole thing will be multiplied by -1 to flip the sign again (returning 1).
      Should be fairly close to Java 8's Long.parseUnsignedLong method, which is an odd omission from earlier JDKs. This doesn't throw on invalid input, though, instead returning 0 if the first char is not a hex digit, or stopping the parse process early if a non-hex-digit char is read before end is reached. If the parse is stopped early, this behaves as you would expect for a number with fewer digits, and simply doesn't fill the larger places.
      Parameters:
      cs - a CharSequence, such as a String, containing only hex digits with an optional sign (no 0x at the start)
      start - the (inclusive) first character position in cs to read
      end - the (exclusive) last character position in cs to read (this stops after 16 characters if end is too large)
      Returns:
      the long that cs represents
    • intFromDec

      public static int intFromDec​(java.lang.CharSequence cs, int start, int end)
      Reads in a CharSequence containing only decimal digits (0-9) with an optional sign at the start and returns the int they represent, reading at most 10 characters (11 if there is a sign) and returning the result if valid, or 0 if nothing could be read. The leading sign can be '+' or '-' if present. This can technically be used to handle unsigned integers in decimal format, but it isn't the intended purpose. If you do use it for handling unsigned ints, 2147483647 is normally the highest positive int and -2147483648 the lowest negative one, but if you give this a number between 2147483647 and 2147483647 + 2147483648, it will interpret it as a negative number that fits in bounds using the normal rules for converting between signed and unsigned numbers.
      Should be fairly close to the JDK's Integer.parseInt method, but this also supports CharSequence data instead of just String data, and allows specifying a start and end. This doesn't throw on invalid input, either, instead returning 0 if the first char is not a decimal digit, or stopping the parse process early if a non-decimal-digit char is read before end is reached. If the parse is stopped early, this behaves as you would expect for a number with fewer digits, and simply doesn't fill the larger places.
      Parameters:
      cs - a CharSequence, such as a String, containing only digits 0-9 with an optional sign
      start - the (inclusive) first character position in cs to read
      end - the (exclusive) last character position in cs to read (this will stop early if it encounters any invalid char, or 10 digits have been read, not including sign)
      Returns:
      the int that cs represents
    • floatFromDec

      public static float floatFromDec​(java.lang.CharSequence cs, int start, int end)
      Reads in a CharSequence containing only decimal digits (0-9) with an optional sign at the start and an optional decimal point anywhere in the CharSequence, and returns the float they represent, reading until it encounters the end of the sequence or any invalid char, then returning the result if valid, or 0 if nothing could be read. The leading sign can be '+' or '-' if present.
      This is somewhat similar to the JDK's Float.parseFloat(String) method, but this also supports CharSequence data instead of just String data, and allows specifying a start and end, but doesn't support scientific notation or hexadecimal float notation. This doesn't throw on invalid input, either, instead returning 0 if the first char is not a decimal digit, or stopping the parse process early if a non-decimal-digit char is read before end is reached. If the parse is stopped early, this behaves as you would expect for a number with fewer digits, and simply doesn't fill the larger places.
      Parameters:
      cs - a CharSequence, such as a String, containing digits 0-9 with an optional sign and decimal point
      start - the (inclusive) first character position in cs to read
      end - the (exclusive) last character position in cs to read (this will stop early if it encounters any invalid char)
      Returns:
      the float that cs represents
    • safeSubstring

      public static java.lang.String safeSubstring​(java.lang.String source, int beginIndex, int endIndex)
      Like String.substring(int, int) but returns "" instead of throwing any sort of Exception.
      Parameters:
      source - the String to get a substring from
      beginIndex - the first index, inclusive; will be treated as 0 if negative
      endIndex - the index after the last character (exclusive); if negative this will be source.length()
      Returns:
      the substring of source between beginIndex and endIndex, or "" if any parameters are null/invalid
    • 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 Font setColorLookup​(ColorLookup lookup)
      Unlikely to be used in most games (meant more for other libraries), this allows changing how colors are looked up by name (or built) given a ColorLookup interface implementation.
      Parameters:
      lookup - a non-null ColorLookup
      Returns:
      this, for chaining
    • loadFNT

      protected void loadFNT​(java.lang.String fntName, float xAdjust, float yAdjust, float widthAdjust, float heightAdjust, boolean makeGridGlyphs)
      The gritty parsing code that pulls relevant info from an AngelCode BMFont .fnt file and uses it to assemble the many Font.GlyphRegions this has for each glyph.
      Parameters:
      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
      makeGridGlyphs - true if this should use its own way of rendering box-drawing/block-element glyphs, ignoring any in the font file
    • loadSad

      protected void loadSad​(java.lang.String prefix, java.lang.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 IntFloatMap.get(int, float) method, you'll get the amount of extra space (in the same unit the font uses) this will insert between first and second.
      Parameters:
      first - the first char
      second - the second char
      Returns:
      a kerning pair that can be looked up in kerning
    • scale

      public Font scale​(float 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
    • fitCell

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

      public float getUnderlineX()
    • getUnderlineY

      public float getUnderlineY()
    • setUnderlinePosition

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

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

      public float getStrikethroughX()
    • getStrikethroughY

      public float getStrikethroughY()
    • setStrikethroughPosition

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

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

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

      public float getInlineImageOffsetX()
    • getInlineImageOffsetY

      public float getInlineImageOffsetY()
    • getInlineImageXAdvance

      public float getInlineImageXAdvance()
    • setInlineImageMetrics

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

      public Font setTextureFilter()
      Calls setTextureFilter(Texture.TextureFilter, Texture.TextureFilter) with Texture.TextureFilter.Linear for both min and mag filters. This is the most common usage for setting the texture filters, and is appropriate when you have a large TextureRegion holding the font and you normally downscale it. This is automatically done for Font.DistanceFieldType.SDF 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
    • useIntegerPositions

      public Font useIntegerPositions​(boolean integer)
    • getDescent

      public float getDescent()
    • setDescent

      public Font setDescent​(float descent)
    • getName

      public java.lang.String getName()
    • setName

      public Font setName​(java.lang.String name)
    • 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
    • addImage

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

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

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

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

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

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

      public void enableShader​(com.badlogic.gdx.graphics.g2d.Batch batch)
      Must be called before drawing anything with an SDF or MSDF font; does not need to be called for other fonts unless you are mixing them with SDF/MSDF fonts or other shaders. This also resets the Batch color to white, in case it had been left with a different setting before. If this Font is not an 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, java.lang.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, java.lang.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 drawVertices(Batch, Texture, float[]) to draw each rectangle with minimal overhead, and this also means it is unaffected by the batch color unless drawVertices was overridden. If you want to alter the colors using a shader, the shader will receive each color in colors as its a_color attribute, the same as if it was passed via the batch color.
      If you want to change the alpha of the colors array, you can use ColorUtils.multiplyAllAlpha(int[][], float).
      Parameters:
      batch - typically a SpriteBatch
      colors - a 2D rectangular array of int colors (typically RGBA)
      x - the x position in world space to draw the text at (lower left corner)
      y - the y position in world space to draw the text at (lower left corner)
    • drawBlocks

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

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

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

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

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

      public int drawMarkupText​(com.badlogic.gdx.graphics.g2d.Batch batch, java.lang.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:
      • [] clears all markup to the initial state without any applied.
      • [[ escapes a literal left bracket, producing it without changing state.
      • [+name], where name is the name of a TextureRegion from an atlas added to this Font with addAtlas(TextureAtlas), produces the corresponding TextureRegion (scaled when drawn) without changing state. If no atlas has been added, this emits a + character instead.
      • [*] toggles bold mode.
      • [/] toggles italic (technically, oblique) mode.
      • [^] toggles superscript mode (and turns off subscript or midscript mode).
      • [=] toggles midscript mode (and turns off superscript or subscript mode).
      • [.] toggles subscript mode (and turns off superscript or midscript mode).
      • [_] toggles underline mode.
      • [~] toggles strikethrough mode.
      • [!] toggles all upper case mode.
      • [,] toggles all lower case mode.
      • [;] toggles capitalize each word mode.
      • [%P], where P is a percentage from 0 to 375, changes the scale to that percentage (rounded to the nearest 25% mark).
      • [%], with no number just after it, resets scale to 100%.
      • [@Name], where Name is a key in family, changes the current Font used for rendering to the Font in this.family by that name. This is ignored if family is null.
      • [@], with no text just after it, resets the font to this one (which should be item 0 in family, if family is non-null).
      • [#HHHHHHHH], where HHHHHHHH is a hex RGB888 or RGBA8888 int color, changes the color.
      • [COLORNAME], where "COLORNAME" is a typically-upper-case color name that will be looked up with getColorLookup(), changes the color. The name can optionally be preceded by |, which allows looking up colors with names that contain punctuation.

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

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

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

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

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

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

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

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

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

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

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

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

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

      protected float handleIntegerPosition​(float p)
      If integerPosition is true, this returns p rounded to the nearest int; otherwise this just returns p unchanged.
      Parameters:
      p - a float that could be rounded
      Returns:
      either p rounded to the nearest int or p unchanged, depending on integerPosition
    • drawGlyph

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

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

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

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

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

      protected boolean handleEllipsis​(Layout appendTo)
    • markupGlyph

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

      public static long markupGlyph​(char chr, java.lang.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). This also disables any alternate mode.
      • [%?MODE], where MODE can be (case-insensitive) one of "black outline", "white outline", "shiny", "drop shadow"/"shadow", "error", "warn", "note", or "jostle", will disable scaling and enable that alternate mode. If MODE is empty or not recognized, this considers it equivalent to "jostle".
      • [%^MODE], where MODE can be (case-insensitive) one of "black outline", "white outline", "shiny", "drop shadow"/"shadow", "error", "warn", "note", or "small caps", will disable scaling and enable that alternate mode along with small caps mode at the same time. If MODE is empty or not recognized, this considers it equivalent to "small caps" (without another mode).
      • [%], with no number just after it, resets scale to 100% and disables any alternate mode.
      • [@Name], where Name is a key in family, changes the current Font used for rendering to the Font in this.family by that name. This is ignored if family is null.
      • [@], with no text just after it, resets the font to this one (which should be item 0 in family, if family is non-null).
      • [#HHHHHHHH], where HHHHHHHH is a hex RGB888 or RGBA8888 int color, changes the color.
      • [COLORNAME], where "COLORNAME" is a typically-upper-case color name that will be looked up in getColorLookup(), changes the color. The name can optionally be preceded by |, which allows looking up colors with names that contain punctuation.
      You can render the result using drawGlyph(Batch, long, float, float). It is recommended that you avoid calling this method every frame, because the color lookups usually allocate some memory, and because this can usually be stored for later without needing repeated computation.
      This takes a ColorLookup so that it can look up colors given a name or description; if you don't know what to use, then ColorLookup.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.DESCRIPTIVE) to get colors from textual names or descriptions
      Returns:
      a long that encodes the given char with the specified markup
    • markupGlyph

      public static long markupGlyph​(char chr, java.lang.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). This also disables any alternate mode.
      • [%?MODE], where MODE can be (case-insensitive) one of "black outline", "white outline", "shiny", "drop shadow"/"shadow", "error", "warn", "note", or "jostle", will disable scaling and enable that alternate mode. If MODE is empty or not recognized, this considers it equivalent to "jostle".
      • [%^MODE], where MODE can be (case-insensitive) one of "black outline", "white outline", "shiny", "drop shadow"/"shadow", "error", "warn", "note", or "small caps", will disable scaling and enable that alternate mode along with small caps mode at the same time. If MODE is empty or not recognized, this considers it equivalent to "small caps" (without another mode).
      • [%], with no number just after it, resets scale to 100% and disables any alternate mode.
      • [@Name], where Name is a key in family, changes the current Font used for rendering to the Font in this.family by that name. This is ignored if family is null.
      • [@], with no text just after it, resets the font to this one (which should be item 0 in family, if family is non-null).
      • [#HHHHHHHH], where HHHHHHHH is a hex RGB888 or RGBA8888 int color, changes the color.
      • [COLORNAME], where "COLORNAME" is a typically-upper-case color name that will be looked up in getColorLookup(), changes the color. The name can optionally be preceded by |, which allows looking up colors with names that contain punctuation.
      You can render the result using drawGlyph(Batch, long, float, float). It is recommended that you avoid calling this method every frame, because the color lookups usually allocate some memory, and because this can usually be stored for later without needing repeated computation.
      This takes a ColorLookup so that it can look up colors given a name or description; if you don't know what to use, then ColorLookup.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.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)
      When the targetWidth of a Layout changes, you can use this to cause the text to be placed according to the new width, and wrap if needed. This doesn't allocate as much as markup(String, Layout), if at all, but may eat up newlines if called repeatedly.
      Parameters:
      changing - a Layout that will be modified in-place
      Returns:
      changing, after modifications
    • 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. If alternate mode is enabled, then this always returns 1.0f , because scale is ignored when alternate mode is on.
      Parameters:
      glyph - a glyph as a long, as used by Layout and Line
      Returns:
      the float scale used by the given glyph, from 0.0f to 3.75f
    • applyScale

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

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

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

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

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

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

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

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

      public java.lang.String debugString()
    • drawVertices

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

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