The Complete Production SOP: How to Deploy and Run opentype.js Vector Font Glyphs & Metrics in Autonomous AI Agents
Step-by-step SOP to install and run opentype.js Vector Font Glyphs & Metrics in Codex, Claude Code, and Cursor. Extract paths and metrics reliably.
Technical Overview & Architectural Context
Autonomous coding agents frequently hallucinate typographic coordinate math and font parsing mechanics when tasked with rendering vector typography. Without deterministic boundaries, agents attempt naive geometric conversions, generate malformed SVG `<path d="...">` strings, miss kerning table pairs (`GPOS` / `kern`), or invoke DOM-dependent APIs such as `document.createElement('canvas')` within headless Node.js environments. These flaws break build pipelines, misalign text bounding boxes, and corrupt Bezier curve control points. The `opentype-js-font-path-metrics` skill enforces rigorous procedural guardrails for LLMs across Codex, Claude Code, Cursor, and Windsurf. By constraining the agent to opentype.js deterministic APIs—such as `font.getPath()`, `font.getPaths()`, `path.toSVG()`, and `path.getBoundingBox()`—it guarantees exact baseline, ascender, descender, and advance width calculations across TrueType (TTF), OpenType (OTF), and WOFF binary formats without DOM hallucinations.
Prerequisites & Environment Requirements
Verified Search Intents & Long-Tail Queries Solved
This operational tutorial is engineered to provide deterministic solutions for these developer search queries:
Step-by-Step Execution Playbook
Local Environment Setup & SKILL.md Mounting
Mount the skill manifest into your agent's configuration directory to register execution triggers and permissions.
Autonomous coding agents like Claude Code and Cursor scan defined directories (`.agents/skills/` or `.claude/skills/`) to parse SKILL.md frontmatter. Mounting the `opentype-js-font-path-metrics` manifest registers natural language triggers like 'convert text to svg path opentype.js' and 'inspect font metrics opentype', and declares strict sandbox constraints (`fs_read: true`, `fs_write: workspace`, `net_access: false`).
mkdir -p .agents/skills/opentype-js-font-path-metrics && curl -fsSL https://askills.dev/api/skills/opentype-js-font-path-metrics/raw -o .agents/skills/opentype-js-font-path-metrics/SKILL.md---
name: "opentype-js-font-path-metrics"
description: "Inspect font metrics, render vector glyph paths, and extract Bezier outlines with opentype.js."
metadata:
author: "Frederik De Bleser"
version: "1.0.0"
runtime_compatibility:
- "codex"
- "claude-code"
- "cursor"
- "windsurf"
triggers:
- "convert text to svg path opentype.js"
- "inspect font metrics opentype"
- "extract font glyphs javascript"
permissions:
fs_read: true
fs_write: "workspace"
shell_exec: false
net_access: false
---Use local workspace mounting (`.agents/skills/`) rather than global mounts so project-specific font conversion scripts respect sandbox boundary rules without bloating the global LLM context.
Ensure `net_access: false` is respected. Agents should not fetch remote CDN fonts during script execution; rely on local TrueType or OpenType binaries within the workspace directory.
Dependency Installation & Runtime Verification
Install opentype.js and configure TypeScript definitions inside the workspace.
Install `opentype.js` alongside `@types/opentype.js` so that the agent writes strictly typed vector extraction scripts with autocompletion for bounding boxes, glyph commands (`M`, `L`, `C`, `Q`, `Z`), and font metric tables.
npm install opentype.js && npm install --save-dev @types/opentype.js typescript @types/nodeimport * as opentype from 'opentype.js';
import * as path from 'path';
export async function inspectFont(fontPath: string) {
const resolvedPath = path.resolve(process.cwd(), fontPath);
const font = await opentype.load(resolvedPath);
return {
familyName: font.names.fontFamily?.en || 'Unknown',
unitsPerEm: font.unitsPerEm,
ascender: font.ascender,
descender: font.descender,
numGlyphs: font.numGlyphs,
tables: Object.keys(font.tables)
};
}Instruct your agent to utilize `opentype.loadSync(path)` or Promise-wrapped `opentype.load(path)` to prevent callback hell and unhandled async rejection traps in Node.js pipelines.
opentype.js requires a Node-compatible buffer or file path when executed outside browser environments; avoid passing pure Web Streams or `fetch` responses without converting to `ArrayBuffer`.
Intent Matching & Vector Extraction Execution
Prompt the agent using frontmatter triggers to generate reproducible SVG path extraction scripts.
Agent runtimes match semantic user prompts against the trigger list. When asking for text-to-SVG translation or Bezier extraction, the agent applies the procedural SOP: loading the font, calling `font.getPath(text, x, y, fontSize)`, calculating bounding boxes via `path.getBoundingBox()`, and outputting SVG elements.
import * as opentype from 'opentype.js';
import * as fs from 'fs';
export async function convertTextToVectorSvg(
fontFilePath: string,
text: string,
fontSize: number = 72,
outputPath: string
): Promise<void> {
const font = await opentype.load(fontFilePath);
const fontScale = (1 / font.unitsPerEm) * fontSize;
const baselineY = Math.round(font.ascender * fontScale);
// Extract vector path at standardized baseline
const textPath = font.getPath(text, 0, baselineY, fontSize, { kerning: true });
const bbox = textPath.getBoundingBox();
const width = Math.ceil(bbox.x2 - bbox.x1) + 20;
const height = Math.ceil(bbox.y2 - bbox.y1) + 20;
const svgContent = `<svg xmlns="http://www.w3.org/2000/svg" viewBox="${bbox.x1 - 10} ${bbox.y1 - 10} ${width} ${height}" width="${width}" height="${height}">
${textPath.toSVG(2)}
</svg>`;
fs.writeFileSync(outputPath, svgContent, 'utf-8');
}Set `{ kerning: true }` in `font.getPath` options. Autonomous agents often omit this flag, leading to amateurish typographic output on character pairs like 'AV' or 'To'.
Bounding boxes generated by `path.getBoundingBox()` can have negative `y1` coordinates because typographic baselines sit at `y = 0` while ascenders go negative in screen coordinate systems.
Verification, Linting & Output Quality Gate
Execute automated self-healing checks verifying SVG validity and accurate metric assertions.
Before accepting agent deliverables, execute a verification script that checks if generated SVG paths parse cleanly, contains valid `d` attributes with valid commands (`M`, `C`, `Q`, `Z`), and exits with return code 0.
npx ts-node scripts/inspect-font.ts && npx ts-node -e "import { convertTextToVectorSvg } from './scripts/text-to-svg'; convertTextToVectorSvg('fonts/Inter-Bold.ttf', 'Vector Typography', 48, 'dist/output.svg').then(() => console.log('Vector validation passed'));"#!/usr/bin/env bash
set -euo pipefail
if [ ! -f "dist/output.svg" ]; then
echo "Error: dist/output.svg was not generated." >&2
exit 1
fi
# Assert path element exists and contains cubic/quadratic commands
if grep -q '<path d="M' "dist/output.svg"; then
echo "Quality gate passed: Valid SVG Bezier glyph path detected."
exit 0
else
echo "Error: SVG does not contain expected vector path commands." >&2
exit 1
fiEnsure your agent executes `verify-glyphs.sh` or the TypeScript verification harness before reporting completion to prevent silent generation of 0-byte SVG outputs.
Do not allow the agent to invoke headless Chrome / Puppeteer for SVG bounding box validation; `path.getBoundingBox()` in opentype.js calculates analytical bounds directly, saving significant compute.
Real-World Scenario: Automated Dynamic SVG Badge & Path Metrics Generation
“Write a Node.js utility using opentype.js to inspect fonts/Inter-Regular.ttf metrics, convert the text 'PROD READY 2026' to an SVG vector path with exact bounding box padding, and output both the SVG file and a font-metrics.json file in the build directory.”
Runtime Troubleshooting & Failure Modes
Root Cause: The agent attempted to extract metrics or paths for characters that do not exist within the font's character-to-glyph index mapping ('cmap' table), such as unmapped emojis or missing unicode blocks.
const glyph = font.charToGlyph(char);
if (!glyph || glyph.index === 0) {
console.warn(`Glyph for character '${char}' missing in cmap table, falling back to default .notdef`);
}Root Cause: The agent attempted to load a modern WOFF2 file directly via opentype.load(). opentype.js supports TTF, OTF, and standard WOFF natively, but requires Brotli decompression (`brotli-wasm` or `wawoff2`) to parse WOFF2 containers.
npm install wawoff2
// In code: decompress WOFF2 buffer before passing to opentype.parse(decompressedBuffer.buffer)Frequently Asked Questions (opentype.js Vector Font Glyphs & Metrics SOP)
Q:Can I use opentype.js Vector Font Glyphs & Metrics across Codex, Claude Code, and Cursor simultaneously?
Yes. This skill adheres strictly to the vendor-agnostic SKILL.md specification. Once committed under `.agents/skills/opentype-js-font-path-metrics/SKILL.md`, it is discoverable across Claude Code CLI, Cursor IDE rules, Codex Desktop, and Windsurf.
Q:How does opentype.js Vector Font Glyphs & Metrics prevent context window overflow during long agent sessions?
Rather than copying raw binary glyph vectors or hundreds of lines of curve-flattening algorithms into prompt memory, the skill instructs the LLM to use opentype.js high-level methods (`getPath`, `toSVG`, `getBoundingBox`) directly in ephemeral code executions.
Q:Does this skill require escalated root or container permissions?
No. The skill is audited with a security score of 98/100. It requires zero shell execution privileges, no outbound internet access (`net_access: false`), and is strictly sandboxed to reading workspace fonts and writing generated assets within project workspace boundaries.
Ready to equip your autonomous agent with opentype.js Vector Font Glyphs & Metrics?
Copy the complete audited SKILL.md specification or download the 1-click zip bundle directly from our verified registry.