Re: FOP hyphenate-ladder-count and pre-hyphenated text
Correction (again… :-)) > On 08 May 2015, at 17:31, Andreas Delmelle > wrote: > > > If you haven’t already found it, be sure to have a look at class > org.apache.fop.SerializeHyphPattern, … Should be: org.apache.fop.hyphenation.SerializeHyphPattern - To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
Re: FOP hyphenate-ladder-count and pre-hyphenated text
> On 08 May 2015, at 08:59, Marc Wiest wrote: > >> Seems like some refactoring may be in order here, to streamline and better >> merge the two approaches. >> @Marc: Will you log a request for enhancement in JIRA for this, or shall I? > > @Andreas: thank you very much for that thorough feedback and insight into how > it all works. It's the way I suspected it to be :( I would appreciate you > making the request, because you, for sure, can articulate the problem more > accurately and precisely than I ever could. OK, will do. > > I'll see if I find the time to pull the source code and see if I can fix > problem 1. myself (being able to add hyphenation exception to the actual FOP > hyphenation system at runtime) and send a pull request - if I manage to find > a solution that seems to be general enough to serve other people, too. > My idea would be to > 1. Create or find a public Java-method for building .hyp files from (updated) > .xml hyphenation patterns - containing the exceptions, so this could be done > on-the-fly. As I understand, this is now part of the build process of FOP. If you haven’t already found it, be sure to have a look at class org.apache.fop.SerializeHyphPattern, which is used for that purpose during the build process. The class is part of the regular source tree, so should be easy to locate. Be aware though, that since this file is normally used during the build process, there are no guarantees that it is safe and fit for use in a web container context… If you experience issues in your attempts, be sure to post to fop-dev@. Hope this helps! KR Andreas - To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
RE: FOP hyphenate-ladder-count and pre-hyphenated text
> Seems like some refactoring may be in order here, to streamline and better > merge the two approaches. > @Marc: Will you log a request for enhancement in JIRA for this, or shall I? @Andreas: thank you very much for that thorough feedback and insight into how it all works. It's the way I suspected it to be :( I would appreciate you making the request, because you, for sure, can articulate the problem more accurately and precisely than I ever could. Thinking this will take a while until it's actually working in a proper release, I'll probably have to find another solution, then - at least in the meantime. But thanks for taking this serious. I'll see if I find the time to pull the source code and see if I can fix problem 1. myself (being able to add hyphenation exception to the actual FOP hyphenation system at runtime) and send a pull request - if I manage to find a solution that seems to be general enough to serve other people, too. My idea would be to 1. Create or find a public Java-method for building .hyp files from (updated) .xml hyphenation patterns - containing the exceptions, so this could be done on-the-fly. As I understand, this is now part of the build process of FOP. 2. Add a way to specify a file-system location for the hyphenation files, rather than using the classspath (which is hard to write to at runtime). 3. See how reloading of these resources could work. Marc
Re: FOP hyphenate-ladder-count and pre-hyphenated text
> Internally, what FOP tries to hyphenate are only the word fragments in > between the spaces and SHYs, but those cannot be broken up further > themselves. As strange as it sounds, a SHY is treated as a word boundary > here, similar to a zero-width space. Correction/Expansion: ZWSP is actually a bad analogy, and quite differently treated by the Unicode algorithm, since the character *is* the break opportunity (=break *on* or *before*). With SHY, the break opportunity lies *after* the character. Still, internally for FOP, the result is roughly the same. The accumulated sequence of characters since the previous break opportunity is taken to be a 'word', which may or may not end in a hyphen. If the latter is true, a specific sequence of elements is glued to the word-box, to prevent a break before SHY and make sure that it is properly rendered, i.e. only counts if the break occurs right after. As hyphenation by FOP itself is applied at a higher level, when all layout elements for a whole paragraph have been collected, that SHY sequence is seen as a word boundary. That is, that part of the algorithm just accumulates the text for ‘uninterrupted' sequences of word-boxes, and feeds those pieces to the hyphenator. The real intention is to apply hyphenation across any nested fo:inlines. ‘Uninterrupted’ means that auxiliary elements, generated for border or padding are explicitly *not* considered as word boundaries. The sequence generated for SHY contains two non-auxiliary elements, as if it were a space. Perhaps, just to ensure that that position in the layout always leads to a character that is visibly rendered. In case of pre-hyphenated text, this has the unintended effect of restricting the input for the hyphenator to parts of words, which is basically meaningless (and wasteful). BTW, there is an entry related to rendering of SHY logged in JIRA already, but more specifically about copy-paste functionality: https://issues.apache.org/jira/browse/FOP-2358 Seems like some refactoring may be in order here, to streamline and better merge the two approaches. @Marc: Will you log a request for enhancement in JIRA for this, or shall I? KR Andreas - To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
Re: FOP hyphenate-ladder-count and pre-hyphenated text
Hi Marc > On 06 May 2015, at 13:40, Marc Wiest wrote: > > I have the requirements of > 1. allow adding hyphenation exceptions at runtime (web container) > 2. don't hyphenate more than two successive lines in a paragraph > > For 1. the only solution I found is to use a third-party library to add the > actual soft-hyphens in the text, instead. > This has other benefits for me, including that I can use hyphenation in other > places than PDF generation, so I prefer this separation. > But if anyone knows a way to add exceptions for words at runtime, I would be > highly interested how to do that. > > Since I solved 1. Using a new library for adding soft-hyphens into the text, > 2. doesn't work anymore. My XSL contains hyphenation-ladder-count="2" > attributes on all relevant blocks, which does the trick when passing text > without soft-hyphens and relying on FOP hyphenation entirely. But it does > nothing if I don't use FOP to hyphenate the words. In general, hyphenation > works, though, like the soft-hyphens in the text are taken into account. But > it happens that 6 or more successive lines are hyphenated, which is deemed > bad style. The effect you see in FOP is just very basic Unicode line breaking at work. An explicit SHY is obviously a legal breaking point, but is not recognised as a true hyphenation point by FOP. Internally, what FOP tries to hyphenate are only the word fragments in between the spaces and SHYs, but those cannot be broken up further themselves. As strange as it sounds, a SHY is treated as a word boundary here, similar to a zero-width space. The SHY is recognised as a special character, however, that only needs to be taken into account and rendered in case the effective line-break occurs at that point, but that is as far as it goes, currently. Not sure how difficult it would be to make FOP recognise that the text in a paragraph has already been hyphenated and then register the SHY as a precomputed hyphenation point. If that can be done, then hyphenation-ladder-count would 'automagically' come into play here. At any rate, something like the above would be a prerequisite for adding hyphenation exceptions. As long as FOP does not see a SHY as a hyphenation point, it is almost useless to add exceptions on this end. KR Andreas - To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
FOP hyphenate-ladder-count and pre-hyphenated text
I have the requirements of 1. allow adding hyphenation exceptions at runtime (web container) 2. don't hyphenate more than two successive lines in a paragraph For 1. the only solution I found is to use a third-party library to add the actual soft-hyphens in the text, instead. This has other benefits for me, including that I can use hyphenation in other places than PDF generation, so I prefer this separation. But if anyone knows a way to add exceptions for words at runtime, I would be highly interested how to do that. Since I solved 1. Using a new library for adding soft-hyphens into the text, 2. doesn't work anymore. My XSL contains hyphenation-ladder-count="2" attributes on all relevant blocks, which does the trick when passing text without soft-hyphens and relying on FOP hyphenation entirely. But it does nothing if I don't use FOP to hyphenate the words. In general, hyphenation works, though, like the soft-hyphens in the text are taken into account. But it happens that 6 or more successive lines are hyphenated, which is deemed bad style. Any input would be appreciated. Marc - To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
