Re: Hyphenation
Robin Becker <[email protected]>
| Newsgroups | gmane.comp.python.reportlab.user |
|---|---|
| Message-ID | <CAOBYczqPSRUaoTcqL0cYVR0dezUYp_Y1NBf2ma3JHfmODUziWQ@mail.gmail.com> |
The hyphenator is not being propagated to any split sub pararagraphs. I think that we don't want to go down the route of supporting large numbers of optional attributes on the paragraph instances that is what the style is for. I tried this and it seems to work. On 24 June 2018 at 16:18, Lele Gaifax <[email protected]> wrote: > 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. > > _______________________________________________ > reportlab-users mailing list > [email protected] > https://pairlist2.pair.net/mailman/listinfo/reportlab-users > > -- Robin Becker
test-hyphen.py
(text/x-python, 2.2 KB)
# -*- coding: iso8859-1 -*-
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("test-hyphen.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.
"""
styNormal = styles['Normal'].clone('NormalIT',hyphenationLang='it_IT')
hyphenator = Pyphen(lang='it_IT')
p1 = Paragraph(text, styNormal)
styNormal = styles['Normal'].clone('NormalIT',hyphenationLang=hyphenator.iterate)
p2 = Paragraph(text2, styNormal)
doc.build([ImageAndFlowables(Image('pythonpowered.gif', 20, 20), [p1], imageSide='left')]
+ [p1]
+ [p2])
print("Created test-hyphen.pdf")