Next / Previous / Contents / Shipman's homepage

6.14. addMasters(): Set up the page masters

docbookindex
# - - -   a d d M a s t e r s

def addMasters(masterSet):
    '''Set up the simple and repeating page masters.

      [ masterSet is a layout-master-set element ->
          masterSet  +:=  simple-page-master elements for
              odd and even pages and a page-sequence-master
              that alternates them ]
    '''

The first step is to create two PageDim instances for the odd and even page master layouts. Then we append simple-page-master elements using those dimensions. Refer to the illustrations in Section 5.2, “Structure of the XSL-FO output: Page masters”. The pageDimFactory function gives us a letter-sized page with generic margins, which we then override.

docbookindex
    #-- 1
    # [ oddDims  :=  a letter PageDim instance modified for odd pages
    #   evenDims  :=  a letter PageDim instance modified for even pages ]
    oddDims = h.pageDimFactory(h.PAPER_LETTER_LAND)
    oddDims.pageMargins.top = WIDE_MARGIN
    oddDims.pageMargins.bot = NARROW_MARGIN
    oddDims.pageMargins.left = NARROW_MARGIN
    oddDims.pageMargins.right = NARROW_MARGIN
    oddDims.frameMargins.top = HEADING_EXTENT
    oddDims.frameMargins.bottom = '0pc'
    oddDims.bodyMargins.top = '18pt'
    oddDims.bodyMargins.bot = '0pc'

    evenDims = h.pageDimFactory(h.PAPER_LETTER_LAND)
    evenDims.pageMargins.top = NARROW_MARGIN
    evenDims.pageMargins.bot = WIDE_MARGIN
    evenDims.pageMargins.left = NARROW_MARGIN
    evenDims.pageMargins.right = NARROW_MARGIN
    evenDims.frameMargins.top = HEADING_EXTENT
    evenDims.frameMargins.bottom = '0pc'
    evenDims.bodyMargins.top = '18pt'
    evenDims.bodyMargins.bot = '0pc'

The simpleMaster() function builds the simple-page-master structure that defines one page layout.

docbookindex
    #-- 2
    # [ masterSet  +:=  a new simple-page-master named
    #       ODD_MASTER set up for odd pages with header
    #       region ODD_BEFORE ]
    masterSet.append(
      h.simpleMaster(ODD_MASTER, oddDims,
        h.regionBody(oddDims, REGION_BODY_PROPS),
        h.regionBefore(oddDims, ODD_BEFORE)))

    #-- 3
    # [ masterSet  +:=  a new simple-page-master named
    #       EVEN_MASTER set up for even pages with header
    #       region EVEN_BEFORE ]
    masterSet.append(
      h.simpleMaster(EVEN_MASTER, evenDims,
        h.regionBody(evenDims, REGION_BODY_PROPS),
        h.regionBefore(evenDims, EVEN_BEFORE)))

Finally, add the page-sequence-master with its child repeatable-page-master-alternatives element containing two conditional-page-master-references, one each for odd and even pages.

docbookindex
    #-- 4
    # [ masterSet  +:=  a new page-sequence-master named
    #       REPEAT_MASTER, with repeatable-page-master-alternatives
    #       child elements that in turn contain
    #       conditional-page-master-references for ODD_MASTER on odd
    #       pages and EVEN_MASTER on even pages ]
    masterSet.append(h.repeatMaster(REPEAT_MASTER,
        h.conditionalMaster(ODD_MASTER, oddEven="odd"),
        h.conditionalMaster(EVEN_MASTER, oddEven="even") ) )