'Find a font on the system capable of rendering the given text.
Returns a font family (as given by fonts_for_family()) that has a
"normal" font and that can render the supplied text. If no such font
exists, returns None.
:return: (family name, faces) or None, None'

def find_font_for_text(self, text, allowed_families={u'serif', u'sans-serif'}, preferred_families=(u'serif', u'sans-serif', u'monospace', u'cursive', u'fantasy')):

    from calibre.utils.fonts.utils import supports_text, panose_to_css_generic_family, get_printable_characters
    if (not isinstance(text, unicode)):
        raise TypeError((u'%r    is    not    unicode' % text))
    text = get_printable_characters(text)
    found = {}
    def filter_faces(font):
        try:
            raw = self.get_font_data(font)
            return supports_text(raw, text)
        except:
            pass
        return False
    for family in self.find_font_families():
        faces = filter(filter_faces, self.fonts_for_family(family))
        if (not faces):
            continue
        generic_family = panose_to_css_generic_family(faces[0][u'panose'])
        if ((generic_family in allowed_families) or (generic_family == preferred_families[0])):
            return (family, faces)
        elif (generic_family not in found):
            found[generic_family] = (family, faces)
    for f in preferred_families:
        if (f in found):
            return found[f]
    return (None, None)
