Fontknife
Rasterize only the glyphs you need. Cut out everything else.
Warning: This is alpha-quality software. It is full of bugs and may change drastically!
Current features:
- Read multiple font formats (TTF, BDF, PCF, 1-bit Sprite sheets)
- Export 1-bit sprite sheets to multiple image formats (PNG, BMP, JPG)
- Guess common formats from file extensions
- Simpler than GUI font editors
- Can be used as a library in custom Python scripts
- Code generation (Partial support for Octo)
See the end of this file for planned features.
How do I install it?
Requirements
- Python 3.7+
- Enough disk space to install pillow and its dependencies
- The ability to create virtual environments or use pipx
Installation
Create a virtual environment and run the following:
pip install fontknife
You can use pipx instead if you'd like.
If you want to use fontknife as a dependency in your projects, be sure to pin a specific version. Breaking changes are almost guaranteed in the future.
What does it do?
1. Convert Fonts to Sprite Sheets
Tom thumb is a public domain pixel font with a common problem: it's shipped in a format most GUI and game frameworks do not support.
This tool fixes that instantly:
fontknife convert tom-thumb.bdf tom_thumb.png
Use your preferred image editor to upscale & adjust the resulting sprite sheet.
Note: Reading the glyph table for TTF fonts is not yet supported. Unless otherwise specified, they will be assumed to provide English-focused glyphs. See the next example for information on how to select specific glyphs.
2. Export Specific Glyphs / Make Game Assets
Imagine you're making a farming game. You need filler assets ASAP.
Use this tool with a Noto Emoji Font variant to rapidly generate filler assets:
fontknife convert -P 48 -G "🌽🍇🍎🍏🫐🍓🍒🍐🍅🥕🥔🥒🍑🥑🧅🍈" NotoEmoji-Regular.ttf fruits_and_veggies.png
If you need more color, the outlines created by the command above should be easy to improve upon with a paint bucket tool in your preferred image editor.
Explanation of Flags
| Flag | Long version | Meaning |
|---|---|---|
-P |
--src-font-size-points |
A point size to render a TTF at. Ignored for non-TTF fonts. |
-G |
--src-glyph-sequence |
The glyphs to use and the order to render them in. |
Note: Although multi-codepoint emoji ( ⛈️ , country and region flags, etc) are not yet supported, adding support is a high priority due to their usefulness for asset generation and LCD hardware projects.
3. Export Fonts to Octo Code
Warning: This feature is legacy code inherited from an earlier project! Do not rely on the drawing routines it outputs, only the tables!
You can generate a width table and sprite data table as valid Octo source your font meets the following requirements:
- All glyphs render as 8px x 8px or smaller
- There are 256 or fewer glyphs in the font
For example, run the following to generate tables of widths and sprite data for Tom thumb as Octo source:
fontknife emit-code tom-thumb.bdf tom-thumb.8o
You should ignore the prefixed drawing routines in the output. Although this
command's implementation was refactored to increase readability, the underlying
logic is still from before
Octo's :stringmode macro
was added. Updating this is on the todo list. See the end of this file for more
information.
Why did you make this?
tl;dr It helps developers iterate faster
If you want a longer history:
- I made a PR for a project
- After checking back over a year later, I forked the project to start an incremental rewrite
- Bitmap fonts were repeatedly brought up as a potential future feature for two projects I contribute to, pyglet and arcade
- I started reading up on bitmap fonts to learn more
- It became painfully clear that finding and importing assets would become even more of a friction point if that feature was added
- Format conversion proved to be more useful and interesting to solve than Octo support
The project began shifting focus and gaining inertia at roughly item 4. I've been using the project as an opportunity to applying new techniques and Python features I've learned about when appropriate.
When will you add X?
When I have time or if I merge a PR.
Features I'd like to add, roughly in order of descending priority:
- Export with a transparent background color
- Upscaling flags to apply during rasterization and after sprite sheet creation
- Image folder export format, 1 glyph per file
- Support for automatically reading TTF glyph tables
- Multi-codepoint emoji (examples: ⛈️ , 🌶️, country/region flags)
- Fix ugly caching behavior
- Regex-like expressions for glyph selection
- C header code generation
- Refactor Octo generation
- Additional font formats, both old (FNT, etc) and new (UXF, etc).
- Additional color support
- Color TTF support
Metadata
Release files for fontknife 0.1.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| fontknife-0.1.2.tar.gz | 52.9 kB | Without provenance | Details for fontknife-0.1.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| fontknife-0.1.2-py3-none-any.whl | Python 3 | none | any | Details for fontknife-0.1.2-py3-none-any.whl |
Total release size: 113.6 kB
Release files / fontknife-0.1.2.tar.gz
| Download URL | fontknife-0.1.2.tar.gz |
|---|---|
| Size | 52.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
5e3b51d031247a01a30b2876c7f21583b749f5c8ecd2a500337db626a6c2932a
|
|
BLAKE2b-256 checksum How to use checksums |
016bda738e62f6e65c1f57d539c08e2bb7bef81657c1889692407f997a601fa4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.1 CPython/3.9.2
|
Release files / fontknife-0.1.2-py3-none-any.whl
| Download URL | fontknife-0.1.2-py3-none-any.whl |
|---|---|
| Size | 60.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
f994b605a162e11fd2ba28526a056da34783a44d7bbd48853c8b6cd1390754c9
|
|
BLAKE2b-256 checksum How to use checksums |
5aeaeb2816781c0d94ecdcbe238dd90051bf1bef54c63e7eb12249ed9dd14382
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.1 CPython/3.9.2
|
Security for fontknife 0.1.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.