Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

opentype.js

Package Overview
Dependencies
Maintainers
2
Versions
47
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

opentype.js

OpenType font parser

  • 1.3.4
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
2
Created

What is opentype.js?

opentype.js is a JavaScript library for working with OpenType and TrueType fonts. It allows you to parse, manipulate, and render font files directly in the browser or in a Node.js environment.

What are opentype.js's main functionalities?

Parsing Font Files

This feature allows you to load and parse font files. The code sample demonstrates how to load a TrueType font file and handle the result.

const opentype = require('opentype.js');
opentype.load('path/to/font.ttf', function(err, font) {
  if (err) {
    console.error('Could not load font: ' + err);
  } else {
    console.log('Font loaded successfully');
  }
});

Rendering Text

This feature allows you to render text using a loaded font. The code sample shows how to render the text 'Hello, World!' on a canvas context.

const opentype = require('opentype.js');
opentype.load('path/to/font.ttf', function(err, font) {
  if (err) {
    console.error('Could not load font: ' + err);
  } else {
    const path = font.getPath('Hello, World!', 0, 150, 72);
    path.draw(ctx); // ctx is a CanvasRenderingContext2D
  }
});

Accessing Glyph Data

This feature allows you to access detailed glyph data from a font. The code sample demonstrates how to get the glyph for the character 'A' and log its details.

const opentype = require('opentype.js');
opentype.load('path/to/font.ttf', function(err, font) {
  if (err) {
    console.error('Could not load font: ' + err);
  } else {
    const glyph = font.charToGlyph('A');
    console.log(glyph);
  }
});

Other packages similar to opentype.js

Keywords

FAQs

Package last updated on 08 Oct 2021

Did you know?

Socket

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc