Truncating a flowable to fit a frame

Lele Gaifax <[email protected]> Sat, 19 Dec 2020 09:09:11 +0100
Newsgroups gmane.comp.python.reportlab.user
Organization Nautilus Entertainments
Message-ID <[email protected]>
Hi,

an app of mine produces a periodic newsletter, mostly composed by a set of
fixed size frames that are filled with some flowable content. The "editor"
user has the responsibility of tweaking the content to make it fit in each
frame.

Now I'm asked about a different approach, where the content for some of those
"areas" may be arbitrarily long, and the system automatically truncates each
flowable as soon as the related frame is full, possibly leaving some space at
the bottom to add something like 'See <a href="here">full content here</a>'.

A brute force implementation would be something like:

  story = [....]
  fits = False
  while not fits:
    flowable = SomeFlowable(story)
    if frame.add(flowable, canvas):
      break
    story = replace_some_trailing_text_with_ellipsis(story)

I suspect that a slightly better way could use the split() method on the
flowable, maybe passing it the height of the frame corrected to leave space
for the hyperlink.... I will try to understand the logic used for example by
PTOContainer().

Any hint would be appreciated!

Thanks in advance and best wishes,
ciao, lele.
-- 
nickname: Lele Gaifax | Quando vivrò di quello che ho pensato ieri
real: Emanuele Gaifas | comincerò ad aver paura di chi mi copia.
[email protected]  |                 -- Fortunato Depero, 1929.

_______________________________________________
reportlab-users mailing list
[email protected]
https://pairlist2.pair.net/mailman/listinfo/reportlab-users