Chapter 7. Phase 3: Rendering the pages

It is the task of the rendering phase to describe the area tree in the target page description language, so that viewers for that language can render the pages. Rendering is done page by page. For each page the rendering system is handed a PageViewport, and it walks the area subtree below it. For each area it retrieves the traits and data, and generates the required output.

The layout of a page is not finished until all forward references on that page have been resolved. As a consequence pages are finished out of pagination order. Some renderers support out of order rendering of pages, AbstractRenderer.supportsOutOfOrder(). If a renderer does, a finished page is handed over to it immediately. Otherwise, the layout system keeps finished pages until all preceding pages are also finished and have been handed over to the renderer. In principle, the PDF renderer supports out of order rendering. In current FOP (27 June 2004) this has been disabled because the support is broken.

This stack at a deep position, rendering a leader in a block in a flow in the body region, shows some details of rendering. Note how the hierarchy of the area tree can be recognized. The lower frames show how the rendering system is called by the layout system:

main[1] where
  [1] org.apache.fop.render.pdf.PDFRenderer.renderLeader (,266)
  [2] org.apache.fop.render.AbstractRenderer.serveVisitor (
  [3] org.apache.fop.area.inline.Leader.acceptVisitor (
  [4] org.apache.fop.render.AbstractRenderer.renderLineArea (
  [5] org.apache.fop.render.pdf.PDFRenderer.renderLineArea (
  [6] org.apache.fop.render.AbstractRenderer.renderBlocks (
  [7] org.apache.fop.render.AbstractRenderer.renderBlock (
  [8] org.apache.fop.render.pdf.PDFRenderer.renderBlock (
  [9] org.apache.fop.render.AbstractRenderer.renderBlocks (
  [10] org.apache.fop.render.AbstractRenderer.renderFlow (
  [11] org.apache.fop.render.AbstractRenderer.renderMainReference (
  [12] org.apache.fop.render.AbstractRenderer.renderBodyRegion (
  [13] org.apache.fop.render.AbstractRenderer.renderRegionViewport (
  [14] org.apache.fop.render.AbstractRenderer.renderPageAreas (
  [15] org.apache.fop.render.pdf.PDFRenderer.renderPage (
  [16] org.apache.fop.area.RenderPagesModel.addPage (
  [17] org.apache.fop.area.AreaTree.addPage (
  [18] org.apache.fop.layoutmgr.PageLayoutManager.finishPage (
  [19] org.apache.fop.layoutmgr.PageLayoutManager.doLayout (

Obviously there is a lot to be documented about the rendering system, and about each renderer separately. Because I do not (yet) know much about the rendering system, I will have to leave that task to others. I only add the obvious: Rendering requires precise programming: spacing and progress calculations, saving and restoring dimensions, etc. It also requires tracking the state in the output format.