Next / Previous / Contents / Shipman's homepage

6.18. formatLine(): Assemble one block in the report body

docbookindex
# - - -   f o r m a t L i n e

def formatLine ( flow, depth, sectionId, titleInline ):
    '''Build the block containing one line of the report.

      [ (flow is an et.Element) and
        (depth is a nonnegative int) and
        (sectionId is the section ID as a string) and
        (titleInline is an FO inline) ->
          flow  +:=  a block displaying sectionId and titleInline,
                     indented by (depth) levels ]
    '''

For notes on the design of this block element, see Section 5.3, “The report format”. Our first task is to compute the start-indent and text-indent dimensions for the block. These computations are functions of the indentation depth and the constants Section 6.3.13, “INDENT_PER_LEVEL and Section 6.3.14, “CONTINUED_INDENT.

docbookindex
    #-- 1
    # [ startIndent  :=  an h.FoDim instance representing
    #       (CONTINUED_INDENT + depth * INDENT_PER_LEVEL)
    #   textIndent  :=  an h.FoDim instance representing
    #       (- CONTINUED_INDENT) ]
    startIndent = CONTINUED_INDENT + INDENT_PER_LEVEL*depth
    textIndent = - CONTINUED_INDENT

    #-- 2
    # [ flow  +:=  a new block element with font BODY_FONT
    #   block  :=  that block element ]
    block = subElement(flow,
        h.block(BODY_FONT,
            h.dash(startIndent=str(startIndent),
                   textIndent=str(textIndent))))

The sectionId is wrapped in an inline that uses a monospaced font. The offset PRE_TITLE between that inline and the following text is implemented as a padding-right property on the inline.

docbookindex
    #-- 3
    # [ block  +:=  an inline containing sectionId in monospaced
    #               font, with PRE_TITLE right padding ]
    idInline = subElement(block,
        h.inline(ID_FONT, sectionId,
                 h.dash(paddingRight=str(PRE_TITLE))))

Finally, add the FO-rendered title text.

docbookindex
    #-- 3
    block.append(titleInline)