简体   繁体   English

XSL-FO领导包装

[英]XSL-FO leader wrapping

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. 我正在使用以下XSL-FO来实现这一目标。

<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 左边的一些文字.................右边的一段长文字 \n                                                       that has wrapped 已经包裹 

I tried to achieve this with leaders and tables but to no avail. 我试图用领导者和桌子实现这一目标,但无济于事。 I'm using the Antenna House formatter. 我正在使用Antenna House格式化程序。 Any advice is very welcome. 任何建议都非常欢迎。 Thanks for you help. 谢谢你的帮助。

Use this as inspiration and set your own rules: 使用它作为灵感并设置自己的规则:

       <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>

The only things you will not be able to stop is a right hand line so long that it comes underneath the dots, but you have not specified that as a requirement. 你无法阻止的唯一事情是右手线,只要它在点下面,但你没有指明这是一个要求。 If that is, I am afraid there is no solution for that. 如果是这样,我恐怕没有解决方法。 Also if a line is too short, it would be right aligned. 此外,如果一条线太短,它将是右对齐的。 You have to use the min/max values to only force a wrap. 您必须使用最小/最大值才强制换行。

If you know the font size you could count the characters in the left/right elements and then call your template or this sample depending on the total characters. 如果您知道字体大小,则可以计算左/右元素中的字符,然后根据总字符调用模板或此示例。

这个FO的结果

And for the count, you can do something like this template where the "50" characters you can adjust with the leader-length to get the correct results. 对于计数,您可以执行类似此模板的操作,您可以使用前导长度调整“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>

With some sample data, I got this to render: 通过一些示例数据,我得到了这个:

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

You can use an fo:inline-container ( https://www.w3.org/TR/xsl11/#fo_inline-container ) and the max-width property ( https://www.w3.org/TR/xsl11/#max-width ) to limit the width of any long text on the right. 您可以使用fo:inline-containerhttps://www.w3.org/TR/xsl11/#fo_inline-container )和max-width属性( https://www.w3.org/TR/xsl11/ #max-width )限制右侧任何长文本的宽度。

This example uses the axf:text-align-first="justify" extension (see https://www.antennahouse.com/product/ahf66/ahf-ext.html#axf.text-align-first ) to justify the first line. 此示例使用axf:text-align-first="justify"扩展名(请参阅https://www.antennahouse.com/product/ahf66/ahf-ext.html#axf.text-align-first )来证明第一个线。 You could instead use the axf:leader-expansion="force" extension (see https://www.antennahouse.com/product/ahf66/ahf-ext.html#axf.leader-expansion ). 您可以使用axf:leader-expansion="force"扩展名(请参阅https://www.antennahouse.com/product/ahf66/ahf-ext.html#axf.leader-expansion )。 Without either of those, I think that your only other alternative is to guesstimate the leader-length.optimum of the second fo:leader . 如果没有这类原因,我认为你唯一的另一种方法是推测将会在leader-length.optimum第二的fo:leader

Note that the example below has no significant white-space characters between the two fo:leader . 请注意,下面的示例在两个fo:leader之间没有明显的空白字符。 This avoids a gap between the two leaders when they are formatted. 这样可以避免格式化时两个领导者之间的差距。

<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>

领导者之后多行右对齐文本的示例。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM