[reportlab-users] reportlab-users Digest, Vol 109, Issue 6
Markos Kapes
mkapes at gmail.com
Wed Feb 27 12:59:56 EST 2013
On 27 Φεβ 2013, at 12:00,
"reportlab-users-request at lists2.reportlab.com"
<reportlab-users-request at lists2.reportlab.com> wrote:
> Send reportlab-users mailing list submissions to
> reportlab-users at lists2.reportlab.com
>
> To subscribe or unsubscribe via the World Wide Web, visit
> http://two.pairlist.net/mailman/listinfo/reportlab-users
> or, via email, send a message with subject or body 'help' to
> reportlab-users-request at lists2.reportlab.com
>
> You can reach the person managing the list at
> reportlab-users-owner at lists2.reportlab.com
>
> When replying, please edit your Subject line so it is more specific
> than "Re: Contents of reportlab-users digest..."
>
>
> Today's Topics:
>
> 1. TrueType fonts and barcode widgets (Markos Kapes)
> 2. Re: TrueType fonts and barcode widgets (J. R. Carroll)
>
>
> ----------------------------------------------------------------------
>
> Message: 1
> Date: Tue, 26 Feb 2013 23:23:34 -0500
> From: Markos Kapes <mkapes at gmail.com>
> Subject: [reportlab-users] TrueType fonts and barcode widgets
> To: reportlab-users at lists2.reportlab.com
> Message-ID: <B5FC8D39-9236-43D8-9C3C-50834A076FED at gmail.com>
> Content-Type: text/plain; charset=us-ascii
>
> When using True Type fonts as prescribed in the documentation, I get a value error if I use a unicode font with a barcode widget if I don't also set the font of the barcode widget to the same font. For the time being, it's not a big deal as it still gets the job done, but I'm curious what I might be doing wrong. The code works fine with builtin 'Courier' but if I try a system unicode font, it chokes unless I make sure barcode has the same font.
>
> Thanks,
> --Markos Kapes
>
> The code relevant code is as follows, followed by the stack trace.
> rl_config.warnOnMissingFontGlyphs = 1
> registerFont(TTFont('Courier New', 'Courier New.ttf'))
> registerFont(TTFont('Courier New Bold', 'Courier New Bold.ttf'))
> registerFont(TTFont('Courier New Italic', 'Courier New Italic.ttf'))
> registerFont(TTFont('Courier New Bold Italic', 'Courier New Bold Italic.ttf'))
> registerFontFamily('Courier New', normal='Courier New', bold='Courier New Bold', italic='Courier New Italicc', boldItalic='Courier New Bold Italic')
>
> font = 'Courier New'
> font_size = 9
> doc_width = 2.4*inch
> doc_height = 2*inch
> margin = 0.1*inch
> tmpfile = tempfile.NamedTemporaryFile(delete=False)
>
> canvas1 = canvas.Canvas(tmpfile, (doc_width, doc_height))
> #change coordinates so origin is now at left bottom margin corner
> canvas1.translate(margin, margin)
> text_object = canvas1.beginText()
> text_object.setFont(font, font_size)
> text_object.setTextOrigin(0, column_height-margin)
> text_object.textOut( title)
> text_object.moveCursor(120, 0)
> text_object.textLine(price)
> canvas1.drawText(text_object)
> #create barcode and draw it at the origin.
> barcode1=barcode.createBarcodeDrawing('EAN13', value=isbn, validate=True, width= column_width, height=1.4*inch, humanReadable=True, fontName=font)
> renderPDF.draw(barcode1, canvas1, 0,0)
> canvas1.showPage()
> canvas1.save()
>
>
> ---------------------------------------------------------------------------
> ValueError Traceback (most recent call last)
> /Library/Python/2.7/site-packages/ipython-0.14.dev-py2.7.egg/IPython/utils/py3compat.pyc in execfile(fname, *where)
> 177 else:
> 178 filename = fname
> --> 179 __builtin__.execfile(filename, *where)
>
> /Users/mkapes/Documents/Developer/git_repos/infoshopkeeper/specialOrderLabel.py in <module>()
> 92 canvas1.save()
> 93
> ---> 94 print_special_order_label(isbn=isbn, booktitle=booktitle, author=author, price=price, customer_name=customer_name, customer_phone=customer_phone, customer_email=customer_email)
>
> /Users/mkapes/Documents/Developer/git_repos/infoshopkeeper/specialOrderLabel.py in print_special_order_label(isbn, booktitle, author, price, customer_name, customer_phone, customer_email)
> 90 canvas1.drawText(text_object)
> 91 canvas1.showPage()
> ---> 92 canvas1.save()
> 93
> 94 print_special_order_label(isbn=isbn, booktitle=booktitle, author=author, price=price, customer_name=customer_name, customer_phone=customer_phone, customer_email=customer_email)
>
> /Library/Python/2.7/site-packages/reportlab/pdfgen/canvas.pyc in save(self)
> 1192 After this operation the canvas must not be used further."""
> 1193 if len(self._code): self.showPage()
> -> 1194 self._doc.SaveToFile(self._filename, self)
> 1195
> 1196 def getpdfdata(self):
>
> /Library/Python/2.7/site-packages/reportlab/pdfbase/pdfdoc.pyc in SaveToFile(self, filename, canvas)
> 234 filename = utf8str(filename)
> 235 f = open(filename, "wb")
> --> 236 f.write(self.GetPDFData(canvas))
> 237 if myfile:
> 238 f.close()
>
> /Library/Python/2.7/site-packages/reportlab/pdfbase/pdfdoc.pyc in GetPDFData(self, canvas)
> 246 # realize delayed fonts
> 247 for fnt in self.delayedFonts:
> --> 248 fnt.addObjects(self)
> 249 # add info stuff to signature
> 250 self.info.invariant = self.invariant
>
> /Library/Python/2.7/site-packages/reportlab/pdfbase/ttfonts.pyc in addObjects(self, doc)
> 1124 if doc.compression:
> 1125 cmapStream.filters = [pdfdoc.PDFZCompress]
> -> 1126 pdfFont.ToUnicode = doc.Reference(cmapStream, 'toUnicodeCMap:' + baseFontName)
> 1127
> 1128 pdfFont.FontDescriptor = self.face.addSubsetObjects(doc, baseFontName, subset)
>
> /Library/Python/2.7/site-packages/reportlab/pdfbase/pdfdoc.pyc in Reference(self, object, name, InstanceType)
> 534 other = idToObject[name]
> 535 if other!=object:
> --> 536 raise ValueError, "redefining named object: "+repr(name)
> 537 return PDFObjectReference(name)
> 538 if iob:
>
> ValueError: redefining named object: 'toUnicodeCMap:AAAAAA+CourierNewPSMT'
>> /Library/Python/2.7/site-packages/reportlab/pdfbase/pdfdoc.py(536)Reference()
> 535 if other!=object:
> --> 536 raise ValueError, "redefining named object: "+repr(name)
> 537 return PDFObjectReference(name)
>
> ------------------------------
>
> Message: 2
> Date: Tue, 26 Feb 2013 23:52:21 -0500
> From: "J. R. Carroll" <jrcarroll at jrcresearch.net>
> Subject: Re: [reportlab-users] TrueType fonts and barcode widgets
> To: reportlab-users <reportlab-users at lists2.reportlab.com>
> Message-ID:
> <CAPjhJmVyhZ7W9GJZtxOt6PnwRK+VHMEOPguYmPfswg1qy9rSFw at mail.gmail.com>
> Content-Type: text/plain; charset="iso-8859-1"
>
> Quickly looking at this, could it be that you are trying to embed a font
> that does not exists? (your stack shows it's happening when you save the
> pdf)...
>
> Perhaps the line that reads:
> *
> *
>
>> *italic='Courier New Italicc'*, (extra c?)
>
>
> Not sure if that's a typo, but you might want to do some debugging to make
> sure all your fonts are available and are usable in a separate reportlab
> instance. If that doesn't fix the problem (and no one else responds with
> the solution) let me know.
>
> -J
>
> ----
>
>
> J. R. Carroll
> Independent Researcher through Hurtz Labs
> Research Methods, Test Development, and Statistics
> www.jrcresearch.net
> www.ontvp.com
> Cell: (650) 776-6613
> Email: jrcarroll at jrcresearch.net
> jrcarroll at hurtzlab.com
> jrc.csus at gmail.com
> <https://www.facebook.com/J.R.Car>
> <https://twitter.com/jNammer><http://www.linkedin.com/in/jrcarroll>
>
>
>
> On Tue, Feb 26, 2013 at 11:23 PM, Markos Kapes <mkapes at gmail.com> wrote:
>
>> When using True Type fonts as prescribed in the documentation, I get a
>> value error if I use a unicode font with a barcode widget if I don't also
>> set the font of the barcode widget to the same font. For the time being,
>> it's not a big deal as it still gets the job done, but I'm curious what I
>> might be doing wrong. The code works fine with builtin 'Courier' but if I
>> try a system unicode font, it chokes unless I make sure barcode has the
>> same font.
>>
>> Thanks,
>> --Markos Kapes
>>
>> The code relevant code is as follows, followed by the stack trace.
>> rl_config.warnOnMissingFontGlyphs = 1
>> registerFont(TTFont('Courier New', 'Courier New.ttf'))
>> registerFont(TTFont('Courier New Bold', 'Courier New Bold.ttf'))
>> registerFont(TTFont('Courier New Italic', 'Courier New Italic.ttf'))
>> registerFont(TTFont('Courier New Bold Italic', 'Courier New Bold
>> Italic.ttf'))
>> registerFontFamily('Courier New', normal='Courier New', bold='Courier
>> New Bold', italic='Courier New Italicc', boldItalic='Courier New Bold
>> Italic')
>>
>> font = 'Courier New'
>> font_size = 9
>> doc_width = 2.4*inch
>> doc_height = 2*inch
>> margin = 0.1*inch
>> tmpfile = tempfile.NamedTemporaryFile(delete=False)
>>
>> canvas1 = canvas.Canvas(tmpfile, (doc_width, doc_height))
>> #change coordinates so origin is now at left bottom margin corner
>> canvas1.translate(margin, margin)
>> text_object = canvas1.beginText()
>> text_object.setFont(font, font_size)
>> text_object.setTextOrigin(0, column_height-margin)
>> text_object.textOut( title)
>> text_object.moveCursor(120, 0)
>> text_object.textLine(price)
>> canvas1.drawText(text_object)
>> #create barcode and draw it at the origin.
>> barcode1=barcode.createBarcodeDrawing('EAN13', value=isbn,
>> validate=True, width= column_width, height=1.4*inch, humanReadable=True,
>> fontName=font)
>> renderPDF.draw(barcode1, canvas1, 0,0)
>> canvas1.showPage()
>> canvas1.save()
>>
>>
>> ---------------------------------------------------------------------------
>> ValueError Traceback (most recent call last)
>> /Library/Python/2.7/site-packages/ipython-0.14.dev-py2.7.egg/IPython/utils/py3compat.pyc
>> in execfile(fname, *where)
>> 177 else:
>> 178 filename = fname
>> --> 179 __builtin__.execfile(filename, *where)
>>
>> /Users/mkapes/Documents/Developer/git_repos/infoshopkeeper/specialOrderLabel.py
>> in <module>()
>> 92 canvas1.save()
>> 93
>> ---> 94 print_special_order_label(isbn=isbn, booktitle=booktitle,
>> author=author, price=price, customer_name=customer_name,
>> customer_phone=customer_phone, customer_email=customer_email)
>>
>> /Users/mkapes/Documents/Developer/git_repos/infoshopkeeper/specialOrderLabel.py
>> in print_special_order_label(isbn, booktitle, author, price, customer_name,
>> customer_phone, customer_email)
>> 90 canvas1.drawText(text_object)
>> 91 canvas1.showPage()
>> ---> 92 canvas1.save()
>> 93
>> 94 print_special_order_label(isbn=isbn, booktitle=booktitle,
>> author=author, price=price, customer_name=customer_name,
>> customer_phone=customer_phone, customer_email=customer_email)
>>
>> /Library/Python/2.7/site-packages/reportlab/pdfgen/canvas.pyc in save(self)
>> 1192 After this operation the canvas must not be used
>> further."""
>> 1193 if len(self._code): self.showPage()
>> -> 1194 self._doc.SaveToFile(self._filename, self)
>> 1195
>> 1196 def getpdfdata(self):
>>
>> /Library/Python/2.7/site-packages/reportlab/pdfbase/pdfdoc.pyc in
>> SaveToFile(self, filename, canvas)
>> 234 filename = utf8str(filename)
>> 235 f = open(filename, "wb")
>> --> 236 f.write(self.GetPDFData(canvas))
>> 237 if myfile:
>> 238 f.close()
>>
>> /Library/Python/2.7/site-packages/reportlab/pdfbase/pdfdoc.pyc in
>> GetPDFData(self, canvas)
>> 246 # realize delayed fonts
>> 247 for fnt in self.delayedFonts:
>> --> 248 fnt.addObjects(self)
>> 249 # add info stuff to signature
>> 250 self.info.invariant = self.invariant
>>
>> /Library/Python/2.7/site-packages/reportlab/pdfbase/ttfonts.pyc in
>> addObjects(self, doc)
>> 1124 if doc.compression:
>> 1125 cmapStream.filters = [pdfdoc.PDFZCompress]
>> -> 1126 pdfFont.ToUnicode = doc.Reference(cmapStream,
>> 'toUnicodeCMap:' + baseFontName)
>> 1127
>> 1128 pdfFont.FontDescriptor =
>> self.face.addSubsetObjects(doc, baseFontName, subset)
>>
>> /Library/Python/2.7/site-packages/reportlab/pdfbase/pdfdoc.pyc in
>> Reference(self, object, name, InstanceType)
>> 534 other = idToObject[name]
>> 535 if other!=object:
>> --> 536 raise ValueError, "redefining named object:
>> "+repr(name)
>> 537 return PDFObjectReference(name)
>> 538 if iob:
>>
>> ValueError: redefining named object: 'toUnicodeCMap:AAAAAA+CourierNewPSMT'
>> /Library/Python/2.7/site-packages/reportlab/pdfbase/pdfdoc.py(536)Reference()
>> 535 if other!=object:
>> --> 536 raise ValueError, "redefining named object:
>> "+repr(name)
>> 537 return PDFObjectReference(name)
>> _______________________________________________
>> reportlab-users mailing list
>> reportlab-users at lists2.reportlab.com
>> http://two.pairlist.net/mailman/listinfo/reportlab-users
> -------------- next part --------------
> An HTML attachment was scrubbed...
> URL: <http://two.pairlist.net/pipermail/reportlab-users/attachments/20130226/aa9a3561/attachment.htm>
>
> ------------------------------
>
> _______________________________________________
> reportlab-users mailing list
> reportlab-users at lists2.reportlab.com
> http://two.pairlist.net/mailman/listinfo/reportlab-users
>
>
> End of reportlab-users Digest, Vol 109, Issue 6
> ***********************************************
More information about the reportlab-users
mailing list