mirror of
https://github.com/ChuckBuilds/LEDMatrix.git
synced 2026-04-10 21:03:01 +00:00
add freetype error handling
This commit is contained in:
@@ -8,7 +8,10 @@ from rgbmatrix import graphics
|
|||||||
import pytz
|
import pytz
|
||||||
from src.config_manager import ConfigManager
|
from src.config_manager import ConfigManager
|
||||||
import time
|
import time
|
||||||
|
try:
|
||||||
import freetype
|
import freetype
|
||||||
|
except ImportError:
|
||||||
|
freetype = None
|
||||||
|
|
||||||
# Configure logger for this module
|
# Configure logger for this module
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
@@ -73,7 +76,11 @@ class OfTheDayManager:
|
|||||||
abs_font_path = os.path.abspath(font_path)
|
abs_font_path = os.path.abspath(font_path)
|
||||||
if os.path.exists(abs_font_path):
|
if os.path.exists(abs_font_path):
|
||||||
logger.debug(f"Loading BDF font: {abs_font_path}")
|
logger.debug(f"Loading BDF font: {abs_font_path}")
|
||||||
|
if freetype is not None:
|
||||||
return freetype.Face(abs_font_path)
|
return freetype.Face(abs_font_path)
|
||||||
|
else:
|
||||||
|
logger.warning("freetype module not available, cannot load BDF fonts")
|
||||||
|
return None
|
||||||
|
|
||||||
logger.debug(f"Font file not found: {filename}")
|
logger.debug(f"Font file not found: {filename}")
|
||||||
# List available fonts for debugging
|
# List available fonts for debugging
|
||||||
@@ -377,7 +384,7 @@ class OfTheDayManager:
|
|||||||
"""Draw text for both BDF (FreeType Face) and PIL TTF fonts."""
|
"""Draw text for both BDF (FreeType Face) and PIL TTF fonts."""
|
||||||
try:
|
try:
|
||||||
# If we have a PIL font, use native text rendering
|
# If we have a PIL font, use native text rendering
|
||||||
if not isinstance(face, freetype.Face):
|
if freetype is None or not isinstance(face, freetype.Face):
|
||||||
draw.text((x, y), text, fill=color, font=face)
|
draw.text((x, y), text, fill=color, font=face)
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user