BitmapFont
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.
Instance Members
Maps texture page IDs to their corresponding textures. A bitmap font can span multiple texture pages to accommodate large character sets.
face: String
The font face name (e.g. "Arial", "Roboto"). This is metadata from the font file.
pointSize: Float
The point size the font was generated at. This is the reference size for all metrics in the font data.
baseSize: Float
The base size used during font generation. Often the same as pointSize but can differ based on the font tool used.
chars: IntMap<BitmapFontCharacter>
Map of character codes to their corresponding glyph data. Each character contains texture coordinates, size, and offset information.
charCount: Int
Total number of characters defined in this font. Useful for statistics and validation.
lineHeight: Float
The recommended line height for this font in pixels. Used for vertical spacing between lines of text.
kernings: IntMap<IntFloatMap>
Kerning data for character pairs. First level maps from first character to second character to kerning amount. Kerning adjusts spacing between specific character pairs for better appearance.
msdf: 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
Custom shaders used for rendering characters, stored per texture page. Automatically set up for MSDF fonts using ceramic's MSDF shader.
preRenderedPages: Map
Pre-rendered textures for different font sizes, stored per page and size. Used to optimize rendering performance by caching commonly used sizes.
asset: Asset
Reference to the asset that created this font. Used for proper resource management.
destroy(): Void
Cleans up all resources associated with this font including textures, shaders, and pre-rendered pages.
Checks if the font needs to be pre-rendered at a specific pixel size.
Name | Type | Description |
---|---|---|
pixelSize |
Int | The target size in pixels |
Returns | Description |
---|---|
Bool | True if pre-rendering is needed, false otherwise |
Pre-renders the font at a specific pixel size. Useful for optimizing rendering performance for frequently used sizes.
Name | Type | Description |
---|---|---|
pixelSize |
Int | The target size in pixels |
done |
Function | Callback function called when pre-rendering is complete |
Gets the kerning amount between two characters. Kerning improves text appearance by adjusting the space between specific character pairs.
Name | Type | Description |
---|---|---|
first |
Int | The character code of the first glyph |
second |
Int | The character code of the second glyph |
Returns | Description |
---|---|
Float | The kerning amount (0 if no kerning is defined) |
new(fontData: BitmapFontData, pages: Map): Void
Creates a new BitmapFont instance.
Name | Type | Description |
---|---|---|
fontData |
BitmapFontData | The font data containing metrics and character information |
pages |
Map | A map of texture file paths to their corresponding textures |
Private Members
fontData: BitmapFontData
The core data structure containing all font information including character metrics, kerning data, and texture coordinates.
Internal method to pre-render a specific texture page at given size.
Name | Type | Description |
---|---|---|
id |
Int | The texture page ID |
pixelsSize |
Int | The target size in pixels |
done |
Function | Callback function called when pre-rendering is complete |
Metadata
Name | Parameters |
---|---|
:build |
ceramic.macros.EntityMacro.buildForCompletion() |
:autoBuild |
ceramic.macros.EntityMacro.buildForCompletion() |
:build |
tracker.macros.EventsMacro.build() |
:autoBuild |
tracker.macros.EventsMacro.build() |