def get_installed_fonts(): fonts = fontman.win32InstalledFonts(fontext='ttf') FONT_SPECIFIER_NAME_ID = 4 FONT_SPECIFIER_FAMILY_ID = 1 def font_short_name(font): """Get the short name from the font's names table""" name = "" family = "" for record in font['name'].names: if b'\x00' in record.string: name_str = record.string.decode('utf-16-be') else: name_str = record.string.decode('latin-1') if record.nameID == FONT_SPECIFIER_NAME_ID and not name: name = name_str elif record.nameID == FONT_SPECIFIER_FAMILY_ID and not family: family = name_str if name and family: break return name, family font_list = {} for i in range(len(fonts)): try: tt = ttLib.TTFont(fonts[i], fontNumber=0) except: print(fonts[i]) break font_list[font_short_name(tt)] = fonts[i] return font_list
def get_installed_fonts(fontfolder): fonts = fontman.win32InstalledFonts(fontext='ttf') print("Recovery of fonts installed on the computer.") if fontfolder is not None : print("Obtaining fonts from a specific folder.") for root, dirs, files in os.walk(fontfolder): path = root.split(os.sep) for file in files: if file.endswith(tuple(font_ext)): fonts.append(os.path.abspath(root + "//" + file)) FONT_SPECIFIER_NAME_ID = 4 FONT_SPECIFIER_FAMILY_ID = 1 def font_short_name(font): name = "" family = "" for record in font['name'].names: if b'\x00' in record.string: name_str = record.string.decode('utf-16-be') else: name_str = record.string.decode('latin-1') if record.nameID == FONT_SPECIFIER_NAME_ID and not name: name = name_str elif record.nameID == FONT_SPECIFIER_FAMILY_ID and not family: family = name_str if name and family: break return name.upper().replace(" ", ""), family.upper().replace(" ", "") font_list = {} for i in range(len(fonts)): try : tt = ttLib.TTFont(fonts[i], fontNumber=0) except: print(Fore.RED + "fontmerge : error : " + fonts[i] + " not found" + Fore.WHITE) break font_list[font_short_name(tt)] = fonts[i] return font_list
from matplotlib.figure import Figure from matplotlib.text import Text from matplotlib.path import Path from matplotlib import _png, rcParams from matplotlib.cbook import is_string_like, is_writable_file_like from matplotlib.compat import subprocess from matplotlib.compat.subprocess import check_output ############################################################################### # create a list of system fonts, all of these should work with xe/lua-latex system_fonts = [] if sys.platform.startswith('win'): from matplotlib import font_manager for f in font_manager.win32InstalledFonts(): try: system_fonts.append(font_manager.get_font(str(f)).family_name) except: pass # unknown error, skip this font else: # assuming fontconfig is installed and the command 'fc-list' exists try: # list scalable (non-bitmap) fonts fc_list = check_output(['fc-list', ':outline,scalable', 'family']) fc_list = fc_list.decode('utf8') system_fonts = [f.split(',')[0] for f in fc_list.splitlines()] system_fonts = list(set(system_fonts)) except: warnings.warn('error getting fonts from fc-list', UserWarning)