Socket
Socket
Sign inDemoInstall

font-measure

Package Overview
Dependencies
11
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    font-measure

Calculate metrics of a font


Version published
Weekly downloads
171K
decreased by-14.56%
Maintainers
1
Install size
71.6 kB
Created
Weekly downloads
 

Readme

Source

font-measure unstable

Calculate metrics for a font.

npm install font-measure

let measure = requrie('font-measure')

measure('Roboto')

/*
{
  top: 0,
  median: 0.640625,
  middle: 0.640625,
  bottom: 1.3125,
  alphabetic: 1.03125,
  baseline: 1.03125,
  upper: 0.328125,
  lower: 0.515625,
  capHeight: 0.703125,
  xHeight: 0.515625
  ascent: 0.28125,
  descent: 1.234375,
  hanging: 0.203125,
  ideographic: 1.296875,
  lineHeight: 1.3125,
  overshoot: 0.015625,
  tittle: 0.28125,
}
 */

API

let metrics = measure(family, options?)

Get metrics data for a font family or CSS font string, possibly with custom options. Font can be a string or an array with fonts.

metrics:
options:
PropertyDefaultMeaning
origintopOrigin for metrics. Can be changed to baseline or any other metric.
fontSize64Font-size to use for calculations. Larger size gives higher precision with slower performance.
fontWeightnormalFont weight to use for calculations, eg. bold, 700 etc.
fontStylenormalFont style to use for calculations, eg. italic, oblique.
canvasmeasure.canvasCanvas to use for measurements.
tittleiCharacter to detect tittle. null disables calculation.
descentpCharacter to detect descent line. null disables calculation.
ascenthCharacter to detect ascent line. null disables calculation.
overshootOCharacter to detect overshoot. null disables calculation.
upperHCharacter to detect upper line / cap-height. null disables calculation.
lowerxCharacter to detect lower line / x-height. null disables calculation.

See also

  • optical-properties − calculate image/character optical center and bounding box.
  • detect-kerning − calculate kerning pairs for a font.

There are many text / font measuring packages for the moment, but most of them don't satisfy basic quality requirements. Special thanks to @soulwire for fontmetrics as model implementation.

License

© 2018 Dima Yv. MIT License

Development supported by plot.ly.

Keywords

FAQs

Last updated on 03 Jul 2018

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