[reportlab-users] Reportlab 2.0 Paragraph using <b> with ttf-fonts, HOW?

Andy Robinson andy at reportlab.com
Wed May 2 16:56:28 EDT 2007



> So, is there a way to use those intra-paragraph formattings with registered

> true type fonts? how?


Yes, you need to use the addMapping function to associate your group
of (usually 4) fonts. For example say you have 4 variants of Vera (in
reportlab/fonts on the trunk) you would do...

from reportlab.pdfbase import pdfmetrics
from reportlab.pdfbase.ttfonts import TTFont
pdfmetrics.registerFont(TTFont('Vera', 'Vera.ttf'))
pdfmetrics.registerFont(TTFont('Vera-Bold', 'VeraBd.ttf'))
pdfmetrics.registerFont(TTFont('Vera-Italic', 'VeraIt.ttf'))
pdfmetrics.registerFont(TTFont('Vera-BoldItalic', 'VeraBI.ttf'))

You now have 4 registered fonts. The next step is to associate them
into a family. You use addMapping(family, bold, italic, fontName)
e.g.

from reportlab.lib.fonts import addMapping
addMapping('Vera', 0, 0, 'Vera') #normal
addMapping('Vera', 0, 1, 'Vera-Italic') #italic
addMapping('Vera', 1, 0, 'Vera-Bold') #bold
addMapping('Vera', 1, 1, 'Vera-BoldItalic') #italic and bold

It's a bit clunky - I am working on a 'fontfinder' which can trawl
directories and organise fonts into families like this for you.

- Andy


More information about the reportlab-users mailing list