[reportlab-users] frame overflow and hypenation
Robin Becker
robin at reportlab.com
Tue Mar 8 09:27:16 EST 2005
Patrick Lawrence - Reportlab Lists wrote:
> Hello,
>
>>From my reading of the documentation, it sounds like it's possible to
> catch an overflow of a frame and take some action.
>
> I'm setting up a script to make a cookbook for my wife and what I'd like
> to do is keep the recipe on one page. To do this, I need to know if the
> frame that contains the ingredient list and directions overflows (both
> the ingredient list and directions have their own paragraph style.) If
> there is an overflow, ideally I'd like to modify the spacing and/or the
> font size until the paragraphs render into the frame without
> overflowing.
>
> Is this possible? Are there any examples that do this (at least catch
> the overflow and do something)?
There is no actual overflow. What happens is that the _add method of the frame
fails when it is too full.
I would be more inclined to handle your situation like this
1) work out how much space is available
2) assemble the story flowables for one page
3) determine the space required by the flowables using the frame width as
available width and an infinite height. You have to give paragraphs a width
anyhow. This code looks like
rh = 0
for f in pageStory:
w,h = f.wrap(width,infinity)
rh += h
4) if the total height is too great you can think of scaling the fonts and
leading in you styles. You should be able to use linear scaling.
if rh>=ah:
sf = (ah/rh)*0.9999
for s in myStyles:
s.fontSize *= sf
s.leading *= sf
s.spaceBefore ......
there are a lot of dimensioned things to worry about
There is a serious gotcha here in that you should be scaling the styles not the
flowables. Since styles are mutables and altering an instance affects everywhere
you ought to get a private copy of the styles at the outset of any piece of
story which might require them to be altered; here the styles ought to be cloned
when you create the styleset for a given page.
This overall approach will work provided arithmetic isn't too exact.
> It looked like in the mailing list archive there was some action on
> hyphenation in 2003 but there isn't anything in the current code or
> documentation from what I saw. Is there any status on this or something
> I'm missing?
>
> Thanks a lot in advance and thanks a lot for Reportlab. It's pretty
> darn impressive.
>
> Regards,
>
> Pat
--
Robin Becker
More information about the reportlab-users
mailing list