npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

font-metrics

v0.4.3

Published

Node.js font metrics parser

Downloads

10

Readme

Font metrics parser

Javascript tool for parsing font metrics data. Each font is loaded via CSS Font Loading API and then parsed from canvas in Chromium browser with experimentalCanvasFeatures set to true

Usage

  • install package
npm install font-metrics --save-dev
  • include parser via import
import 'fontParser' from 'font-metrics'

or require syntax

var fontParser = require('font-metrics')
  • call parse method
fontParser(options).parse();

Options

  • fonts {Object[]} Array of objects.
  • fonts.fontFamily {String} font-family
  • [fonts.src] {String} Custom fonts are expected to have src value specified. Each font will be loaded via CSS Font Loading API and then parsed.
  • debug {Boolean} Show logs.
  • output {String} Output path.
  • filename {String} Output filename.
  • fontSize {Number} Font size
  • [express] {Object} Express options
    • [express.port] {Number} Express port
    • [express.mount] {Object[]} Additional directories that could be mounted to Express server. Usefull for parsing font files saved locally.
    • [express.mount.alias] {String} Local path alias
    • [express.mount.path] {String} Local path that could be used for using static files
  • nightmare {Object} Nightmare options. Accepts any options that are valid for Nightmare initialization.
    • show {Boolean} Show browser window. Default: false

Returns

JSON data

Usage example

var fontMetrics = require('font-metrics');

fontMetrics({
	fonts: [
		{
			fontFamily: 'Arial'
		},
		{
			fontFamily: 'Roboto',
			src: 'https://fonts.gstatic.com/s/roboto/v15/sTdaA6j0Psb920Vjv-mrzH-_kf6ByYO6CLYdB4HQE-Y.woff2'
		},
		{
			fontFamily: 'SteelworksVintageDemo',
			src: 'mounted-path/SteelworksVintageDemo.otf'
		}
	],
	output: './metrics/',
	filename: 'metrics.json',
	express: {
		port: 3412,
		mount: [
			{
				alias: 'mounted-path',
				path: __dirname + '/your-local-dir-with-fonts'
			}
		]
	}
}).parse();

Output example

{
	"metrics": {
		"Arial": {
			"_fontSize": 24,
			"_textBaseline": "alphabetic",
			"actualBoundingBoxAscent": 0,
			"actualBoundingBoxDescent": 24,
			"actualBoundingBoxLeft": 0,
			"actualBoundingBoxRight": 93,
			"alphabeticBaseline": 0,
			"emHeightAscent": 0,
			"emHeightDescent": 0,
			"fontBoundingBoxAscent": 22,
			"fontBoundingBoxDescent": 5,
			"hangingBaseline": -17.600000381469727,
			"ideographicBaseline": 5,
			"width": 93.375
		},
		"Roboto": {
			"_fontSize": 24,
			"_textBaseline": "alphabetic",
			"actualBoundingBoxAscent": 0,
			"actualBoundingBoxDescent": 24,
			"actualBoundingBoxLeft": 0,
			"actualBoundingBoxRight": 85,
			"alphabeticBaseline": 0,
			"emHeightAscent": 0,
			"emHeightDescent": 0,
			"fontBoundingBoxAscent": 22,
			"fontBoundingBoxDescent": 6,
			"hangingBaseline": -17.600000381469727,
			"ideographicBaseline": 6,
			"width": 85.30078125
		},
		"SteelworksVintageDemo": {
			"_fontSize": 24,
			"_textBaseline": "alphabetic",
			"actualBoundingBoxAscent": 0,
			"actualBoundingBoxDescent": 24,
			"actualBoundingBoxLeft": 0,
			"actualBoundingBoxRight": 69,
			"alphabeticBaseline": 0,
			"emHeightAscent": 0,
			"emHeightDescent": 0,
			"fontBoundingBoxAscent": 19,
			"fontBoundingBoxDescent": 7,
			"hangingBaseline": -15.199999809265137,
			"ideographicBaseline": 7,
			"width": 68.9759521484375
		}
	},
	"src": [
		{
			"fontFamily": "Arial"
		},
		{
			"fontFamily": "Roboto",
			"src": "https://fonts.gstatic.com/s/roboto/v15/sTdaA6j0Psb920Vjv-mrzH-_kf6ByYO6CLYdB4HQE-Y.woff2"
		},
		{
			"fontFamily": "SteelworksVintageDemo",
			"src": "mounted-path/SteelworksVintageDemo.otf"
		}
	]
}