From e49ffdf1540f92a8b25ab8bae54169ea4cab4d51 Mon Sep 17 00:00:00 2001 From: ChuckBuilds <33324927+ChuckBuilds@users.noreply.github.com> Date: Tue, 22 Apr 2025 19:31:53 -0500 Subject: [PATCH] feat: update font test to include MatrixChunky6 font --- src/font_test_manager.py | 63 +++++++++++++++++++++++----------------- 1 file changed, 37 insertions(+), 26 deletions(-) diff --git a/src/font_test_manager.py b/src/font_test_manager.py index 6fe5643b..dfa57b84 100644 --- a/src/font_test_manager.py +++ b/src/font_test_manager.py @@ -10,28 +10,32 @@ logging.basicConfig(level=logging.INFO) logger = logging.getLogger(__name__) class FontTestManager: - """Manager for testing different font sizes of 4x6 font.""" + """Manager for testing different font sizes of multiple fonts.""" def __init__(self, config: Dict[str, Any], display_manager: DisplayManager): self.display_manager = display_manager self.config = config - self.font_path = "assets/fonts/4x6-font.ttf" + self.fonts = { + "4x6": "assets/fonts/4x6-font.ttf", + "MatrixChunky6": "assets/fonts/MatrixChunky6.ttf" + } self.font_sizes = [4, 6, 8, 10, 12, 14, 16, 18] self.logger = logging.getLogger('FontTest') - # Verify font exists - if not os.path.exists(self.font_path): - self.logger.error(f"Font file not found: {self.font_path}") - raise FileNotFoundError(f"Font file not found: {self.font_path}") + # Verify fonts exist + for font_name, font_path in self.fonts.items(): + if not os.path.exists(font_path): + self.logger.error(f"Font file not found: {font_path}") + raise FileNotFoundError(f"Font file not found: {font_path}") - self.logger.info(f"Initialized FontTestManager with {len(self.font_sizes)} font sizes to test using 4x6 font") + self.logger.info(f"Initialized FontTestManager with {len(self.font_sizes)} font sizes to test using {len(self.fonts)} fonts") def update(self): """No update needed for static display.""" pass def display(self, force_clear: bool = False): - """Display all font sizes at once across the screen.""" + """Display all font sizes at once across the screen for each font.""" try: # Clear the display self.display_manager.clear() @@ -44,27 +48,34 @@ class FontTestManager: total_sizes = len(self.font_sizes) spacing = width // (total_sizes + 1) # Add 1 to account for edges - # Draw each font size + # Draw each font draw = ImageDraw.Draw(self.display_manager.image) - for i, size in enumerate(self.font_sizes): - # Load the font at the current size - font = ImageFont.truetype(self.font_path, size) + for font_name, font_path in self.fonts.items(): + # Draw font name at the top + font_name_y = 2 if font_name == "4x6" else height - 10 + self.display_manager.draw_text(font_name, y=font_name_y, color=(255, 255, 255)) - # Create text to display (the size number) - text = str(size) - - # Get text dimensions - bbox = draw.textbbox((0, 0), text, font=font) - text_width = bbox[2] - bbox[0] - text_height = bbox[3] - bbox[1] - - # Calculate position to center the text horizontally and vertically - x = spacing * (i + 1) - (text_width // 2) - y = (height - text_height) // 2 - - # Draw the text - draw.text((x, y), text, font=font, fill=(255, 255, 255)) + # Draw each font size + for i, size in enumerate(self.font_sizes): + # Load the font at the current size + font = ImageFont.truetype(font_path, size) + + # Create text to display (the size number) + text = str(size) + + # Get text dimensions + bbox = draw.textbbox((0, 0), text, font=font) + text_width = bbox[2] - bbox[0] + text_height = bbox[3] - bbox[1] + + # Calculate position to center the text horizontally + x = spacing * (i + 1) - (text_width // 2) + # Position vertically based on font type + y = 10 if font_name == "4x6" else height - 20 + + # Draw the text + draw.text((x, y), text, font=font, fill=(255, 255, 255)) # Update the display once self.display_manager.update_display()