v.0.4.3 fonts_check jetzt über kompletten Fonts
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -68,21 +68,14 @@ class NeoPixel_64x64(NeoPixel):
|
||||
self.write()
|
||||
|
||||
def clear_row(self, row: int, effect: bool = False) -> None:
|
||||
"""
|
||||
"""löscht eine Zeile im Display entsprechend des eingestellten Fonts
|
||||
|
||||
Clear one row of the display (turn off all pixels)\n
|
||||
PRESUMING: font_5x7\n
|
||||
rows: range(0,3) [row-height: 8 pixels, row-length: MATRIX_WIDTH(64)]\n
|
||||
\n
|
||||
row-0: 0 - 511 (Pixel 0 bis Pixel 8 * MATRIX_WIDTH(64)-1)\n
|
||||
row-1: 512 - 1023\n
|
||||
row-2: 1024 - 1535\n
|
||||
row-3: 1536 - 2047\n
|
||||
etc. ...
|
||||
Args:
|
||||
row (int): in Pixel start bei 0 !!!
|
||||
effect (bool, optional): zeilenweise bzw. pixelweise löschen. Defaults to False.
|
||||
"""
|
||||
|
||||
start = row * 8 * self.MATRIX_WIDTH
|
||||
ende = start + 8 * self.MATRIX_WIDTH - 1
|
||||
start = row * self.MATRIX_WIDTH
|
||||
ende = start + self.font_height * self.MATRIX_WIDTH - 1
|
||||
|
||||
print(f'clear row: {row} --> pixels {start} to {ende}')
|
||||
for i in range(start, ende):
|
||||
|
||||
@@ -1,41 +1,35 @@
|
||||
from app.display.fonts.fonts_utils import align_font, font_height
|
||||
from app.display.fonts.fonts_utils import align_font, font_height, char_width, screen_text
|
||||
from app.display.neopixel_64x64 import NeoPixel_64x64
|
||||
import app.utils as utils
|
||||
from app.utils import colors
|
||||
|
||||
|
||||
def font_pretty(font):
|
||||
pretty_font = align_font(font)
|
||||
pretty_font = align_font(font, debug=False)
|
||||
print(pretty_font)
|
||||
|
||||
|
||||
def fonts_check(display, font, pretty=False) -> None:
|
||||
def fonts_check(display: NeoPixel_64x64, font, pretty=False) -> None:
|
||||
display.clear()
|
||||
display.set_font(font)
|
||||
|
||||
height = font_height(font)
|
||||
|
||||
alphabet: str = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
|
||||
char_line_1 = alphabet[:11]
|
||||
char_line_2 = alphabet[11:22]
|
||||
char_line_3 = alphabet[21:]
|
||||
num_line = '0123456789'
|
||||
alphanum: str = ''.join(sorted(font.keys()))
|
||||
|
||||
row = 0
|
||||
incr = height
|
||||
display.write_text(num_line, 0, row)
|
||||
row += incr
|
||||
display.write_text(char_line_1.upper(), 0, row, utils.colors.YELLOW)
|
||||
# row += incr
|
||||
# display.write_text(char_line_2.upper(), 0, row, colors.YELLOW)
|
||||
# row += incr
|
||||
# display.write_text(char_line_3.upper(), 0, row, colors.YELLOW)
|
||||
row += incr
|
||||
display.write_text(char_line_1.lower(), 0, row, utils.colors.YELLOW)
|
||||
# row += incr
|
||||
# display.write_text(char_line_2.lower(), 0, row, colors.YELLOW)
|
||||
# row += incr
|
||||
# display.write_text(char_line_3.lower(), 0, row, colors.YELLOW)
|
||||
row += incr
|
||||
display.write_text('!.,:;\'"-_+=*/\\()~°•', 0, row, utils.colors.ORANGE)
|
||||
text_left = alphanum
|
||||
while text_left:
|
||||
# Text entsprechend des Display splitten
|
||||
scr_txt_dict = screen_text(text=text_left, screen_width=display.MATRIX_WIDTH, screen_height=display.MATRIX_HEIGHT, font=font)
|
||||
print(f'scr_txt: {scr_txt_dict}')
|
||||
|
||||
display.clear()
|
||||
for idx, row_text in enumerate(scr_txt_dict['visible']):
|
||||
ypos = height * idx
|
||||
# display.clear_row(ypos)
|
||||
display.write_text(row_text, 0, ypos, colors.RAINBOW[idx])
|
||||
|
||||
text_left = scr_txt_dict['invisible']
|
||||
|
||||
if pretty:
|
||||
font_pretty(font)
|
||||
|
||||
Reference in New Issue
Block a user