Script for extracting glyphes by ligatures from font and creating new minimized fonts with them
npm install fontextfontext is a Node.js library that allows you to extract font glyphs and convert them into various formats, including SVG, TTF, WOFF, WOFF2, and EOT. It provides an easy-to-use interface for converting font glyphs to different formats, making it suitable for use in web development projects and font manipulation tasks.
bash
npm install fontext
`
or
`bash
yarn add fontext
`
Usage
`javascript
import { extract } from 'fontext';
// Your font file as a Buffer
const fontBuffer = fs.readFileSync('path/to/your/font.ttf');
// Specify the extraction options
const options = {
fontName: 'YourFontName', // Name of the output font
formats: ['ttf', 'woff', 'woff2'], // Output formats you want to generate
ligatures: ['fi', 'fl'], // Ligatures to include in the font
raws: [''], // Raws unicode that auto find ligatures and include in the font
withWhitespace: true, // Include whitespace glyphs in the font
};
// Extract and convert the font glyphs
extract(fontBuffer, options)
.then(result => {
// 'result' will be an object containing the extracted font data
// You can access the converted formats using 'result.ttf', 'result.woff', etc.
})
.catch(error => { console.error('Font extraction error:', error) });
`
API
`
extract(content: Buffer, option: MinifyOption): Promise
`
The main function that extracts font glyphs and converts them into different formats.
$3
* content Buffer: The font file as a Buffer.
* option MinifyOption: An object containing extraction options.
* fontName string: The desired name for the output font.
* ligatures string[] | undefined: An array of ligatures to include in the font.
* raws string[] | undefined: An array of unicode and symbols that auto find and include in the font.
* formats Formats[] | undefined: An array of output formats to generate. Valid values: 'svg', 'ttf', 'woff', 'woff2', 'eot'.
* withWhitespace boolean | undefined`: Set to true if you want to include whitespace glyphs in the font.