[reportlab-users] Using non-standard fonts on Mac OS X
Wed, 26 May 2004 20:22:44 +0300
Content-Type: text/plain; charset=us-ascii
On Wed, May 26, 2004 at 03:23:24PM +0100, Tim Jarman wrote:
> I copied the original Arial font file (using the cmd-R thing from FontBoo=
> tell me its whereabouts) and ran fondu on my copy which got me a bunch=20
> of .ttf files (Arial, ArialBold, ArialItalic and ArialBoldItalic). When I=
> pointed my test script at the new Arial.ttf it successfully created a TTF=
> object -- but alas, it wouldn't register. I got a ValueError in addMappin=
> (fonts.py) suggesting it already *has* Arial registered. So I commented o=
> the registration step and what do you know -- my test PDF file is created!
> I'm confused now... is font registration a one-off thing, i.e. something =
> installation procedure should do? I thought I was going to have to do the=
> font magic as part of application startup but apparently not.
I believe this is a know problem.
There are two layers in Reportlab. The base pdfgen layer considers each
of the variants of Arial (Arial.ttf, ArialBold.ttf and so on) to be a
completely separate font. The Platypus layer considers all these to be
variants of the same font and knows how to map from a font name
("Arial") and a variant (Bold) to a pdfgen-registered font name.
Originally registerFont only registered fonts at the base layer, and you
had to manually call addMapping to tell Platypus about the mappings:
from reportlab.pdfbase.pdfmetrics import registerFont
from reportlab.lib.fonts import addMapping
addMapping('Arial', 0, 0, 'XArial')
addMapping('Arial', 0, 1, 'XArialI')
addMapping('Arial', 1, 0, 'XArialB')
addMapping('Arial', 1, 1, 'XArialBI')
I intentionally called the pdfgen-level font name 'XArial' to avoid
confusion with platypus-level name 'Arial', and to show that the font
name can be arbitrary.
Back to the problem: someone changed registerFont code to call
addMapping and register mappings for all four variants to the same font.
I do not understand the reason for that change. The comment implies
that this change was targeted to PostScript CID fonts, and affects
TrueTypes accidentally, because those are also multibyte fonts.
So you have one problem: you cannot use all four variants of 'Arial' on
the platypus level, as they all map to the same base font. You can work
around this by using a fake font name like XArial that I did before.
Then you also have another problem which you experienced: the default
Platypus mappings in lib/fonts.py already include a mapping for 'Arial':
('arial', 0, 0) :'Arial',
('arial', 1, 0) :'Arial-Bold',
('arial', 0, 1) :'Arial-Italic',
('arial', 1, 1) :'Arial-BoldItalic',
Therefore the first step of registerFont succeeds (pdfbase learns about
the font), but the second step, the addMapping call fails.
You could to work around this second issue by using a fake font
name on the platypus level.
Or you can comment out the addMapping calls in registerFont in
pdfbase/pdfmetrics.py and the default mapping for Arial in lib/fonts.py.
Apologies for taking up the bandwidth with the apology. Anything else I
can apologise for ...... er no can't think of anything, sorry about that.
Andy Hunt (Member of British Olympic Apology Squad)
Content-Type: application/pgp-signature; name="signature.asc"
Content-Description: Digital signature
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (GNU/Linux)
-----END PGP SIGNATURE-----