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

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();