4

I have a list of data with a dotted leader separating text aligned to the left and to the right. I'm using the following XSL-FO to achieve this.

<fo:block text-align-last="justify">
    <xsl:value-of select="left-text"/>
    <fo:leader leader-pattern="dots"/>
    <xsl:value-of select="right-text"/>
</fo:block>
Some text on the left............................some text on the right

This works perfectly when the text all fits onto one line. The issue I'm having is correctly handling how the text on the right wraps onto a new line. I have a specific requirement for it to be formatted with the wrapped text staying aligned to the right as below:

Some text on the left.................a long piece of text on the right 
                                                       that has wrapped

I tried to achieve this with leaders and tables but to no avail. I'm using the Antenna House formatter. Any advice is very welcome. Thanks for you help.

4

2 回答 2

9

以此为灵感并制定自己的规则:

       <fo:block text-align="justify" text-align-last="right">
           <fo:inline>Some text on the left</fo:inline>
           <fo:leader leader-pattern="dots" leader-length.minimum="2in" leader-length.optimum="2in" leader-length.maximum="3in"/>
           <fo:inline>a long piece of text on the right that has wrapped</fo:inline>
       </fo:block>
        <fo:block text-align="justify" text-align-last="right">
           <fo:inline>Some text</fo:inline>
           <fo:leader leader-pattern="dots" leader-length.minimum="2in" leader-length.optimum="2in" leader-length.maximum="3in"/>
           <fo:inline>a long piece of text on the right that has wrapped and is even longer</fo:inline>
       </fo:block>

唯一不能停止的是右手线太长以至于它位于点下方,但您没有将其指定为要求。如果是这样,恐怕没有解决办法。此外,如果一条线太短,它会右对齐。您必须使用最小/最大值来强制换行。

如果您知道字体大小,您可以计算左/右元素中的字符,然后根据总字符调用您的模板或此示例。

此 FO 的结果

对于计数,您可以执行类似此模板的操作,您可以使用前导长度调整“50”个字符以获得正确的结果。

<xsl:template name="processitem">
    <xsl:choose>
        <xsl:when test="string-length(left) + string-length(right) > 50">
            <fo:block text-align="justify" text-align-last="right">
                <fo:inline><xsl:value-of select="left"/></fo:inline>
                <fo:leader leader-pattern="dots" leader-length.minimum="2in" leader-length.optimum="2in" leader-length.maximum="4in"/>
                <fo:inline><xsl:value-of select="right"/></fo:inline>
            </fo:block>
        </xsl:when>
        <xsl:otherwise>
            <fo:block text-align-last="justify">
                <fo:inline><xsl:value-of select="left"/></fo:inline>
                <fo:leader leader-pattern="dots"/>
                <fo:inline><xsl:value-of select="right"/></fo:inline>
            </fo:block>
        </xsl:otherwise>
    </xsl:choose>
</xsl:template>

使用一些示例数据,我得到了这个来呈现:

使用上面的模板和样本数据

于 2014-07-23T22:37:15.683 回答
1

您可以使用fo:inline-container( https://www.w3.org/TR/xsl11/#fo_inline-container ) 和max-width属性 ( https://www.w3.org/TR/xsl11/#max-width ) 来限制右侧任何长文本的宽度。

此示例使用axf:text-align-first="justify"扩展名(请参阅https://www.antennahouse.com/product/ahf66/ahf-ext.html#axf.text-align-first)来证明第一行的合理性。您可以改为使用axf:leader-expansion="force"扩展名(请参阅https://www.antennahouse.com/product/ahf66/ahf-ext.html#axf.leader-expansion)。如果没有其中任何一个,我认为您唯一的其他选择是猜测leader-length.optimum第二个fo:leader

请注意,下面的示例在两者之间没有重要的空白字符fo:leader。这避免了格式化时两个引线之间的间隙。

<fo:block text-align="justify">
  <fo:inline>Some text</fo:inline><fo:leader
  leader-pattern="dots" leader-length.optimum="100%"
  leader-alignment="end"
  /><fo:inline-container
  max-width="1.5in" text-align="right"
  axf:text-align-first="justify" >
          <fo:block><fo:leader leader-pattern="dots"
  leader-length.minimum="0" />a long piece of text on the right that has wrapped
and is even longer</fo:block>
  </fo:inline-container>
</fo:block>

引线后多行右对齐文本的示例。

于 2018-10-12T11:37:46.627 回答