Next / Previous / Contents / Shipman's homepage

14. addFlow(): Populate the page-sequence element

This function is the final phase of XSL-FO generation: to the page-sequence element we add running heads, then formatted input file lines.

listext2
# - - -   a d d F l o w

def addFlow(pages, bodyLayout, inputFile):
    '''Output the Formatted lines from the input file.

      [ (Args() is valid) and
        (pages is a page-sequence et.Element) and
        (bodyLayout is a BodyLayout instance) and
        (inputFile is an InputFile instance) ->
          pages  +:=  (running heads as specified by Args()) +
             (XSL-FO renderings of lines from inputFile using the
             layout described by (bodyLayout) ]
    '''

First we build the running heads, which are static-content children of the page-sequence element. See Section 15, “buildStatic(): Set up page headings”.

listext2
    #-- 1
    # [ pages  +:=  running heads as specified by Args() with
    #               page count from inputFile ]
    buildStatic(pages, inputFile)

Rather than specifying every style attribute on every output line, we'll wrap the entire content under the flow element in a block-container, and add the style attributes there so the block elements inside it will inherit that style. The wrapper is created in Section 16, “wrapFlow: Add a styling block-container.

listext2
    #-- 2
    # [ pages  :=  a new flow element
    #   flow  :=  that element ]
    flow = subElement(pages, h.flow())

    #-- 3
    # [ flow  +:=  a block-container that styles its child blocks
    #              as specified by Args()
    #   wrapper  :=  that block-container ]
    wrapper = wrapFlow(flow)

The InputFile.genBlocks() method generates the sliced and paginated input lines as a sequence of instances of Section 22, “class OutBlock: One output block”. Method OutBlock.render() attaches a block element to wrapper containing a rendered version of the line.

listext2
    #-- 3
    # [ wrapper  +:=  blocks containing XSL-FO renderings of the
    #       lines in inputfile ]
    for outBlock in inputFile.genBlocks():
        outBlock.render(wrapper)