Skip to content

Added proportional bitmap font format support#9592

Closed
endreszabo wants to merge 11 commits into
python-pillow:mainfrom
endreszabo:yaff-font-format
Closed

Added proportional bitmap font format support#9592
endreszabo wants to merge 11 commits into
python-pillow:mainfrom
endreszabo:yaff-font-format

Conversation

@endreszabo

Copy link
Copy Markdown

This PR introduces support for YAFF proportional bitmap font support. Not only proportional, but YAFF is the ultimate bitmap font format that supersedes most popular formats. Unlike xkcd#927 this not a random 15th standard; this IS the standard to which all bitmap font should be converted to and used directly with Pillow. It is easily parsable for machines and human-friendly as you can edit the font files directly with your favorite text editor.

The following framebuffer has been created with Pillow, using the C64 font with manually added kerning pairs:

yaff-with-kerning

YAFF features include:

  • multiple-font container
  • Unicode with multi-codepoint sequences
  • Multi-byte character sets
  • Overlapping glyphs
  • Kerning
  • Vertical metrics
  • Greyscale fonts
  • Colour fonts

Out of these features only the kerning support has been implemented in this commit. In order to avoid introducing dependency on monobit, we wrote our YAFF format parser; with support for kerning.

Details on the YAFF format from the specs:

The yaff format has the following design aims:

  • Human-friendly. Truly human-readable and human-editable. For example, BDF and XML claim to be human-readable formats, but let's not kid ourselves. Human-friendly means plain text, flat, immediately visualised, easy on the eye, and light and obvious syntax. We should avoid duplication of information, unless it is of obvious use to a human user.
  • Able to represent fixed-width and proportional fonts.
  • Preserves comments, metadata and metrics. Formats such as BDF contain a wealth of metadata such as names, acknowledgements and style specification, but also font metrics that affect the way the font is displayed. The yaff format should preserve these.
  • Able to represent Unicode fonts as well as codepage fonts.

endreszabo and others added 2 commits April 28, 2026 14:35
Comment thread src/PIL/ImageFont.py Outdated
Comment thread src/PIL/ImageFont.py Outdated
@radarhere

Copy link
Copy Markdown
Member

Unlike xkcd#927 this not a random 15th standard; this IS the standard to which all bitmap font should be converted to and used directly with Pillow

As far as I can see, YAFF resides within monobit, which has 244 stars on GitHub, and is still in 'Beta' on PyPI.

Your claim seems a bit superlative, especially considering that https://github.com/robhagemans/monobit/blob/master/YAFF.md states

Does the world need yet another font format?
No. No, it doesn't.

I'm not saying that this shouldn't be a part of Pillow, but it would good to assess exactly how much use this feature would receive. Are there any articles you can link to demonstrating widespread acceptance?

What advantage do you see in embedding this support into Pillow directly, rather than, say, using monobit to convert a YAFF font into PCF or BDF, which Pillow already supports?

radarhere and others added 3 commits April 28, 2026 23:48
Co-authored-by: Andrew Murray <3112309+radarhere@users.noreply.github.com>
Co-authored-by: Andrew Murray <3112309+radarhere@users.noreply.github.com>
@endreszabo

endreszabo commented Apr 28, 2026

Copy link
Copy Markdown
Author

As far as I can see, YAFF resides within monobit, which has 244 stars on GitHub, and is still in 'Beta' on PyPI.

Your claim seems a bit superlative, especially considering that https://github.com/robhagemans/monobit/blob/master/YAFF.md states

Does the world need yet another font format?
No. No, it doesn't.

Yes, I am very enthusiastic as I spent years with Jimp + AngelCode BMFont to achieve the same (= my goal is to render a proportional bitmap font with kerning). And even with that, BMFont is basically PNG sprites, so you can't 'detach' the font rendering from the sprite images (no fill= for instance, you need to have a unique set of PNG files for each font color you'd need).

I'm not saying that this shouldn't be a part of Pillow, but it would good to assess exactly how much use this feature would receive. Are there any articles you can link to demonstrating widespread acceptance?

I have no evidence for widespread acceptance. This PR will certainly raise awareness of its existence.

What advantage do you see in embedding this support into Pillow directly, rather than, say, using monobit to convert a YAFF font into PCF or BDF, which Pillow already supports?

Immediate benefit is the proportional (variable width) glyph support (+kerning, which narrows the scope even further in the field of bitmap fonts) that BDF and PCF do not have.

@radarhere

Copy link
Copy Markdown
Member

Did you use AI to develop this?

@endreszabo

Copy link
Copy Markdown
Author

Did you use AI to develop this?

Yes, I was using Opus.

@radarhere radarhere added the 🤖-assisted AI-assisted label Apr 28, 2026
Comment thread src/PIL/YaffFontFile.py Outdated
Comment thread src/PIL/ImageFont.py Outdated
Comment thread src/PIL/ImageFont.py Outdated
@radarhere radarhere force-pushed the yaff-font-format branch 3 times, most recently from 0bc328e to 9453848 Compare June 18, 2026 13:18
@endreszabo

Copy link
Copy Markdown
Author

thank you @radarhere for your cooperation. Can I contribute more in any way?

@mergify

This comment was marked as outdated.

@hugovk

hugovk commented Jun 29, 2026

Copy link
Copy Markdown
Member

I don't think YAFF is quite suitable for including in Pillow right now, I think it needs a lot more adoption first before we commit to maintaining this "forever".

I'd suggest this could be a standalone package on PyPI first, and then when YAFF is more mature, we can reconsider. That will also allow this code to mature and support more YAFF features beyond kerning.

Thanks anyway for the suggestion!

@endreszabo

Copy link
Copy Markdown
Author

I don't think YAFF is quite suitable for including in Pillow right now, I think it needs a lot more adoption first before we commit to maintaining this "forever".

I'd suggest this could be a standalone package on PyPI first, and then when YAFF is more mature, we can reconsider. That will also allow this code to mature and support more YAFF features beyond kerning.

Thanks for you reply.

Is it theoretically possible to extract this PR into a standalone package on PyPI, which can then be used with the vanilla Pillow codebase? More specifically: is there an interface where I can specify which font rendering engine Pillow should use?

@radarhere

Copy link
Copy Markdown
Member

Sure. There's no reason why you couldn't have YaffImageFont in your own package, and then pass an instance as the font to the Pillow package's ImageDraw or ImageText.

@radarhere radarhere closed this Jul 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🤖-assisted AI-assisted

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants