Chapter 1. Overview

A FOP process has three stages:

  1. building the FO tree,
  2. building the Area tree,

    1. The getNextBreakPoss call tree
    2. The addAreas call tree
    3. Finishing the page
  3. rendering the pages.

These stages are preceded by two other stages:

Stage 0. The preparation stage occurs before the other stages. When it is completed it starts the parsing stage by calling the parser's parse method.

The parsing stage and stages 1, 2, 3 run concurrently. Each stage calls into the following stage at appropriate points in its process. It is feasible that stages 2 and 3 will run in separate threads.

Stage X. The parser now takes control. It parses the FO document or walks over the DOM tree. When it encounters XML events such as the start or end of the document, the start or end of an XML element, or character data, it makes a call back into the FO tree builder.

Stage 1. The FO tree builder now takes control to create or finish the FO node for which the XML event was fired. When it is done, it returns control to the parser.

The end events of a few XML elements invoke further actions of the FO tree builder. When a page-sequence FO node is finished, the FO tree builder notifies its tree listeners (of which there usually is only one, the Area tree builder) of this event. Each listener in turn takes control to process the page sequence.

Stage 2. The Area tree builder (which is the tree listener) now takes control to lay out the page sequence and construct the Area tree for it. This stage is divided in three substages.

Stage 2a. The (pseudo)tree of possible break points is created. Each node in the FO tree creates a Layout Manager of the appropriate type. The resulting tree of Layout Managers is recursed. Each Layout Manager asks each of its child Layout Managers in turn to return a possible break point, until all child Layout Managers are finished. This process is started by the Page Layout Manager, which is tied to the page-sequence FO node that was just completed in stage 1. Each time when its current child Layout Manager returns a possible break point, a complete (pseudo)tree of possible break points for a page has been collected. The next substage takes control.

Stage 2b. Now the area tree is created. The (pseudo)tree of possible break points and their Layout Managers is recursed. Each possible break point may create an area. It then calls the possible break points of the child LM that fall in this area, to create and return their area, and adds those areas to its own area. This process is started by the Page Layout Manager after the previous substage has finished. When its possible break point returns its area, the area tree for the flow of the page is complete.

Stage 2c. The Page Layout Manager adds the static areas and hands the page to the Area tree builder, which adds it to the root area. The Area tree builder now inspects the set of complete pages, and fills in forward references to the page just finished. Pages which are now complete including the forward references contained in them, are handed over to the renderer, which now takes control. When the renderer returns control, the Page Layout Manager starts again in stage 2a to lay out the next page in the page sequence.

When all pages of this page sequence are done, this stage finishes, and the Area tree builder returns control to the FO tree builder.

Stage 3. The renderer now takes control to render the finished pages. When it is done with those pages, it returns control to the Area tree builder.

This process model is FOP's default process model. It is completely configurable, through the objects constructed in the preparation stage. Stage 1 is configured by the content handler that is registered with the parser. Stage 2 is configured by the listeners that are registered with the FO tree builder. The layout process in stage 2 is also configured by the layout strategy that is registered with the Area tree builder. [It might be more appropriate to say that stage 2 is controlled by the tree control object. The actual Area tree builder is assigned by the layout strategy.] Stage 3 is configured by the selected renderer or output format.