[reportlab-users] Using non-standard fonts on Mac OS X
Wed, 26 May 2004 22:52:17 +0200
Content-Type: text/plain; charset=us-ascii
Please, could the following explanation be added to ReportLab's
I think it clarifies things in a lot of minds (mine at the very least).
Thanks Marius !!!
On Wed, May 26, 2004 at 08:22:44PM +0300, Marius Gedminas wrote:
> 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 FontB=
> > tell me its whereabouts) and ran fondu on my copy which got me a bunch=
> > of .ttf files (Arial, ArialBold, ArialItalic and ArialBoldItalic). When=
> > pointed my test script at the new Arial.ttf it successfully created a T=
> > object -- but alas, it wouldn't register. I got a ValueError in addMapp=
> > (fonts.py) suggesting it already *has* Arial registered. So I commented=
> > the registration step and what do you know -- my test PDF file is creat=
> > I'm confused now... is font registration a one-off thing, i.e. somethin=
> > installation procedure should do? I thought I was going to have to do t=
> > 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
> registerFont(TTFont('XArial', 'Arial.ttf'))
> registerFont(TTFont('XArialI', 'Arial_Italic.ttf'))
> registerFont(TTFont('XArialB', 'Arial_Bold.ttf'))
> registerFont(TTFont('XArialBI', 'Arial_Bold_Italic.ttf'))
> 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.
> Marius Gedminas
> 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)
"Ni dieu ! Ni Maitre ?" - Me.
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-----