[reportlab-users] simpler simple code for docs

Carl Karsten carl at personnelware.com
Fri Jan 2 12:05:13 EST 2009

docs section 3.3

... code as simple as this:

class FontNameNotFoundError(Exception):
def findFontName(path):
"Extract a font name from an AFM file."
f = open(path)
found = 0
while not found:
line = f.readline()[:-1]
if not found and line[:16] == 'StartCharMetrics':
raise FontNameNotFoundError, path
if line[:8] == 'FontName':
fontName = line[9:]
found = 1
return fontName

This can be replaced with:

from reportlab.pdfbase import pdfmetrics
(topLevel, glyphData) = pdfmetrics.parseAFMFile(path)

I would post this to the issue tracker, but i cant log in and I wanted to get
this posted somewhere.

Carl K

More information about the reportlab-users mailing list