Skip to content

Conversation

flowchartsman
Copy link

@flowchartsman flowchartsman commented Aug 8, 2025

I wanted to use a couple bitmap fonts in an e-paper project I was working on, and I noticed that unscii-8 was getting converted from TTF. That didn't seem right, when LVGL already has a perfectly good bitmap format already! Of course, when I did the initial pass, I discovered that the TTF is perfectly fine for the 8px font, and in fact generates identical glyphs to the pcf (as near as I could tell). This was dismaying, but I decided to press on with the 16px version and, to my surprise I realized the bundled version was just the 8px version scaled up, and I could actually use the native 16px version now! So I started trying out some other fonts and thought, what the heck, bpf isn't that much different, why not add that too? Around then the special casing was getting kind of messy and so I dusted off my (admittedly out of date) javascript and did a little refactor to make an abstract-class-style FontReader and, well, here we are.

image

For fun, I did a few more, and it seems to work well, though I had to walk a couple of them through otb/yaff with monobit

image

This might be fairly niche, and perhaps I got carried away with the refactoring, but perhaps also it is a good foundation for supporting other bitmap fonts (provided there are enough of them out there still that are worth writing a UI in).

There are some open questions about how to handle scaling (or not), and what to do about writing direction, both of which throw errors if they get confused at the moment, and I have not tried to integrate it into the UI at all, but I've tried to stay faithful to parsing the formats insofar as bitmaps fall out the other side in what appear to be the right configuration. It's certainly enough for my little project, and I'll probably rewrite it in a language I'm better at if it's too much to include here.

Let me know what you think!

Changes:

  • create FontReader "abstract class"
  • create BitmapFontReader class to share bitmap font functionality
  • create BDFReader/PCFReader to parset the two classic X11/Adobe bitmap font formats
  • migrate freetype/opentype to its own reader

- create  FontAdapter "abstract class"
- create BitmapFontAdapter class to share bitmap font functionality
- create BDFReader/PCFReader to parset the two classic X11/Adobe bitmap font formats
- migrate freetype/opentype to its own adapter
@flowchartsman flowchartsman marked this pull request as draft August 8, 2025 06:49
- The way this shook out, calling these FontReaders and squashing down the classes seems like a better abstraction
- No need to toss an error for the default impl.
- isPCFFont doesn't live here anymore; missed during refactor.
- comment tweak -- I suppose there could be other bitmap fonts in the future
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant