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 6 месяцев назад
.github 991d6a954f Set minimum PHP version to 7.1 for unit testing 6 месяцев назад
maps dad8a054d0 Added support for custome encoding to build Adobe Font Metrics files (ie. not Unicode) 13 лет назад
src e3dd5e54f9 Fix incorrect link in class headers 6 месяцев назад
tests e32750768a Update Ahem readme and license 6 месяцев назад
.gitattributes 671df0f351 Exclude SECURITY.md from export 10 месяцев назад
.gitignore a45ae21b18 phpunit updates 11 месяцев назад
AUTHORS.md 84d6a7eaae Add Authors file 6 месяцев назад
LICENSE c30c7fc00a Add license file (Fixes #13) 10 лет назад
README.md 502d27879e Improve the README 11 месяцев назад
SECURITY.md 1b977efc58 Update SECURITY.md 10 месяцев назад
composer.json c8ae362a22 Set minimum PHP version to 7.1 in Composer configuration 6 месяцев назад
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();