3

I have created a small Java Swing application to generate PDFs of XML files here at my workplace. I need to enable hyphenation, as I have some text in tables that flows outside the cell borders.

I have downloaded the OFFO Compiled Hyphenation Patterns for FOP and placed the fop-hyph.jar file alongside my fop.jar in my "lib" folder.

When I run the application I get the following error:

Jan 20, 2016 2:57:43 PM org.apache.fop.hyphenation.Hyphenator getHyphenationTree
SEVERE: Couldn't find hyphenation pattern for lang="en",country="US".

I am using FOP 2.0 and have the following entry in my fop.xconf file:

<hyphenation-pattern lang="en">en_US</hyphenation-pattern>

I have also tried this with no difference:

<hyphenation-pattern lang="en" country="US">en_US</hyphenation-pattern>

On the root of the XSL-FO file I have entered:

<fo:root font-family="Helvetica" language="en" country="US" hyphenate="true">

What am I missing to get this working? Everything else works fine, creates PDFs correctly.

twfurst
  • 165
  • 2
  • 13

1 Answers1

3

According to the hyphenation pattern installation instruction, the pattern file for American English is called just en.xml, so in the configuration file you should have:

<hyphenation-pattern lang="en">en</hyphenation-pattern>

By the way, the entries in the configuration file are only needed when you want something different from the default behaviour, so in this case you could omit it completely.

lfurini
  • 3,729
  • 4
  • 30
  • 48
  • Ok, so removing the "_US" removed the error message. I read this in the install instructs, and still somehow misinterpreted it. I still do not get hyphenation within my table. Are `` elements prevented from hyphenating? I get an error stating that they overflow the allowable area. – twfurst Jan 23 '16 at 12:15
  • 1
    If some text is not hyphenated despite the presence of `hyphenate="true"` on the `fo:root`, the reason could be: _(a)_ `hyphenate="false"` on an `fo:block` ancestor of the text; _(b)_ `keep-together="always"` (which involves `keep-together.within-line="always"`) on an ancestor of the text; _(c)_ the text is not text :-) (hyphenation rules do not apply to sequences of digits). – lfurini Jan 23 '16 at 12:46
  • 1
    The digits may be the issue, the string looks something like 23-00-00-01A-251A-A. Is there a way to work around the digits issue? – twfurst Jan 23 '16 at 12:53
  • You could insert some _zero width spaces_ (`​`) into the string while you are producing the FO file; FOP will be able to use these invisible spaces as a breaking point. There are Q&As about this: I could only find [this one](http://stackoverflow.com/q/17317588/4453460) but I'm quite sure there are others too. – lfurini Jan 23 '16 at 13:08
  • I will give these spaces a shot. Thanks for the help. – twfurst Jan 23 '16 at 13:27
  • 1
    Put them in before and after each '-' and it worked. Thanks again. – twfurst Jan 23 '16 at 13:36
  • does a string of all capital letters have any impact on hyphenation? I have a sentence that is all caps that I would expect to hyphenate but is not. – twfurst Jan 26 '16 at 13:34
  • Capitalization should not have any impact on hyphenation; I think the text is normalized to lowercase when finding hyphenation points (otherwise hyphenation patterns would need to be duplicated to account for every possible combination of lower- and uppercase ...). – lfurini Jan 26 '16 at 14:09