Honza Hejzl
Honza Hejzl

Reputation: 884

How to really keep together fo:inline objects in Apache FOP 1.1

I have a list of authors:

<titleStmt>
    <author>GivenName1 Surname1</author>
    <author>GivenName2 Surname2</author>
    <author>GivenName3 Surname3</author>
    <author>GivenName4 Surname4</author>
    <author>GivenName5 Surname5</author>
    <author>GivenName6 Surname6</author>
</titleStmt>

After the initial transformation into XSL-FO I have:

<fo:block font-family="Times New Roman" text-transform="uppercase" text-align="left" font-size="8pt" line-height="11pt" margin-right="5cm">
    <fo:inline keep-together.within-line="always">GivenName1 Surname1</fo:inline>
    <fo:inline keep-together.within-line="always">GivenName2 Surname2</fo:inline>
    <fo:inline keep-together.within-line="always">GivenName3 Surname3</fo:inline>
    <fo:inline keep-together.within-line="always">GivenName4 Surname4</fo:inline>
    <fo:inline keep-together.within-line="always">GivenName5 Surname5</fo:inline>
    <fo:inline keep-together.within-line="always">GivenName6 Surname6</fo:inline>
</fo:block>

I need to wrap lines only between every record, not inside it (don’t want to split GivenName and Surname). With keep-together.within-line, I would expect it should work but it doesn’t. The only one result I have is line overflowing the page border, like I applied the rule to the whole block container. Is there something I am missing here?

Upvotes: 1

Views: 1523

Answers (2)

Honza Hejzl
Honza Hejzl

Reputation: 884

It seems a bit nasty to me but adding of non-breaking spaces works as expected:

<fo:block font-family="Times New Roman" text-transform="uppercase" text-align="left" font-size="8pt" line-height="11pt" margin-right="5cm">
    <fo:inline keep-together.within-line="always">GivenName1&#160;Surname1</fo:inline>
    <fo:inline keep-together.within-line="always">GivenName2&#160;Surname2</fo:inline>
    <fo:inline keep-together.within-line="always">GivenName3&#160;Surname3</fo:inline>
    <fo:inline keep-together.within-line="always">GivenName4&#160;Surname4</fo:inline>
    <fo:inline keep-together.within-line="always">GivenName5&#160;Surname5</fo:inline>
    <fo:inline keep-together.within-line="always">GivenName6&#160;Surname6</fo:inline>
</fo:block>

I am generating this with an XSL stylesheet, so:

<fo:inline>
    <xsl:value-of select="replace(., '\s', '&#160;')"/>
</fo:inline>

Upvotes: 1

lfurini
lfurini

Reputation: 3778

I tested your block with FOP 1.1 and the output is as expected (several lines, breaking only after the surnames).

I think you probably have a keep-together.within-line="always" or keep-together="always" (*) in an ancestor of the fo:block, thus forcing the whole block to produce a single line.

(*) The XSL 1.1 Recommendation, section 5.11 Property Datatypes, explains that:

keep-together="always" is equivalent to a specification of keep-together.within-line="always" keep-together.within-column="always" keep-together.within-page="always"

Upvotes: 1

Related Questions