[XeTeX] Finding out if a font supports a particular Unicode character and using it

Chris Jones cjns1989 at gmail.com
Tue Feb 2 04:10:09 CET 2010

On Mon, Feb 01, 2010 at 08:11:25AM EST, Peter Baker wrote:
> Chris Jones wrote:

>> I maintain a debian squeeze system on another partition so I can find
>> out what I'm in for when "testing" becomes "stable". Let me check the
>> version of fontforge on that system and run a test to see if it make a
>> difference.

Sorry for the delay and not getting back to you earlier.

> Here are a couple of other tests:
> Open unifont.ttf in the FontForge GUI and see what happens. Does it  
> freeze the machine?


I ran a quick test this morning and fontforge aborted with a message to
the effect that it was unable to allocate memory.

I tried to recreate tonight so I could paste the exact message, and
although I had two instances of a heavy weight browser open, each with
about half a dozen tabs, and was streaming a TV news channel on another
VT at the same time, fontforge was able to open the font file. It took
about ten minutes and the machine was not useable for any form of
interactive use. It ended up gobbling up about one gig of memory, pretty
much the same as the fontswith script.

So it looks like this a problem with my rather old version of fontforge
or the python bindings, and that I need to test on debian squeeze or
ubuntu 9.10 which probably ship a more current version.

I should be able to reboot some time tomorrow and will keep you posted.

> Try this minimal Python script (make sure not to lose the spacing):
> import fontforge
> import sys
> try:
>    f = fontforge.open(sys.argv[1])
> except Exception:
>    sys.stderr.write("Couldn't open " + sys.argv[1] + "\n")
> else:
>    try:
>        gly = f['A']
>    except TypeError:
>        sys.stdout.write("This font doesn't contain the letter A\n")
>    else:
>        sys.stdout.write("This font contains the letter A\n")
>    f.close()

I will run that as well tomorrow.

>> Also, I checked my ~/.fontswith/ directory and found a
>> fontswith.index file in there and quickly browsing it confirmed that
>> your script had successfully indexed GNU/unifont at some point. 

>> I ran a quick test that quickly revealed the following:
>> | $ fontswith ~/.fontswith/fontswith.index U+5D0
>> | These fonts contain the glyph U+05D0:
>> | unifont: ./unifont.ttf
>> So it looks like the indexing did work at some point.

> That was probably from an earlier version: the current version uses
> bzip2 to compress the index. If you use bzip2 to make
> ~/.fontswith/fontswith.index.bz2, then fontswith will see it and use
> it  automatically. Or use the -n or --no-bz2 option to automatically
> use the  uncompressed index. If you type fontswith -h you'll get some
> additional  usage info.

Yes, I notices the -h option. Very useful. 

Never used with python input, but you might be able use the help2man
utility to generate a man page at minimal cost. 



More information about the XeTeX mailing list