mirror of
https://github.com/ChuckBuilds/LEDMatrix.git
synced 2026-04-10 21:03:01 +00:00
revert daily weather temp font change due to negative effects on other displays
This commit is contained in:
@@ -226,28 +226,7 @@ class DisplayManager:
|
|||||||
logger.error(f"Failed to load 4x6 TTF font: {font_err}. Falling back.")
|
logger.error(f"Failed to load 4x6 TTF font: {font_err}. Falling back.")
|
||||||
self.extra_small_font = self.small_font
|
self.extra_small_font = self.small_font
|
||||||
|
|
||||||
# Load MatrixLight6 BDF font for weather forecasts
|
|
||||||
try:
|
|
||||||
script_dir = os.path.dirname(os.path.abspath(__file__))
|
|
||||||
relative_font_path = os.path.join(script_dir, "../assets/fonts/MatrixLight6.bdf")
|
|
||||||
self.matrix_light6_font_path = os.path.abspath(relative_font_path)
|
|
||||||
logger.info(f"Attempting to load MatrixLight6 font from: {self.matrix_light6_font_path}")
|
|
||||||
|
|
||||||
if not os.path.exists(self.matrix_light6_font_path):
|
|
||||||
raise FileNotFoundError(f"Font file not found at {self.matrix_light6_font_path}")
|
|
||||||
|
|
||||||
# Load with freetype for proper BDF handling
|
|
||||||
face = freetype.Face(self.matrix_light6_font_path)
|
|
||||||
logger.info(f"MatrixLight6 font loaded successfully from {self.matrix_light6_font_path}")
|
|
||||||
logger.info(f"MatrixLight6 font size: {face.size.height >> 6} pixels")
|
|
||||||
|
|
||||||
# Store the face for later use
|
|
||||||
self.matrix_light6_font = face
|
|
||||||
|
|
||||||
except Exception as font_err:
|
|
||||||
logger.error(f"Failed to load MatrixLight6 font: {str(font_err)}", exc_info=True)
|
|
||||||
logger.error("Falling back to small font")
|
|
||||||
self.matrix_light6_font = self.small_font
|
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error(f"Error in font loading: {e}", exc_info=True)
|
logger.error(f"Error in font loading: {e}", exc_info=True)
|
||||||
@@ -259,8 +238,7 @@ class DisplayManager:
|
|||||||
self.extra_small_font = self.regular_font
|
self.extra_small_font = self.regular_font
|
||||||
if not hasattr(self, 'bdf_5x7_font'): # Ensure bdf_5x7_font also gets a fallback
|
if not hasattr(self, 'bdf_5x7_font'): # Ensure bdf_5x7_font also gets a fallback
|
||||||
self.bdf_5x7_font = self.regular_font
|
self.bdf_5x7_font = self.regular_font
|
||||||
if not hasattr(self, 'matrix_light6_font'): # Ensure matrix_light6_font also gets a fallback
|
|
||||||
self.matrix_light6_font = self.regular_font
|
|
||||||
|
|
||||||
def get_text_width(self, text, font):
|
def get_text_width(self, text, font):
|
||||||
"""Get the width of text when rendered with the given font."""
|
"""Get the width of text when rendered with the given font."""
|
||||||
|
|||||||
@@ -503,23 +503,12 @@ class WeatherManager:
|
|||||||
|
|
||||||
# Draw high/low temperatures at bottom (without degree symbol)
|
# Draw high/low temperatures at bottom (without degree symbol)
|
||||||
temp_text = f"{forecast['temp_low']} / {forecast['temp_high']}" # Removed degree symbols
|
temp_text = f"{forecast['temp_low']} / {forecast['temp_high']}" # Removed degree symbols
|
||||||
# Use MatrixLight6 font for temperature text
|
temp_width = draw.textlength(temp_text, font=self.display_manager.extra_small_font)
|
||||||
if hasattr(self.display_manager, 'matrix_light6_font'):
|
temp_y = self.display_manager.matrix.height - 8 # Position at bottom with small margin
|
||||||
# For BDF fonts, we need to calculate width manually and use _draw_bdf_text
|
draw.text((center_x - temp_width // 2, temp_y),
|
||||||
temp_width = self.display_manager.get_text_width(temp_text, self.display_manager.matrix_light6_font)
|
temp_text,
|
||||||
# Calculate y position for BDF font at bottom
|
font=self.display_manager.extra_small_font,
|
||||||
self.display_manager.matrix_light6_font.load_char('A')
|
fill=self.COLORS['text'])
|
||||||
font_height = self.display_manager.matrix_light6_font.glyph.bitmap.rows
|
|
||||||
temp_y = self.display_manager.matrix.height - font_height - 1 # Position at bottom with small margin
|
|
||||||
self.display_manager._draw_bdf_text(temp_text, center_x - temp_width // 2, temp_y, self.COLORS['text'], self.display_manager.matrix_light6_font)
|
|
||||||
else:
|
|
||||||
# Fallback to extra_small font
|
|
||||||
temp_width = draw.textlength(temp_text, font=self.display_manager.extra_small_font)
|
|
||||||
temp_y = self.display_manager.matrix.height - 8 # Position at bottom with small margin
|
|
||||||
draw.text((center_x - temp_width // 2, temp_y),
|
|
||||||
temp_text,
|
|
||||||
font=self.display_manager.extra_small_font,
|
|
||||||
fill=self.COLORS['text'])
|
|
||||||
|
|
||||||
# Update the display
|
# Update the display
|
||||||
self.display_manager.image = image
|
self.display_manager.image = image
|
||||||
|
|||||||
@@ -1,69 +0,0 @@
|
|||||||
#!/usr/bin/env python3
|
|
||||||
|
|
||||||
import sys
|
|
||||||
import os
|
|
||||||
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
|
||||||
|
|
||||||
from src.display_manager import DisplayManager
|
|
||||||
from src.config_manager import ConfigManager
|
|
||||||
from PIL import Image, ImageDraw
|
|
||||||
import freetype
|
|
||||||
|
|
||||||
def test_matrix_light6_font():
|
|
||||||
"""Test the MatrixLight6 font rendering."""
|
|
||||||
print("Testing MatrixLight6 font rendering...")
|
|
||||||
|
|
||||||
# Load config
|
|
||||||
config_manager = ConfigManager()
|
|
||||||
config = config_manager.get_config()
|
|
||||||
|
|
||||||
# Initialize display manager
|
|
||||||
display_manager = DisplayManager(config)
|
|
||||||
|
|
||||||
# Test if the font was loaded
|
|
||||||
if hasattr(display_manager, 'matrix_light6_font'):
|
|
||||||
print(f"MatrixLight6 font loaded: {type(display_manager.matrix_light6_font)}")
|
|
||||||
if isinstance(display_manager.matrix_light6_font, freetype.Face):
|
|
||||||
print(f"Font size: {display_manager.matrix_light6_font.size.height >> 6} pixels")
|
|
||||||
else:
|
|
||||||
print("Font is not a FreeType face")
|
|
||||||
else:
|
|
||||||
print("MatrixLight6 font not found")
|
|
||||||
return
|
|
||||||
|
|
||||||
# Test text rendering
|
|
||||||
test_text = "45 / 67"
|
|
||||||
print(f"Testing text: '{test_text}'")
|
|
||||||
|
|
||||||
# Create a test image
|
|
||||||
image = Image.new('RGB', (display_manager.matrix.width, display_manager.matrix.height))
|
|
||||||
draw = ImageDraw.Draw(image)
|
|
||||||
|
|
||||||
# Try to render the text using the BDF font
|
|
||||||
try:
|
|
||||||
# Calculate width
|
|
||||||
text_width = display_manager.get_text_width(test_text, display_manager.matrix_light6_font)
|
|
||||||
print(f"Calculated width: {text_width}")
|
|
||||||
|
|
||||||
# Calculate position (center)
|
|
||||||
x = (display_manager.matrix.width - text_width) // 2
|
|
||||||
y = 10
|
|
||||||
|
|
||||||
print(f"Drawing at position: ({x}, {y})")
|
|
||||||
|
|
||||||
# Draw the text
|
|
||||||
display_manager._draw_bdf_text(test_text, x, y, (255, 255, 255), display_manager.matrix_light6_font)
|
|
||||||
|
|
||||||
# Update the display
|
|
||||||
display_manager.image = image
|
|
||||||
display_manager.update_display()
|
|
||||||
|
|
||||||
print("Text should be displayed on the matrix")
|
|
||||||
|
|
||||||
except Exception as e:
|
|
||||||
print(f"Error rendering text: {e}")
|
|
||||||
import traceback
|
|
||||||
traceback.print_exc()
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
|
||||||
test_matrix_light6_font()
|
|
||||||
Reference in New Issue
Block a user