[reportlab-users] Using non-standard fonts on Mac OS X

Jerome Alet reportlab-users@reportlab.com
Wed, 26 May 2004 22:52:17 +0200


--ZGiS0Q5IWpPtfppv
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

Please, could the following explanation be added to ReportLab's
documentation ?

I think it clarifies things in a lot of minds (mine at the very least).

Thanks Marius !!!

Jerome Alet

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=
ook to=20
> > 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=20
> > pointed my test script at the new Arial.ttf it successfully created a T=
TFont=20
> > object -- but alas, it wouldn't register. I got a ValueError in addMapp=
ing=20
> > (fonts.py) suggesting it already *has* Arial registered. So I commented=
 out=20
> > the registration step and what do you know -- my test PDF file is creat=
ed!
> >=20
> > I'm confused now... is font registration a one-off thing, i.e. somethin=
g my=20
> > installation procedure should do? I thought I was going to have to do t=
he=20
> > font magic as part of application startup but apparently not.
>=20
> I believe this is a know problem.
>=20
> 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.
>=20
> Originally registerFont only registered fonts at the base layer, and you
> had to manually call addMapping to tell Platypus about the mappings:
>=20
>   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'))
>=20
>   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')
>=20
> 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.
>=20
> 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.
>=20
> 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.
>=20
> Then you also have another problem which you experienced: the default
> Platypus mappings in lib/fonts.py already include a mapping for 'Arial':
>=20
>   ('arial', 0, 0) :'Arial',
>   ('arial', 1, 0) :'Arial-Bold',
>   ('arial', 0, 1) :'Arial-Italic',
>   ('arial', 1, 1) :'Arial-BoldItalic',
>=20
> Therefore the first step of registerFont succeeds (pdfbase learns about
> the font), but the second step, the addMapping call fails.
>=20
> You could to work around this second issue by using a fake font
> name on the platypus level.
>=20
> Or you can comment out the addMapping calls in registerFont in
> pdfbase/pdfmetrics.py and the default mapping for Arial in lib/fonts.py.
>=20
> HTH,
> Marius Gedminas
> --=20
> 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)


> !DSPAM:40b50122155123509822746!

--=20
"Ni dieu ! Ni Maitre ?" - Me.

--ZGiS0Q5IWpPtfppv
Content-Type: application/pgp-signature; name="signature.asc"
Content-Description: Digital signature
Content-Disposition: inline

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (GNU/Linux)

iD8DBQFAtQOByl5Sl04/FQQRAmaTAJ0eze4t8RP0Dw0uIeGlwa24HPOBFACfcsHT
84DNcPbkmnRA+lwwmPO2xW8=
=+fMJ
-----END PGP SIGNATURE-----

--ZGiS0Q5IWpPtfppv--