【发布时间】:2020-01-21 16:26:36
【问题描述】:
是否有可能禁用 fo:block 中文本 sn-p 的连字符? 我的问题是无法设置 hyphenate="false" 在 fo:inline 上,因为它不是一个属性。并且 fo:block 里面的 fo:block 创建了一个新行...
Fo-示例:
<fo:block hyphenate="true">
This text should be hyphenated <fo:inline hyphenate="false">This text shouldn’t be hyphenated</fo:inline>
</fo:block>
更新:
我尝试了@DanielNorberg 发布的解决方案,因为所有解决方案都无法正常工作。这似乎是一种解决方法,但仍然没有提供我想要的输出。
我使用这个模板:
<xsl:template match="text()[ancestor::span[@class='nobreak']]">
<xsl:param name="text"><xsl:value-of select="." /></xsl:param>
<fo:inline hyphenate="false" color="red">
<xsl:for-each select="tokenize(replace(replace($text,'(.)','$1\\n'),'\\n$',''),'\\n')">
<fo:inline keep-with-next.within-line="always">
<xsl:value-of select="."/>
<fo:character font-size="0pt">
<xsl:value-of select="' '" />
</fo:character>
</fo:inline>
</xsl:for-each>
</fo:inline>
</xsl:template>
fo部分是这样的
<fo:block xmlns:fn="http://www.w3.org/2005/xpath-functions" space-after="14pt">
<fo:block text-align-last="left" font-size="10pt" color="black" text-align="justify"
font-family="ITCFranklinGothicStd-Book" line-height="14pt" wrap-option="wrap">
<fo:block hyphenate="true" xml:lang="de">
<fo:block>Die Entwicklung der folgenden Jahre bestätigte unsere Auffassung. Nicht nur erwiesen
sich die <fo:inline hyphenate="false" color="red">
<fo:inline keep-with-next.within-line="always">T<fo:character font-size="0pt"> </fo:character></fo:inline>
<fo:inline keep-with-next.within-line="always">r<fo:character font-size="0pt"> </fo:character></fo:inline>
<fo:inline keep-with-next.within-line="always">e<fo:character font-size="0pt"> </fo:character></fo:inline>
<fo:inline keep-with-next.within-line="always">i<fo:character font-size="0pt"> </fo:character></fo:inline>
<fo:inline keep-with-next.within-line="always">b<fo:character font-size="0pt"> </fo:character></fo:inline>
<fo:inline keep-with-next.within-line="always">e<fo:character font-size="0pt"> </fo:character></fo:inline>
<fo:inline keep-with-next.within-line="always">r<fo:character font-size="0pt"> </fo:character></fo:inline>
</fo:inline>
</fo:block>
</fo:block>
</fo:block>
</fo:block>
所以“Treiber”这个词不应该用连字符连接。但 PDF 输出如下所示:
解决方案更新: 对我有用的最终解决方法类似于上面的模板,但在每个字符之间添加了一个不间断空格 ()。
<xsl:template match="text()[ancestor::span[@class='nobreak']]">
<xsl:param name="text"><xsl:value-of select="replace(., ' ', ' ')" /></xsl:param>
<fo:inline>
<xsl:for-each select="tokenize(replace(replace($text,'(.)','$1\\n'),'\\n$',''),'\\n')">
<fo:inline>
<xsl:value-of select="."/>
<!-- non-breaking invisible space after each character-->
<fo:inline>⁠</fo:inline>
</fo:inline>
</xsl:for-each>
</fo:inline>
</xsl:template>
非常感谢@DanielNorberg
【问题讨论】:
标签: xsl-fo apache-fop hyphenation