registerFont
On this page
registerFont()
Register fonts for @napi-rs/canvas rendering helpers.
Local file paths must be absolute. Remote fonts must use https://.
Parameters
Section titled “Parameters”| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
| pathOrURL | string | ✅ | Absolute file path or HTTPS URL to the font file. | |
| name | string | ✅ | The name of the font. | |
| timeout | number | ❌ | 1500 | Request timeout in milliseconds (IF FONT IS A URL). |
Returns
Section titled “Returns”- Promise<
void>
Throws
Section titled “Throws”XpFatal- If invalid parameters are provided.
[JS] Example
Section titled “[JS] Example”const { registerFont } = require("simply-xp");const path = require("path");
(async () => { await registerFont( "https://cdn.jsdelivr.net/fontsource/fonts/mochiy-pop-one@latest/japanese-400-normal.woff2", "MochiyPopOne" );
await registerFont( path.resolve(__dirname, "fonts", "MochiyPopOne.ttf"), "MochiyPopOne" );})().catch(console.error);