如何处理很长 fo:list-item-labels 的缩进?

How to handle indents of very long fo:list-item-labels?

我有以下 fo 标记:

<fo:list-block>
    <fo:list-item>
        <fo:list-item-label end-indent="label-end()">
            <fo:block>[KEY]</fo:block>
        </fo:list-item-label>
        <fo:list-item-body start-indent="body-start()">
            <fo:block>Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah 
            Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah </fo:block>
        </fo:list-item-body>
    </fo:list-item>
</fo:list-block>

虽然这在印刷上看起来不错,但如果我将其更改为:

<fo:list-block>
    <fo:list-item>
        <fo:list-item-label end-indent="label-end()">
            <fo:block>[VERYLONGKEY]</fo:block>
        </fo:list-item-label>
        <fo:list-item-body start-indent="body-start()">
            <fo:block>Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah 
            Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah </fo:block>
        </fo:list-item-body>
    </fo:list-item>
</fo:list-block>

fo:list-item-label 和下面的 fo:list-item-body 重叠。如何设置 start-indentend-indent 以使用标签的实际宽度?目前看来 label-end()body-start() 是一个常数,但我想要一个动态标签宽度。这在 xsl-fo 中可能吗?

在 XSL 1.1 中严格来说是不可能的。

如果 FOP 支持自动 table 布局,您可以通过为标签和正文使用两列 table 来捏造它。

您也可以通过对列表项正文的内容使用 fo:inline-container 来针对每个列表项捏造它,但目前据说 FOP 中的 fo:inline-container 支持是有限的(参见 http://xmlgraphics.apache.org/fop/compliance.html)。

但是,您可以使用来自打印和页面布局社区组的 XSLT 扩展来获取 FOP 区域树,以便您可以根据格式化的大小做出决定。在 https://www.w3.org/community/ppl/wiki/XSLTExtensions#Example_4_-_List_item_label_width and https://www.w3.org/community/ppl/2015/02/18/getting-an-area-tree-within-your-xslt-transform/.

处有使用扩展设置列表缩进的示例

您需要知道最长标签的长度才能做到这一点。如果你这样做,你设置 provisional-distance-between-starts 来适应它。这与您设置缩进的任何文字处理器没有什么不同。给定所需的最长缩进的已知长度,并将其全部放在一行中,将该属性设置为为标签保留 space。例如,如果您的标签约为 100pt,则:

       <fo:list-block provisional-distance-between-starts="100pt" provisional-label-separation="3pt">
            <fo:list-item>
                <fo:list-item-label end-indent="label-end()">
                    <fo:block>A.</fo:block>
                </fo:list-item-label>
                <fo:list-item-body start-indent="body-start()">
                    <fo:block>Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah 
                        Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah </fo:block>
                </fo:list-item-body>
            </fo:list-item>
            <fo:list-item>
                <fo:list-item-label end-indent="label-end()">
                    <fo:block>[VERYLONGKEY]</fo:block>
                </fo:list-item-label>
                <fo:list-item-body start-indent="body-start()">
                    <fo:block>Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah 
                        Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah </fo:block>
                </fo:list-item-body>
            </fo:list-item>
        </fo:list-block>

产生以下结果:

请注意,这是必需的,因为您的字符串 [VERYLONGKEY] 没有断点。如果您设置 provisional-distance-between-starts 并且您的标签类似于 "I am a label that is very long and I should wrap" 它会换行。

像这样:

         <fo:list-block provisional-distance-between-starts="100pt" provisional-label-separation="3pt">
            <fo:list-item>
                <fo:list-item-label end-indent="label-end()">
                    <fo:block>A.</fo:block>
                </fo:list-item-label>
                <fo:list-item-body start-indent="body-start()">
                    <fo:block>Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah 
                        Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah </fo:block>
                </fo:list-item-body>
            </fo:list-item>
            <fo:list-item>
                <fo:list-item-label end-indent="label-end()">
                    <fo:block>[VERYLONGKEY]</fo:block>
                </fo:list-item-label>
                <fo:list-item-body start-indent="body-start()">
                    <fo:block>Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah 
                        Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah </fo:block>
                </fo:list-item-body>
            </fo:list-item>
            <fo:list-item>
                <fo:list-item-label end-indent="label-end()">
                    <fo:block>I am a label that is very long and I should wrap</fo:block>
                </fo:list-item-label>
                <fo:list-item-body start-indent="body-start()">
                    <fo:block>Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah 
                        Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah </fo:block>
                </fo:list-item-body>
            </fo:list-item>
        </fo:list-block>