public class Font
extends java.lang.Object
implements com.badlogic.gdx.utils.Disposable
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.
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.
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.
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!
| Modifier and Type | Class and 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.
|
| Modifier and Type | Field and 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 |
BOLD
Bit flag for bold mode, as a long.
|
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
Colors. |
Font.GlyphRegion |
defaultValue
Which GlyphRegion to display if a char isn't found in
mapping. |
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). |
Font.FontFamily |
family
If non-null, may contain connected Font values and names/aliases to look them up with using [@Name] syntax.
|
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.
|
com.badlogic.gdx.utils.IntIntMap |
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.
|
com.badlogic.gdx.utils.ObjectIntMap<java.lang.String> |
nameLookup
Optional; maps the names of TextureRegions to the indices they use in
mapping, and usually assigned by
addAtlas(TextureAtlas). |
static long |
OBLIQUE
Bit flag for oblique mode, as a long.
|
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. |
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.
|
com.badlogic.gdx.graphics.glutils.ShaderProgram |
shader
The ShaderProgram used to render this font, as used by
enableShader(Batch). |
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. |
static long |
STRIKETHROUGH
Bit flag for strikethrough mode, as a long.
|
static long |
SUBSCRIPT
Bit flag for subscript mode, as a long.
|
static long |
SUPERSCRIPT
Two-bit flag for superscript mode, as a long.
|
static long |
UNDERLINE
Bit flag for underline mode, as a long.
|
static java.lang.String |
vertexShader
The standard libGDX vertex shader source, which is also used by the MSDF shader.
|
| Constructor and Description |
|---|
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.
|
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,
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,
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,
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)
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 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.
|
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.
|
| Modifier and Type | Method and 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. |
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 |
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. |
float |
calculateSize(Layout layout) |
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. |
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). |
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 |
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.
|
void |
enableShader(com.badlogic.gdx.graphics.g2d.Batch batch)
Must be called before drawing anything with an SDF or MSDF font; does not need to be called for other fonts
unless you are mixing them with SDF/MSDF fonts or other shaders.
|
static char |
extractChar(long glyph)
Given a glyph as a long, this returns the char it displays.
|
static int |
extractColor(long glyph)
Given a glyph as a long, this returns the RGBA8888 color it uses.
|
static float |
extractScale(long glyph)
Given a glyph as a long, this returns the float multiplier it uses for scale.
|
static long |
extractStyle(long glyph)
Given a glyph as a long, this returns the style bits it uses.
|
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.
|
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).
|
java.lang.String |
getName() |
protected float |
handleIntegerPosition(float p) |
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 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)
|
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. |
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) |
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 |
setFamily(Font.FontFamily family)
Sets the FontFamily this can use to switch fonts using [@Name] syntax.
|
Font |
setName(java.lang.String name) |
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. |
java.lang.String |
toString() |
Font |
useIntegerPositions(boolean integer) |
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. |
float |
xAdvance(long glyph)
Gets the distance to advance the cursor after drawing
glyph, scaled by scaleX as if drawing. |
public com.badlogic.gdx.utils.IntMap<Font.GlyphRegion> mapping
Font.GlyphRegion values. You can add arbitrary images
to this mapping if you create appropriate GlyphRegion values (as with
GlyphRegion(TextureRegion, int, int, int, int)), though they must map to a char.public com.badlogic.gdx.utils.ObjectIntMap<java.lang.String> nameLookup
mapping, and usually assigned by
addAtlas(TextureAtlas).public Font.GlyphRegion defaultValue
mapping. May be null to show a space by default.public com.badlogic.gdx.utils.Array<com.badlogic.gdx.graphics.g2d.TextureRegion> parents
Font.GlyphRegion images are pulled from; these could be whole Textures or be
drawn from a TextureAtlas that the font shares with other images.public Font.DistanceFieldType distanceField
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.public boolean isMono
public com.badlogic.gdx.utils.IntIntMap kerning
public float actualCrispness
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.public float distanceFieldCrispness
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.public float cellWidth
isMono is true; otherwise refers to the largest width of any
glyph in the font, after scaling.public float cellHeight
public float originalCellWidth
isMono is true; otherwise refers to the largest width of any
glyph in the font, before any scaling.public float originalCellHeight
public float scaleX
public float scaleY
public char solidBlock
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 character 0, this defaults to u0000 . 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.public Font.FontFamily family
public ColorLookup colorLookup
Colors.public boolean integerPosition
public java.lang.String name
Font.FontFamily.public static final long BOLD
public static final long OBLIQUE
public static final long UNDERLINE
public static final long STRIKETHROUGH
public static final long SUBSCRIPT
public static final long MIDSCRIPT
public static final long SUPERSCRIPT
SUBSCRIPT, MIDSCRIPT, or SUPERSCRIPT are enabled.public static final java.lang.String vertexShader
public static final java.lang.String msdfFragmentShader
enableShader(Batch) is
called and the distanceField is Font.DistanceFieldType.MSDF.public com.badlogic.gdx.graphics.glutils.ShaderProgram shader
enableShader(Batch).
If this is null, the font will be rendered with the Batch's default shader.
It may be set to a custom ShaderProgram if distanceField is set to Font.DistanceFieldType.MSDF,
or to one created by DistanceFieldFont.createDistanceFieldShader() if distanceField is set to
Font.DistanceFieldType.SDF. It can be set to a user-defined ShaderProgram; if it is meant to render
MSDF or SDF fonts, then the ShaderProgram should have a uniform float u_smoothing; that will be
set by enableShader(Batch). Values passed to u_smoothing can vary a lot, depending on how the
font was initially created, its current scale, and its actualCrispness field. You can
also use a user-defined ShaderProgram with a font using Font.DistanceFieldType.STANDARD, which may be
easier and can use any uniforms you normally could with a ShaderProgram, since enableShader() won't
change any of the uniforms.public Font(java.lang.String fntName)
fntName - the file path and name to a .fnt file this will loadpublic Font(java.lang.String fntName,
Font.DistanceFieldType distanceField)
fntName - the file path and name to a .fnt file this will loaddistanceField - determines how edges are drawn; if unsure, you should use Font.DistanceFieldType.STANDARDpublic Font(java.lang.String fntName,
java.lang.String textureName)
fntName - the file path and name to a .fnt file this will loadpublic Font(java.lang.String fntName,
java.lang.String textureName,
Font.DistanceFieldType distanceField)
fntName - the file path and name to a .fnt file this will loaddistanceField - determines how edges are drawn; if unsure, you should use Font.DistanceFieldType.STANDARDpublic Font(Font toCopy)
shader or colorLookup, if it has them (it uses the
same reference for the new Font), but will fully copy everything else.toCopy - another Font to copypublic Font(java.lang.String fntName,
float xAdjust,
float yAdjust,
float widthAdjust,
float heightAdjust)
originalCellWidth to widthAdjust and about half that to xAdjust; this can be used to make the glyphs fit
in square cells.fntName - the path and filename of a .fnt file this will load; may be internal or localxAdjust - how many pixels to offset each character's x-position by, moving to the rightyAdjust - how many pixels to offset each character's y-position by, moving upwidthAdjust - how many pixels to add to the used width of each character, using more to the rightheightAdjust - how many pixels to add to the used height of each character, using more abovepublic Font(java.lang.String fntName,
Font.DistanceFieldType distanceField,
float xAdjust,
float yAdjust,
float widthAdjust,
float heightAdjust)
originalCellWidth to widthAdjust and about half that to xAdjust; this can be used to make the glyphs fit
in square cells.fntName - the path and filename of a .fnt file this will load; may be internal or localdistanceField - determines how edges are drawn; if unsure, you should use Font.DistanceFieldType.STANDARDxAdjust - how many pixels to offset each character's x-position by, moving to the rightyAdjust - how many pixels to offset each character's y-position by, moving upwidthAdjust - how many pixels to add to the used width of each character, using more to the rightheightAdjust - how many pixels to add to the used height of each character, using more abovepublic Font(java.lang.String fntName,
Font.DistanceFieldType distanceField,
float xAdjust,
float yAdjust,
float widthAdjust,
float heightAdjust,
boolean makeGridGlyphs)
originalCellWidth to widthAdjust and about half that to xAdjust; this can be used to make the glyphs fit
in square cells.fntName - the path and filename of a .fnt file this will load; may be internal or localdistanceField - determines how edges are drawn; if unsure, you should use Font.DistanceFieldType.STANDARDxAdjust - how many pixels to offset each character's x-position by, moving to the rightyAdjust - how many pixels to offset each character's y-position by, moving upwidthAdjust - how many pixels to add to the used width of each character, using more to the rightheightAdjust - how many pixels to add to the used height of each character, using more abovemakeGridGlyphs - true if this should use its own way of rendering box-drawing/block-element glyphs, ignoring any in the font filepublic Font(java.lang.String fntName,
java.lang.String textureName,
float xAdjust,
float yAdjust,
float widthAdjust,
float heightAdjust)
originalCellWidth to widthAdjust and about half that to xAdjust; this can be used to make the glyphs fit
in square cells.fntName - the path and filename of a .fnt file this will load; may be internal or localtextureName - the path and filename of a texture file this will load; may be internal or localxAdjust - how many pixels to offset each character's x-position by, moving to the rightyAdjust - how many pixels to offset each character's y-position by, moving upwidthAdjust - how many pixels to add to the used width of each character, using more to the rightheightAdjust - how many pixels to add to the used height of each character, using more abovepublic Font(java.lang.String fntName,
java.lang.String textureName,
Font.DistanceFieldType distanceField,
float xAdjust,
float yAdjust,
float widthAdjust,
float heightAdjust)
originalCellWidth to widthAdjust and about half that to xAdjust; this can be used to make the glyphs fit
in square cells.fntName - the path and filename of a .fnt file this will load; may be internal or localtextureName - the path and filename of a texture file this will load; may be internal or localdistanceField - determines how edges are drawn; if unsure, you should use Font.DistanceFieldType.STANDARDxAdjust - how many pixels to offset each character's x-position by, moving to the rightyAdjust - how many pixels to offset each character's y-position by, moving upwidthAdjust - how many pixels to add to the used width of each character, using more to the rightheightAdjust - how many pixels to add to the used height of each character, using more abovepublic Font(java.lang.String fntName,
java.lang.String textureName,
Font.DistanceFieldType distanceField,
float xAdjust,
float yAdjust,
float widthAdjust,
float heightAdjust,
boolean makeGridGlyphs)
originalCellWidth to widthAdjust and about half that to xAdjust; this can be used to make the glyphs fit
in square cells.fntName - the path and filename of a .fnt file this will load; may be internal or localtextureName - the path and filename of a texture file this will load; may be internal or localdistanceField - determines how edges are drawn; if unsure, you should use Font.DistanceFieldType.STANDARDxAdjust - how many pixels to offset each character's x-position by, moving to the rightyAdjust - how many pixels to offset each character's y-position by, moving upwidthAdjust - how many pixels to add to the used width of each character, using more to the rightheightAdjust - how many pixels to add to the used height of each character, using more abovemakeGridGlyphs - true if this should use its own way of rendering box-drawing/block-element glyphs, ignoring any in the font filepublic Font(java.lang.String fntName,
com.badlogic.gdx.graphics.g2d.TextureRegion textureRegion,
float xAdjust,
float yAdjust,
float widthAdjust,
float heightAdjust)
originalCellWidth to widthAdjust and about half that to xAdjust; this can be used to make the glyphs fit
in square cells.fntName - the path and filename of a .fnt file this will load; may be internal or localtextureRegion - an existing TextureRegion, typically inside a larger TextureAtlasxAdjust - how many pixels to offset each character's x-position by, moving to the rightyAdjust - how many pixels to offset each character's y-position by, moving upwidthAdjust - how many pixels to add to the used width of each character, using more to the rightheightAdjust - how many pixels to add to the used height of each character, using more abovepublic Font(java.lang.String fntName,
com.badlogic.gdx.graphics.g2d.TextureRegion textureRegion,
Font.DistanceFieldType distanceField,
float xAdjust,
float yAdjust,
float widthAdjust,
float heightAdjust)
originalCellWidth to widthAdjust and about half that to xAdjust; this can be used to make the glyphs fit
in square cells.fntName - the path and filename of a .fnt file this will load; may be internal or localtextureRegion - an existing TextureRegion, typically inside a larger TextureAtlasdistanceField - determines how edges are drawn; if unsure, you should use Font.DistanceFieldType.STANDARDxAdjust - how many pixels to offset each character's x-position by, moving to the rightyAdjust - how many pixels to offset each character's y-position by, moving upwidthAdjust - how many pixels to add to the used width of each character, using more to the rightheightAdjust - how many pixels to add to the used height of each character, using more abovepublic 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)
originalCellWidth to widthAdjust and about half that to xAdjust; this can be used to make the glyphs fit
in square cells.fntName - the path and filename of a .fnt file this will load; may be internal or localtextureRegion - an existing TextureRegion, typically inside a larger TextureAtlasdistanceField - determines how edges are drawn; if unsure, you should use Font.DistanceFieldType.STANDARDxAdjust - how many pixels to offset each character's x-position by, moving to the rightyAdjust - how many pixels to offset each character's y-position by, moving upwidthAdjust - how many pixels to add to the used width of each character, using more to the rightheightAdjust - how many pixels to add to the used height of each character, using more abovemakeGridGlyphs - true if this should use its own way of rendering box-drawing/block-element glyphs, ignoring any in the font filepublic 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)
originalCellWidth to widthAdjust and about half that to xAdjust; this can be used to make the glyphs fit
in square cells.fntName - the path and filename of a .fnt file this will load; may be internal or localtextureRegions - an Array of TextureRegions that will be used in order as the .fnt file uses more pagesxAdjust - how many pixels to offset each character's x-position by, moving to the rightyAdjust - how many pixels to offset each character's y-position by, moving upwidthAdjust - how many pixels to add to the used width of each character, using more to the rightheightAdjust - how many pixels to add to the used height of each character, using more abovepublic 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)
originalCellWidth to widthAdjust and about half that to xAdjust; this can be used to make the glyphs fit
in square cells.fntName - the path and filename of a .fnt file this will load; may be internal or localtextureRegions - an Array of TextureRegions that will be used in order as the .fnt file uses more pagesdistanceField - determines how edges are drawn; if unsure, you should use Font.DistanceFieldType.STANDARDxAdjust - how many pixels to offset each character's x-position by, moving to the rightyAdjust - how many pixels to offset each character's y-position by, moving upwidthAdjust - how many pixels to add to the used width of each character, using more to the rightheightAdjust - how many pixels to add to the used height of each character, using more abovepublic 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)
originalCellWidth to widthAdjust and about half that to xAdjust; this can be used to make the glyphs fit
in square cells.fntName - the path and filename of a .fnt file this will load; may be internal or localtextureRegions - an Array of TextureRegions that will be used in order as the .fnt file uses more pagesdistanceField - determines how edges are drawn; if unsure, you should use Font.DistanceFieldType.STANDARDxAdjust - how many pixels to offset each character's x-position by, moving to the rightyAdjust - how many pixels to offset each character's y-position by, moving upwidthAdjust - how many pixels to add to the used width of each character, using more to the rightheightAdjust - how many pixels to add to the used height of each character, using more abovemakeGridGlyphs - true if this should use its own way of rendering box-drawing/block-element glyphs, ignoring any in the font filepublic Font(com.badlogic.gdx.graphics.g2d.BitmapFont bmFont)
bmFont - an existing BitmapFont that will be copied in almost every way this canpublic Font(com.badlogic.gdx.graphics.g2d.BitmapFont bmFont,
float xAdjust,
float yAdjust,
float widthAdjust,
float heightAdjust)
bmFont - an existing BitmapFont that will be copied in almost every way this canxAdjust - how many pixels to offset each character's x-position by, moving to the rightyAdjust - how many pixels to offset each character's y-position by, moving upwidthAdjust - how many pixels to add to the used width of each character, using more to the rightheightAdjust - how many pixels to add to the used height of each character, using more abovepublic Font(com.badlogic.gdx.graphics.g2d.BitmapFont bmFont,
Font.DistanceFieldType distanceField,
float xAdjust,
float yAdjust,
float widthAdjust,
float heightAdjust)
bmFont - an existing BitmapFont that will be copied in almost every way this candistanceField - determines how edges are drawn; if unsure, you should use Font.DistanceFieldType.STANDARDxAdjust - how many pixels to offset each character's x-position by, moving to the rightyAdjust - how many pixels to offset each character's y-position by, moving upwidthAdjust - how many pixels to add to the used width of each character, using more to the rightheightAdjust - how many pixels to add to the used height of each character, using more abovepublic Font(com.badlogic.gdx.graphics.g2d.BitmapFont bmFont,
Font.DistanceFieldType distanceField,
float xAdjust,
float yAdjust,
float widthAdjust,
float heightAdjust,
boolean makeGridGlyphs)
bmFont - an existing BitmapFont that will be copied in almost every way this candistanceField - determines how edges are drawn; if unsure, you should use Font.DistanceFieldType.STANDARDxAdjust - how many pixels to offset each character's x-position by, moving to the rightyAdjust - how many pixels to offset each character's y-position by, moving upwidthAdjust - how many pixels to add to the used width of each character, using more to the rightheightAdjust - how many pixels to add to the used height of each character, using more abovemakeGridGlyphs - true if this should use its own way of rendering box-drawing/block-element glyphs, ignoring any in the font filepublic Font(java.lang.String fntName,
boolean ignoredSadConsoleFlag)
fntName - the path and filename of a .font file this will load; may be internal or localignoredSadConsoleFlag - the value is ignored here; the presence of this parameter says to load a SadConsole .font filepublic static long longFromHex(java.lang.CharSequence cs,
int start,
int end)
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 readend - the (exclusive) last character position in cs to read (this stops after 16 characters if end is too large)public static int intFromHex(java.lang.CharSequence cs,
int start,
int end)
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 readend - the (exclusive) last character position in cs to read (this stops after 16 characters if end is too large)public static int intFromDec(java.lang.CharSequence cs,
int start,
int end)
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.
cs - a CharSequence, such as a String, containing only digits 0-9 with an optional signstart - the (inclusive) first character position in cs to readend - the (exclusive) last character position in cs to read (this stops after 10 or 11 characters if end is too large, depending on sign)public static java.lang.String safeSubstring(java.lang.String source,
int beginIndex,
int endIndex)
String.substring(int, int) but returns "" instead of throwing any sort of Exception.source - the String to get a substring frombeginIndex - the first index, inclusive; will be treated as 0 if negativeendIndex - the index after the last character (exclusive); if negative this will be source.length()public static boolean isLowerCase(char c)
c is a lower-case letter, or false otherwise.
Similar to Character.isLowerCase(char), but should actually work on GWT.c - a char to checkpublic static boolean isUpperCase(char c)
c is an upper-case letter, or false otherwise.
Similar to Character.isUpperCase(char), but should actually work on GWT.c - a char to checkpublic ColorLookup getColorLookup()
public Font setColorLookup(ColorLookup lookup)
ColorLookup interface implementation.lookup - a non-null ColorLookupprotected void loadFNT(java.lang.String fntName,
float xAdjust,
float yAdjust,
float widthAdjust,
float heightAdjust,
boolean makeGridGlyphs)
Font.GlyphRegions this has for each glyph.fntName - the file name of the .fnt file; can be internal or localxAdjust - added to the x-position for each glyph in the fontyAdjust - added to the y-position for each glyph in the fontwidthAdjust - added to the glyph width for each glyph in the fontheightAdjust - added to the glyph height for each glyph in the fontmakeGridGlyphs - true if this should use its own way of rendering box-drawing/block-element glyphs, ignoring any in the font fileprotected void loadSad(java.lang.String fntName)
Font.GlyphRegions this has for each glyph.fntName - the name of a font file this will load from an internal or local file handle (tried in that order)public int kerningPair(char first,
char second)
kerning. This is unlikely to
be used by most user code, but can be useful for anything that's digging deeply into the internals here.
If you give such a pair to kerning's IntIntMap.get(int, int) method, you'll get the amount of
extra space (in the same unit the font uses) this will insert between first and second.first - the first charsecond - the second charkerningpublic Font scale(float horizontal, float vertical)
horizontal - how much to multiply the width of each glyph byvertical - how much to multiply the height of each glyph bypublic Font scaleTo(float width, float height)
width - the target width of the font, in world unitsheight - the target height of the font, in world unitspublic Font adjustLineHeight(float multiplier)
multiplier without changing the size of any characters.
This can cut off the tops of letters if the multiplier is too small.multiplier - will be applied to cellHeight and originalCellHeightpublic Font adjustCellWidth(float multiplier)
multiplier without changing the size of
any characters.multiplier - will be applied to cellWidth and originalCellWidthpublic Font fitCell(float width, float height, boolean center)
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.width - the target width of a cell, in world unitsheight - the target height of a cell, in world unitscenter - if true, this will center every glyph in its cellpublic Font setTextureFilter()
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.public Font setTextureFilter(com.badlogic.gdx.graphics.Texture.TextureFilter minFilter, com.badlogic.gdx.graphics.Texture.TextureFilter magFilter)
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.public Font useIntegerPositions(boolean integer)
public java.lang.String getName()
public Font setName(java.lang.String name)
public float getCrispness()
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.public Font setCrispness(float crispness)
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.crispness - a float multiplier to be applied to the working crispness; 1.0 is the defaultpublic Font multiplyCrispness(float multiplier)
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.multiplier - a float multiplier to be applied to the working crispness multiplierpublic Font addImage(java.lang.String character, com.badlogic.gdx.graphics.g2d.TextureRegion region, float offsetX, float offsetY, float xAdvance)
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.
Like this atlas.character - a String containing at least one character; only the last char (not codepoint) will be usedregion - the TextureRegion to associate with the given characteroffsetX - the x offset to position the drawn TextureRegion at, with positive offset moving rightoffsetY - the y offset to position the drawn TextureRegion at, with positive offset moving upxAdvance - how much horizontal space the GlyphRegion should take uppublic Font addImage(java.lang.String character, com.badlogic.gdx.graphics.g2d.TextureRegion region)
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.
Like this atlas.character - a String containing at least one character; only the last char (not codepoint) will be usedregion - the TextureRegion to associate with the given characterpublic Font addAtlas(com.badlogic.gdx.graphics.g2d.TextureAtlas atlas)
atlas to the private use area of mapping, and stores their names, so they can
be looked up with [+saxophone] syntax.
Here's a possible atlas.atlas - a TextureAtlas that shouldn't have more than 6144 names; all of it will be usedpublic void enableShader(com.badlogic.gdx.graphics.g2d.Batch batch)
batch.setShader(null)).
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); .batch - the Batch to instruct to use the appropriate shader for this font; should usually be a SpriteBatchpublic void drawText(com.badlogic.gdx.graphics.g2d.Batch batch,
java.lang.CharSequence text,
float x,
float y)
batch - typically a SpriteBatchtext - typically a String, but this can also be a StringBuilder or some custom classx - 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)public void drawText(com.badlogic.gdx.graphics.g2d.Batch batch,
java.lang.CharSequence text,
float x,
float y,
int color)
batch - typically a SpriteBatchtext - typically a String, but this can also be a StringBuilder or some custom classx - 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 colorpublic void drawBlocks(com.badlogic.gdx.graphics.g2d.Batch batch,
int[][] colors,
float x,
float y)
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.
Batch.draw(Texture, float[], int, int) to draw each rectangle with minimal
overhead, and this also means it is unaffected by the batch color. If you want to alter the colors using a
shader, the shader will receive each color in colors as its a_color attribute, the same as if it
was passed via the batch color.
ColorUtils.multiplyAllAlpha(int[][], float).batch - typically a SpriteBatchcolors - 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)public void drawBlocks(com.badlogic.gdx.graphics.g2d.Batch batch,
char blockChar,
int[][] colors,
float x,
float y)
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.
Batch.draw(Texture, float[], int, int) to draw each rectangle with minimal
overhead, and this also means it is unaffected by the batch color. If you want to alter the colors using a
shader, the shader will receive each color in colors as its a_color attribute, the same as if it
was passed via the batch color.
ColorUtils.multiplyAllAlpha(int[][], float).batch - typically a SpriteBatchblockChar - a char that renders as a full block, occupying an entire monospaced cell with a colorcolors - 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)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[], 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.batch - typically a SpriteBatchsequence - a sequence of instructions in groups of 4: starting x, starting y, width to draw, height to drawblock - the TextureRegion to use as a block for drawing; usually solidBlockcolor - the color as a packed floatx - the x position to draw aty - the y position to draw atprotected 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[], 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.batch - typically a SpriteBatchsequence - a sequence of instructions in groups of 4: starting x, starting y, width to draw, height to drawblock - the TextureRegion to use as a block for drawing; usually solidBlockcolor - the color as a packed floatx - the x position to draw aty - the y position to draw atwidth - the width of one cell for the purposes of sequence instructionsheight - the height of one cell for the purposes of sequence instructionsprotected void drawBlockSequence(com.badlogic.gdx.graphics.g2d.Batch batch,
float[] sequence,
com.badlogic.gdx.graphics.g2d.TextureRegion block,
float color,
float x,
float y,
float width,
float height,
float rotation)
float[], 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.batch - typically a SpriteBatchsequence - a sequence of instructions in groups of 4: starting x, starting y, width to draw, height to drawblock - the TextureRegion to use as a block for drawing; usually solidBlockcolor - the color as a packed floatx - the x position to draw aty - the y position to draw atwidth - the width of one cell for the purposes of sequence instructionsheight - the height of one cell for the purposes of sequence instructionsrotation - the rotation in degrees to use for the cell of blocks, with the origin in the center of the cellpublic int drawMarkupText(com.badlogic.gdx.graphics.g2d.Batch batch,
java.lang.String text,
float x,
float y)
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.markup(String, Layout) and render its result with
drawGlyphs(Batch, Layout, float, float) every frame.batch - typically a SpriteBatchtext - typically a String with markup, but this can also be a StringBuilder or some custom classx - 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)public float drawGlyphs(com.badlogic.gdx.graphics.g2d.Batch batch,
Layout glyphs,
float x,
float y)
batch - typically a SpriteBatchglyphs - 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)public float drawGlyphs(com.badlogic.gdx.graphics.g2d.Batch batch,
Layout glyphs,
float x,
float y,
int align)
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.batch - typically a SpriteBatchglyphs - 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 cornerpublic float drawGlyphs(com.badlogic.gdx.graphics.g2d.Batch batch,
Layout glyphs,
float x,
float y,
int align,
float rotation,
float originX,
float originY)
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.batch - typically a SpriteBatchglyphs - 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 Linerotation - measured in degrees counterclockwise, typically 0-360, and applied to the whole LayoutoriginX - the x position in world space of the point to rotate aroundoriginY - the y position in world space of the point to rotate aroundpublic float drawGlyphs(com.badlogic.gdx.graphics.g2d.Batch batch,
Line glyphs,
float x,
float y)
batch - typically a SpriteBatchglyphs - 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)public float drawGlyphs(com.badlogic.gdx.graphics.g2d.Batch batch,
Line glyphs,
float x,
float y,
int align)
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.batch - typically a SpriteBatchglyphs - 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 cornerpublic float drawGlyphs(com.badlogic.gdx.graphics.g2d.Batch batch,
Line glyphs,
float x,
float y,
int align,
float rotation,
float originX,
float originY)
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.batch - typically a SpriteBatchglyphs - 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 cornerrotation - measured in degrees counterclockwise and applied to the whole LineoriginX - the x position in world space of the point to rotate aroundoriginY - the y position in world space of the point to rotate aroundpublic static float xAdvance(Font font, float scale, long glyph)
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.font - the Font object to use to measurescale - the scale to draw the glyph at, usually scaleX and possibly adjusted by per-glyph scalingglyph - a long encoding the color, style information, and char of a glyph, as from a Linepublic float xAdvance(long glyph)
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.glyph - a long encoding the color, style information, and char of a glyph, as from a Linepublic float measureWidth(Line line)
line - a Line, as from inside a Layoutpublic float calculateSize(Line line)
Line.width
field.line - a Line, as from inside a Layoutpublic float calculateSize(Layout layout)
protected float handleIntegerPosition(float p)
public float drawGlyph(com.badlogic.gdx.graphics.g2d.Batch batch,
long glyph,
float x,
float y)
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.batch - typically a SpriteBatchglyph - a long storing a char, format, and color; typically part of a longer formatted text as a LongArrayx - 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)public float drawGlyph(com.badlogic.gdx.graphics.g2d.Batch batch,
long glyph,
float x,
float y,
float rotation)
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.batch - typically a SpriteBatchglyph - a long storing a char, format, and color; typically part of a longer formatted text as a LongListx - 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 counterclockwisepublic float drawGlyph(com.badlogic.gdx.graphics.g2d.Batch batch,
long glyph,
float x,
float y,
float rotation,
float sizingX,
float sizingY)
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.batch - typically a SpriteBatchglyph - a long storing a char, format, and color; typically part of a longer formatted text as a LongListx - 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 counterclockwisesizingX - the multiple for the glyph to be stretched on x, where 1 is "no change"; does not affect metricssizingY - the multiple for the glyph to be stretched on y, where 1 is "no change"; does not affect metricspublic Layout markup(java.lang.String text, Layout appendTo)
Layout holding one or more Lines. A common way of getting a Layout is with
Layout.POOL.obtain(); you can free the Layout when you are done using it with Pool.free(Object)
on Layout.POOL. This parses an extension of libGDX markup and uses it to determine color, size, position,
shape, strikethrough, underline, case, and scale of the given CharSequence. It also reads typing markup, for
effects, but passes it through without changing it and without considering it for line wrapping or text position.
The text drawn will start in appendTo's Layout.baseColor, which is usually white, with the normal
size as determined by the font's metrics and scale (scaleX and scaleY), normal case, and
without bold, italic, superscript, subscript, strikethrough, or underline. Markup starts with [; the next
character determines what that piece of markup toggles. Markup this knows:
[] 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 in
getColorLookup(), changes the color. The name can optionally be preceded by |, which allows
looking up colors with names that contain punctuation.appendTo using drawGlyphs(Batch, Layout, float, float).text - text with markupappendTo - a Layout that stores one or more Line objects, carrying color, style, chars, and sizepublic long markupGlyph(char chr,
java.lang.String markup)
markup, processes it, and applies it to the given char chr; returns a long
in the format used for styled glyphs here. This parses an extension of libGDX markup and uses it to determine
color, size, position, shape, strikethrough, underline, case, and scale of the given char.
The char drawn will start in white, with the normal size as determined by the font's metrics and scale
(scaleX and scaleY), normal case, and without bold, italic, superscript, subscript,
strikethrough, or underline. Markup starts with [; the next character determines what that piece of
markup toggles. Markup this knows:
[] clears all markup to the initial state without any applied.[*] toggles bold mode.[/] toggles italic (technically, oblique) mode.[^] toggles superscript mode (and turns off subscript or midscript mode).[=] toggles midscript mode (and turns off superscript or subscript mode).[.] toggles subscript mode (and turns off superscript or midscript mode).[_] toggles underline mode.[~] toggles strikethrough mode.[!] toggles all upper case mode.[,] toggles all lower case mode.[;] toggles capitalize each word mode (this is the same as upper case mode here).[%P], where P is a percentage from 0 to 375, changes the scale to that percentage (rounded to
the nearest 25% mark).[%], with no number just after it, resets scale to 100% (this usually has no effect here).[@Name], where Name is a key in family, changes the current Font used for rendering to the Font
in this.family by that name. This is ignored if family is null.[@], with no text just after it, resets the font to this one (which should be item 0 in family,
if family is non-null).[#HHHHHHHH], where HHHHHHHH is a hex RGB888 or RGBA8888 int color, changes the color.[COLORNAME], where "COLORNAME" is a typically-upper-case color name that will be looked up in
getColorLookup(), changes the color. The name can optionally be preceded by |, which allows
looking up colors with names that contain punctuation.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.
markupGlyph(char, String, ColorLookup) and giving it this
Font's colorLookup value.chr - a single char to apply markup tomarkup - a String containing only markup syntax, like "[*][_][RED]" for bold underline in redpublic static long markupGlyph(char chr,
java.lang.String markup,
ColorLookup colorLookup)
markup, processes it, and applies it to the given char chr; returns a long
in the format used for styled glyphs here. This parses an extension of libGDX markup and uses it to determine
color, size, position, shape, strikethrough, underline, case, and scale of the given char.
The char drawn will start in white, with the normal size as determined by the font's metrics and scale
(scaleX and scaleY), normal case, and without bold, italic, superscript, subscript,
strikethrough, or underline. Markup starts with [; the next character determines what that piece of
markup toggles. Markup this knows:
[] clears all markup to the initial state without any applied.[*] toggles bold mode.[/] toggles italic (technically, oblique) mode.[^] toggles superscript mode (and turns off subscript or midscript mode).[=] toggles midscript mode (and turns off superscript or subscript mode).[.] toggles subscript mode (and turns off superscript or midscript mode).[_] toggles underline mode.[~] toggles strikethrough mode.[!] toggles all upper case mode.[,] toggles all lower case mode.[;] toggles capitalize each word mode (this is the same as upper case mode here).[%P], where P is a percentage from 0 to 375, changes the scale to that percentage (rounded to
the nearest 25% mark).[%], with no number just after it, resets scale to 100% (this usually has no effect here).[@Name], where Name is a key in family, changes the current Font used for rendering to the Font
in this.family by that name. This is ignored if family is null.[@], with no text just after it, resets the font to this one (which should be item 0 in family,
if family is non-null).[#HHHHHHHH], where HHHHHHHH is a hex RGB888 or RGBA8888 int color, changes the color.[COLORNAME], where "COLORNAME" is a typically-upper-case color name that will be looked up in
getColorLookup(), changes the color. The name can optionally be preceded by |, which allows
looking up colors with names that contain punctuation.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.
ColorLookup.INSTANCE is often perfectly fine. Because this is static, it does
not need a Font to be involved.chr - a single char to apply markup tomarkup - a String containing only markup syntax, like "[*][_][RED]" for bold underline in redcolorLookup - a ColorLookup (often a method reference or ColorLookup.INSTANCE) to get
colors from textual names or descriptionspublic static long markupGlyph(char chr,
java.lang.String markup,
ColorLookup colorLookup,
Font.FontFamily family)
markup, processes it, and applies it to the given char chr; returns a long
in the format used for styled glyphs here. This parses an extension of libGDX markup and uses it to determine
color, size, position, shape, strikethrough, underline, case, and scale of the given char.
The char drawn will start in white, with the normal size as determined by the font's metrics and scale
(scaleX and scaleY), normal case, and without bold, italic, superscript, subscript,
strikethrough, or underline. Markup starts with [; the next character determines what that piece of
markup toggles. Markup this knows:
[] clears all markup to the initial state without any applied.[*] toggles bold mode.[/] toggles italic (technically, oblique) mode.[^] toggles superscript mode (and turns off subscript or midscript mode).[=] toggles midscript mode (and turns off superscript or subscript mode).[.] toggles subscript mode (and turns off superscript or midscript mode).[_] toggles underline mode.[~] toggles strikethrough mode.[!] toggles all upper case mode.[,] toggles all lower case mode.[;] toggles capitalize each word mode (this is the same as upper case mode here).[%P], where P is a percentage from 0 to 375, changes the scale to that percentage (rounded to
the nearest 25% mark).[%], with no number just after it, resets scale to 100% (this usually has no effect here).[@Name], where Name is a key in family, changes the current Font used for rendering to the Font
in this.family by that name. This is ignored if family is null.[@], with no text just after it, resets the font to this one (which should be item 0 in family,
if family is non-null).[#HHHHHHHH], where HHHHHHHH is a hex RGB888 or RGBA8888 int color, changes the color.[COLORNAME], where "COLORNAME" is a typically-upper-case color name that will be looked up in
getColorLookup(), changes the color. The name can optionally be preceded by |, which allows
looking up colors with names that contain punctuation.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.
ColorLookup.INSTANCE is often perfectly fine. Because this is static, it does
not need a Font to be involved.chr - a single char to apply markup tomarkup - a String containing only markup syntax, like "[*][_][RED]" for bold underline in redcolorLookup - a ColorLookup (often a method reference or ColorLookup.INSTANCE) to get
colors from textual names or descriptionspublic Font setFamily(Font.FontFamily family)
family - a Font.FontFamily that may be null or shared with other Fonts.public void resizeDistanceField(int width,
int height)
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.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)public static int extractColor(long glyph)
public static long applyColor(long glyph,
int color)
public static long extractStyle(long glyph)
BOLD, OBLIQUE, UNDERLINE, STRIKETHROUGH, SUBSCRIPT,
MIDSCRIPT, and SUPERSCRIPT.public static long applyStyle(long glyph,
long style)
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.public static float extractScale(long glyph)
public static long applyScale(long glyph,
float scale)
public static char extractChar(long glyph)
'['.public static long applyChar(long glyph,
char c)
public void dispose()
dispose in interface com.badlogic.gdx.utils.Disposablepublic java.lang.String toString()
toString in class java.lang.Object