Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How come xsl-fo padding is being applied to other blocks?

I'm at a loss trying to understand this. I'm new to using xsl-fo (apache-fop implementation) and I want a block with a border and the content inside padded so it's not bumped up against the border. However when I add the padding, the padding is also applied to the following block?

<fo:page-sequence master-reference="report-page">
<fo:flow flow-name="xsl-region-body">

    <fo:block border="1px solid black" font-size="8pt" margin-bottom="3mm" padding="3mm" >
        <fo:block font-weight="bold">FOO</fo:block>
        <fo:block>ANOTHER BLOCK</fo:block>
    </fo:block>

    <fo:block font-size="8pt">BAR</fo:block>
</fo:flow>

Why does BAR become indented by the amount of padding from the previous block? If I remove the padding on the first block, things line up fine?

like image 723
Rick Reumann Avatar asked Feb 15 '23 15:02

Rick Reumann


2 Answers

What you should be doing is setting margin to "0mm" and padding to "3mm" on the block if your intention is to have no space outside the border and a 3mm space between the text and the border.

<fo:block border="1px solid black" font-size="8pt" margin="0mm" padding="3mm">
    <fo:block font-weight="bold">FOO</fo:block>
</fo:block>

If the margin-bottom was intended to make space between elements, then you would use space-after or space-before on the following element.

like image 161
Kevin Brown Avatar answered Mar 16 '23 09:03

Kevin Brown


Try to do the following (this is not tested because my Apache FOP installation is not within reach...)

EDIT : Now tested. Padding is only applied to the first block ("FOO").

Specify the padding inside a fo:inline element like this:

<fo:block border="1px solid black" margin-bottom="3mm">
 <fo:inline padding="3mm" font-size="8pt" font-weight="bold"> 
  <fo:block>FOO</fo:block>
 </fo:inline>
</fo:block>

Also, I've moved the font-weight and font-size properties to the inline element, since the inner block is the only place they are needed (at least in your simple snippet). The outer block only defines the border. Let me know if this works.

like image 34
Mathias Müller Avatar answered Mar 16 '23 07:03

Mathias Müller