def get_font(fn, size, bold, italics, outline, antialias, vertical): t = (fn, bold, italics) fn, bold, italics = renpy.config.font_replacement_map.get(t, t) rv = image_fonts.get((fn, size, bold, italics), None) if rv is not None: return rv if vertical: key = (fn, size, bold, italics, outline, antialias, True) else: key = (fn, size, bold, italics, outline, antialias) rv = font_cache.get(key, None) if rv is not None: return rv # If we made it here, we need to load a ttf. face = load_face(fn) rv = ftfont.FTFont(face, size, bold, italics, outline, antialias, vertical) #@UndefinedVariable font_cache[key] = rv return rv
def get_font(fn, size, bold, italics, outline, antialias, vertical, hinting, scale): # If the scale changed, invalidate caches of scaled fonts. global last_scale if (scale != 1.0) and (scale != last_scale): scaled_image_fonts.clear() font_cache.clear() last_scale = scale # Perform replacement. t = (fn, bold, italics) fn, bold, italics = renpy.config.font_replacement_map.get(t, t) # Image fonts. key = (fn, size, bold, italics) rv = image_fonts.get(key, None) if rv is not None: if scale != 1.0: if key in scaled_image_fonts: rv = scaled_image_fonts[key] else: rv = ScaledImageFont(rv, scale) scaled_image_fonts[key] = rv return rv # Check for a cached TTF. key = (fn, size, bold, italics, outline, antialias, vertical, hinting, scale) rv = font_cache.get(key, None) if rv is not None: return rv # Load a TTF. face = load_face(fn) rv = ftfont.FTFont(face, int(size * scale), bold, italics, outline, antialias, vertical, hinting) #@UndefinedVariable font_cache[key] = rv return rv