A bitmap font implementation that handles both regular bitmap fonts and MSDF (Multi-channel Signed Distance Field) fonts. This class manages font textures, character data, kerning, and optional pre-rendering of characters. It supports multiple texture pages and custom shaders, particularly useful for MSDF fonts.
Constructor
new(fontData:BitmapFontData, pages:Map<String, Texture>)
Creates a new BitmapFont instance.
Parameters:
fontData | The font data containing metrics and character information |
---|---|
pages | A map of texture file paths to their corresponding textures |
Throws:
String | if fontData or pages are null |
---|
Variables
pages:IntMap<Texture> = new IntMap(16, 0.5, true)
Maps texture page IDs to their corresponding textures. A bitmap font can span multiple texture pages to accommodate large character sets.
read onlymsdf:Bool
Indicates if this font is an MSDF (Multi-channel Signed Distance Field) font. MSDF fonts provide superior scaling quality compared to regular bitmap fonts.
spaceChar:BitmapFontCharacter
Cached reference to the space character (ASCII 32). Used for efficient spacing calculations in text rendering.
pageShaders:Map<Int, Shader> = null
Custom shaders used for rendering characters, stored per texture page. Automatically set up for MSDF fonts using ceramic's MSDF shader.
Methods
destroy():Void
Cleans up all resources associated with this font including textures, shaders, and pre-rendered pages.
needsToPreRenderAtSize(pixelSize:Int):Bool
Checks if the font needs to be pre-rendered at a specific pixel size.
Parameters:
pixelSize | The target size in pixels |
---|
Returns:
True if pre-rendering is needed, false otherwise
preRenderAtSize(pixelSize:Int, done:() ‑> Void):Void
Pre-renders the font at a specific pixel size. Useful for optimizing rendering performance for frequently used sizes.
Parameters:
pixelSize | The target size in pixels |
---|---|
done | Callback function called when pre-rendering is complete |
inlinekerning(first:Int, second:Int):Float
Gets the kerning amount between two characters. Kerning improves text appearance by adjusting the space between specific character pairs.
Parameters:
first | The character code of the first glyph |
---|---|
second | The character code of the second glyph |
Returns:
The kerning amount (0 if no kerning is defined)