https://github.com/hyx0329/circuitpython-better-pcf-font-loader
Maybe a better PCF font loader for CircuitPython, support different glyph padding schemes
https://github.com/hyx0329/circuitpython-better-pcf-font-loader
circuitpython font
Last synced: about 1 month ago
JSON representation
Maybe a better PCF font loader for CircuitPython, support different glyph padding schemes
- Host: GitHub
- URL: https://github.com/hyx0329/circuitpython-better-pcf-font-loader
- Owner: hyx0329
- License: unlicense
- Created: 2024-09-06T11:16:09.000Z (over 1 year ago)
- Default Branch: dev
- Last Pushed: 2024-09-07T06:19:22.000Z (over 1 year ago)
- Last Synced: 2025-05-30T17:43:22.570Z (about 1 year ago)
- Topics: circuitpython, font
- Language: Python
- Homepage:
- Size: 5.86 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# A better PCF font loader for CircuitPython
PCF is abbreviation for X11 Portable Compiled Font.
There's [Adafruit_CircuitPython_Bitmap_Font](https://github.com/adafruit/Adafruit_CircuitPython_Bitmap_Font) but it does not support glyphs that padded to bytes & chars(2 bytes) and the code is a bit confusing.
Pros:
- cleaner code(I think)
- limited glyph cache
- useful for fonts with numerous code points(like CJK fonts) so memory won't be exhausted by cache
- support different glyph paddings
- thus font file can be smaller
- faster(batch load) than Adafruit_CircuitPython_Bitmap_Font
- 158ms VS 242ms when loading 72 unique CJK characters
- 173ms VS 341ms when loading 72 unique/125 total CJK characters
- tested on RP2040, both use the same PCF font, *YMMV though*
Cons:
- only PCF is supported
- may not work on some older CircuitPython
- needs `bitmaptools.readinto`
- consumes __more__ RAM, possibly
- about(less than) 1KB with default configuration
- maybe neglectable for CircuitPython
Example:
```python
import board
from adafruit_display_text import label
from pcf_font import PcfFont
# replace with your own font
font = PcfFont("fonts/fusion-pixel-12px-proportional-zh_hans.pcf")
text = "世界,你好!World, hello!"
text_area = label.Label(font, text=text)
text_area.x = 10
text_area.y = 10
board.DISPLAY.root_group = text_area
```
It's designed to be API compatible, and can replace Adafruit_CircuitPython_Bitmap_Font if only PCF is used.
## License
This project is released under [Unlicense](https://unlicense.org/).