Skip to content

projectitis/packedbdf

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

packedbdf

Packed BDF font helpers and code

Packed BDF is a compact binary format of BDF. packedbdf_t or ILI9341_t3_font_t is one of the font formats used when programming the Teensy USB-based microcontroller development boards. Version 1 of the format packs glyph pixels as individual bits. It does not support anti-aliasing, but it allows maximum efficiency of data, especially for smaller fonts. Version 23 (numbered for BDF v2.3) extends the format to allow for 4, 16 and 256 levels of anti-aliasing (2, 4 and 8 bits respectively).

Libraries that currently support Packed BDF are:

There are two steps to creating a Packed BDF file. These are detailed below:

  • Download the font as TrueType or OpenType font (ttf or otf)
  • Create the BDF font using Font Forge
  • Convert the BDF file to a header file

BDF

From Wikipedia: The Glyph Bitmap Distribution Format (BDF) by Adobe is a file format for storing bitmap fonts. The content takes the form of a text file intended to be human- and computer-readable. BDF is typically used in Unix X Window environments. It has largely been replaced by the PCF font format which is somewhat more efficient, and by scalable fonts such as OpenType and TrueType fonts.

1 of 3: Download the fonts you want to convert

If you don't already have the fonts you want, Google Fonts is a fantastic source. It's up to you to make sure that the licence for the font allows for what you are going to use it for. The OFL (Open-Font Licence) is recommended, as it's the most permissive.

2 of 3: Create BDF files using Font Forge

These instructions are for how to create BDF files using the Font Forge open source font editor. Font Forge is free and has downloads for Windows, Mac and Linux.

  1. Download and install Font Forge
  2. Launch Font Forge and open the font file (ttf or otf)
  3. Select all the glyphs that you want in your font - usually 32 to 126 (inclusive)
  4. Edit > Select > Invert the selection (to select the glyphs you don't want to keep), and
  5. Encoding > Detach and remove Glyphs to remove them from the font
  6. Then select Encoding > Compact to reduce the character set

The next few steps will generate the bitmaps/pixel versions of each glyph in the sizes that you need:

  1. Element > Bitmap strikes available launches the dialog to generate the bitmap versions
  2. Enter the sizes that you need, seperated by commas. These can be specified as point sizes or pixel sizes (in different text boxes)
    • For non anti-alias fonts (v1), simply enter the font sizes. E.g. "8,9,10,12,16"
    • For anti-alias fonts (v23), enter the font sizes, each followed by '@' and then the number of bits per pixel. E,g, 8@4,9@4,10@4,12@4
    • Use @2 for 4 levels of anti-alias, @4 for 16 levels, and @8 for 255
    • The resulting font is much bigger the higher you go. In practice I've found that @2 actually gives very decent results
    • The settings that work best for me (even though I use PC) are "Mac" and "72dpi"
    • I tend to use this set, in points, at 72dpi: 7@2,8@2,9@2,10@2,11@2,12@2,14@2,16@2,18@2,20@2,24@2,28@2,32@2
    • 7pt is very small (almost unreadable). Anything larger than 32 is almost too large for the display.
  3. Click [OK] to generate the bitmap strikes of each glyph in various sizes
  4. Use View > ## pixel bitmap options to view the bitmap strikes that were generated
  5. Any glyphs that aren't perfect can be edited individually before saving
  6. Finally, select File > Generate Fonts
    • Select "No outline font" (for Outline font) and "BDF" (for Bitmap font), then hit [Generate].
    • Enter 72dpi as the screen resolution (also see step 7). This ensures that the font sizes are correct inside the files.
  7. A seperate BDF file for each size will be generated.

3 of 3: Convert the BDF files to Packed BDF

There are two python scripts to convert the BDF files to packed BDF format. The python scripts are based on bdf_to_ili9341.c by Paul Stoffregen.

  1. If you haven't already, install Python on your system
  2. Put the .py scripts in the same folder as your BDF font files
  3. Now double-click either of these two files, depending on what you want:
    • bdf_to_h.py - this will create a seperate .h file for each BDF file
    • bdf_to_h_combined.py - all BDF fonts with the same name combined into the same .h file (with multiple sizes)

Error: packedbdf_t unrecognised

If your compiled throws an error about not recognising packedbdf_t, add this to your code (usually immediately following the definition of ILI9341_t3_font_t: typedef ILI9341_t3_font_t packedbdf_t;

About

Packed BDF font helpers and code

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 3

  •  
  •  
  •