[reportlab-users] Harmonizing font APIs?

Dinu Gherman reportlab-users@reportlab.com
Mon, 29 Jul 2002 11:14:40 +0200


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