Fix font loading in NHL managers - Use available 4x6-font.ttf as primary font - Add PressStart2P-Regular.ttf as fallback - Improve font loading error handling with detailed logging

This commit is contained in:
ChuckBuilds
2025-04-18 11:10:09 -05:00
parent 2b6cbcbbc8
commit 95ea58e03e

View File

@@ -36,10 +36,6 @@ class BaseNHLManager:
self.display_width = int(cols * chain) self.display_width = int(cols * chain)
self.display_height = hardware_config.get("rows", 32) self.display_height = hardware_config.get("rows", 32)
# Load fonts
self.font = ImageFont.truetype("assets/fonts/4x6.bdf", 6)
self.small_font = ImageFont.truetype("assets/fonts/3x5.bdf", 5)
# Cache for loaded logos # Cache for loaded logos
self._logo_cache = {} self._logo_cache = {}
@@ -51,16 +47,28 @@ class BaseNHLManager:
"""Load fonts used by the scoreboard.""" """Load fonts used by the scoreboard."""
fonts = {} fonts = {}
try: try:
fonts['score'] = ImageFont.truetype("arial.ttf", 12) # Try to load the 4x6 font for scores
fonts['time'] = ImageFont.truetype("arial.ttf", 10) fonts['score'] = ImageFont.truetype("assets/fonts/4x6-font.ttf", 12)
fonts['team'] = ImageFont.truetype("arial.ttf", 8) fonts['time'] = ImageFont.truetype("assets/fonts/4x6-font.ttf", 10)
fonts['status'] = ImageFont.truetype("arial.ttf", 9) fonts['team'] = ImageFont.truetype("assets/fonts/4x6-font.ttf", 8)
fonts['status'] = ImageFont.truetype("assets/fonts/4x6-font.ttf", 9)
logging.info("[NHL] Successfully loaded 4x6 font for all text elements")
except IOError: except IOError:
logging.warning("[NHL] Arial font not found, using default PIL font.") logging.warning("[NHL] 4x6 font not found, trying PressStart2P font.")
fonts['score'] = ImageFont.load_default() try:
fonts['time'] = ImageFont.load_default() # Try to load the PressStart2P font as a fallback
fonts['team'] = ImageFont.load_default() fonts['score'] = ImageFont.truetype("assets/fonts/PressStart2P-Regular.ttf", 12)
fonts['status'] = ImageFont.load_default() fonts['time'] = ImageFont.truetype("assets/fonts/PressStart2P-Regular.ttf", 10)
fonts['team'] = ImageFont.truetype("assets/fonts/PressStart2P-Regular.ttf", 8)
fonts['status'] = ImageFont.truetype("assets/fonts/PressStart2P-Regular.ttf", 9)
logging.info("[NHL] Successfully loaded PressStart2P font for all text elements")
except IOError:
logging.warning("[NHL] PressStart2P font not found, using default PIL font.")
# Use default PIL font as a last resort
fonts['score'] = ImageFont.load_default()
fonts['time'] = ImageFont.load_default()
fonts['team'] = ImageFont.load_default()
fonts['status'] = ImageFont.load_default()
return fonts return fonts
def _load_and_resize_logo(self, team_abbrev: str) -> Optional[Image.Image]: def _load_and_resize_logo(self, team_abbrev: str) -> Optional[Image.Image]: