[reportlab-users] RE: fonts.py & RegisterFonts

Henning von Bargen reportlab-users@reportlab.com
Fri, 30 May 2003 09:44:00 +0200


Ian Sparks wrote:
> 
> As Marc Stober identified in a recent post you can't register some fonts =
> with registerFont() because fonts.py identifies a whole set of =
> font-names that are supposedly "registered" which in fact are not part =
> of the standard PDF set.
> 
> At the end of this message is the guilty dictionary in fonts.py which is =
> the reason Marc can't register his 'verdana' font and I can't register =
> an 'Arial' font. For now I'm working round it by registering my font as =
> 'XArial' (yuk).
> 
> Still, there must be a reason for this stuff in here...
> 
> - Ian Sparks.
> 
> ....
>
> #maps a piddle font to a postscript one.
> _tt2ps_map =3D {
> ....
>             ('arial', 0, 0) :'Arial',
>             ('arial', 1, 0) :'Arial-Bold',
>             ('arial', 0, 1) :'Arial-Italic',
>             ('arial', 1, 1) :'Arial-BoldItalic',
> ...
>             }
> 

This seems to be a FAQ, but I didn't find a helpful answer anywhere.
Can it be that the current TrueType implementation is broken somehow?
Can someone post an example where the following fragment actually works
(the text "bold" should be displayed bold etc.):

# what to do here to make it work?
story=[]
styNormal = ParagraphStyle("normal")
styTest = ParagraphStyle ("TestStyle", parent = styNormal, fontName="Arial")
txtTest = "\n".join(["Franz jagt im komplett verwahrlosten Taxi quer durch
Bayern.",
                           "Testing <b>Bold</b> and <i>Italic</i> and
<b><i>BoldItalic</i></b>"
                          ])
story.append (Paragraph (txtTest, styTest))

template = SimpleDocTemplate('test2.pdf', showBoundary=1)
template.build(story)

The problem seems to be that registerFont adds mappings for
plain, bold, italic and bolditalic all to the same font.

Instead I believe that TT font registration SHOULD work in such a way 
that optionally the user can specify up to four TT font files somewhere
(for plain, bold, italic, bolditalic).
The default for the bold and italic font should be the plain font,
and the default for bolditalic should then be the bold font.

And here is another problem: I tried German Umlaute (&auml; etc. in HTML).
But if I try using them in txtTest, I get a ValueError in parse_utf8 in file
ttfonts.py