[XeTeX] Finding out if a font supports a particular Unicode character and using it
pomax at nihongoresources.com
Wed Feb 3 22:55:59 CET 2010
Peter, (and everyone else reading this thread I suppose),
as of yesterday I found I needed a way to determine whether a font
contains a certain glyph in PHP, and it turns out there is no such
functionality available anywhere, at all, using any utility or extension
that PHP understands, so I just decided to take the plunge and write a
TTF/OTF file parser, instead of trying to find ways to glue fontforge
and PHP together. The result is certainly good enough for my own needs
(namely, it correcly parses a ttf/otf file's byte layout and navigates
through the tables to see if the glyph is in the 'Unicode BMP (UCS-2)'
subtable of the 'cmap' table), but perhaps this approach is also helpful
for you and others.
The code is pretty vanilla, and should port ridiculously easily to
Python. Relying on FontForge for full table checking is of course very
nice, but if all you need is to check if a glyph is in a file's
"standard" Unicode BMP cmap, this script might be a nice and quick solution.
I put the file on
http://pomax.nihongoresources.com/downloads/fonttest.php.txt with a .txt
extension, just download and rename to plain .php for the functional script.
- Mike "Pomax" Kamermans
More information about the XeTeX