Next / Previous / Contents / Shipman's homepage

15. buildStatic(): Set up page headings

The purpose of this function is to set up the running head by addin either one (for simplex) or two (for duplex) static-content elements to the page-sequence element.

For details about all the items in the running head and what they contain, see Section 21, “class Heading: Information for the running head”. The same information is always present, but the order of the elements is reversed in some layouts. By “right-hand content” we mean that the page number appears last, and with “left-hand content” the page number appears first, as it must for duplex portrait layout. In the Heading class, the .rightContent() and .leftContent() methods produced the content with those respective orderings.

The main complication handled here is that the running head normally appears in the before-region, but in one case (odd duplex pages) actually appears in the after-region, where footers normally appear.

# - - -   b u i l d S t a t i c

def buildStatic(pages, inputFile):
    '''Generate the headers' static content.

      [ (Args() is valid) and
        (pages is a page-sequence et.Element) ->
          pages  +:=  static-content children containing headings 
              as per Args() with page count from inputFile ]

To gather the various elements of the page headings, we instantiate Section 21, “class Heading: Information for the running head”. This constructor needs inputFile.nOutPages so it can display the total page count on every page.

    #-- 1
    # [ heading  :=  a Heading instance representing the header
    #       content for Args() and inputFile ]
    heading = Heading(inputFile)

Refer to the page layout diagrams in Section 5.2, “XSL-FO design: General page layout”. We add content to the even page masters only for duplex layout.

    #-- 2
    if Args().isLandscape:
        heading.rightContent(pages, ODD_AFTER)
        if Args().duplex:
            heading.rightContent(pages, EVEN_BEFORE)
        heading.rightContent(pages, ODD_BEFORE)
        if Args().duplex:
            heading.leftContent(pages, EVEN_BEFORE)