[reportlab-users] Trouble using TTF font
Satish Kalipatnapu
Satish.Kalipatnapu at CipherTrust.com
Wed Apr 12 11:20:20 EDT 2006
You can convert the TTF to PFB+AFM using tools like fontforge.
-----Original Message-----
From: reportlab-users-bounces at reportlab.com
[mailto:reportlab-users-bounces at reportlab.com] On Behalf Of George Lee
Sent: Tuesday, March 21, 2006 11:31 PM
To: reportlab-users at reportlab.com
Subject: [reportlab-users] Trouble using TTF font
Below is code and traceback for an attempt to use a TTF font, and some
additional information. Most recent stable RenderPM (1.01), and
reportlab .... Any idea what is going wrong?? Are certain TTF fonts not
supported?
I'm pretty sure that this code actually finds the font on the
filesystem, because I see all the font data loaded into the variable
socketFont.
Thanks; peace,
George
****************************************************************
CODE
****************************************************************
facename = "Socket"
folder = "/usr/local/zope/instance1/var/fonts"
ttffile = "Socket.TTF"
fontsize = 21
reportlab.rl_config.TTFSearchPath.append(folder)
socketFont = TTFont(facename, ttffile)
pdfmetrics.registerFont(socketFont)
c = renderPM.PMCanvas(400, 50)
c.setFont(facename, fontsize)
****************************************************************
TRACEBACK
****************************************************************
Warn: Can't find .pfb for face 'Socket'
Traceback (most recent call last):
File "test.py", line 19, in ?
c.setFont(facename, fontsize)
File
"/usr/local/lib/python2.3/site-packages/reportlab/graphics/renderPM.py",
line 327, in setFont
_setFont(self._gs,fontName,fontSize)
File
"/usr/local/lib/python2.3/site-packages/reportlab/graphics/renderPM.py",
line 207, in _setFont
raise RenderPMError, "Can't setFont(%s) missing the T1
files?\nOriginally %s: %s" % (fontName,s1,s2)
reportlab.graphics.renderPM.RenderPMError: Can't setFont(Socket) missing
the T1 files? Originally exceptions.AttributeError: TTEncoding instance
has no attribute 'vector'
****************************************************************
ADDITIONAL INFORMATION
****************************************************************
If it helps, using a python debugger the following occurs:
(1) In reportlab/graphics/renderPM.py(195)_setFont(), the code
try:
gs.setFont(fontName, fontSize)
fails with Error "Can't find font!"
(2) So instead, renderPM tries to execute
_renderPM.makeT1Font(fontName,f.face.findT1File(),f.encoding.vector,open
_and_read)
(3) But f.encoding is {'name': 'UTF-8'}, without a 'vector' attribute,
causing an AttributeError. f.encoding is first set in the
initialization
socketFont = TTFont(facename, ttffile)
which includes the line
encoding = TTEncoding()
which intializes encoding to {'name': 'UTF-8'}.
Should the error in (1) even occur? What is going on in (3)?
_______________________________________________
reportlab-users mailing list
reportlab-users at reportlab.com
http://two.pairlist.net/mailman/listinfo/reportlab-users
More information about the reportlab-users
mailing list