v.0.4.3 fonts_check jetzt über kompletten Fonts

This commit is contained in:
tiijay
2025-10-24 17:33:03 +02:00
parent 37d5276537
commit 3c30018893
3 changed files with 74 additions and 40 deletions

View File

@@ -84,17 +84,64 @@ def shift_letter_right(char, letter, debug=False) -> bool:
return shifted
def align_font(font):
def align_font(font, debug=False):
chars = [char for char in font]
print(chars)
# Print the dictionary
print('font_pretty = {')
for char in sorted(font.keys()):
shifted = shift_letter_right(char=char, letter=font[char])
shifted = shift_letter_right(char=char, letter=font[char], debug=debug)
hex_values = [f'0x{val:02X}' for val in shifted]
print(f"\t'{char}': [{', '.join(hex_values)}],")
print('}')
# return f'#keys: {len(list(font.keys()))}'
return f'#keys: {len(font)}'
def screen_text(text: str, font, screen_height: int, screen_width: int):
"""Text für einen Screen anpassen,
Anzahl der Zeichen je Zeile begrenzen,
ebenso wird die Höhe des Screen brücksichtigt
Args:
text (str): Text der ausgegeben werden soll
font: Berechnungen für den Font
height (int): Pixel
width (int): Pixel
"""
def text_per_row(txt):
pixs = 0
visible_text = ''
for a in txt:
pixs += char_width(font[a]) + 1
if pixs > screen_width:
# Zeilenende erreicht
break
visible_text += a
return visible_text
f_height: int = font_height(font)
# Ganzzahl Division
max_visible_rows = screen_height // f_height
print(f'rows_visible: {max_visible_rows}')
text_left = text
scn_txt = []
for _ in range(max_visible_rows):
visible_text = text_per_row(text_left)
visible_text_len = len(visible_text)
text_left = text_left[visible_text_len:]
scn_txt.append(visible_text)
if not text_left:
break
scr_txt_dict = {'visible': scn_txt, 'invisible': text_left}
return scr_txt_dict