| 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; |