BitmapFontParser
Parser for bitmap font definition files in BMFont format.
BitmapFontParser reads and parses font definition files (.fnt) that describe bitmap font layouts. It supports both plain text and XML formats commonly generated by tools like:
- BMFont (AngelCode)
- Hiero
- msdf-bmfont-xml
The parser extracts:
- Font metadata (face, size, line height)
- Character definitions with texture coordinates
- Texture page references
- Kerning pairs
- Distance field information (for MSDF fonts)
// Parse a font definition file
var fontData = BitmapFontParser.parse(fontFileContent);
// Create textures from the page files
var textures = new Map<String,Texture>();
for (page in fontData.pages) {
textures.set(page.file, loadTexture(page.file));
}
// Create the font
var font = new BitmapFont(fontData, textures);
Static Members
parse(rawFontData: String): BitmapFontData
Parses a bitmap font definition file into structured data.
Accepts both plain text (.fnt) and XML (.xml) formats. XML format is automatically detected and converted to text format before parsing.
Name | Type | Description |
---|---|---|
rawFontData |
String | The raw content of the font definition file |
Returns | Description |
---|---|
BitmapFontData | Parsed font data ready for use with BitmapFont |
Private Members
Converts XML format font data to plain text format.
XML format is commonly used by tools like Hiero and msdf-bmfont-xml. This method transforms the XML structure into the text-based format that the parser expects internally.
Name | Type | Description |
---|---|---|
rawFontData |
String | XML font definition content |
Returns | Description |
---|---|
String | Equivalent font data in plain text format |
parseLine(line: String, info: BitmapFontData): Void
Parses a single line of font definition data.
Each line starts with a token identifying the data type:
info
: Font face and sizecommon
: Line height and base sizepage
: Texture page definitionchars
: Character countchar
: Individual character metricskerning
: Kerning pair datadistanceField
: MSDF configuration
Name | Type | Description |
---|---|---|
line |
String | A single line from the font file |
info |
BitmapFontData | The font data structure to populate |
Extracts key-value pairs from a font definition line.
Parses lines in the format: token key1=value1 key2="quoted value"
Handles both quoted and unquoted values, with proper escape sequence support.
Name | Type | Description |
---|---|---|
line |
String | The line to parse |
map |
Map | Output map to populate with key-value pairs |
Returns | Description |
---|---|
String | The first token on the line (e.g., "char", "info") |
Removes surrounding quotes from a string if present.
Used to clean up quoted values from the font file. Only removes quotes if they exist at both start and end.
Name | Type | Description |
---|---|---|
s |
String | The string to unquote |
Returns | Description |
---|---|
String | The string without surrounding quotes |