mirror of
https://git.undefined-dev.fr/Blendman974/faceclaw.git
synced 2026-11-19 21:03:09 +00:00
17 lines
655 B
TypeScript
17 lines
655 B
TypeScript
import { LvglFont } from '../graphics/lvgl-font'
|
|
import { readBinaryFile } from './file-access'
|
|
const cache = new Map<string, LvglFont>()
|
|
function load(path: string): LvglFont {
|
|
let font = cache.get(path)
|
|
if (!font) {
|
|
const bytes = readBinaryFile(path)
|
|
if (!bytes) throw new Error('Cannot read LVGL font')
|
|
font = new LvglFont(bytes)
|
|
if (cache.size >= 2) cache.delete(cache.keys().next().value!)
|
|
cache.set(path, font)
|
|
}
|
|
return font
|
|
}
|
|
export function lvglMetrics(path: string): Uint8Array { return load(path).metrics }
|
|
export function lvglGlyph(path: string, codePoint: number): Uint8Array { return load(path).glyph(codePoint) }
|