Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] Underscores on the last captured line are clipped when exporting to SVG #3576

Open
dottspina opened this issue Nov 28, 2024 · 1 comment

Comments

@dottspina
Copy link

dottspina commented Nov 28, 2024

Underscore characters on the last captured line are clipped when exporting to SVG.

Easily reproducible (rich 13.9.4):

console = Console(record=True)
console.print("STRING_WITH_UNDERSCORE_CHARS")
console.save_svg("test.svg")

When opening the SVG file in a browser or an image viewer, underscores look like white spaces:

clipped-underscore-chars

Reading the SVG source, we can see that:

  • the text string indeed contains _ and not white spaces
  • the underscores are actually clipped by the main <cliPath> (the one whose identifier ends with "clip-terminal"), giving it a little more height reveals the _

expected-underscore-chars

In the test example:

  • the viewbox height is 74.4
  • the terminal <cliPath> height is 23.4
  • the terminal group is translated to 41 on the vertical axis (as always)

Adding 23.4 to 41, we're at 64.4 on the vertical axis, about 10px above the end of the viewbox. My 2 cents is that it is too much.

Still my 2 cents:

  • the height of the main <rect> (the one that sets the background) equals to (y + 1) * line_height + padding_top + padding_bottom
  • the height of the terminal group equals to (y + 1) * line_height - 1 : I understand we don't have to take padding_top into account (we're translated bellow the padding on the vertical axis), but shouldn't we still add padding_bottom ?
--- console.py
+++ console.py
@@ -2623,7 +2623,7 @@
             char_height=char_height,
             line_height=line_height,
             terminal_width=char_width * width - 1,
-            terminal_height=(y + 1) * line_height - 1,
+            terminal_height=(y + 1) * line_height - 1 + padding_bottom,
             width=terminal_width + margin_width,
             height=terminal_height + margin_height,
             terminal_x=margin_left + padding_left,

This is how I generated the SVG where the underscores aren't clipped. Which does not prove that my reasoning is correct, 8 may very well be a value that falls just right, and incidentally equal to padding_bottom.

BTW, thanks for the good work, DTSh could hardly be what it (humbly) is without this library.

Copy link

Thank you for your issue. Give us a little time to review it.

PS. You might want to check the FAQ if you haven't done so already.

This is an automated reply, generated by FAQtory

dottspina added a commit to dottspina/dtsh that referenced this issue Dec 9, 2024
Workaround upstream rich library issue 3576:
Underscores on the last captured line are clipped
when exporting to SVG.

The main <clipPath> height computed
by the rich library in Console.export_svg() is a bit too small,
and the bottom of the last captured output line may be truncated,
depending on the font and the printed characters (e.g. underscores,
but also the bottom of the letter 'y').

This workaround adds the bottom padding to the height computed
by the rich library.

Ref:
- #8
- Textualize/rich#3576
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant