alto/font

Read OpenType, TrueType, WOFF, and WOFF2 font files from PHP.

Maintainers

Package info

github.com/altophp/font

Homepage

Documentation

pkg:composer/alto/font

Transparency log

Fund package maintenance!

smnandre

Statistics

Installs: 28

Dependents: 1

Suggesters: 0

Stars: 0

Open Issues: 0

v0.8.0 2026-08-10 04:51 UTC

This package is auto-updated.

Last update: 2026-08-13 03:41:20 UTC


README

Read OpenType, TrueType, WOFF, and WOFF2 font files from PHP.

  PHP Version   CI   Packagist   License   GitHub Sponsors

ALTO Font answers what a font contains: names, descriptors, licensing metadata, face dimensions, character maps, glyph metrics, outlines, collections, and variable-font axes. It deliberately does not shape text, apply kerning, or render glyphs.

use Alto\Font\Font;

$font = Font::fromFile(__DIR__.'/fonts/Inter.ttf');

echo $font->metadata()->family;
echo $font->face()->unitsPerEm;
echo $font->getMetrics('A')->advanceWidth;

The package has no PHP package runtime dependencies. Unsupported containers and font features fail with typed exceptions instead of returning partial data.

Installation

Install ALTO Font with Composer:

composer require alto/font

ALTO Font requires PHP 8.4 or later with Iconv and Zlib. Both extensions are included in most PHP distributions. WOFF2 additionally requires the Brotli PHP extension or the brotli executable.

Quick Start

Load a font and inspect its face, descriptor, and one glyph:

use Alto\Font\Font;

$font = Font::fromFile(__DIR__.'/fonts/Inter-Regular.ttf');
$descriptor = $font->getDescriptor();

printf(
    "%s %s, %d units per em\n",
    $descriptor->family,
    $descriptor->subfamily,
    $font->face()->unitsPerEm,
);

$metrics = $font->getMetrics('A');
$outline = $font->glyphOutline($metrics->glyphId);

Metrics and outlines use the font's design units. Read Getting started for scaling and outline inspection.

Format Support

Format Support
TrueType and OpenType with glyf outlines Supported
WOFF 1 Supported
WOFF2 Supported, including transformed glyf, loca, and hmtx
TTC and OTC collections Supported with faceIndex
Variable glyf fonts Supported through fvar, avar, gvar, and HVAR
CFF/CFF2 outlines, WOFF2 collections, and color glyph rendering Not supported

Read Font formats for requirements, boundaries, and failure types.

Discovery

Find the closest face for a family, weight, style, and stretch query:

use Alto\Font\FontFinder;
use Alto\Font\FontQuery;

$finder = FontFinder::fromDirectories(__DIR__.'/fonts');
$font = $finder->get(FontQuery::family('Inter')->weight(700)->italic());

ALTO Font can search application directories, system fonts, or a custom locator. Read Font discovery for matching and absence policies.

Metadata and Glyphs

FontFace exposes structural metrics and table records. FontDescriptor provides names and CSS-like matching values, while FontMetadata includes optional publisher and licensing fields.

Character lookup returns a font-specific glyph identifier. From it, retrieve metrics or neutral contour geometry made of move, line, quadratic-curve, and close commands.

See Font metadata and Glyphs.

Variable Fonts

Inspect axes and select immutable coordinates:

$boldCondensed = $font->withVariations([
    'wght' => 700,
    'wdth' => 85,
]);

Selected coordinates affect supported glyph metrics and outlines. Read Variable fonts for axes, named instances, clamping, and observable results. The complete guide links every topic.

Contributing

Contributions of all kinds are welcome. Visit the project on GitHub to report a bug, suggest a feature, or open a pull request.

Before submitting code, run:

# Runs PHP CS Fixer, PHPStan, and PHPUnit
composer qa

Changes to public behavior should include tests and documentation.

Support

ALTO Font is open source. You can support its continued development through GitHub Sponsors.

Sharing this package with others or starring it on GitHub is also much appreciated.

License

ALTO Font is released by ALTO PHP under the MIT License.