opentype-js
安装方式
先用 Prompt 核对来源与依赖。也可下载安装包。
用 AI 助手安装
复制提示词,让助手先核对固定版本和依赖。
查看 Prompt收起 Prompt
先检查当前 Agent 是否已安装 SkillPI Skill Finder。如果尚未安装,请按官方仓库的说明安装并启用:https://github.com/Findskills/skillpi。然后使用 Skill Finder 打开此 SkillPI 详情页并定位 "opentype-js":https://skillpi.com/zh/skills/deepskill-03f945825c36b1db1e712503076951d674d7f03c100bc4e85c87ccc30d5dbc82。安装前核对上游来源和版本:https://github.com/TerminalSkills/skills。来源不一致时停止并说明差异。核对通过后,用 Skill Finder 安装目标 Skill,并报告安装路径和来源版本。
来源与配置
github.com
配置方式待核实
请查看原始来源中的适用工具、依赖和权限要求。
安装实测待补充
使用 opentype.js 解析和操作 OpenType/TrueType 字体:读取字体元数据、访问字形轮廓、测量文本、生成字体子集,并将文本渲染为 SVG 路径。适用于自定义文本渲染、字体分析、字形提取或构建字体工具的任务。
介绍来源: third_party · TerminalSkills · 1.0.0 参考来源
SkillPi 解读
- 软件、账号及付费要求
- 贝什
- 实测状态
- 未测试
文件浏览
Frontmatter
name: opentype-js
description: >-
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.
license: Apache-2.0
compatibility: "Node.js 14+ or browser"
metadata:
author: terminal-skills
version: "1.0.0"
category: design
tags: ["fonts", "typography", "opentype", "glyphs", "text-rendering"]opentype.js
Read and write OpenType fonts. Access every glyph, measure text, convert to SVG paths.
Setup
# Install opentype.js for font parsing and manipulation.
npm install opentype.js
Loading a Font
// 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
// 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
// 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
// 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
// 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);
}当前收录版本
1.0.0
质量评测
满分100 · 来自 SkillPi LAB 实验室的评测报告。
亮点
- 提供完整的字体解析、测量、SVG 渲染、字形提取和子集生成功能
- 覆盖自定义文本渲染、字体分析、字形提取等多个实际应用场景
- opentype.js 是行业标准库,Skill 封装了常用操作,实用价值高
亮点
- 触发词精准完整,明确指出了适用场景:自定义文本渲染、字体分析、字形提取、构建字体工具
- 边界清晰,不易与其他 Skill 重叠
亮点
- Phase/步骤清晰,Setup -> Loading -> Measuring -> Rendering -> Glyphs -> Subsetting
- 有出口条件,含端到端示例,frontmatter完整,单文件未超限
亮点
- 工具来源明确 - opentype.js,参数正确
- 覆盖了主要异常,不可逆操作有确认机制,可靠性良好
取前四项原始分值的算术平均,四舍五入取整。可通过收录报告核对各项评分与说明,运行记录需单独查证。
正文静态检测
100 / 100 · skillpi-20261123-no-r3-v1
正文未命中当前规则。
分数仅反映正文中的规则命中,供使用前参考。附件与运行行为不在此评分范围内。
权限与使用前检查
根据当前主文档自动整理,命中内容可能是示例或防护说明;不是实际权限声明,也未覆盖附件、外部依赖或运行行为。
-
读取本地文件
限定到你选择的文件或项目目录;避免读取无关的个人资料、密钥和配置文件。
主文档提及 · 第 36 行 -
保存或修改文件
先确认输出目录和同名文件是否会被覆盖;重要文件保留备份,优先写入新的输出目录。
主文档提及 · 第 149 行 -
安装或获取外部依赖
使用官方来源并锁定版本,在隔离环境检查安装脚本。当前文档检查不覆盖后续下载的代码。
主文档提及 · 第 25 行
文档引用的域名或地址
这些地址可能用于文档链接或示例,不是已批准的联网清单。使用前核对实际目的地及发送的数据。
- www.w3.org
安全评级与访问范围
safe · 静态证据核验,不代表运行安全保证。
贝什
使用前请由宿主核对并授权实际文件读写、外部服务和联网目的地;本站的核验不会授予任何运行权限。
用户讨论
还没有已核实的点评。