JSPM

  • Created
  • Published
  • Downloads 241180
  • Score
    100M100P100Q166133F

OpenType font parser

Package Exports

  • opentype.js

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 (opentype.js) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

opentype.js

opentype.js is a JavaScript parser for TrueType and OpenType fonts.

It gives you access to the letterforms of text from the browser or node.js.

Example of opentype.js

Here's an example. We load a font using an XMLHttpRequest, then display it on a canvas with id "canvas":

var req = new XMLHttpRequest();
req.open('get', 'fonts/Roboto-Black.ttf', true);
req.responseType = 'arraybuffer';
req.onload = function () {
    var arrayBuffer = req.response;
    var font = opentype.parseFont(arrayBuffer);
    if (!font.supported) {
        alert('This font is not supported.');
    }
    var ctx = document.getElementById('canvas').getContext('2d');
    // The path is always placed on the baseline, so move it down to make it visible.
    var path = font.getPath('Hello, World!', {x: 0, y: 150, fontSize: 72});
    path.draw(ctx);
};
req.send(null);

See index.html for a bigger example.

Features

  • Create a bézier path out of a piece of text.
  • Support for composite glyphs (accented letters).
  • Support for kerning tables (configurable and on by default).
  • Very efficient.
  • Runs in the browser and node.js.

Planned

  • Support for PostScript outlines.
  • Better support for composite glyphs (advanced scaling and transformations).
  • Support for ligatures and contextual alternates.