在 Apache FOP 中将文本覆盖在图像上

Overlay text over an image in Apache FOP

我正在尝试将一段文本覆盖在外部图形上,我能够做到这一点,但是每当在图像上呈现文本块时我都会看到此错误:

org.apache.fop.layoutmgr.table.TableCellLayoutManager: getContentAreaBPD called on unknown BPD

我尝试为 table 单元格、块容器和块设置高度,但没有任何帮助。

   <fo:table-cell display-align="center" height="229px">
          <fo:block>
              <fo:block-container z-index="1" top="0px" left="0px">
                  <fo:block height="229px" absolute-position="absolute">
                      <fo:external-graphic scaling="non-uniform" src=url("http://previews.123rf.com/images/nujalee/nujalee1108/nujalee110800004/10410227-Beautiful-green-leaf-isolated-on-white-Stock-Photo-leaf-texture.jpg") content-height="229px" content-width="110px"/>
                  </fo:block>
              </fo:block-container>
              <fo:block-container z-index="2" background-color="#538000" height="20px" width="77px" bottom="-229px" right="0px" absolute-position="absolute">
                  <fo:block color="#333333" font-size="10px" height="20px" font-family="Arial" display-align="center" text-align="center">
                      LEAF
                  </fo:block>
              </fo:block-container>
          </fo:block>
   </fo:table-cell>

任何人都可以帮助我如何解决此错误并指导我做错了什么。我正在使用 ApacheFOP 2.1

XSL-Recommendation 指出:

The area's position (and possibly size) is specified with the "left", "right", "top", and "bottom" properties. These properties specify offsets with respect to the area's nearest ancestor reference area.

Absolutely positioned areas are taken out of the normal flow. This means they have no impact on the layout of later siblings.

所以:

  • 不需要将绝对定位的fo:block-containerfo:block元素放在其他对象中,它们可以是fo:flow
  • 的直接子元素
  • 第二个fo:block-container上的属性bottom="-229px"我不明白你想达到什么目的,但它的实际效果是把这个区域放在body区域下面很远的地方, 完全在页面之外;如果您希望对象重叠,请改用 top,其值小于其他容器的高度
  • 目前,z-index is not supported by FOP所以它也可以删除;重叠的对象按照它们在文档中的顺序堆叠,所以第一个在下面,最后一个出现在所有其他对象之上

这是简化后的结果,经过FOP处理没有错误:

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

      <fo:block height="229px" absolute-position="absolute">
          <fo:external-graphic scaling="non-uniform" src="url('http://previews.123rf.com/images/nujalee/nujalee1108/nujalee110800004/10410227-Beautiful-green-leaf-isolated-on-white-Stock-Photo-leaf-texture.jpg')" content-height="229px" content-width="110px"/>
      </fo:block>
      <fo:block-container background-color="#538000" height="20px" width="77px" absolute-position="absolute" top="30px">
          <fo:block color="#333333" font-size="10px" height="20px" font-family="Arial" display-align="center" text-align="center">
              LEAF
          </fo:block>
      </fo:block-container>

    </fo:flow>

(作为最后的说明,错误本身可能是由于错误造成的)

披露:我是一名 FOP 开发人员,虽然现在不是很活跃。