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

8ctopus 6137b7d423 Add php 8.4 to github action workflow 1 week ago
.github 6137b7d423 Add php 8.4 to github action workflow 1 day ago
maps dad8a054d0 Added support for custome encoding to build Adobe Font Metrics files (ie. not Unicode) 13 years ago
src ff30916b5a Fix php 8.4 deprecation nullable parameter must be explicitly declared 1 day ago
tests e32750768a Update Ahem readme and license 7 months ago
.gitattributes 671df0f351 Exclude SECURITY.md from export 11 months ago
.gitignore a45ae21b18 phpunit updates 11 months ago
AUTHORS.md 84d6a7eaae Add Authors file 7 months ago
LICENSE c30c7fc00a Add license file (Fixes #13) 10 years ago
README.md 502d27879e Improve the README 11 months ago
SECURITY.md 1b977efc58 Update SECURITY.md 11 months ago
composer.json c8ae362a22 Set minimum PHP version to 7.1 in Composer configuration 7 months ago
phpunit.xml.dist a45ae21b18 phpunit updates 11 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();