From bb0290f576db7f5601f3acc201bbb295f3fda16b Mon Sep 17 00:00:00 2001 From: wjl2023 Date: Tue, 14 Apr 2026 21:28:08 +0800 Subject: [PATCH] fix: normalize bubble text and adjust padding for better readability --- frontends/desktop_pet_v2.pyw | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/frontends/desktop_pet_v2.pyw b/frontends/desktop_pet_v2.pyw index 1eb96ff..ae20f24 100644 --- a/frontends/desktop_pet_v2.pyw +++ b/frontends/desktop_pet_v2.pyw @@ -1,5 +1,6 @@ """Desktop Pet with Skin System — Cross-platform with True Transparency""" import os +import re import sys import json import threading @@ -108,9 +109,21 @@ def _load_default_font(size): return ImageFont.load_default() +def _normalize_bubble_text(text): + """Normalize text for fonts that cannot render some symbols.""" + text = (text or '').strip() + lines = text.replace('\r\n', '\n').replace('\r', '\n').split('\n') + if lines: + turn_match = re.match(r'^\s*🔄?\s*Turn\s+(\d+)\s*$', lines[0], flags=re.IGNORECASE) + if turn_match: + rest = '\n'.join(line.strip() for line in lines[1:] if line.strip()) + return f"Turn {turn_match.group(1)}: {rest}" if rest else f"Turn {turn_match.group(1)}:" + return text.replace('🔄 Turn', 'Turn').replace('🔄', '').strip() + + def _wrap_text_for_width(draw, text, font, max_width): """Wrap text to fit inside max_width.""" - text = (text or '').strip() + text = _normalize_bubble_text(text) if not text: return [''] @@ -157,11 +170,11 @@ def build_bubble_image(message, max_width=220): font = _load_default_font(font_size) draw = ImageDraw.Draw(bubble) - pad_left = max(10, bubble.width // 18) - pad_right = max(10, bubble.width // 18) + max(6, bubble.width // 14) + pad_left = max(12, bubble.width // 16) + pad_right = max(16, bubble.width // 10) pad_top = max(8, bubble.height // 10) - pad_bottom = max(18, bubble.height // 4) - text_area_width = max(40, bubble.width - pad_left - pad_right) + pad_bottom = max(20, bubble.height // 3) + text_area_width = max(36, bubble.width - pad_left - pad_right) lines = _wrap_text_for_width(draw, message, font, text_area_width) ascent, descent = font.getmetrics() if hasattr(font, 'getmetrics') else (font_size, font_size // 4)