MCPcopy Create free account
hub / github.com/esengine/esengine / loadFont

Method loadFont

packages/fairygui/src/render/Canvas2DBackend.ts:192–211  ·  view source on GitHub ↗
(family: string, url?: string)

Source from the content-addressed store, hash-verified

190 }
191
192 public async loadFont(family: string, url?: string): Promise<IFontHandle> {
193 const font = new Canvas2DFont(family);
194
195 if (url) {
196 try {
197 const fontFace = new FontFace(family, `url(${url})`);
198 await fontFace.load();
199 // Use type assertion for FontFaceSet.add which exists in browsers
200 (document.fonts as unknown as { add(font: FontFace): void }).add(fontFace);
201 font.setLoaded();
202 } catch (error) {
203 console.error(`Failed to load font: ${family}`, error);
204 }
205 } else {
206 // Assume system font is available
207 font.setLoaded();
208 }
209
210 return font;
211 }
212
213 public resize(width: number, height: number): void {
214 if (!this._canvas) return;

Callers

nothing calls this directly

Calls 4

setLoadedMethod · 0.95
loadMethod · 0.65
addMethod · 0.45
errorMethod · 0.45

Tested by

no test coverage detected