def get_cached_font(fontname, fontsize): key = (fontname, fontsize) try: return font_asst.get_cache(key) except KeyError: # see if we can build the font info = font_asst.get_font_info(fontname, subst_ok=True) font = ImageFont.truetype(info.font_path, fontsize) font_asst.add_cache(key, font) return font
def get_cached_font(fontname, fontsize, color, alpha): key = (fontname, fontsize, color, alpha) try: return font_asst.get_cache(key) except KeyError: # see if we can build the font info = font_asst.get_font_info(fontname, subst_ok=True) font = agg.Font(color, info.font_path, size=fontsize, opacity=alpha) font_asst.add_cache(key, font) return font
def get_cached_font(fontname, fontsize): key = (fontname, fontsize) try: return font_asst.get_cache(key) except KeyError: # see if we can build the font info = font_asst.get_font_info(fontname, subst_ok=True) font = cv2.freetype.createFreeType2() font.loadFontData(info.font_path, id=0) font_asst.add_cache(key, font) return font