CachingFontDriver

A caching implementation of FontDriver that wraps another driver to avoid loading the same face repeatedly.

CachingFontDriver keeps one base face per fileOrUrl, data: urls are kept by their SHA-256 digest, so the cache does not hold the font data in them. Every call to loadFace returns a new face obtained through Face.withSize on the base face, which shares the font data with it. Each returned face is owned by the caller and can be closed independently; the shared font data is freed once the base face and all faces derived from it are closed.

Constructors

Link copied to clipboard
constructor(driver: FontDriver)

Properties

Link copied to clipboard

The underlying FontDriver used to load faces that are not in the cache.

Link copied to clipboard
val size: Int

the number of cached base faces

Functions

Link copied to clipboard
fun clear()
Link copied to clipboard
open override fun loadFace(fileOrUrl: String): Face

Load a face at DEFAULT_SIZE_IN_POINTS, use Face.withSize to obtain the face at other sizes

Link copied to clipboard
open suspend override fun loadFaceSuspend(fileOrUrl: String): Face

Load a face at DEFAULT_SIZE_IN_POINTS without blocking, drivers that load fonts asynchronously, like in browsers, override this