Drawing glyphs based on their index (NOT their character code)

Christian Stapfer nobody at nowhere.nil
Thu May 20 07:02:53 EDT 2010


Here's an interesting little problem: I am given a master.ttf font file and 
a subset file subset.ttf of that font, and I am asked to map indices of all 
the glyphs in subset.ttf to the corresponding indices in master.ttf. The 
subset font file is the result of a pipeline of 3 tools (pdflatex, Adobe 
Reader, and the Microsoft XPS Document Writer).
  The resulting document format (XAML) holds indices into subset.ttf, and in 
order to display that document with reference to master.ttf, I need to do 
this mapping of indices: subset -> master.
(Carrying subset.ttf along with the XAML code is not an option, I think, 
because I need to be able to support copy and paste of small snippets from 
that document through a shared whiteboard.)

I have tried to parse the two font files to the point of having the x- and 
y-coordinate points of the outlines of glyphs handy. But, unfortunately, 
subset.ttf has been processed in a way that makes it very difficult to 
compare its glyph outlines with the outlines of glyphs in master.ttf.

So my next best idea is to draw the various glyphs as, 16x16 B/W images, 
say, and use the 16*16 bits (that is, 16 ints or 8 longs) that result from 
this as a sufficiently precise description of the glyph to do the necessary 
comparisons.

PIL would be great for this, except for one "little" problem: I need to be 
able to draw glyphs based on their index, not based on their character code.

Any ideas to get around that limitation of PIL's drawing primitives?

Thanks in advance,
Christian 




More information about the Python-list mailing list