https://github.com/nickscha/ttf_to_c89
converts a ttf font file to BMP and a C89 compatible header
https://github.com/nickscha/ttf_to_c89
bmp c89 font-atlas ttf-fonts
Last synced: about 1 month ago
JSON representation
converts a ttf font file to BMP and a C89 compatible header
- Host: GitHub
- URL: https://github.com/nickscha/ttf_to_c89
- Owner: nickscha
- License: mit
- Created: 2025-07-04T14:12:11.000Z (12 months ago)
- Default Branch: main
- Last Pushed: 2025-07-04T16:03:46.000Z (12 months ago)
- Last Synced: 2025-07-04T16:06:55.890Z (12 months ago)
- Topics: bmp, c89, font-atlas, ttf-fonts
- Language: Python
- Homepage:
- Size: 32.2 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# ttf_to_c89
A small python utility that converts a given ttf font file into a single row font atlas of all ASCII printable characters as a BMP and C89 header file.
## Quick Start
Install pillow package if not available and run the python file.
```sh
pip install pillow
python ttf_to_c89.py
```
Afterwards a font_atlas.bmp single row bitmap and a C89 compatible font.h file are generated.
A "Consolas" rendered font bitmap would look like this:
## Customization
Modify the "ttf_to_bmp_c89" call in the file and adjust the parameters as needed.
For a higher/smoother resolution try adjusting the pixel_height parameter since it can vary based on the ttf font.
Works best with monospaced fonts.
```python
if __name__ == "__main__":
ttf_to_c89(
font_path = "C:\\Windows\\Fonts\\consola.ttf", # Path to TTF Font file
pixel_height = 32, # Pixel height for each glyph
bmp_output = "font_atlas.bmp", # Bitmap output file
c_output = "font_data.h", # C89 single header output file
flip_y = True # If true Y axis is inverted for OpenGl/Vulkan compatibility
)
```
