Calculate the length of text in pixels, given a list of (font-specific)
    glyph widths and the fontsize. Parameter 'widthlist' should have been
    created by 'doc._getCharWidths()'.

def pixlen(text, widthlist, fontsize):
    """Calculate the length of text in pixels, given a list of (font-specific)
    glyph widths and the fontsize. Parameter 'widthlist' should have been
    created by 'doc._getCharWidths()'."""
    pl = 0.0
    for t in text:
        pl += widthlist[ord(t)]
    return pl * fontsize