"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.registerFont = registerFont;
exports.loadFonts = loadFonts;
const node_fs_1 = __importDefault(require("node:fs"));
const node_path_1 = __importDefault(require("node:path"));
const canvas_1 = require("@napi-rs/canvas");
const errors_1 = require("../errors");
function registerFont(fontPath, family) {
    if (!node_fs_1.default.existsSync(fontPath)) {
        throw new errors_1.KythiaArtsError(`Font file not found: ${fontPath}`);
    }
    try {
        return canvas_1.GlobalFonts.registerFromPath(fontPath, family);
    }
    catch (error) {
        throw new errors_1.KythiaArtsError(`Failed to register font: ${error.message}`);
    }
}
function loadFonts(directory) {
    if (!node_fs_1.default.existsSync(directory)) {
        return 0;
    }
    const files = node_fs_1.default.readdirSync(directory);
    const fontExtensions = ['.ttf', '.otf', '.woff', '.woff2'];
    let count = 0;
    for (const file of files) {
        const ext = node_path_1.default.extname(file).toLowerCase();
        if (fontExtensions.includes(ext)) {
            const fontPath = node_path_1.default.join(directory, file);
            const family = node_path_1.default.basename(file, ext);
            try {
                registerFont(fontPath, family);
                count++;
            }
            catch {
            }
        }
    }
    return count;
}
//# sourceMappingURL=fonts.js.map