[英]XSL-FO table-cell with superscript and vertical alignment
This is the situation: I am converting html to xsl-fo to pdf.这就是情况:我正在将 html 转换为 xsl-fo 到 pdf。 I am displaying a heading text like "4.4.1. [Header Text]" by use of a table, because it might happen that the [Header Text] is quite long and in that case shall wrap onto the next line like so:我正在使用表格显示类似“4.4.1. [Header Text]”的标题文本,因为可能会发生 [Header Text] 很长,在这种情况下应该像这样换行到下一行:
[table-row]
[cell with numbering] [cell with header text]
[/table-row]
There are 4 different cases how the header may be composed:标题的组成方式有 4 种不同的情况:
The problem is that superscript will increase the row's height and mess with the vertical text alignment.问题是上标会增加行的高度并弄乱垂直文本对齐方式。 This is how it would look by default in all 4 cases:这就是它在所有 4 种情况下的默认外观:
__________________________
|_1.2.3_|_header_text____| <<< OK
__________________________
| 1.2.3 | long long long | <<< OK
|_______|_header_text____|
__________________________
| 1.2.3 | (1) | <<< NOT OK
|_______|_header_text____|
__________________________
| 1.2.3 | long long long | <<< OK
| | (1) |
|_______|_header_text____|
As you can see, in case no.3 the numbering and most of the header text are not aligned in a nice way.如您所见,在第3 种情况下,编号和大部分标题文本没有以良好的方式对齐。
I could solve case no.3 by using display-align="after" on the table-cell with the numbering.我可以通过在带有编号的表格单元格上使用display-align="after"来解决案例 3。 But in order not to mess up the other 3 cases, I would need to determine whether the content of the header text will wrap onto the next line or not.但为了不弄乱其他 3 种情况,我需要确定标题文本的内容是否会换行到下一行。 The font I am using for output is not monospaced, this is why counting characters would be an approximation, at best.我用于输出的字体不是等宽的,这就是为什么计数字符充其量只是一个近似值。
My question is, how it could be done so that case 3 looks like:我的问题是,如何才能使案例 3 看起来像:
__________________________
| | (1) |
|_1.2.3_|_header_text____|
while the others stay the same.而其他保持不变。
Thanks!谢谢!
EDIT: example of the markup for case 3编辑:案例 3 的标记示例
<fo:table font-size="18pt" font-weight="bold" font-style="italic" space-after="2mm" space-before="7mm" keep-with-next.within-page="always">
<fo:table-column column-width="16mm"/>
<fo:table-column/>
<fo:table-body>
<fo:table-row>
<fo:table-cell>
<fo:block>1.2.3</fo:block>
</fo:table-cell>
<fo:table-cell>
<fo:block>
<fo:block text-align="left">
<fo:block>Header Text (<fo:inline baseline-shift="super">1</fo:inline>)
</fo:block>
</fo:block>
</fo:block>
</fo:table-cell>
</fo:table-row>
</fo:table-body>
</fo:table>
EDIT 2: I tried to reverse the superscript-logic:编辑 2:我试图反转上标逻辑:
This "worked", I tested it for cases 3 + 4 and the heading text was in-line with the numbering in both cases.这“有效”,我针对案例 3 + 4 对其进行了测试,并且标题文本在这两种情况下都与编号一致。
But it has the drawback that I get a little extra spacing on top of the heading and that I would have to twist around to completely revert the superscript settings in the heading.但它的缺点是我在标题顶部有一点额外的间距,并且我必须扭转以完全恢复标题中的上标设置。
You are using an fo:inline element to wrap your superscript text, I suppose.我想您正在使用 fo:inline 元素来包装上标文本。 If you change the line-stacking-strategy from default max-height to font-height, there won't be a gap from superscript.如果您将 line-stacking-strategy 从默认的 max-height 更改为 font-height,则不会与上标有差距。 Try:尝试:
<fo:inline vertical-align="super" line-stacking-strategy="font-height">Your superscript text here</fo:inline>
Edit: I put line-stacking-strategy in the parent block too which was actually causing the effect.编辑:我也将 line-stacking-strategy 放在父块中,这实际上导致了效果。 I tested with Altsoft's renderer XML2PDF:我用 Altsoft 的渲染器 XML2PDF 进行了测试:
<fo:block line-stacking-strategy="font-height">Header Text <fo:inline baseline-shift="super">(1)</fo:inline>
To get the exact same baseline, I suggest to use it for the previous field too:为了获得完全相同的基线,我建议也将它用于上一个字段:
<fo:block line-stacking-strategy="font-height">1.2.3</fo:block>
Use relative-align="baseline"
(see https://www.w3.org/TR/xsl11/#relative-align ).使用relative-align="baseline"
(参见https://www.w3.org/TR/xsl11/#relative-align )。 Since it's inherited, you could put it on the fo:table-row
or even the fo:table
if you wanted.由于它是继承的,如果需要,您可以将它放在fo:table-row
甚至fo:table
。
With relative-align="baseline"
, the first lines in each fo:table-cell
are aligned to the same baseline.使用relative-align="baseline"
,每个fo:table-cell
中的第一行对齐到相同的基线。 The superscript in Case 3 effectively pushes down the baseline of the first line in its fo:table-cell
, and the baselines in the other fo:table-cell
will be aligned to match the lower baseline.案例 3 中的上标有效地将其fo:table-cell
第一行的基线向下推,另一个fo:table-cell
中的基线将对齐以匹配较低的基线。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.