Skip to content

vicocotea/export-kerning

Repository files navigation

export-kerning

Exports the kerning of an OpenType font (ttf, otf and woff)

Try it Online

https://vicocotea.github.io/export-kerning-app/

Upload a font file and export its kerning pairs directly in your browser.

Installation

npm install

Usage

Programmatic Usage

npm install export-kerning opentype.js
import opentype from "opentype.js";
import { exportKerning } from "export-kerning";

const font = await opentype.load("path/to/font.ttf");

// Export all kerning pairs
const result = exportKerning(font);

// With options
const result = exportKerning(font, {
  ranges: "U+0020-007E", // Unicode ranges (optional)
  text: "Sample text", // Generate subset (optional)
});

CLI Usage

You can also use the tool from command line:

Using npx (recommended)

npx export-kerning <font-file> [options]

Using node directly

node index.js <font-file> [options]

Options

  • -o, --output <file> - Output file path (default: "kerning.json")
  • -t, --text <text> - Text to analyze for kerning pairs
  • -r, --ranges <ranges> - Unicode ranges to analyze
  • -h, --help - Display help information

Examples

Export kerning to JSON:

npx export-kerning LibreBaskerville.ttf

Optimized export with ranges :

npx export-kerning LibreBaskerville.ttf -r U+0020-007E

Optimized export with text :

npx export-kerning LibreBaskerville.ttf -t "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."

Export / optimized format

{
  "unitsPerEm": 1000,
  "kerningPairs": [
    { "left": ["f"], "right": ["í", "ı"], "value": 1 },
    { "left": ["ď", "ĩ", "ľ", "ť"], "right": ["ß"], "value": 1 },
    { "left": ["ff"], "right": ["í", "ı", "ȷ"], "value": 1 },
    { "left": ["ĩ"], "right": ["]"], "value": 4 },
    { "left": ["("], "right": ["W", "Ŵ", "Ẁ", "Ẃ", "Ẅ"], "value": 5 },
    {
      "left": ["U", "Ù", "Ú", "Û", "Ü", "Ũ", "Ū", "Ŭ", "Ů", "Ű", "Ų", "Ụ"],
      "right": ["b", "þ"],
      "value": 5
    }
  ]
}

License

ISC

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Packages

No packages published