[IMP/FIX] report, trml2pdf: added the support of registerFontFamily tag to allow the mapping of different fonts for bold, italic or boldItalic

bzr revid: qdp-launchpad@openerp.com-20130531114612-ofcn1swt5o5cc7oc
This commit is contained in:
Quentin (OpenERP) 2013-05-31 13:46:12 +02:00
parent 4045f8c9a5
commit 03d39c5429
1 changed files with 13 additions and 0 deletions

View File

@ -277,11 +277,24 @@ class _rml_doc(object):
fname = font.get('fontFile').encode('ascii')
if name not in pdfmetrics._fonts:
pdfmetrics.registerFont(TTFont(name, fname))
#by default, we map the fontName to each style (bold, italic, bold and italic), so that
#if there isn't any font defined for one of these style (via a font family), the system
#will fallback on the normal font.
addMapping(name, 0, 0, name) #normal
addMapping(name, 0, 1, name) #italic
addMapping(name, 1, 0, name) #bold
addMapping(name, 1, 1, name) #italic and bold
#if registerFontFamily is defined, we register the mapping of the fontName to use for each style.
for font_family in node.findall('registerFontFamily'):
family_name = font_family.get('normal').encode('ascii')
if font_family.get('italic'):
addMapping(family_name, 0, 1, font_family.get('italic').encode('ascii'))
if font_family.get('bold'):
addMapping(family_name, 1, 0, font_family.get('bold').encode('ascii'))
if font_family.get('boldItalic'):
addMapping(family_name, 1, 1, font_family.get('boldItalic').encode('ascii'))
def setTTFontMapping(self,face, fontname, filename, mode='all'):
from reportlab.lib.fonts import addMapping
from reportlab.pdfbase import pdfmetrics