Re: Multiple hyphenation issue

Christoph Zwerschke <[email protected]>
Newsgroups gmane.comp.python.reportlab.user
Message-ID <[email protected]>
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.
_______________________________________________
reportlab-users mailing list
[email protected]
https://pairlist2.pair.net/mailman/listinfo/reportlab-users
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.