Floats
The fo:float element can be used to position an image or other elements to the side or top of the page and cause text to flow around that image. The paragraph in Figure 10-1 uses two fo:float elements to make the image appear on the left and right sides, with the text flowing around the images and below them.
The XML used to create Figure 10-1 is as follows:
<fo:block font-size="1.0em" text-align="justify">
<fo:float float="left">
<fo:block-container inline-progression-dimension="2.5cm">
<fo:block text-align="center">
<fo:external-graphic src="url(ibexorange.jpg)" content-width="50%" padding="3pt"/>
</fo:block>
</fo:block-container>
</fo:float>
Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Duis in dolor quis lectus cursus condimentum. Vestibulum
id nunc vitae dui semper ultrices. Mauris a mi. Phasellus eu lacus. Pellentesque eu ligula mattis odio faucibus faucibus.
Aliquam sit amet
<fo:float float="right">
<fo:block-container inline-progression-dimension="2.5cm">
<fo:block text-align="center">
<fo:external-graphic src="url(ibexorange.jpg)" content-width="50%" padding="3pt"/>
</fo:block>
</fo:block-container>
</fo:float>
nunc laoreet tellus ullamcorper malesuada. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere
cubilia Curae; Cras nec mauris. Proin cursus tincidunt leo. Maecenas metus lacus, imperdiet fermentum, blandit at,
sollicitudin eu, sem. Duis elementum libero vitae lacus. Curabitur justo. Aliquam erat volutpat. Maecenas nec nulla
in massa consectetuer volutpat. Aenean turpis nisl, rutrum a, posuere sit amet, varius in, enim. Praesent risus. Nam
volutpat enim eget neque. Maecenas a dui ac felis nonummy sollicitudin. Proin iaculis. Vestibulum in eros sit amet
libero mollis convallis. nunc laoreet tellus ullamcorper malesuada. Vestibulum ante ipsum primis in faucibus orci
luctus et ultrices posuere cubilia Curae; Cras nec mauris. Proin cursus tincidunt leo. Maecenas metus lacus,imperdiet
fermentum, blandit at, sollicitudin eu, sem. Duis elementum libero vitae lacus. Curabitur justo. Aliquam erat volutpat.
Maecenas nec nulla in massa consectetuer volutpat. Aenean turpis nisl, rutrum a, posuere sit amet, varius in, enim.
Praesent risus. Nam volutpat enim eget neque. Maecenas a dui ac felis nonummy sollicitudin. Proin iaculis. Vestibulum
in eros sit amet libero mollis convallis.
</fo:block>
This effect is achieved by having a fo:block which contains the text and two fo:float elements. The fo:float elements in turn contain a fo:block-container element which has a inline-progression-dimension attribute defining the width of the float area. Any elements inside the block-container will be in the float area. If a fo:block-container is not used within the float and the width of the float cannot be determined, a default configurable value is used.
The FO for creating the above is show in Figure 10-2. Figure 10-2 is itself contained inside an fo:float with float = "before", which will make it appear at the top of the following page. This technique is used in this manual when we do not want a large example to be split across page breaks or to interrupt the content. When a fo:float has float = "before", its position in the PDF file is not the same as its position in the FO file, in that it will be moved to the top of the next page and the blocks before and after the fo:float will flow as if the fo:float was not there.
The side on which the float occurs is specified using the float attribute. This can be set to "left" or "right" to position the fo:float at the side of the page. It can also be set to "before" to position the fo:float at the start of the next page.
Side floats (with float = "left" or float = "right") are closely tied to the block which contains the float element.
If the float element does not fit on the page, then the float and some or all of the containing block will be moved to the following page. This ensures that the text in the block does not refer to (for example) an image in the float which is not on the same page as the text.
How the float width is calculated
Ibex looks at the content of the fo:float element to try and determine how wide the float should be. If a block-container element is found directly below the float element, and this block-container has a width attribute, then that determines the width of the float. If no width can be found, then the width of the float is calculated from by multplying the containing block width by Settings.SideFloatDefaultWidthPercentage, which defaults to 30%.