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