-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathfont_list.py
67 lines (51 loc) · 2 KB
/
font_list.py
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# SPDX-FileCopyrightText: 2024 Brad Barnett
#
# SPDX-License-Identifier: MIT
"""
This script gathers font files from a specified directory and displays them on a display driver.
It uses the Font class to load and render the fonts.
The font files should have a naming convention of "fontname_WxH.bin", where W is the width and H is the height of the font.
The script iterates through the font files, creates a framebuffer, and renders the font on it.
The rendered font is then displayed on the display driver.
"""
from board_config import display_drv
from graphics import Font, FrameBuffer, RGB565
import os
EXPORT = False # Set to True to export the font to a .py file
display_drv.fill(0)
y_pos = 0
def main():
global y_pos
# Specify the directory containing the .bin files
directory = "examples/assets/"
def gather_font_files(directory):
font_files = []
for file in os.listdir(directory):
if file.endswith(".bin"):
file_path = "/".join([directory, file])
font_files.append(file_path)
return font_files
font_files = gather_font_files(directory)
bg_color = 0
fg_color = 0x07E0
scale = 1
for font_file in font_files:
try:
font = Font(font_file)
except RuntimeError as e:
print(e)
continue
if EXPORT:
font.export(font.font_data.replace(".bin", ".py"))
height = font.height
font_name = font.font_name
buffer = bytearray(display_drv.width * height * 2)
fb = FrameBuffer(buffer, display_drv.width, height, RGB565)
fb.fill(bg_color)
string = "".join([chr(i) for i in range(65, 91)]) + ": " + font_name.split("/")[-1]
font.text(fb, string, 0, 0, fg_color, scale)
display_drv.blit_rect(buffer, 0, y_pos % display_drv.height, display_drv.width, height)
y_pos += height
if y_pos > display_drv.height:
display_drv.vscsad((y_pos - display_drv.height) % display_drv.height)
main()