[reportlab-users] Line-wrapping in tables

Steve Hill steve at opendium.com
Mon Apr 7 13:15:30 EDT 2014


On 07/04/14 17:55, Tim Roberts wrote:


> What would be "more sensible"? ReportLab doesn't do hyphenation. If

> there are no spaces, then there's no place to break.


Well, by "more sensible" I really just mean tweakable in some way to
make the results readable.

At the moment I'm producing a report that contains various things
without spaces, such as web URIs, etc. The upshot is that any long
lines just get rendered on top of each other (since they escape the
table cell boundaries), which makes them unreadable. They also run off
the edge of the page, again making them unreadable.

I realise that hyphenation is hard, but even just splitting the line at
a non-space character (and not bothering to do hyphenation) would be
preferable to the current situation, since at least then the results
would be readable.

I guess the rules I'd like to implement are fairly simple:

1. Split the line at a space, as is currently done.
2. If there isn't a space, split at some punctuation
3. As a last ditch effort, if there's no suitable space or punctuation,
just split the line wherever it starts to overflow from the containing box.


> Genuine hyphenation is hard. Really hard. There is a dump hyphenator

> in ReportLab (lib/textsplit.py), but it doesn't use English rules. It

> just inserts the hyphen at the last place it fits.

>

> If you just want to have the long text wrap at the last character that

> fits, you can do that yourself. It's not hard.


How do I integrate a custom splitting function (or the dumb function you
mentioned) into the Paragraph class? From looking at the code, it
appears to use the split() function defined in paragraph.py; however,
this function is not within the Paragraph class, so this doesn't appear
to be a simple job of defining a new class that inherits from Paragraph
and contains a replacement for the split() function.

Is there some option I've missed to tell it to use a different split
function?

--

- Steve Hill
Technical Director
Opendium Limited http://www.opendium.com

Direct contacts:
Instant messager: xmpp:steve at opendium.com
Email: steve at opendium.com
Phone: sip:steve at opendium.com

Sales / enquiries contacts:
Email: sales at opendium.com
Phone: +44-844-9791439 / sip:sales at opendium.com

Support contacts:
Email: support at opendium.com
Phone: +44-844-4844916 / sip:support at opendium.com


More information about the reportlab-users mailing list