Next / Previous / Contents / Shipman's homepage

10. treeSetup(): Build the XSL-FO layout

This function builds all of the XSL-FO tree except for the children of the page-sequence element. Here is an overview of the structure of an XSL-FO tree:

root
     layout-master-set: Defines all page layouts.
          simple-page-master: Defines one page layout.
          …
          page-sequence-master: When to use which layout.
     page-sequence: Root of all content.
           static-content: Define a header or footer.
          …
          flow: Main content.

Keep the fohelpers module documentation at hand when following this code. References to module h are to this module.

listext2
# - - -   t r e e S e t u p

def treeSetup(bodyLayout):
    '''Build the XSL-FO except for the flow element.

      [ (Args() is valid) and
        (bodyLayout is a BodyLayout instance) ->
          return (a new h.FlowTree containing XSL-FO formatted
          according to Args() and bodyLayout, the page-sequence
          element of that tree ]
    '''
    #-- 1
    # [ tree  :=  a new, empty h.FlowTree instance ]
    tree = h.FlowTree()

Section 11, “buildMasters(): Set up the page formats” adds everything under the layout-master-set that is available as tree.masters.

listext2
    #-- 2
    # [ tree.masters  +:=  (one or two simple-page-master
    #       subtrees as per bodyLayout) + (a page-sequence-master
    #       named REPEAT_MASTER as per bodyLayout) ]
    buildMasters(tree, bodyLayout)

    #-- 3
    # [ tree.root  +:=  a new, empty page-sequence element referring
    #                   to REPEAT_MASTER ]
    pages = subElement(tree.root, h.pageSequence(REPEAT_MASTER))

    #-- 4
    return (tree, pages)