예제 #1
0
def _getRegistry():
    if os.path.isfile( registryFile ):
        registry = ttffiles.load( registryFile )
    else:
        registry = ttffiles.Registry()
        log.info( """Scanning for system fonts...""" )
        new,failed = registry.scan( printErrors = 1, force = 0)
        log.info( """Scan complete. Saving to %r\n""", registryFile,)
        registry.save(registryFile)
    return registry
예제 #2
0
def _getRegistry():
    if os.path.isfile(registryFile):
        registry = ttffiles.load(registryFile)
    else:
        registry = ttffiles.Registry()
        sys.stderr.write("""Scanning for system fonts...\n""")
        new, failed = registry.scan(printErrors=1, force=0)
        sys.stderr.write("""Scan complete. Saving to %r\n""" %
                         (registryFile, ))
        registry.save(registryFile)
    return registry
예제 #3
0
def load_font(fontname, allow_fallback, ttf_registry=ttffiles.Registry()):
    try:
        return describe.openFont("C:/Windows/Fonts/" + fontname)
    except IOError:
        pass

    try:
        if 0 == len(ttf_registry.fonts):
            ttf_registry.scan()
        return ttf_registry.fontFile(os.path.splitext(fontname)[0])
    except KeyError:
        if allow_fallback:
            print "could not load font", fontname, " so try to fall back to arial"
            return load_font("arial.ttf", False)
        else:
            raise IOError("could not load font", fontname,
                          " and no fallback is allowed->we are done")