Manuel Mall wrote:
In preparation for the upcoming 0.90 release I was reviewing the
examples in examples/fo/basic. When looking at the output of hyphen.fo I
noticed that in both the English hyphenation example and the German
hyphenation example 4 consecutive lines ending with hyphens were
generated.
It was my understanding that the Knuth algorithm was designed to exactly
prevent this situation by adding a penalty to a hyphen break and by
adding additional demerits for consecutive line ending with hyphens.
Have I misunderstood the algorithm (the most likely scenario), or is the
example a particular 'unfortunate' case, or is our implementation
incomplete or incorrect?
In BreakingAlgorithm::computeDemerits() we add "repeatedFlaggedDemerit" to
the demerits due to the adjustment ratio if the previous node is a flagged
penalty too. Maybe this value is too little, but I don't have the book at
hand to check: at the moment it is 50. Anyway, it seems it's just an
unfortunate case, the algorithm should be ok.
However, this situation could be improved implementing the property
hyphenation-ladder-count, which should not prove too difficult. Once the
BreakingAlgorithm knows the value (yet another parameter?), we could just
add a check in the same place (BreakingAlgorithm::computeDemerits()): if
the previous N nodes are all flagged penalties, we add INFINITE_DEMERITS
instead of repeatedFlaggedDemerit, such preventing this break to be chosen
(unless there is no other alternative break).
On a related matter: Knuth says in his paper that hyphenations in
unjustified text are even less desirable than in justified text and
suggests 10 times higher penalty (500 instead of 50) for hyphenations
breaks in unjustified text. I don't think we do that.
You are right, at the moment we use everywhere the same FLAGGED_PENALTY
value; note that this constant is used even in
TextLM::addALetterSpaceTo(), which at the moment is not passed the text
alignment.
Sorry for not having much time just now that the release is approaching,
but I'm having a very busy November! I hope I'll be able to spend more
time working on fop in December.
Regards
Luca
- Re: Hyphenation Luca Furini
-