{"_id":"measury","_rev":"6-21dac5201ecacf0e291148c1ce19a9c5","name":"measury","dist-tags":{"latest":"0.1.5"},"versions":{"0.1.0":{"name":"measury","version":"0.1.0","keywords":["text","width","height","measure","font","typography","text-metrics"],"author":"","license":"MIT","_id":"measury@0.1.0","maintainers":[{"name":"iaaron","email":"943720372@qq.com"}],"homepage":"https://github.com/Aarebecca/measury#readme","bugs":{"url":"https://github.com/Aarebecca/measury/issues"},"dist":{"shasum":"41eec4eb62629b2fbf004f3346fea95971566f34","tarball":"https://registry.npmjs.org/measury/-/measury-0.1.0.tgz","fileCount":20,"integrity":"sha512-NkCMri5RdFwL4a8SqLgLmxrn7sy6r4SDero271WjJN1yMGEch+bLuU0cD2W34K3/EkeGyxSZIe1agP2s74/b2Q==","signatures":[{"sig":"MEQCIA+9n6GdS5DugDKr+URP8ykcNKa6ANlT/IdO+cCqc4nLAiBVDpwsyBBeBKIsgQ+u+ardLdn6BJM/XUDyhShLSsfNSQ==","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":227988},"main":"lib/index.js","types":"lib/index.d.ts","exports":{".":{"types":"./lib/index.d.ts","default":"./lib/index.js"},"./*":{"types":"./lib/fonts/*.d.ts","default":"./lib/fonts/*.js"}},"gitHead":"c66a47f0229293ef1aefe491601032f150e25724","scripts":{"dev":"npx serve test-browser -p 8090","lint":"eslint src/**/*.ts","test":"vitest run","build":"tsc","extract":"tsx scripts/extract-font.ts","prebuild":"rm -rf lib","test:watch":"vitest","test:coverage":"vitest run --coverage","prepublishOnly":"npm run build"},"_npmUser":{"name":"iaaron","email":"943720372@qq.com"},"repository":{"url":"git+https://github.com/Aarebecca/measury.git","type":"git"},"_npmVersion":"10.8.2","description":"A lightweight library for estimating text width and height in non-browser environments","directories":{},"sideEffects":false,"_nodeVersion":"20.19.5","_hasShrinkwrap":false,"devDependencies":{"tsx":"^4.21.0","eslint":"^9.39.1","vitest":"^4.0.15","globals":"^16.5.0","minimist":"^1.2.8","prettier":"^3.7.4","typescript":"^5.9.3","@types/node":"^24.10.2","opentype.js":"^1.3.4","@types/minimist":"^1.2.5","@types/opentype.js":"^1.3.8","@typescript-eslint/parser":"^8.49.0","@typescript-eslint/eslint-plugin":"^8.49.0"},"_npmOperationalInternal":{"tmp":"tmp/measury_0.1.0_1765348364136_0.2579419505453062","host":"s3://npm-registry-packages-npm-production"}},"0.1.1":{"name":"measury","version":"0.1.1","keywords":["text","width","height","measure","font","typography","text-metrics"],"author":"","license":"MIT","_id":"measury@0.1.1","maintainers":[{"name":"iaaron","email":"943720372@qq.com"}],"homepage":"https://github.com/Aarebecca/measury#readme","bugs":{"url":"https://github.com/Aarebecca/measury/issues"},"dist":{"shasum":"f6331ca27c64d8867f22b4fcb14a2d0f9431c898","tarball":"https://registry.npmjs.org/measury/-/measury-0.1.1.tgz","fileCount":24,"integrity":"sha512-yjRcNrcoYTIiqU3jsp2C6pd90LZQsI+7YJ7YNKhYwSERVQOuRpjOJZTWMjdV/QELx7clFhvwRbJz1SNeyBlR0Q==","signatures":[{"sig":"MEYCIQCjp4hY0La9q2e7Tc5ANf/sP9otXFIHFMLhz+rekam5/gIhAIb9PCM9GUAuU0iXHjoioLQOmIGk3sP/BA9iKnsfpGN1","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":257969},"main":"lib/index.js","types":"lib/index.d.ts","exports":{".":{"types":"./lib/index.d.ts","default":"./lib/index.js"},"./*":{"types":"./lib/fonts/*.d.ts","default":"./lib/fonts/*.js"}},"gitHead":"51ca920083867ff4fcec2953fc6e71d529d53bfd","scripts":{"ci":"run-p lint test build","dev":"npx serve test-browser -p 8090","lint":"eslint src/**/*.ts","test":"vitest run","build":"tsc","extract":"tsx scripts/extract-font.ts","prebuild":"rm -rf lib","test:watch":"vitest","test:coverage":"vitest run --coverage","prepublishOnly":"npm run build"},"_npmUser":{"name":"iaaron","email":"943720372@qq.com"},"repository":{"url":"git+https://github.com/Aarebecca/measury.git","type":"git"},"_npmVersion":"10.8.2","description":"A lightweight library for estimating text width and height in non-browser environments","directories":{},"sideEffects":false,"_nodeVersion":"20.19.5","_hasShrinkwrap":false,"devDependencies":{"tsx":"^4.21.0","eslint":"^9.39.1","vitest":"^4.0.15","globals":"^16.5.0","minimist":"^1.2.8","prettier":"^3.7.4","typescript":"^5.9.3","@types/node":"^24.10.2","npm-run-all":"^4.1.5","opentype.js":"^1.3.4","@types/minimist":"^1.2.5","typescript-eslint":"^8.49.0","@types/opentype.js":"^1.3.8","@typescript-eslint/eslint-plugin":"^8.49.0"},"_npmOperationalInternal":{"tmp":"tmp/measury_0.1.1_1765422973953_0.4114661485857858","host":"s3://npm-registry-packages-npm-production"}},"0.1.2":{"name":"measury","version":"0.1.2","keywords":["text","width","height","measure","font","typography","text-metrics"],"author":"","license":"MIT","_id":"measury@0.1.2","maintainers":[{"name":"iaaron","email":"943720372@qq.com"}],"homepage":"https://github.com/Aarebecca/measury#readme","bugs":{"url":"https://github.com/Aarebecca/measury/issues"},"dist":{"shasum":"f0ce6cd8c0ff014420b6a0cf554ff605604c3c70","tarball":"https://registry.npmjs.org/measury/-/measury-0.1.2.tgz","fileCount":24,"integrity":"sha512-VNeYDvV2+PtI3dqd2QNyKkUma+nDBeRNMYBWEa90KW6WAtHqcFfVtXi2SgzvynP/Qn9gSIaEOxd1XnHD77gYLQ==","signatures":[{"sig":"MEYCIQCkoinrXvqfblqoiIxPYZ20umDVvlDYNrn7rsrO9/NTRAIhAJH1zHvZmA9An9KRMBxkagt0j3ZC1NGi3a0O6BUu2n+M","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":255712},"main":"lib/index.js","type":"module","types":"lib/index.d.ts","exports":{".":{"types":"./lib/index.d.ts","import":"./lib/index.js"},"./fonts/*":{"types":"./lib/fonts/*.d.ts","import":"./lib/fonts/*.js"}},"gitHead":"5bc609b9ebaa75126cca694aab5ff43c458a4e8f","scripts":{"ci":"run-p lint test build","dev":"npx serve test-browser -p 8090","lint":"eslint src/**/*.ts","test":"vitest run","build":"tsc","extract":"tsx scripts/extract-font.ts","prebuild":"rm -rf lib","test:watch":"vitest","test:coverage":"vitest run --coverage","prepublishOnly":"npm run build"},"_npmUser":{"name":"iaaron","email":"943720372@qq.com"},"repository":{"url":"git+https://github.com/Aarebecca/measury.git","type":"git"},"_npmVersion":"10.8.2","description":"A lightweight library for estimating text width and height in non-browser environments","directories":{},"sideEffects":false,"_nodeVersion":"20.19.5","typesVersions":{"*":{"fonts/*":["lib/fonts/*"]}},"_hasShrinkwrap":false,"devDependencies":{"tsx":"^4.21.0","eslint":"^9.39.1","vitest":"^4.0.15","globals":"^16.5.0","minimist":"^1.2.8","prettier":"^3.7.4","typescript":"^5.9.3","@types/node":"^24.10.2","npm-run-all":"^4.1.5","opentype.js":"^1.3.4","@types/minimist":"^1.2.5","typescript-eslint":"^8.49.0","@types/opentype.js":"^1.3.8","@typescript-eslint/eslint-plugin":"^8.49.0"},"_npmOperationalInternal":{"tmp":"tmp/measury_0.1.2_1765434148938_0.16757806327447033","host":"s3://npm-registry-packages-npm-production"}},"0.1.3":{"name":"measury","version":"0.1.3","keywords":["text","width","height","measure","font","typography","text-metrics"],"author":"","license":"MIT","_id":"measury@0.1.3","maintainers":[{"name":"iaaron","email":"943720372@qq.com"}],"homepage":"https://github.com/Aarebecca/measury#readme","bugs":{"url":"https://github.com/Aarebecca/measury/issues"},"dist":{"shasum":"392ebf6cf4dae92595307e90e42b0f23a1382902","tarball":"https://registry.npmjs.org/measury/-/measury-0.1.3.tgz","fileCount":24,"integrity":"sha512-vWRXVJdAbyhn0NJsrFHBbJ4XRRv0IgcKFT17Jls69bk9wA5Y95ndE7C0FEk25y87tCKqmK7xPqdSxK2ympU19Q==","signatures":[{"sig":"MEYCIQDoms6GP802qERiXn46aw0si48BgQP/g7z7krj2rLY3pgIhAIbiYGendYxSmHnRjZu7br8fKMJSpV+I9ojzl4mBHsFo","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":255764},"main":"lib/index.js","type":"module","types":"lib/index.d.ts","exports":{".":{"types":"./lib/index.d.ts","import":"./lib/index.js"},"./fonts/*":{"types":"./lib/fonts/*.d.ts","import":"./lib/fonts/*.js","default":"./lib/fonts/*.js"}},"gitHead":"863255694c7aab443c3bc6e40164b7239094dcee","scripts":{"ci":"run-p lint test build","dev":"npx serve test-browser -p 8090","lint":"eslint src/**/*.ts","test":"vitest run","build":"tsc","extract":"tsx scripts/extract-font.ts","prebuild":"rm -rf lib","test:watch":"vitest","test:coverage":"vitest run --coverage","prepublishOnly":"npm run build"},"_npmUser":{"name":"iaaron","email":"943720372@qq.com"},"repository":{"url":"git+https://github.com/Aarebecca/measury.git","type":"git"},"_npmVersion":"10.8.2","description":"A lightweight library for estimating text width and height in non-browser environments","directories":{},"sideEffects":false,"_nodeVersion":"20.19.5","typesVersions":{"*":{"fonts/*":["lib/fonts/*"]}},"_hasShrinkwrap":false,"devDependencies":{"tsx":"^4.21.0","eslint":"^9.39.1","vitest":"^4.0.15","globals":"^16.5.0","minimist":"^1.2.8","prettier":"^3.7.4","typescript":"^5.9.3","@types/node":"^24.10.2","npm-run-all":"^4.1.5","opentype.js":"^1.3.4","@types/minimist":"^1.2.5","typescript-eslint":"^8.49.0","@types/opentype.js":"^1.3.8","@typescript-eslint/eslint-plugin":"^8.49.0"},"_npmOperationalInternal":{"tmp":"tmp/measury_0.1.3_1765452254444_0.46955595183234466","host":"s3://npm-registry-packages-npm-production"}},"0.1.4":{"name":"measury","version":"0.1.4","keywords":["text","width","height","measure","font","typography","text-metrics"],"author":"","license":"MIT","_id":"measury@0.1.4","maintainers":[{"name":"iaaron","email":"943720372@qq.com"}],"homepage":"https://github.com/Aarebecca/measury#readme","bugs":{"url":"https://github.com/Aarebecca/measury/issues"},"dist":{"shasum":"938d2a42a25748a50eccef9634963eaf6876e5ff","tarball":"https://registry.npmjs.org/measury/-/measury-0.1.4.tgz","fileCount":24,"integrity":"sha512-AAY8ojVbYNdv1S+vrx7tEQe0LAL3EwzWnjHWwsjnmU34XH9LECfsstHv3y+gJkZjMOwmBArej561n7Hk6gKMGQ==","signatures":[{"sig":"MEYCIQDgfTukyQ6nLzaa/DAYHQ/9WKmzCVKAMfyHRYPn06hKAgIhAJ5hs6ICUK3jhmNlFhig7vrT+LK+6HBmqhPNnfBNPhla","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":255812},"main":"lib/index.js","type":"module","types":"lib/index.d.ts","exports":{".":{"types":"./lib/index.d.ts","import":"./lib/index.js"},"./fonts/*":{"types":"./lib/fonts/*.d.ts","import":"./lib/fonts/*.js","default":"./lib/fonts/*.js"}},"gitHead":"e62a86bbf9b1acec4548f2f921b1de2e7cea7793","scripts":{"ci":"run-p lint test build","dev":"npx serve test-browser -p 8090","lint":"eslint src/**/*.ts","test":"vitest run","build":"tsc","extract":"tsx scripts/extract-font.ts","prebuild":"rm -rf lib","test:watch":"vitest","test:coverage":"vitest run --coverage","prepublishOnly":"npm run build"},"_npmUser":{"name":"iaaron","email":"943720372@qq.com"},"repository":{"url":"git+https://github.com/Aarebecca/measury.git","type":"git"},"_npmVersion":"10.8.2","description":"A lightweight library for estimating text width and height in non-browser environments","directories":{},"sideEffects":false,"_nodeVersion":"20.19.5","typesVersions":{"*":{"fonts/*":["lib/fonts/*"]}},"_hasShrinkwrap":false,"devDependencies":{"tsx":"^4.21.0","eslint":"^9.39.1","vitest":"^4.0.15","globals":"^16.5.0","minimist":"^1.2.8","prettier":"^3.7.4","typescript":"^5.9.3","@types/node":"^24.10.2","npm-run-all":"^4.1.5","opentype.js":"^1.3.4","@types/minimist":"^1.2.5","typescript-eslint":"^8.49.0","@types/opentype.js":"^1.3.8","@typescript-eslint/eslint-plugin":"^8.49.0"},"_npmOperationalInternal":{"tmp":"tmp/measury_0.1.4_1765453482422_0.34988944675732814","host":"s3://npm-registry-packages-npm-production"}},"0.1.5":{"name":"measury","version":"0.1.5","description":"A lightweight library for estimating text width and height in non-browser environments","type":"module","main":"lib/index.js","types":"lib/index.d.ts","exports":{".":{"types":"./lib/index.d.ts","import":"./lib/index.js","default":"./lib/index.js"},"./fonts/*":{"types":"./lib/fonts/*.d.ts","import":"./lib/fonts/*.js","default":"./lib/fonts/*.js"}},"typesVersions":{"*":{"fonts/*":["lib/fonts/*"]}},"sideEffects":false,"scripts":{"dev":"npx serve test-browser -p 8090","build":"tsc","prebuild":"rm -rf lib","lint":"eslint src/**/*.ts","prepublishOnly":"npm run build","test":"vitest run","test:watch":"vitest","test:coverage":"vitest run --coverage","extract":"tsx scripts/extract-font.ts","ci":"run-p lint test build"},"keywords":["text","width","height","measure","font","typography","text-metrics"],"repository":{"type":"git","url":"git+https://github.com/Aarebecca/measury.git"},"author":"","license":"MIT","devDependencies":{"@types/minimist":"^1.2.5","@types/node":"^24.10.2","@types/opentype.js":"^1.3.8","@typescript-eslint/eslint-plugin":"^8.49.0","eslint":"^9.39.1","globals":"^16.5.0","minimist":"^1.2.8","npm-run-all":"^4.1.5","opentype.js":"^1.3.4","prettier":"^3.7.4","tsx":"^4.21.0","typescript":"^5.9.3","typescript-eslint":"^8.49.0","vitest":"^4.0.15"},"_id":"measury@0.1.5","gitHead":"07e1c9b348bfb8f07c3564bf347a140d73ccd209","bugs":{"url":"https://github.com/Aarebecca/measury/issues"},"homepage":"https://github.com/Aarebecca/measury#readme","_nodeVersion":"20.19.5","_npmVersion":"10.8.2","dist":{"integrity":"sha512-YS9nhEbFECQzM9V7kyYylASFwpMyajeRvVnpmfRnhZZwbl9AfpBW+C/o7YwmIQLjK8XFzPHt0OGR7GwqoDuWjA==","shasum":"bb845f80704cb56a863cedd2ffe3a25ae7f7e49d","tarball":"https://registry.npmjs.org/measury/-/measury-0.1.5.tgz","fileCount":24,"unpackedSize":256558,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEYCIQCtjQJn0GKawGHhIXCAosBAgl9cAL7XXw736tKjzzuK+gIhAILx41GXvZWPQVXq8M6lOy4z9GRKspnki5Yfw5H68B52"}]},"_npmUser":{"name":"iaaron","email":"943720372@qq.com"},"directories":{},"maintainers":[{"name":"iaaron","email":"943720372@qq.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/measury_0.1.5_1768529939783_0.9559690508793113"},"_hasShrinkwrap":false}},"time":{"created":"2025-12-10T06:32:44.135Z","modified":"2026-01-16T02:19:00.043Z","0.1.0":"2025-12-10T06:32:44.270Z","0.1.1":"2025-12-11T03:16:14.103Z","0.1.2":"2025-12-11T06:22:29.079Z","0.1.3":"2025-12-11T11:24:14.584Z","0.1.4":"2025-12-11T11:44:42.570Z","0.1.5":"2026-01-16T02:18:59.939Z"},"bugs":{"url":"https://github.com/Aarebecca/measury/issues"},"license":"MIT","homepage":"https://github.com/Aarebecca/measury#readme","keywords":["text","width","height","measure","font","typography","text-metrics"],"repository":{"type":"git","url":"git+https://github.com/Aarebecca/measury.git"},"description":"A lightweight library for estimating text width and height in non-browser environments","maintainers":[{"name":"iaaron","email":"943720372@qq.com"}],"readme":"# Measury\n\n一个轻量级的 JavaScript 库，用于在非浏览器环境中估算文本的宽度和高度。\n\n与 `node-canvas` 或 `opentype` 等重量级方案不同，本库提供了一个基于字体度量配置的轻量级替代方案，适用于近似文本测量。\n\n## ✨ 特性\n\n- 📏 精确的文本宽度和高度测量\n- 🎨 支持多种文本样式（字体、大小、粗细、间距等）\n- 🔤 文本转换支持（大写、小写、首字母大写）\n- 📦 **轻量级** - 按需加载，核心库仅 3-5KB\n- 🌲 **Tree-shaking 友好** - 只打包使用的字体\n- 🚀 快速 - 基于预计算的字体度量\n- 🛠️ 完整的 TypeScript 类型定义\n- 🔧 内置字体提取脚本\n\n## 📦 安装\n\n```bash\nnpm install measury\n```\n\n## 🚀 快速开始\n\n### 方式 1：使用系统字体（最小体积）\n\n```typescript\nimport { measureText } from 'measury';\n\n// 测量系统字体，无需额外配置\nconst metrics = measureText('Hello World', {\n  fontFamily: 'Arial',\n  fontSize: 16,\n});\n\nconsole.log(metrics.width);    // 文本宽度（像素）\nconsole.log(metrics.height);   // 行高（像素）\nconsole.log(metrics.baseline); // 基线位置（像素）\n```\n\n### 方式 2：按需加载字体数据（精确测量）\n\n```typescript\nimport { measureText, registerFont } from 'measury';\nimport AlibabaPuHuiTiRegular from 'measury/fonts/AlibabaPuHuiTi-Regular';\n\n// 注册字体\nregisterFont(AlibabaPuHuiTiRegular);\n\n// 精确测量\nconst metrics = measureText('你好世界', {\n  fontFamily: 'Alibaba PuHuiTi',\n  fontSize: 16,\n  fontStyle: 'normal', // 支持 'normal' | 'italic' | 'oblique'\n});\n```\n\n**优势**：\n- ✅ 核心库体积小（3-5KB），只在需要时加载字体数据\n- ✅ Tree-shaking 友好，打包工具自动去除未使用的字体\n- ✅ 灵活控制打包体积\n- ✅ 支持多种字体样式（normal, italic, oblique）\n\n**字体导入方式**：\n\n```typescript\nimport AlibabaPuHuiTiRegular from 'measury/fonts/AlibabaPuHuiTi-Regular';\n```\n\n## 📖 API\n\n### `measureText(text, style?)`\n\n测量单行文本的尺寸。\n\n**参数：**\n- `text` - 要测量的文本\n- `style` - 可选的文本样式配置\n\n**返回：** `TextMetrics` 对象\n- `width` - 文本宽度（像素）\n- `height` - 行高（像素）\n- `baseline` - 基线位置（像素）\n\n**样式选项：**\n\n```typescript\ninterface TextStyle {\n  fontSize?: number;              // 默认: 16\n  fontFamily?: string;            // 默认: 'sans-serif'\n  fontWeight?: 'normal' | 'bold' | number;\n  fontStyle?: 'normal' | 'italic' | 'oblique';\n  textTransform?: 'none' | 'capitalize' | 'uppercase' | 'lowercase';\n  letterSpacing?: number;         // 字符间距（像素）\n  wordSpacing?: number;           // 单词间距（像素）\n  lineHeight?: number | { type: 'pixel', value: number };\n}\n```\n\n### `registerFont(fontData)`\n\n注册字体供文本测量使用。\n\n```typescript\nimport { registerFont } from 'measury';\nimport MyFont from 'measury/myfont';\n\nregisterFont(MyFont);\n```\n\n支持在字体数据中声明别名：\n\n```typescript\nregisterFont({\n  ...MyFont,\n  aliases: ['AlibabaPuHuiTi', 'AlibabaPuHuiTi-Regular'],\n});\n```\n\n### `setDefaultFontFamily(fontFamily)`\n\n设置默认字体族。\n\n```typescript\nimport { setDefaultFontFamily } from 'measury';\n\nsetDefaultFontFamily('Alibaba PuHuiTi');\n```\n\n## 🔧 从 TTF 文件提取字体数据\n\n本库内置了从 TTF 文件提取字体度量数据的脚本。\n\n### 基本用法\n\n```bash\nnpm run extract <字体文件路径.ttf>\n```\n\n这将：\n1. 从 TTF/OFT 文件提取字体数据\n2. 在 `src/fonts/` 生成 TypeScript 文件\n3. 自动添加到 `src/fonts/index.ts`\n\n### 示例\n\n**提取字体：**\n```bash\nnpm run extract fonts/Roboto-Regular.ttf\n# 生成: src/fonts/roboto-regular.ts\n```\n\n**指定字重：**\n```bash\nnpm run extract fonts/Roboto-Bold.ttf --weight 700\n# 或简写\nnpm run extract fonts/Roboto-Bold.ttf -w 700\n```\n\n**指定字体样式：**\n```bash\nnpm run extract fonts/Roboto-Italic.ttf --style italic\n# 或简写\nnpm run extract fonts/Roboto-Italic.ttf -s italic\n```\n\n**自定义字体名称：**\n```bash\nnpm run extract fonts/CustomFont.ttf --family \"自定义字体\"\n```\n\n**只提取特定字符（减小文件体积）：**\n```bash\n# 只提取数字\nnpm run extract fonts/Arial.ttf --charset \"0123456789\"\n\n# 只提取英文字母\nnpm run extract fonts/Font.ttf -c \"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz\"\n```\n\n**跳过字偶距数据：**\n```bash\nnpm run extract fonts/Font.ttf --no-kerning\n```\n\n### 选项说明\n\n| 选项 | 简写 | 说明 | 示例 |\n|------|------|------|------|\n| `--weight <weight>` | `-w` | 设置字重 | `--weight 700` |\n| `--style <style>` | `-s` | 设置字体样式 (normal/italic/oblique) | `--style italic` |\n| `--family <name>` | `-f` | 自定义字体名称 | `--family \"我的字体\"` |\n| `--charset <chars>` | `-c` | 只提取指定字符 | `--charset \"ABC123\"` |\n| `--output <file>` | `-o` | 输出文件路径 | `-o src/fonts/my-font.ts` |\n| `--no-kerning` | - | 跳过字偶距数据 | `--no-kerning` |\n\n### 提取后使用\n\n```typescript\nimport { measureText } from 'measury';\n\nconst metrics = measureText('Hello', {\n  fontFamily: 'Roboto',\n  fontSize: 16,\n});\n```\n\n### 优化建议\n\n- **减小文件体积**：\n  - 使用 `--charset` 只提取需要的字符\n  - 使用 `--no-kerning` 跳过字偶距数据\n  - 脚本自动优化：将最常见的字形宽度设为默认值\n  \n- **字重**：分别提取每个字重（Regular、Bold 等）\n\n- **提取速度**：\n  - 小字体（拉丁字符，~100-500 字形）：< 1 秒\n  - 大字体（CJK，10,000+ 字形）：1-10 秒\n\n## 🧪 测试\n\n运行测试：\n\n```bash\nnpm test\n```\n\n监听模式：\n\n```bash\nnpm run test:watch\n```\n\n生成覆盖率报告：\n\n```bash\nnpm run test:coverage\n```\n\n### 浏览器验证\n\n验证测量准确性：\n\n```bash\nnpm run dev\n# 访问 http://localhost:8090\n```\n\n功能：\n- ✅ 包含字体文件，开箱即用\n- ✅ 对比真实浏览器渲染结果\n- ✅ 生成测试代码\n- ✅ 验证测量精度\n\n## ⚙️ 工作原理\n\n1. 从 TTF 文件预提取字体度量数据（字形宽度、垂直度量、字偶距）\n2. 通过累加每个字符的推进宽度来测量文本\n3. 应用字符对之间的字偶距调整\n4. 添加指定的字符间距和单词间距\n5. 根据字体度量或样式设置计算行高\n\n这种方法提供快速的近似测量，无需完整字体渲染的开销。\n\n## ⚠️ 限制\n\n- 仅支持单行文本测量（不支持自动换行）\n- 需要预注册字体数据\n- 测量结果是基于字体度量的近似值，非像素完美\n- 不考虑字体微调、亚像素渲染或平台特定的文本渲染差异\n\n## 📄 许可证\n\nMIT\n","readmeFilename":"README.md"}