APIdia Launch Partner
Top Description Inners Fields Constructors Methods
com.badlogic.gdx.tools.bmfont

public Class BitmapFontWriter

extends Object
Class Inheritance
Imports
com.badlogic.gdx.files.FileHandle, com.badlogic.gdx.graphics.Pixmap, .PixmapIO, com.badlogic.gdx.graphics.g2d.BitmapFont.BitmapFontData, .BitmapFont.Glyph, .PixmapPacker.Page, com.badlogic.gdx.utils.Array

A utility to output BitmapFontData to a FNT file. This can be useful for caching the result from TrueTypeFont, for faster load times.

The font file format is from the AngelCodeFont BMFont tool.

Output is nearly identical to the FreeType settting in the Hiero tool com.badlogic.gdx.tools.hiero.Hiero. BitmapFontWriter gives more flexibility, eg borders and shadows can be used. Hiero is able to avoid outputting the same glyph image more than once if multiple character codes have the exact same glyph.

Author
mattdesl AKA davedes

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static class
BitmapFontWriter.FontInfo

The font "info" line; everything except padding and override metrics are ignored by libGDX's BitmapFont reader, it is otherwise just useful for clean and organized output.

public static enum
public static class
BitmapFontWriter.Padding

The Padding parameter for FontInfo.

public static class
BitmapFontWriter.Spacing

The spacing parameter for FontInfo.

Field Summary

Modifier and TypeField and Description
private static BitmapFontWriter.OutputFormat
format

The output format

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public static BitmapFontWriter.OutputFormat

Returns:

the output format
getOutputFormat
()

Returns the currently used output format.

private static String
quote(Object params)

private static String
quote(Object params, boolean spaceAfter)

public static void
setOutputFormat(BitmapFontWriter.OutputFormat
the output format to use
fmt
)

Sets the AngelCodeFont output format for subsequent writes; can be text (for libGDX) or XML (for other engines, like Pixi.js).

public static void
writeFont(BitmapFont.BitmapFontData
the bitmap font
fontData
,
String[]
the references to each texture page image file, generally in the same folder as outFntFile
pageRefs
,
FileHandle
the font file to save to (typically ends with '.fnt')
outFntFile
,
BitmapFontWriter.FontInfo
the optional info for the file header; can be null
info
,
int
the width of your texture pages
scaleW
,
int
the height of your texture pages
scaleH
)

Writes the given BitmapFontData to a file, using the specified pageRefs strings as the image paths for each texture page.

public static void
writeFont(BitmapFont.BitmapFontData
the font data
fontData
,
Pixmap[]
the pixmaps to write as PNGs
pages
,
FileHandle
the output file for the font definition
outFntFile
,
BitmapFontWriter.FontInfo
the optional font info for the header file, can be null
info
)

A utility method which writes the given font data to a file.

public static String[]

Returns:

the array of string references to be used with writeFont
writePixmaps
(Pixmap[]
the pages of pixmap data to write
pages
,
FileHandle
the output directory
outputDir
,
String
the file names for the output images
fileName
)

A utility method to write the given array of pixmaps to the given output directory, with the specified file name.

public static String[]

Returns:

the file refs
writePixmaps
(Array<PixmapPacker.Page>
the pages containing the Pixmaps
pages
,
FileHandle
the output directory
outputDir
,
String
the file name
fileName
)

A convenience method to write pixmaps by page; typically returned from a PixmapPacker when used alongside FreeTypeFontGenerator.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

formatback to summary
private static BitmapFontWriter.OutputFormat format

The output format

Constructor Detail

BitmapFontWriterback to summary
public BitmapFontWriter()

Method Detail

getOutputFormatback to summary
public static BitmapFontWriter.OutputFormat getOutputFormat()

Returns the currently used output format.

Returns:BitmapFontWriter.OutputFormat

the output format

quoteback to summary
private static String quote(Object params)
quoteback to summary
private static String quote(Object params, boolean spaceAfter)
setOutputFormatback to summary
public static void setOutputFormat(BitmapFontWriter.OutputFormat fmt)

Sets the AngelCodeFont output format for subsequent writes; can be text (for libGDX) or XML (for other engines, like Pixi.js).

Parameters
fmt:BitmapFontWriter.OutputFormat

the output format to use

writeFontback to summary
public static void writeFont(BitmapFont.BitmapFontData fontData, String[] pageRefs, FileHandle outFntFile, BitmapFontWriter.FontInfo info, int scaleW, int scaleH)

Writes the given BitmapFontData to a file, using the specified pageRefs strings as the image paths for each texture page. The glyphs in BitmapFontData have a "page" id, which references the index of the pageRef you specify here. The FontInfo parameter is useful for cleaner output; such as including a size and font face name hint. However, it can be null to use default values. libGDX ignores most of the "info" line when reading back fonts, only padding is used. Padding also affects the size, location, and offset of the glyphs that are output. Likewise, the scaleW and scaleH are only for cleaner output. They are currently ignored by libGDX's reader. For maximum compatibility with other BMFont tools, you should use the width and height of your texture pages (each page should be the same size).

Parameters
fontData:BitmapFont.BitmapFontData

the bitmap font

pageRefs:String[]

the references to each texture page image file, generally in the same folder as outFntFile

outFntFile:FileHandle

the font file to save to (typically ends with '.fnt')

info:BitmapFontWriter.FontInfo

the optional info for the file header; can be null

scaleW:int

the width of your texture pages

scaleH:int

the height of your texture pages

writeFontback to summary
public static void writeFont(BitmapFont.BitmapFontData fontData, Pixmap[] pages, FileHandle outFntFile, BitmapFontWriter.FontInfo info)

A utility method which writes the given font data to a file. The specified pixmaps are written to the parent directory of outFntFile, using that file's name without an extension for the PNG file name(s). The specified FontInfo is optional, and can be null. Typical usage looks like this:

BitmapFontWriter.writeFont(myFontData, myFontPixmaps, Gdx.files.external("fonts/output.fnt"), new FontInfo("Arial", 16));
Parameters
fontData:BitmapFont.BitmapFontData

the font data

pages:Pixmap[]

the pixmaps to write as PNGs

outFntFile:FileHandle

the output file for the font definition

info:BitmapFontWriter.FontInfo

the optional font info for the header file, can be null

writePixmapsback to summary
public static String[] writePixmaps(Pixmap[] pages, FileHandle outputDir, String fileName)

A utility method to write the given array of pixmaps to the given output directory, with the specified file name. If the pages array is of length 1, then the resulting file ref will look like: "fileName.png". If the pages array is greater than length 1, the resulting file refs will be appended with "_N", such as "fileName_0.png", "fileName_1.png", "fileName_2.png" etc. The returned string array can then be passed to the writeFont method.

Note

None of the pixmaps will be disposed.

Parameters
pages:Pixmap[]

the pages of pixmap data to write

outputDir:FileHandle

the output directory

fileName:String

the file names for the output images

Returns:String[]

the array of string references to be used with writeFont

writePixmapsback to summary
public static String[] writePixmaps(Array<PixmapPacker.Page> pages, FileHandle outputDir, String fileName)

A convenience method to write pixmaps by page; typically returned from a PixmapPacker when used alongside FreeTypeFontGenerator.

Parameters
pages:Array<PixmapPacker.Page>

the pages containing the Pixmaps

outputDir:FileHandle

the output directory

fileName:String

the file name

Returns:String[]

the file refs

com.badlogic.gdx.tools.bmfont back to summary

public Class BitmapFontWriter.FontInfo

extends Object
Class Inheritance

The font "info" line; everything except padding and override metrics are ignored by libGDX's BitmapFont reader, it is otherwise just useful for clean and organized output.

Field Summary

Modifier and TypeField and Description
public int
aa

Amount of anti-aliasing that was applied to the font

public float
public boolean
bold

Whether the font is bold

public float
public String
charset

The charset; or null/empty for default

public float
public float
public String
face

Face name

public boolean
hasOverrideMetrics

Override metrics

public boolean
italic

Whether the font is italic

public float
public int
public BitmapFontWriter.Padding
padding

Padding that was applied to the font

public int
size

Font size (pt)

public boolean
smooth

Whether smoothing is applied

public float
public BitmapFontWriter.Spacing
spacing

Horizontal/vertical spacing that was applied to font

public int
stretchH

Stretch for height; default to 100%

public boolean
unicode

Whether the font uses unicode glyphs

public float

Constructor Summary

AccessConstructor and Description
public
public
FontInfo(String face, int size)

Method Summary

Modifier and TypeMethod and Description
public void
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

aaback to summary
public int aa

Amount of anti-aliasing that was applied to the font

ascentback to summary
public float ascent
boldback to summary
public boolean bold

Whether the font is bold

capHeightback to summary
public float capHeight
charsetback to summary
public String charset

The charset; or null/empty for default

descentback to summary
public float descent
downback to summary
public float down
faceback to summary
public String face

Face name

hasOverrideMetricsback to summary
public boolean hasOverrideMetrics

Override metrics

italicback to summary
public boolean italic

Whether the font is italic

lineHeightback to summary
public float lineHeight
outlineback to summary
public int outline
paddingback to summary
public BitmapFontWriter.Padding padding

Padding that was applied to the font

sizeback to summary
public int size

Font size (pt)

smoothback to summary
public boolean smooth

Whether smoothing is applied

spaceXAdvanceback to summary
public float spaceXAdvance
spacingback to summary
public BitmapFontWriter.Spacing spacing

Horizontal/vertical spacing that was applied to font

stretchHback to summary
public int stretchH

Stretch for height; default to 100%

unicodeback to summary
public boolean unicode

Whether the font uses unicode glyphs

xHeightback to summary
public float xHeight

Constructor Detail

FontInfoback to summary
public FontInfo()
FontInfoback to summary
public FontInfo(String face, int size)

Method Detail

overrideMetricsback to summary
public void overrideMetrics(BitmapFont.BitmapFontData data)
com.badlogic.gdx.tools.bmfont back to summary

public final Enum BitmapFontWriter.OutputFormat

extends Enum<BitmapFontWriter.OutputFormat>
Class Inheritance

The output format.

Field Summary

Modifier and TypeField and Description
public static final BitmapFontWriter.OutputFormat
Text

AngelCodeFont text format

public static final BitmapFontWriter.OutputFormat
XML

AngelCodeFont XML format

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public static BitmapFontWriter.OutputFormat
public static BitmapFontWriter.OutputFormat[]
Inherited from java.lang.Enum:
clonecompareTodescribeConstableequalsfinalizegetDeclaringClasshashCodenameordinaltoStringvalueOf

Field Detail

Textback to summary
public static final BitmapFontWriter.OutputFormat Text

AngelCodeFont text format

XMLback to summary
public static final BitmapFontWriter.OutputFormat XML

AngelCodeFont XML format

Constructor Detail

OutputFormatback to summary
private OutputFormat()

Method Detail

valueOfback to summary
public static BitmapFontWriter.OutputFormat valueOf(String name)
valuesback to summary
public static BitmapFontWriter.OutputFormat[] values()
com.badlogic.gdx.tools.bmfont back to summary

public Class BitmapFontWriter.Padding

extends Object
Class Inheritance

The Padding parameter for FontInfo.

Field Summary

Modifier and TypeField and Description
public int
public int
public int
public int

Constructor Summary

AccessConstructor and Description
public
public
Padding(int up, int down, int left, int right)

Method Summary

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

downback to summary
public int down
leftback to summary
public int left
rightback to summary
public int right
upback to summary
public int up

Constructor Detail

Paddingback to summary
public Padding()
Paddingback to summary
public Padding(int up, int down, int left, int right)
com.badlogic.gdx.tools.bmfont back to summary

public Class BitmapFontWriter.Spacing

extends Object
Class Inheritance

The spacing parameter for FontInfo.

Field Summary

Modifier and TypeField and Description
public int
public int

Constructor Summary

AccessConstructor and Description
public

Method Summary

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

horizontalback to summary
public int horizontal
verticalback to summary
public int vertical

Constructor Detail

Spacingback to summary
public Spacing()