Before/after spacing in _splitCell, break on split

44 views
Skip to first unread message

James Fitzsimmons

unread,
Apr 1, 2025, 1:18:45 AMApr 1
to reportlab-users
Hi all,

I've hit a couple of issues with `splitInRow=1` where the contents of a table cell overflow the table/page. As far as I can tell, the bugs are:
  1. `beforeSpace` and `afterSpace` from the flowable's style are not factored into the height calculations
  2. When a flowable is split, the height of the non-postponed part is not added to `usedHeight`
Initially tested on 4.3.1 but confirmed the issues still exist on 4.3.1.2. (The latter might only be an issue on 4.3.1.2; once I found the first issue I switched to the latest version of the code.)

Patch

diff --git a/src/reportlab/platypus/tables.py b/src/reportlab/platypus/tables.py
--- a/src/reportlab/platypus/tables.py
+++ b/src/reportlab/platypus/tables.py
@@ -1462,15 +1462,17 @@
for i,flowable in enumerate(value):
flowable_height = getattr(flowable,'height',FH[i])
- if usedHeight + flowable_height <= height0:
+ if usedHeight + flowable_height + flowable.getSpaceBefore() <= height0:
newCellContent.append(flowable)
- usedHeight += flowable_height
+ usedHeight += flowable_height + flowable.getSpaceBefore() + flowable.getSpaceAfter()
else:
# This is where we need to split
- splits = flowable.split(width, height0-usedHeight)
+ splits = flowable.split(width, height0-usedHeight-flowable.getSpaceBefore())
if splits:
newCellContent.append(splits[0])
postponedContent.append(splits[1])
+ postponedContent.extend(list(value[i+1:]))
+ break
elif newCellContent and ((style.valign=='BOTTOM' and flowable_height<=height1)
or flowable.split(width,self._getPossibleHeight(height1))):
postponedContent.extend(list(value[i:]))

Examples

Here's what it looks like before any of the patch changes above:

 Screenshot 2025-04-01 at 4.01.55 pm.png

And after adding calls to `getSpaceBefore`/`getSpaceAfter` in the height checks, the first paragraph is correctly split. However the height of `splits[0]` is not added to `usedHeight` so the next paragraph is also split, with both paragraphs' second-halves ending up on the next page:

Screenshot 2025-04-01 at 4.07.37 pm.png

Given we know we need to split at this particular flowable, the easiest fix seemed to be to append the remaining flowables into `postponedContent`, then break. With that part of the patch also applied, content breaks as expected:

Screenshot 2025-04-01 at 4.09.55 pm.png

Questions

I don't really follow the `elif newCellContent and [...]` check. Do similar changes need to made there?

Regards,
James
Reply all
Reply to author
Forward
0 new messages