OSArch Community

Does bonsai have a library where you can find the font on the particular OS

  1. T

    Does bonsai have a library where you can find the font on the particular OS--whether it's Windows or Linux?

    Something like matplotlib

    
    from matplotlib import font_manager
    
    
    def find_font_path(font_name):
    
        """Find the font path by its name on the system."""
    
        font_files = font_manager.findSystemFonts(fontpaths=None, fontext='ttf')
    
        for font_path in font_files:
    
            font = font_manager.FontProperties(fname=font_path)
    
            if font.get_name() == font_name:
    
                return font_path
    
        return None
    
    
    # Example usage:
    
    font_path = find_font_path("Arial")
    
    if font_path:
    
        print(f"Font path found: {font_path}")
    
    else:
    
        print("Font not found.")
    

Login or Register to reply.