FOray Users
Module Users

FOray Developer: General Layout



The purpose of this document is to describe some general layout concepts that are relevant to all layout systems. FOray’s modular design allows multiple layout systems to share the other modules, allowing layout systems to be developed in parallel. This allows old layout systems to continue being used while new ones are developed. It also provides the possibility of having different layout systems optimized for different axes, and letting the user select the one that meets his operational needs.

Layout Tasks

The task of layout is to create an AreaTree representation of the content and constraints in the FO Tree. This can broadly be broken down into these two tasks:

  • Creating line-breaks. More precisely, this is the process of getting text and inlines stacked in line-areas.
  • Creating page-breaks. More precisely, this is the process of getting line-areas stacked in pages, i.e. deciding on which page each line area should be placed.

Because the AreaTree is the output from layout, it is easy for systems to confuse the two. FOray's modular design wants as much logic as possible to be placed in the AreaTree. For example, AreaTree should handle all aspects of trait resolution, and issues like reference-orientation, writing-mode, and the location of individual areas on a page. A layout system should not need to worry about anything except the size of the various areas with which it works.

Line-breaking is actually handled in the FOrayText module, which might rightfully be considered part of the layout system. FOrayText is also designed to allow multiple line-breaking strategies (LBS) to be employed.

The net result is that the layout system's job is to find page breaks.

Eager vs. Patient Processing

Layout systems can generally be divided into those that are "eager" and those that are "patient". Eager systems try to finalize the layout of each element, in order, as it is encountered in the FO Tree. Patient systems wait to finalize the layout until the entire document or a substantial portion of the document has been analyzed. There is some middle ground between these two poles. For example, a system could be patient with regard to line-breaking, but, once a block has been laid out, finalize its location on the page(s) without regard to subsequent content.

In general, the linear nature of an eager system will tend to be faster and leaner on memory than a patient one, but will produce output of lower quality. By allowing backtracking and lookahead, and by evaluating options, a more patient system consumes more system resources, but allows the possibility of substantially higher-quality output.

The flows of eager and patient processors tend to be very different as well. In an eager system, when lines can no longer be created on a page, the system must store information about the state of the layout process, return control back up the FOTree until a new page can be created, then continue the layout from the stored state information. Since a patient system is driven more from the top of the tree (i.e. nearer the root) and processes in larger chunks, it conceptually creates new pages and lines in the background.


Here are some resources for researching layout, line-breaking, and page-breaking issues: