(font="segoe", size=32)
Find the closest font size in the existing font files.
Find the closest font size in the existing font files.
Find the closest font size in the existing font files .
def find_best_size(font="segoe", size=32):
    """Find the closest font size in the existing font files."""
    filename = font + str(size)
    path = os.path.dirname(os.path.realpath(__file__))
    fnt = os.path.join(path, "%s.fnt" % filename)
    if os.path.exists(fnt):
        return size
    else:
        # we go through all .fnt files
        files = [file for file in os.listdir(path) if file.startswith(font) \
            and file.endswith('.fnt')]
        files.sort()
        # we take the largest existing size that is smaller to the requested
        # size
        newsize = 0
        for file in files:
            m = re.match(font + "([0-9]+)", file)
            if m:
                if int(m.group(1)) > size:
                    break
                newsize = int(m.group(1))
        log_debug("font %s %d does not exist, loading size %d instead" % \
            (font, size, newsize))
        return newsize
def find_best_size ( font = "segoe" , size = 32 ) : filename = font + str ( size ) path = os . path . dirname ( os . path . realpath ( __file__ ) ) fnt = os . path . join ( path , "%s.fnt" % filename ) if os . path . exists ( fnt ) : return size else : # we go through all .fnt files files = [ file for file in os . listdir ( path ) if file . startswith ( font ) and file . endswith ( '.fnt' ) ] files . sort ( ) # we take the largest existing size that is smaller to the requested # size newsize = 0 for file in files : m = re . match ( font + "([0-9]+)" , file ) if m : if int ( m . group ( 1 ) ) > size : break newsize = int ( m . group ( 1 ) ) log_debug ( "font %s %d does not exist, loading size %d instead" % ( font , size , newsize ) ) return newsize