[reportlab-users] KeyError: Vera-Bold
Johannes Schönberger
jls at icoost.com
Sun Mar 21 03:53:48 EDT 2010
Hi everybody,
I didn't know, if this is also a support "channel", so I apologize if so.
I always get a KeyError, when adding my own fonts, but I have no idea why... my code:
font_dir = os.path.abspath(os.path.dirname(__file__))
for font in ['Vera', 'Arial']:
pdfmetrics.registerFont(TTFont(font,
os.path.join(font_dir, 'fonts/%s.ttf' % font)))
addMapping(font, 0, 0, '%s' % font)
pdfmetrics.registerFont(TTFont('%s-Bold',
os.path.join(font_dir, 'fonts/%s Bold.ttf' % font)))
addMapping(font, 1, 0, '%s-Bold' % font)
pdfmetrics.registerFont(TTFont('%s-Italic' % font,
os.path.join(font_dir, 'fonts/%s Italic.ttf' % font)))
addMapping(font, 0, 1, '%s-Italic' % font)
pdfmetrics.registerFont(TTFont('%s-BoldItalic' % font,
os.path.join(font_dir, 'fonts/%s BoldItalic.ttf' % font)))
addMapping(font, 1, 1, '%s-BoldItalic' % font)
If I try to add a paragraph via platypus with the following content: "Hello <b>World</b>", I get this traceback: (without the <b>-tags it works fine)
I hope you can help me, thank you very much in advance!
In [3]: generate.build_doc('test.pdf', text_before='<b>Hello</b> World')
---------------------------------------------------------------------------
KeyError Traceback (most recent call last)
/folder<ipython console> in <module>()
/folder/generate.py in build_doc(path, template_path, position_data, meta_data, text_before, text_after)
238 elements.append(Paragraph(text_after, style=settings['CONTENT_STYLE']))
239
--> 240 doc.build(elements)
241
242 if template_path is not None:
/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/reportlab/platypus/doctemplate.pyc in build(self, flowables, filename, canvasmaker)
775 try:
776 first = flowables[0]
--> 777 self.handle_flowable(flowables)
778 handled += 1
779 except:
/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/reportlab/platypus/doctemplate.pyc in handle_flowable(self, flowables)
663 canv = self.canv
664 #try to fit it then draw it
--> 665 if frame.add(f, canv, trySplit=self.allowSplitting):
666 if not isinstance(f,FrameActionFlowable):
667 self._curPageFlowableCount += 1
/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/reportlab/platypus/frames.pyc in _add(self, flowable, canv, trySplit)
157 h = y - p - s
158 if h>0:
--> 159 w, h = flowable.wrap(aW, h)
160 else:
161 return 0
/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/reportlab/platypus/paragraph.pyc in wrap(self, availWidth, availHeight)
837 blPara = self.breakLinesCJK([first_line_width, later_widths])
838 else:
--> 839 blPara = self.breakLines([first_line_width, later_widths])
840 self.blPara = blPara
841 autoLeading = getattr(self,'autoLeading',getattr(style,'autoLeading',''))
/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/reportlab/platypus/paragraph.pyc in breakLines(self, width)
1053 n = 0
1054 words = []
-> 1055 for w in _getFragWords(frags):
1056 f=w[-1][0]
1057 fontName = f.fontName
/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/reportlab/platypus/paragraph.pyc in _getFragWords(frags)
382 w = S[-1]
383 W.append((f,w))
--> 384 n += stringWidth(w, f.fontName, f.fontSize)
385 if text and text[-1] in whitespace:
386 W.insert(0,n)
/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/_rl_accel.so in stringWidthU()
/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/reportlab/pdfbase/pdfmetrics.pyc in findFontAndRegister(fontName)
660 #it might have a font-specific encoding e.g. Symbol
661 # or Dingbats. If not, take the default.
--> 662 face = getTypeFace(fontName)
663 if face.requiredEncoding:
664 font = Font(fontName, fontName, face.requiredEncoding)
/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/reportlab/pdfbase/pdfmetrics.pyc in getTypeFace(faceName)
619 """Lazily construct known typefaces if not found"""
620 try:
--> 621 return _typefaces[faceName]
622 except KeyError:
623 # not found, construct it if known
KeyError: 'Vera-Bold'
-----
Johannes Schönberger
<jls at icoost.com>
More information about the reportlab-users
mailing list