opentype-js
Parse and manipulate OpenType/TrueType fonts with opentype.js — read font metadata, access glyph outlines, measure text, generate font subsets, and render text to SVG paths. Use when tasks involve custom text rendering, font analysis, glyph extraction, or building font tools.
What this skill does
# opentype.js
Read and write OpenType fonts. Access every glyph, measure text, convert to SVG paths.
## Setup
```bash
# Install opentype.js for font parsing and manipulation.
npm install opentype.js
```
## Loading a Font
```typescript
// src/fonts/load.ts — Load a font from file or URL and read metadata.
import opentype from "opentype.js";
import fs from "fs";
// From file (Node.js)
const buffer = fs.readFileSync("./fonts/Inter-Regular.otf");
const font = opentype.parse(buffer.buffer);
console.log(font.names.fontFamily); // "Inter"
console.log(font.names.designer); // designer name
console.log(font.unitsPerEm); // 2048
console.log(font.numGlyphs); // total glyph count
```
## Measuring Text
```typescript
// src/fonts/measure.ts — Calculate text width and bounding box at a given size.
// Useful for layout engines and canvas text positioning.
import opentype from "opentype.js";
export function measureText(font: opentype.Font, text: string, fontSize: number) {
const path = font.getPath(text, 0, 0, fontSize);
const bb = path.getBoundingBox();
const advance = font.getAdvanceWidth(text, fontSize);
return {
width: advance,
height: bb.y2 - bb.y1,
boundingBox: { x1: bb.x1, y1: bb.y1, x2: bb.x2, y2: bb.y2 },
};
}
```
## Rendering Text to SVG
```typescript
// src/fonts/to-svg.ts — Convert a text string to an SVG path element.
// This produces resolution-independent text that doesn't require the font file.
import opentype from "opentype.js";
export function textToSvg(
font: opentype.Font,
text: string,
fontSize: number,
x: number,
y: number
): string {
const path = font.getPath(text, x, y, fontSize);
const pathData = path.toPathData(2); // precision
const bb = path.getBoundingBox();
return `<svg xmlns="http://www.w3.org/2000/svg" viewBox="${bb.x1} ${bb.y1} ${bb.x2 - bb.x1} ${bb.y2 - bb.y1}">
<path d="${pathData}" fill="currentColor"/>
</svg>`;
}
```
## Accessing Individual Glyphs
```typescript
// src/fonts/glyphs.ts — Extract glyph outlines and metadata for specific characters.
import opentype from "opentype.js";
export function getGlyphInfo(font: opentype.Font, char: string) {
const glyph = font.charToGlyph(char);
const path = glyph.getPath(0, 0, 72);
return {
name: glyph.name,
unicode: glyph.unicode,
advanceWidth: glyph.advanceWidth,
pathData: path.toPathData(2),
commands: path.commands,
};
}
// List all glyphs in a font
export function listGlyphs(font: opentype.Font) {
const glyphs: { index: number; name: string; unicode: number | undefined }[] = [];
for (let i = 0; i < font.numGlyphs; i++) {
const g = font.glyphs.get(i);
glyphs.push({ index: i, name: g.name, unicode: g.unicode });
}
return glyphs;
}
```
## Font Subsetting
```typescript
// src/fonts/subset.ts — Create a subset font containing only the glyphs needed
// for a specific string. Reduces font file size for web embedding.
import opentype from "opentype.js";
import fs from "fs";
export function subsetFont(font: opentype.Font, chars: string, outputPath: string) {
const glyphs = [font.glyphs.get(0)]; // always include .notdef
const seen = new Set<number>();
for (const char of chars) {
const glyph = font.charToGlyph(char);
if (glyph.index !== 0 && !seen.has(glyph.index)) {
glyphs.push(glyph);
seen.add(glyph.index);
}
}
const subset = new opentype.Font({
familyName: font.names.fontFamily?.en || "Subset",
styleName: font.names.fontSubfamily?.en || "Regular",
unitsPerEm: font.unitsPerEm,
ascender: font.ascender,
descender: font.descender,
glyphs,
});
const buffer = Buffer.from(subset.download() as any);
fs.writeFileSync(outputPath, buffer);
}
```
Related in Image & Video
watch
IncludedWatch a video (URL or local path). Downloads with yt-dlp, extracts auto-scaled frames with ffmpeg, pulls the transcript from captions (or Whisper API fallback), and hands the result to Claude so it can answer questions about what's in the video.
physical-ai-defect-image-generation
IncludedUse when the user wants to orchestrate defect image generation, run associated setup, or handle outputs on OSMO. The Day 0 path handles cold-start with USD-to-ROI, image-edit augmentation, and AnomalyGen to create initial PCBA datasets. The Day 1 path performs inference and labeling on real images. This skill helps with first-time asset setup, creation of finetuning checkpoints, and configuring deployment. Trigger keywords: defect image generation, dig workflow, dig pipeline, defect image detection workflow, aoi pipeline, aoi anomalygen, usd2roi anomalygen, day 0 pcba, day 1 pcba, day 1 real-photo alignment, day 1 manual roi, metal surface anomaly, glass defect, anomalygen finetune, setup_pcb, setup_metal, setup_glass, setup_pretrained, dig setup, dig datasets, dig pretrained checkpoint, dig image-edit endpoint.
accelint-react-best-practices
IncludedReact performance optimization and best practices. ALWAYS use this skill when working with any React code - writing components, hooks, JSX; refactoring; optimizing re-renders, memoization, state management; reviewing for performance; fixing hydration mismatches; debugging infinite re-renders, stale closures, input focus loss, animations restarting; preventing remounting; implementing transitions, lazy initialization, effect dependencies. Even simple React tasks benefit from these patterns. Covers React 19+ (useEffectEvent, Activity, ref props). Triggers - useEffect, useState, useMemo, useCallback, memo, inline components, nested components, components inside components, re-render, performance, hydration, SSR, Next.js, useDeferredValue, combined hooks.
elevenlabs-agents
IncludedBuild conversational AI voice agents with ElevenLabs Platform using React, JavaScript, React Native, or Swift SDKs. Configure agents, tools (client/server/MCP), RAG knowledge bases, multi-voice, and Scribe real-time STT. Use when: building voice chat interfaces, implementing AI phone agents with Twilio, configuring agent workflows or tools, adding RAG knowledge bases, testing with CLI "agents as code", or troubleshooting deprecated @11labs packages, Android audio cutoff, CSP violations, dynamic variables, or WebRTC config. Keywords: ElevenLabs Agents, ElevenLabs voice agents, AI voice agents, conversational AI, @elevenlabs/react, @elevenlabs/client, @elevenlabs/react-native, @elevenlabs/elevenlabs-js, @elevenlabs/agents-cli, elevenlabs SDK, voice AI, TTS, text-to-speech, ASR, speech recognition, turn-taking model, WebRTC voice, WebSocket voice, ElevenLabs conversation, agent system prompt, agent tools, agent knowledge base, RAG voice agents, multi-voice agents, pronunciation dictionary, voice speed control, elevenlabs scribe, @11labs deprecated, Android audio cutoff, CSP violation elevenlabs, dynamic variables elevenlabs, case-sensitive tool names, webhook authentication
humanizer
IncludedHumanize AI-generated text by detecting and removing patterns typical of LLM output. Rewrites text to sound natural, specific, and human. Uses 28 pattern detectors, 560+ AI vocabulary terms across 3 tiers, and statistical analysis (burstiness, type-token ratio, readability) for comprehensive detection. Use when asked to humanize text, de-AI writing, make content sound more natural/human, review writing for AI patterns, score text for AI detection, or improve AI-generated drafts. Covers content, language, style, communication, and filler categories.
generating-mermaid-diagrams
IncludedSalesforce architecture diagrams using Mermaid with ASCII fallback. Use this skill when generating text-based diagrams for Salesforce architecture, OAuth flows, ERDs, integration sequences, or Agentforce structure. TRIGGER when: user says "diagram", "visualize", "ERD", or asks for sequence diagrams, flowcharts, class diagrams, or architecture visualizations in Mermaid. DO NOT TRIGGER when: user wants PNG/SVG image output (use generating-visual-diagrams), or asks about non-Salesforce systems.