Package com.github.tommyettinger.textra
Class Font
java.lang.Object
com.github.tommyettinger.textra.Font
- All Implemented Interfaces:
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
You can generate SDF fonts with Hiero or a related tool that is part of libGDX; MSDF fonts need a different tool, like maltaisn's msdf-gdx-gen (good for fonts with few chars) or fontwriter (recommended, but Windows-only). Using fontwriter means you get Structured JSON Font files instead of AngelCode BMFont files; these can be loaded with
This interacts with the
The
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
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.
A Font represents either one size of a "standard" bitmap font (which can be drawn scaled up or down), or many sizes of a distance field font (using either the commonly-used SDF format or newer MSDF format). The same class is used for standard, SDF, and MSDF fonts, but you call
enableShader(Batch)
before rendering with SDF or MSDF fonts, and
can switch back to a normal SpriteBatch shader with batch.setShader(null);
. The TextraLabel
and
TypingLabel
classes handle the calls to enableShader() for you. You don't have to use SDF or MSDF
fonts, but they can scale more cleanly. MSDF looks the sharpest in general, but SDF can display inline with emoji or
other colorful icons, without changing the shader. "Standard" fonts look the best when mixing different Fonts in one
piece of text, and also have the best compatibility with emoji and other icons. There's also the
Font.DistanceFieldType.SDF_OUTLINE
distance field mode, which you can change an SDF font to use; it draws fairly
sharply, but also adds a thick black outline around everything that uses SDF.
You can generate SDF fonts with Hiero or a related tool that is part of libGDX; MSDF fonts need a different tool, like maltaisn's msdf-gdx-gen (good for fonts with few chars) or fontwriter (recommended, but Windows-only). Using fontwriter means you get Structured JSON Font files instead of AngelCode BMFont files; these can be loaded with
Font(String, TextureRegion, float, float, float, float, boolean, boolean)
. Structured JSON Fonts can be SDF,
MSDF, standard (no distance field), or some other kinds of font; the information about this is stored in the font.
You can also load a libGDX BitmapFont with a Structured JSON Font using the BitmapFontSupport
class.
If you want a .fnt file instead for an MSDF font, msdf-gdx-gen does work, but has an uneven baseline if you put too
many chars in a font, or use too small of a texture size.
This interacts with the
Layout
class, with a Layout referencing a Font, and various methods in Font taking
a Layout. You usually want to have a Layout for any text you draw repeatedly, and draw that Layout each frame with
drawGlyphs(Batch, Layout, float, float, int)
or a similar method.
The
TypingLabel
class has its own markup that generally has an equivalent for all the markup options here.
This class has some special behavior for both the square-bracket markup used here and the curly-bracket markup used
by TypingLabel, even if the markup isn't actually used in a TypingLabel. In particular, anything in curly brackets is
ignored and left alone when markup() is called, and is not considered part of the size of the Layout. Anything inside
single curly braces is not rendered here, though it may be interpreted by TypingLabel if you use a Layout this
produces there. You should escape both square brackets with [[
and curly braces with {{
if
you intend them to appear. You can change the behavior of curly braces by setting omitCurlyBraces
to false;
this will make curly braces and their contents parse as normal text (the default setting is true). If curly braces
have a special meaning in some other markup you use, like I18N bundles, you can change a curly-brace tag such as
{RESET}
to [-RESET]
, with the -
at the start making it ignored by markup here but
usable to TypingLabel.
Most things this can draw can be drawn with a rotation, and usually an origin can be specified (where it makes sense). The rotation can't be configured from markup, but the widgets that understand this class, like
TextraLabel
and TypingLabel
, can have their rotation set using the standard scene2d.ui method
Actor.setRotation(float)
, and then they will request the correct rotation
from this class. This is different from Label
, which ignores rotation!
There are some features here that cannot be used purely from markup, such as per-character rotation and smooth scaling, but these can be used by TypingLabel and its Effect assortment.
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic enum
Defines what types of distance field font this can use and render.static class
Holds up to 16 Font values, accessible by index or by name, that markup can switch between while rendering.static class
Describes the region of a glyph in a larger TextureRegion, carrying a little more info about the offsets that apply to where the glyph is rendered. -
Field Summary
Modifier and TypeFieldDescriptionfloat
WhendistanceField
isFont.DistanceFieldType.SDF
,Font.DistanceFieldType.MSDF
, orFont.DistanceFieldType.SDF_OUTLINE
, this determines how much the edges of the glyphs should be aliased sharply (higher values) or anti-aliased softly (lower values).static final long
Bit flag for alternate mode, as a long.static final long
Bit flag for matching alternate modes, as a long.static final long
Bit flag for black outline mode, as a long.static final long
Bit flag for bold mode, as a long.float
A multiplier that applies to the distance bold text will stretch away from the original glyph outline.float
WhenmakeGridGlyphs
is passed as true to a constructor here, box drawing and other block elements will be drawn using a solid block GlyphRegion that is stretched and moved to form various lines and blocks.float
Refers to the largest height of any glyph in the font, after scaling.float
Only actually refers to a "cell" whenisMono
is true; otherwise refers to the largest width of any glyph in the font, after scaling.static final regexodus.Replacer
A RegExodus Replacer that replaces any CJK ideographic characters with themselves plus a zero-width space after.Determines how colors are looked up by name; defaults to usingColorUtils.describe(String)
.Which GlyphRegion to display if a char isn't found inmapping
.float
How far the unscaled font descends below the baseline, typically as a negative number (not always).protected Font.DistanceFieldType
float
WhendistanceField
isFont.DistanceFieldType.SDF
,Font.DistanceFieldType.MSDF
, orFont.DistanceFieldType.SDF_OUTLINE
, this determines how much the edges of the glyphs should be aliased sharply (higher values) or anti-aliased softly (lower values).static final long
Bit flag for drop shadow mode, as a long.boolean
If true (the default), square bracket markup functions as documented inmarkup(String, Layout)
.static final long
Bit flag for error mode, shown as a red wiggly-underline, as a long.If non-null, may contain connected Font values and names/aliases to look them up with using [@Name] syntax.float
Precise adjustment for the x-position of "fancy lines" such as error, warning, and note effects, affecting the left side of the line.float
Precise adjustment for the y-position of "fancy lines" such as error, warning, and note effects, affecting the bottom side of the line.float
The height-adjustment this Font was initialized with, or 0 if there was none given.float
An adjustment added to theFont.GlyphRegion.offsetX
of any inline images added withaddAtlas(TextureAtlas, String, String, float, float, float)
(or its overloads).float
An adjustment added to theFont.GlyphRegion.offsetY
of any inline images added withaddAtlas(TextureAtlas, String, String, float, float, float)
(or its overloads).float
An adjustment added to thexAdvance(com.github.tommyettinger.textra.Font, float, long)
of any inline images added withaddAtlas(TextureAtlas, String, String, float, float, float)
(or its overloads).boolean
By default, this doesn't do anything; subclasses can overridehandleIntegerPosition(float)
to try to do something different with it.boolean
If true, this is a fixed-width (monospace) font; if false, this is probably a variable-width font.static final long
Bit flag for "jostle" mode, as a long.com.badlogic.gdx.utils.IntFloatMap
Unlikely to be used externally, this is one way of storing the kerning information that some fonts have.com.badlogic.gdx.utils.IntMap<Font.GlyphRegion>
Maps char keys (stored as ints) to their correspondingFont.GlyphRegion
values.static final long
Bit flag for midscript mode, as a long.static final String
Fragment shader source meant for MSDF fonts.The name of the Font, for display purposes.Optional; maps the names of TextureRegions to the indices they use inmapping
, and usually assigned byaddAtlas(TextureAtlas)
.com.badlogic.gdx.utils.IntMap<String>
Optional; a reversed form ofnameLookup
that allows you to get the printable name for a given char code.static final long
Bit flag for note mode, shown as a blue wavy-underline, as a long.static final long
Bit flag for oblique mode, as a long.float
A multiplier that applies to the horizontal movement associated with oblique text (which is similar to italic).boolean
If true (the default), any text inside matching curly braces, plus the curly braces themselves, will be ignored during rendering and not displayed.float
Refers to the largest height of any glyph in the font, before any scaling.float
Only actually refers to a "cell" whenisMono
is true; otherwise refers to the largest width of any glyph in the font, before any scaling.float
A multiplier that applies to the distance the "blacken" and "whiten" outlines will stretch away from the original glyph edge.float
The color black, as a packed float using the default RGBA color space.float
The color to use forERROR
's underline, as a packed float using the default RGBA color space.float
The color to use forNOTE
's underline, as a packed float using the default RGBA color space.float
The color to use forDROP_SHADOW
, as a packed float using the default RGBA color space.float
The color to use forWARN
's underline, as a packed float using the default RGBA color space.float
The color white, as a packed float using the default RGBA color space.com.badlogic.gdx.utils.Array<com.badlogic.gdx.graphics.g2d.TextureRegion>
The larger TextureRegions thatFont.GlyphRegion
images are pulled from; these could be whole Textures or be drawn from a TextureAtlas that the font shares with other images.float
Scale multiplier for width.float
Scale multiplier for height.static final String
A modified version of the fragment shader for SDF fonts fromDistanceFieldFont
, this draws a moderately thick black outline around each glyph, with the outline respecting the transparency of the glyph (unlikeBLACK_OUTLINE
mode).static final String
A modified version of the fragment shader for SDF fonts fromDistanceFieldFont
, now supporting RGB colors other than white (but with limited support for partial transparency).com.badlogic.gdx.graphics.glutils.ShaderProgram
The ShaderProgram used to render this font, as used byenableShader(Batch)
.static final long
Bit flag for shiny mode, as a long.static final long
Bit flag for small caps mode, as a long.char
A char that will be used to draw solid blocks withdrawBlocks(Batch, int[][], float, float)
, and to draw box-drawing/block-element characters ifmakeGridGlyphs
is true in the constructor.float
Precise adjustment for the strikethrough's y-size, affecting how thick the strikethrough is from bottom to top.float
Precise adjustment for the strikethrough's x-size, affecting the extra strikethrough drawn to the right of the strikethrough.static final long
Bit flag for strikethrough mode, as a long.float
Precise adjustment for the strikethrough's x-position, affecting the left side of the strikethrough.float
Precise adjustment for the strikethrough's y-position, affecting the bottom side of the strikethrough.static final long
Bit flag for subscript mode, as a long.static final long
Two-bit flag for superscript mode, as a long.float
Precise adjustment for the underline's y-size, affecting how thick the underline is from bottom to top.float
Precise adjustment for the underline's x-size, affecting the extra underline drawn to the right of the underline.static final long
Bit flag for underline mode, as a long.float
Precise adjustment for the underline's x-position, affecting the left side of the underline.float
Precise adjustment for the underline's y-position, affecting the bottom side of the underline.static final String
The standard libGDX vertex shader source, which is also used by the SDF and MSDF shaders.static final long
Bit flag for warning mode, shown as a yellow barred-underline, as a long.static final long
Bit flag for white outline mode, as a long.com.badlogic.gdx.graphics.Texture
A white square Texture, typically 3x3, that can be used as a backup in case a Font doesn't have a solid block character available to it already (such as for many Fonts created from BitmapFonts).float
The width-adjustment this Font was initialized with, or 0 if there was none given.float
The x-adjustment this Font was initialized with, or 0 if there was none given.float
The y-adjustment this Font was initialized with, or 0 if there was none given. -
Constructor Summary
ConstructorDescriptionFont()
Constructs a Font from a newly-created default BitmapFont, as byBitmapFont()
, passing it toFont(BitmapFont, float, float, float, float)
.Font
(com.badlogic.gdx.files.FileHandle jsonHandle, com.badlogic.gdx.graphics.g2d.TextureRegion textureRegion, boolean ignoredStructuredJsonFlag) Creates a Font from a "Structured JSON" file produced by Chlumsky's msdf-atlas-gen tool, and uses it to assemble the manyFont.GlyphRegion
s this has for each glyph.Font
(com.badlogic.gdx.files.FileHandle jsonHandle, com.badlogic.gdx.graphics.g2d.TextureRegion textureRegion, float xAdjust, float yAdjust, float widthAdjust, float heightAdjust, boolean makeGridGlyphs, boolean ignoredStructuredJsonFlag) Creates a Font from a "Structured JSON" file produced by Chlumsky's msdf-atlas-gen tool, and uses it to assemble the manyFont.GlyphRegion
s this has for each glyph.Font
(com.badlogic.gdx.files.FileHandle fntHandle, com.badlogic.gdx.graphics.g2d.TextureRegion textureRegion, Font.DistanceFieldType distanceField, float xAdjust, float yAdjust, float widthAdjust, float heightAdjust, boolean makeGridGlyphs) Constructs a font based off of an AngelCode BMFont .fnt file and the given TextureRegion that holds all of its glyphs, with the specified distance field effect.Font
(com.badlogic.gdx.files.FileHandle fntHandle, com.badlogic.gdx.utils.Array<com.badlogic.gdx.graphics.g2d.TextureRegion> textureRegions, Font.DistanceFieldType distanceField, float xAdjust, float yAdjust, float widthAdjust, float heightAdjust, boolean makeGridGlyphs) Constructs a font based off of an AngelCode BMFont .fnt file, with the given TextureRegion Array and specified distance field effect.Font
(com.badlogic.gdx.files.FileHandle fntHandle, Font.DistanceFieldType distanceField, float xAdjust, float yAdjust, float widthAdjust, float heightAdjust, boolean makeGridGlyphs) Constructs a new Font by reading in a .fnt file from the given FileHandle and loading any images specified in that file.Font
(com.badlogic.gdx.graphics.g2d.BitmapFont bmFont) Constructs a new Font from the existing BitmapFont, using its same Textures and TextureRegions for glyphs, and without a distance field effect or any adjustments to position except for a y offset equal toBitmapFont.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.Copy constructor; does not copy the font'sshader
orcolorLookup
, if it has them (it uses the same reference for the new Font), but will fully copy everything else.Constructs a Font by reading in the given .fnt file and loading any images it specifies.Creates a Font from a "Structured JSON" file produced by Chlumsky's msdf-atlas-gen tool, and uses it to assemble the manyFont.GlyphRegion
s this has for each glyph.Constructs a new Font by reading in a .fnt file with the given name (an internal handle is tried first, then a local handle) and loading any images specified in that file.Font
(String jsonName, com.badlogic.gdx.graphics.g2d.TextureRegion textureRegion, boolean makeGridGlyphs, boolean ignoredStructuredJsonFlag) Creates a Font from a "Structured JSON" file produced by Chlumsky's msdf-atlas-gen tool, and uses it to assemble the manyFont.GlyphRegion
s this has for each glyph.Font
(String fntName, com.badlogic.gdx.graphics.g2d.TextureRegion textureRegion, float xAdjust, float yAdjust, float widthAdjust, float heightAdjust) Constructs a font using the given TextureRegion that holds all of its glyphs, with no distance field effect.Font
(String jsonName, com.badlogic.gdx.graphics.g2d.TextureRegion textureRegion, float xAdjust, float yAdjust, float widthAdjust, float heightAdjust, boolean makeGridGlyphs, boolean ignoredStructuredJsonFlag) Creates a Font from a "Structured JSON" file produced by Chlumsky's msdf-atlas-gen tool, and uses it to assemble the manyFont.GlyphRegion
s this has for each glyph.Font
(String fntName, com.badlogic.gdx.graphics.g2d.TextureRegion textureRegion, Font.DistanceFieldType distanceField, float xAdjust, float yAdjust, float widthAdjust, float heightAdjust) Constructs a font based off of an AngelCode BMFont .fnt file and the given TextureRegion that holds all of its glyphs, with the specified distance field effect.Font
(String fntName, com.badlogic.gdx.graphics.g2d.TextureRegion textureRegion, Font.DistanceFieldType distanceField, float xAdjust, float yAdjust, float widthAdjust, float heightAdjust, boolean makeGridGlyphs) Constructs a font based off of an AngelCode BMFont .fnt file and the given TextureRegion that holds all of its glyphs, with the specified distance field effect.Font
(String fntName, com.badlogic.gdx.utils.Array<com.badlogic.gdx.graphics.g2d.TextureRegion> textureRegions, float xAdjust, float yAdjust, float widthAdjust, float heightAdjust) Constructs a font based off of an AngelCode BMFont .fnt file and the given TextureRegion Array, with no distance field effect.Font
(String fntName, com.badlogic.gdx.utils.Array<com.badlogic.gdx.graphics.g2d.TextureRegion> textureRegions, Font.DistanceFieldType distanceField, float xAdjust, float yAdjust, float widthAdjust, float heightAdjust) Constructs a font based off of an AngelCode BMFont .fnt file, with the given TextureRegion Array and specified distance field effect.Font
(String fntName, com.badlogic.gdx.utils.Array<com.badlogic.gdx.graphics.g2d.TextureRegion> textureRegions, Font.DistanceFieldType distanceField, float xAdjust, float yAdjust, float widthAdjust, float heightAdjust, boolean makeGridGlyphs) Constructs a font based off of an AngelCode BMFont .fnt file, with the given TextureRegion Array and specified distance field effect.Font
(String fntName, Font.DistanceFieldType distanceField) Constructs a Font by reading in the given .fnt file and loading any images it specifies.Font
(String fntName, Font.DistanceFieldType distanceField, float xAdjust, float yAdjust, float widthAdjust, float heightAdjust) Constructs a new Font by reading in a .fnt file with the given name (an internal handle is tried first, then a local handle) and loading any images specified in that file.Font
(String fntName, Font.DistanceFieldType distanceField, float xAdjust, float yAdjust, float widthAdjust, float heightAdjust, boolean makeGridGlyphs) Constructs a new Font by reading in a .fnt file with the given name (an internal handle is tried first, then a local handle) and loading any images specified in that file.Constructs a Font by reading in the given .fnt file and the given Texture by filename.Constructs a new Font by reading in a SadConsole .font file with the given name (an internal handle is tried first, then a local handle) and loading any images specified in that file.Font
(String fntName, String textureName, float xAdjust, float yAdjust, float widthAdjust, float heightAdjust) Constructs a new Font by reading in a Texture from the given named path (internal is tried, then local), and no distance field effect.Font
(String fntName, String textureName, Font.DistanceFieldType distanceField) Constructs a Font by reading in the given .fnt file and the given Texture by filename.Font
(String fntName, String textureName, Font.DistanceFieldType distanceField, float xAdjust, float yAdjust, float widthAdjust, float heightAdjust) Constructs a new Font by reading in a Texture from the given named path (internal is tried, then local), and the specified distance field effect.Font
(String fntName, String textureName, Font.DistanceFieldType distanceField, float xAdjust, float yAdjust, float widthAdjust, float heightAdjust, boolean makeGridGlyphs) Constructs a new Font by reading in a Texture from the given named path (internal is tried, then local), and the specified distance field effect. -
Method Summary
Modifier and TypeMethodDescriptionaddAtlas
(com.badlogic.gdx.graphics.g2d.TextureAtlas atlas) Adds all items inatlas
to the private use area ofmapping
, and stores their names, so they can be looked up with[+saxophone]
syntax (which is often the same as the[+π·]
syntax).addAtlas
(com.badlogic.gdx.graphics.g2d.TextureAtlas atlas, float offsetXChange, float offsetYChange, float xAdvanceChange) Adds all items inatlas
to the private use area ofmapping
, and stores their names, so they can be looked up with[+saxophone]
syntax (which is often the same as the[+π·]
syntax).addAtlas
(com.badlogic.gdx.graphics.g2d.TextureAtlas atlas, String prepend, String append, float offsetXChange, float offsetYChange, float xAdvanceChange) Adds all items inatlas
to the private use area ofmapping
, and stores their names, so they can be looked up with[+saxophone]
syntax (which is often the same as the[+π·]
syntax).Makes this Font "learn" a new mapping from a char (typically an emoji in a String forcharacter
) to a TextureRegion.addImage
(String character, com.badlogic.gdx.graphics.g2d.TextureRegion region, float offsetX, float offsetY, float xAdvance) Makes this Font "learn" a new mapping from a char (typically an emoji in a String forcharacter
) to a TextureRegion, allowing any offsets on x or y to be specified as well as the amount of horizontal space the resulting GlyphRegion should use.adjustCellWidth
(float multiplier) Multiplies the width used by each glyph in a monospaced font bymultiplier
without changing the size of any characters.adjustLineHeight
(float multiplier) Multiplies the line height bymultiplier
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 withBOLD
,OBLIQUE
,UNDERLINE
,STRIKETHROUGH
,SUBSCRIPT
,MIDSCRIPT
, andSUPERSCRIPT
.int
atlasLookup
(String name) Gets the char that might be associated withname
in at Atlas added to this (seeaddAtlas(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'sLine.width
field.float
calculateXAdvances
(Line line, com.badlogic.gdx.utils.FloatArray advances) Not meant for general use; calculates the x-positions before every glyph inline
, including invisible ones.static void
ClearsTypingConfig.GLOBAL_VARS
and callsTypingConfig.initializeGlobalVars()
.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, float width, float height, float rotation) An internal method that draws blocks in a sequence specified by afloat[]
, with the block usuallysolidBlock
(but not always).protected void
drawBlockSequence
(com.badlogic.gdx.graphics.g2d.Batch batch, float[] sequence, com.badlogic.gdx.graphics.g2d.TextureRegion block, float color, float x, float y, float width, float height, float rotation, float breadth) An internal method that draws blocks in a sequence specified by afloat[]
, with the block usuallysolidBlock
(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 amode
, with the block alwayssolidBlock
.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, usingalign
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, usingalign
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, usingalign
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, usingalign
to determine how to position the text.int
drawMarkupText
(com.badlogic.gdx.graphics.g2d.Batch batch, String text, float x, float y) Draws the specified text at the given x,y position (in world space), parsing an extension of libGDX markup and using it to determine color, size, position, shape, strikethrough, underline, case, and scale of the given CharSequence.void
drawText
(com.badlogic.gdx.graphics.g2d.Batch batch, CharSequence text, float x, float y) Draws the specified text at the given x,y position (in world space) with a white foreground.void
drawText
(com.badlogic.gdx.graphics.g2d.Batch batch, CharSequence text, float x, float y, int color) Draws the specified text at the given x,y position (in world space) with the given foreground color.protected void
drawVertices
(com.badlogic.gdx.graphics.g2d.Batch batch, com.badlogic.gdx.graphics.Texture texture, float[] vertices) Given a 20-item float array (almost alwaysvertices
in this class) and a Texture to draw (part of), this draws some part of the Texture using the given Batch.void
enableShader
(com.badlogic.gdx.graphics.g2d.Batch batch) Must be called before drawing anything with an SDF or MSDF font; does not need to be called for other fonts unless you are mixing them with SDF/MSDF fonts or other shaders.static char
extractChar
(long glyph) Given a glyph as a long, this returns the char it displays.static int
extractColor
(long glyph) Given a glyph as a long, this returns the RGBA8888 color it uses.static long
extractMode
(long glyph) Given a glyph as a long, this returns the bit flags for the current mode, if alternate mode is enabled.static float
extractScale
(long glyph) Given a glyph as a long, this returns the float multiplier it uses for scale.static long
extractStyle
(long glyph) Given a glyph as a long, this returns the style bits it uses.fitCell
(float width, float height, boolean center) Fits all chars into cells width by height in size, and optionally centers them in their cells.float
float
WhenmakeGridGlyphs
is passed as true to a constructor here, box drawing and other block elements will be drawn using a solid block GlyphRegion that is stretched and moved to form various lines and blocks.Gets the ColorLookup this uses to look up colors by name.float
Gets the "crispness" multiplier for distance field fonts (SDF and MSDF).float
AFont.DistanceFieldType
that should beFont.DistanceFieldType.STANDARD
for most fonts, and can beFont.DistanceFieldType.SDF
,Font.DistanceFieldType.MSDF
, orFont.DistanceFieldType.SDF_OUTLINE
if you know you have a font made to be used with one of those rendering techniques.Gets the FontFamily this can use to switch fonts using [@Name] syntax.float
float
float
float
float
getName()
float
float
long
getStoredState
(String name, long fallback) Looks up the given name in the stored states and returns the associated formatting state, orfallback
if the name was not present.float
float
float
float
protected boolean
handleEllipsis
(Layout appendTo) protected float
handleIntegerPosition
(float p) Currently, this is only an extension point for code that wants to ensure integer positions; it does nothing on its own other than return its argument unchanged.static String
Inserts a zero-width space character (Unicode U+200B) after every CJK ideographic character in text.int
kerningPair
(char first, char second) Assembles two chars into a kerning pair that can be looked up as a key inkerning
.protected void
loadFNT
(com.badlogic.gdx.files.FileHandle fntHandle, float xAdjust, float yAdjust, float widthAdjust, float heightAdjust, boolean makeGridGlyphs) The gritty parsing code that pulls relevant info from an AngelCode BMFont .fnt file and uses it to assemble the manyFont.GlyphRegion
s this has for each glyph.protected void
loadJSON
(com.badlogic.gdx.files.FileHandle jsonHandle, com.badlogic.gdx.graphics.g2d.TextureRegion textureRegion, float xAdjust, float yAdjust, float widthAdjust, float heightAdjust, boolean makeGridGlyphs) The bulk of the loading code for Structured JSON fonts.protected void
The parsing code that pulls relevant info from a SadConsole .font configuration file and uses it to assemble the manyFont.GlyphRegion
s this has for each glyph.static long
markupGlyph
(char chr, String markup, ColorLookup colorLookup) Reads markup frommarkup
, processes it, and applies it to the given charchr
; returns a long in the format used for styled glyphs here.static long
markupGlyph
(char chr, String markup, ColorLookup colorLookup, Font.FontFamily family) Reads markup frommarkup
, processes it, and applies it to the given charchr
; returns a long in the format used for styled glyphs here.long
markupGlyph
(int chr, String markup) Reads markup frommarkup
, processes it, and applies it to the given charchr
; returns a long in the format used for styled glyphs here.long
markupGlyph
(String markup) Reads markup frommarkup
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.multiplyCrispness
(float multiplier) Takes the "crispness" multiplier for distance field fonts (SDF and MSDF) and multiplies it by another multiplier.void
pauseDistanceFieldShader
(com.badlogic.gdx.graphics.g2d.Batch batch) If a distance field font needs to have its distance field effect disabled temporarily (such as to draw an icon or emoji), you can call this just before you start drawing the non-distance-field images.regenerateLayout
(Layout changing) When thetargetWidth
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
removeStoredState
(String name) Removes the formatting state with the given name if it is present, or does nothing if the name is not present.void
resizeDistanceField
(float width, float height) Important; must be called inApplicationListener.resize(int, int)
on each SDF, MSDF, or SDF_OUTLINE font you have currently rendering! This allows the distance field to appear as correct and crisp-outlined as it should be; without this, the distance field will probably not look very sharp at all.void
resizeDistanceField
(float width, float height, com.badlogic.gdx.utils.viewport.Viewport viewport) Important; must be called inApplicationListener.resize(int, int)
on each SDF, MSDF, or SDF_OUTLINE font you have currently rendering! This allows the distance field to appear as correct and crisp-outlined as it should be; without this, the distance field will probably not look very sharp at all.void
resumeDistanceFieldShader
(com.badlogic.gdx.graphics.g2d.Batch batch) If a distance field font needs to be drawn with a different size, different crispness, or a different Texture altogether (such as to draw an icon or emoji), you can call this just before you start drawing distance field text with this Font.scale
(float both) Scales the font by the given multiplier, applying it both horizontally and vertically.scale
(float horizontal, float vertical) Scales the font by the given horizontal and vertical multipliers.scaleHeightTo
(float height) Scales the font so that it will have the given height, keeping the current aspect ratio.scaleTo
(float width, float height) Scales the font so that it will have the given width and height.setBoldStrength
(float boldStrength) setBoxDrawingBreadth
(float boxDrawingBreadth) WhenmakeGridGlyphs
is passed as true to a constructor here, box drawing and other block elements will be drawn using a solid block GlyphRegion that is stretched and moved to form various lines and blocks.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 aColorLookup
interface implementation.setCrispness
(float crispness) Sets the "crispness" multiplier for distance field fonts (SDF and MSDF).setDescent
(float descent) setDistanceField
(Font.DistanceFieldType distanceField) Sets this Font's distance field type; this should beFont.DistanceFieldType.STANDARD
for most fonts (meaning it is a normal bitmap font with no distance field effect), but specially-made fonts can useFont.DistanceFieldType.SDF
orFont.DistanceFieldType.MSDF
to get smoother scaling and/or sharper edges.setFamily
(Font.FontFamily family) Sets the FontFamily this can use to switch fonts using [@Name] syntax.setFancyLinePosition
(float x, float y) setInlineImageMetrics
(float offsetX, float offsetY, float xAdvance) Sets the adjustments added to the metric for inline images added withaddAtlas(TextureAtlas)
(or its overloads).setLineMetrics
(float x, float y, float length, float breadth) Sets both the underline and strikethrough metric adjustments with the same values, as if you called bothsetUnderlineMetrics(float, float, float, float)
andsetStrikethroughMetrics(float, float, float, float)
with identical parameters.setObliqueStrength
(float obliqueStrength) setOutlineStrength
(float outlineStrength) setStrikethroughMetrics
(float strikeX, float strikeY, float strikeLength, float strikeBreadth) setStrikethroughPosition
(float strikeX, float strikeY) CallssetTextureFilter(Texture.TextureFilter, Texture.TextureFilter)
withTexture.TextureFilter.Linear
for both min and mag filters.setTextureFilter
(com.badlogic.gdx.graphics.Texture.TextureFilter minFilter, com.badlogic.gdx.graphics.Texture.TextureFilter magFilter) Sets the texture filters on each Texture that holds a TextureRegion used by the font to the givenminFilter
andmagFilter
.setUnderlineMetrics
(float underX, float underY, float underLength, float underBreadth) setUnderlinePosition
(float underX, float underY) void
storeState
(String name, long formatted) Evaluatesmarkup
to get a formatting state and stores it for later usage with"[ name]"
syntax and the givenname
.void
storeState
(String name, String markup) Evaluatesmarkup
to get a formatting state and stores it for later usage with"[ name]"
syntax and the givenname
.toString()
useIntegerPositions
(boolean integer) A no-op unless this is a subclass that overrideshandleIntegerPosition(float)
.float
xAdvance
(long glyph) Gets the distance to advance the cursor after drawingglyph
, scaled byscaleX
as if drawing.static float
Gets the distance to advance the cursor after drawingglyph
, scaled byscale
as if drawing.
-
Field Details
-
mapping
Maps char keys (stored as ints) to their correspondingFont.GlyphRegion
values. You can add arbitrary images to this mapping if you create appropriate GlyphRegion values (as withGlyphRegion(TextureRegion, float, float, float, float)
), though they must map to a char. -
nameLookup
Optional; maps the names of TextureRegions to the indices they use inmapping
, and usually assigned byaddAtlas(TextureAtlas)
. The keys in this map are case-insensitive. -
namesByCharCode
Optional; a reversed form ofnameLookup
that allows you to get the printable name for a given char code. This is usually assigned byaddAtlas(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 ofKnownFonts.addEmoji(Font)
, this means the printable names are all emoji. -
defaultValue
Which GlyphRegion to display if a char isn't found inmapping
. May be null to show a space by default. -
parents
public com.badlogic.gdx.utils.Array<com.badlogic.gdx.graphics.g2d.TextureRegion> parentsThe larger TextureRegions thatFont.GlyphRegion
images are pulled from; these could be whole Textures or be drawn from a TextureAtlas that the font shares with other images. -
distanceField
-
isMono
public boolean isMonoIf 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 kerningUnlikely 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 actualCrispnessWhendistanceField
isFont.DistanceFieldType.SDF
,Font.DistanceFieldType.MSDF
, orFont.DistanceFieldType.SDF_OUTLINE
, this determines how much the edges of the glyphs should be aliased sharply (higher values) or anti-aliased softly (lower values). The default value is 1. This is set internally byresizeDistanceField(float, float)
usingdistanceFieldCrispness
as a multiplier; when you want to have a change to crispness persist, use that other field. -
distanceFieldCrispness
public float distanceFieldCrispnessWhendistanceField
isFont.DistanceFieldType.SDF
,Font.DistanceFieldType.MSDF
, orFont.DistanceFieldType.SDF_OUTLINE
, this determines how much the edges of the glyphs should be aliased sharply (higher values) or anti-aliased softly (lower values). The default value is 1. This is used as a persistent multiplier that can be configured per-font, whereasactualCrispness
is the working value that changes often but is influenced by this one. This variable is used byresizeDistanceField(float, float)
to affect the working crispness value. -
cellWidth
public float cellWidthOnly actually refers to a "cell" whenisMono
is true; otherwise refers to the largest width of any glyph in the font, after scaling. -
cellHeight
public float cellHeightRefers to the largest height of any glyph in the font, after scaling. -
originalCellWidth
public float originalCellWidthOnly actually refers to a "cell" whenisMono
is true; otherwise refers to the largest width of any glyph in the font, before any scaling. -
originalCellHeight
public float originalCellHeightRefers to the largest height of any glyph in the font, before any scaling. -
scaleX
public float scaleXScale multiplier for width. -
scaleY
public float scaleYScale multiplier for height. -
descent
public float descentHow far the unscaled font descends below the baseline, typically as a negative number (not always). -
solidBlock
public char solidBlockA char that will be used to draw solid blocks withdrawBlocks(Batch, int[][], float, float)
, and to draw box-drawing/block-element characters ifmakeGridGlyphs
is true in the constructor. The glyph that corresponds to this char should be a 1x1 pixel block of solid white pixels in most cases. Because there is already a solid block in Unicode, this defaults to that Unicode glyph, at u2588 . There is also a test in TextraTypist, BlockStamper, that can place a tiny solid block in the lower-right corner and use that for this purpose. You can check if a .fnt file has a solid block present by searching forchar id=9608
(9608 is the decimal way to write 0x2588). -
family
If non-null, may contain connected Font values and names/aliases to look them up with using [@Name] syntax. -
colorLookup
Determines how colors are looked up by name; defaults to usingColorUtils.describe(String)
. -
integerPosition
public boolean integerPositionBy default, this doesn't do anything; subclasses can overridehandleIntegerPosition(float)
to try to do something different with it. BitmapFont in libGDX defaults to having integer positions enabled, and there they actually do something (lock the font positions to integer world units). When world units aren't equivalent to on-screen pixels, BitmapFont's behavior leads to severe glitches in font appearance, so usually we aren't missing much by not using this behavior. -
obliqueStrength
public float obliqueStrengthA 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 boldStrengthA multiplier that applies to the distance bold text will stretch away from the original glyph outline. The bold effect is achieved here by drawing the same GlyphRegion multiple times, separated to the left and right by a small distance. By reducing boldStrength to between 0.0 and 1.0, you can reduce the weight of bold text, but increasing boldStrength does not usually work well. -
outlineStrength
public float outlineStrengthA multiplier that applies to the distance the "blacken" and "whiten" outlines will stretch away from the original glyph edge. The outline effects are achieved here by drawing the same GlyphRegion multiple times, in a grid of duplicate draws each a small distance apart. By reducing outlineStrength to between 0.0 and 1.0, you can reduce the thickness of outlines at large font sizes, or by increasing outlineStrength above 1.0, you can make the outlines more visible with smaller font sizes. -
boxDrawingBreadth
public float boxDrawingBreadthWhenmakeGridGlyphs
is passed as true to a constructor here, box drawing and other block elements will be drawn using a solid block GlyphRegion that is stretched and moved to form various lines and blocks. Setting this field to something other than 1 affects how wide the lines are for box drawing characters only; this is acts as a multiplier on the original width of a line. Normal box drawing lines such as those inβ
are 0.1f of a cell across. Thick lines such as those inβ
are 0.2f of a cell across. Double lines such as those inβ
are two normal lines, 0.1f of a cell apart; double lines are not affected by this field. -
name
The name of the Font, for display purposes. This is not necessarily the same as the name of the font used in any particularFont.FontFamily
. -
whiteBlock
public com.badlogic.gdx.graphics.Texture whiteBlockA 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 BOLDBit flag for bold mode, as a long.- See Also:
-
OBLIQUE
public static final long OBLIQUEBit flag for oblique mode, as a long.- See Also:
-
UNDERLINE
public static final long UNDERLINEBit flag for underline mode, as a long.- See Also:
-
STRIKETHROUGH
public static final long STRIKETHROUGHBit flag for strikethrough mode, as a long.- See Also:
-
SUBSCRIPT
public static final long SUBSCRIPTBit flag for subscript mode, as a long.- See Also:
-
MIDSCRIPT
public static final long MIDSCRIPTBit flag for midscript mode, as a long.- See Also:
-
SUPERSCRIPT
public static final long SUPERSCRIPTTwo-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 ofSUBSCRIPT
,MIDSCRIPT
, or SUPERSCRIPT are enabled.- See Also:
-
ALTERNATE
public static final long ALTERNATEBit flag for alternate mode, as a long. The behavior of the scale bits changes if alternate mode is enabled.- See Also:
-
ALTERNATE_MODES_MASK
public static final long ALTERNATE_MODES_MASKBit 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 matchSMALL_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 requiresSMALL_CAPS
to be disabled and, when a glyph is masked with this field, that mask to be exactly equal toALTERNATE
. In other words, that is a case where the alternate bit flag is enabled, but all the bits that normally affect it are disabled.- See Also:
-
SMALL_CAPS
public static final long SMALL_CAPSBit 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. IfALTERNATE
is set, and bits 20 (small caps), 21, 22, and 23 are all not set, then a special mode is enabled,JOSTLE
, which moves affected characters around in a stationary random pattern.- See Also:
-
JOSTLE
public static final long JOSTLEBit 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 andSMALL_CAPS
is disabled. This cannot be used at the same time as scaling, and cannot overlap with other alternate modes. This requiresALTERNATE
to be set, but bits 20 (small caps), 21, 22, and 23 to all be not set.- See Also:
-
BLACK_OUTLINE
public static final long BLACK_OUTLINEBit flag for black outline mode, as a long. This only has its intended effect if alternate mode is enabled. This can overlap withSMALL_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 changingPACKED_BLACK
.- See Also:
-
WHITE_OUTLINE
public static final long WHITE_OUTLINEBit 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, likeKnownFonts.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 withSMALL_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 changingPACKED_WHITE
.- See Also:
-
DROP_SHADOW
public static final long DROP_SHADOWBit flag for drop shadow mode, as a long. This only has its intended effect if alternate mode is enabled. This can overlap withSMALL_CAPS
, but cannot be used at the same time as scaling.- See Also:
-
SHINY
public static final long SHINYBit flag for shiny mode, as a long. This only has its intended effect if alternate mode is enabled. This can overlap withSMALL_CAPS
, but cannot be used at the same time as scaling.- See Also:
-
ERROR
public static final long ERRORBit 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 withSMALL_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 changingPACKED_ERROR_COLOR
.- See Also:
-
WARN
public static final long WARNBit 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 withSMALL_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 changingPACKED_WARN_COLOR
.- See Also:
-
NOTE
public static final long NOTEBit 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 withSMALL_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 changingPACKED_NOTE_COLOR
.- See Also:
-
PACKED_BLACK
public float PACKED_BLACKThe color black, as a packed float using the default RGBA color space. This can be edited for Fonts that either use a different color space, or want to use a different color in place of black for effects likeBLACK_OUTLINE
. -
PACKED_WHITE
public float PACKED_WHITEThe color white, as a packed float using the default RGBA color space. This can be edited for Fonts that either use a different color space, or want to use a different color in place of white for effects likeWHITE_OUTLINE
andSHINY
. -
PACKED_ERROR_COLOR
public float PACKED_ERROR_COLORThe color to use forERROR
's underline, as a packed float using the default RGBA color space. Defaults to red. This can be edited for Fonts that either use a different color space, or want to use a different color in place of red forERROR
. In RGBA8888 format, this is the color0xFF0000FF
. You can generate packed float colors usingColor.toFloatBits()
orNumberUtils.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_COLORThe color to use forWARN
's underline, as a packed float using the default RGBA color space. Defaults to yellow or gold. This can be edited for Fonts that either use a different color space, or want to use a different color in place of yellow forWARN
. In RGBA8888 format, this is the color0xFFD510FF
. You can generate packed float colors usingColor.toFloatBits()
orNumberUtils.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_COLORThe color to use forNOTE
's underline, as a packed float using the default RGBA color space. Defaults to blue. This can be edited for Fonts that either use a different color space, or want to use a different color in place of blue forNOTE
. In RGBA8888 format, this is the color0x3088B8FF
. You can generate packed float colors usingColor.toFloatBits()
orNumberUtils.intToFloatColor(int)
, among other methods. Make sure that the order the method expects RGBA channels is what you provide. -
PACKED_SHADOW_COLOR
public float PACKED_SHADOW_COLORThe color to use forDROP_SHADOW
, as a packed float using the default RGBA color space. Defaults to 13% lightness, 50% alpha gray. This can be edited for Fonts that either use a different color space, or want to use a different color in place of half-transparent dark gray forDROP_SHADOW
. In RGBA8888 format, this is the color0x2121217E
. You can generate packed float colors usingColor.toFloatBits()
orNumberUtils.intToFloatColor(int)
, among other methods. Make sure that the order the method expects RGBA channels is what you provide. -
xAdjust
public float xAdjustThe 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 yAdjustThe 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 widthAdjustThe 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 heightAdjustThe 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 underXPrecise 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 increasingunderLength
by a similar amount.
This is a "Zen" metric, which means it is measured in fractions ofcellWidth
orcellHeight
(as appropriate), and only affects one value. -
underY
public float underYPrecise 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 ofcellWidth
orcellHeight
(as appropriate), and only affects one value. -
underLength
public float underLengthPrecise 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, decreasingunderX
should be accompanied by increasing underLength by a similar amount.
This is a "Zen" metric, which means it is measured in fractions ofcellWidth
orcellHeight
(as appropriate), and only affects one value. -
underBreadth
public float underBreadthPrecise 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 ofcellWidth
orcellHeight
(as appropriate), and only affects one value. -
strikeX
public float strikeXPrecise 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 increasingstrikeLength
by a similar amount.
This is a "Zen" metric, which means it is measured in fractions ofcellWidth
orcellHeight
(as appropriate), and only affects one value. -
strikeY
public float strikeYPrecise 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 ofcellWidth
orcellHeight
(as appropriate), and only affects one value. -
strikeLength
public float strikeLengthPrecise 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, decreasingstrikeX
should be accompanied by increasing strikeLength by a similar amount.
This is a "Zen" metric, which means it is measured in fractions ofcellWidth
orcellHeight
(as appropriate), and only affects one value. -
strikeBreadth
public float strikeBreadthPrecise 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 ofcellWidth
orcellHeight
(as appropriate), and only affects one value. -
fancyX
public float fancyXPrecise adjustment for the x-position of "fancy lines" such as error, warning, and note effects, affecting the left side of the line.
This is a "Zen" metric, which means it is measured in fractions ofcellWidth
orcellHeight
(as appropriate), and only affects one value. -
fancyY
public float fancyYPrecise adjustment for the y-position of "fancy lines" such as error, warning, and note effects, affecting the bottom side of the line.
This is a "Zen" metric, which means it is measured in fractions ofcellWidth
orcellHeight
(as appropriate), and only affects one value. -
inlineImageOffsetX
public float inlineImageOffsetXAn adjustment added to theFont.GlyphRegion.offsetX
of any inline images added withaddAtlas(TextureAtlas, String, String, float, float, float)
(or its overloads). This is meant as a guess for how square inline images, such asemoji
, 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 theaddAtlas(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 inlineImageOffsetYAn adjustment added to theFont.GlyphRegion.offsetY
of any inline images added withaddAtlas(TextureAtlas, String, String, float, float, float)
(or its overloads). This is meant as a guess for how square inline images, such asemoji
, 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 theaddAtlas(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 inlineImageXAdvanceAn adjustment added to thexAdvance(com.github.tommyettinger.textra.Font, float, long)
of any inline images added withaddAtlas(TextureAtlas, String, String, float, float, float)
(or its overloads). This is meant as a guess for how square inline images, such asemoji
, 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 theaddAtlas(TextureAtlas, float, float, float)
overload that allows adding additional adjustments if one atlas isn't quite right.
Changing xAdvanceChange with a positive value will shrink all GlyphRegions (this is probably unexpected). -
omitCurlyBraces
public boolean omitCurlyBracesIf true (the default), any text inside matching curly braces, plus the curly braces themselves, will be ignored during rendering and not displayed. If false, curly braces and their contents are treated as normal text. Note that regardless of this setting, you can use the[-TAG]
syntax instead of{TAG}
to produce a tag that TypingLabel can read, even though Font itself wouldn't do anything with TAG there. -
enableSquareBrackets
public boolean enableSquareBracketsIf true (the default), square bracket markup functions as documented inmarkup(String, Layout)
. If false, square brackets and their contents are treated as normal text. -
CJK_SPACE_INSERTER
public static final regexodus.Replacer CJK_SPACE_INSERTERA RegExodus Replacer that replaces any CJK ideographic characters with themselves plus a zero-width space after. Meant to be used viainsertZeroWidthSpacesInCJK(CharSequence)
, but can be used on its own. -
vertexShader
The standard libGDX vertex shader source, which is also used by the SDF and MSDF shaders.- See Also:
-
sdfFragmentShader
A modified version of the fragment shader for SDF fonts fromDistanceFieldFont
, now supporting RGB colors other than white (but with limited support for partial transparency). This is automatically used whenenableShader(Batch)
is called and thedistanceField
isFont.DistanceFieldType.SDF
. This shader can be used with inline images, but won't behave 100% correctly if they use partial transparency, such as to anti-alias edges.- See Also:
-
sdfBlackOutlineFragmentShader
A modified version of the fragment shader for SDF fonts fromDistanceFieldFont
, this draws a moderately thick black outline around each glyph, with the outline respecting the transparency of the glyph (unlikeBLACK_OUTLINE
mode). This also supports RGB colors other than white (but with limited support for partial transparency). This is automatically used whenenableShader(Batch)
is called and thedistanceField
isFont.DistanceFieldType.SDF_OUTLINE
. This shader can be used with inline images, but won't behave 100% correctly if they use partial transparency, such as to anti-alias edges.- See Also:
-
msdfFragmentShader
Fragment shader source meant for MSDF fonts. This is automatically used whenenableShader(Batch)
is called and thedistanceField
isFont.DistanceFieldType.MSDF
. This shader will almost always fail to work correctly with inline images.
This is mostly derived from msdf-gdx, which is Apache 2.0-licensed.- See Also:
-
shader
public com.badlogic.gdx.graphics.glutils.ShaderProgram shaderThe ShaderProgram used to render this font, as used byenableShader(Batch)
. If this is null, the font will be rendered with the Batch's default shader. It may be set to a custom ShaderProgram ifdistanceField
is set toFont.DistanceFieldType.MSDF
orFont.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 auniform float u_smoothing;
that will be set byenableShader(Batch)
. Values passed to u_smoothing can vary a lot, depending on how the font was initially created, its current scale, and itsactualCrispness
field. You can also use a user-defined ShaderProgram with a font usingFont.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 byBitmapFont()
, passing it toFont(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 inKnownFonts
by using the[%?shadow]
mode, so you don't typically need or want the shadow to be applied to the font beforehand. -
Font
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
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 loaddistanceField
- determines how edges are drawn; if unsure, you should useFont.DistanceFieldType.STANDARD
-
Font
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
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 loaddistanceField
- determines how edges are drawn; if unsure, you should useFont.DistanceFieldType.STANDARD
-
Font
Copy constructor; does not copy the font'sshader
orcolorLookup
, 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
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 normaloriginalCellWidth
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 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 above
-
Font
public Font(String fntName, Font.DistanceFieldType distanceField, float xAdjust, float yAdjust, float widthAdjust, float heightAdjust) Constructs a new Font by reading in a .fnt file with the given name (an internal handle is tried first, then a local handle) and loading any images specified in that file. The specified distance field effect is used. This allows globally adjusting the x and y positions of glyphs in the font, as well as globally adjusting the horizontal and vertical space glyphs take up. Changing these adjustments by small values can drastically improve the appearance of text, but has to be manually edited; every font is quite different. If you want to add empty space around each character, you can add approximately the normaloriginalCellWidth
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 localdistanceField
- determines how edges are drawn; if unsure, you should useFont.DistanceFieldType.STANDARD
xAdjust
- 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 above
-
Font
public Font(String fntName, Font.DistanceFieldType distanceField, float xAdjust, float yAdjust, float widthAdjust, float heightAdjust, boolean makeGridGlyphs) Constructs a new Font by reading in a .fnt file with the given name (an internal handle is tried first, then a local handle) and loading any images specified in that file. The specified distance field effect is used. This allows globally adjusting the x and y positions of glyphs in the font, as well as globally adjusting the horizontal and vertical space glyphs take up. Changing these adjustments by small values can drastically improve the appearance of text, but has to be manually edited; every font is quite different. If you want to add empty space around each character, you can add approximately the normaloriginalCellWidth
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 localdistanceField
- determines how edges are drawn; if unsure, you should useFont.DistanceFieldType.STANDARD
xAdjust
- 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 file
-
Font
public Font(com.badlogic.gdx.files.FileHandle fntHandle, Font.DistanceFieldType distanceField, float xAdjust, float yAdjust, float widthAdjust, float heightAdjust, boolean makeGridGlyphs) Constructs a new Font by reading in a .fnt file from the given FileHandle and loading any images specified in that file. The specified distance field effect is used. This allows globally adjusting the x and y positions of glyphs in the font, as well as globally adjusting the horizontal and vertical space glyphs take up. Changing these adjustments by small values can drastically improve the appearance of text, but has to be manually edited; every font is quite different. If you want to add empty space around each character, you can add approximately the normaloriginalCellWidth
to widthAdjust and about half that to xAdjust; this can be used to make the glyphs fit in square cells.- Parameters:
fntHandle
- the FileHandle holding the path to a .fnt filedistanceField
- determines how edges are drawn; if unsure, you should useFont.DistanceFieldType.STANDARD
xAdjust
- 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 file
-
Font
public Font(String fntName, String textureName, float xAdjust, float yAdjust, float widthAdjust, float heightAdjust) Constructs a new Font by reading in a Texture from the given named path (internal is tried, then local), and no distance field effect. This allows globally adjusting the x and y positions of glyphs in the font, as well as globally adjusting the horizontal and vertical space glyphs take up. Changing these adjustments by small values can drastically improve the appearance of text, but has to be manually edited; every font is quite different. If you want to add empty space around each character, you can add approximately the normaloriginalCellWidth
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 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 above
-
Font
public Font(String fntName, String textureName, Font.DistanceFieldType distanceField, float xAdjust, float yAdjust, float widthAdjust, float heightAdjust) Constructs a new Font by reading in a Texture from the given named path (internal is tried, then local), and the specified distance field effect. This allows globally adjusting the x and y positions of glyphs in the font, as well as globally adjusting the horizontal and vertical space glyphs take up. Changing these adjustments by small values can drastically improve the appearance of text, but has to be manually edited; every font is quite different. If you want to add empty space around each character, you can add approximately the normaloriginalCellWidth
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 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 useFont.DistanceFieldType.STANDARD
xAdjust
- 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 above
-
Font
public Font(String fntName, String textureName, Font.DistanceFieldType distanceField, float xAdjust, float yAdjust, float widthAdjust, float heightAdjust, boolean makeGridGlyphs) Constructs a new Font by reading in a Texture from the given named path (internal is tried, then local), and the specified distance field effect. This allows globally adjusting the x and y positions of glyphs in the font, as well as globally adjusting the horizontal and vertical space glyphs take up. Changing these adjustments by small values can drastically improve the appearance of text, but has to be manually edited; every font is quite different. If you want to add empty space around each character, you can add approximately the normaloriginalCellWidth
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 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 useFont.DistanceFieldType.STANDARD
xAdjust
- 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 file
-
Font
public Font(String fntName, com.badlogic.gdx.graphics.g2d.TextureRegion textureRegion, float xAdjust, float yAdjust, float widthAdjust, float heightAdjust) Constructs a font using the given TextureRegion that holds all of its glyphs, with no distance field effect. This allows globally adjusting the x and y positions of glyphs in the font, as well as globally adjusting the horizontal and vertical space glyphs take up. Changing these adjustments by small values can drastically improve the appearance of text, but has to be manually edited; every font is quite different. If you want to add empty space around each character, you can add approximately the normaloriginalCellWidth
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 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 above
-
Font
public Font(String fntName, com.badlogic.gdx.graphics.g2d.TextureRegion textureRegion, Font.DistanceFieldType distanceField, float xAdjust, float yAdjust, float widthAdjust, float heightAdjust) Constructs a font based off of an AngelCode BMFont .fnt file and the given TextureRegion that holds all of its glyphs, with the specified distance field effect. This allows globally adjusting the x and y positions of glyphs in the font, as well as globally adjusting the horizontal and vertical space glyphs take up. Changing these adjustments by small values can drastically improve the appearance of text, but has to be manually edited; every font is quite different. If you want to add empty space around each character, you can add approximately the normaloriginalCellWidth
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 localtextureRegion
- an existing TextureRegion, typically inside a larger TextureAtlasdistanceField
- determines how edges are drawn; if unsure, you should useFont.DistanceFieldType.STANDARD
xAdjust
- 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 above
-
Font
public Font(String fntName, com.badlogic.gdx.graphics.g2d.TextureRegion textureRegion, Font.DistanceFieldType distanceField, float xAdjust, float yAdjust, float widthAdjust, float heightAdjust, boolean makeGridGlyphs) Constructs a font based off of an AngelCode BMFont .fnt file and the given TextureRegion that holds all of its glyphs, with the specified distance field effect. This allows globally adjusting the x and y positions of glyphs in the font, as well as globally adjusting the horizontal and vertical space glyphs take up. Changing these adjustments by small values can drastically improve the appearance of text, but has to be manually edited; every font is quite different. If you want to add empty space around each character, you can add approximately the normaloriginalCellWidth
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 localtextureRegion
- an existing TextureRegion, typically inside a larger TextureAtlasdistanceField
- determines how edges are drawn; if unsure, you should useFont.DistanceFieldType.STANDARD
xAdjust
- 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 file
-
Font
public Font(com.badlogic.gdx.files.FileHandle fntHandle, com.badlogic.gdx.graphics.g2d.TextureRegion textureRegion, Font.DistanceFieldType distanceField, float xAdjust, float yAdjust, float widthAdjust, float heightAdjust, boolean makeGridGlyphs) Constructs a font based off of an AngelCode BMFont .fnt file and the given TextureRegion that holds all of its glyphs, with the specified distance field effect. This allows globally adjusting the x and y positions of glyphs in the font, as well as globally adjusting the horizontal and vertical space glyphs take up. Changing these adjustments by small values can drastically improve the appearance of text, but has to be manually edited; every font is quite different. If you want to add empty space around each character, you can add approximately the normaloriginalCellWidth
to widthAdjust and about half that to xAdjust; this can be used to make the glyphs fit in square cells.- Parameters:
fntHandle
- the FileHandle holding the path to a .fnt filetextureRegion
- an existing TextureRegion, typically inside a larger TextureAtlasdistanceField
- determines how edges are drawn; if unsure, you should useFont.DistanceFieldType.STANDARD
xAdjust
- 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 file
-
Font
public Font(String fntName, com.badlogic.gdx.utils.Array<com.badlogic.gdx.graphics.g2d.TextureRegion> textureRegions, float xAdjust, float yAdjust, float widthAdjust, float heightAdjust) Constructs a font based off of an AngelCode BMFont .fnt file and the given TextureRegion Array, with no distance field effect. This allows globally adjusting the x and y positions of glyphs in the font, as well as globally adjusting the horizontal and vertical space glyphs take up. Changing these adjustments by small values can drastically improve the appearance of text, but has to be manually edited; every font is quite different. If you want to add empty space around each character, you can add approximately the normaloriginalCellWidth
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 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 above
-
Font
public Font(String fntName, com.badlogic.gdx.utils.Array<com.badlogic.gdx.graphics.g2d.TextureRegion> textureRegions, Font.DistanceFieldType distanceField, float xAdjust, float yAdjust, float widthAdjust, float heightAdjust) Constructs a font based off of an AngelCode BMFont .fnt file, with the given TextureRegion Array and specified distance field effect. This allows globally adjusting the x and y positions of glyphs in the font, as well as globally adjusting the horizontal and vertical space glyphs take up. Changing these adjustments by small values can drastically improve the appearance of text, but has to be manually edited; every font is quite different. If you want to add empty space around each character, you can add approximately the normaloriginalCellWidth
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 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 useFont.DistanceFieldType.STANDARD
xAdjust
- 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 above
-
Font
public Font(String fntName, com.badlogic.gdx.utils.Array<com.badlogic.gdx.graphics.g2d.TextureRegion> textureRegions, Font.DistanceFieldType distanceField, float xAdjust, float yAdjust, float widthAdjust, float heightAdjust, boolean makeGridGlyphs) Constructs a font based off of an AngelCode BMFont .fnt file, with the given TextureRegion Array and specified distance field effect. This allows globally adjusting the x and y positions of glyphs in the font, as well as globally adjusting the horizontal and vertical space glyphs take up. Changing these adjustments by small values can drastically improve the appearance of text, but has to be manually edited; every font is quite different. If you want to add empty space around each character, you can add approximately the normaloriginalCellWidth
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 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 useFont.DistanceFieldType.STANDARD
xAdjust
- 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 file
-
Font
public Font(com.badlogic.gdx.files.FileHandle fntHandle, com.badlogic.gdx.utils.Array<com.badlogic.gdx.graphics.g2d.TextureRegion> textureRegions, Font.DistanceFieldType distanceField, float xAdjust, float yAdjust, float widthAdjust, float heightAdjust, boolean makeGridGlyphs) Constructs a font based off of an AngelCode BMFont .fnt file, with the given TextureRegion Array and specified distance field effect. This allows globally adjusting the x and y positions of glyphs in the font, as well as globally adjusting the horizontal and vertical space glyphs take up. Changing these adjustments by small values can drastically improve the appearance of text, but has to be manually edited; every font is quite different. If you want to add empty space around each character, you can add approximately the normaloriginalCellWidth
to widthAdjust and about half that to xAdjust; this can be used to make the glyphs fit in square cells.- Parameters:
fntHandle
- the FileHandle holding the path to a .fnt filetextureRegions
- 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 useFont.DistanceFieldType.STANDARD
xAdjust
- 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 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 toBitmapFont.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 toyAdjust
equal toBitmapFont.getDescent()
.- Parameters:
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 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 toyAdjust
equal toBitmapFont.getDescent()
.- Parameters:
bmFont
- an existing BitmapFont that will be copied in almost every way this candistanceField
- determines how edges are drawn; if unsure, you should useFont.DistanceFieldType.STANDARD
xAdjust
- 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 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 toyAdjust
equal toBitmapFont.getDescent()
.- Parameters:
bmFont
- an existing BitmapFont that will be copied in almost every way this candistanceField
- determines how edges are drawn; if unsure, you should useFont.DistanceFieldType.STANDARD
xAdjust
- 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 file
-
Font
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 localignoredSadConsoleFlag
- the value is ignored here; the presence of this parameter says to load a SadConsole .font file
-
Font
Creates a Font from a "Structured JSON" file produced by Chlumsky's msdf-atlas-gen tool, and uses it to assemble the manyFont.GlyphRegion
s this has for each glyph. Reads the distance field type from the JSON. This always tries to load a PNG file with the same filename as (and different extension from) the JSON file, trying an internal file path first, and a local file path if that fails. No matter what extension the JSON font uses, this will be able to load it (so this can load compressed .dat fonts as well as .json or .js). This always makes grid glyphs.
The msdf-atlas-gen tool can actually produce MSDF, SDF, PSDF, and "soft masked" (standard) fonts. It can't produce AngelCode BMFont .fnt files, but the JSON it can produce is fairly full-featured. Its handling of metrics seems significantly better than the tools that work with AngelCode BMFont .fnt files, so all the fonts inKnownFonts
use JSON. A specialized version of msdf-atlas-gen that only writes structured JSON files (and optimizes the files at the right size) is available at fontwriter (Windows-only, for now).- Parameters:
jsonName
- the name of a structured JSON font file this will load from an internal or local file handle (tried in that order)ignoredStructuredJsonFlag
- only present to distinguish this from other constructors; ignored
-
Font
public Font(String jsonName, com.badlogic.gdx.graphics.g2d.TextureRegion textureRegion, boolean makeGridGlyphs, boolean ignoredStructuredJsonFlag) Creates a Font from a "Structured JSON" file produced by Chlumsky's msdf-atlas-gen tool, and uses it to assemble the manyFont.GlyphRegion
s this has for each glyph. Reads the distance field type from the JSON.
The msdf-atlas-gen tool can actually produce MSDF, SDF, PSDF, and "soft masked" (standard) fonts. It can't produce AngelCode BMFont .fnt files, but the JSON it can produce is fairly full-featured. Its handling of metrics seems significantly better than the tools that work with AngelCode BMFont .fnt files, so all the fonts inKnownFonts
use JSON. A specialized version of msdf-atlas-gen that only writes structured JSON files (and optimizes the files at the right size) is available at fontwriter (Windows-only, for now).- Parameters:
jsonName
- the name of a structured JSON font file this will load from an internal or local file handle (tried in that order)textureRegion
- a non-null TextureRegion, often taking up all of a Texture, that stores the images of the glyphsmakeGridGlyphs
- true if this should use its own way of rendering box-drawing/block-element glyphs, ignoring any in the font fileignoredStructuredJsonFlag
- only present to distinguish this from other constructors; ignored
-
Font
public Font(String jsonName, com.badlogic.gdx.graphics.g2d.TextureRegion textureRegion, float xAdjust, float yAdjust, float widthAdjust, float heightAdjust, boolean makeGridGlyphs, boolean ignoredStructuredJsonFlag) Creates a Font from a "Structured JSON" file produced by Chlumsky's msdf-atlas-gen tool, and uses it to assemble the manyFont.GlyphRegion
s this has for each glyph. Reads the distance field type from the JSON.
The msdf-atlas-gen tool can actually produce MSDF, SDF, PSDF, and "soft masked" (standard) fonts. It can't produce AngelCode BMFont .fnt files, but the JSON it can produce is fairly full-featured. Its handling of metrics seems significantly better than the tools that work with AngelCode BMFont .fnt files, so all the fonts inKnownFonts
use JSON. A specialized version of msdf-atlas-gen that only writes structured JSON files (and optimizes the files at the right size) is available at fontwriter (Windows-only, for now).- Parameters:
jsonName
- the name of a structured JSON font file this will load from an internal or local file handle (tried in that order)textureRegion
- a non-null TextureRegion, often taking up all of a Texture, that stores the images of the glyphsxAdjust
- 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 fileignoredStructuredJsonFlag
- only present to distinguish this from other constructors; ignored
-
Font
public Font(com.badlogic.gdx.files.FileHandle jsonHandle, com.badlogic.gdx.graphics.g2d.TextureRegion textureRegion, boolean ignoredStructuredJsonFlag) Creates a Font from a "Structured JSON" file produced by Chlumsky's msdf-atlas-gen tool, and uses it to assemble the manyFont.GlyphRegion
s this has for each glyph. Reads the distance field type from the JSON.
The msdf-atlas-gen tool can actually produce MSDF, SDF, PSDF, and "soft masked" (standard) fonts. It can't produce AngelCode BMFont .fnt files, but the JSON it can produce is fairly full-featured. Its handling of metrics seems significantly better than the tools that work with AngelCode BMFont .fnt files, so all the fonts inKnownFonts
use JSON. A specialized version of msdf-atlas-gen that only writes structured JSON files (and optimizes the files at the right size) is available at fontwriter (Windows-only, for now).- Parameters:
jsonHandle
- the FileHandle of a structured JSON font filetextureRegion
- a non-null TextureRegion, often taking up all of a Texture, that stores the images of the glyphsignoredStructuredJsonFlag
- only present to distinguish this from other constructors; ignored
-
Font
public Font(com.badlogic.gdx.files.FileHandle jsonHandle, com.badlogic.gdx.graphics.g2d.TextureRegion textureRegion, float xAdjust, float yAdjust, float widthAdjust, float heightAdjust, boolean makeGridGlyphs, boolean ignoredStructuredJsonFlag) Creates a Font from a "Structured JSON" file produced by Chlumsky's msdf-atlas-gen tool, and uses it to assemble the manyFont.GlyphRegion
s this has for each glyph. Reads the distance field type from the JSON.
The msdf-atlas-gen tool can actually produce MSDF, SDF, PSDF, and "soft masked" (standard) fonts. It can't produce AngelCode BMFont .fnt files, but the JSON it can produce is fairly full-featured. Its handling of metrics seems significantly better than the tools that work with AngelCode BMFont .fnt files, so all the fonts inKnownFonts
use JSON. A specialized version of msdf-atlas-gen that only writes structured JSON files (and optimizes the files at the right size) is available at fontwriter (Windows-only, for now).- Parameters:
jsonHandle
- the FileHandle of a structured JSON font filetextureRegion
- a non-null TextureRegion, often taking up all of a Texture, that stores the images of the glyphsxAdjust
- 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 fileignoredStructuredJsonFlag
- only present to distinguish this from other constructors; ignored
-
-
Method Details
-
insertZeroWidthSpacesInCJK
Inserts a zero-width space character (Unicode U+200B) after every CJK ideographic character in text. This is meant to create word breaks where there might otherwise be none, to allow breaking lines up how at least written Chinese expects them to be broken up. This assumes there won't be any ideograms in color markup or effects, and won't add zero-width spaces to Latin, Greek, Cyrillic, or other non-CJK languages.
The zero-width space character is automatically added to every Font that defines a normal space character (U+0020), and is literally a modified version of space that has zero width. This definition is allowed to overwrite an existing zero-width space character, but both should be invisible and have zero width (plus, not many fonts have a zero-width space without this modification).- Parameters:
text
- a CharSequence such as a String, typically containing CJK ideograms- Returns:
- a String where every CJK char has a zero-width space (U+200B) appended after it
-
getColorLookup
Gets the ColorLookup this uses to look up colors by name.- Returns:
- a ColorLookup implementation
-
setColorLookup
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 aColorLookup
interface implementation.- Parameters:
lookup
- a non-null ColorLookup- Returns:
- this, for chaining
-
loadFNT
protected void loadFNT(com.badlogic.gdx.files.FileHandle fntHandle, float xAdjust, float yAdjust, float widthAdjust, float heightAdjust, boolean makeGridGlyphs) The gritty parsing code that pulls relevant info from an AngelCode BMFont .fnt file and uses it to assemble the manyFont.GlyphRegion
s this has for each glyph.- Parameters:
fntHandle
- the FileHandle holding the path to a .fnt filexAdjust
- 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 file
-
loadSad
The parsing code that pulls relevant info from a SadConsole .font configuration file and uses it to assemble the manyFont.GlyphRegion
s this has for each glyph.- Parameters:
fntName
- the name of a font file this will load from an internal or local file handle (tried in that order)
-
loadJSON
protected void loadJSON(com.badlogic.gdx.files.FileHandle jsonHandle, com.badlogic.gdx.graphics.g2d.TextureRegion textureRegion, float xAdjust, float yAdjust, float widthAdjust, float heightAdjust, boolean makeGridGlyphs) The bulk of the loading code for Structured JSON fonts.- Parameters:
jsonHandle
- the FileHandle of a structured JSON font filetextureRegion
- a non-null TextureRegion, often taking up all of a Texture, that stores the images of the glyphsxAdjust
- 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 file
-
getDistanceField
AFont.DistanceFieldType
that should beFont.DistanceFieldType.STANDARD
for most fonts, and can beFont.DistanceFieldType.SDF
,Font.DistanceFieldType.MSDF
, orFont.DistanceFieldType.SDF_OUTLINE
if you know you have a font made to be used with one of those rendering techniques. SeedistanceFieldCrispness
for one way to configure SDF and MSDF fonts, andresizeDistanceField(float, float)
for an important method to handle window-resizing correctly. -
setDistanceField
Sets this Font's distance field type; this should beFont.DistanceFieldType.STANDARD
for most fonts (meaning it is a normal bitmap font with no distance field effect), but specially-made fonts can useFont.DistanceFieldType.SDF
orFont.DistanceFieldType.MSDF
to get smoother scaling and/or sharper edges. Fonts compatible with SDF can useFont.DistanceFieldType.SDF_OUTLINE
to show a black outline around all glyphs in the font.- Parameters:
distanceField
- a DistanceFieldType enum constant; if null, this will be treated asFont.DistanceFieldType.STANDARD
- Returns:
- this, for chaining
-
kerningPair
public int kerningPair(char first, char second) Assembles two chars into a kerning pair that can be looked up as a key inkerning
. 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 tokerning
'sIntFloatMap.get(int, float)
method, you'll get the amount of extra space (in the same unit the font uses) this will insert betweenfirst
andsecond
.- Parameters:
first
- the first charsecond
- the second char- Returns:
- a kerning pair that can be looked up in
kerning
-
scale
Scales the font by the given multiplier, applying it both horizontally and vertically.- Parameters:
both
- how much to multiply the width and height of each glyph by- Returns:
- this Font, for chaining
-
scale
Scales the font by the given horizontal and vertical multipliers.- Parameters:
horizontal
- how much to multiply the width of each glyph byvertical
- how much to multiply the height of each glyph by- Returns:
- this Font, for chaining
-
scaleTo
Scales the font so that it will have the given width and height.- Parameters:
width
- the target width of the font, in world unitsheight
- the target height of the font, in world units- Returns:
- this Font, for chaining
-
scaleHeightTo
Scales the font so that it will have the given height, keeping the current aspect ratio.- Parameters:
height
- the target height of the font, in world units- Returns:
- this Font, for chaining
-
adjustLineHeight
Multiplies the line height bymultiplier
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 tocellHeight
andoriginalCellHeight
- Returns:
- this Font, for chaining
-
adjustCellWidth
Multiplies the width used by each glyph in a monospaced font bymultiplier
without changing the size of any characters.- Parameters:
multiplier
- will be applied tocellWidth
andoriginalCellWidth
- Returns:
- this Font, for chaining
-
fitCell
Fits all chars into cells width by height in size, and optionally centers them in their cells. This setsisMono
to true, andkerning
to null. If you callscaleTo(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 unitsheight
- the target height of a cell, in world unitscenter
- if true, this will center every glyph in its cell- Returns:
- this Font, for chaining
-
getUnderlineX
public float getUnderlineX() -
getUnderlineY
public float getUnderlineY() -
setUnderlinePosition
-
setUnderlineMetrics
-
getStrikethroughX
public float getStrikethroughX() -
getStrikethroughY
public float getStrikethroughY() -
setStrikethroughPosition
-
setStrikethroughMetrics
public Font setStrikethroughMetrics(float strikeX, float strikeY, float strikeLength, float strikeBreadth) -
setLineMetrics
Sets both the underline and strikethrough metric adjustments with the same values, as if you called bothsetUnderlineMetrics(float, float, float, float)
andsetStrikethroughMetrics(float, float, float, float)
with identical parameters. This does not affect "fancy lines" (the zigzag lines produced by error, warning, and note effects).
This affects "Zen" metrics, which means it is measured in fractions ofcellWidth
orcellHeight
(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 liney
- adjustment for the underline and strikethrough y-position, affecting the bottom side of each linelength
- adjustment for the underline and strikethrough x-size, affecting the extra part drawn to the right of each linebreadth
- adjustment for the underline and strikethrough y-size, affecting how thick each line is from bottom to top- Returns:
- this, for chaining
-
getFancyLineX
public float getFancyLineX() -
getFancyLineY
public float getFancyLineY() -
setFancyLinePosition
Sets both the "fancy line" metric adjustments for position, only changingfancyX
andfancyY
. "Fancy lines" are the zigzag lines produced by error, warning, and note effects. This does not change the normal underline or the strikethrough styles.
This affects "Zen" metrics, which means it is measured in fractions ofcellWidth
orcellHeight
(as appropriate), and each metric only affects one value (even though this sets two metrics for each parameter).- Parameters:
x
- adjustment for the "fancy line" x-position, affecting the left side of each liney
- adjustment for the "fancy line" y-position, affecting the bottom side of each line- Returns:
- this, for chaining
-
getInlineImageOffsetX
public float getInlineImageOffsetX() -
getInlineImageOffsetY
public float getInlineImageOffsetY() -
getInlineImageXAdvance
public float getInlineImageXAdvance() -
setInlineImageMetrics
Sets the adjustments added to the metric for inline images added withaddAtlas(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 theFont.GlyphRegion.offsetX
of each added glyph; positive change moves a GlyphRegion to the rightoffsetY
- will be added to theFont.GlyphRegion.offsetY
of each added glyph; positive change moves a GlyphRegion downxAdvance
- will be added to thexAdvance(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
CallssetTextureFilter(Texture.TextureFilter, Texture.TextureFilter)
withTexture.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 forFont.DistanceFieldType.SDF
,Font.DistanceFieldType.MSDF
, andFont.DistanceFieldType.SDF_OUTLINE
fonts, but you may also want to use it forFont.DistanceFieldType.STANDARD
fonts when downscaling (they can look terrible if the defaultTexture.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 givenminFilter
andmagFilter
. You may want to use this to set a font usingFont.DistanceFieldType.STANDARD
to use a better TextureFilter for smooth downscaling, likeTexture.TextureFilter.MipMapLinearLinear
or justTexture.TextureFilter.Linear
. You might, for some reason, want to set a font usingFont.DistanceFieldType.SDF
,Font.DistanceFieldType.MSDF
, orFont.DistanceFieldType.SDF_OUTLINE
to use TextureFilters other than its defaultTexture.TextureFilter.Linear
. Note that this may affect the filter on other parts of an atlas.- Returns:
- this, for chaining
-
useIntegerPositions
A no-op unless this is a subclass that overrideshandleIntegerPosition(float)
.- Parameters:
integer
- usually ignored- Returns:
- this for chaining
-
getDescent
public float getDescent() -
setDescent
-
getName
-
setName
-
getObliqueStrength
public float getObliqueStrength() -
setObliqueStrength
-
getBoldStrength
public float getBoldStrength() -
setBoldStrength
-
getOutlineStrength
public float getOutlineStrength() -
setOutlineStrength
-
getBoxDrawingBreadth
public float getBoxDrawingBreadth()WhenmakeGridGlyphs
is passed as true to a constructor here, box drawing and other block elements will be drawn using a solid block GlyphRegion that is stretched and moved to form various lines and blocks. Setting this field to something other than 1 affects how wide the lines are for box drawing characters only; this is acts as a multiplier on the original width of a line. Normal box drawing lines such as those inβ
are 0.1f of a cell across. Thick lines such as those inβ
are 0.2f of a cell across. Double lines such as those inβ
are two normal lines, 0.1f of a cell apart; double lines are not affected by this field.- Returns:
- the current box drawing breadth multiplier, which defaults to 1
-
setBoxDrawingBreadth
WhenmakeGridGlyphs
is passed as true to a constructor here, box drawing and other block elements will be drawn using a solid block GlyphRegion that is stretched and moved to form various lines and blocks. Setting this field to something other than 1 affects how wide the lines are for box drawing characters only; this is acts as a multiplier on the original width of a line. Normal box drawing lines such as those inβ
are 0.1f of a cell across. Thick lines such as those inβ
are 0.2f of a cell across. Double lines such as those inβ
are two normal lines, 0.1f of a cell apart; double lines are not affected by this field.- Parameters:
boxDrawingBreadth
- the new float value to use for the box drawing breadth multiplier- Returns:
- this, for chaining
-
getFamily
Gets the FontFamily this can use to switch fonts using [@Name] syntax. If the family is null, only the current Font will be used.- Returns:
- the current FontFamily this Font uses, or null if this does not have one
-
setFamily
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
- aFont.FontFamily
that may be null or shared with other Fonts.- Returns:
- this, for chaining
-
getCrispness
public float getCrispness()Gets the "crispness" multiplier for distance field fonts (SDF and MSDF). There is no default value, because this depends on how an individual distance field font was created. Typical values range from 1.5 to 4.5 . Lower values look softer and fuzzier, while higher values look sharper and possibly more jagged. This is used as a persistent multiplier that can be configured per-font, whereasactualCrispness
is the working value that changes often but is influenced by this one. This variable is used byresizeDistanceField(float, float)
to affect the working crispness value.- Returns:
- the current crispness multiplier, as a float
-
setCrispness
Sets the "crispness" multiplier for distance field fonts (SDF and MSDF). There is no default value, because this depends on how an individual distance field font was created. Typical values range from 1.5 to 4.5 . Lower values look softer and fuzzier, while higher values look sharper and possibly more jagged. This is used as a persistent multiplier that can be configured per-font, whereasactualCrispness
is the working value that changes often but is influenced by this one. This variable is used byresizeDistanceField(float, float)
to affect the working crispness value. Changing the crispness does nothing unless you also resize the distance field, for each font you are rendering. So make sure to callresizeDistanceField(float, float)
in resize() !- Parameters:
crispness
- a float multiplier to be applied to the working crispness; often between 1.5 and 4.5- Returns:
- this Font, for chaining
-
multiplyCrispness
Takes the "crispness" multiplier for distance field fonts (SDF and MSDF) and multiplies it by another multiplier. There is no default value for crispness, because this depends on how an individual distance field font was created. Typical values range from 1.5 to 4.5 . Lower values look softer and fuzzier, while higher values look sharper and possibly more jagged. This affects a persistent multiplier that can be configured per-font, whereasactualCrispness
is the working value that changes often but is influenced by this one. The variable this affects is used byresizeDistanceField(float, float)
to affect the working crispness value. Changing the crispness does nothing unless you also resize the distance field, for each font you are rendering. So make sure to callresizeDistanceField(float, float)
in resize() !- Parameters:
multiplier
- a float multiplier to be applied to the working crispness multiplier- Returns:
- this Font, for chaining
-
addImage
public Font addImage(String character, com.badlogic.gdx.graphics.g2d.TextureRegion region, float offsetX, float offsetY, float xAdvance) Makes this Font "learn" a new mapping from a char (typically an emoji in a String forcharacter
) 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 Javachar
, we only use the last char incharacter
, 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 byKnownFonts.addEmoji(Font)
.- Parameters:
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 up- Returns:
- this Font, for chaining
-
addImage
Makes this Font "learn" a new mapping from a char (typically an emoji in a String forcharacter
) to a TextureRegion. The GlyphRegion that will be placed intomapping
will have 0 for its offsetX and offsetY, and its xAdvance will be the same as region'sTextureRegion.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 Javachar
, we only use the last char incharacter
, 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 byKnownFonts.addEmoji(Font)
.- Parameters:
character
- a String containing at least one character; only the last char (not codepoint) will be usedregion
- the TextureRegion to associate with the given character- Returns:
- this Font, for chaining
-
addAtlas
Adds all items inatlas
to the private use area ofmapping
, 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 useKnownFonts.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 inatlas
to the private use area ofmapping
, 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 useKnownFonts.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
, andinlineImageXAdvance
all are added in here.- Parameters:
atlas
- a TextureAtlas that shouldn't have more than 6144 names; all of it will be usedoffsetXChange
- will be added to theFont.GlyphRegion.offsetX
of each added glyph; positive change moves a GlyphRegion to the rightoffsetYChange
- will be added to theFont.GlyphRegion.offsetY
of each added glyph; positive change moves a GlyphRegion downxAdvanceChange
- will be added to thexAdvance(com.github.tommyettinger.textra.Font, float, long)
of each added glyph; positive change shrinks a GlyphRegion due to how size is calculated- Returns:
- this Font, for chaining
-
addAtlas
public Font addAtlas(com.badlogic.gdx.graphics.g2d.TextureAtlas atlas, String prepend, String append, float offsetXChange, float offsetYChange, float xAdvanceChange) Adds all items inatlas
to the private use area ofmapping
, 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 useKnownFonts.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
, andinlineImageXAdvance
all are added in here.- Parameters:
atlas
- a TextureAtlas that shouldn't have more than 6144 names; all of it will be usedprepend
- 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 theFont.GlyphRegion.offsetX
of each added glyph; positive change moves a GlyphRegion to the rightoffsetYChange
- will be added to theFont.GlyphRegion.offsetY
of each added glyph; positive change moves a GlyphRegion downxAdvanceChange
- will be added to thexAdvance(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
Gets the char that might be associated withname
in at Atlas added to this (seeaddAtlas(TextureAtlas)
, or returns the int -1 if the name could not be found. This will only return a negative result if the name was not found. This can be useful to look up complex names, such as emoji entered by a user, and get the char that can be used to render such an emoji. The name is treated as case-insensitive. If you are certain a name is present, you can cast the result immediately to a char to use it normally.- Parameters:
name
- a name from a TextureAtlas added to this Font, looked up as case-insensitive- Returns:
- the char that the given name is associated with, as an int in the char range if found, or -1 otherwise
-
enableShader
public void enableShader(com.badlogic.gdx.graphics.g2d.Batch batch) Must be called before drawing anything with an SDF or MSDF font; does not need to be called for other fonts unless you are mixing them with SDF/MSDF fonts or other shaders. This also resets the Batch color to white, in case it had been left with a different setting before. If this Font is not an SDF or MSDF font, then this resets batch's shader to the default (usingbatch.setShader(null)
).
This is called automatically forTextraLabel
andTypingLabel
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 withbatch.setShader(null);
.
Like all distance field code here, this is dependent on callingresizeDistanceField(float, float)
in yourApplicationListener.resize(int, int)
method, since that allows the distance field to be scaled correctly to the screen. Without calling resizeDistanceField(), distance field fonts will look terrible.- Parameters:
batch
- the Batch to instruct to use the appropriate shader for this font; should usually be a SpriteBatch
-
resumeDistanceFieldShader
public void resumeDistanceFieldShader(com.badlogic.gdx.graphics.g2d.Batch batch) If a distance field font needs to be drawn with a different size, different crispness, or a different Texture altogether (such as to draw an icon or emoji), you can call this just before you start drawing distance field text with this Font. You should only call this when you just changed something that affects how distance fields are drawn, which primarily meansactualCrispness
,cellHeight
,originalCellHeight
,cellWidth
, ororiginalCellWidth
, and also includes Texture changes to non-distance-field Textures. This should not be called immediately afterenableShader(Batch)
, since they do similar things. This does nothing if this font is not a distance field font. It also does nothing if batch's shader is different from the shader this Font uses. Otherwise, this flushes batch and sets a uniform ("u_smoothing") to a value calculated with the ratio of current cell size to original (unscaled) cell size.
Typically, if you callpauseDistanceFieldShader(Batch)
, you call this method later to resume drawing with a distance field. This is usually done automatically byTextraLabel
andTypingLabel
.
Like all distance field code here, this is dependent on callingresizeDistanceField(float, float)
in yourApplicationListener.resize(int, int)
method, since that allows the distance field to be scaled correctly to the screen. Without calling resizeDistanceField(), distance field fonts will look terrible.- Parameters:
batch
- a Batch that should be running (betweenBatch.begin()
andBatch.end()
)
-
pauseDistanceFieldShader
public void pauseDistanceFieldShader(com.badlogic.gdx.graphics.g2d.Batch batch) If a distance field font needs to have its distance field effect disabled temporarily (such as to draw an icon or emoji), you can call this just before you start drawing the non-distance-field images. You should only call this just before drawing from a non-distance-field Texture. This flushes batch and sets a uniform ("u_smoothing") to 0, unless that uniform was already 0 (then this doesn't flush, or do anything).
You can resume using the distance field by callingresumeDistanceFieldShader(Batch)
. This is usually done automatically byTextraLabel
andTypingLabel
.
Like all distance field code here, this is dependent on callingresizeDistanceField(float, float)
in yourApplicationListener.resize(int, int)
method, since that allows the distance field to be scaled correctly to the screen. Without calling resizeDistanceField(), distance field fonts will look terrible.- Parameters:
batch
- a Batch that should be running (betweenBatch.begin()
andBatch.end()
)
-
drawText
public void drawText(com.badlogic.gdx.graphics.g2d.Batch batch, CharSequence text, float x, float y) Draws the specified text at the given x,y position (in world space) with a white foreground.- Parameters:
batch
- typically a 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)
-
drawText
public void drawText(com.badlogic.gdx.graphics.g2d.Batch batch, CharSequence text, float x, float y, int color) Draws the specified text at the given x,y position (in world space) with the given foreground color.- Parameters:
batch
- typically a 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 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 atsolidBlock
, so you should have set that field; most fonts inKnownFonts
have a solid block char set already. Thecolors
parameter should be a rectangular 2D array, and because any colors that are the default int value0
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 usesdrawVertices(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 incolors
as itsa_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 useColorUtils.multiplyAllAlpha(int[][], float)
.- Parameters:
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)
-
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. TheblockChar
should visually be represented by a very large block, occupying all of a monospaced cell. Thecolors
parameter should be a rectangular 2D array, and because any colors that are the default int value0
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 usesdrawVertices(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 incolors
as itsa_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 useColorUtils.multiplyAllAlpha(int[][], float)
.- Parameters:
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)
-
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 afloat[]
, with the block usuallysolidBlock
(but not always). This is somewhat complicated; the sequence is typically drawn directly fromBlockUtils
. Drawsblock
at the given width and height, in the given packed color, rotating by the specified amount in degrees.- Parameters:
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; usuallysolidBlock
color
- 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 cell
-
drawBlockSequence
protected void drawBlockSequence(com.badlogic.gdx.graphics.g2d.Batch batch, float[] sequence, com.badlogic.gdx.graphics.g2d.TextureRegion block, float color, float x, float y, float width, float height, float rotation, float breadth) An internal method that draws blocks in a sequence specified by afloat[]
, with the block usuallysolidBlock
(but not always). This is somewhat complicated; the sequence is typically drawn directly fromBlockUtils
. Drawsblock
at the given width and height, in the given packed color, rotating by the specified amount in degrees. This overload also allows specifying a breadth multiplier for box drawing character lines, which can help match the aesthetic of a given font. The breadth multiplier only affects box drawing characters, but not any with double lines, nor does it affect block elements.- Parameters:
batch
- typically a 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; usuallysolidBlock
color
- 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 cellbreadth
- a multiplier applied only to the size of box-drawing characters going across the line(s); breadth changes are not performed if this is 1
-
drawFancyLine
protected void drawFancyLine(com.badlogic.gdx.graphics.g2d.Batch batch, long mode, float x, float y, float width, float xPx, float yPx, float rotation) An internal method that draws blocks in a sequence specified by amode
, with the block alwayssolidBlock
. Draws the solidBlock at a very small size (determined byxPx
andyPx
, 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 SpriteBatchmode
- currently must beERROR
,WARN
, orNOTE
, determining the patternx
- the x position to draw aty
- the y position to draw atwidth
- the width of one cell in world unitsxPx
- the width of one pixel, approximately, in world unitsyPx
- the height of one pixel, approximately, in world unitsrotation
- the rotation in degrees to use for the cell of blocks, with the origin in the center of the cell
-
drawMarkupText
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 bycellWidth
andcellHeight
, normal case, and without bold, italic, superscript, subscript, strikethrough, or underline. Markup starts with[
; the next non-letter character determines what that piece of markup toggles. Markup this knows:[]
undoes the most-recently-applied format change.[ ]
clears all markup to the initial state without any applied.[(label)]
temporarily stores the current formatting state aslabel
.[ label]
re-applies the formatting state stored aslabel
, if there is one.[[
escapes a literal left bracket, producing it without changing state.[+name]
, where name is the name of a TextureRegion from an atlas added to this Font withaddAtlas(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 withgetColorLookup()
, 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 callingmarkup(String, Layout)
and render its result withdrawGlyphs(Batch, Layout, float, float)
every frame.- Parameters:
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)- Returns:
- the number of glyphs drawn
-
drawGlyphs
Draws the specified Layout of glyphs with a Batch at a given x, y position, drawing the full layout.- Parameters:
batch
- typically a SpriteBatchglyphs
- typically returned as part ofmarkup(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, usingalign
to determine how to position the text. Typically, align isAlign.left
,Align.center
, orAlign.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 SpriteBatchglyphs
- typically returned bymarkup(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
- anAlign
constant; ifAlign.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, usingalign
to determine how to position the text. Typically, align isAlign.left
,Align.center
, orAlign.right
, but it can have a vertical component as well.- Parameters:
batch
- typically a SpriteBatchglyphs
- typically returned bymarkup(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
- anAlign
constant; ifAlign.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 around- Returns:
- the total distance in world units all drawn Lines use up from lines along the given rotation
-
drawGlyphs
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 SpriteBatchglyphs
- typically returned as part ofmarkup(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, usingalign
to determine how to position the text. Typically, align isAlign.left
,Align.center
, orAlign.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 SpriteBatchglyphs
- typically returned as part ofmarkup(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
- anAlign
constant; ifAlign.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, usingalign
to determine how to position the text. Typically, align isAlign.left
,Align.center
, orAlign.right
, but it can have a vertical component as well.- Parameters:
batch
- typically a SpriteBatchglyphs
- typically returned as part ofmarkup(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
- anAlign
constant; ifAlign.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 around- Returns:
- the distance in world units the drawn Line uses up out of a line along the given rotation
-
xAdvance
Gets the distance to advance the cursor after drawingglyph
, scaled byscale
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 measurescale
- the scale to draw the glyph at, usuallyscaleX
and possibly adjusted by per-glyph scalingglyph
- a long encoding the color, style information, and char of a glyph, as from aLine
- 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 drawingglyph
, scaled byscaleX
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 aLine
- Returns:
- the (possibly non-integer) amount to advance the cursor when you draw the given glyph, not counting kerning
-
measureWidth
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
Measures the actual width that the given Line will use when drawn, and sets it into the Line'sLine.width
field.- Parameters:
line
- a Line, as from inside a Layout- Returns:
- the width in world units
-
calculateSize
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 itsLayout.getWidth()
and/orLayout.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
Not meant for general use; calculates the x-positions before every glyph inline
, including invisible ones. Clearsadvances
and fills it with the never-decreasing position values.- Parameters:
line
- a Line to measure the contentsadvances
- will be cleared and refilled with the positions of each glyph in line- Returns:
- the x-position after the last glyph
-
handleIntegerPosition
protected float handleIntegerPosition(float p) Currently, this is only an extension point for code that wants to ensure integer positions; it does nothing on its own other than return its argument unchanged. SeeintegerPosition
for more.- Parameters:
p
- a float that could be rounded (it will not be unless this is overridden)- Returns:
- unless overridden, p without changes
-
drawGlyph
public float drawGlyph(com.badlogic.gdx.graphics.g2d.Batch batch, long glyph, float x, float y) Draws the specified glyph with a Batch at the given x, y position. The glyph contains multiple types of data all packed into onelong
: the bottom 16 bits store achar
, 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 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)- 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 onelong
: the bottom 16 bits store achar
, 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 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 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 onelong
: the bottom 16 bits store achar
, 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 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 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 onelong
: the bottom 16 bits store achar
, 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 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 metricsbackgroundColor
- 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
Reads markup from text, along with the chars to receive markup, processes it, and appends into appendTo, which is aLayout
holding one or moreLine
s. 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 inappendTo
'sLayout.baseColor
, which is usually white, with the normal size as determined by the font's metrics and scale (scaleX
andscaleY
), normal case, and without bold, italic, superscript, subscript, strikethrough, or underline. Markup starts with[
; the next character determines what that piece of markup toggles. Markup this knows:[]
undoes the most-recently-applied format change.[ ]
clears all markup to the initial state without any applied.[(label)]
temporarily stores the current formatting state aslabel
.[ label]
re-applies the formatting state stored aslabel
, if there is one.[[
escapes a literal left bracket, producing it without changing state.[+name]
, where name is the name of a TextureRegion from an atlas added to this Font withaddAtlas(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 ingetColorLookup()
, changes the color. By default this can receive ALL_CAPS names fromColors
in libGDX, any names fromPalette
, 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.
appendTo
usingdrawGlyphs(Batch, Layout, float, float)
.- Parameters:
text
- text, typically with square-bracket markupappendTo
- a Layout that stores one or more Line objects, carrying color, style, chars, and size- Returns:
- appendTo, for chaining
-
handleEllipsis
-
markupGlyph
Reads markup frommarkup
, processes it, and applies it to the given charchr
; 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
andscaleY
), normal case, and without bold, italic, superscript, subscript, strikethrough, or underline. Markup starts with[
; the next character determines what that piece of markup toggles. Markup this knows:[]
undoes the most-recently-applied format change.[ ]
clears all markup to the initial state without any applied.[*]
toggles bold mode.[/]
toggles italic (technically, oblique) mode.[^]
toggles superscript mode (and turns off subscript or midscript mode).[=]
toggles midscript mode (and turns off superscript or subscript mode).[.]
toggles subscript mode (and turns off superscript or midscript mode).[_]
toggles underline mode.[~]
toggles strikethrough mode.[!]
toggles all upper case mode.[,]
toggles all lower case mode.[;]
toggles capitalize each word mode (this is the same as upper case mode here).[%P]
, where P is a percentage from 0 to 375, changes the scale to that percentage (rounded to the nearest 25% mark). This also disables any alternate mode.[%?MODE]
, where MODE can be (case-insensitive) one of "black outline", "white outline", "shiny", "drop shadow"/"shadow", "error", "warn", "note", or "jostle", will disable scaling and enable that alternate mode. If MODE is empty or not recognized, this considers it equivalent to "jostle".[%^MODE]
, where MODE can be (case-insensitive) one of "black outline", "white outline", "shiny", "drop shadow"/"shadow", "error", "warn", "note", or "small caps", will disable scaling and enable that alternate mode along with small caps mode at the same time. If MODE is empty or not recognized, this considers it equivalent to "small caps" (without another mode).[%]
, with no number just after it, resets scale to 100% and disables any alternate mode.[@Name]
, where Name is a key in family, changes the current Font used for rendering to the Font in this.family by that name. This is ignored if family is null.[@]
, with no text just after it, resets the font to this one (which should be item 0 in family, if family is non-null).[#HHHHHHHH]
, where HHHHHHHH is a hex RGB888 or RGBA8888 int color, changes the color.[COLORNAME]
, where "COLORNAME" is a typically-upper-case color name that will be looked up ingetColorLookup()
, changes the color. The name can optionally be preceded by|
, which allows looking up colors with names that contain punctuation.
[+π¬]
syntax; you can useatlasLookup(String)
to get the internal character code that refers to an atlas glyph such as an emoji, or you can just usemarkupGlyph(String)
with that plus-sign syntax to enter the character.
You can render the result usingdrawGlyph(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 callingmarkupGlyph(String)
using a placeholder character (or none) and changing the returned glyph to usechr
usingapplyChar(long, char)
.- Parameters:
chr
- a single char to apply markup to; may also be a character code fromatlasLookup(String)
markup
- a String containing only markup syntax, like "[*][_][RED]" for bold underline in red- Returns:
- a long that encodes the given char with the specified markup
-
markupGlyph
Reads markup frommarkup
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 (seeaddAtlas(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
andscaleY
), normal case, and without bold, italic, superscript, subscript, strikethrough, or underline. Markup starts with[
; the next character determines what that piece of markup toggles. Markup this knows:[]
undoes the most-recently-applied format change.[ ]
clears all markup to the initial state without any applied.[*]
toggles bold mode.[/]
toggles italic (technically, oblique) mode.[^]
toggles superscript mode (and turns off subscript or midscript mode).[=]
toggles midscript mode (and turns off superscript or subscript mode).[.]
toggles subscript mode (and turns off superscript or midscript mode).[_]
toggles underline mode.[~]
toggles strikethrough mode.[!]
toggles all upper case mode.[,]
toggles all lower case mode.[;]
toggles capitalize each word mode (this is the same as upper case mode here).[%P]
, where P is a percentage from 0 to 375, changes the scale to that percentage (rounded to the nearest 25% mark). This also disables any alternate mode.[%?MODE]
, where MODE can be (case-insensitive) one of "black outline", "white outline", "shiny", "drop shadow"/"shadow", "error", "warn", "note", or "jostle", will disable scaling and enable that alternate mode. If MODE is empty or not recognized, this considers it equivalent to "jostle".[%^MODE]
, where MODE can be (case-insensitive) one of "black outline", "white outline", "shiny", "drop shadow"/"shadow", "error", "warn", "note", or "small caps", will disable scaling and enable that alternate mode along with small caps mode at the same time. If MODE is empty or not recognized, this considers it equivalent to "small caps" (without another mode).[%]
, with no number just after it, resets scale to 100% and disables any alternate mode.[@Name]
, where Name is a key in family, changes the current Font used for rendering to the Font in this.family by that name. This is ignored if family is null.[@]
, with no text just after the @, resets the font to this one (which should be item 0 in family, if family is non-null).[#HHHHHHHH]
, where HHHHHHHH is a hex RGB888 or RGBA8888 int color, changes the color.[COLORNAME]
, where "COLORNAME" is a typically-upper-case color name that will be looked up inColorLookup.DESCRIPTIVE
, 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.
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
Reads markup frommarkup
, processes it, and applies it to the given charchr
; 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
andscaleY
), normal case, and without bold, italic, superscript, subscript, strikethrough, or underline. Markup starts with[
; the next character determines what that piece of markup toggles. Markup this knows:[]
undoes the most-recently-applied format change.[ ]
clears all markup to the initial state without any applied.[*]
toggles bold mode.[/]
toggles italic (technically, oblique) mode.[^]
toggles superscript mode (and turns off subscript or midscript mode).[=]
toggles midscript mode (and turns off superscript or subscript mode).[.]
toggles subscript mode (and turns off superscript or midscript mode).[_]
toggles underline mode.[~]
toggles strikethrough mode.[!]
toggles all upper case mode.[,]
toggles all lower case mode.[;]
toggles capitalize each word mode (this is the same as upper case mode here).[%P]
, where P is a percentage from 0 to 375, changes the scale to that percentage (rounded to the nearest 25% mark). This also disables any alternate mode.[%?MODE]
, where MODE can be (case-insensitive) one of "black outline", "white outline", "shiny", "drop shadow"/"shadow", "error", "warn", "note", or "jostle", will disable scaling and enable that alternate mode. If MODE is empty or not recognized, this considers it equivalent to "jostle".[%^MODE]
, where MODE can be (case-insensitive) one of "black outline", "white outline", "shiny", "drop shadow"/"shadow", "error", "warn", "note", or "small caps", will disable scaling and enable that alternate mode along with small caps mode at the same time. If MODE is empty or not recognized, this considers it equivalent to "small caps" (without another mode).[%]
, with no number just after it, resets scale to 100% and disables any alternate mode.[@Name]
, where Name is a key in family, changes the current Font used for rendering to the Font in this.family by that name. This is ignored if family is null.[@]
, with no text just after it, resets the font to this one (which should be item 0 in family, if family is non-null).[#HHHHHHHH]
, where HHHHHHHH is a hex RGB888 or RGBA8888 int color, changes the color.[COLORNAME]
, where "COLORNAME" is a typically-upper-case color name that will be looked up ingetColorLookup()
, 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.
This takes a ColorLookup so that it can look up colors given a name or description; if you don't know what to use, thenColorLookup.DESCRIPTIVE
is the default elsewhere. Because this is static, it does not need a Font to be involved.- Parameters:
chr
- a single char to apply markup tomarkup
- a String containing only markup syntax, like "[*][_][RED]" for bold underline in redcolorLookup
- a ColorLookup (often a method reference orColorLookup.DESCRIPTIVE
) to get colors from textual names or descriptions- Returns:
- a long that encodes the given char with the specified markup
-
markupGlyph
public static long markupGlyph(char chr, String markup, ColorLookup colorLookup, Font.FontFamily family) Reads markup frommarkup
, processes it, and applies it to the given charchr
; 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
andscaleY
), normal case, and without bold, italic, superscript, subscript, strikethrough, or underline. Markup starts with[
; the next character determines what that piece of markup toggles. Markup this knows:[]
undoes the most-recently-applied format change.[ ]
clears all markup to the initial state without any applied.[*]
toggles bold mode.[/]
toggles italic (technically, oblique) mode.[^]
toggles superscript mode (and turns off subscript or midscript mode).[=]
toggles midscript mode (and turns off superscript or subscript mode).[.]
toggles subscript mode (and turns off superscript or midscript mode).[_]
toggles underline mode.[~]
toggles strikethrough mode.[!]
toggles all upper case mode.[,]
toggles all lower case mode.[;]
toggles capitalize each word mode (this is the same as upper case mode here).[%P]
, where P is a percentage from 0 to 375, changes the scale to that percentage (rounded to the nearest 25% mark). This also disables any alternate mode.[%?MODE]
, where MODE can be (case-insensitive) one of "black outline", "white outline", "shiny", "drop shadow"/"shadow", "error", "warn", "note", or "jostle", will disable scaling and enable that alternate mode. If MODE is empty or not recognized, this considers it equivalent to "jostle".[%^MODE]
, where MODE can be (case-insensitive) one of "black outline", "white outline", "shiny", "drop shadow"/"shadow", "error", "warn", "note", or "small caps", will disable scaling and enable that alternate mode along with small caps mode at the same time. If MODE is empty or not recognized, this considers it equivalent to "small caps" (without another mode).[%]
, with no number just after it, resets scale to 100% and disables any alternate mode.[@Name]
, where Name is a key in family, changes the current Font used for rendering to the Font in this.family by that name. This is ignored if family is null.[@]
, with no text just after it, resets the font to this one (which should be item 0 in family, if family is non-null).[#HHHHHHHH]
, where HHHHHHHH is a hex RGB888 or RGBA8888 int color, changes the color.[COLORNAME]
, where "COLORNAME" is a typically-upper-case color name that will be looked up ingetColorLookup()
, 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.
This takes a ColorLookup so that it can look up colors given a name or description; if you don't know what to use, thenColorLookup.DESCRIPTIVE
is the default elsewhere. Because this is static, it does not need a Font to be involved.- Parameters:
chr
- a single char to apply markup tomarkup
- a String containing only markup syntax, like "[*][_][RED]" for bold underline in redcolorLookup
- a ColorLookup (often a method reference orColorLookup.DESCRIPTIVE
) to get colors from textual names or descriptions- Returns:
- a long that encodes the given char with the specified markup
-
regenerateLayout
When thetargetWidth
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 asmarkup(String, Layout)
, if at all, but may eat up newlines if called repeatedly.- Parameters:
changing
- a Layout that will be modified in-place- Returns:
changing
, after modifications
-
storeState
Evaluatesmarkup
to get a formatting state and stores it for later usage with"[ name]"
syntax and the givenname
. Where"[ ]"
will reset state to its starting value,"[ name]"
will restore a previously saved state. States can be stored with this method (which will associate the named state with this Font, and will be copied with it), or temporarily stored in a markup String using"[(name)]"
.- Parameters:
name
- a non-null String to associate a formatting state withmarkup
- markup (with or without a char in it) that will be applied when this formatting state is used
-
storeState
Evaluatesmarkup
to get a formatting state and stores it for later usage with"[ name]"
syntax and the givenname
. Where"[ ]"
will reset state to its starting value,"[ name]"
will restore a previously saved state. States can be stored with this method (which will associate the named state with this Font, and will be copied with it), or temporarily stored in a markup String using"[(name)]"
.- Parameters:
name
- a non-null String to associate a formatting state withformatted
- any (ignored) character that will have its formatting stored for later usage
-
getStoredState
Looks up the given name in the stored states and returns the associated formatting state, orfallback
if the name was not present. A suggestion forfallback
is to use'N'
, since a valid formatting state won't have any character data, and'N'
only has character data.- Parameters:
name
- a non-null String to look up in the stored statesfallback
- a formatting state or character to return if the given name is not found (often'N'
- Returns:
- the formatting state associated with name (if found), or
fallback
(if not found)
-
removeStoredState
Removes the formatting state with the given name if it is present, or does nothing if the name is not present.- Parameters:
name
- the name of the formatting state to remove
-
resizeDistanceField
public void resizeDistanceField(float width, float height) Important; must be called inApplicationListener.resize(int, int)
on each SDF, MSDF, or SDF_OUTLINE font you have currently rendering! This allows the distance field to appear as correct and crisp-outlined as it should be; without this, the distance field will probably not look very sharp at all. This doesn't need to be called every frame, only in resize().
Given the new width and height for a window, this attempts to adjust theactualCrispness
of an SDF/MSDF/SDF_OUTLINE font so that it will display cleanly at a different size. This uses this font'sdistanceFieldCrispness
as a multiplier applied after calculating the initial crispness.
If you use a viewport that significantly zooms in or out, you should multiply width byviewport.getScreenWidth() / viewport.getWorldWidth()
, and similarly multiply height by the corresponding screen height divided by world height. This can avoid the distance fields looking extremely blurry or boxy when one world unit covers many pixels, or too aliased and jagged in the opposite case.Typically, in yourApplicationListener.resize(int, int)
method, you callViewport.update(int, int)
(or the overload that can center the camera, if needed), and then call this or another method that resizes distance fields on each Font you are currently using.
If you load all or most of your Font instances via aFWSkin
, you can useFWSkin.resizeDistanceFields(float, float)
to resize all Fonts loaded by the Skin at once. You can also resize all distance fields in a FontFamily usingFont.FontFamily.resizeDistanceFields(float, float)
.- Parameters:
width
- the new window width; usually a parameter inApplicationListener.resize(int, int)
height
- the new window height; usually a parameter inApplicationListener.resize(int, int)
-
resizeDistanceField
public void resizeDistanceField(float width, float height, com.badlogic.gdx.utils.viewport.Viewport viewport) Important; must be called inApplicationListener.resize(int, int)
on each SDF, MSDF, or SDF_OUTLINE font you have currently rendering! This allows the distance field to appear as correct and crisp-outlined as it should be; without this, the distance field will probably not look very sharp at all. This doesn't need to be called every frame, only in resize(). This overload also uses a Viewport to better configure heavily-zoomed Fonts. It does not change the Viewport.
Given the new width and height for a window, this attempts to adjust theactualCrispness
of an SDF/MSDF/SDF_OUTLINE font so that it will display cleanly at a different size. This uses this font'sdistanceFieldCrispness
as a multiplier applied after calculating the initial crispness.
This handles scaling based on the given Viewport as well as based on the given width and height. This means you do not need to consider the manual changes suggested for the other overload,resizeDistanceField(float, float)
. The given Viewport must have been updated with the proper width and height for your application window before passing it here. Typically, in yourApplicationListener.resize(int, int)
method, you callViewport.update(int, int)
(or the overload that can center the camera, if needed), and then call this or another method that resizes distance fields on each Font you are currently using.
If you load all or most of your Font instances via aFWSkin
, you can useFWSkin.resizeDistanceFields(float, float, Viewport)
to resize all Fonts loaded by the Skin at once. You can also resize all distance fields in a FontFamily usingFont.FontFamily.resizeDistanceFields(float, float, Viewport)
.- Parameters:
width
- the new window width; usually a parameter inApplicationListener.resize(int, int)
height
- the new window height; usually a parameter inApplicationListener.resize(int, int)
viewport
- the current Viewport, after it has been updated usingViewport.update(int, int)
-
extractColor
public static int extractColor(long glyph) Given a glyph as a long, this returns the RGBA8888 color it uses. -
applyColor
public static long applyColor(long glyph, int color) Replaces the section of glyph that stores its color with the given RGBA8888 int 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 withBOLD
,OBLIQUE
,UNDERLINE
,STRIKETHROUGH
,SUBSCRIPT
,MIDSCRIPT
, andSUPERSCRIPT
. -
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 withBOLD
,OBLIQUE
,UNDERLINE
,STRIKETHROUGH
,SUBSCRIPT
,MIDSCRIPT
, andSUPERSCRIPT
. 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. -
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. -
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. -
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 includeSMALL_CAPS
separately from any other flags except forJOSTLE
(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
-
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 usingextractMode(long)
, though you could acquire or create them in any number of ways.- Parameters:
glyph
- a glyph as a long, as used byLayout
andLine
modeFlags
- bit flags typically obtained fromextractMode(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,'['
. -
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. -
dispose
public void dispose()Releases all resources of this object.- Specified by:
dispose
in interfacecom.badlogic.gdx.utils.Disposable
-
clearStatic
public static void clearStatic()ClearsTypingConfig.GLOBAL_VARS
and callsTypingConfig.initializeGlobalVars()
. This can be useful if you target Android and you use Activity.finish(), or some other way of ending an app that does not clear static values. Consider calling this if you encounter different (buggy) behavior on the second launch of an Android app vs. the first launch. It is not needed on desktop JVMs or GWT. This only could be needed if you add different items toTypingConfig.GLOBAL_VARS
on different runs of your Android app. -
toString
-
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 alwaysvertices
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 toBatch.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 callingbatch.draw(texture, vertices, 0, 20);
.
The format this should generally expect forvertices
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 fromColor.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 fromtexture
, 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 fromvertices
to its own 24-item float array, then pass that larger array toBatch.draw(Texture, float[], int, int)
.- Parameters:
batch
- a Batch, which should be a SpriteBatch (or a compatible Batch) unless this was overriddentexture
- a Texture to draw (part of)vertices
- a 20-item float array organized into 5-float sections per-vertex
-