[reportlab-users] Harmonizing font APIs?
Robin Becker
reportlab-users@reportlab.com
Mon, 29 Jul 2002 10:54:36 +0100
In article <9CAC0DD0-A2D3-11D6-B82C-00039345C610@darwin.in-berlin.de>,
Dinu Gherman <gherman@darwin.in-berlin.de> writes
>Hi,
>
>I'll be writing an article about the ReportLab universe and while
>looking at fonts again, I see that it seems to be much easier to
>use TrueType fonts than it is to use Type-1 fonts - speaking from
>an API point of view. It only takes this much to register a TTF:
>
> from reportlab.pdfbase import pdfmetrics
> from reportlab.pdfbase.ttfonts import TTFont
> pdfmetrics.registerFont(TTFont('Rina', 'rina.ttf'))
> # now use it
> canvas.setFont('Rina', 24)
> canvas.drawString(10, 100, "Text in Rina")
>
>but quite a few more lines to register a Type-1 font:
>
> from reportlab.pdfbase import pdfmetrics
> gFace = pdfmetrics.EmbeddedType1Face('GDB.AFM','GDB.PFB')
> pdfmetrics.registerTypeFace(gFace)
> gFont = pdfmetrics.Font('GaramondBold', 'AGaramond-Bold',
> 'WinAnsiEncoding')
> pdfmetrics.registerFont(gFont)
> # now use it
> c.setFont('AGaramond-Bold', 24)
> c.drawString(100, 650, 'Text in AGaramond-Bold')
>
>Isn't this a great opportunity for refactoring and could we get
>rid off the font face name and having to look manually into the
>AFM file to determine this and/or other names?
>
>I'm not using many fonts excessively, so I wonder if other people
>share this sentiment?
>
>Dinu
TTF fonts are unknown to the renderPM stuff and cannot be used there.
The PDB file is definitely required for that, the AFM file may or may
not be required for string widths.
If we could agree on a search mechanism then certainly by referring to
the correct face/font name the T1 font files can be located.
Andy originally wanted to be able to pass fonts around with a simple
string name and that's the a problem as it introduced an extra layer of
indirection.
--
Robin Becker