v.0.3.1 font 3x5 pretty
This commit is contained in:
@@ -1,40 +1,4 @@
|
||||
from .font_3x5 import font_3x5
|
||||
from .font_5x7 import font_5x7
|
||||
from .font_5x7_opt import font_5x7 as font_5x7_opt
|
||||
from .font_8x8 import font_8x8
|
||||
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},
|
||||
5: {'w': 5, 'h': 7},
|
||||
8: {'w': 8, 'h': 8},
|
||||
16: {'w': 16, 'h': 16},
|
||||
}
|
||||
|
||||
|
||||
def fonts_meta(font):
|
||||
if font == font_3x5:
|
||||
return fonts_meta_[3]
|
||||
elif font == font_5x7:
|
||||
return fonts_meta_[5]
|
||||
elif font == font_5x7_opt:
|
||||
return fonts_meta_[5]
|
||||
elif font == font_8x8:
|
||||
return fonts_meta_[8]
|
||||
elif font == font_16x16:
|
||||
return fonts_meta_[16]
|
||||
elif font == emoji_5x7:
|
||||
return fonts_meta_[5]
|
||||
elif font == emoji_8x8:
|
||||
return fonts_meta_[8]
|
||||
elif font == emoji_16x16:
|
||||
return fonts_meta_[16]
|
||||
else:
|
||||
return None
|
||||
import app.utils.utils as utils
|
||||
|
||||
|
||||
def char_width(char_matrix) -> int:
|
||||
@@ -56,3 +20,66 @@ def char_width(char_matrix) -> int:
|
||||
cw += 1
|
||||
|
||||
return cw
|
||||
|
||||
|
||||
def shift_letter_right(char, letter, debug=False) -> bool:
|
||||
"""Prüfe ob das Zeichen auch komplett nach rechts gezogen ist
|
||||
|
||||
Args:
|
||||
letter (_type_): Array[0..nBytes]
|
||||
|
||||
Returns:
|
||||
bool: _description_
|
||||
"""
|
||||
|
||||
def isLetterRight(letter):
|
||||
def isByteRight(byte):
|
||||
return True if 1 & byte == 1 else False
|
||||
|
||||
for byte in letter:
|
||||
if isByteRight(byte):
|
||||
return True
|
||||
|
||||
return False
|
||||
|
||||
def shiftLetterRight(letter):
|
||||
def shift(letter):
|
||||
return [byte >> 1 for byte in letter]
|
||||
|
||||
shifted = letter
|
||||
for i in range(8): # max 1 Bit's
|
||||
shifted = shift(shifted)
|
||||
if isLetterRight(shifted):
|
||||
break
|
||||
|
||||
return shifted
|
||||
|
||||
if isLetterRight(letter):
|
||||
return letter
|
||||
|
||||
# letter is not right shifted
|
||||
shifted = shiftLetterRight(letter)
|
||||
|
||||
if debug:
|
||||
print('origin:')
|
||||
utils.show_byte_matrix(char, letter)
|
||||
print('shifted')
|
||||
utils.show_byte_matrix(char, shifted)
|
||||
|
||||
return shifted
|
||||
|
||||
|
||||
def align_font(font):
|
||||
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])
|
||||
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)}'
|
||||
|
||||
Reference in New Issue
Block a user