Package com.github.tommyettinger.textra
Class Font
java.lang.Object
com.github.tommyettinger.textra.Font
- All Implemented Interfaces:
com.badlogic.gdx.utils.Disposable
public class Font
extends java.lang.Object
implements com.badlogic.gdx.utils.Disposable
A replacement for libGDX's BitmapFont class, supporting additional markup to allow styling text with various effects.
This includes the commonly-requested "faux bold" and oblique mode using one font image; you don't need a bold and
italic/oblique image separate from the book face. This also supports underline, strikethrough, subscript/superscript
(and "midscript," for a height between the two), color markup, scale/size markup, and the option to switch to other
Fonts from a family of several.
A Font represents either one size of a "standard" bitmap font (which can be drawn scaled up or down), or many sizes of a distance field font (using either the commonly-used SDF format or newer MSDF format). The same class is used for standard, SDF, and MSDF fonts, but you call
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. You can generate SDF fonts with Hiero or
a related tool
that is part of libGDX; MSDF fonts are harder to generate, but possible using a tool like
Glamer. Note that SDF and non-distance-field fonts can be
created with kerning information, but currently MSDF fonts cannot, making MSDF a better choice for monospace fonts
than variable-width ones.
This interacts with the
Layout class, with a Layout referencing a Font, and various methods in Font taking
a Layout. You usually want to have a Layout for any text you draw repeatedly, and draw that Layout each frame with
drawGlyphs(Batch, Layout, float, float, int) or a similar method.
The
TypingLabel class has its own markup that generally has an equivalent for all the markup options here.
This class has some special behavior for both the square-bracket markup used here and the curly-bracket markup used
by TypingLabel, even if the markup isn't actually used in a TypingLabel. In particular, anything in curly brackets is
ignored and left alone when markup() is called, and is not considered part of the size of the Layout. Anything inside
single curly braces is not rendered here, though it may be interpreted by TypingLabel if you use a Layout this
produces there. You should escape both square brackets with [[ and curly braces with {{ if
you intend them to appear.
Most things this can draw can be drawn with a rotation, and usually an origin can be specified (where it makes sense). The rotation can't be configured from markup, but the widgets that understand this class, like
TextraLabel and TypingLabel, can have their rotation set using the standard scene2d.ui method
Actor.setRotation(float), and then they will request the correct rotation
from this class. This is different from Label, which ignores rotation!
There are some features here that cannot be used purely from markup, such as per-character rotation and smooth scaling, but these can be used by TypingLabel and its Effect assortment.
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classFont.DistanceFieldTypeDefines what types of distance field font this can use and render.static classFont.FontFamilyHolds up to 16 Font values, accessible by index or by name, that markup can switch between while rendering.static classFont.GlyphRegionDescribes the region of a glyph in a larger TextureRegion, carrying a little more info about the offsets that apply to where the glyph is rendered. -
Field Summary
Fields Modifier and Type Field Description floatactualCrispnessWhendistanceFieldisFont.DistanceFieldType.SDForFont.DistanceFieldType.MSDF, this determines how much the edges of the glyphs should be aliased sharply (higher values) or anti-aliased softly (lower values).static longBOLDBit flag for bold mode, as a long.floatcellHeightRefers to the largest height of any glyph in the font, after scaling.floatcellWidthOnly actually refers to a "cell" whenisMonois true; otherwise refers to the largest width of any glyph in the font, after scaling.ColorLookupcolorLookupDetermines how colors are looked up by name; defaults to usingColorUtils.describe(String).Font.GlyphRegiondefaultValueWhich GlyphRegion to display if a char isn't found inmapping.floatdescentHow far the unscaled font descends below the baseline, typically as a negative number (not always).Font.DistanceFieldTypedistanceFieldAFont.DistanceFieldTypethat should beFont.DistanceFieldType.STANDARDfor most fonts, and can beFont.DistanceFieldType.SDForFont.DistanceFieldType.MSDFif you know you have a font made to be used with one of those rendering techniques.floatdistanceFieldCrispnessWhendistanceFieldisFont.DistanceFieldType.SDForFont.DistanceFieldType.MSDF, this determines how much the edges of the glyphs should be aliased sharply (higher values) or anti-aliased softly (lower values).Font.FontFamilyfamilyIf non-null, may contain connected Font values and names/aliases to look them up with using [@Name] syntax.booleanintegerPositionIf true, this will always use integers for x and y position (rounding), which can help some fonts look more clear.booleanisMonoIf true, this is a fixed-width (monospace) font; if false, this is probably a variable-width font.com.badlogic.gdx.utils.IntIntMapkerningUnlikely to be used externally, this is one way of storing the kerning information that some fonts have.com.badlogic.gdx.utils.IntMap<Font.GlyphRegion>mappingMaps char keys (stored as ints) to their correspondingFont.GlyphRegionvalues.static longMIDSCRIPTBit flag for midscript mode, as a long.static java.lang.StringmsdfFragmentShaderFragment shader source meant for MSDF fonts.java.lang.StringnameThe name of the Font, for display purposes.CaseInsensitiveIntMapnameLookupOptional; maps the names of TextureRegions to the indices they use inmapping, and usually assigned byaddAtlas(TextureAtlas).com.badlogic.gdx.utils.IntMap<java.lang.String>namesByCharCodeOptional; a reversed form ofnameLookupthat allows you to get the printable name for a given char code.static longOBLIQUEBit flag for oblique mode, as a long.floatoriginalCellHeightRefers to the largest height of any glyph in the font, before any scaling.floatoriginalCellWidthOnly actually refers to a "cell" whenisMonois true; otherwise refers to the largest width of any glyph in the font, before any scaling.com.badlogic.gdx.utils.Array<com.badlogic.gdx.graphics.g2d.TextureRegion>parentsThe larger TextureRegions thatFont.GlyphRegionimages are pulled from; these could be whole Textures or be drawn from a TextureAtlas that the font shares with other images.floatscaleXScale multiplier for width.floatscaleYScale multiplier for height.com.badlogic.gdx.graphics.glutils.ShaderProgramshaderThe ShaderProgram used to render this font, as used byenableShader(Batch).charsolidBlockA char that will be used to draw solid blocks withdrawBlocks(Batch, int[][], float, float), and to draw box-drawing/block-element characters ifmakeGridGlyphsis true in the constructor.static longSTRIKETHROUGHBit flag for strikethrough mode, as a long.static longSUBSCRIPTBit flag for subscript mode, as a long.static longSUPERSCRIPTTwo-bit flag for superscript mode, as a long.static longUNDERLINEBit flag for underline mode, as a long.static java.lang.StringvertexShaderThe standard libGDX vertex shader source, which is also used by the MSDF shader.com.badlogic.gdx.graphics.TexturewhiteBlockA 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). -
Constructor Summary
Constructors Constructor Description Font(com.badlogic.gdx.graphics.g2d.BitmapFont bmFont)Constructs a new Font from the existing BitmapFont, using its same Textures and TextureRegions for glyphs, and without a distance field effect or any adjustments to position 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.Font(Font toCopy)Copy constructor; does not copy the font'sshaderorcolorLookup, if it has them (it uses the same reference for the new Font), but will fully copy everything else.Font(java.lang.String fntName)Constructs a Font by reading in the given .fnt file and loading any images it specifies.Font(java.lang.String fntName, float xAdjust, float yAdjust, float widthAdjust, float heightAdjust)Constructs a new Font by reading in a .fnt file with the given name (an internal handle is tried first, then a local handle) and loading any images specified in that file.Font(java.lang.String fntName, com.badlogic.gdx.graphics.g2d.TextureRegion textureRegion, float xAdjust, float yAdjust, float widthAdjust, float heightAdjust)Constructs a font using the given TextureRegion that holds all of its glyphs, with no distance field effect.Font(java.lang.String fntName, com.badlogic.gdx.graphics.g2d.TextureRegion textureRegion, Font.DistanceFieldType distanceField, float xAdjust, float yAdjust, float widthAdjust, float heightAdjust)Constructs a font based off of an AngelCode BMFont .fnt file and the given TextureRegion that holds all of its glyphs, with the specified distance field effect.Font(java.lang.String fntName, com.badlogic.gdx.graphics.g2d.TextureRegion textureRegion, Font.DistanceFieldType distanceField, float xAdjust, float yAdjust, float widthAdjust, float heightAdjust, boolean makeGridGlyphs)Constructs a font based off of an AngelCode BMFont .fnt file and the given TextureRegion that holds all of its glyphs, with the specified distance field effect.Font(java.lang.String fntName, com.badlogic.gdx.utils.Array<com.badlogic.gdx.graphics.g2d.TextureRegion> textureRegions, float xAdjust, float yAdjust, float widthAdjust, float heightAdjust)Constructs a font based off of an AngelCode BMFont .fnt file and the given TextureRegion Array, with no distance field effect.Font(java.lang.String fntName, com.badlogic.gdx.utils.Array<com.badlogic.gdx.graphics.g2d.TextureRegion> textureRegions, Font.DistanceFieldType distanceField, float xAdjust, float yAdjust, float widthAdjust, float heightAdjust)Constructs a font based off of an AngelCode BMFont .fnt file, with the given TextureRegion Array and specified distance field effect.Font(java.lang.String fntName, com.badlogic.gdx.utils.Array<com.badlogic.gdx.graphics.g2d.TextureRegion> textureRegions, Font.DistanceFieldType distanceField, float xAdjust, float yAdjust, float widthAdjust, float heightAdjust, boolean makeGridGlyphs)Constructs a font based off of an AngelCode BMFont .fnt file, with the given TextureRegion Array and specified distance field effect.Font(java.lang.String fntName, Font.DistanceFieldType distanceField)Constructs a Font by reading in the given .fnt file and loading any images it specifies.Font(java.lang.String fntName, Font.DistanceFieldType distanceField, float xAdjust, float yAdjust, float widthAdjust, float heightAdjust)Constructs a new Font by reading in a .fnt file with the given name (an internal handle is tried first, then a local handle) and loading any images specified in that file.Font(java.lang.String fntName, Font.DistanceFieldType distanceField, float xAdjust, float yAdjust, float widthAdjust, float heightAdjust, boolean makeGridGlyphs)Constructs a new Font by reading in a .fnt file with the given name (an internal handle is tried first, then a local handle) and loading any images specified in that file.Font(java.lang.String fntName, java.lang.String textureName)Constructs a Font by reading in the given .fnt file and the given Texture by filename.Font(java.lang.String prefix, java.lang.String fntName, boolean ignoredSadConsoleFlag)Constructs a new Font by reading in a SadConsole .font file with the given name (an internal handle is tried first, then a local handle) and loading any images specified in that file.Font(java.lang.String fntName, java.lang.String textureName, float xAdjust, float yAdjust, float widthAdjust, float heightAdjust)Constructs a new Font by reading in a Texture from the given named path (internal is tried, then local), and no distance field effect.Font(java.lang.String fntName, java.lang.String textureName, Font.DistanceFieldType distanceField)Constructs a Font by reading in the given .fnt file and the given Texture by filename.Font(java.lang.String fntName, java.lang.String textureName, Font.DistanceFieldType distanceField, float xAdjust, float yAdjust, float widthAdjust, float heightAdjust)Constructs a new Font by reading in a Texture from the given named path (internal is tried, then local), and the specified distance field effect.Font(java.lang.String fntName, java.lang.String textureName, Font.DistanceFieldType distanceField, float xAdjust, float yAdjust, float widthAdjust, float heightAdjust, boolean makeGridGlyphs)Constructs a new Font by reading in a Texture from the given named path (internal is tried, then local), and the specified distance field effect. -
Method Summary
Modifier and Type Method Description FontaddAtlas(com.badlogic.gdx.graphics.g2d.TextureAtlas atlas)Adds all items inatlasto 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).FontaddImage(java.lang.String character, com.badlogic.gdx.graphics.g2d.TextureRegion region)Makes this Font "learn" a new mapping from a char (typically an emoji in a String forcharacter) to a TextureRegion.FontaddImage(java.lang.String character, com.badlogic.gdx.graphics.g2d.TextureRegion region, float offsetX, float offsetY, float xAdvance)Makes this Font "learn" a new mapping from a char (typically an emoji in a String 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.FontadjustCellWidth(float multiplier)Multiplies the width used by each glyph in a monospaced font bymultiplierwithout changing the size of any characters.FontadjustLineHeight(float multiplier)Multiplies the line height bymultiplierwithout changing the size of any characters.static longapplyChar(long glyph, char c)Replaces the section of glyph that stores its char with the given other char.static longapplyColor(long glyph, int color)Replaces the section of glyph that stores its color with the given RGBA8888 int color.static longapplyScale(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 longapplyStyle(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.intatlasLookup(java.lang.String name)Gets the char that might be associated withnamein at Atlas added to this (seeaddAtlas(TextureAtlas), or returns the int -1 if the name could not be found.floatcalculateSize(Layout layout)floatcalculateSize(Line line)Measures the actual width that the given Line will use when drawn, and sets it into the Line'sLine.widthfield.floatcalculateXAdvances(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 voidclearStatic()voiddispose()Releases all resources of this object.voiddrawBlocks(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.voiddrawBlocks(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 voiddrawBlockSequence(com.badlogic.gdx.graphics.g2d.Batch batch, float[] sequence, com.badlogic.gdx.graphics.g2d.TextureRegion block, float color, float x, float y)An internal method that draws blocks in a sequence specified by afloat[], with the block usuallysolidBlock(but not always).protected voiddrawBlockSequence(com.badlogic.gdx.graphics.g2d.Batch batch, float[] sequence, com.badlogic.gdx.graphics.g2d.TextureRegion block, float color, float x, float y, float width, float height)An internal method that draws blocks in a sequence specified by afloat[], with the block usuallysolidBlock(but not always).protected voiddrawBlockSequence(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).floatdrawGlyph(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.floatdrawGlyph(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.floatdrawGlyph(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.floatdrawGlyph(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.floatdrawGlyphs(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.floatdrawGlyphs(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, usingalignto determine how to position the text.floatdrawGlyphs(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, usingalignto determine how to position the text.floatdrawGlyphs(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.floatdrawGlyphs(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, usingalignto determine how to position the text.floatdrawGlyphs(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, usingalignto determine how to position the text.intdrawMarkupText(com.badlogic.gdx.graphics.g2d.Batch batch, java.lang.String text, float x, float y)Draws the specified text at the given x,y position (in world space), parsing an extension of libGDX markup and using it to determine color, size, position, shape, strikethrough, underline, case, and scale of the given CharSequence.voiddrawText(com.badlogic.gdx.graphics.g2d.Batch batch, java.lang.CharSequence text, float x, float y)Draws the specified text at the given x,y position (in world space) with a white foreground.voiddrawText(com.badlogic.gdx.graphics.g2d.Batch batch, java.lang.CharSequence text, float x, float y, int color)Draws the specified text at the given x,y position (in world space) with the given foreground color.voidenableShader(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 charextractChar(long glyph)Given a glyph as a long, this returns the char it displays.static intextractColor(long glyph)Given a glyph as a long, this returns the RGBA8888 color it uses.static floatextractScale(long glyph)Given a glyph as a long, this returns the float multiplier it uses for scale.static longextractStyle(long glyph)Given a glyph as a long, this returns the style bits it uses.FontfitCell(float width, float height, boolean center)Fits all chars into cells width by height in size, and optionally centers them in their cells.ColorLookupgetColorLookup()Gets the ColorLookup this uses to look up colors by name.floatgetCrispness()Gets the "crispness" multiplier for distance field fonts (SDF and MSDF).java.lang.StringgetName()protected floathandleIntegerPosition(float p)static intintFromDec(java.lang.CharSequence cs, int start, int end)Reads in a CharSequence containing only decimal digits (0-9) with an optional sign at the start and returns the int they represent, reading at most 10 characters (11 if there is a sign) and returning the result if valid, or 0 if nothing could be read.static intintFromHex(java.lang.CharSequence cs, int start, int end)Reads in a CharSequence containing only hex digits (only 0-9, a-f, and A-F) with an optional sign at the start and returns the long they represent, reading at most 16 characters (17 if there is a sign) and returning the result if valid, or 0 if nothing could be read.static booleanisLowerCase(char c)Returns true ifcis a lower-case letter, or false otherwise.static booleanisUpperCase(char c)Returns true ifcis an upper-case letter, or false otherwise.intkerningPair(char first, char second)Assembles two chars into a kerning pair that can be looked up as a key inkerning.protected voidloadFNT(java.lang.String fntName, float xAdjust, float yAdjust, float widthAdjust, float heightAdjust, boolean makeGridGlyphs)The gritty parsing code that pulls relevant info from an AngelCode BMFont .fnt file and uses it to assemble the manyFont.GlyphRegions this has for each glyph.protected voidloadSad(java.lang.String prefix, java.lang.String fntName)The parsing code that pulls relevant info from a SadConsole .font configuration file and uses it to assemble the manyFont.GlyphRegions this has for each glyph.static longlongFromHex(java.lang.CharSequence cs, int start, int end)Reads in a CharSequence containing only hex digits (only 0-9, a-f, and A-F) with an optional sign at the start and returns the long they represent, reading at most 16 characters (17 if there is a sign) and returning the result if valid, or 0 if nothing could be read.Layoutmarkup(java.lang.String text, Layout appendTo)longmarkupGlyph(char chr, java.lang.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.static longmarkupGlyph(char chr, java.lang.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 longmarkupGlyph(char chr, java.lang.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.longmarkupGlyph(java.lang.String markup)Reads markup frommarkupand processes it until it has a single complete glyph; returns that glyph as a long in the format used for styled glyphs here.floatmeasureWidth(Line line)Measures the actual width that the given Line will use when drawn.FontmultiplyCrispness(float multiplier)Takes the "crispness" multiplier for distance field fonts (SDF and MSDF) and multiplies it by another multiplier.LayoutregenerateLayout(Layout changing)voidresizeDistanceField(int width, int height)Given the new width and height for a window, this attempts to adjust theactualCrispnessof an SDF or MSDF font so that it will display cleanly at a different size.static java.lang.StringsafeSubstring(java.lang.String source, int beginIndex, int endIndex)LikeString.substring(int, int)but returns "" instead of throwing any sort of Exception.Fontscale(float horizontal, float vertical)Scales the font by the given horizontal and vertical multipliers.FontscaleTo(float width, float height)Scales the font so that it will have the given width and height.FontsetColorLookup(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 aColorLookupinterface implementation.FontsetCrispness(float crispness)Sets the "crispness" multiplier for distance field fonts (SDF and MSDF).FontsetFamily(Font.FontFamily family)Sets the FontFamily this can use to switch fonts using [@Name] syntax.FontsetName(java.lang.String name)FontsetTextureFilter()CallssetTextureFilter(Texture.TextureFilter, Texture.TextureFilter)withTexture.TextureFilter.Linearfor both min and mag filters.FontsetTextureFilter(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 givenminFilterandmagFilter.java.lang.StringtoString()FontuseIntegerPositions(boolean integer)floatxAdvance(long glyph)Gets the distance to advance the cursor after drawingglyph, scaled byscaleXas if drawing.static floatxAdvance(Font font, float scale, long glyph)Gets the distance to advance the cursor after drawingglyph, scaled byscaleas if drawing.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Field Details
-
mapping
Maps char keys (stored as ints) to their correspondingFont.GlyphRegionvalues. You can add arbitrary images to this mapping if you create appropriate GlyphRegion values (as withGlyphRegion(TextureRegion, int, int, int, int)), 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
public com.badlogic.gdx.utils.IntMap<java.lang.String> namesByCharCodeOptional; a reversed form ofnameLookupthat 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.GlyphRegionimages are pulled from; these could be whole Textures or be drawn from a TextureAtlas that the font shares with other images. -
distanceField
AFont.DistanceFieldTypethat should beFont.DistanceFieldType.STANDARDfor most fonts, and can beFont.DistanceFieldType.SDForFont.DistanceFieldType.MSDFif you know you have a font made to be used with one of those rendering techniques. SeedistanceFieldCrispnessfor one way to configure SDF and MSDF fonts, andresizeDistanceField(int, int)for a convenience method to handle window-resizing sharply. -
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.IntIntMap 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 an int associated with it, which applies to the x-position of the later char. -
actualCrispness
public float actualCrispnessWhendistanceFieldisFont.DistanceFieldType.SDForFont.DistanceFieldType.MSDF, this determines how much the edges of the glyphs should be aliased sharply (higher values) or anti-aliased softly (lower values). The default value is 1. This is set internally byresizeDistanceField(int, int)usingdistanceFieldCrispnessas a multiplier; when you want to have a change to crispness persist, use that other field. -
distanceFieldCrispness
public float distanceFieldCrispnessWhendistanceFieldisFont.DistanceFieldType.SDForFont.DistanceFieldType.MSDF, this determines how much the edges of the glyphs should be aliased sharply (higher values) or anti-aliased softly (lower values). The default value is 1. This is used as a persistent multiplier that can be configured per-font, whereasactualCrispnessis the working value that changes often but is influenced by this one. This variable is used byresizeDistanceField(int, int)to affect the working crispness value. -
cellWidth
public float cellWidthOnly actually refers to a "cell" whenisMonois 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" whenisMonois 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 ifmakeGridGlyphsis true in the constructor. The glyph that corresponds to this char should be a 1x1 pixel block of solid white pixels in most cases. Because Glamer (which generated many of the knownFonts here) places a solid block at where there is one in Unicode, this defaults to that Unicode glyph, at u2588 . There is also a test in TextraTypist, BlockStamper, that can place a tiny solid block in the lower-right corner and use that for this purpose. You can check if a .fnt file has a solid block present by searching 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 integerPositionIf true, this will always use integers for x and y position (rounding), which can help some fonts look more clear. However, if your world units are measured so that one world unit covers several pixels, then having this enabled can cause bizarre-looking visual glitches involving stretched or disappearing glyphs. This defaults to false, unlike what libGDX BitmapFont defaults to. -
name
public java.lang.String nameThe 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:
- Constant Field Values
-
OBLIQUE
public static final long OBLIQUEBit flag for oblique mode, as a long.- See Also:
- Constant Field Values
-
UNDERLINE
public static final long UNDERLINEBit flag for underline mode, as a long.- See Also:
- Constant Field Values
-
STRIKETHROUGH
public static final long STRIKETHROUGHBit flag for strikethrough mode, as a long.- See Also:
- Constant Field Values
-
SUBSCRIPT
public static final long SUBSCRIPTBit flag for subscript mode, as a long.- See Also:
- Constant Field Values
-
MIDSCRIPT
public static final long MIDSCRIPTBit flag for midscript mode, as a long.- See Also:
- Constant Field Values
-
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:
- Constant Field Values
-
vertexShader
public static final java.lang.String vertexShaderThe standard libGDX vertex shader source, which is also used by the MSDF shader.- See Also:
- Constant Field Values
-
msdfFragmentShader
public static final java.lang.String msdfFragmentShaderFragment shader source meant for MSDF fonts. This is automatically used whenenableShader(Batch)is called and thedistanceFieldisFont.DistanceFieldType.MSDF.- See Also:
- Constant Field Values
-
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 ifdistanceFieldis set toFont.DistanceFieldType.MSDF, or to one created byDistanceFieldFont.createDistanceFieldShader()if distanceField is set toFont.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 itsactualCrispnessfield. 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(java.lang.String fntName)Constructs a Font by reading in the given .fnt file and loading any images it specifies. Tries an internal handle first, then a local handle. Does not use a distance field effect.- Parameters:
fntName- the file path and name to a .fnt file this will load
-
Font
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
public Font(java.lang.String fntName, java.lang.String textureName)Constructs a Font by reading in the given .fnt file and the given Texture by filename. Tries an internal handle first, then a local handle. Does not use a distance field effect.- Parameters:
fntName- the file path and name to a .fnt file this will load
-
Font
public Font(java.lang.String fntName, java.lang.String textureName, Font.DistanceFieldType distanceField)Constructs a Font by reading in the given .fnt file and the given Texture by filename. Tries an internal handle first, then a local handle. Uses the specified distance field effect.- Parameters:
fntName- the file path and name to a .fnt file this will loaddistanceField- determines how edges are drawn; if unsure, you should useFont.DistanceFieldType.STANDARD
-
Font
Copy constructor; does not copy the font'sshaderorcolorLookup, if it has them (it uses the same reference for the new Font), but will fully copy everything else.- Parameters:
toCopy- another Font to copy
-
Font
public Font(java.lang.String fntName, float xAdjust, float yAdjust, float widthAdjust, float heightAdjust)Constructs a new Font by reading in a .fnt file with the given name (an internal handle is tried first, then a local handle) and loading any images specified in that file. No distance field effect is used. This allows globally adjusting the x and y positions of glyphs in the font, as well as globally adjusting the horizontal and vertical space glyphs take up. Changing these adjustments by small values can drastically improve the appearance of text, but has to be manually edited; every font is quite different. If you want to add empty space around each character, you can add approximately the normaloriginalCellWidthto 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(java.lang.String fntName, Font.DistanceFieldType distanceField, float xAdjust, float yAdjust, float widthAdjust, float heightAdjust)Constructs a new Font by reading in a .fnt file with the given name (an internal handle is tried first, then a local handle) and loading any images specified in that file. The specified distance field effect is used. This allows globally adjusting the x and y positions of glyphs in the font, as well as globally adjusting the horizontal and vertical space glyphs take up. Changing these adjustments by small values can drastically improve the appearance of text, but has to be manually edited; every font is quite different. If you want to add empty space around each character, you can add approximately the normaloriginalCellWidthto 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.STANDARDxAdjust- how many pixels to offset each character's x-position by, moving to the rightyAdjust- how many pixels to offset each character's y-position by, moving upwidthAdjust- how many pixels to add to the used width of each character, using more to the rightheightAdjust- how many pixels to add to the used height of each character, using more above
-
Font
public Font(java.lang.String fntName, Font.DistanceFieldType distanceField, float xAdjust, float yAdjust, float widthAdjust, float heightAdjust, boolean makeGridGlyphs)Constructs a new Font by reading in a .fnt file with the given name (an internal handle is tried first, then a local handle) and loading any images specified in that file. The specified distance field effect is used. This allows globally adjusting the x and y positions of glyphs in the font, as well as globally adjusting the horizontal and vertical space glyphs take up. Changing these adjustments by small values can drastically improve the appearance of text, but has to be manually edited; every font is quite different. If you want to add empty space around each character, you can add approximately the normaloriginalCellWidthto 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.STANDARDxAdjust- how many pixels to offset each character's x-position by, moving to the rightyAdjust- how many pixels to offset each character's y-position by, moving upwidthAdjust- how many pixels to add to the used width of each character, using more to the rightheightAdjust- how many pixels to add to the used height of each character, using more abovemakeGridGlyphs- true if this should use its own way of rendering box-drawing/block-element glyphs, ignoring any in the font file
-
Font
public Font(java.lang.String fntName, java.lang.String textureName, float xAdjust, float yAdjust, float widthAdjust, float heightAdjust)Constructs a new Font by reading in a Texture from the given named path (internal is tried, then local), and no distance field effect. This allows globally adjusting the x and y positions of glyphs in the font, as well as globally adjusting the horizontal and vertical space glyphs take up. Changing these adjustments by small values can drastically improve the appearance of text, but has to be manually edited; every font is quite different. If you want to add empty space around each character, you can add approximately the normaloriginalCellWidthto 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(java.lang.String fntName, java.lang.String textureName, Font.DistanceFieldType distanceField, float xAdjust, float yAdjust, float widthAdjust, float heightAdjust)Constructs a new Font by reading in a Texture from the given named path (internal is tried, then local), and the specified distance field effect. This allows globally adjusting the x and y positions of glyphs in the font, as well as globally adjusting the horizontal and vertical space glyphs take up. Changing these adjustments by small values can drastically improve the appearance of text, but has to be manually edited; every font is quite different. If you want to add empty space around each character, you can add approximately the normaloriginalCellWidthto 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.STANDARDxAdjust- how many pixels to offset each character's x-position by, moving to the rightyAdjust- how many pixels to offset each character's y-position by, moving upwidthAdjust- how many pixels to add to the used width of each character, using more to the rightheightAdjust- how many pixels to add to the used height of each character, using more above
-
Font
public Font(java.lang.String fntName, java.lang.String textureName, Font.DistanceFieldType distanceField, float xAdjust, float yAdjust, float widthAdjust, float heightAdjust, boolean makeGridGlyphs)Constructs a new Font by reading in a Texture from the given named path (internal is tried, then local), and the specified distance field effect. This allows globally adjusting the x and y positions of glyphs in the font, as well as globally adjusting the horizontal and vertical space glyphs take up. Changing these adjustments by small values can drastically improve the appearance of text, but has to be manually edited; every font is quite different. If you want to add empty space around each character, you can add approximately the normaloriginalCellWidthto 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.STANDARDxAdjust- how many pixels to offset each character's x-position by, moving to the rightyAdjust- how many pixels to offset each character's y-position by, moving upwidthAdjust- how many pixels to add to the used width of each character, using more to the rightheightAdjust- how many pixels to add to the used height of each character, using more abovemakeGridGlyphs- true if this should use its own way of rendering box-drawing/block-element glyphs, ignoring any in the font file
-
Font
public Font(java.lang.String fntName, com.badlogic.gdx.graphics.g2d.TextureRegion textureRegion, float xAdjust, float yAdjust, float widthAdjust, float heightAdjust)Constructs a font using the given TextureRegion that holds all of its glyphs, with no distance field effect. This allows globally adjusting the x and y positions of glyphs in the font, as well as globally adjusting the horizontal and vertical space glyphs take up. Changing these adjustments by small values can drastically improve the appearance of text, but has to be manually edited; every font is quite different. If you want to add empty space around each character, you can add approximately the normaloriginalCellWidthto 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(java.lang.String fntName, com.badlogic.gdx.graphics.g2d.TextureRegion textureRegion, Font.DistanceFieldType distanceField, float xAdjust, float yAdjust, float widthAdjust, float heightAdjust)Constructs a font based off of an AngelCode BMFont .fnt file and the given TextureRegion that holds all of its glyphs, with the specified distance field effect. This allows globally adjusting the x and y positions of glyphs in the font, as well as globally adjusting the horizontal and vertical space glyphs take up. Changing these adjustments by small values can drastically improve the appearance of text, but has to be manually edited; every font is quite different. If you want to add empty space around each character, you can add approximately the normaloriginalCellWidthto 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.STANDARDxAdjust- how many pixels to offset each character's x-position by, moving to the rightyAdjust- how many pixels to offset each character's y-position by, moving upwidthAdjust- how many pixels to add to the used width of each character, using more to the rightheightAdjust- how many pixels to add to the used height of each character, using more above
-
Font
public Font(java.lang.String fntName, com.badlogic.gdx.graphics.g2d.TextureRegion textureRegion, Font.DistanceFieldType distanceField, float xAdjust, float yAdjust, float widthAdjust, float heightAdjust, boolean makeGridGlyphs)Constructs a font based off of an AngelCode BMFont .fnt file and the given TextureRegion that holds all of its glyphs, with the specified distance field effect. This allows globally adjusting the x and y positions of glyphs in the font, as well as globally adjusting the horizontal and vertical space glyphs take up. Changing these adjustments by small values can drastically improve the appearance of text, but has to be manually edited; every font is quite different. If you want to add empty space around each character, you can add approximately the normaloriginalCellWidthto 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.STANDARDxAdjust- how many pixels to offset each character's x-position by, moving to the rightyAdjust- how many pixels to offset each character's y-position by, moving upwidthAdjust- how many pixels to add to the used width of each character, using more to the rightheightAdjust- how many pixels to add to the used height of each character, using more abovemakeGridGlyphs- true if this should use its own way of rendering box-drawing/block-element glyphs, ignoring any in the font file
-
Font
public Font(java.lang.String fntName, com.badlogic.gdx.utils.Array<com.badlogic.gdx.graphics.g2d.TextureRegion> textureRegions, float xAdjust, float yAdjust, float widthAdjust, float heightAdjust)Constructs a font based off of an AngelCode BMFont .fnt file and the given TextureRegion Array, with no distance field effect. This allows globally adjusting the x and y positions of glyphs in the font, as well as globally adjusting the horizontal and vertical space glyphs take up. Changing these adjustments by small values can drastically improve the appearance of text, but has to be manually edited; every font is quite different. If you want to add empty space around each character, you can add approximately the normaloriginalCellWidthto 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(java.lang.String fntName, com.badlogic.gdx.utils.Array<com.badlogic.gdx.graphics.g2d.TextureRegion> textureRegions, Font.DistanceFieldType distanceField, float xAdjust, float yAdjust, float widthAdjust, float heightAdjust)Constructs a font based off of an AngelCode BMFont .fnt file, with the given TextureRegion Array and specified distance field effect. This allows globally adjusting the x and y positions of glyphs in the font, as well as globally adjusting the horizontal and vertical space glyphs take up. Changing these adjustments by small values can drastically improve the appearance of text, but has to be manually edited; every font is quite different. If you want to add empty space around each character, you can add approximately the normaloriginalCellWidthto 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.STANDARDxAdjust- how many pixels to offset each character's x-position by, moving to the rightyAdjust- how many pixels to offset each character's y-position by, moving upwidthAdjust- how many pixels to add to the used width of each character, using more to the rightheightAdjust- how many pixels to add to the used height of each character, using more above
-
Font
public Font(java.lang.String fntName, com.badlogic.gdx.utils.Array<com.badlogic.gdx.graphics.g2d.TextureRegion> textureRegions, Font.DistanceFieldType distanceField, float xAdjust, float yAdjust, float widthAdjust, float heightAdjust, boolean makeGridGlyphs)Constructs a font based off of an AngelCode BMFont .fnt file, with the given TextureRegion Array and specified distance field effect. This allows globally adjusting the x and y positions of glyphs in the font, as well as globally adjusting the horizontal and vertical space glyphs take up. Changing these adjustments by small values can drastically improve the appearance of text, but has to be manually edited; every font is quite different. If you want to add empty space around each character, you can add approximately the normaloriginalCellWidthto 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.STANDARDxAdjust- how many pixels to offset each character's x-position by, moving to the rightyAdjust- how many pixels to offset each character's y-position by, moving upwidthAdjust- how many pixels to add to the used width of each character, using more to the rightheightAdjust- how many pixels to add to the used height of each character, using more abovemakeGridGlyphs- true if this should use its own way of rendering box-drawing/block-element glyphs, ignoring any in the font 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 toyAdjustequal 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 toyAdjustequal 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.STANDARDxAdjust- how many pixels to offset each character's x-position by, moving to the rightyAdjust- how many pixels to offset each character's y-position by, moving upwidthAdjust- how many pixels to add to the used width of each character, using more to the rightheightAdjust- how many pixels to add to the used height of each character, using more 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 toyAdjustequal 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.STANDARDxAdjust- how many pixels to offset each character's x-position by, moving to the rightyAdjust- how many pixels to offset each character's y-position by, moving upwidthAdjust- how many pixels to add to the used width of each character, using more to the rightheightAdjust- how many pixels to add to the used height of each character, using more abovemakeGridGlyphs- true if this should use its own way of rendering box-drawing/block-element glyphs, ignoring any in the font file
-
Font
public Font(java.lang.String prefix, java.lang.String fntName, boolean ignoredSadConsoleFlag)Constructs a new Font by reading in a SadConsole .font file with the given name (an internal handle is tried first, then a local handle) and loading any images specified in that file. This never uses a distance field effect, and always tries to load one image by the path specified in the .font file.- Parameters:
prefix- a String to prepend to any filenames looked up for this Font (typically a .font file and a .png file)fntName- the path and filename of a .font file this will load; may be internal or localignoredSadConsoleFlag- the value is ignored here; the presence of this parameter says to load a SadConsole .font file
-
-
Method Details
-
longFromHex
public static long longFromHex(java.lang.CharSequence cs, int start, int end)Reads in a CharSequence containing only hex digits (only 0-9, a-f, and A-F) with an optional sign at the start and returns the long they represent, reading at most 16 characters (17 if there is a sign) and returning the result if valid, or 0 if nothing could be read. The leading sign can be '+' or '-' if present. This can also represent negative numbers as they are printed by such methods as String.format given %x in the formatting string; that is, if the first char of a 16-char (or longer) CharSequence is a hex digit 8 or higher, then the whole number represents a negative number, using two's complement and so on. This means "FFFFFFFFFFFFFFFF" would return the long -1 when passed to this, though you could also simply use "-1 ". If you use both '-' at the start and have the most significant digit as 8 or higher, such as with "-FFFFFFFFFFFFFFFF", then both indicate a negative number, but the digits will be processed first (producing -1) and then the whole thing will be multiplied by -1 to flip the sign again (returning 1).
Should be fairly close to Java 8's Long.parseUnsignedLong method, which is an odd omission from earlier JDKs. This doesn't throw on invalid input, though, instead returning 0 if the first char is not a hex digit, or stopping the parse process early if a non-hex-digit char is read before end is reached. If the parse is stopped early, this behaves as you would expect for a number with fewer digits, and simply doesn't fill the larger places.- Parameters:
cs- a CharSequence, such as a String, containing only hex digits with an optional sign (no 0x at the start)start- the (inclusive) first character position in cs to readend- the (exclusive) last character position in cs to read (this stops after 16 characters if end is too large)- Returns:
- the long that cs represents
-
intFromHex
public static int intFromHex(java.lang.CharSequence cs, int start, int end)Reads in a CharSequence containing only hex digits (only 0-9, a-f, and A-F) with an optional sign at the start and returns the long they represent, reading at most 16 characters (17 if there is a sign) and returning the result if valid, or 0 if nothing could be read. The leading sign can be '+' or '-' if present. This can also represent negative numbers as they are printed by such methods as String.format given %x in the formatting string; that is, if the first char of a 16-char (or longer) CharSequence is a hex digit 8 or higher, then the whole number represents a negative number, using two's complement and so on. This means "FFFFFFFFFFFFFFFF" would return the long -1 when passed to this, though you could also simply use "-1 ". If you use both '-' at the start and have the most significant digit as 8 or higher, such as with "-FFFFFFFFFFFFFFFF", then both indicate a negative number, but the digits will be processed first (producing -1) and then the whole thing will be multiplied by -1 to flip the sign again (returning 1).
Should be fairly close to Java 8's Long.parseUnsignedLong method, which is an odd omission from earlier JDKs. This doesn't throw on invalid input, though, instead returning 0 if the first char is not a hex digit, or stopping the parse process early if a non-hex-digit char is read before end is reached. If the parse is stopped early, this behaves as you would expect for a number with fewer digits, and simply doesn't fill the larger places.- Parameters:
cs- a CharSequence, such as a String, containing only hex digits with an optional sign (no 0x at the start)start- the (inclusive) first character position in cs to readend- the (exclusive) last character position in cs to read (this stops after 16 characters if end is too large)- Returns:
- the long that cs represents
-
intFromDec
public static int intFromDec(java.lang.CharSequence cs, int start, int end)Reads in a CharSequence containing only decimal digits (0-9) with an optional sign at the start and returns the int they represent, reading at most 10 characters (11 if there is a sign) and returning the result if valid, or 0 if nothing could be read. The leading sign can be '+' or '-' if present. This can technically be used to handle unsigned integers in decimal format, but it isn't the intended purpose. If you do use it for handling unsigned ints, 2147483647 is normally the highest positive int and -2147483648 the lowest negative one, but if you give this a number between 2147483647 and2147483647 + 2147483648, it will interpret it as a negative number that fits in bounds using the normal rules for converting between signed and unsigned numbers.
Should be fairly close to the JDK's Integer.parseInt method, but this also supports CharSequence data instead of just String data, and allows specifying a start and end. This doesn't throw on invalid input, either, instead returning 0 if the first char is not a decimal digit, or stopping the parse process early if a non-decimal-digit char is read before end is reached. If the parse is stopped early, this behaves as you would expect for a number with fewer digits, and simply doesn't fill the larger places.- Parameters:
cs- a CharSequence, such as a String, containing only digits 0-9 with an optional signstart- the (inclusive) first character position in cs to readend- the (exclusive) last character position in cs to read (this stops after 10 or 11 characters if end is too large, depending on sign)- Returns:
- the int that cs represents
-
safeSubstring
public static java.lang.String safeSubstring(java.lang.String source, int beginIndex, int endIndex)LikeString.substring(int, int)but returns "" instead of throwing any sort of Exception.- Parameters:
source- the String to get a substring frombeginIndex- the first index, inclusive; will be treated as 0 if negativeendIndex- the index after the last character (exclusive); if negative this will be source.length()- Returns:
- the substring of source between beginIndex and endIndex, or "" if any parameters are null/invalid
-
isLowerCase
public static boolean isLowerCase(char c)Returns true ifcis a lower-case letter, or false otherwise. Similar toCharacter.isLowerCase(char), but should actually work on GWT.- Parameters:
c- a char to check- Returns:
- true if c is a lower-case letter, or false otherwise.
-
isUpperCase
public static boolean isUpperCase(char c)Returns true ifcis an upper-case letter, or false otherwise. Similar toCharacter.isUpperCase(char), but should actually work on GWT.- Parameters:
c- a char to check- Returns:
- true if c is an upper-case letter, or false otherwise.
-
getColorLookup
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 aColorLookupinterface implementation.- Parameters:
lookup- a non-null ColorLookup- Returns:
- this, for chaining
-
loadFNT
protected void loadFNT(java.lang.String fntName, float xAdjust, float yAdjust, float widthAdjust, float heightAdjust, boolean makeGridGlyphs)The gritty parsing code that pulls relevant info from an AngelCode BMFont .fnt file and uses it to assemble the manyFont.GlyphRegions this has for each glyph.- Parameters:
fntName- the file name of the .fnt file; can be internal or localxAdjust- added to the x-position for each glyph in the fontyAdjust- added to the y-position for each glyph in the fontwidthAdjust- added to the glyph width for each glyph in the fontheightAdjust- added to the glyph height for each glyph in the fontmakeGridGlyphs- true if this should use its own way of rendering box-drawing/block-element glyphs, ignoring any in the font file
-
loadSad
protected void loadSad(java.lang.String prefix, java.lang.String fntName)The parsing code that pulls relevant info from a SadConsole .font configuration file and uses it to assemble the manyFont.GlyphRegions this has for each glyph.- Parameters:
fntName- the name of a font file this will load from an internal or local file handle (tried in that order)
-
kerningPair
public int kerningPair(char first, char second)Assembles two chars into a kerning pair that can be looked up as a key 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'sIntIntMap.get(int, int)method, you'll get the amount of extra space (in the same unit the font uses) this will insert betweenfirstandsecond.- 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 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
-
adjustLineHeight
Multiplies the line height bymultiplierwithout 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 tocellHeightandoriginalCellHeight- Returns:
- this Font, for chaining
-
adjustCellWidth
Multiplies the width used by each glyph in a monospaced font bymultiplierwithout changing the size of any characters.- Parameters:
multiplier- will be applied tocellWidthandoriginalCellWidth- Returns:
- this Font, for chaining
-
fitCell
Fits all chars into cells width by height in size, and optionally centers them in their cells. This setsisMonoto true, andkerningto 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
-
setTextureFilter
CallssetTextureFilter(Texture.TextureFilter, Texture.TextureFilter)withTexture.TextureFilter.Linearfor 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.SDFandFont.DistanceFieldType.MSDFfonts, but you may also want to use it forFont.DistanceFieldType.STANDARDfonts when downscaling (they can look terrible if the defaultTexture.TextureFilter.Nearestfilter 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 givenminFilterandmagFilter. You may want to use this to set a font usingFont.DistanceFieldType.STANDARDto use a better TextureFilter for smooth downscaling, likeTexture.TextureFilter.MipMapLinearLinearor justTexture.TextureFilter.Linear. You might, for some reason, want to set a font usingFont.DistanceFieldType.SDForFont.DistanceFieldType.MSDFto 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
-
getName
public java.lang.String getName() -
setName
-
getCrispness
public float getCrispness()Gets the "crispness" multiplier for distance field fonts (SDF and MSDF). This is usually 1.0 unless it has been changed. The default value is 1.0; lower values look softer and fuzzier, while higher values look sharper and possibly more jagged. This is used as a persistent multiplier that can be configured per-font, whereasactualCrispnessis the working value that changes often but is influenced by this one. This variable is used byresizeDistanceField(int, int)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). The default value is 1.0; lower values look softer and fuzzier, while higher values look sharper and possibly more jagged. This is used as a persistent multiplier that can be configured per-font, whereasactualCrispnessis the working value that changes often but is influenced by this one. This variable is used byresizeDistanceField(int, int)to affect the working crispness value.- Parameters:
crispness- a float multiplier to be applied to the working crispness; 1.0 is the default- Returns:
- this Font, for chaining
-
multiplyCrispness
Takes the "crispness" multiplier for distance field fonts (SDF and MSDF) and multiplies it by another multiplier. Using lower values for multiplier will make the font look softer and fuzzier, while higher values will make it look sharper and possibly more jagged. This affects a persistent multiplier that can be configured per-font, whereasactualCrispnessis the working value that changes often but is influenced by this one. The variable this affects is used byresizeDistanceField(int, int)to affect the working crispness value.- Parameters:
multiplier- a float multiplier to be applied to the working crispness multiplier- Returns:
- this Font, for chaining
-
addImage
public Font addImage(java.lang.String character, com.badlogic.gdx.graphics.g2d.TextureRegion region, float offsetX, float offsetY, float xAdvance)Makes this Font "learn" a new mapping from a char (typically an emoji in a String 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
public Font addImage(java.lang.String character, com.badlogic.gdx.graphics.g2d.TextureRegion region)Makes this Font "learn" a new mapping from a char (typically an emoji in a String forcharacter) to a TextureRegion. The GlyphRegion that will be placed intomappingwill 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 inatlasto 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
-
atlasLookup
public int atlasLookup(java.lang.String name)Gets the char that might be associated withnamein 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 MSDF font, then this resets batch's shader to the default (usingbatch.setShader(null)).
This is called automatically forTextraLabelandTypingLabelif 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);.- Parameters:
batch- the Batch to instruct to use the appropriate shader for this font; should usually be a SpriteBatch
-
drawText
public void drawText(com.badlogic.gdx.graphics.g2d.Batch batch, java.lang.CharSequence text, float x, float y)Draws the specified text at the given x,y position (in world space) with a white foreground.- Parameters:
batch- typically a 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, java.lang.CharSequence text, float x, float y, int color)Draws the specified text at the given x,y position (in world space) with the given foreground color.- Parameters:
batch- typically a 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 at char u0000 by default, or atsolidBlockif you have set that field; Glamer produces fonts that have a block at u0000 already. Thecolorsparameter should be a rectangular 2D array, and because any colors that are the default int value0will 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 usesBatch.draw(Texture, float[], int, int)to draw each rectangle with minimal overhead, and this also means it is unaffected by the batch color. If you want to alter the colors using a shader, the shader will receive each color incolorsas itsa_colorattribute, 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. TheblockCharshould visually be represented by a very large block, occupying all of a monospaced cell. Thecolorsparameter should be a rectangular 2D array, and because any colors that are the default int value0will 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 usesBatch.draw(Texture, float[], int, int)to draw each rectangle with minimal overhead, and this also means it is unaffected by the batch color. If you want to alter the colors using a shader, the shader will receive each color incolorsas itsa_colorattribute, 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)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. Drawsblockat its full width and height, in the given packed color.- 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; usuallysolidBlockcolor- the color as a packed floatx- the x position to draw aty- the y position to draw at
-
drawBlockSequence
protected void drawBlockSequence(com.badlogic.gdx.graphics.g2d.Batch batch, float[] sequence, com.badlogic.gdx.graphics.g2d.TextureRegion block, float color, float x, float y, float width, float height)An internal method that draws blocks in a sequence specified by afloat[], with the block usuallysolidBlock(but not always). This is somewhat complicated; the sequence is typically drawn directly fromBlockUtils. Drawsblockat the given width and height, in the given packed color.- 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; usuallysolidBlockcolor- 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 instructions
-
drawBlockSequence
protected void drawBlockSequence(com.badlogic.gdx.graphics.g2d.Batch batch, float[] sequence, com.badlogic.gdx.graphics.g2d.TextureRegion block, float color, float x, float y, float width, float height, float rotation)An internal method that draws blocks in a sequence specified by afloat[], with the block usuallysolidBlock(but not always). This is somewhat complicated; the sequence is typically drawn directly fromBlockUtils. Drawsblockat 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; usuallysolidBlockcolor- 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
-
drawMarkupText
public int drawMarkupText(com.badlogic.gdx.graphics.g2d.Batch batch, java.lang.String text, float x, float y)Draws the specified text at the given x,y position (in world space), parsing an extension of libGDX markup and using it to determine color, size, position, shape, strikethrough, underline, case, and scale of the given CharSequence. The text drawn will start as white, with the normal size as bycellWidthandcellHeight, normal case, and without bold, italic, superscript, subscript, strikethrough, or underline. Markup starts with[; the next non-letter character determines what that piece of markup toggles. Markup this knows:[]clears all markup to the initial state without any applied.[[escapes a literal left bracket, producing it without changing state.[+name], where name is the name of a TextureRegion from an atlas added to this Font 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
public float drawGlyphs(com.badlogic.gdx.graphics.g2d.Batch batch, Layout glyphs, float x, float y)Draws the specified Layout of glyphs with a Batch at a given x, y position, drawing the full layout.- Parameters:
batch- typically a 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, usingalignto 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- anAlignconstant; 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, usingalignto 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- anAlignconstant; 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, usingalignto 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- anAlignconstant; 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, usingalignto 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- anAlignconstant; 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 byscaleas 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, usuallyscaleXand 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 byscaleXas 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.widthfield.- Parameters:
line- a Line, as from inside a Layout- Returns:
- the width in world units
-
calculateSize
-
calculateXAdvances
Not meant for general use; calculates the x-positions before every glyph inline, including invisible ones. Clearsadvancesand 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) -
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 aLayoutholding one or moreLines. A common way of getting a Layout is withLayout.POOL.obtain(); you can free the Layout when you are done using it withPool.free(Object)onLayout.POOL. This parses an extension of libGDX markup and uses it to determine color, size, position, shape, strikethrough, underline, case, and scale of the given CharSequence. It also reads typing markup, for effects, but passes it through without changing it and without considering it for line wrapping or text position. The text drawn will start inappendTo'sLayout.baseColor, which is usually white, with the normal size as determined by the font's metrics and scale (scaleXandscaleY), normal case, and without bold, italic, superscript, subscript, strikethrough, or underline. Markup starts with[; the next character determines what that piece of markup toggles. Markup this knows:[]clears all markup to the initial state without any applied.[[escapes a literal left bracket, producing it without changing state.[+name], where name is the name of a TextureRegion from an atlas added to this Font 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).[%], 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 color name or description that will be looked up ingetColorLookup(), changes the color. By default this can receive ALL_CAPS names fromColorsin 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.
appendTousingdrawGlyphs(Batch, Layout, float, float).- Parameters:
text- text with markupappendTo- a Layout that stores one or more Line objects, carrying color, style, chars, and size- Returns:
- appendTo, for chaining
-
markupGlyph
public long markupGlyph(char chr, java.lang.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. 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 (scaleXandscaleY), normal case, and without bold, italic, superscript, subscript, strikethrough, or underline. Markup starts with[; the next character determines what that piece of markup toggles. Markup this knows:[]clears all markup to the initial state without any applied.[*]toggles bold mode.[/]toggles italic (technically, oblique) mode.[^]toggles superscript mode (and turns off subscript or midscript mode).[=]toggles midscript mode (and turns off superscript or subscript mode).[.]toggles subscript mode (and turns off superscript or midscript mode).[_]toggles underline mode.[~]toggles strikethrough mode.[!]toggles all upper case mode.[,]toggles all lower case mode.[;]toggles capitalize each word mode (this is the same as upper case mode here).[%P], where P is a percentage from 0 to 375, changes the scale to that percentage (rounded to the nearest 25% mark).[%], with no number just after it, resets scale to 100% (this usually has no effect here).[@Name], where Name is a key in family, changes the current Font used for rendering to the Font in this.family by that name. This is ignored if family is null.[@], with no text just after it, resets the font to this one (which should be item 0 in family, if family is non-null).[#HHHHHHHH], where HHHHHHHH is a hex RGB888 or RGBA8888 int color, changes the color.[COLORNAME], where "COLORNAME" is a typically-upper-case color name that will be looked up 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 is equivalent to calling the staticmarkupGlyph(char, String, ColorLookup)and giving it this Font'scolorLookupvalue.- Parameters:
chr- a single char to apply markup tomarkup- a String containing only markup syntax, like "[*][_][RED]" for bold underline in red- Returns:
- a long that encodes the given char with the specified markup
-
markupGlyph
public long markupGlyph(java.lang.String markup)Reads markup frommarkupand 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 (scaleXandscaleY), normal case, and without bold, italic, superscript, subscript, strikethrough, or underline. Markup starts with[; the next character determines what that piece of markup toggles. Markup this knows:[]clears all markup to the initial state without any applied.[*]toggles bold mode.[/]toggles italic (technically, oblique) mode.[^]toggles superscript mode (and turns off subscript or midscript mode).[=]toggles midscript mode (and turns off superscript or subscript mode).[.]toggles subscript mode (and turns off superscript or midscript mode).[_]toggles underline mode.[~]toggles strikethrough mode.[!]toggles all upper case mode.[,]toggles all lower case mode.[;]toggles capitalize each word mode (this is the same as upper case mode here).[%P], where P is a percentage from 0 to 375, changes the scale to that percentage (rounded to the nearest 25% mark).[%], with no number just after it, resets scale to 100% (this usually has no effect here).[@Name], where Name is a key in family, changes the current Font used for rendering to the Font in this.family by that name. This is ignored if family is null.[@], with no text just after 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 (scaleXandscaleY), normal case, and without bold, italic, superscript, subscript, strikethrough, or underline. Markup starts with[; the next character determines what that piece of markup toggles. Markup this knows:[]clears all markup to the initial state without any applied.[*]toggles bold mode.[/]toggles italic (technically, oblique) mode.[^]toggles superscript mode (and turns off subscript or midscript mode).[=]toggles midscript mode (and turns off superscript or subscript mode).[.]toggles subscript mode (and turns off superscript or midscript mode).[_]toggles underline mode.[~]toggles strikethrough mode.[!]toggles all upper case mode.[,]toggles all lower case mode.[;]toggles capitalize each word mode (this is the same as upper case mode here).[%P], where P is a percentage from 0 to 375, changes the scale to that percentage (rounded to the nearest 25% mark).[%], with no number just after it, resets scale to 100% (this usually has no effect here).[@Name], where Name is a key in family, changes the current Font used for rendering to the Font in this.family by that name. This is ignored if family is null.[@], with no text just after it, resets the font to this one (which should be item 0 in family, if family is non-null).[#HHHHHHHH], where HHHHHHHH is a hex RGB888 or RGBA8888 int color, changes the color.[COLORNAME], where "COLORNAME" is a typically-upper-case color name that will be looked up 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.INSTANCEis often perfectly fine. 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, java.lang.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 (scaleXandscaleY), normal case, and without bold, italic, superscript, subscript, strikethrough, or underline. Markup starts with[; the next character determines what that piece of markup toggles. Markup this knows:[]clears all markup to the initial state without any applied.[*]toggles bold mode.[/]toggles italic (technically, oblique) mode.[^]toggles superscript mode (and turns off subscript or midscript mode).[=]toggles midscript mode (and turns off superscript or subscript mode).[.]toggles subscript mode (and turns off superscript or midscript mode).[_]toggles underline mode.[~]toggles strikethrough mode.[!]toggles all upper case mode.[,]toggles all lower case mode.[;]toggles capitalize each word mode (this is the same as upper case mode here).[%P], where P is a percentage from 0 to 375, changes the scale to that percentage (rounded to the nearest 25% mark).[%], with no number just after it, resets scale to 100% (this usually has no effect here).[@Name], where Name is a key in family, changes the current Font used for rendering to the Font in this.family by that name. This is ignored if family is null.[@], with no text just after it, resets the font to this one (which should be item 0 in family, if family is non-null).[#HHHHHHHH], where HHHHHHHH is a hex RGB888 or RGBA8888 int color, changes the color.[COLORNAME], where "COLORNAME" is a typically-upper-case color name that will be looked up 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.INSTANCEis often perfectly fine. 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.INSTANCE) to get colors from textual names or descriptions- Returns:
- a long that encodes the given char with the specified markup
-
regenerateLayout
-
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.FontFamilythat may be null or shared with other Fonts.- Returns:
- this, for chaining
-
resizeDistanceField
public void resizeDistanceField(int width, int height)Given the new width and height for a window, this attempts to adjust theactualCrispnessof an SDF or MSDF font so that it will display cleanly at a different size. This uses this font'sdistanceFieldCrispnessas a multiplier applied after calculating the initial crispness. This is a suggestion for what to call in yourApplicationListener.resize(int, int)method for each SDF or MSDF font you have currently rendering.- 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)
-
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. -
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. -
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. -
dispose
public void dispose()Releases all resources of this object.- Specified by:
disposein interfacecom.badlogic.gdx.utils.Disposable
-
clearStatic
public static void clearStatic()Frees allLineandLayoutobjects stored in static pools, and also clearsTypingConfig.GLOBAL_VARS. This can be useful if you target Android and you use Activity.finish(), or some other way of ending an app that does not clear static values. Consider calling this if you encounter different (buggy) behavior on the second launch of an Android app vs. the first launch. It is not needed on desktop JVMs or GWT. -
toString
public java.lang.String toString()- Overrides:
toStringin classjava.lang.Object
-