[英]XSL-FO leader wrapping
我有一个数据列表,带有一个虚线的引线,分隔左右两边的文字。 我正在使用以下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>
左边的一些文字............................右边的一些文字
当文本全部适合一行时,这非常有效。 我遇到的问题是正确处理右侧文本如何换行到新行。 我有一个特定的要求,它的格式与包装文本保持对齐,如下所示:
左边的一些文字.................右边的一段长文字 \n 已经包裹
我试图用领导者和桌子实现这一目标,但无济于事。 我正在使用Antenna House格式化程序。 任何建议都非常欢迎。 谢谢你的帮助。
使用它作为灵感并设置自己的规则:
<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>
你无法阻止的唯一事情是右手线,只要它在点下面,但你没有指明这是一个要求。 如果是这样,我恐怕没有解决方法。 此外,如果一条线太短,它将是右对齐的。 您必须使用最小/最大值才强制换行。
如果您知道字体大小,则可以计算左/右元素中的字符,然后根据总字符调用模板或此示例。
对于计数,您可以执行类似此模板的操作,您可以使用前导长度调整“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>
通过一些示例数据,我得到了这个:
您可以使用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>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.