[reportlab-users] TTF fonts with non-Unicode mappings

Srdjan Veljkovic srdjan_veljkovic at yahoo.com
Mon Jul 28 09:07:13 EDT 2008


Hi,Through trial-and-error and a lot of print statements inserted in ReportLab code, I have "discovered" that ReportLab uses only the Unicode mappings ("cmap" tables) in TTF fonts. Some fonts have other mappings too, and actually don't have some glyphs mapped in the Unicode tables, but in these other tables. The fonts delivered with ReportLab (Bitstream Vera Sans) are like this - they containt cyrillic glyphs (and possibly other, I was interested in cyrillic), but cyrillic glyphs are not mapped in the Unicode "cmap" table, they are mapped in the other cmap table (Vera TTF fonts have two "cmap" tables). ReportLab reads only the Unicode table, doesn't find the Unicode code for cyrillic letters (0x04..) in this table, and you get "rectangles" when viewing the generated PDF. The ugly thing is that you can use these fonts (Vera and others too - Luxi for example) in applications, like OpenOffice.org Writer, and get PDFs with cyrillic glyphs.The workaround is
to use TTF fonts with "full" (or _just_) Unicode mappings, like DejaVu.I have a few points:1. This should be documented, so that people other than me don't loose two days over this. :)2. Maybe Vera fonts should be changed with DejaVu fonts in ReportLab distribution. I mean, you expect the fonts delivered with ReportLab to work with ReportLab, so this would be better than just documenting.3. Maybe it is not so difficult to support these other mappings. I'm not a Python expert, but I think Python has standard encoding mapping libraries. It should be sufficient to read the encoding of the "cmap" table in TTF, and use it to translate the glyph codes to Unicode. I was actually on the verge of coding this, before I "discovered" DejaVu fonts. Maybe I will code this if I happen to need some font, with no replacement for it, but I think someone with more Python knowledge is a better candidate for coding it.Best regards,Srdjan



-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://two.pairlist.net/pipermail/reportlab-users/attachments/20080728/48c3bb41/attachment.html>


More information about the reportlab-users mailing list