[reportlab-users] Hyphenation

Robin Becker robin at reportlab.com
Thu Jun 21 05:52:14 EDT 2018




On 21/06/2018 09:51, Lele Gaifax wrote:
> Lele Gaifax <lele at metapensiero.it> writes:
> 
>> However, I must be missing something in the "width" argument, because for
>> example when using a ImageAndFlowables it clearly uses the wrong width in the
>> "second" part (where the image ends so there's a wider space available)...
> 
> I think I figured it out and spotted the problem with ImageAndFlowables: the
> widget basically first calls .wrap() on the paragraphs on image's side, that
> in turn compute their blPara attribute, then if the height of the flowables is
> taller than the image's it splits the paragraphs, and that's where it does the
> wrong thing (for my purpose, of course): the Paragraph.split() method cuts it
> in two halves, rebuilding their respective frags attribute from blPara
> honoring the height constraint, and thus possibly already hyphenated words end
> into the ParaFrag structure and are eventually rendered as-is into a possibly
> wider context.
> 
I


> Fixing the issue is complicated, because the Paragraph.split() method calls
> plain functions (_split_blParaSimple() and _split_blParaHard()) so I should
> override the whole method simply to call a "smarter" implementation that knows
> about _SplitText and _SplitList...
> 
I think the issue could be resolved if you don't explicitly add the hyphen, but instead change the fragment type so we know this 
fragment should end with a hyphen if it is at the end of a line. The line output code is then responsible for adding the hyphen 
and making space for it. Of course the simple paragraphs don't actually have a notion of fragments so that's a problem, but I did 
add the shrinkage recently to the simple paragraphs so perhaps there's a way to do it.


> At this point, given that my need for ImageAndFlowables is marginal at best, I
> won't be feeding it PyphenParagraphs, using them only in "plain" containers.
> 
> I updated my gist to what I'm currently using, previous version had a glitch
> with multifrag paragraphs.
> 
> Thanks in advance for any further insight.
> 
> ciao, lele.
> 


-- 
Robin Becker


More information about the reportlab-users mailing list