Fonts

Two type of fonts are supported by this driver fixed size bitmap fonts converted from PC Bios images using the font_from_romfont utility and fixed or proportional fonts converted from True-Type fonts using the font2bitmap utility.

The rom fonts are available in 128 and 256 PC character sets in 8x8, 8x16, 16x6 and 16x32 pixel sizes. They written using the text method.

The True-Type fonts can be converted to any size as long as the widest character is 256 pixels or less. They are written using the write method.

Pre-compiling the font files to .mpy files will significantly reduce the memory required for the fonts.

Rom Font Conversion

The utils directory contains the font_from_romfont.py program used to convert PC BIOS bitmap fonts from the font-bin directory of spacerace’s https://github.com/spacerace/romfont repo.

The utility converts all romfont bin files in the specified -input-directory (-i) and writes python font files to the specified -output-directory (-o).

Characters included can be limited by using the -first-char (-f) and -last-char (-l) options.

Example:

font_from_romfont -i font-bin -o fonts -f 32 -l 127

Example python font file.
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
"""converted from vga_8x8.bin """
WIDTH = 8
HEIGHT = 8
FIRST = 0x20
LAST = 0x7f
_FONT =\
b'\x00\x00\x00\x00\x00\x00\x00\x00'\
b'\x18\x3c\x3c\x18\x18\x00\x18\x00'\
b'\x66\x66\x24\x00\x00\x00\x00\x00'\

... many more lines of data...

b'\x70\x18\x18\x0e\x18\x18\x70\x00'\
b'\x76\xdc\x00\x00\x00\x00\x00\x00'\
b'\x00\x10\x38\x6c\xc6\xc6\xfe\x00'\

FONT = memoryview(_FONT)

True-Type Font Conversion

The utils directory contains the font2bitmap.py program used to convert True-Type font into bitmap font modules. Use the -h option to see details of the available options. The font2bitmap.py program uses font handling classes from Dan Bader blog post on using freetype http://dbader.org/blog/monochrome-font-rendering-with-freetype-and-python and the negative glyph.left fix from peterhinch’s font conversion program https://github.com/peterhinch/micropython-font-to-py.

The utility requires the python freetype module.

Example use:

  • ./font2bitmap NotoSans-Regular.ttf 32 -s “0123456789ABCEDF”

  • ./font2bitmap.py Chango-Regular.ttf 16 -c 0x20-0x7f

8x8 Rom Fonts

_images/vga1_8x8.png

vga1_8x8.py: 128 Character 8x8 Font


_images/vga2_8x8.png

vga2_8x8.py: 256 Character 8x8 Font


8x16 Rom Fonts

_images/vga1_8x16.png

vga1_8x16.py: 128 Character 8x16 Font


_images/vga2_8x16.png

vga2_8x16.py: 256 Character 8x16 Font


16x16 Rom Fonts

_images/vga1_16x16.png

vga1_16x16.py: 128 Character 16x16 Thin Font


_images/vga1_bold_16x16.png

vga1_bold_16x16.py: 128 Character 16x16 Bold Font


_images/vga2_16x16.png

vga2_16x16.py: 256 Character 16x16 Thin Font


_images/vga2_bold_16x16.png

vga2_bold_16x16.py: 256 Character 16x16 Bold Font


16x32 Rom Fonts

_images/vga1_16x32.png

vga1_16x32.py: 128 Character 16x32 Thin Font


_images/vga1_bold_16x32.png

vga1_bold_16x32.py: 128 Character 16x32 Bold Font


_images/vga2_16x32.png

vga2_16x32.py: 256 Character 16x32 Thin Font


_images/vga2_bold_16x32.png

vga2_bold_16x32.py: 256 Character 16x32 Bold Font