mirror of
https://github.com/ChuckBuilds/LEDMatrix.git
synced 2026-04-12 13:42:59 +00:00
Update display_manager.py
remove bitmap and go back to a font. Bitmap was too bold
This commit is contained in:
@@ -124,13 +124,23 @@ class DisplayManager:
|
|||||||
def _load_fonts(self):
|
def _load_fonts(self):
|
||||||
"""Load fonts optimized for LED matrix display."""
|
"""Load fonts optimized for LED matrix display."""
|
||||||
try:
|
try:
|
||||||
# Use the default bitmap font - it's actually great for LED matrices
|
# Use DejaVu Sans with optimized sizes
|
||||||
self.font = ImageFont.load_default()
|
matrix_height = self.matrix.height
|
||||||
self.small_font = ImageFont.load_default()
|
# For 32px height matrix, use 16px for large text and 8px for small
|
||||||
logger.info("Using default bitmap font")
|
large_size = 16 # Fixed size instead of percentage
|
||||||
|
small_size = 8 # Fixed size for better clarity
|
||||||
|
|
||||||
|
try:
|
||||||
|
self.font = ImageFont.truetype("/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf", large_size)
|
||||||
|
self.small_font = ImageFont.truetype("/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf", small_size)
|
||||||
|
logger.info(f"Using DejaVu Sans with sizes {large_size}px and {small_size}px")
|
||||||
|
except Exception as e:
|
||||||
|
logger.error(f"Failed to load DejaVu Sans: {e}")
|
||||||
|
self.font = ImageFont.load_default()
|
||||||
|
self.small_font = ImageFont.load_default()
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error(f"Error loading fonts: {e}")
|
logger.error(f"Error in font loading: {e}")
|
||||||
self.font = ImageFont.load_default()
|
self.font = ImageFont.load_default()
|
||||||
self.small_font = self.font
|
self.small_font = self.font
|
||||||
|
|
||||||
@@ -138,20 +148,28 @@ class DisplayManager:
|
|||||||
"""Draw text on the display with improved clarity."""
|
"""Draw text on the display with improved clarity."""
|
||||||
font = self.small_font if small_font else self.font
|
font = self.small_font if small_font else self.font
|
||||||
|
|
||||||
# Get text dimensions for centering if x not specified
|
# Get text dimensions including ascenders and descenders
|
||||||
bbox = self.draw.textbbox((0, 0), text, font=font)
|
bbox = self.draw.textbbox((0, 0), text, font=font)
|
||||||
text_width = bbox[2] - bbox[0]
|
text_width = bbox[2] - bbox[0]
|
||||||
text_height = bbox[3] - bbox[1]
|
text_height = bbox[3] - bbox[1]
|
||||||
|
|
||||||
|
# Add padding to prevent cutoff
|
||||||
|
padding = 2
|
||||||
|
|
||||||
# Center text horizontally if x not specified
|
# Center text horizontally if x not specified
|
||||||
if x is None:
|
if x is None:
|
||||||
x = (self.matrix.width - text_width) // 2
|
x = (self.matrix.width - text_width) // 2
|
||||||
|
|
||||||
# Center text vertically if y not specified
|
# Center text vertically if y not specified, with padding
|
||||||
if y is None:
|
if y is None:
|
||||||
y = (self.matrix.height - text_height) // 2
|
y = (self.matrix.height - text_height) // 2
|
||||||
|
else:
|
||||||
|
# Ensure text doesn't get cut off at bottom
|
||||||
|
max_y = self.matrix.height - text_height - padding
|
||||||
|
y = min(y, max_y)
|
||||||
|
y = max(y, padding) # Ensure text doesn't get cut off at top
|
||||||
|
|
||||||
# Draw text at full brightness for maximum clarity
|
# Draw text
|
||||||
self.draw.text((x, y), text, font=font, fill=color)
|
self.draw.text((x, y), text, font=font, fill=color)
|
||||||
|
|
||||||
def draw_sun(self, x: int, y: int, size: int = 16):
|
def draw_sun(self, x: int, y: int, size: int = 16):
|
||||||
|
|||||||
Reference in New Issue
Block a user