[reportlab-users] registerFont(font) does addMapping in RL 1.17

Ury Marshak reportlab-users@reportlab.com
Wed, 2 Apr 2003 16:22:38 +0200


Hi,
After some time I've decided to upgrade the RTL-languages support
to version 1.17 . It went very smooth, but I've bumped into some other
problem. Earlier I was using the following code to load TrueType font:

def _load_times():
    pdfmetrics.registerFont(TTFont('TimesNewRoman', 'times.ttf'))
    pdfmetrics.registerFont(TTFont('TimesNewRomanBD', 'timesbd.ttf'))
    pdfmetrics.registerFont(TTFont('TimesNewRomanI', 'timesi.ttf'))
    pdfmetrics.registerFont(TTFont('TimesNewRomanBI', 'timesbi.ttf'))
    addMapping('TimesNewRoman', 0, 0, 'TimesNewRoman') #normal
    addMapping('TimesNewRoman', 1, 0, 'TimesNewRomanBD') #bold
    addMapping('TimesNewRoman', 0, 1, 'TimesNewRomanI') #italic
    addMapping('TimesNewRoman', 1, 1, 'TimesNewRomanBI') #bold italic


But in 1.17 this code started throwing the exception, that looks like (this
one
speaks about Tahoma, but TimesNewRoman gives the same error):

ValueError: _tt2ps_map[('tahoma', 1, 0)]==Tahoma already, not TahomaBD

I tracked this down to a change in pdfbase/pdfmetrics.py ,
registerFont(font) ,
where the mappings are added automatically to be the same font. So this
brings
the following question - what is the recommended method now to do what I
was doing before - loading different bold/italic fonts and setting the
mapping?

Thanks,
Ury


P.S. Oh, one more thing... Is it possible to do underlined text?