v.0.3.0 calculate char_width with shift operator

This commit is contained in:
tiijay
2025-10-23 14:31:09 +02:00
parent 2eea871408
commit a66b00989f
8 changed files with 377 additions and 182 deletions

View File

@@ -221,9 +221,9 @@ char_width = {
}
def get_char_width(char):
def get_char_width(char, default_witdth=5):
"""Get the display width of a character for proper spacing"""
return char_width.get(char, 5) # Default to 5 if character not found
return char_width.get(char, default_witdth) # Default to 5 if character not found
def get_text_width(text):

View File

@@ -6,6 +6,7 @@ from .font_16x16 import font_16x16
from ..emoji.emoji_5x7 import emoji_5x7
from ..emoji.emoji_8x8 import emoji_8x8
from ..emoji.emoji_16x16 import emoji_16x16
from ...utils.utils import number_to_bitarray_msb
fonts_meta_ = {
3: {'w': 3, 'h': 5},
@@ -34,3 +35,24 @@ def fonts_meta(font):
return fonts_meta_[16]
else:
return None
def char_width(char_matrix) -> int:
"""Berechnung der Bits für die Zeichenbreite
Args:
char_matrix (int): Zeichen als Array[int]
Returns:
int: Anzahl Bits für die Zeichenbreite
"""
max_val = max(char_matrix)
val = max_val
cw = 0
while 0xFFFFFFFF & val:
"""rechts shiften, bis alles Nullen da sind"""
val >>= 1
cw += 1
return cw