JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 10358
  • Score
    100M100P100Q140390F
  • License MIT

Find ligature replacements for any system font

Package Exports

  • font-ligatures

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (font-ligatures) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

font-ligatures

Travis CI build status codecov npm version

Find ligature replacements for any system font. Useful for determining glyph substitutions and ranges where ligatures exist within a string of input text.

npm install font-ligatures

Usage

const fontLigatures = require('font-ligatures');

(async () => {
  const font = await fontLigatures.load('Iosevka');
  console.log(font.findLigatures('in --> out'));
  // {
  //   inputGlyphs:   [ 76, 81, 3, 16,   16,   33, 3, 82, 88, 87 ],
  //   outputGlyphs:  [ 76, 81, 3, 3140, 3128, 33, 3, 82, 88, 87 ],
  //   contextRanges: [ [ 3, 6 ] ]
  // }
})();

API

load(name)

Loads the font with the given name, returning a Promise with a Font that can be used to find ligature information.

Params

  • name [string] - The font family of the font to load

loadFile(path)

Loads the font at the given path, returning a Promise with a Font that can be used to find ligature information.

Params

  • path [string] - Path to the file containing the font

Font

Object returned by load(). Includes the following methods:

findLigatures(text)

Scans the provided text for font ligatures, returning an object with the following keys:

  • inputGlyphs [number[]] - The list of font glyphs in the input text.
  • outputGlyphs [number[]] - The list of font glyphs after performing replacements for font ligatures.
  • contextRanges [[number, number][]] - Sorted array of ranges that must be rendered together to produce the ligatures in the output sequence. The ranges are inclusive on the left and exclusive on the right

Params

  • text [string] - text to search for ligatures

Font Support

This library is designed to support fonts that make use of programming ligatures. As a result, it is tested against all of the ligatures produced by the following fonts:

If there is another font that you use which doesn't seem to be working, please open an issue with the font information and where to get it. The most likely cause is that the font uses a type of substitution which is not yet supported.

Contributing

Want to contribute to the project? Go check out the Contribution Guide for instructions to set up your development environment, open an issue and create a pull request.