Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

XSL-FO fop. Long text flows into adjacent cells/block, obscuring stuff there

Could anyone suggest me a way to make long words (like serial numbers) to be wrapped? I tried some commercial software and there is no such issue. Is it a fop bug or probably there is a solution available?

I can't insert zero length space after each character of every word in document. This solution sounds insane for me.

like image 508
Alex Avatar asked Nov 23 '10 04:11

Alex


5 Answers

Zkoh's answer (wraping) will help you only if the text contains multiple words split by white spaces. In case of long words (as mensioned in question), hyphenation is way to go (as Daniel suggested).

There can be quite a few problems with hyphenation in FOP:

  1. FOP is using hyphenation algorithms from TeX and because of some licencing issues, those algorithms (at least for some languages) are not part of standard FOP binary distribution (as stated here) and must be downloaded separately from OFFO web site. There are two kinds of hyphenation pattern files on the website. XML format (which needs to be compiled 1st to be used with FOP) and JAR file (already compiled). Be sure to download compiled version! Installation is straightforward and well documented - just drop the OFFO binary into FOP's lib folder and thats it...
  2. Don't forget to specify language of your document and if needed, enable hyphenation on block level (its inherited so add it to the root element and you should be fine) - see FOP FAQ
like image 59
Michal Levý Avatar answered Nov 10 '22 01:11

Michal Levý


You can specify the wrap-option attribute in your fo:block like so:

<fo:block wrap-option="wrap"> ... stuff </fo:block>

Here's the XSL-FO specification for this attribute:

XSL Definition:

Value: no-wrap | wrap | inherit

Initial: wrap

Applies to: fo:block, fo:inline, fo:page-number, fo:page-number-citation

Inherited: yes

Percentages: N/A

Media: visual

Values have the following meanings:

no-wrap

No line-wrapping will be performed.

In the case when lines are longer than the available width of the content-rectangle, the overflow will be treated in accordance with the "overflow" property specified on the reference-area.

wrap

Line-breaking will occur if the line overflows the available block width. No special markers or other treatment will occur.

Specifies how line-wrapping (line-breaking) of the content of the formatting object is to be handled.

Implementations must support the "no-wrap" value, as defined in this Recommendation, when the value of "linefeed-treatment" is "preserve".

You can also define the wrap-option attribute in an fo:table-cell

<fo:table-cell wrap-option="wrap"> ... </fo:table-cell>

and the fo:blocks within will inherit the property.

like image 34
Zkoh Avatar answered Nov 10 '22 01:11

Zkoh


Would hyphenation solve your problem? You should be able to enable hyphenation with a hyphenate="true" attribute. Placement of this attribute will depend on where you want to enable hyphenation.

Here's a link to FOP's hyphenation compliance: Apache FOP Compliance Page

Here's a link to the XSL spec: XSL Spec #hyphenate

If not, you may need to experiment with some keeps properties (like keep-together.within-line).

like image 32
Daniel Haley Avatar answered Nov 09 '22 23:11

Daniel Haley


Use keep-together.within-column="always" instead of keep-together="always" of to keep long lines with in table cell.

like image 3
Vivek Dhiman Avatar answered Nov 10 '22 01:11

Vivek Dhiman


The question is about serial numbers, not about dictionary words. Specifying hyphenate="true" is useful only when the hyphenation dictionary or hyphenation algorithm can successfully hyphenate the words in the text. Serial numbers would rarely generate sequences that can usefully be hyphenated as if they are words.

You can, of course, use XSLT to add zero-width spaces in text in table cells rather than doing it manually. StackOverflow likes duplicate questions (see https://stackoverflow.blog/2010/11/16/dr-strangedupe-or-how-i-learned-to-stop-worrying-and-love-duplication/), but, all the same, please see the answers in XSL-FO: Force Wrap on Table Entries.

like image 1
Tony Graham Avatar answered Nov 09 '22 23:11

Tony Graham