dompdf / php-font-lib

A library to read, parse, export and make subsets of different types of font files.
GNU Lesser General Public License v2.1
1.73k stars 256 forks source link

How we can Make an Adobe Font Metrics (AFM) file from a font #114

Closed thewebdevelopment closed 1 year ago

thewebdevelopment commented 1 year ago

I have recently checked php-font-lib but not sure how we can create Adobe Font Metrics (AFM) file from a font. Please share example or anything else for better understanding.

bsweeney commented 1 year ago

You can generate font metrics as follows:

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

The default format produced by php-font-lib is "UFM" (Unicode Font Metrics). This format is based on the AFM format but supports the full Unicode character set. The primary difference is that the UFM format references characters using the "U" key (instead of "C") followed by the decimal Unicode index, and also adds a glyph index (G) which indicates where to find the character in the font's glyph table.

If you need the AFM format you have to specify the appropriate encoding, where the encoding matches one of the map files.

$font->saveAdobeFontMetrics(basename($test_file) . '.afm', 'iso-8859-1');

Note that the AFM produced by php-font-lib only writes the code, width, and name for each character.