[reportlab-users] Multiple hyphenation issue
Christoph Zwerschke
cito at online.de
Thu Apr 2 09:55:51 EDT 2020
Sorry for coming back to this only now.
Here is my patch to support multiple hyphenations in one word:
###
src/reportlab/platypus/paragraph.py | 9 +++++++--
1 file changed, 7 insertions(+), 2 deletions(-)
diff --git a/src/reportlab/platypus/paragraph.py
b/src/reportlab/platypus/paragraph.py
index 88b020be..2dad8a8f 100644
--- a/src/reportlab/platypus/paragraph.py
+++ b/src/reportlab/platypus/paragraph.py
@@ -1856,9 +1856,14 @@ class Paragraph(Flowable):
if currentWidth > self._width_max: self._width_max
= currentWidth
#end of line
lines.append((maxWidth - currentWidth, cLine))
- cLine = [word]
spaceShrink = 0
- currentWidth = wordWidth
+ if wordWidth <= maxWidth:
+ cLine = [word]
+ currentWidth = wordWidth
+ else: # word does not fit in new line
+ cLine = []
+ currentWidth = 0
+ words.insert(0, word)
lineno += 1
maxWidth = maxWidths[min(maxlineno,lineno)]
###
See the example below for a test. Maybe you can make a test from this in
test_platypus_paragraphs.py.
-- Christoph
Am 10.03.2020 um 15:39 schrieb Robin Becker:
> On 09/03/2020 15:32, Christoph Zwerschke wrote:
>> Good to see that ReportLab is still around and some hyphenation
>> support has been built-in.
>>
>> Unfortunately, I'm still struggling with several hyphenation issues.
>>
>> For instance, when I want to print a very long word in a very narrow
>> column, it will be only split once, which may be not sufficient.
>>
>> Here is an example:
>>
>> ###
>>
>> from reportlab.pdfgen import canvas
>> from reportlab.platypus import Frame, Paragraph
>> from reportlab.lib.styles import ParagraphStyle
>>
>> pagesize = (80, 120)
>> c = canvas.Canvas('hyphenation.pdf', pagesize=pagesize)
>> f = Frame(0, 0, *pagesize)
>> style = ParagraphStyle(
>> 'normal', fontName='Helvetica', fontSize=12,
>> embeddedHyphenation=1, splitLongWords=0)
>> text = 'Super-cali-fragi-listic-expi-ali-docious'
>> f.addFromList([Paragraph(text, style)], c)
>> c.showPage()
>> c.save()
>>
>> ###
>>
>> With ReportLab 3.5.34, you get
>>
>> Super-cali-
>> fragi-listic-exp (cut off here)
>>
>> What I expect is actually this:
>>
>> Super-cali-
>> fragi-listic-
>> expi-ali-
>> docious
>>
>> I've already found the problem in Pragraph.breakLines() and fixed it,
>> and I'd like to contribute the patch and tests. What's the best way to
>> do this? There is a GitHub mirror, can I send a pull request? Or must
>> I use mercurial (but I haven't used that for years)?
>>
>> -- Christoph
> ........
>
> just post the patch here. The github mirror is exactly that and we copy
> directly from the mercurial.
More information about the reportlab-users
mailing list