From d82f40c4fa7c578e9d7f3565cab5e8fff926751a Mon Sep 17 00:00:00 2001 From: GitHub Copilot Date: Sat, 24 Jan 2026 18:51:10 +0000 Subject: [PATCH] Fix character alignment with textLength attribute Use SVG textLength and lengthAdjust='spacingAndGlyphs' to enforce exact character spacing, preventing gaps between box-drawing and other characters that may render at slightly different widths. Also include whitespace spans in output for proper alignment. --- src/textual_webterm/svg_exporter.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/textual_webterm/svg_exporter.py b/src/textual_webterm/svg_exporter.py index 0d5353b..e2b7978 100644 --- a/src/textual_webterm/svg_exporter.py +++ b/src/textual_webterm/svg_exporter.py @@ -191,8 +191,8 @@ def render_terminal_svg( f'fill="{span["bg"]}"/>' ) - if not text or (text.isspace() and not span["has_bg"]): - # Skip empty spans without background, but advance position + if not text: + # Skip truly empty spans (wide char placeholders already counted) x += columns * char_width continue @@ -208,14 +208,19 @@ def render_terminal_svg( for span in spans: text = span["text"] columns = span["columns"] - if not text or (text.isspace() and not span["has_bg"]): - # Skip empty spans without background, but advance position + if not text: + # Skip truly empty spans x += columns * char_width continue # Build tspan attributes attrs = [f'x="{x:.1f}"'] + # Use textLength to enforce exact character spacing for alignment + span_width = columns * char_width + attrs.append(f'textLength="{span_width:.1f}"') + attrs.append('lengthAdjust="spacingAndGlyphs"') + # Foreground color if span["fg"] != foreground: attrs.append(f'fill="{span["fg"]}"')