[reportlab-users] Long word in paragraph in table cell

Simon Metson s.metson at bristol.ac.uk
Fri Aug 31 10:56:56 EDT 2007


Hi Andy,


> We don't do hyphenation at the moment so it's your problem to break

> up the text prior to formatting.


Yes, thanks Tim Roberts told me the same.


> Assuming it only happens in some very specific situations and you

> know which columns are prone to it, and you know the table cell

> width, font name and size, you can use the

> reportlab.pdfbase.pdfmetrics.stringWidth(..) function to size your

> text.


Yeah, unfortuneatly I found that method at 4am after I finished off
my implementation. Always the way... ;)


> I suggest writing a function which splits up these mega-words into

> a list of shorter ones. (Or, use Courier and count characters not

> points...). You can then either put a list of strings in each

> cell, or combine them with newlines into preformatted objects.


As I said in a previous mail I ended up doing just that by over-
riding the breaklines method of Paragraph. It might not be pretty but
it works for what I'm doing. (I did think about doing it prior to
making the Paragraph, but it kind of makes sense to do it at render
time, at least at the moment...)


> If you feel very brave you could contribute a hyphenation feature

> for our Paragraph classes, but there is a lot of optimised and rather

> scary code to work through there...


If I clean this up maybe I will in the future. Henning von Bargen has
also contacted me with a pointer to http://deco-cow.sourceforge.net/,
which seems to do likewise.
Thanks a lot everyone for your help!
Cheers
Simon


More information about the reportlab-users mailing list