registerFontバージョン: v2.0
目次
registerFont()
@napi-rs/canvas のレンダリングヘルパーで使用するフォントを登録します。
ローカルファイルパスは絶対パスである必要があります。リモートフォントは https:// を使用してください。
パラメーター
Section titled “パラメーター”| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
| pathOrURL | string | ✅ | フォントファイルへの絶対パス、または HTTPS URL。 | |
| name | string | ✅ | フォント名。 | |
| timeout | number | ❌ | 1500 | リクエストのタイムアウト (URL のフォントを使う場合)。 |
- Promise<
void>
XpFatal- 無効なパラメーターが渡された場合。
[JS] 例
Section titled “[JS] 例”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);