[reportlab-users] ValueError: redefining named object: 'toUnicodeCMap:SUBSET+ArialMT+0'

reportlab-users@reportlab.com reportlab-users@reportlab.com
Fri, 29 Oct 2004 13:19:19 -0400


This is a multipart message in MIME format.
--=_alternative 005F48F485256F3C_=
Content-Type: text/plain; charset="US-ASCII"

I'm trying to use truetype fonts w/ ReportLab.  I am able to add all of my 
frames, however, when I try to save the PDF I get the following traceback:

Traceback (most recent call last):
  File "C:\Python23\lib\threading.py", line 436, in __bootstrap
    self.run()
  File 
"\\ispa02\python23\ss_app\erp\thick_gui\IDCardExecDefinitionMaintenance.py", 
line 441, in run
    einst.test()
  File 
"\\ispa02\python23\lib\site-packages\ss_prod\ss\IDCard\IDCardExecDriver.py", 
line 384, in test
    self.renderer.save()
  File 
"\\ispa02\python23\lib\site-packages\ss_prod\ss\IDCard\IDCardPDFRenderer.py", 
line 255, in save
    self.generate()
  File 
"\\ispa02\python23\lib\site-packages\ss_prod\ss\IDCard\IDCardPDFRenderer.py", 
line 75, in generate
    self.canvas.save()
  File "C:\Python23\Lib\site-packages\reportlab\pdfgen\canvas.py", line 
749, in save
    self._doc.SaveToFile(self._filename, self)
  File "C:\Python23\Lib\site-packages\reportlab\pdfbase\pdfdoc.py", line 
213, in SaveToFile
    fnt.addObjects(self)
  File "C:\Python23\Lib\site-packages\reportlab\pdfbase\ttfonts.py", line 
966, in addObjects
    pdfFont.ToUnicode = doc.Reference(cmapStream, 'toUnicodeCMap:' + 
baseFontName)
  File "C:\Python23\Lib\site-packages\reportlab\pdfbase\pdfdoc.py", line 
449, in Reference
    raise ValueError, "redefining named object: "+repr(name)
ValueError: redefining named object: 'toUnicodeCMap:SUBSET+ArialMT+0'

Does anyone have any ideas what may be causing this and a proposed 
solution?

Here's the part of the code where I create the TTFont object and register 
it:

            fontDBO = element.getFontDBO()              #this is a 
database object that has my font info
            fweight = fontDBO.get_weight_name()
            fstyle = fontDBO.get_style_name()
            fkey = fontDBO.face + fweight + fstyle  #face attribute 
contains "arial"

            if fkey not in self.pstyles.keys():
              pstyle = ParagraphStyle({})
              pstyle.bulletFontName = fontDBO.face
              pstyle.fontSize = fontDBO.points * 0.85
              pstyle.bulletFontSize = fontDBO.points * 0.85
              pstyle.leading = pstyle.fontSize * 1.2
              r, g, b = fontDBO.getColor().Get()
              pstyle.textColor = colors.Color(r, g, b)
              fmodlist = [] 
              fbold = 0
              fital = 0
              if fweight == "Bold":
                fmodlist.append("bold")
                fbold = 1
              if fstyle == "Italic":
                fmodlist.append("italic")
                fital = 1
              if len(fmodlist):
                pstyle.fontName = fontDBO.face.lower() + " " + " 
".join(fmodlist)
              else:
                pstyle.fontName = fontDBO.face.lower()
              isTT = 0
              if pstyle.fontName in fontinfo:
                isTT = 1
                ttffile = fontinfo[pstyle.fontName]
                pdfmetrics.registerFont(TTFont(pstyle.fontName, ttffile))
              addMapping(fontDBO.face, fbold, fital, pstyle.fontName) 
              self.pstyles[fkey] = pstyle
            else:
              pstyle = self.pstyles[fkey]

            flow = []
            textdata = element.static_text
            for line in textdata.split('\n'):
              flow.append( Paragraph(line, pstyle) )
            self.addFrame(posx, posy, sizew, sizeh, flow)
--=_alternative 005F48F485256F3C_=
Content-Type: text/html; charset="US-ASCII"


<br><font size=2 face="sans-serif">I'm trying to use truetype fonts w/
ReportLab. &nbsp;I am able to add all of my frames, however, when I try
to save the PDF I get the following traceback:</font>
<br>
<br><font size=2 face="sans-serif">Traceback (most recent call last):</font>
<br><font size=2 face="sans-serif">&nbsp; File &quot;C:\Python23\lib\threading.py&quot;,
line 436, in __bootstrap</font>
<br><font size=2 face="sans-serif">&nbsp; &nbsp; self.run()</font>
<br><font size=2 face="sans-serif">&nbsp; File &quot;\\ispa02\python23\ss_app\erp\thick_gui\IDCardExecDefinitionMaintenance.py&quot;,
line 441, in run</font>
<br><font size=2 face="sans-serif">&nbsp; &nbsp; einst.test()</font>
<br><font size=2 face="sans-serif">&nbsp; File &quot;\\ispa02\python23\lib\site-packages\ss_prod\ss\IDCard\IDCardExecDriver.py&quot;,
line 384, in test</font>
<br><font size=2 face="sans-serif">&nbsp; &nbsp; self.renderer.save()</font>
<br><font size=2 face="sans-serif">&nbsp; File &quot;\\ispa02\python23\lib\site-packages\ss_prod\ss\IDCard\IDCardPDFRenderer.py&quot;,
line 255, in save</font>
<br><font size=2 face="sans-serif">&nbsp; &nbsp; self.generate()</font>
<br><font size=2 face="sans-serif">&nbsp; File &quot;\\ispa02\python23\lib\site-packages\ss_prod\ss\IDCard\IDCardPDFRenderer.py&quot;,
line 75, in generate</font>
<br><font size=2 face="sans-serif">&nbsp; &nbsp; self.canvas.save()</font>
<br><font size=2 face="sans-serif">&nbsp; File &quot;C:\Python23\Lib\site-packages\reportlab\pdfgen\canvas.py&quot;,
line 749, in save</font>
<br><font size=2 face="sans-serif">&nbsp; &nbsp; self._doc.SaveToFile(self._filename,
self)</font>
<br><font size=2 face="sans-serif">&nbsp; File &quot;C:\Python23\Lib\site-packages\reportlab\pdfbase\pdfdoc.py&quot;,
line 213, in SaveToFile</font>
<br><font size=2 face="sans-serif">&nbsp; &nbsp; fnt.addObjects(self)</font>
<br><font size=2 face="sans-serif">&nbsp; File &quot;C:\Python23\Lib\site-packages\reportlab\pdfbase\ttfonts.py&quot;,
line 966, in addObjects</font>
<br><font size=2 face="sans-serif">&nbsp; &nbsp; pdfFont.ToUnicode = doc.Reference(cmapStream,
'toUnicodeCMap:' + baseFontName)</font>
<br><font size=2 face="sans-serif">&nbsp; File &quot;C:\Python23\Lib\site-packages\reportlab\pdfbase\pdfdoc.py&quot;,
line 449, in Reference</font>
<br><font size=2 face="sans-serif">&nbsp; &nbsp; raise ValueError, &quot;redefining
named object: &quot;+repr(name)</font>
<br><font size=2 face="sans-serif">ValueError: redefining named object:
'toUnicodeCMap:SUBSET+ArialMT+0'</font>
<br>
<br><font size=2 face="sans-serif">Does anyone have any ideas what may
be causing this and a proposed solution?</font>
<br>
<br><font size=2 face="sans-serif">Here's the part of the code where I
create the TTFont object and register it:</font>
<br>
<br><font size=2 face="sans-serif">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
fontDBO = element.getFontDBO() &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp; &nbsp;#this is a database object that has my font
info</font>
<br><font size=2 face="sans-serif">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
fweight = fontDBO.get_weight_name()</font>
<br><font size=2 face="sans-serif">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
fstyle = fontDBO.get_style_name()</font>
<br><font size=2 face="sans-serif">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
fkey = fontDBO.face + fweight + fstyle &nbsp;#face attribute contains &quot;arial&quot;</font>
<br>
<br><font size=2 face="sans-serif">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
if fkey not in self.pstyles.keys():</font>
<br><font size=2 face="sans-serif">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; pstyle = ParagraphStyle({})</font>
<br><font size=2 face="sans-serif">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; pstyle.bulletFontName = fontDBO.face</font>
<br><font size=2 face="sans-serif">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; pstyle.fontSize = fontDBO.points * 0.85</font>
<br><font size=2 face="sans-serif">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; pstyle.bulletFontSize = fontDBO.points * 0.85</font>
<br><font size=2 face="sans-serif">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; pstyle.leading = pstyle.fontSize * 1.2</font>
<br><font size=2 face="sans-serif">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; r, g, b = fontDBO.getColor().Get()</font>
<br><font size=2 face="sans-serif">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; pstyle.textColor = colors.Color(r, g, b)</font>
<br><font size=2 face="sans-serif">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; fmodlist = [] </font>
<br><font size=2 face="sans-serif">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; fbold = 0</font>
<br><font size=2 face="sans-serif">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; fital = 0</font>
<br><font size=2 face="sans-serif">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; if fweight == &quot;Bold&quot;:</font>
<br><font size=2 face="sans-serif">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp; fmodlist.append(&quot;bold&quot;)</font>
<br><font size=2 face="sans-serif">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp; fbold = 1</font>
<br><font size=2 face="sans-serif">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; if fstyle == &quot;Italic&quot;:</font>
<br><font size=2 face="sans-serif">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp; fmodlist.append(&quot;italic&quot;)</font>
<br><font size=2 face="sans-serif">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp; fital = 1</font>
<br><font size=2 face="sans-serif">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; if len(fmodlist):</font>
<br><font size=2 face="sans-serif">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp; pstyle.fontName = fontDBO.face.lower() + &quot; &quot; +
&quot; &quot;.join(fmodlist)</font>
<br><font size=2 face="sans-serif">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; else:</font>
<br><font size=2 face="sans-serif">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp; pstyle.fontName = fontDBO.face.lower()</font>
<br><font size=2 face="sans-serif">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; isTT = 0</font>
<br><font size=2 face="sans-serif">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; if pstyle.fontName in fontinfo:</font>
<br><font size=2 face="sans-serif">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp; isTT = 1</font>
<br><font size=2 face="sans-serif">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp; ttffile = fontinfo[pstyle.fontName]</font>
<br><font size=2 face="sans-serif">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp; pdfmetrics.registerFont(TTFont(pstyle.fontName, ttffile))</font>
<br><font size=2 face="sans-serif">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; addMapping(fontDBO.face, fbold, fital, pstyle.fontName) </font>
<br><font size=2 face="sans-serif">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; self.pstyles[fkey] = pstyle</font>
<br><font size=2 face="sans-serif">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
else:</font>
<br><font size=2 face="sans-serif">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; pstyle = self.pstyles[fkey]</font>
<br>
<br><font size=2 face="sans-serif">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
flow = []</font>
<br><font size=2 face="sans-serif">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
textdata = element.static_text</font>
<br><font size=2 face="sans-serif">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
for line in textdata.split('\n'):</font>
<br><font size=2 face="sans-serif">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; flow.append( Paragraph(line, pstyle) )</font>
<br><font size=2 face="sans-serif">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
self.addFrame(posx, posy, sizew, sizeh, flow)</font>
--=_alternative 005F48F485256F3C_=--