[reportlab-users] TrueType and German Umlaut
Dirk Holtwick
reportlab-users@reportlab.com
Tue, 11 Feb 2003 10:30:40 +0100
> Could you try to be more precise and show some code and tracebacks?
here's an example:
from reportlab.pdfgen.canvas import Canvas
from reportlab.lib.styles import getSampleStyleSheet
from reportlab.lib.units import inch
from reportlab.platypus import Paragraph, Frame
from reportlab.pdfbase import pdfmetrics
from reportlab.pdfbase.ttfonts import TTFont
from reportlab.lib.fonts import addMapping
ttf = "test.ttf"
name = "milano"
pdfmetrics.registerFont(TTFont(name, ttf))
addMapping(name, 0, 0, name) #normal
addMapping(name, 0, 1, name) #italic
addMapping(name, 1, 0, name) #bold
addMapping(name, 1, 1, name) #italic and bol
styles = getSampleStyleSheet()
styleN = styles['Normal']
story = []
story.append(Paragraph("""
<font face="milano">äöü Test FONT Milano</font>
""", styleN))
c = Canvas('mydoc.pdf')
f = Frame(inch, inch, 6*inch, 9*inch, showBoundary=1)
f.addFromList(story,c)
c.save()
--------
the traceback:
Warn: Font milano: _not an encoding_ not found - using Courier: _not an
encoding_ for widths
Traceback (most recent call last):
File "pdftest.py", line 25, in ?
f.addFromList(story,c)
File "H:\work\dado2\python21\reportlab\platypus\frames.py", line 179,
in addFromList
if self.add(head,canv,trySplit=0):
File "H:\work\dado2\python21\reportlab\platypus\frames.py", line 111,
in _add
w, h = flowable.wrap(self._aW, h)
File "H:\work\dado2\python21\reportlab\platypus\paragraph.py", line
382, in wrap
self.blPara = self.breakLines([first_line_width, later_widths])
File "H:\work\dado2\python21\reportlab\platypus\paragraph.py", line
491, in breakLines
wordWidth = stringWidth(word, fontName, fontSize)
File "H:\work\dado2\python21\reportlab\pdfbase\pdfmetrics.py", line
668, in _SWRecover
return _stringWidth(text,'courier',fontSize,encoding)
_rl_accel.error: unknown font
-----
Everything works fine if you strip the chars "äöü" from the abvoe
example. If I change the string to unicode the parser says that it
doesn't like non ascii stuff.
bye, dirk