A library to read, parse, export and make subsets of different types of font files

Brian Sweeney 991d6a954f Set minimum PHP version to 7.1 for unit testing 2 months ago
.github 991d6a954f Set minimum PHP version to 7.1 for unit testing 2 months ago
maps dad8a054d0 Added support for custome encoding to build Adobe Font Metrics files (ie. not Unicode) 13 years ago
src e3dd5e54f9 Fix incorrect link in class headers 2 months ago
tests e32750768a Update Ahem readme and license 2 months ago
.gitattributes 671df0f351 Exclude SECURITY.md from export 5 months ago
.gitignore a45ae21b18 phpunit updates 6 months ago
AUTHORS.md 84d6a7eaae Add Authors file 2 months ago
LICENSE c30c7fc00a Add license file (Fixes #13) 10 years ago
README.md 502d27879e Improve the README 6 months ago
SECURITY.md 1b977efc58 Update SECURITY.md 5 months ago
composer.json c8ae362a22 Set minimum PHP version to 7.1 in Composer configuration 2 months ago
phpunit.xml.dist a45ae21b18 phpunit updates 6 months ago

README.md

PHPUnit tests

PHP Font Lib

This library can be used to:

  • Read TrueType, OpenType (with TrueType glyphs), WOFF font files
  • Extract basic info (name, style, etc)
  • Extract advanced info (horizontal metrics, glyph names, glyph shapes, etc)
  • Make an Adobe Font Metrics (AFM) file from a font

This project was initiated by the need to read font files in the DOMPDF project.

Usage Example

Base font information

$font = \FontLib\Font::load('fontfile.ttf');
$font->parse();  // for getFontWeight() to work this call must be done first!
echo $font->getFontName() .'<br>';
echo $font->getFontSubfamily() .'<br>';
echo $font->getFontSubfamilyID() .'<br>';
echo $font->getFontFullName() .'<br>';
echo $font->getFontVersion() .'<br>';
echo $font->getFontWeight() .'<br>';
echo $font->getFontPostscriptName() .'<br>';
$font->close();

Font Metrics Generation

$font = FontLib\Font::load('fontfile.ttf');
$font->parse();
$font->saveAdobeFontMetrics('fontfile.ufm');

Create a font subset

$font = FontLib\Font::load('fontfile.ttf');
$font->parse();
$font->setSubset("abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ.:,;' (!?)+-*/== 1234567890"); // characters to include
$font->reduce();
touch('fontfile.subset.ttf');
$font->open('fontfile.subset.ttf', FontLib\BinaryStream::modeReadWrite);
$font->encode(array("OS/2"));
$font->close();