Search code examples
xmlxsl-fo

External-graphic has space above even though I've set it to zero


My XSL-FO template has an image in the footer of each page:

<fo:block-container left="0mm" top="10mm" absolute-position="absolute" width="210mm" height="10mm" border="0.1pt black solid" margin="0mm" padding="0mm" space-before="0mm">
    <fo:block border="0.1pt green solid" margin="0mm" padding="0mm" space-before="0mm">
        <fo:external-graphic src="grayblock.pdf"  height="10mm" content-height="scale-to-fit" border="0.1pt blue solid" margin="0mm" padding="0mm" space-before="0mm"/>
    </fo:block>
</fo:block-container>

I expect the top of the image to be aligned with the top of the block-container. But this is the result I get:

enter image description here

My image (the blue/gray rectangle) starts about 0.5 mm below the top of the block-container (the distance between the black line and the blue/gray rectangle).

What I've tried:

  • I inserted margin="0mm" padding="0mm" space-before="0mm" to make sure the block-container, block and external-graphic don't inherit any margins, padding etc. from ancestors. That didn't change the result.
  • Adding a negative margin/padding doesn't move the external-graphic up.
  • setting the borders to "none" doesn't resolve the problem. I've added the borders to visualize which of the elements is causing the problem.

Normally, this 0.5 mm gap doesn't matter much. In this case, I'm trying to align two block-containers and their contents, and the difference is making it difficult to get them to line up exactly.

How do I eliminate this gap above the external-graphic?

(I'm using Antenna House XSL Formatter 6.1)


Solution

  • I think the gap has two culprits:

    • the three borders (on fo:block-container, fo:block and fo:external-graphic), which erode the available heigth
    • the half-leading trait

    Removing the borders and setting the block line-height to be exactly 10mm should avoid the gap (I tested with FOP 2.2):

    <fo:block-container left="0mm" top="30mm" absolute-position="absolute" width="210mm" height="10mm" margin="0mm" padding="0mm" space-before="0mm" background-color="#AAFFFF">
        <fo:block line-height="10mm" line-stacking-strategy="font-height" margin="0mm" padding="0mm" space-before="0mm" background-color="#FFFFAA">
            <fo:external-graphic vertical-align="top" src="grayblock.pdf" height="10mm" content-height="scale-to-fit" margin="0mm" padding="0mm" space-before="0mm"/>
        </fo:block>
    </fo:block-container>