MinecraftFontEngine

class MinecraftFontEngine @JvmOverloads constructor(snapshot: MinecraftFontSnapshot, backendFactory: MinecraftFontBackendFactory, cacheEntries: Int = 4096, cacheBytes: Long = 16L * 1024L * 1024L, maxFaces: Int = 16) : AutoCloseable(source)

Owner-thread portable glyph engine for one immutable resource state. The engine owns its backend and native faces, while returned glyphs retain only detached pixels and metrics. Its access-ordered raster cache is bounded by both entry count and pixel bytes; large values bypass the cache. Sheets share detached resource identity; bitmap scans share resource, grid, and cell identity with one current metric result per cell. TrueType faces and glyphs share resource and exact settings, with provider skips checked before glyph lookup. Other glyphs use snapshot-local provider identities and Unicode scalars; changing resources, limits, or options requires a new engine. Decoded dimensions and detached failure messages are bounded by the current snapshot's resources and settings, even with raster caching disabled. Native faces have an independent entry bound of at most 16 and a combined encoded-input ceiling equal to the snapshot's maxAssetBytes. Eviction closes faces before opening replacements; successful descriptor checks survive eviction without retaining native state. Preallocation-limit failures occupy ordinary bounded glyph-cache entries and retain only a message. A backend returning an image beyond its allocation contract permanently disables that face descriptor and closes its live face. Closing clears snapshot, cache, and native references and never invalidates returned glyphs. Glyph selection, cache eviction, and terminal cleanup share this owner to preserve resource lifetime boundaries.

Parameters

snapshot

immutable font definitions and resource bytes, safely reusable by other engines.

backendFactory

creates the independently owned CPU backend.

cacheEntries

maximum combined cached glyph or cell results and decoded bitmap sheets; zero disables raster caching.

cacheBytes

maximum retained raster pixel bytes; zero disables pixel caching.

maxFaces

maximum concurrently retained native faces, from 1 through 16.

Throws

when a raster cache bound is negative or the face bound is outside 1 through 16.

when the backend cannot be opened.

Constructors

Link copied to clipboard
constructor(snapshot: MinecraftFontSnapshot, backendFactory: MinecraftFontBackendFactory, cacheEntries: Int = 4096, cacheBytes: Long = 16L * 1024L * 1024L, maxFaces: Int = 16)

Properties

Link copied to clipboard

Immutable release capabilities captured by this still-open owner-thread engine.

Link copied to clipboard

Detached resource and provider-load diagnostics accumulated by this owner-thread engine.

Link copied to clipboard

Immutable selection options captured by this still-open owner-thread engine.

Link copied to clipboard

Number of currently retained native faces; zero after close.

Link copied to clipboard

Total copied pixel payload retained by the cache, excluding caller-owned returned runs.

Link copied to clipboard

Number of cached glyph results and bitmap sheets; readable after owner-thread close.

Functions

Link copied to clipboard
open override fun close()

Releases native faces and backend ownership exactly once on the owner thread. Cleanup continues after failures; the first failure remains primary and distinct later failures are suppressed once.

Link copied to clipboard
fun glyph(font: ResourceId, codePoint: Int): MinecraftFontGlyph

Resolves the first applicable provider for one Unicode scalar. Every provider is preflighted before filtering, so a failed disabled provider still invalidates its bundle. Unknown fonts and missing glyphs return the native missing-glyph shape instead of silently selecting the default font. Atlas-rejected rasters use the missing shape with the selected release's advance behavior. Successful providers retain native non-finite metrics without permitting them into portable drawing geometry. This operation performs only derived work and never calls a tree or mutates application state.

Link copied to clipboard
fun visualGlyphs(text: String, rightToLeft: Boolean = options.rightToLeft): List<MinecraftVisualGlyph>

Shapes and orders a complete logical line while retaining original UTF-16 scalar positions for font inheritance. Positions precede shaping and bidirectional reordering; contractions belong to their first contributing scalar. No input or derived run is retained by the engine.

Link copied to clipboard
fun visualOrder(text: String, rightToLeft: Boolean = options.rightToLeft): String

Uses the selected backend's native-compatible text ordering without retaining the input string.