如何在不扩大行高的情况下在段落的第一行生成一个首字母?

Fel*_*lHa 5 pdf xslt xsl-fo apache-fop

我想要一个段落的第一行的首字母和所有其他段落的文本缩进.我正在使用以下代码:

<xsl:template match="paragraph">
    <xsl:choose>
        <!-- no text-indent, first letter bigger -->
        <xsl:when test="fn:position() = 1">
            <fo:block font-size="10pt" font-height="12pt">
                <fo:inline font-size="18pt"><xsl:value-of 
                  select="substring(.,1,1)"/></fo:inline>
                <xsl:value-of select="substring(.,2)"/>
            </fo:block>
        </xsl:when>
        <xsl:otherwise>
            <!-- text-indent --> 
            <fo:block line-height="12pt"  
                text-indent="10pt">
                <xsl:value-of select="."/></fo:block>
        </xsl:otherwise>
    </xsl:choose>
</xsl:template>
Run Code Online (Sandbox Code Playgroud)

这是有效的,但是第一行的行高被放大了,行之间有很大的空间. 在此输入图像描述

line-height-attributes或<fo:initial-property-set>不起作用.非常感谢.

编辑:我正在使用fop

编辑:FOP不支持<fo:float><fo:initial-property-set>.我尝试使用另一个代码<fo:list>:

        <xsl:when test="fn:position() = 1">
            <fo:block font-family="Times" font-size="10pt" line-height="12pt"> 
                <fo:list-block>
                    <fo:list-item>
                        <fo:list-item-label>
                            <fo:block font-size="18pt"><xsl:value-of select="substring(.,1,1)"/></fo:block>
                        </fo:list-item-label>
                        <fo:list-item-body>
                            <fo:block><xsl:value-of select="substring(.,2)"/></fo:block>
                        </fo:list-item-body>
                    </fo:list-item>
                </fo:list-block>
            </fo:block>
        </xsl:when>
Run Code Online (Sandbox Code Playgroud)

结果如下:

在此输入图像描述

所以我&#8199;在选择模式的值中使用了数字空间<fo:list-item-body>:

        <xsl:when test="fn:position() = 1">
            <fo:block font-family="Times" font-size="10pt" line-height="12pt"> 
                <fo:list-block>
                    <fo:list-item>
                        <fo:list-item-label>
                            <fo:block font-size="18pt"><xsl:value-of select="substring(.,1,1)"/></fo:block>
                        </fo:list-item-label>
                        <fo:list-item-body>
                            <fo:block><xsl:value-of select="('&#8199;', '&#8199;', substring(.,2))"/></fo:block>
                        </fo:list-item-body>
                    </fo:list-item>
                </fo:list-block>
            </fo:block>
        </xsl:when> 
Run Code Online (Sandbox Code Playgroud)

这不仅仅是邋,,它也不是很好用:

在此输入图像描述

在此输入图像描述

有没有人有办法解决吗?

lfu*_*ini 3

此 xsl 片段对问题中的第一个片段进行了最小程度的修改,使用 Apache FOP 生成所需的结果:

<xsl:template match="paragraph">
    <xsl:choose>
        <!-- no text-indent, first letter bigger -->
        <xsl:when test="not(preceding-sibling::paragraph)">
            <fo:block line-height="12pt" 
                line-stacking-strategy="font-height">
                <fo:inline font-size="18pt"><xsl:value-of 
                  select="substring(.,1,1)"/></fo:inline>
                <xsl:value-of select="substring(.,2)"/>
            </fo:block>
        </xsl:when>
        <xsl:otherwise>
            <!-- text-indent --> 
            <fo:block line-height="12pt"  
                text-indent="10pt">
                <xsl:value-of select="."/></fo:block>
        </xsl:otherwise>
    </xsl:choose>
</xsl:template>
Run Code Online (Sandbox Code Playgroud)

要点:

  • 所有 fo:block 都被赋予相同的行高
  • 第一个具有line-stacking-strategy="font-height",因此格式化程序使用nominal-requested-line-rectangle构建行,无论内联子项的尺寸如何
  • 如果输入文件缩进,测试条件position() = 1(如问题中所做的那样)有点冒险(因为子#1可能是仅由空格组成的文本节点,并且“第一个”段落元素将是子元素) #2),所以我检查not (preceding-sibling::paragraph)
  • 第一段的首字母溢出结果行区域;如果需要的话,可以在 fo:block 上设置一些空格来避免这种情况