# fonts.py - Optimized fonts for LED matrix with character width adjustment # 5x7 Font (Optimized Width) font_5x7 = { # Uppercase letters (A-Z) - Optimized for better spacing 'A': [0x0E, 0x11, 0x11, 0x1F, 0x11, 0x11, 0x11], # Width: 5 'B': [0x1E, 0x11, 0x11, 0x1E, 0x11, 0x11, 0x1E], # Width: 5 'C': [0x0E, 0x11, 0x10, 0x10, 0x10, 0x11, 0x0E], # Width: 5 'D': [0x1E, 0x11, 0x11, 0x11, 0x11, 0x11, 0x1E], # Width: 5 'E': [0x1F, 0x10, 0x10, 0x1E, 0x10, 0x10, 0x1F], # Width: 5 'F': [0x1F, 0x10, 0x10, 0x1E, 0x10, 0x10, 0x10], # Width: 5 'G': [0x0E, 0x11, 0x10, 0x13, 0x11, 0x11, 0x0F], # Width: 5 'H': [0x11, 0x11, 0x11, 0x1F, 0x11, 0x11, 0x11], # Width: 5 # 'I': [0x0E, 0x04, 0x04, 0x04, 0x04, 0x04, 0x0E], # Width: 3 'I': [0x07, 0x02, 0x02, 0x02, 0x02, 0x02, 0x07], # Width: 3 'J': [0x07, 0x02, 0x02, 0x02, 0x02, 0x12, 0x0C], # Width: 4 'K': [0x11, 0x12, 0x14, 0x18, 0x14, 0x12, 0x11], # Width: 5 'L': [0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x1F], # Width: 5 'M': [0x11, 0x1B, 0x15, 0x15, 0x11, 0x11, 0x11], # Width: 5 'N': [0x11, 0x19, 0x19, 0x15, 0x13, 0x13, 0x11], # Width: 5 'O': [0x0E, 0x11, 0x11, 0x11, 0x11, 0x11, 0x0E], # Width: 5 'P': [0x1E, 0x11, 0x11, 0x1E, 0x10, 0x10, 0x10], # Width: 5 'Q': [0x0E, 0x11, 0x11, 0x11, 0x15, 0x12, 0x0D], # Width: 5 'R': [0x1E, 0x11, 0x11, 0x1E, 0x14, 0x12, 0x11], # Width: 5 'S': [0x0F, 0x10, 0x10, 0x0E, 0x01, 0x01, 0x1E], # Width: 5 'T': [0x1F, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04], # Width: 5 'U': [0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x0E], # Width: 5 'V': [0x11, 0x11, 0x11, 0x11, 0x11, 0x0A, 0x04], # Width: 5 'W': [0x11, 0x11, 0x11, 0x15, 0x15, 0x15, 0x0A], # Width: 5 'X': [0x11, 0x11, 0x0A, 0x04, 0x0A, 0x11, 0x11], # Width: 5 'Y': [0x11, 0x11, 0x0A, 0x04, 0x04, 0x04, 0x04], # Width: 5 'Z': [0x1F, 0x01, 0x02, 0x04, 0x08, 0x10, 0x1F], # Width: 5 # Lowercase letters (a-z) - Optimized for compact display 'a': [0x00, 0x00, 0x0E, 0x01, 0x0F, 0x11, 0x0F], # Width: 4 'b': [0x10, 0x10, 0x16, 0x19, 0x11, 0x11, 0x1E], # Width: 5 'c': [0x00, 0x00, 0x0E, 0x11, 0x10, 0x11, 0x0E], # Width: 4 'd': [0x01, 0x01, 0x0D, 0x13, 0x11, 0x11, 0x0F], # Width: 5 'e': [0x00, 0x00, 0x0E, 0x11, 0x1F, 0x10, 0x0E], # Width: 4 'f': [0x06, 0x09, 0x08, 0x1C, 0x08, 0x08, 0x08], # Width: 4 'g': [0x00, 0x0F, 0x11, 0x11, 0x0F, 0x01, 0x0E], # Width: 5 'h': [0x10, 0x10, 0x16, 0x19, 0x11, 0x11, 0x11], # Width: 5 # 'i': [0x00, 0x04, 0x00, 0x0C, 0x04, 0x04, 0x0E], # Width: 2 'i': [0x00, 0x02, 0x00, 0x06, 0x02, 0x02, 0x07], # Width: 2 'j': [0x00, 0x02, 0x00, 0x06, 0x02, 0x12, 0x0C], # Width: 3 'k': [0x10, 0x10, 0x12, 0x14, 0x18, 0x14, 0x12], # Width: 4 # 'l': [0x0C, 0x04, 0x04, 0x04, 0x04, 0x04, 0x0E], # Width: 3 'l': [0x06, 0x02, 0x02, 0x02, 0x02, 0x02, 0x07], # Width: 3 'm': [0x00, 0x00, 0x1A, 0x15, 0x15, 0x15, 0x15], # Width: 5 'n': [0x00, 0x00, 0x16, 0x19, 0x11, 0x11, 0x11], # Width: 5 'o': [0x00, 0x00, 0x0E, 0x11, 0x11, 0x11, 0x0E], # Width: 4 'p': [0x00, 0x00, 0x1E, 0x11, 0x1E, 0x10, 0x10], # Width: 5 'q': [0x00, 0x00, 0x0D, 0x13, 0x0F, 0x01, 0x01], # Width: 5 'r': [0x00, 0x00, 0x16, 0x19, 0x10, 0x10, 0x10], # Width: 5 's': [0x00, 0x00, 0x0E, 0x10, 0x0E, 0x01, 0x1E], # Width: 4 't': [0x08, 0x08, 0x1C, 0x08, 0x08, 0x09, 0x06], # Width: 4 'u': [0x00, 0x00, 0x11, 0x11, 0x11, 0x13, 0x0D], # Width: 5 'v': [0x00, 0x00, 0x11, 0x11, 0x11, 0x0A, 0x04], # Width: 5 'w': [0x00, 0x00, 0x11, 0x11, 0x15, 0x15, 0x0A], # Width: 5 'x': [0x00, 0x00, 0x11, 0x0A, 0x04, 0x0A, 0x11], # Width: 5 'y': [0x00, 0x00, 0x11, 0x11, 0x0F, 0x01, 0x0E], # Width: 5 'z': [0x00, 0x00, 0x1F, 0x02, 0x04, 0x08, 0x1F], # Width: 5 # Numbers (0-9) - Optimized for consistent width '0': [0x0E, 0x11, 0x13, 0x15, 0x19, 0x11, 0x0E], # Width: 5 # '1': [0x04, 0x0C, 0x04, 0x04, 0x04, 0x04, 0x0E], # Width: 3 '1': [0x02, 0x06, 0x02, 0x02, 0x02, 0x02, 0x07], # Width: 3 '2': [0x0E, 0x11, 0x01, 0x02, 0x04, 0x08, 0x1F], # Width: 5 '3': [0x1F, 0x02, 0x04, 0x02, 0x01, 0x11, 0x0E], # Width: 5 '4': [0x02, 0x06, 0x0A, 0x12, 0x1F, 0x02, 0x02], # Width: 5 '5': [0x1F, 0x10, 0x1E, 0x01, 0x01, 0x11, 0x0E], # Width: 5 '6': [0x06, 0x08, 0x10, 0x1E, 0x11, 0x11, 0x0E], # Width: 5 '7': [0x1F, 0x01, 0x02, 0x04, 0x08, 0x08, 0x08], # Width: 5 '8': [0x0E, 0x11, 0x11, 0x0E, 0x11, 0x11, 0x0E], # Width: 5 '9': [0x0E, 0x11, 0x11, 0x0F, 0x01, 0x02, 0x0C], # Width: 5 # Punctuation and symbols - Optimized widths ' ': [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00], # Width: 2 # '!': [0x04, 0x04, 0x04, 0x04, 0x00, 0x00, 0x04], # Width: 1 '!': [0x01, 0x01, 0x01, 0x01, 0x01, 0x00, 0x01], # Width: 1 '?': [0x0E, 0x11, 0x02, 0x04, 0x04, 0x00, 0x04], # Width: 5 '.': [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01], # Width: 1 ',': [0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x02], # Width: 1 ':': [0x00, 0x00, 0x01, 0x00, 0x00, 0x01, 0x00], # Width: 1 ';': [0x00, 0x00, 0x01, 0x00, 0x00, 0x01, 0x02], # Width: 1 "'": [0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00], # Width: 1 '"': [0x05, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00], # Width: 3 '-': [0x00, 0x00, 0x00, 0x1F, 0x00, 0x00, 0x00], # Width: 5 '_': [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1F], # Width: 5 '+': [0x00, 0x04, 0x04, 0x1F, 0x04, 0x04, 0x00], # Width: 5 '=': [0x00, 0x00, 0x1F, 0x00, 0x1F, 0x00, 0x00], # Width: 5 '*': [0x00, 0x0A, 0x04, 0x1F, 0x04, 0x0A, 0x00], # Width: 5 '/': [0x00, 0x01, 0x02, 0x04, 0x08, 0x10, 0x00], # Width: 5 '\\': [0x00, 0x10, 0x08, 0x04, 0x02, 0x01, 0x00], # Width: 5 '(': [0x01, 0x02, 0x04, 0x04, 0x04, 0x02, 0x01], # Width: 3 ')': [0x04, 0x02, 0x01, 0x01, 0x01, 0x02, 0x04], # Width: 3 '[': [0x07, 0x04, 0x04, 0x04, 0x04, 0x04, 0x07], # Width: 3 ']': [0x07, 0x01, 0x01, 0x01, 0x01, 0x01, 0x07], # Width: 3 '{': [0x03, 0x02, 0x02, 0x04, 0x02, 0x02, 0x03], # Width: 3 '}': [0x06, 0x02, 0x02, 0x01, 0x02, 0x02, 0x06], # Width: 3 '<': [0x00, 0x01, 0x02, 0x04, 0x02, 0x01, 0x00], # Width: 4 '>': [0x00, 0x04, 0x02, 0x01, 0x02, 0x04, 0x00], # Width: 4 '@': [0x0E, 0x11, 0x17, 0x15, 0x17, 0x10, 0x0E], # Width: 5 '#': [0x0A, 0x0A, 0x1F, 0x0A, 0x1F, 0x0A, 0x0A], # Width: 5 '$': [0x04, 0x0F, 0x14, 0x0E, 0x05, 0x1E, 0x04], # Width: 5 '%': [0x18, 0x19, 0x02, 0x04, 0x08, 0x13, 0x03], # Width: 5 '&': [0x0C, 0x12, 0x14, 0x08, 0x15, 0x12, 0x0D], # Width: 5 '^': [0x04, 0x0A, 0x11, 0x00, 0x00, 0x00, 0x00], # Width: 5 '~': [0x00, 0x00, 0x00, 0x0D, 0x12, 0x00, 0x00], # Width: 5 # Special characters '°': [0x07, 0x05, 0x07, 0x00, 0x00, 0x00, 0x00], # Width: 3 (Degree symbol) '|': [0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01], # Width: 1 (Vertical bar) '`': [0x02, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00], # Width: 2 (Backtick) '¶': [0x0F, 0x0D, 0x0D, 0x0D, 0x0D, 0x0D, 0x0D], # Width: 5 (Paragraph symbol) '•': [0x00, 0x00, 0x02, 0x07, 0x02, 0x00, 0x00], # Width: 3 (Bullet point) } # Character width mapping for optimized spacing char_width = { # Wide characters (5 pixels) 'A': 5, 'B': 5, 'C': 5, 'D': 5, 'E': 5, 'F': 5, 'G': 5, 'H': 5, 'K': 5, 'L': 5, 'M': 5, 'N': 5, 'O': 5, 'P': 5, 'Q': 5, 'R': 5, 'S': 5, 'T': 5, 'U': 5, 'V': 5, 'W': 5, 'X': 5, 'Y': 5, 'Z': 5, 'b': 5, 'd': 5, 'g': 5, 'h': 5, 'm': 5, 'n': 5, 'p': 5, 'q': 5, 'u': 5, 'v': 5, 'w': 5, 'x': 5, 'y': 5, 'z': 5, '0': 5, '2': 5, '3': 5, '4': 5, '5': 5, '6': 5, '7': 5, '8': 5, '9': 5, '?': 5, '-': 5, '_': 5, '+': 5, '=': 5, '*': 5, '/': 5, '\\': 5, '@': 5, '#': 5, '$': 5, '%': 5, '&': 5, '^': 5, '~': 5, '¶': 4, # Medium characters (4 pixels) 'J': 5, 'a': 5, 'c': 5, 'e': 5, 'f': 5, 'k': 5, 'o': 5, 's': 5, 't': 5, '<': 4, '>': 4, # Narrow characters (3 pixels) 'I': 3, '1': 3, 'l': 3, 'j': 4, '(': 3, ')': 3, '[': 3, ']': 3, '{': 3, '}': 3, '°': 3, '•': 3, # Very narrow characters (2 pixels) 'i': 3, ' ': 1, '`': 2, # Single pixel characters '!': 1, '.': 1, ',': 2, ':': 1, ';': 2, "'": 1, '|': 1, # Special cases '"': 3, } def get_char_width(char): """Get the display width of a character for proper spacing""" return char_width.get(char, 5) # Default to 5 if character not found def get_text_width(text): """Calculate total width of text including character spacing""" width = 0 for char in text: if char in char_width: width += char_width[char] + 1 # +1 for spacing between characters else: width += 6 # Default width + spacing return max(0, width - 1) # Remove last spacing