[reportlab-users] Re: rotated text (90?) in a table cell

Paulino paulino1 at sapo.pt
Wed Oct 18 16:47:33 EDT 2006


> ------------------------------
>
> Message: 5
> Date: Wed, 18 Oct 2006 10:35:00 +0100
> From: Robin Becker <robin at reportlab.com>
> Subject: Re: [reportlab-users] rotated text (90?) in a table cell
> To: Support list for users of Reportlab software
> 	<reportlab-users at reportlab.com>
> Message-ID: <4535F544.4020703 at chamonix.reportlab.co.uk>
> Content-Type: text/plain; charset=ISO-8859-1; format=flowed
>
>   
> ......
>
> Flowables need to report the width and height of the wrapped contents; so you 
> need to override the wrap method. In this simple case I guess you need something 
> like
>
>      def wrap(self,aW,aH):
>          canv = self.canv
>          return canv._leading, canv.stringWidth(self.text)
>
> because width and height are interchanged.
>   
well now the script gives some errors:

Traceback (most recent call last):
  File "D:/Python/reportlab/PPI_cabec.py", line 40, in <module>
    doc.build(story)
  File "C:\Python25\reportlab\platypus\doctemplate.py", line 870, in build
    BaseDocTemplate.build(self,flowables, canvasmaker=canvasmaker)
  File "C:\Python25\reportlab\platypus\doctemplate.py", line 702, in build
    self.handle_flowable(flowables)
  File "C:\Python25\reportlab\platypus\doctemplate.py", line 617, in 
handle_flowable
    if self.frame.add(f, self.canv, trySplit=self.allowSplitting):
  File "C:\Python25\reportlab\platypus\frames.py", line 133, in _add
    w, h = flowable.wrap(aW, h)
  File "C:\Python25\reportlab\platypus\tables.py", line 966, in wrap
    self._calc(availWidth, availHeight)
  File "C:\Python25\reportlab\platypus\tables.py", line 512, in _calc
    self._calc_height(availHeight,availWidth,W=W)
  File "C:\Python25\reportlab\platypus\tables.py", line 469, in _calc_height
    dW,t = self._listCellGeom(v,w,s)
  File "C:\Python25\reportlab\platypus\tables.py", line 349, in 
_listCellGeom
    vw, vh = v.wrapOn(canv,aW, aH)
  File "C:\Python25\reportlab\platypus\flowables.py", line 114, in wrapOn
    w, h = self.wrap(aW,aH)
  File "D:/Python/reportlab/PPI_cabec.py", line 21, in wrap
    return canv._leading, canv.stringWidth(self.text)
TypeError: stringWidth() takes exactly 4 arguments (2 given)

......
I think the missing arguments should be aW, aH

"return canv._leading, canv.stringWidth(self.text, aW, aH)"

and the shell gives this traceback:


Traceback (most recent call last):
  File "D:/Python/reportlab/PPI_cabec.py", line 40, in <module>
    doc.build(story)
  File "C:\Python25\reportlab\platypus\doctemplate.py", line 870, in build
    BaseDocTemplate.build(self,flowables, canvasmaker=canvasmaker)
  File "C:\Python25\reportlab\platypus\doctemplate.py", line 702, in build
    self.handle_flowable(flowables)
  File "C:\Python25\reportlab\platypus\doctemplate.py", line 617, in 
handle_flowable
    if self.frame.add(f, self.canv, trySplit=self.allowSplitting):
  File "C:\Python25\reportlab\platypus\frames.py", line 133, in _add
    w, h = flowable.wrap(aW, h)
  File "C:\Python25\reportlab\platypus\tables.py", line 966, in wrap
    self._calc(availWidth, availHeight)
  File "C:\Python25\reportlab\platypus\tables.py", line 512, in _calc
    self._calc_height(availHeight,availWidth,W=W)
  File "C:\Python25\reportlab\platypus\tables.py", line 469, in _calc_height
    dW,t = self._listCellGeom(v,w,s)
  File "C:\Python25\reportlab\platypus\tables.py", line 349, in 
_listCellGeom
    vw, vh = v.wrapOn(canv,aW, aH)
  File "C:\Python25\reportlab\platypus\flowables.py", line 114, in wrapOn
    w, h = self.wrap(aW,aH)
  File "D:/Python/reportlab/PPI_cabec.py", line 21, in wrap
    return canv._leading, canv.stringWidth(self.text, aW, aH)
  File "C:\Python25\reportlab\pdfgen\canvas.py", line 1283, in stringWidth
    return pdfmetrics.stringWidth(text, fontName, fontSize)
  File "C:\Python25\reportlab\pdfbase\pdfmetrics.py", line 709, in 
_py_stringWidth
    return getFont(fontName).stringWidth(text, fontSize, encoding=encoding)
  File "C:\Python25\reportlab\pdfbase\pdfmetrics.py", line 678, in 
_py_getFont
    return findFontAndRegister(fontName)
  File "C:\Python25\reportlab\pdfbase\pdfmetrics.py", line 660, in 
findFontAndRegister
    face = getTypeFace(fontName)
  File "C:\Python25\reportlab\pdfbase\pdfmetrics.py", line 619, in 
getTypeFace
    return _typefaces[faceName]
KeyError: 28



the script:

from reportlab.platypus.flowables import Flowable
from reportlab.platypus import SimpleDocTemplate, Paragraph, Table
from reportlab.lib.units import cm
from reportlab.lib import colors
from reportlab.lib.styles import ParagraphStyle

stlppi = ParagraphStyle("normal", fontName='Helvetica', fontSize=8)

class TTR(Flowable): #TableTextRotate
    '''Rotates a tex in a table cell.'''
    def __init__(self, text ):
        Flowable.__init__(self)
        self.text=text
    def draw(self):
        canv = self.canv
        canv.rotate(90)
        canv.drawString( 0, -1, self.text)
    def wrap(self, aW, aH) :
        canv = self.canv
        return canv._leading, canv.stringWidth(self.text)

doc=SimpleDocTemplate('vertical2.pdf')

cli=Paragraph( 'Clientes de cobranca muito duvidosa', style=stlppi)

dados=[ [ 'codigo', TTR('nivel'), 'descricao'],
        [ '11', '0', 'Caixa'],
        [ '21', '1', cli ] ]

st=[( 'ALIGN',(1,0), (1, -1), 'CENTER' ),
    ('INNERGRID', (0,0), (-1,-1), 0.25, colors.blue ),
    ('BOX', (0,0), (-1,-1), 0.25, colors.blue ),
    ('VALIGN', (0,0), (-1,-1), 'MIDDLE' ) ]

tb=Table(dados, colWidths=(40, 40, 100), style=st )

story=[tb]

doc.build(story)

..........

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://two.pairlist.net/pipermail/reportlab-users/attachments/20061018/8ee924d3/attachment.html


More information about the reportlab-users mailing list