Next / Previous / Contents / Shipman's homepage

22.6. OutBlock.renderChar(): Translate one character to XSL-FO

listext2
# - - -   O u t B l o c k . r e n d e r C h a r

    def renderChar(self, parent, c):
        '''Translate one character to XSL-FO.
        '''

Characters outside the printable range (between SP and ~, inclusive) are rendered as an inline whose font size is half of the body size, containing the two hexadecimal digits of the character's code. This box is outlined by rules so that in a long sequence of unprintables you can tell which digits go in which character.

listext2
        #-- 1
        # [ if ' ' <= c <= '~' ->
        #     parent  :=  parent with c added to its text
        #     return
        #   else -> I ]
        if ' ' <= c <= '~':
            addText(parent, c)
            return

        #-- 2
        # [ parent  :=  parent with an inline added, containing the
        #       two hex digits of c's ordinal in half-size font ]
        halfSize = "%spt" % (Args().pointSize/2)
        halfFont = h.font(fontSize=halfSize)
        parent.append(
            h.inline(halfFont, "%02x" % ord(c),
                h.dash(borderStyle='solid', borderWidth='0.3pt')))