如何在apache-fo

时间:2016-01-12 12:00:29

标签: xsl-fo apache-fop

我在apache-fo中遇到问题,在一般HTML& CSS,如果我们给位置:绝对一个div,它将取自其父级Top和Left, 但同样的,如果我给位置:绝对到Apache FO中的特定块容器,它取自Page Top&左

例如:

<fo:flow flow-name="xsl-region-body">

[I want this type of scenario][1]
<fo:block-container width="100%" color="rgb(0, 0, 0)">
<fo:block>

<fo:block-container>
<fo:block-container width="50%" left="1in" top="1in" position="absolute"><fo:block>First Block</fo:block></fo:block-container>
<fo:block-container width="50%" left="2in" top="3in" position="absolute"><fo:block>Second Block</fo:block></fo:block-container>
</fo:block-container>

<fo:block-container>

<fo:block-container width="50%" left="1in" top="1in" position="absolute"><fo:block>Third Block</fo:block></fo:block-container>
<fo:block-container width="50%" left="2in" top="2in" position="absolute"><fo:block>Fourth Block</fo:block></fo:block-container>
</fo:block-container>

</fo:block>
</fo:block-container>

</fo:flow>

在给定的例子中:我给postion绝对阻止容器和top 1in;并离开1in;而不是从顶部&amp;离开他们的父母,从顶部和顶部拿走1英寸从顶部块Container离开。

我希望输出像After First Block,Second Block将在Top&amp;距离第一街区左侧1英寸。但现在它显示所有第一区块,第二区块,第三区块,第四区块都处于相同的位置,并采取顶部&amp;从顶部块容器中留下1英寸。

#main_div, #main_div1, #block1, #block2, #block3, #block4{
  border:2px solid red;
  position:absolute;
  height:80px;
}
<html>
  <head></head>
  <body>
    <div id ="main_div" style="position: relative; width:100%;"> 
      <div id="block1" style="top:2px; left:2px; width:100px;">First Block</div>
      <div id="block2" style="top:2px; left:110px;width:100px;">Second Block</div>
    </div>
    
    <div id ="main_div1" style="position: relative; width:100%;"> 
      <div id="block3" style="top:2px; left:2px; width:100px;">Third Block</div>
      <div id="block4" style="top:2px; left:110px;width:100px;">Fourth Block</div>
    </div>
    
    
  </body>
  </html>

2 个答案:

答案 0 :(得分:1)

position="absolute"absolute-position="absolute" relative-position="static"的简写。 fo:block-container absolute-position="absolute"已从正常流量中删除(请参阅http://www.w3.org/TR/xsl11/#absolute-position),因此包含fo:blockfo:block-container的内容实际上没有内容,并且没有高度,因为他们没有内容。所以你的块重叠是因为它们相对于两个有效位于彼此之上的零高度fo:block-container

如果我正确理解您的要求,您可以通过为包含绝对定位的`fo:block容器的height指定fo:block-container来获得您想要的内容:

<fo:flow flow-name="xsl-region-body">
    <fo:block-container width="100%" color="rgb(0, 0, 0)">
        <fo:block border="thin solid silver">
            <fo:block-container border="thin solid yellow" height="4in">
                <fo:block-container width="50%" left="1in" top="1in" position="absolute" border="thin solid black"><fo:block>First Block</fo:block></fo:block-container>
                <fo:block-container width="50%" left="2in" top="3in" position="absolute" border="thin solid red"><fo:block>Second Block</fo:block></fo:block-container>
            </fo:block-container>
            <fo:block-container border="thin solid purple" height="4in">
                <fo:block-container width="50%" left="1in" top="1in" position="absolute" border="thin solid green"><fo:block>Third Block</fo:block></fo:block-container>
                <fo:block-container width="50%" left="2in" top="2in" position="absolute" border="thin solid blue"><fo:block>Fourth Block</fo:block></fo:block-container>
            </fo:block-container>
        </fo:block>
    </fo:block-container>
</fo:flow>

使用AH Formatter进行测试。

答案 1 :(得分:1)

此解决方案仅在fo:block-container s上为第一个和第三个文本块设置高度(这应该是一个合理的约束,否则这些块将分别与第二个和第四个块重叠):

start-indent
  • left s 给定绝对定位
  • 使用
  • fo:block代替margin-top,并且必须在内部height中将其设置为0,以避免不必要的继承缩进
  • topgl_FragCoord = vec4(color.a > 0. ? color.rgb / color.a : vec3(0), color.a); 代替Un-premultiplied Red = 0.7 Alpha = 0.2 convert to premultiplied Red = Red * Alpha Premultiplied Red = 0.14 Alpha = 0.2 blend with ONE,ONE_MINUS_SRC_ALPHA DstRed = 0.0 DstAlpha = 0.0 newPixelRed = Red(0.14) * ONE + DstRed(0.0) * (1 - Alpha(0.2)) newPixelRed = 0.14 + 0.0 * 0.8 newPixelRed = 0.14 newPixelAlpha = Alpha(0.2) * ONE + DstAlpha(0.0) * (1 - Alpha(0.2)) newPixelAlpha = 0.2 + 0.0 * 0.8 newPixelAlpha = 0.2

彩色边框从Tony Graham's answer无耻地复制:它们对于查看不同区域的大小和位置非常有帮助。

使用FOP 1.1,2.0和2.1进行测试(我非常有信心,其他格式化程序也会产生相同的输出)。