canvas-font-metrics

1.0.6 • Public • Published

A performant javascript library that provides useful font metrics, including:

  • Ascent
  • Cap height
  • Tittle
  • X-Height
  • Baseline
  • Available ligatures
  • Available glyphs

It uses the Font Face Observer library to ensure the fonts are loaded before providing metrics.

Note: This library provides some metrics that aren't neccessary for most use cases (ligature and glyph detection, for instance). The bulk of the filesize comes from the inclusion of Adobe's 'Blank' font, which is used to detect what glyphs are available in a font. This functionality can be removed, if needed.

Installation

yarn add canvas-font-metrics

Usage

import CanvasFontMetrics from 'canvas-font-metrics'

var metrics = await CanvasFontMetrics({
	fontFamily: 'Helvetica',
	fontWeight: 400,
	fontStyle: 'normal',
	options: null // override default options
})

/*

metrics {
	capHeight,
	baseline,
	xHeight,
	descent,
	ascent,
	tittle,
	ligatures,
	getGlyphs,
	measureWidth,
	measureText
}

*/

To do: Finish documentation

Readme

Keywords

none

Package Sidebar

Install

npm i canvas-font-metrics

Weekly Downloads

1

Version

1.0.6

License

MIT

Unpacked Size

149 kB

Total Files

8

Last publish

Collaborators

  • peteshilling