def getTextlength(text, fontname="<STR_LIT>", fontsize=<NUM_LIT:11>, encoding=<NUM_LIT:0>):
fontname = fontname.lower()<EOL>basename = Base14_fontdict.get(fontname, None)<EOL>glyphs = None<EOL>if basename == "<STR_LIT>":<EOL><INDENT>glyphs = symbol_glyphs<EOL><DEDENT>if basename == "<STR_LIT>":<EOL><INDENT>glyphs = zapf_glyphs<EOL><DEDENT>if glyphs is not None:<EOL><INDENT>w = sum([glyphs[ord(c)][<NUM_LIT:1>] if ord(c)<<NUM_LIT> else glyphs[<NUM_LIT>][<NUM_LIT:1>] for c in text])<EOL>return w * fontsize<EOL><DEDENT>if fontname in Base14_fontdict.keys():<EOL><INDENT>return TOOLS.measure_string(text, Base14_fontdict[fontname], fontsize, encoding)<EOL><DEDENT>if fontname in ["<STR_LIT>", "<STR_LIT>",<EOL>"<STR_LIT>", "<STR_LIT>",<EOL>"<STR_LIT>", "<STR_LIT>",<EOL>"<STR_LIT>", "<STR_LIT>"]:<EOL><INDENT>return len(text) * fontsize<EOL><DEDENT>raise ValueError("<STR_LIT>" % fontname)<EOL>
Calculate length of a string for a given built-in font.

    Args:
        fontname: name of the font.
        fontsize: size of font in points.
        encoding: encoding to use (0=Latin, 1=Greek, 2=Cyrillic).
    Returns:
        (float) length of text.