Search code examples
xsl-foapache-fop

XSL-FO/Apache FOP: How to keep a word together when hyphenation is enabled


The task is very simple: to prevent "donothyphenatethisextremelylongword" from getting hyphenated inside a block where hyphenate="true". What I tried:

<root xmlns="http://www.w3.org/1999/XSL/Format" xml:lang="en">
    <layout-master-set>
        <simple-page-master master-name="the-master-name" page-height="29.7cm"
                            page-width="21.0cm" margin-top="1.21cm"
                            margin-bottom=".8cm" margin-left="2.4cm"
                            margin-right="1.5cm">
            <region-body region-name="the-region-body"/>
        </simple-page-master>
    </layout-master-set>
    <page-sequence master-reference="the-master-name">
        <flow flow-name="the-region-body">
            <block hyphenate="true">
                Whereas recognition of the inherent dignity and of the equal and
                inalienable rights of all members of the human family is the
                foundation of freedom, justice and peace in the world, Whereas
                disregard and contempt for human rights have resulted in
                barbarous acts which have outraged the conscience of mankind,
                and the advent of a
                <inline keep-together="always" hyphenate="false" color="red">
                    donothyphenatethisextremelylongword
                </inline>
                world in which human beings shall enjoy freedom of speech and
                belief and freedom from fear and want has been proclaimed as the
                highest aspiration of the common people
            </block>
        </flow>
    </page-sequence>
</root>

Result:

Rendering result

Is there really no way to do that? Any help would be appreciated.


Solution

  • FWIW, your sample works fine in AH Formatter. So does wrapping the word in an fo:inline-container with an fo:block that has the hyphenate="false", but FOP 2.6 then puts the word on a separate line (because, I think, the width isn't specified).

    The only thing that I've found that works with FOP 2.6 is to turn every character in the fo:inline into an fo:character; i.e., <character character="d" />, etc.

    Alternatively, you can drop the fo:inline and repeat the hyphenate on every fo:character: <character hyphenate="false" character="d" />, etc.

    You can drop the keep-together="always". I haven't seen it have any effect.


    Making your own fo:character shouldn't be necessary. Section 1.1.2, Formatting, of the XSL 1.1 Recommendation includes (just after the graphic):

    As part of the step of objectifying, the characters that occur in the result tree are replaced by fo:character nodes.

    I don't know that any formatter would do that in practice because it would explode the number of objects with (usually) no good effect, but the formatter should behave as if the inherited properties that apply to fo:character apply to every character in a run of text.