BitmapFont and BitmapFontData instances from TrueType, OTF, and other FreeType supported fonts.
Usage example:
FreeTypeFontGenerator gen = new FreeTypeFontGenerator(Gdx.files.internal("myfont.ttf"));
BitmapFont font = gen.generateFont(16);
gen.dispose(); // Don't dispose if doing incremental glyph generation.
The generator has to be disposed once it is no longer used. The returned BitmapFont instances are managed by the user
and have to be disposed as usual.
| Modifier and Type | Class and Description |
|---|---|
| public static class | FreeTypeFontGenerator.
|
| public static class | FreeTypeFontGenerator.
Parameter container class that helps configure how |
| public class | |
| public static enum | FreeTypeFontGenerator.
Font smoothing algorithm. |
| Modifier and Type | Field and Description |
|---|---|
| pack-priv boolean | |
| public static final String | |
| pack-priv final FreeType. | |
| pack-priv final FreeType. | |
| private static int | maxTextureSize
The maximum texture size allowed by generateData, when storing in a texture atlas. |
| pack-priv final String | |
| public static final int | NO_MAXIMUM
A hint to scale the texture as needed, without capping it at any maximum size |
| private int | |
| private int |
| Access | Constructor and Description |
|---|---|
| public | |
| public | FreeTypeFontGenerator(FileHandle fontFile, int faceIndex)
Creates a new generator from the given font file. |
| Modifier and Type | Method and Description |
|---|---|
| private boolean | |
| protected BitmapFont. | createGlyph(char c, FreeTypeFontGenerator.
Returns: null if glyph was not found. |
| public void | dispose()
Implements com. Cleans up all resources of the generator. |
| public FreeTypeFontGenerator. | |
| public FreeTypeFontGenerator. | |
| public FreeTypeFontGenerator. | generateData(FreeTypeFontGenerator.
configures how the font is generated parameter,Generates a new |
| public BitmapFont | |
| public BitmapFont | generateFont(FreeTypeFontGenerator.
configures how the font is generated parameter,Generates a new |
| public FreeTypeFontGenerator. | generateGlyphAndBitmap(int c, int size, boolean flip)
Returns null if glyph was not found in the font. |
| private int | |
| public static int | Returns: the power-of-two max texture sizeReturns the maximum texture size that will be used by generateData() when creating a texture atlas for the glyphs. |
| public boolean | |
| private boolean | |
| private boolean | |
| protected BitmapFont | newBitmapFont(BitmapFont.
Called by generateFont to create a new |
| public int | scaleForPixelHeight(int height)
Uses ascender and descender of font to calculate real height that makes all glyphs to fit in given pixel size. |
| public int | scaleForPixelWidth(int
the max width to fit (in pixels) width, int max number of characters that to fill width numChars)Uses max advance, ascender and descender of font to calculate real height that makes any n glyphs to fit in given pixel width. |
| public int | scaleToFitSquare(int
the max width to fit (in pixels) width, int the max height to fit (in pixels) height, int max number of characters that to fill width numChars)Uses max advance, ascender and descender of font to calculate real height that makes any n glyphs to fit in given pixel width and height. |
| public static void | setMaxTextureSize(int
the maximum texture size for one page of glyphs texSize)Sets the maximum size that will be used when generating texture atlases for glyphs with generateData(). |
| pack-priv void | |
| public String |
| bitmapped | back to summary |
|---|---|
| pack-priv boolean bitmapped | |
| DEFAULT_CHARS | back to summary |
|---|---|
| public static final String DEFAULT_CHARS | |
| face | back to summary |
|---|---|
| pack-priv final FreeType. | |
| library | back to summary |
|---|---|
| pack-priv final FreeType. | |
| maxTextureSize | back to summary |
|---|---|
| private static int maxTextureSize The maximum texture size allowed by generateData, when storing in a texture atlas. Multiple texture pages will be created if necessary. Default is 1024.
| |
| name | back to summary |
|---|---|
| pack-priv final String name | |
| NO_MAXIMUM | back to summary |
|---|---|
| public static final int NO_MAXIMUM A hint to scale the texture as needed, without capping it at any maximum size | |
| pixelHeight | back to summary |
|---|---|
| private int pixelHeight | |
| pixelWidth | back to summary |
|---|---|
| private int pixelWidth | |
| FreeTypeFontGenerator | back to summary |
|---|---|
| public FreeTypeFontGenerator(FileHandle fontFile) | |
| FreeTypeFontGenerator | back to summary |
|---|---|
| public FreeTypeFontGenerator(FileHandle fontFile, int faceIndex) Creates a new generator from the given font file. Uses | |
| checkForBitmapFont | back to summary |
|---|---|
| private boolean checkForBitmapFont() | |
| createGlyph | back to summary |
|---|---|
protected BitmapFont.
| |
| dispose | back to summary |
|---|---|
| public void dispose() Implements com. Cleans up all resources of the generator. Call this if you no longer use the generator.
| |
| generateData | back to summary |
|---|---|
| public FreeTypeFontGenerator. Generates a new
| |
| generateData | back to summary |
|---|---|
| public FreeTypeFontGenerator. | |
| generateData | back to summary |
|---|---|
| public FreeTypeFontGenerator. Generates a new
| |
| generateFont | back to summary |
|---|---|
| public BitmapFont generateFont(FreeTypeFontGenerator. | |
| generateFont | back to summary |
|---|---|
| public BitmapFont generateFont(FreeTypeFontGenerator. Generates a new
| |
| generateGlyphAndBitmap | back to summary |
|---|---|
| public FreeTypeFontGenerator. Returns null if glyph was not found in the font. If there is nothing to render, for example with various space characters,
then
| |
| getLoadingFlags | back to summary |
|---|---|
| private int getLoadingFlags(FreeTypeFontGenerator. | |
| getMaxTextureSize | back to summary |
|---|---|
| public static int getMaxTextureSize() Returns the maximum texture size that will be used by generateData() when creating a texture atlas for the glyphs.
| |
| hasGlyph | back to summary |
|---|---|
| public boolean hasGlyph(int charCode) check the font glyph exists for single UTF-32 code point | |
| loadChar | back to summary |
|---|---|
| private boolean loadChar(int c) | |
| loadChar | back to summary |
|---|---|
| private boolean loadChar(int c, int flags) | |
| newBitmapFont | back to summary |
|---|---|
| protected BitmapFont newBitmapFont(BitmapFont. Called by generateFont to create a new | |
| scaleForPixelHeight | back to summary |
|---|---|
| public int scaleForPixelHeight(int height) Uses ascender and descender of font to calculate real height that makes all glyphs to fit in given pixel size. Source: http://nothings.org/stb/stb_truetype.h / stbtt_ScaleForPixelHeight | |
| scaleForPixelWidth | back to summary |
|---|---|
| public int scaleForPixelWidth(int width, int numChars) Uses max advance, ascender and descender of font to calculate real height that makes any n glyphs to fit in given pixel width.
| |
| scaleToFitSquare | back to summary |
|---|---|
| public int scaleToFitSquare(int width, int height, int numChars) Uses max advance, ascender and descender of font to calculate real height that makes any n glyphs to fit in given pixel width and height.
| |
| setMaxTextureSize | back to summary |
|---|---|
| public static void setMaxTextureSize(int texSize) Sets the maximum size that will be used when generating texture atlases for glyphs with generateData(). The
default is 1024. By specifying
| |
| setPixelSizes | back to summary |
|---|---|
| pack-priv void setPixelSizes(int pixelWidth, int pixelHeight) | |
| 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- | |
BitmapFontData used for fonts generated via the FreeTypeFontGenerator. The texture storing the glyphs is
held in memory, thus the getImagePaths() and getFontFile() methods will return null.
| Modifier and Type | Field and Description |
|---|---|
| private boolean | |
| pack-priv FreeTypeFontGenerator | |
| pack-priv Array | |
| pack-priv PixmapPacker | |
| pack-priv FreeTypeFontGenerator. | |
| public Array | |
| pack-priv FreeType. |
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| public void | dispose()
Implements com. Releases all resources of this object. |
| public BitmapFont. | getGlyph(char ch)
Overrides com. Returns the glyph for the specified character, or null if no such glyph exists. |
| public void | getGlyphs(GlyphLayout.
Overrides com. Using the specified string, populates the glyphs and positions of the specified glyph run. |
| dirty | back to summary |
|---|---|
| private boolean dirty | |
| generator | back to summary |
|---|---|
| pack-priv FreeTypeFontGenerator generator | |
| glyphs | back to summary |
|---|---|
| pack-priv Array<BitmapFont. Hides com. | |
| packer | back to summary |
|---|---|
| pack-priv PixmapPacker packer | |
| parameter | back to summary |
|---|---|
| pack-priv FreeTypeFontGenerator. | |
| regions | back to summary |
|---|---|
| public Array<TextureRegion> regions | |
| stroker | back to summary |
|---|---|
| pack-priv FreeType. | |
| FreeTypeBitmapFontData | back to summary |
|---|---|
| public FreeTypeBitmapFontData() | |
| dispose | back to summary |
|---|---|
| public void dispose() Implements com. Doc from com. Releases all resources of this object.
| |
| getGlyph | back to summary |
|---|---|
| public BitmapFont. Overrides com. Doc from com. Returns the glyph for the specified character, or null if no such glyph exists. Note that
| |
| getGlyphs | back to summary |
|---|---|
| public void getGlyphs(GlyphLayout. Overrides com. Doc from com. Using the specified string, populates the glyphs and positions of the specified glyph run. | |
FreeTypeBitmapFontData and BitmapFont instances are
generated.
The packer field is for advanced usage, where it is necessary to pack multiple BitmapFonts (i.e. styles, sizes, families)
into a single Texture atlas. If no packer is specified, the generator will use its own PixmapPacker to pack the glyphs into
a power-of-two sized texture, and the resulting FreeTypeBitmapFontData will have a valid TextureRegion which
can be used to construct a new BitmapFont.
| Modifier and Type | Field and Description |
|---|---|
| public Color | borderColor
Border color; only used if borderWidth > 0 |
| public float | borderGamma
Values < 1 increase the border size. |
| public boolean | borderStraight
true for straight (mitered), false for rounded borders |
| public float | borderWidth
Border width in pixels, 0 to disable |
| public String | characters
The characters the font should contain. |
| public Color | color
Foreground color (required for non-black borders) |
| public boolean | flip
Whether to flip the font vertically |
| public float | gamma
Glyph gamma. |
| public boolean | genMipMaps
Whether to generate mip maps for the resulting texture |
| public FreeTypeFontGenerator. | hinting
Strength of hinting |
| public boolean | incremental
When true, glyphs are rendered on the fly to the font's glyph page textures as they are needed. |
| public boolean | kerning
Whether the font should include kerning |
| public Texture. | magFilter
Magnification filter |
| public Texture. | minFilter
Minification filter |
| public boolean | mono
If true, font smoothing is disabled. |
| public PixmapPacker | packer
The optional PixmapPacker to use for packing multiple fonts into a single texture. |
| public int | padBottom
Pixels to add to the glyph in the texture. |
| public int | padLeft
Pixels to add to the glyph in the texture. |
| public int | padRight
Pixels to add to the glyph in the texture. |
| public int | padTop
Pixels to add to the glyph in the texture. |
| public int | renderCount
Number of times to render the glyph. |
| public Color | shadowColor
Shadow color; only used if shadowOffset > 0. |
| public int | shadowOffsetX
Offset of text shadow on X axis in pixels, 0 to disable |
| public int | shadowOffsetY
Offset of text shadow on Y axis in pixels, 0 to disable |
| public int | size
The size in pixels |
| public int | spaceX
Pixels to add to glyph spacing when text is rendered. |
| public int | spaceY
Pixels to add to glyph spacing when text is rendered. |
| Access | Constructor and Description |
|---|---|
| public |
| borderColor | back to summary |
|---|---|
| public Color borderColor Border color; only used if borderWidth > 0 | |
| borderGamma | back to summary |
|---|---|
| public float borderGamma Values < 1 increase the border size. | |
| borderStraight | back to summary |
|---|---|
| public boolean borderStraight true for straight (mitered), false for rounded borders | |
| borderWidth | back to summary |
|---|---|
| public float borderWidth Border width in pixels, 0 to disable | |
| characters | back to summary |
|---|---|
| public String characters The characters the font should contain. If '\0' is not included then | |
| color | back to summary |
|---|---|
| public Color color Foreground color (required for non-black borders) | |
| flip | back to summary |
|---|---|
| public boolean flip Whether to flip the font vertically | |
| gamma | back to summary |
|---|---|
| public float gamma Glyph gamma. Values > 1 reduce antialiasing. | |
| genMipMaps | back to summary |
|---|---|
| public boolean genMipMaps Whether to generate mip maps for the resulting texture | |
| hinting | back to summary |
|---|---|
| public FreeTypeFontGenerator. Strength of hinting | |
| incremental | back to summary |
|---|---|
| public boolean incremental When true, glyphs are rendered on the fly to the font's glyph page textures as they are needed. The
FreeTypeFontGenerator must not be disposed until the font is no longer needed. The FreeTypeBitmapFontData must be
disposed (separately from the generator) when the font is no longer needed. The FreeTypeFontParameter should not be
modified after creating a font. If a PixmapPacker is not specified, the font glyph page textures will use
| |
| kerning | back to summary |
|---|---|
| public boolean kerning Whether the font should include kerning | |
| magFilter | back to summary |
|---|---|
| public Texture. Magnification filter | |
| minFilter | back to summary |
|---|---|
| public Texture. Minification filter | |
| mono | back to summary |
|---|---|
| public boolean mono If true, font smoothing is disabled. | |
| packer | back to summary |
|---|---|
| public PixmapPacker packer The optional PixmapPacker to use for packing multiple fonts into a single texture.
| |
| padBottom | back to summary |
|---|---|
| public int padBottom Pixels to add to the glyph in the texture. Cannot be negative. | |
| padLeft | back to summary |
|---|---|
| public int padLeft Pixels to add to the glyph in the texture. Cannot be negative. | |
| padRight | back to summary |
|---|---|
| public int padRight Pixels to add to the glyph in the texture. Cannot be negative. | |
| padTop | back to summary |
|---|---|
| public int padTop Pixels to add to the glyph in the texture. Cannot be negative. | |
| renderCount | back to summary |
|---|---|
| public int renderCount Number of times to render the glyph. Useful with a shadow or border, so it doesn't show through the glyph. | |
| shadowColor | back to summary |
|---|---|
| public Color shadowColor Shadow color; only used if shadowOffset > 0. If alpha component is 0, no shadow is drawn but characters are still offset by shadowOffset. | |
| shadowOffsetX | back to summary |
|---|---|
| public int shadowOffsetX Offset of text shadow on X axis in pixels, 0 to disable | |
| shadowOffsetY | back to summary |
|---|---|
| public int shadowOffsetY Offset of text shadow on Y axis in pixels, 0 to disable | |
| size | back to summary |
|---|---|
| public int size The size in pixels | |
| spaceX | back to summary |
|---|---|
| public int spaceX Pixels to add to glyph spacing when text is rendered. Can be negative. | |
| spaceY | back to summary |
|---|---|
| public int spaceY Pixels to add to glyph spacing when text is rendered. Can be negative. | |
| FreeTypeFontParameter | back to summary |
|---|---|
| public FreeTypeFontParameter() | |
| Modifier and Type | Field and Description |
|---|---|
| public FreeType. | |
| public BitmapFont. |
| Access | Constructor and Description |
|---|---|
| public |
| bitmap | back to summary |
|---|---|
| public FreeType. | |
| glyph | back to summary |
|---|---|
| public BitmapFont. | |
| GlyphAndBitmap | back to summary |
|---|---|
| public GlyphAndBitmap() | |
| Modifier and Type | Field and Description |
|---|---|
| public static final FreeTypeFontGenerator. | AutoFull
Strong hinting with crisp edges at the expense of shape fidelity. |
| public static final FreeTypeFontGenerator. | AutoMedium
Average hinting. |
| public static final FreeTypeFontGenerator. | AutoSlight
Light hinting with fuzzy edges, but close to the original shape. |
| public static final FreeTypeFontGenerator. | Full
Strong hinting with crisp edges at the expense of shape fidelity |
| public static final FreeTypeFontGenerator. | Medium
Average hinting |
| public static final FreeTypeFontGenerator. | None
Disable hinting. |
| public static final FreeTypeFontGenerator. | Slight
Light hinting with fuzzy edges, but close to the original shape |
| Access | Constructor and Description |
|---|---|
| private |
| Modifier and Type | Method and Description |
|---|---|
| public static FreeTypeFontGenerator. | |
| public static FreeTypeFontGenerator. |
| AutoFull | back to summary |
|---|---|
| public static final FreeTypeFontGenerator. Strong hinting with crisp edges at the expense of shape fidelity. Uses the FreeType auto-hinter. | |
| AutoMedium | back to summary |
|---|---|
| public static final FreeTypeFontGenerator. Average hinting. Uses the FreeType auto-hinter. | |
| AutoSlight | back to summary |
|---|---|
| public static final FreeTypeFontGenerator. Light hinting with fuzzy edges, but close to the original shape. Uses the FreeType auto-hinter. | |
| Full | back to summary |
|---|---|
| public static final FreeTypeFontGenerator. Strong hinting with crisp edges at the expense of shape fidelity | |
| Medium | back to summary |
|---|---|
| public static final FreeTypeFontGenerator. Average hinting | |
| None | back to summary |
|---|---|
| public static final FreeTypeFontGenerator. Disable hinting. Generated glyphs will look blurry. | |
| Slight | back to summary |
|---|---|
| public static final FreeTypeFontGenerator. Light hinting with fuzzy edges, but close to the original shape | |
| Hinting | back to summary |
|---|---|
| private Hinting() | |
| valueOf | back to summary |
|---|---|
| public static FreeTypeFontGenerator. | |
| values | back to summary |
|---|---|
| public static FreeTypeFontGenerator. | |