6. Fonts

6.1. Bitmap Fonts

The Micropython firmware image provided includes 12 bitmap fonts converted from pc bios text mode fonts for use with the tftui module. The fonts are encoded as frozen byte code and can be imported and used directly from flash to conserve RAM.


6.1.1. Font file format

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)

6.1.2. Bitmap Font Tables


6.1.2.1. vga1_8x8

_images/vga1_8x8.jpg

6.1.2.2. vga2_8x8

_images/vga2_8x8.jpg

6.1.2.3. vga1_8x16

_images/vga1_8x16.jpg

6.1.2.4. vga2_8x16

_images/vga2_8x16.jpg

6.1.2.5. vga1_16x16

_images/vga1_16x16.jpg

6.1.2.6. vga2_16x16

_images/vga2_16x16.jpg

6.1.2.7. vga1_bold_16x16

_images/vga1_bold_16x16.jpg

6.1.2.8. vga2_bold_16x16

_images/vga2_bold_16x16.jpg

6.1.2.9. vga1_16x32

_images/vga1_16x32.jpg

6.1.2.10. vga2_16x32

_images/vga2_16x32.jpg

6.1.2.11. vga1_bold_16x32

_images/vga1_bold_16x32.jpg

6.1.2.12. vga2_bold_16x32

_images/vga2_bold_16x32.jpg

6.2. Vector Fonts

6.2.1. Introduction

The TurtlePlotBot uses the public domain Hershey Fonts fonts distributed on the USENET network. The Hershey Fonts were originally created by Dr. A. V. Hershey while working at the U. S. National Bureau of Standards.

Note

The format of the Font data in this distribution was originally created by:

James Hurt
Cognition, Inc.
900 Technology Park Drive
Billerica, MA 01821
(mit-eddie!ci-dandelion!hurt)

The fonts range from simple to complex and include many symbols. The standard TurtlePlotBot does not have the movement accuracy to make all of the fonts practical. The more complex the font or the longer the message the more the movement errors will distort the text drawn.

6.2.2. Font file format

You do not have to understand the font file format in order to use the fonts in TurtlePlotBot programs the library takes care of the details with the write function.

The font files begin with a 8 bit byte containing the number of characters in the front followed by a sequence of (little endian) 16 bit unsigned integers containing the file offset to the coordinate data for each of the characters in the font file. Fonts with 96 characters are in ASCII order for characters 0x20 though 0x7f. Other fonts have characters starting at 0x00.

The first byte of the coordinate data contains the number of x,y coordinates for the glyph. The second and third byte contain the coordinates for the left and right limits of the glyph. The following pairs of bytes are the x and y coordinates that make glyph. Like the original Hershey data each byte is offset by 0x52 (ascii ‘R’). A value of -50 for the x coordinate is used to indicate the pen should be raised for the next move.

6.2.3. LCD Font Demo

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
'''
scroll_fonts.py - Scroll Hershey fonts on display
'''

#pylint: disable-msg=import-error
import uos
import button
import vga2_bold_16x16 as font
import tftui

def main(ui):
    """
    Main routine
    """
    fonts = [font for font in uos.listdir('/fonts') if font.endswith('.fnt')]
    font_count = len(fonts)
    font_current = 0
    message="Hello!"
    again = True
    joystick = button.JoyStick()

    while again:
        ui.cls(fonts[font_current], 0)

        font = '/fonts/' + fonts[font_current]
        column = ui.width//2 - ui.size(message, scale=1, font=font)//2
        line = ui.height//2 - 16

        ui.draw(message, column, line, scale=1, font=font)

        ui.center('Up-Prev Dn-Next', 6)
        ui.center('other-exit', 7)
        btn = button.JoyStick().read()

        if btn == button.DOWN:
            font_current -= 1
            font_current %= font_count

        elif btn == button.UP:
            font_current += 1
            font_current %= font_count

        again = btn in [button.UP, button.DOWN]

main(tftui.UI(font))

__import__("menu")      # return to turtleplotbot menu

6.2.4. Vector Font Tables

6.2.4.1. astrol.fnt

_images/astrol.svg

6.2.4.2. cyrilc.fnt

_images/cyrilc.svg

6.2.4.3. gotheng.fnt

_images/gotheng.svg

6.2.4.4. gothger.fnt

_images/gothger.svg

6.2.4.5. gothita.fnt

_images/gothita.svg

6.2.4.6. greekc.fnt

_images/greekc.svg

6.2.4.7. greekcs.fnt

_images/greekcs.svg

6.2.4.8. greekp.fnt

_images/greekp.svg

6.2.4.9. greeks.fnt

_images/greeks.svg

6.2.4.10. italicc.fnt

_images/italicc.svg

6.2.4.11. italiccs.fnt

_images/italiccs.svg

6.2.4.12. italict.fnt

_images/italict.svg

6.2.4.13. japan.fnt

_images/japan.svg

6.2.4.14. lowmat.fnt

_images/lowmat.svg

6.2.4.15. marker.fnt

_images/marker.svg

6.2.4.16. meteo.fnt

_images/meteo.svg

6.2.4.17. misc.fnt

_images/misc.svg

6.2.4.18. music.fnt

_images/music.svg

6.2.4.19. romanc.fnt

_images/romanc.svg

6.2.4.20. romancs.fnt

_images/romancs.svg

6.2.4.21. romand.fnt

_images/romand.svg

6.2.4.22. romanp.fnt

_images/romanp.svg

6.2.4.23. romans.fnt

_images/romans.svg

6.2.4.24. romant.fnt

_images/romant.svg

6.2.4.25. scriptc.fnt

_images/scriptc.svg

6.2.4.26. scripts.fnt

_images/scripts.svg

6.2.4.27. symbol.fnt

_images/symbol.svg

6.2.4.28. uppmat.fnt

_images/uppmat.svg