CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/pypi-pyfiglet

Pure Python implementation of FIGlet for creating ASCII art text from regular text using various fonts

Pending
Overview
Eval results
Files

font-management.mddocs/

Font Management

Comprehensive font system for managing FIGlet fonts including discovery, validation, installation, and information retrieval. Supports .flf, .tlf font formats and ZIP archives containing multiple fonts.

Capabilities

Font Discovery

Retrieves a list of all available fonts from both built-in and user-installed locations.

@classmethod
def getFonts(cls) -> list[str]:
    """
    Get list of all available font names.
    
    Returns:
    list[str]: Sorted list of available font names (without extensions)
    
    Searches:
    - Built-in fonts in pyfiglet.fonts package
    - User fonts in SHARED_DIRECTORY
    - Validates each font file before including
    """

Usage Example

from pyfiglet import FigletFont

# Get all available fonts
fonts = FigletFont.getFonts()
print(f"Available fonts: {len(fonts)}")
for font in fonts[:10]:  # Show first 10
    print(f"  {font}")

# Check if a specific font exists
if "slant" in FigletFont.getFonts():
    print("Slant font is available")

Font Information

Retrieves detailed information about a specific font including metadata, character descriptions, and font properties.

@classmethod  
def infoFont(cls, font: str, short: bool = False) -> str:
    """
    Get information about a specific font.
    
    Parameters:
    - font (str): Font name to get information about
    - short (bool): If True, return only the first line of info
    
    Returns:
    str: Font information including metadata and description
    
    Raises:
    FontNotFound: If the specified font cannot be located
    """

Usage Example

from pyfiglet import FigletFont

# Get full font information
info = FigletFont.infoFont("standard")
print(info)

# Get short description only
short_info = FigletFont.infoFont("standard", short=True)
print(f"Font info: {short_info}")

# Info for multiple fonts
for font in ["big", "slant", "shadow"]:
    try:
        info = FigletFont.infoFont(font, short=True)
        print(f"{font}: {info}")
    except Exception as e:
        print(f"{font}: Error - {e}")

Font Installation

Installs new font files or font archives to the system for use with PyFiglet.

@staticmethod
def installFonts(file_name: str) -> None:
    """
    Install the specified font file to the system.
    
    Parameters:
    - file_name (str): Path to font file (.flf, .tlf) or ZIP archive
    
    Returns:
    None: Prints installation progress to stdout
    
    Installation locations:
    - Standard install: Package fonts directory  
    - Zipped package: SHARED_DIRECTORY
    
    Raises:
    FileNotFoundError: If the font file cannot be found
    PermissionError: If unable to write to installation directory
    """

Usage Example

from pyfiglet import FigletFont

# Install a single font file
FigletFont.installFonts("path/to/newfont.flf")

# Install fonts from ZIP archive
FigletFont.installFonts("path/to/font-collection.zip")

# The installation creates necessary directories automatically
# and extracts fonts from ZIP files preserving their names

Font Validation

Checks if a font file is valid FIGlet format before attempting to load it.

@classmethod
def isValidFont(cls, font: str) -> bool:
    """
    Check if a font file is valid FIGlet format.
    
    Parameters:
    - font (str): Font filename (with extension) to validate
    
    Returns:
    bool: True if font file is valid FIGlet format
    
    Validation checks:
    - File extension (.flf or .tlf)
    - FIGlet magic number in header
    - Supports ZIP archives (validates first file)
    """

Usage Example

from pyfiglet import FigletFont

# Validate font files
valid_fonts = []
test_files = ["standard.flf", "big.flf", "invalid.txt"]

for font_file in test_files:
    if FigletFont.isValidFont(font_file):
        valid_fonts.append(font_file)
        print(f"✓ {font_file} is valid")
    else:
        print(f"✗ {font_file} is invalid")

Font File Formats

PyFiglet supports multiple font formats:

  • .flf: Standard FIGlet Font format
  • .tlf: Transitional FIGlet Font format
  • .zip: ZIP archives containing font files

Font Locations

Fonts are searched in this order:

  1. Package fonts: Built-in fonts in pyfiglet.fonts package
  2. Shared directory: User-installed fonts in platform-specific location
    • Windows: %APPDATA%/pyfiglet
    • Unix/Linux: /usr/local/share/pyfiglet/

Font Installation Behavior

  • Creates target directories if they don't exist
  • ZIP files are extracted automatically
  • Existing fonts are overwritten
  • Installation progress is printed to stdout
  • Font names are derived from filenames (without extension)

Install with Tessl CLI

npx tessl i tessl/pypi-pyfiglet

docs

advanced-rendering.md

cli.md

color-support.md

font-management.md

index.md

string-manipulation.md

text-rendering.md

tile.json