From 430f0cbee1ce00111e4580e613f11f4100b13dc3 Mon Sep 17 00:00:00 2001 From: alvroble <50918598+alvroble@users.noreply.github.com> Date: Mon, 16 Jun 2025 19:20:10 +0200 Subject: [PATCH] Remove "libraqm not supported" tweaks --- src/seedsigner/gui/components.py | 16 ---------------- tests/screenshot_generator/generator.py | 11 ++++++----- 2 files changed, 6 insertions(+), 21 deletions(-) diff --git a/src/seedsigner/gui/components.py b/src/seedsigner/gui/components.py index eecc407d..2c9dfffb 100644 --- a/src/seedsigner/gui/components.py +++ b/src/seedsigner/gui/components.py @@ -432,10 +432,6 @@ class TextArea(BaseComponent): self.text_y = self.text_height_above_baseline self.visible_width = self.width - max(self.edge_padding, self.min_text_x) - self.edge_padding - if not ImageFont.core.HAVE_RAQM: - # Fudge factor for imprecise width calcs w/out libraqm - full_text_width = int(full_text_width * 1.05) - self.visible_width = int(self.visible_width * 1.05) if self.is_horizontal_scrolling_enabled or not self.auto_line_break: # Guaranteed to be a single line of text, possibly wider than self.width @@ -589,10 +585,6 @@ class TextArea(BaseComponent): self.rendered_text_img = img - if not ImageFont.core.HAVE_RAQM: - # At this point we need the visible_width to be the "actual" (yet still incorrect) width - self.visible_width = int(self.visible_width * 0.95) - self.horizontal_text_scroll_thread: TextArea.HorizontalTextScrollThread = None if self.is_horizontal_scrolling_enabled: self.horizontal_text_scroll_thread = TextArea.HorizontalTextScrollThread( @@ -1843,10 +1835,6 @@ def reflow_text_for_width(text: str, # Measure from left baseline ("ls") (left, top, full_text_width, px_below_baseline) = font.getbbox(text, anchor="ls") - if not ImageFont.core.HAVE_RAQM: - # Fudge factor for imprecise width calcs w/out libraqm - full_text_width = int(full_text_width * 1.05) - # Assume we can break Asian text on any character treat_chars_as_words = Settings.get_instance().get_value(SettingsConstants.SETTING__LOCALE) in [ SettingsConstants.LOCALE__CHINESE_SIMPLIFIED, @@ -1880,10 +1868,6 @@ def reflow_text_for_width(text: str, (left, top, right, px_below_baseline) = font.getbbox(word_spacer.join(words[0:index]), anchor="ls") line_width = right - left - if not ImageFont.core.HAVE_RAQM: - # Fudge factor for imprecise width calcs w/out libraqm - line_width = int(line_width * 1.05) - if line_width >= width: # Candidate line is still too long. Restrict search range down. if min_index + 1 == index: diff --git a/tests/screenshot_generator/generator.py b/tests/screenshot_generator/generator.py index bd877174..fce87164 100644 --- a/tests/screenshot_generator/generator.py +++ b/tests/screenshot_generator/generator.py @@ -6,6 +6,7 @@ import random import sys import time from unittest.mock import Mock, patch, MagicMock +from PIL import ImageFont from embit import compact from embit.psbt import PSBT, OutputScope @@ -21,9 +22,6 @@ sys.modules['RPi.GPIO'] = MagicMock() sys.modules['seedsigner.hardware.camera'] = MagicMock() sys.modules['seedsigner.hardware.microsd'] = MagicMock() -# Force the screenshots to mimic Pi Zero's output without libraqm -patch('PIL.ImageFont.core.HAVE_RAQM', False).start() - from seedsigner.controller import Controller from seedsigner.gui.components import GUIConstants from seedsigner.gui.renderer import Renderer @@ -47,8 +45,6 @@ from .utils import ScreenshotComplete, ScreenshotConfig, ScreenshotRenderer import warnings; warnings.warn = lambda *args, **kwargs: None - - # Dynamically generate a pytest test run for each locale @pytest.mark.parametrize("locale", [x for x, y in SettingsConstants.get_detected_languages()]) def test_generate_all(locale, target_locale): @@ -60,6 +56,11 @@ def test_generate_all(locale, target_locale): if target_locale and locale != target_locale: pytest.skip(f"Skipping {locale}") + if not ImageFont.core.HAVE_RAQM: + # We can't generate pixel-perfect screenshots that match what gets rendered on + # the device if we don't have libraqm. + pytest.fail("libraqm is not installed.") + generate_screenshots(locale)