string-to-svg
Version:
Convert text to SVG path without native dependence.
40 lines (38 loc) • 871 B
JavaScript
import {
getD,
getHeight,
getMetrics,
getPath,
getWidth
} from "./chunk-3RXCOM3X.js";
// src/node.ts
import { join } from "path";
import { loadSync, Font } from "opentype.js";
function loadFont(fontPath) {
const path = join(__dirname, fontPath);
return loadSync(path);
}
function getSVG(text, options) {
if (!options.font) {
options.font = loadFont("../fonts/ipag.ttf");
}
const metrics = getMetrics(text, options);
let svg = `<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="${metrics.width}" height="${metrics.height}">`;
if (options.beforePath)
svg += options.beforePath;
svg += getPath(text, options);
if (options.afterPath)
svg += options.afterPath;
svg += "</svg>";
return svg;
}
export {
Font,
getD,
getHeight,
getMetrics,
getPath,
getSVG,
getWidth,
loadFont
};