Socket
Socket
Sign inDemoInstall

opentype.js

Package Overview
Dependencies
0
Maintainers
1
Versions
47
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    opentype.js

OpenType font parser


Version published
Weekly downloads
254K
increased by5.66%
Maintainers
1
Install size
212 kB
Created
Weekly downloads
 

Readme

Source

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.

Keywords

FAQs

Last updated on 27 Sep 2013

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc