Re: Hyphenation

Lele Gaifax <[email protected]>
Newsgroups gmane.comp.python.reportlab.user
Organization Nautilus Entertainments
Message-ID <[email protected]>
Robin Becker <[email protected]> writes:

> Thanks for these. The gffset is some kind of mistype, you are right the
> lambda seems not to be required. As for using the longest split I am not
> sure that is always best; the branch code is looking for a balanced split.
> It's nearly 50 years since I last looked at hyphanation (for a port of
> troff) so I am no doubt well out of date :)

:-)

I just tried your branch (using Py3.6, fwiw): it works well for "normal"
paragraphs, but the ImageAndFlowables still behaves oddly. I tried to execute
it under pdb but I have (again! sorry :-\) the feeling that I'm missing
something in the logic.

Anyway, I'm attaching the sample script I used, and an image showing the place
where the hyphenation does not happen, even when there's plenty of space to
split the words "semplicemente" and "avanzare".

All the best,
ciao, lele.


-- 
nickname: Lele Gaifax | Quando vivrò di quello che ho pensato ieri
real: Emanuele Gaifas | comincerò ad aver paura di chi mi copia.
[email protected]  |                 -- Fortunato Depero, 1929.
test.py (text/x-python, 2.1 KB)
from reportlab.lib.pagesizes import A4
from reportlab.platypus import ImageAndFlowables, SimpleDocTemplate, Image, Paragraph
from reportlab.lib.styles import getSampleStyleSheet
from pyphen import Pyphen

styles = getSampleStyleSheet()

doc = SimpleDocTemplate("sample1.pdf", pagesize=A4,
                        rightMargin=144, leftMargin=144,
                        topMargin=72, bottomMargin=18)

text = """\
A differenza del primo caso, dove la libreria implementa uno standard eticamente superiore, in questo l'adozione senza un forte motivo non serve a compiere alcun obiettivo particolare, motivo per il quale non c'è alcun motivo valido per evitare il copyleft. Ma, se chiedete agli utenti della vostra libreria di rilasciare i propri programmi sotto copyleft, questi passeranno semplicemente ad una delle alternative disponibili, senza avanzare la nostra causa. La Lesser GPL è stata creata proprio per fare da ponte tra questi casi, permettendo agli sviluppatori di software proprietario di usare la libreria senza però privare gli utenti delle libertà relative al codice stesso della libreria.
"""

text2 = """\
A differenza del primo caso, dove la libreria implementa uno standard eticamente superiore, in questo l'adozione senza un forte motivo non serve a compiere alcun obiettivo particolare, motivo per il quale non c'è alcun motivo valido per evitare il copyleft. Ma, se chiedete agli utenti della vostra libreria di rilasciare i propri programmi sotto copyleft, questi <b>passeranno</b> semplicemente ad una delle alternative disponibili, senza avanzare la nostra causa. La Lesser GPL è stata creata proprio per fare da ponte tra questi casi, permettendo agli sviluppatori di software proprietario di usare la libreria senza però privare gli utenti delle libertà relative al codice stesso della libreria.
"""


hyphenator = Pyphen(lang='it_IT')
p1 = Paragraph(text, styles['Normal'])
p1.hyphenator = hyphenator.iterate
p2 = Paragraph(text2, styles['Normal'])
p2.hyphenator = hyphenator.iterate

doc.build([ImageAndFlowables(Image('pythonpowered.gif', 20, 20), [p1], imageSide='left')]
          + [p1]
          + [p2])
print("Created sample1.pdf")
hyph.png (image/png, 7.8 KB) - not displayed
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.