1.2.0 • Published 3 months ago

fontext v1.2.0

Weekly downloads
-
License
MIT
Repository
github
Last release
3 months ago

Fontext (Font Extractor)

fontext 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.

Installation

To install fontext, use npm or yarn:

npm install fontext

or

yarn add fontext

Usage

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<ExtractedResult>

The main function that extracts font glyphs and converts them into different formats.

Parameters

  • 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.

Returns

  • Promise\<ExtractedResult>: A promise that resolves to an object containing the extracted font data, with keys corresponding to the specified output formats.

License

fontext is released under the MIT License. See the LICENSE file for details.

Contributions

Contributions are welcome! If you find a bug or want to add a new feature, please open an issue or submit a pull request.

Credits

fontext is built on top of various open-source libraries like fontkit, svg2ttf, ttf2woff, ttf2woff2, ttf2eot, SVGIcons2SVGFontStream, handlebars, and more. Thanks to all the developers and contributors of these projects.

1.2.0

3 months ago

1.1.1

4 months ago

1.1.0

4 months ago

1.1.2

4 months ago

1.0.9

5 months ago

1.0.8

5 months ago

1.0.10

5 months ago

1.0.7

9 months ago

1.0.6

9 months ago

1.0.5

9 months ago

1.0.4

9 months ago

1.0.3

9 months ago

1.0.2

9 months ago

1.0.1

9 months ago

1.0.0

9 months ago