Reputation: 21
I want a block of text to wrap to the next line when it overflows. The text has no spaces or dashes. Apache FOP will not wrap this text nor clip it, even though the block contains the overflow="hidden" and wrap-option="wrap" attributes. The FO file does not contain any keep-together settings, so that can't cause this issue.
Version: problem occurs with Apache FOP 0.95, 1.0 and 1.1. Unfortunately, older versions don't work in my DocBook Maven setup, so I haven't tested these.
This is the block in my FO file:
<fo:block
overflow="hidden"
wrap-option="wrap"
white-space-collapse="false"
white-space-treatment="preserve"
linefeed-treatment="preserve"
text-align="start"
margin-top="0.5em"
margin-right="0.5pt"
margin-bottom="1em"
margin-left="0.5pt"
border-width="0.5pt"
border-left-style="solid"
border-left-color="#D3CEC6"
padding="2mm"
font-family="Courier New"
font-size="8pt"
background-color="#EBE5D7">veryverylongtextwithoutspacesordashes
</fo:block>
Upvotes: 2
Views: 3548
Reputation: 230
This might be old, but I came across this and wrote a FOP function to solve my issue.
<#function breakValue value limit>
<#if value?length lte limit>
<#return value>
<#else>
<#return value?substring(0, limit) + "​" + breakValue(value?substring(limit))>
</#if>
</#function>
where value
is the string you want to break and limit
is the index where you want to add ​
and then call the same function on the remaining of the string.
Upvotes: 0
Reputation: 7735
In order to get string wrapped, you must have breakable characters within the line.
Consider pre-processing your input by inserting zero-width space character (​
or ​
) at certain places. The formatter will see it and it will break lines at these characters only where necessary. Other occurrences of this character will not be seen.
<fo:block>very​very​long​text​without​spaces​or​dashes</fo:block>
If the text is a string of digits, it may be logical to insert zero-width space character at every nth symbol.
Alternatively, you may setup your formatter to hyphenate the string according to particular language's hyphenation rules. In fact, hyphenation is essentially based on adding hyphenation markers into the original text. Again, it would require the string to contain meaningful text belonging to a certain language.
Upvotes: 3