A JS based OpenType font inspector
npm install lib-fontIf you're looking for the (really) old ES5 version of LibFont, when it was still called "Font.js", you should be able to find it here.
Also, if this made a difference in your dev life, consider (temporarily, even?) becoming a patron of my work over on https://www.patreon.com/bezierinfo, or send a one-time donatation to help keep this project funded. Any amount is appreciated!
Use npm install lib-font, after which the package can be imported using import { Font } from "lib-font".
Note that there is no legacy commonjs version of this library available. Node LTS 14 and above have native support for ES modules - Have a look at babel's transform-modules-commonjs plugin if you really have no choice but to use commonjs.
You can either use the pre-built lib-font.browser.js bundle, or you can download the code and unpack it into a vendor directory, then point to the lib-font.js file in that directory. Either way, remember to tell the browser that this is modern ES module code by using type="module" in the script tag, and be kind to your users and remember the async attribute, too:
``html
...
(Although you'll generally want to use this _in_ something so your HTML would look more like
with the myscript.js file having an import { Font } from "./lib-font"; instead)Note that there is no legacy ES5 version of this library available, because there are no ES5 browsers anymore, every single still in support browser supports ES Modules, so if you _really_ need to target dead browsers have a look at babel.
Introduction
What if you could actually inspect your fonts? In the same context that you actually _use_ those fonts?
That's what this is for:
`js
// On the Node side: import { Font } from "lib-font";
// In browser-ESM context: import { Font } from "your/js/dir/lib-font-browser.js";
//
// Also note that on the browser side, you can either use the ESM import
// or you can load the library "on its own" using its own script tag,
// which sets up a global Font object for you to use.// Create a font object
const myFont = new Font(
Adobe Source Code Pro);// Assign event handling (.addEventListener version supported too, of course)
myFont.onerror = evt => console.error(evt);
myFont.onload = evt => doSomeFontThings(evt);
// Kick off the font load by setting a source file, exactly as you would
// for an
or
`#### Why can't this draw stuff??
Because you already have lots of text shaping engines available. In the browser, it's literally your browser (you can already draw all the text you need, properly shaped and typeset, both in HTML and on a Canvas). In node, it's whatever graphics library you're using to already draw everything else you need to draw.
Proper OpenType text shaping is _incredibly complex_ and requires _a lot_ of specialized code; there is no reason for this library to pretend it supports text shaping when it's guaranteed to do it worse than other technologies you're already using.
#### Why would I use this instead of OpenType.js or Fontkit or something?
I don't have a good answer to that. Those are some great projects, you probably _should_ use them if they do what you need? The reason _I_ needed this is because it doesn't do text shaping: it just lets me query the opentype data to get me the information I need, without being too big of a library. And I've written enough OpenType parsers to know how much code goes into the actual shaping.
#### How do I use this with webpack?
By first remembering that bundling was born out of JS not having a module system, where we needed to deliver code in a way that required a single