fonts.py

../_images/fonts.jpg

Test text_font_converter.py

Pages through all characters of four fonts on the Display. https://www.youtube.com/watch?v=2cnAhEucPD4

Note

This example requires the following modules:

  • st7789py

  • tft_config

  • vga2_8x8

  • vga2_8x16

  • vga2_bold_16x16

  • vga2_bold_16x32

 1"""
 2fonts.py
 3========
 4
 5.. figure:: ../_static/fonts.jpg
 6    :align: center
 7
 8    Test text_font_converter.py
 9
10Pages through all characters of four fonts on the Display.
11https://www.youtube.com/watch?v=2cnAhEucPD4
12
13.. note:: This example requires the following modules:
14
15  .. hlist::
16    :columns: 3
17
18    - `st7789py`
19    - `tft_config`
20    - `vga2_8x8`
21    - `vga2_8x16`
22    - `vga2_bold_16x16`
23    - `vga2_bold_16x32`
24
25"""
26
27import utime
28import st7789py as st7789
29import tft_config
30import vga2_8x8 as font1
31import vga2_8x16 as font2
32import vga2_bold_16x16 as font3
33import vga2_bold_16x32 as font4
34
35
36def main():
37    tft = tft_config.config(tft_config.WIDE)
38    tft.vscrdef(40, 240, 40)
39
40    while True:
41        for font in (font1, font2, font3, font4):
42            tft.fill(st7789.BLUE)
43            line = 0
44            col = 0
45
46            for char in range(font.FIRST, font.LAST):
47                tft.text(font, chr(char), col, line, st7789.WHITE, st7789.BLUE)
48                col += font.WIDTH
49                if col > tft.width - font.WIDTH:
50                    col = 0
51                    line += font.HEIGHT
52
53                    if line > tft.height-font.HEIGHT:
54                        utime.sleep(3)
55                        tft.fill(st7789.BLUE)
56                        line = 0
57                        col = 0
58
59            utime.sleep(3)
60
61
62main()