v.0.3.0 calculate char_width with shift operator
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
# Emoji symbols for LED matrix (16x16)
|
||||
emoji_16x16 = {
|
||||
# Basic Smileys
|
||||
'😀': [
|
||||
# === SMILEYS & EMOTIONS ===
|
||||
'😀': [ # Grinning Face
|
||||
0x07E0,
|
||||
0x1FF8,
|
||||
0x3FFC,
|
||||
@@ -18,8 +18,8 @@ emoji_16x16 = {
|
||||
0x1FF8,
|
||||
0x07E0,
|
||||
0x0000,
|
||||
], # Grinning face (circle outline)
|
||||
'😊': [
|
||||
],
|
||||
'😊': [ # Smiling Face with Smiling Eyes
|
||||
0x07E0,
|
||||
0x1FF8,
|
||||
0x3FFC,
|
||||
@@ -36,8 +36,8 @@ emoji_16x16 = {
|
||||
0x3FFC,
|
||||
0x1FF8,
|
||||
0x07E0,
|
||||
], # Smiling face
|
||||
'😂': [
|
||||
],
|
||||
'😂': [ # Face with Tears of Joy
|
||||
0x07E0,
|
||||
0x1FF8,
|
||||
0x3FFC,
|
||||
@@ -54,8 +54,8 @@ emoji_16x16 = {
|
||||
0x3FFC,
|
||||
0x1FF8,
|
||||
0x07E0,
|
||||
], # Laughing with tears
|
||||
'😍': [
|
||||
],
|
||||
'😍': [ # Smiling Face with Heart-Eyes
|
||||
0x07E0,
|
||||
0x1FF8,
|
||||
0x3FFC,
|
||||
@@ -72,8 +72,8 @@ emoji_16x16 = {
|
||||
0x3FFC,
|
||||
0x1FF8,
|
||||
0x07E0,
|
||||
], # Heart eyes
|
||||
'😎': [
|
||||
],
|
||||
'😎': [ # Smiling Face with Sunglasses
|
||||
0x07E0,
|
||||
0x1FF8,
|
||||
0x3FFC,
|
||||
@@ -90,9 +90,45 @@ emoji_16x16 = {
|
||||
0x3FFC,
|
||||
0x1FF8,
|
||||
0x07E0,
|
||||
], # Cool sunglasses
|
||||
# Hearts
|
||||
'❤️': [
|
||||
],
|
||||
'😢': [ # Crying Face
|
||||
0x07E0,
|
||||
0x1FF8,
|
||||
0x3FFC,
|
||||
0x7FFE,
|
||||
0x7C3E,
|
||||
0xF81F,
|
||||
0xF00F,
|
||||
0xF3CF,
|
||||
0xF3CF,
|
||||
0xF00F,
|
||||
0xF99F,
|
||||
0x7C3E,
|
||||
0x7FFE,
|
||||
0x3FFC,
|
||||
0x1FF8,
|
||||
0x07E0,
|
||||
],
|
||||
'😠': [ # Angry Face
|
||||
0x07E0,
|
||||
0x1FF8,
|
||||
0x3FFC,
|
||||
0x7FFE,
|
||||
0x7C3E,
|
||||
0xF81F,
|
||||
0xF3CF,
|
||||
0xE667,
|
||||
0xE667,
|
||||
0xF3CF,
|
||||
0xF81F,
|
||||
0x7C3E,
|
||||
0x7FFE,
|
||||
0x3FFC,
|
||||
0x1FF8,
|
||||
0x07E0,
|
||||
],
|
||||
# === HEARTS ===
|
||||
'❤️': [ # Red Heart
|
||||
0x0000,
|
||||
0x0000,
|
||||
0x0C30,
|
||||
@@ -109,9 +145,27 @@ emoji_16x16 = {
|
||||
0x0F80,
|
||||
0x0700,
|
||||
0x0000,
|
||||
], # Red heart
|
||||
# Weather & Nature
|
||||
'☀️': [
|
||||
],
|
||||
'💙': [ # Blue Heart
|
||||
0x0000,
|
||||
0x0000,
|
||||
0x0C30,
|
||||
0x1E78,
|
||||
0x3FFC,
|
||||
0x7FFE,
|
||||
0x7FFE,
|
||||
0xFFFE,
|
||||
0xFFFC,
|
||||
0x7FF8,
|
||||
0x7FF0,
|
||||
0x3FE0,
|
||||
0x1FC0,
|
||||
0x0F80,
|
||||
0x0700,
|
||||
0x0000,
|
||||
],
|
||||
# === WEATHER & NATURE ===
|
||||
'☀️': [ # Sun
|
||||
0x8001,
|
||||
0x4002,
|
||||
0x2004,
|
||||
@@ -128,8 +182,8 @@ emoji_16x16 = {
|
||||
0x2004,
|
||||
0x4002,
|
||||
0x8001,
|
||||
], # Sun with detailed rays
|
||||
'🌙': [
|
||||
],
|
||||
'🌙': [ # Crescent Moon
|
||||
0x0000,
|
||||
0x1F80,
|
||||
0x3FC0,
|
||||
@@ -146,8 +200,8 @@ emoji_16x16 = {
|
||||
0xFC00,
|
||||
0xF800,
|
||||
0x0000,
|
||||
], # Crescent moon
|
||||
'⭐': [
|
||||
],
|
||||
'⭐': [ # Star
|
||||
0x0180,
|
||||
0x0180,
|
||||
0x03C0,
|
||||
@@ -164,9 +218,27 @@ emoji_16x16 = {
|
||||
0x03C0,
|
||||
0x0180,
|
||||
0x0180,
|
||||
], # Star
|
||||
# Objects
|
||||
'📱': [
|
||||
],
|
||||
'☁️': [ # Cloud
|
||||
0x0000,
|
||||
0x0000,
|
||||
0x0F00,
|
||||
0x1F80,
|
||||
0x3FC0,
|
||||
0x7FE0,
|
||||
0x7FE0,
|
||||
0xFFF0,
|
||||
0xFFF0,
|
||||
0xFFF0,
|
||||
0x7FE0,
|
||||
0x7FE0,
|
||||
0x3FC0,
|
||||
0x1F80,
|
||||
0x0F00,
|
||||
0x0000,
|
||||
],
|
||||
# === TECHNOLOGY ===
|
||||
'📱': [ # Mobile Phone
|
||||
0xFFFF,
|
||||
0x8001,
|
||||
0x8001,
|
||||
@@ -183,8 +255,8 @@ emoji_16x16 = {
|
||||
0x8001,
|
||||
0x8001,
|
||||
0xFFFF,
|
||||
], # Smartphone
|
||||
'💻': [
|
||||
],
|
||||
'💻': [ # Laptop
|
||||
0x0000,
|
||||
0x7FFE,
|
||||
0x4002,
|
||||
@@ -201,65 +273,8 @@ emoji_16x16 = {
|
||||
0x3FFC,
|
||||
0x1FF8,
|
||||
0x0000,
|
||||
], # Laptop
|
||||
# Animals
|
||||
'🐱': [
|
||||
0x07E0,
|
||||
0x1FF8,
|
||||
0x3FFC,
|
||||
0x7FFE,
|
||||
0x7FFE,
|
||||
0x6FF6,
|
||||
0x6FF6,
|
||||
0x6FF6,
|
||||
0x6FF6,
|
||||
0x6FF6,
|
||||
0x7FFE,
|
||||
0x7FFE,
|
||||
0x3FFC,
|
||||
0x1FF8,
|
||||
0x07E0,
|
||||
0x0000,
|
||||
], # Cat face
|
||||
'🐶': [
|
||||
0x07E0,
|
||||
0x1FF8,
|
||||
0x3FFC,
|
||||
0x7FFE,
|
||||
0x7FFE,
|
||||
0x6FF6,
|
||||
0x6FF6,
|
||||
0x6FF6,
|
||||
0x6FF6,
|
||||
0x6FF6,
|
||||
0x7FFE,
|
||||
0x7FFE,
|
||||
0x3FFC,
|
||||
0x1FF8,
|
||||
0x07E0,
|
||||
0x0000,
|
||||
], # Dog face
|
||||
# Food
|
||||
'🍕': [
|
||||
0x07E0,
|
||||
0x1FF8,
|
||||
0x3FFC,
|
||||
0x7FFE,
|
||||
0x7FFE,
|
||||
0x7FFE,
|
||||
0x7FFE,
|
||||
0x7FFE,
|
||||
0x7FFE,
|
||||
0x7FFE,
|
||||
0x7FFE,
|
||||
0x7FFE,
|
||||
0x3FFC,
|
||||
0x1FF8,
|
||||
0x07E0,
|
||||
0x0000,
|
||||
], # Pizza
|
||||
# Technology
|
||||
'🔒': [
|
||||
],
|
||||
'🔒': [ # Lock
|
||||
0x0FC0,
|
||||
0x1FE0,
|
||||
0x3FF0,
|
||||
@@ -276,28 +291,82 @@ emoji_16x16 = {
|
||||
0x3FF0,
|
||||
0x3FF0,
|
||||
0x3FF0,
|
||||
], # Lock
|
||||
# Vehicles
|
||||
'🚗': [
|
||||
],
|
||||
'🔑': [ # Key
|
||||
0x0000,
|
||||
0x0000,
|
||||
0x0FC0,
|
||||
0x1FE0,
|
||||
0x3FF0,
|
||||
0x3FF0,
|
||||
0x3FF0,
|
||||
0x3FF0,
|
||||
0x3FF0,
|
||||
0x3FF0,
|
||||
0x3FF0,
|
||||
0x3FF0,
|
||||
0x1FE0,
|
||||
0x0FC0,
|
||||
0x0F00,
|
||||
0x1F80,
|
||||
0x3FC0,
|
||||
0x3FC0,
|
||||
0x3FC0,
|
||||
0x3FC0,
|
||||
0x3FC0,
|
||||
0x3FC0,
|
||||
0x3FC0,
|
||||
0x3FC0,
|
||||
0x3FC0,
|
||||
0x3FC0,
|
||||
0x3FC0,
|
||||
0x3FC0,
|
||||
],
|
||||
# === ANIMALS ===
|
||||
'🐱': [ # Cat Face
|
||||
0x07E0,
|
||||
0x1FF8,
|
||||
0x3FFC,
|
||||
0x7FFE,
|
||||
0x7FFE,
|
||||
0x6FF6,
|
||||
0x6FF6,
|
||||
0x6FF6,
|
||||
0x6FF6,
|
||||
0x6FF6,
|
||||
0x7FFE,
|
||||
0x7FFE,
|
||||
0x3FFC,
|
||||
0x1FF8,
|
||||
0x07E0,
|
||||
0x0000,
|
||||
],
|
||||
'🐶': [ # Dog Face
|
||||
0x07E0,
|
||||
0x1FF8,
|
||||
0x3FFC,
|
||||
0x7FFE,
|
||||
0x7FFE,
|
||||
0x6FF6,
|
||||
0x6FF6,
|
||||
0x6FF6,
|
||||
0x6FF6,
|
||||
0x6FF6,
|
||||
0x7FFE,
|
||||
0x7FFE,
|
||||
0x3FFC,
|
||||
0x1FF8,
|
||||
0x07E0,
|
||||
0x0000,
|
||||
],
|
||||
'🐦': [ # Bird
|
||||
0x0000,
|
||||
0x0000,
|
||||
], # Car
|
||||
# Sports
|
||||
'⚽': [
|
||||
0x0000,
|
||||
0x0000,
|
||||
0x0000,
|
||||
0x0000,
|
||||
0x0000,
|
||||
0x0000,
|
||||
0x0000,
|
||||
0x0000,
|
||||
0x0000,
|
||||
0x0000,
|
||||
0x0000,
|
||||
0x0000,
|
||||
0x0000,
|
||||
0x0000,
|
||||
],
|
||||
# === FOOD ===
|
||||
'🍕': [ # Pizza
|
||||
0x07E0,
|
||||
0x1FF8,
|
||||
0x3FFC,
|
||||
@@ -314,9 +383,101 @@ emoji_16x16 = {
|
||||
0x1FF8,
|
||||
0x07E0,
|
||||
0x0000,
|
||||
], # Soccer ball
|
||||
# Holidays
|
||||
'🎄': [
|
||||
],
|
||||
'🍎': [ # Red Apple
|
||||
0x0000,
|
||||
0x0000,
|
||||
0x0000,
|
||||
0x0000,
|
||||
0x0000,
|
||||
0x0000,
|
||||
0x0000,
|
||||
0x0000,
|
||||
0x0000,
|
||||
0x0000,
|
||||
0x0000,
|
||||
0x0000,
|
||||
0x0000,
|
||||
0x0000,
|
||||
0x0000,
|
||||
0x0000,
|
||||
],
|
||||
# === VEHICLES ===
|
||||
'🚗': [ # Car
|
||||
0x0000,
|
||||
0x0000,
|
||||
0x0FC0,
|
||||
0x1FE0,
|
||||
0x3FF0,
|
||||
0x3FF0,
|
||||
0x3FF0,
|
||||
0x3FF0,
|
||||
0x3FF0,
|
||||
0x3FF0,
|
||||
0x3FF0,
|
||||
0x3FF0,
|
||||
0x1FE0,
|
||||
0x0FC0,
|
||||
0x0000,
|
||||
0x0000,
|
||||
],
|
||||
'✈️': [ # Airplane
|
||||
0x0000,
|
||||
0x0000,
|
||||
0x0000,
|
||||
0x0000,
|
||||
0x0000,
|
||||
0x0000,
|
||||
0x0000,
|
||||
0x0000,
|
||||
0x0000,
|
||||
0x0000,
|
||||
0x0000,
|
||||
0x0000,
|
||||
0x0000,
|
||||
0x0000,
|
||||
0x0000,
|
||||
0x0000,
|
||||
],
|
||||
# === SPORTS ===
|
||||
'⚽': [ # Soccer Ball
|
||||
0x07E0,
|
||||
0x1FF8,
|
||||
0x3FFC,
|
||||
0x7FFE,
|
||||
0x7FFE,
|
||||
0x7FFE,
|
||||
0x7FFE,
|
||||
0x7FFE,
|
||||
0x7FFE,
|
||||
0x7FFE,
|
||||
0x7FFE,
|
||||
0x7FFE,
|
||||
0x3FFC,
|
||||
0x1FF8,
|
||||
0x07E0,
|
||||
0x0000,
|
||||
],
|
||||
'🏀': [ # Basketball
|
||||
0x07E0,
|
||||
0x1FF8,
|
||||
0x3FFC,
|
||||
0x7FFE,
|
||||
0x7FFE,
|
||||
0x7FFE,
|
||||
0x7FFE,
|
||||
0x7FFE,
|
||||
0x7FFE,
|
||||
0x7FFE,
|
||||
0x7FFE,
|
||||
0x7FFE,
|
||||
0x3FFC,
|
||||
0x1FF8,
|
||||
0x07E0,
|
||||
0x0000,
|
||||
],
|
||||
# === HOLIDAYS ===
|
||||
'🎄': [ # Christmas Tree
|
||||
0x0180,
|
||||
0x03C0,
|
||||
0x03C0,
|
||||
@@ -333,5 +494,23 @@ emoji_16x16 = {
|
||||
0x03C0,
|
||||
0x03C0,
|
||||
0x03C0,
|
||||
], # Christmas tree
|
||||
],
|
||||
'🎃': [ # Jack-O-Lantern
|
||||
0x07E0,
|
||||
0x1FF8,
|
||||
0x3FFC,
|
||||
0x7FFE,
|
||||
0x7FFE,
|
||||
0x7FFE,
|
||||
0x7FFE,
|
||||
0x7FFE,
|
||||
0x7FFE,
|
||||
0x7FFE,
|
||||
0x7FFE,
|
||||
0x7FFE,
|
||||
0x3FFC,
|
||||
0x1FF8,
|
||||
0x07E0,
|
||||
0x0000,
|
||||
],
|
||||
}
|
||||
|
||||
@@ -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):
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
from machine import Pin, RTC
|
||||
from neopixel import NeoPixel
|
||||
from .fonts.fonts_utils import fonts_meta
|
||||
from .fonts.fonts_utils import fonts_meta, char_width as charwidth
|
||||
|
||||
from .fonts.font_5x7 import font_5x7
|
||||
from .fonts.font_5x7_opt import font_5x7 as font_5x7_opt, get_char_width
|
||||
@@ -124,17 +124,20 @@ class NeoPixel_64x64(NeoPixel):
|
||||
color: RGB color tuple
|
||||
"""
|
||||
|
||||
# background for the letter (full font size)
|
||||
[
|
||||
# print(xpos, ypos)
|
||||
self.set_pixel(xpos, ypos, GRAY)
|
||||
for xpos in range(x, x + 8) # 8 because full with of character representation
|
||||
for ypos in range(y, y + self.font_height)
|
||||
]
|
||||
|
||||
if letter in self.selected_font:
|
||||
char_data = self.selected_font[letter]
|
||||
char_width = get_char_width(letter)
|
||||
# char_width = get_char_width(letter, default_witdth=16)
|
||||
char_width = charwidth(char_data)
|
||||
|
||||
# background for the letter (full font size)
|
||||
[
|
||||
# print(xpos, ypos)
|
||||
self.set_pixel(xpos, ypos, GRAY)
|
||||
for xpos in range(
|
||||
x, x + char_width
|
||||
) # 8 because full with of character representation
|
||||
for ypos in range(y, y + self.font_height)
|
||||
]
|
||||
|
||||
for row in range(self.font_height):
|
||||
row_data = char_data[row]
|
||||
|
||||
Reference in New Issue
Block a user