1 unstable release

0.1.0 Jul 26, 2024

#1319 in Parser implementations

MIT/Apache

41KB
829 lines

font-info 🗚

Print font information and metrics

MIT/Apache 2.0 Crates.io Build status

This is a cross-platform program that can parse font files and prints out information such as metrics and font style. It can find fonts installed or your system or you can point it to a specific font file.

Supported font formats:

  • OpenType
  • TrueType

Supported platforms:

  • Unix-like (Fontconfig)
  • Windows (DirectWrite; untested)
  • MacOS (Core Text; untested)

Usage

See $ font-info --help for CLI usage documentation. For example, to find all fonts in the "Liberation Sans" font family on your system and print out their metrics, run:

$ font-info --family-name "Liberation Sans"
-[ FONT 1 ]-------------------------------------------------
              Source: /path/to/share/fonts/truetype/LiberationSans-Bold.ttf
Font index in source: 0
              Weight: 700
               Style: normal
             Stretch: 1.00
         Glyph count: 2620
        Units per em: 2048
     Average advance: 1248
              Ascent: 1854
             Descent: 434
         Line height: 2288
             Leading: 67
      Capital height: 1409
          "x" height: 1082
    Stroke thickness: 215
    Underline offset: -2
    Strikeout offset: 530
-[ FONT 2 ]-------------------------------------------------
... etc

By default font-info produces human-readable output. To output as machine-readable JSON, run:

$ font-info --family-name "Liberation Sans" --format json

You can print fonts' features and supported writing systems using the --print-features and --print-writing-systems flags.

Installation

Install using Cargo:

$ cargo install font-info
$ font-info --family-name "Liberation Sans"

Run using Nix flakes:

# Run ls
$ nix run github:tomcur/font-info -- --family-name "Liberation Sans"

Dependencies

fontconfig

On Unix-like systems this program depends on fontconfig (and pkg-config for finding fontconfig during build). For example, for Debian or Ubuntu:

$ sudo apt install pkg-config libfontconfig-dev

Dependencies

~7–13MB
~166K SLoC