A Python utility that generates bitmap fonts compatible with Garmin devices using Google Fonts. This tool analyzes character pixel data to create optimally-spaced bitmap fonts with proper character boundaries.
- Downloads fonts from Google Fonts API
- Generates bitmap fonts in multiple resolutions (454x454, 416x416, 390x390, 360x360)
- Supports different font styles (regular, bold, italic, bolditalic)
- Optimized character spacing using pixel analysis
- Generates all required files for Garmin font implementation
- Interactive font style selection
- Progress visualization
- Error handling and user feedback
- Python 3.6 or higher
- Required Python packages:
pip install Pillow requests rich numpy
project/
├── config.py # Configuration constants
├── utils.py # Utility functions
├── font_manager.py # Font download and selection
├── bitmap_generator.py # Main bitmap generation logic
├── generate.py # Entry point
├── requirements.txt # Python dependencies
├── apikey.txt # Google Fonts API key
└── char.txt # Characters to include in the font
-
Create a
char.txt
file with the characters you want to include:0123456789:ABCDEFGHIJKLM.,-
-
Get a Google Fonts API key:
- Go to Google Cloud Console
- Create a new project or select an existing one
- Enable the Google Fonts API
- Go to "APIs & Services" > "Credentials"
- Create an API key
- Save the key in
apikey.txt
-
Install dependencies:
pip install -r requirements.txt
Basic command:
python generate.py "Font Name" font_size
Examples:
# Generate Roboto font with size 71
python generate.py "Roboto" 71
# Generate Open Sans font with size 53
python generate.py "Open Sans" 53
The tool generates the following files for each resolution:
output/
├── resources-454x454/
│ ├── FontName_style.png # Bitmap font image
│ ├── FontName_style.fnt # Font metrics file
│ └── fonts.xml # Garmin font configuration
├── resources-416x416/
│ └── ...
├── resources-390x390/
│ └── ...
└── resources-360x360/
└── ...
-
.png
file:- Black background with white characters
- Optimally spaced characters
- No extra padding or margins
-
.fnt
file:- Contains font metrics and character mapping
- Includes character positions and dimensions
- Specifies font properties and settings
-
fonts.xml
:- Garmin-specific font configuration
- References the font files
- Sets font properties like antialiasing
- Copy the generated resources to your Garmin project's resources directory
- Use the appropriate resolution folder for your target device
- Reference the font in your layouts:
<font id="CustomFont" filename="FontName_style.fnt" />
The tool includes comprehensive error handling for:
- Missing or invalid API key
- Network connectivity issues
- Font download failures
- Invalid font names or styles
- Character rendering issues
- File system operations
- Use appropriate font sizes for your target devices
- Include only necessary characters to minimize file size
- Test the generated fonts on target devices
- Keep the generated files in your version control
- Document font usage in your Garmin project
- Maximum texture size depends on target device specifications
- Characters must be defined in advance via char.txt
- Some fonts might not support all styles
Feel free to open issues or submit pull requests for:
- Bug fixes
- Feature improvements
- Documentation updates
- New features
This project is licensed under the MIT License - see the LICENSE file for details.
- Google Fonts API for providing the font library
- PIL (Python Imaging Library) for image processing
- Rich library for beautiful console output