[reportlab-users] Preformatted problem with split and join error
Remy C. Cool
reportlab-users@reportlab.com
Mon, 9 Dec 2002 15:25:46 +0100
On Monday 09 December 2002 14:59, Remy C. Cool wrote:
> flowable = Preformatted('this is preformatted text ... <b>t h
> i s i s f a t</b>', self.styleN, bulletText=None, dedent=0))
>
> When I want to check if this text will fit into the frame (object),
> I use:
>
> flowables = self.document.object.split(flowable, self.canvas)
>
> The result is a list with 2 flowables ... one with the text and one
> empty with just a newline character. This happens even if the
> flowable fits nicely into the frame. No problems with Paragraph or
> XPreformatted flowables.
When I change the code in platypus flowables preformatted
flowables.split
def split(self, availWidth, availHeight):
#returns two Preformatted objects
#not sure why they can be called with a negative height
if availHeight < self.style.leading:
return []
linesThatFit = int(availHeight * 1.0 / self.style.leading)
text1 = string.join(self.lines[0:linesThatFit], '\n')
text2 = string.join(self.lines[linesThatFit:], '\n')
style = self.style
if style.firstLineIndent != 0:
style = deepcopy(style)
style.firstLineIndent = 0
# edited to return only one value if text2 is empty
if text2:
return [Preformatted(text1, self.style), Preformatted(text2,
style)]
else:
return [Preformatted(text1, self.style)]
After this 'crude hack' (if you can call it a hack :) my program
works and does not create an empty preformatted flowable after the
split function. I don't know what further impact this has on the
preformatted flowable because I presume that returning two
preformatted objects has a purpose. (?)
Regards,
Remy