[reportlab-users] Flowing Text Around a paragraph.
Robin Becker
reportlab-users@reportlab.com
Sun, 3 Nov 2002 14:08:44 +0000
In article <836726132.20021103132120@lux.de>, Harald Lux <info@lux.de> writes
Well I hacked this up mostly from memory. It seems to work for my simple
test case, but I have not tested with splitting and other horrors.
class ParagraphAndImage(Flowable):
'''combine a Paragraph and an Image'''
def __init__(self,P,I,xpad=3,ypad=3):
self.P, self.style, self.I, self.xpad, self.ypad = P,P.style,I,xpad,ypad
def wrap(self,availWidth,availHeight):
wI, hI = self.I.wrap(availWidth,availHeight)
self.wI, self.hI = wI, hI
# work out widths array for breaking
self.width = availWidth
P, style, xpad, ypad = self.P, self.style, self.xpad, self.ypad
leading = style.leading
leftIndent = style.leftIndent
later_widths = availWidth - leftIndent - style.rightIndent
intermediate_widths = later_widths - xpad - wI
first_line_width = intermediate_widths - style.firstLineIndent
P.width = 0
P.blPara = P.breakLines([first_line_width] + int((hI+ypad)/leading)*[intermediate_widths]+[later_widths])
P.height = len(P.blPara.lines)*leading
self.height = max(hI,P.height)
return (self.width, self.height)
def split(self,availWidth, availHeight):
P, wI, hI, ypad = self.P, self.wI, self.hI, self.ypad
if hI+ypad>availHeight or len(P.frags)<=0: return []
S = P.split(availWidth,availHeight)
if not S: return S
P = self.P = S[0]
del S[0]
style = self.style = P.style
P.height = len(self.P.blPara.lines)*style.leading
self.height = max(hI,P.height)
return [self]+S
def draw(self):
I, P, xoffs, hI, canv = self.I, self.P, (self.width-self.wI-self.xpad), self.hI, self.canv
I.drawOn(canv,xoffs,self.height-hI)
P.drawOn(canv,0,0)
>
>that's exactly the way I need it ...
>
>> since we can specify varying line lengths for the first k lines
>> and the combined flowable can then place the image.
>
>Up to day I used only only existing flowables so it would be nice and
>helpful if you could give me an example?
>
>TIA
>Harald
>
>
--
Robin Becker