Skip to content

Implement PCF font loading #32

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 15 commits into from
Dec 9, 2020
Merged

Implement PCF font loading #32

merged 15 commits into from
Dec 9, 2020

Conversation

jepler
Copy link
Contributor

@jepler jepler commented Dec 8, 2020

PCF is a binary font format historically used in the X11 system. It offers a smaller size for many font files, as well as improved random access to glyph data.

PCF fonts can be created from BDF fonts with bdftopcf, such as bdftopcf -o Arial16.pcf Arial16.bdf. bdf has many sub-formats. The format I selected is the default (on x86 / x64 systems). This is not quite the most compact format (it pads bitmap rows to a multiple of 32 bits) and it also doesn't match the preferred internal bitmap format of circuitpython. Adding support for other formats is possible.

About 50% of the time loading are in the bit-pushing loop,

                for k in range(width):
                    if buf[k >> 3] & (128 >> (k & 7)):
                        bitmap[start + k] = 1

which is the most optimized version I could devise. A future improvement to the core to allow setting multiple pixels from a buffer (bitmap.blit or slice assignment) could yield further improvements.

On magtag loading the yasashi24 font takes much less time, around 2s instead of 13s to load ASCII plus kana code points.

This also

  • improves the example program so that it can accept a specimen string in addition to a font file
  • adds ascent/descent properties to bdf font objects

jepler and others added 12 commits December 7, 2020 19:05
A pcf font can be generated from a bdf font using `bdftopcf` from debian/ubuntu package fonts-utils
This font was probably manually trimmed from one with a larger repertoire of code points.

This was fine, except that bdftopcf didn't like it.
This will be used by a future version of adafruit_display_text to avoid
needing to load glyphs from the font to guess these values.
@jepler jepler requested a review from ladyada December 8, 2020 17:28
@ladyada
Copy link
Member

ladyada commented Dec 8, 2020

this is working great for me, can merge on CI

@jepler jepler merged commit da4fa0b into adafruit:master Dec 9, 2020
adafruit-adabot added a commit to adafruit/Adafruit_CircuitPython_Bundle that referenced this pull request Dec 9, 2020
Updating https://github.com/adafruit/Adafruit_CircuitPython_SCD30 to 1.0.1 from 1.0.0:
  > fixed co2=> eCO2

Updating https://github.com/adafruit/Adafruit_CircuitPython_Bitmap_Font to 1.3.0 from 1.2.3:
  > Merge pull request adafruit/Adafruit_CircuitPython_Bitmap_Font#32 from jepler/pcf

Updating https://github.com/adafruit/Adafruit_CircuitPython_Bundle/circuitpython_library_list.md to NA from NA:
  > Added the following libraries: Adafruit_CircuitPython_SCD30
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.

2 participants