[reportlab-users] vertically centered text

Aaron Spike aaron at ekips.org
Mon Jan 28 21:17:16 EST 2008


Robin Becker wrote:

> >>> from reportlab.graphics.charts.textlabels import _text2Path

> >>> p=_text2Path('a min')

> >>> p.getBounds()

> (34, -14, 2246, 694)

> >>> p=_text2Path('A min')

> >>> p.getBounds()

> (10, 0, 2524, 694)

> >>>


Trying this.

I do:

from reportlab.pdfgen import canvas
from reportlab.lib.pagesizes import letter
from reportlab.graphics.charts.textlabels import _text2Path

FACE = 'Helvetica'
SIZE = 12

def t(text):
p = _text2Path(text, 0, 0, FACE, SIZE)
return text, p.getBounds()

c = canvas.Canvas('_text2Path_test.pdf', pagesize=letter)
print c.getAvailableFonts()
c.setFont(FACE, SIZE)

print t('test')
print t('tegt')
print t('a min')
print t('A min')

I get:

C:\Documents and Settings\Aaron\Desktop\arpeggio\arpeggio>text2Path.py
['Courier', 'Courier-Bold', 'Courier-BoldOblique', 'Courier-Oblique',
'Helvetica
', 'Helvetica-Bold', 'Helvetica-BoldOblique', 'Helvetica-Oblique',
'Symbol', 'Ti
mes-Bold', 'Times-BoldItalic', 'Times-Italic', 'Times-Roman',
'ZapfDingbats']
Warn: Can't find .pfb for face 'Helvetica'
Traceback (most recent call last):
File "C:\Documents and
Settings\Aaron\Desktop\arpeggio\arpeggio\text2Path.py",
line 16, in <module>
print t('test')
File "C:\Documents and
Settings\Aaron\Desktop\arpeggio\arpeggio\text2Path.py",
line 9, in t
p = _text2Path(text, 0, 0, FACE, SIZE)
File
"C:\Python25\lib\site-packages\reportlab\graphics\charts\textlabels.py",
line 80, in _text2Path

fontSize=fontSize,anchor=anchor,truncate=truncate,pathReverse=pathReverse))
File
"C:\Python25\lib\site-packages\reportlab\graphics\charts\textlabels.py",
line 65, in _text2PathDescription
renderPM._setFont(_gs,fontName,fontSize)
File "C:\Python25\lib\site-packages\reportlab\graphics\renderPM.py",
line 212,
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(Helvetica)
missing the
T1 files?
Originally <type 'exceptions.TypeError'>: makeT1Font() argument 2 must
be string
, not None


I turned up an old thread on google:

http://osdir.com/ml/python.reportlab.user/2005-05/msg00088.html
http://osdir.com/ml/python.reportlab.user/2005-05/msg00092.html
http://bioinf.scri.ac.uk/lp/downloads/programs/genomediagram/renderPM_help.txt

I don't happen to have Acrobat Reader <=5 installed here, so I placed
the Type1 fonts in the fonts directory of the reportlab package. Is
there anything better I can do? I'm wondering, what was the "ready
answer" that Andy had for me?

Aaron Spike


More information about the reportlab-users mailing list