Documentation Index
Fetch the complete documentation index at: https://mintlify.com/originalankur/maptoposter/llms.txt
Use this file to discover all available pages before exploring further.
Overview
The font management module handles font loading from both local files and Google Fonts API, with automatic caching to minimize network requests.load_fonts()
Load fonts from local directory or download from Google Fonts.Google Fonts family name (e.g., “Noto Sans JP”, “Open Sans”, “Playfair Display”)If None or “roboto”, uses local Roboto fonts from the fonts/ directory.
Dictionary with keys:
"bold": Path to bold weight font file"regular": Path to regular weight font file"light": Path to light weight font file
Behavior
- Custom Google Font: If
font_familyis specified and not “roboto”, attempts to download from Google Fonts - Fallback to Local: If download fails, falls back to local Roboto fonts
- Default: If
font_familyis None, loads local Roboto fonts directly - Validation: Verifies that all font files exist before returning
Example Usage
download_google_font()
Download a font family from Google Fonts and cache it locally.Google Fonts family name (e.g., “Noto Sans JP”, “Open Sans”)Must exactly match the font family name as it appears on Google Fonts.
List of font weights to download:
- 300 = Light
- 400 = Regular
- 700 = Bold
Dictionary with ‘light’, ‘regular’, ‘bold’ keys mapping to font file paths.Returns None if download fails.
Download Process
- Cache Check: Checks if fonts are already cached in
fonts/cache/ - API Request: Fetches font CSS from Google Fonts API
- URL Extraction: Parses CSS to extract weight-specific font URLs
- File Download: Downloads WOFF2 or TTF files for each weight
- Weight Mapping: Maps downloaded weights to ‘light’, ‘regular’, ‘bold’ keys
- Fallback Handling: Uses closest available weight if exact weight unavailable
Caching
Downloaded fonts are cached in:fonts/cache/noto_sans_jp_bold.woff2fonts/cache/open_sans_regular.woff2fonts/cache/playfair_display_light.ttf
Error Handling
Font File Formats
Supported Formats
WOFF2
Preferred format from Google Fonts
- Better compression (30% smaller than TTF)
- Faster loading
- Modern browsers only
TTF
Fallback format
- Universal compatibility
- Larger file size
- Works everywhere
Local Font Structure
Default Roboto Fonts
Local Roboto fonts must be located at:Adding Custom Local Fonts
To use custom local fonts without Google Fonts:- Place font files in
fonts/directory - Modify
load_fonts()function to reference your files:
Command Line Usage
You can specify custom fonts when generating posters:Font family names are case-sensitive and must match exactly as they appear on Google Fonts.
Constants
FONTS_DIR
Directory for local font files.FONTS_CACHE_DIR
Directory for cached Google Fonts downloads.Font Recommendations
For Latin Scripts
- Roboto (default) - Clean, modern sans-serif
- Open Sans - Friendly, readable
- Montserrat - Geometric, elegant
- Playfair Display - Classic serif for sophisticated look
- Raleway - Elegant sans-serif with personality
For Non-Latin Scripts
- Noto Sans JP - Japanese
- Noto Sans KR - Korean
- Noto Sans SC - Simplified Chinese
- Noto Sans TC - Traditional Chinese
- Noto Sans Thai - Thai
- Noto Sans Arabic - Arabic
Rate Limiting
Thedownload_google_font() function includes:
- 10-second timeout for HTTP requests
- Automatic retry handling
- Respectful delays between requests
Troubleshooting
Font Not Found
Local Fonts Missing
fonts/Roboto-*.ttf files exist.