TextureRegion containing the glyphs and a file in
the AngleCode BMFont text format that describes where each glyph is on the image.
Text is drawn using a Batch. Text can be cached in a BitmapFontCache for faster rendering of static text, which
saves needing to compute the location of each glyph each frame.
* The texture for a BitmapFont loaded from a file is managed. dispose() must be called to free the texture when no
longer needed. A BitmapFont loaded using a TextureRegion is managed if the region's texture is managed. Disposing the
BitmapFont disposes the region's texture, which may not be desirable if the texture is still being used elsewhere.
The code was originally based on Matthias Mann's TWL BitmapFont class. Thanks for sharing, Matthias! :)
| Modifier and Type | Class and Description |
|---|---|
| public static class | BitmapFont.
Backing data for a |
| public static class | BitmapFont.
Represents a single character in a font page. |
| Modifier and Type | Field and Description |
|---|---|
| private final BitmapFontCache | |
| pack-priv final BitmapFont. | |
| private boolean | |
| pack-priv boolean | |
| private static final int | |
| private boolean | |
| private static final int | |
| private static final int | |
| pack-priv Array |
| Access | Constructor and Description |
|---|---|
| public | BitmapFont()
Creates a BitmapFont using the default 15pt Liberation Sans font included in the libgdx JAR file. |
| public | BitmapFont(boolean
If true, the glyphs will be flipped for use with a perspective where 0,0 is the upper left corner. flip)Creates a BitmapFont using the default 15pt Liberation Sans font included in the libgdx JAR file. |
| public | BitmapFont(FileHandle
the font definition file fontFile, TextureRegion The texture region containing the glyphs. The glyphs must be relative to the lower left corner (ie, the region
should not be flipped). If the region is null the glyph images are loaded from the image path in the font file. region)Creates a BitmapFont with the glyphs relative to the specified region. |
| public | BitmapFont(FileHandle fontFile, TextureRegion
The texture region containing the glyphs. The glyphs must be relative to the lower left corner (ie, the region
should not be flipped). If the region is null the glyph images are loaded from the image path in the font file. region, boolean If true, the glyphs will be flipped for use with a perspective where 0,0 is the upper left corner. flip)Creates a BitmapFont with the glyphs relative to the specified region. |
| public | |
| public | BitmapFont(FileHandle fontFile, boolean
If true, the glyphs will be flipped for use with a perspective where 0,0 is the upper left corner. flip)Creates a BitmapFont from a BMFont file. |
| public | BitmapFont(FileHandle fontFile, FileHandle imageFile, boolean
If true, the glyphs will be flipped for use with a perspective where 0,0 is the upper left corner. flip)Creates a BitmapFont from a BMFont file, using the specified image for glyphs. |
| public | BitmapFont(FileHandle fontFile, FileHandle imageFile, boolean
If true, the glyphs will be flipped for use with a perspective where 0,0 is the upper left corner. flip, boolean If true, rendering positions will be at integer values to avoid filtering artifacts. integer)Creates a BitmapFont from a BMFont file, using the specified image for glyphs. |
| public | BitmapFont(BitmapFont.
If true, rendering positions will be at integer values to avoid filtering artifacts. integer)Constructs a new BitmapFont from the given |
| public | BitmapFont(BitmapFont.
If true, rendering positions will be at integer values to avoid filtering artifacts. integer)Constructs a new BitmapFont from the given |
| Modifier and Type | Method and Description |
|---|---|
| public void | dispose()
Implements com. Disposes the texture used by this BitmapFont's region IF this BitmapFont created the texture. |
| public GlyphLayout | |
| public GlyphLayout | draw(Batch batch, CharSequence str, float x, float y, float targetWidth, int halign, boolean wrap)
Draws text at the specified position. |
| public GlyphLayout | draw(Batch batch, CharSequence str, float x, float y, int start, int end, float targetWidth, int halign, boolean wrap)
Draws text at the specified position. |
| public GlyphLayout | draw(Batch batch, CharSequence str, float x, float y, int start, int end, float targetWidth, int halign, boolean wrap, String truncate)
Draws text at the specified position. |
| public void | |
| public float | getAscent()
Returns the ascent, which is the distance from the cap height to the top of the tallest glyph. |
| public BitmapFontCache | Returns: the bitmap font cache used by this fontFor expert usage -- returns the BitmapFontCache used by this font, for rendering to a sprite batch. |
| public float | getCapHeight()
Returns the cap height, which is the distance from the top of most uppercase characters to the baseline. |
| public Color | |
| public BitmapFont. | |
| public float | getDescent()
Returns the descent, which is the distance from the bottom of the glyph that extends the lowest to the baseline. |
| public float | |
| public TextureRegion | |
| public TextureRegion | Returns: the texture page at the given indexReturns the texture page at the given index. |
| public Array | Returns: the array of texture regions; modifying it may produce undesirable resultsReturns the array of TextureRegions that represents each texture page of glyphs. |
| public float | |
| public float | |
| public float | |
| public float | getXHeight()
Returns the x-height, which is the distance from the top of most lowercase characters to the baseline. |
| pack-priv static int | |
| public boolean | isFlipped()
Returns true if this BitmapFont has been flipped for use with a y-down coordinate system. |
| protected void | |
| public BitmapFontCache | |
| public boolean | ownsTexture()
Returns: whether the texture is owned by the font, font disposes the texture itself if true |
| public void | |
| public void | |
| public void | |
| public void | setOwnsTexture(boolean
whether the font owns the texture ownsTexture)Sets whether the font owns the texture. |
| public void | |
| public String | |
| public boolean |
| cache | back to summary |
|---|---|
| private final BitmapFontCache cache | |
| data | back to summary |
|---|---|
| pack-priv final BitmapFont. | |
| flipped | back to summary |
|---|---|
| private boolean flipped | |
| integer | back to summary |
|---|---|
| pack-priv boolean integer | |
| LOG2_PAGE_SIZE | back to summary |
|---|---|
| private static final int LOG2_PAGE_SIZE | |
| ownsTexture | back to summary |
|---|---|
| private boolean ownsTexture | |
| PAGE_SIZE | back to summary |
|---|---|
| private static final int PAGE_SIZE | |
| PAGES | back to summary |
|---|---|
| private static final int PAGES | |
| regions | back to summary |
|---|---|
| pack-priv Array<TextureRegion> regions | |
| BitmapFont | back to summary |
|---|---|
| public BitmapFont() Creates a BitmapFont using the default 15pt Liberation Sans font included in the libgdx JAR file. This is convenient to easily display text without bothering without generating a bitmap font yourself. | |
| BitmapFont | back to summary |
|---|---|
| public BitmapFont(boolean flip) Creates a BitmapFont using the default 15pt Liberation Sans font included in the libgdx JAR file. This is convenient to easily display text without bothering without generating a bitmap font yourself.
| |
| BitmapFont | back to summary |
|---|---|
| public BitmapFont(FileHandle fontFile, TextureRegion region) Creates a BitmapFont with the glyphs relative to the specified region. If the region is null, the glyph textures are loaded
from the image file given in the font file. The The font data is not flipped.
| |
| BitmapFont | back to summary |
|---|---|
| public BitmapFont(FileHandle fontFile, TextureRegion region, boolean flip) Creates a BitmapFont with the glyphs relative to the specified region. If the region is null, the glyph textures are loaded
from the image file given in the font file. The
| |
| BitmapFont | back to summary |
|---|---|
| public BitmapFont(FileHandle fontFile) Creates a BitmapFont from a BMFont file. The image file name is read from the BMFont file and the image is loaded from the same directory. The font data is not flipped. | |
| BitmapFont | back to summary |
|---|---|
| public BitmapFont(FileHandle fontFile, boolean flip) Creates a BitmapFont from a BMFont file. The image file name is read from the BMFont file and the image is loaded from the same directory.
| |
| BitmapFont | back to summary |
|---|---|
| public BitmapFont(FileHandle fontFile, FileHandle imageFile, boolean flip) Creates a BitmapFont from a BMFont file, using the specified image for glyphs. Any image specified in the BMFont file is ignored.
| |
| BitmapFont | back to summary |
|---|---|
| public BitmapFont(FileHandle fontFile, FileHandle imageFile, boolean flip, boolean integer) Creates a BitmapFont from a BMFont file, using the specified image for glyphs. Any image specified in the BMFont file is ignored.
| |
| BitmapFont | back to summary |
|---|---|
| public BitmapFont(BitmapFont. Constructs a new BitmapFont from the given Passing a single TextureRegion assumes that your font only needs a single texture page. If you need to support multiple pages, either let the Font read the images themselves (by specifying null as the TextureRegion), or by specifying each page manually with the TextureRegion[] constructor.
| |
| BitmapFont | back to summary |
|---|---|
| public BitmapFont(BitmapFont. Constructs a new BitmapFont from the given
| |
| dispose | back to summary |
|---|---|
| public void dispose() Implements com. Disposes the texture used by this BitmapFont's region IF this BitmapFont created the texture. | |
| draw | back to summary |
|---|---|
| public GlyphLayout draw(Batch batch, CharSequence str, float x, float y) Draws text at the specified position. | |
| draw | back to summary |
|---|---|
| public GlyphLayout draw(Batch batch, CharSequence str, float x, float y, float targetWidth, int halign, boolean wrap) Draws text at the specified position. | |
| draw | back to summary |
|---|---|
| public GlyphLayout draw(Batch batch, CharSequence str, float x, float y, int start, int end, float targetWidth, int halign, boolean wrap) Draws text at the specified position. | |
| draw | back to summary |
|---|---|
| public GlyphLayout draw(Batch batch, CharSequence str, float x, float y, int start, int end, float targetWidth, int halign, boolean wrap, String truncate) Draws text at the specified position. | |
| draw | back to summary |
|---|---|
| public void draw(Batch batch, GlyphLayout layout, float x, float y) Draws text at the specified position. | |
| getAscent | back to summary |
|---|---|
| public float getAscent() Returns the ascent, which is the distance from the cap height to the top of the tallest glyph. | |
| getCache | back to summary |
|---|---|
| public BitmapFontCache getCache() For expert usage -- returns the BitmapFontCache used by this font, for rendering to a sprite batch. This can be used, for example, to manipulate glyph colors within a specific index.
| |
| getCapHeight | back to summary |
|---|---|
| public float getCapHeight() Returns the cap height, which is the distance from the top of most uppercase characters to the baseline. Since the drawing position is the cap height of the first line, the cap height can be used to get the location of the baseline. | |
| getColor | back to summary |
|---|---|
| public Color getColor() Returns the color of text drawn with this font. | |
| getData | back to summary |
|---|---|
| public BitmapFont. Gets the underlying | |
| getDescent | back to summary |
|---|---|
| public float getDescent() Returns the descent, which is the distance from the bottom of the glyph that extends the lowest to the baseline. This number is negative. | |
| getLineHeight | back to summary |
|---|---|
| public float getLineHeight() Returns the line height, which is the distance from one line of text to the next. | |
| getRegion | back to summary |
|---|---|
| public TextureRegion getRegion() Returns the first texture region. This is included for backwards compatibility, and for convenience since most fonts only
use one texture page. For multi-page fonts, use
| |
| getRegion | back to summary |
|---|---|
| public TextureRegion getRegion(int index) Returns the texture page at the given index.
| |
| getRegions | back to summary |
|---|---|
| public Array Returns the array of TextureRegions that represents each texture page of glyphs.
| |
| getScaleX | back to summary |
|---|---|
| public float getScaleX() | |
| getScaleY | back to summary |
|---|---|
| public float getScaleY() | |
| getSpaceXadvance | back to summary |
|---|---|
| public float getSpaceXadvance() Returns the x-advance of the space character. | |
| getXHeight | back to summary |
|---|---|
| public float getXHeight() Returns the x-height, which is the distance from the top of most lowercase characters to the baseline. | |
| indexOf | back to summary |
|---|---|
| pack-priv static int indexOf(CharSequence text, char ch, int start) | |
| isFlipped | back to summary |
|---|---|
| public boolean isFlipped() Returns true if this BitmapFont has been flipped for use with a y-down coordinate system. | |
| load | back to summary |
|---|---|
| protected void load(BitmapFont. | |
| newFontCache | back to summary |
|---|---|
| public BitmapFontCache newFontCache() Creates a new BitmapFontCache for this font. Using this method allows the font to provide the BitmapFontCache implementation to customize rendering. Note this method is called by the BitmapFont constructors. If a subclass overrides this method, it will be called before the subclass constructors. | |
| ownsTexture | back to summary |
|---|---|
public boolean ownsTexture()
| |
| setColor | back to summary |
|---|---|
| public void setColor(Color color) A convenience method for setting the font color. The color can also be set by modifying | |
| setColor | back to summary |
|---|---|
| public void setColor(float r, float g, float b, float a) A convenience method for setting the font color. The color can also be set by modifying | |
| setFixedWidthGlyphs | back to summary |
|---|---|
| public void setFixedWidthGlyphs(CharSequence glyphs) Makes the specified glyphs fixed width. This can be useful to make the numbers in a font fixed width. Eg, when horizontally centering a score or loading percentage text, it will not jump around as different numbers are shown. | |
| setOwnsTexture | back to summary |
|---|---|
| public void setOwnsTexture(boolean ownsTexture) Sets whether the font owns the texture. In case it does, the font will also dispose of the texture when
| |
| setUseIntegerPositions | back to summary |
|---|---|
| public void setUseIntegerPositions(boolean integer) Specifies whether to use integer positions. Default is to use them so filtering doesn't kick in as badly. | |
| toString | back to summary |
|---|---|
| public String toString() Overrides java. Doc from java. Returns a string representation of the object.
Satisfying this method's contract implies a non- | |
| usesIntegerPositions | back to summary |
|---|---|
| public boolean usesIntegerPositions() Checks whether this font uses integer positions for drawing. | |
BitmapFont.
| Modifier and Type | Field and Description |
|---|---|
| public float | ascent
The distance from the cap height to the top of the tallest glyph. |
| public float | blankLineScale
Multiplier for the line height of blank lines. |
| public char[] | breakChars
Additional characters besides whitespace where text is wrapped. |
| public char[] | |
| public float | capHeight
The distance from the top of most uppercase characters to the baseline. |
| public float | cursorX
The amount to add to the glyph X position when drawing a cursor between glyphs. |
| public float | descent
The distance from the baseline to the bottom of the glyph that extends the lowest. |
| public float | down
The distance to move down when \n is encountered. |
| public boolean | |
| public FileHandle | |
| public final BitmapFont. | |
| public String[] | imagePaths
An array of the image paths, for multiple texture pages. |
| public float | lineHeight
The distance from one line of text to the next. |
| public boolean | |
| public BitmapFont. | missingGlyph
The glyph to display for characters not in the font. |
| public String | name
The name of the font, or null. |
| public float | |
| public float | |
| public float | |
| public float | |
| public float | |
| public float | |
| public float | spaceXadvance
The width of the space character. |
| public char[] | |
| public float | xHeight
The x-height, which is the distance from the top of most lowercase characters to the baseline. |
| Access | Constructor and Description |
|---|---|
| public | BitmapFontData()
Creates an empty BitmapFontData for configuration before calling |
| public |
| Modifier and Type | Method and Description |
|---|---|
| public BitmapFont. | |
| public FileHandle | |
| public BitmapFont. | |
| public void | getGlyphs(GlyphLayout.
Characters to convert to glyphs. Will not contain newline or color tags. May contain "[[" for an escaped left
square bracket. str, int start, int end, BitmapFont.The glyph immediately before this run, or null if this is run is the first on a line of text. Used tp
apply kerning between the specified glyph and the first glyph in this run. lastGlyphUsing the specified string, populates the glyphs and positions of the specified glyph run. |
| public String | getImagePath(int index)
Returns the image path for the texture page at the given index (the "id" in the BMFont file). |
| public String[] | |
| public int | getWrapIndex(Array<BitmapFont.
Returns the first valid glyph index to use to wrap to the next line, starting at the specified start index and (typically) moving toward the beginning of the glyphs array. |
| public boolean | |
| public boolean | |
| public boolean | |
| public void | |
| public void | |
| public void | |
| public void | |
| public void | setLineHeight(float height)
Sets the line height, which is the distance from one line of text to the next. |
| public void | setScale(float scaleX, float scaleY)
Scales the font by the specified amounts on both axes
Note that smoother scaling can be achieved if the texture backing the BitmapFont is using |
| public void | |
| public String |
| ascent | back to summary |
|---|---|
| public float ascent The distance from the cap height to the top of the tallest glyph. | |
| blankLineScale | back to summary |
|---|---|
| public float blankLineScale Multiplier for the line height of blank lines. down * blankLineHeight is used as the distance to move down for a blank line. | |
| breakChars | back to summary |
|---|---|
| public char[] breakChars Additional characters besides whitespace where text is wrapped. Eg, a hypen (-). | |
| capChars | back to summary |
|---|---|
| public char[] capChars | |
| capHeight | back to summary |
|---|---|
| public float capHeight The distance from the top of most uppercase characters to the baseline. Since the drawing position is the cap height of the first line, the cap height can be used to get the location of the baseline. | |
| cursorX | back to summary |
|---|---|
| public float cursorX The amount to add to the glyph X position when drawing a cursor between glyphs. This field is not set by the BMFont file, it needs to be set manually depending on how the glyphs are rendered on the backing textures. | |
| descent | back to summary |
|---|---|
| public float descent The distance from the baseline to the bottom of the glyph that extends the lowest. This number is negative. | |
| down | back to summary |
|---|---|
| public float down The distance to move down when \n is encountered. | |
| flipped | back to summary |
|---|---|
| public boolean flipped | |
| fontFile | back to summary |
|---|---|
| public FileHandle fontFile | |
| glyphs | back to summary |
|---|---|
| public final BitmapFont. | |
| imagePaths | back to summary |
|---|---|
| public String[] imagePaths An array of the image paths, for multiple texture pages. | |
| lineHeight | back to summary |
|---|---|
| public float lineHeight The distance from one line of text to the next. To set this value, use | |
| markupEnabled | back to summary |
|---|---|
| public boolean markupEnabled | |
| missingGlyph | back to summary |
|---|---|
| public BitmapFont. The glyph to display for characters not in the font. May be null. | |
| name | back to summary |
|---|---|
| public String name The name of the font, or null. | |
| padBottom | back to summary |
|---|---|
| public float padBottom | |
| padLeft | back to summary |
|---|---|
| public float padLeft | |
| padRight | back to summary |
|---|---|
| public float padRight | |
| padTop | back to summary |
|---|---|
| public float padTop | |
| scaleX | back to summary |
|---|---|
| public float scaleX | |
| scaleY | back to summary |
|---|---|
| public float scaleY | |
| spaceXadvance | back to summary |
|---|---|
| public float spaceXadvance The width of the space character. | |
| xChars | back to summary |
|---|---|
| public char[] xChars | |
| xHeight | back to summary |
|---|---|
| public float xHeight The x-height, which is the distance from the top of most lowercase characters to the baseline. | |
| BitmapFontData | back to summary |
|---|---|
| public BitmapFontData() Creates an empty BitmapFontData for configuration before calling | |
| BitmapFontData | back to summary |
|---|---|
| public BitmapFontData(FileHandle fontFile, boolean flip) | |
| getFirstGlyph | back to summary |
|---|---|
| public BitmapFont. | |
| getFontFile | back to summary |
|---|---|
| public FileHandle getFontFile() | |
| getGlyph | back to summary |
|---|---|
| public BitmapFont. Returns the glyph for the specified character, or null if no such glyph exists. Note that
| |
| getGlyphs | back to summary |
|---|---|
| public void getGlyphs(GlyphLayout. Using the specified string, populates the glyphs and positions of the specified glyph run.
| |
| getImagePath | back to summary |
|---|---|
| public String getImagePath(int index) Returns the image path for the texture page at the given index (the "id" in the BMFont file). | |
| getImagePaths | back to summary |
|---|---|
| public String[] getImagePaths() | |
| getWrapIndex | back to summary |
|---|---|
| public int getWrapIndex(Array<BitmapFont. Returns the first valid glyph index to use to wrap to the next line, starting at the specified start index and (typically) moving toward the beginning of the glyphs array. | |
| hasGlyph | back to summary |
|---|---|
| public boolean hasGlyph(char ch) Returns true if the font has the glyph, or if the font has a | |
| isBreakChar | back to summary |
|---|---|
| public boolean isBreakChar(char c) | |
| isWhitespace | back to summary |
|---|---|
| public boolean isWhitespace(char c) | |
| load | back to summary |
|---|---|
| public void load(FileHandle fontFile, boolean flip) | |
| scale | back to summary |
|---|---|
| public void scale(float amount) Sets the font's scale relative to the current scale.
| |
| setGlyph | back to summary |
|---|---|
| public void setGlyph(int ch, BitmapFont. | |
| setGlyphRegion | back to summary |
|---|---|
| public void setGlyphRegion(BitmapFont. | |
| setLineHeight | back to summary |
|---|---|
| public void setLineHeight(float height) Sets the line height, which is the distance from one line of text to the next. | |
| setScale | back to summary |
|---|---|
| public void setScale(float scaleX, float scaleY) Scales the font by the specified amounts on both axes
Note that smoother scaling can be achieved if the texture backing the BitmapFont is using
| |
| setScale | back to summary |
|---|---|
| public void setScale(float scaleXY) Scales the font by the specified amount in both directions.
| |
| toString | back to summary |
|---|---|
| public String toString() Overrides java. Doc from java. Returns a string representation of the object.
Satisfying this method's contract implies a non- | |
| Modifier and Type | Field and Description |
|---|---|
| public boolean | |
| public int | |
| public int | |
| public byte[][] | |
| public int | page
The index to the texture page that holds this glyph. |
| public int | |
| public int | |
| public float | |
| public float | |
| public float | |
| public float | |
| public int | |
| public int | |
| public int | |
| public int |
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| public int | |
| public void | |
| public String |
| fixedWidth | back to summary |
|---|---|
| public boolean fixedWidth | |
| height | back to summary |
|---|---|
| public int height | |
| id | back to summary |
|---|---|
| public int id | |
| kerning | back to summary |
|---|---|
| public byte[][] kerning | |
| page | back to summary |
|---|---|
| public int page The index to the texture page that holds this glyph. | |
| srcX | back to summary |
|---|---|
| public int srcX | |
| srcY | back to summary |
|---|---|
| public int srcY | |
| u | back to summary |
|---|---|
| public float u | |
| u2 | back to summary |
|---|---|
| public float u2 | |
| v | back to summary |
|---|---|
| public float v | |
| v2 | back to summary |
|---|---|
| public float v2 | |
| width | back to summary |
|---|---|
| public int width | |
| xadvance | back to summary |
|---|---|
| public int xadvance | |
| xoffset | back to summary |
|---|---|
| public int xoffset | |
| yoffset | back to summary |
|---|---|
| public int yoffset | |
| Glyph | back to summary |
|---|---|
| public Glyph() | |
| getKerning | back to summary |
|---|---|
| public int getKerning(char ch) | |
| setKerning | back to summary |
|---|---|
| public void setKerning(int ch, int value) | |
| toString | back to summary |
|---|---|
| public String toString() Overrides java. Doc from java. Returns a string representation of the object.
Satisfying this method's contract implies a non- | |