Curly underline is rendered as single #20786

Closed
opened 2026-01-31 07:24:02 +00:00 by claunia · 7 comments
Owner

Originally created by @alabuzhev on GitHub (Nov 10, 2023).

Originally assigned to: @tusharsnx on GitHub.

Windows Terminal version

1.20.3131.0

Windows build number

10.0.19045.3448

Other Software

No response

Steps to reproduce

Originally posted in https://github.com/microsoft/terminal/pull/16097#discussion_r1389476524

  1. Set display scaling to 100%

  2. Run OpenConsole or WT

  3. Set font to Consolas

  4. Set font size to:

    • 34 or smaller for OpenConsole, e.g. 20
    • 19 or smaller for WT, e.g. 12
  5. Run something to showcase new underlines, e.g. this script

@echo off

echo 4:1 [4:1;58:2::255:000:000mtest
echo 4:2 [4:2;58:2::255:255:000mtest
echo 4:3 [4:3;58:2::000:255:000mtest
echo 4:4 [4:4;58:2::000:255:255mtest
echo 4:5 [4:5;58:2::255:000:255mtest

pause

- where � is \x1b, or whatever else you might have.

Expected Behavior

Clearly visible underline styles, curly in particular, e.g.:

image

Actual Behavior

Curly is rendered as single in both OpenConsole and WT:

image

OpenConsole also renders double underline as single, which may or may not be related.


Other terminals, e.g. wezterm, seemingly have no issues with even smaller sizes:

image

Technically it's not too small if the wave height is at least 2 pixels:
image

Additionally, OpenConsole with even smaller sizes, e.g. Consolas 15, doesn't render anything but "double" at all:

image

Technical limitations are understandable, but, assuming that the key selling point of this feature is spellchecking, any ugly/incorrect/clipping/overlapping rendering would be better than nothing at all.

Originally created by @alabuzhev on GitHub (Nov 10, 2023). Originally assigned to: @tusharsnx on GitHub. ### Windows Terminal version 1.20.3131.0 ### Windows build number 10.0.19045.3448 ### Other Software _No response_ ### Steps to reproduce _Originally posted in https://github.com/microsoft/terminal/pull/16097#discussion_r1389476524_ 1. Set display scaling to 100% 2. Run OpenConsole or WT 3. Set font to Consolas 4. Set font size to: - 34 or smaller for OpenConsole, e.g. 20 - 19 or smaller for WT, e.g. 12 5. Run something to showcase new underlines, e.g. this script ``` @echo off echo 4:1 [4:1;58:2::255:000:000mtest echo 4:2 [4:2;58:2::255:255:000mtest echo 4:3 [4:3;58:2::000:255:000mtest echo 4:4 [4:4;58:2::000:255:255mtest echo 4:5 [4:5;58:2::255:000:255mtest pause ``` \- where � is \x1b, or whatever else you might have. ### Expected Behavior Clearly visible underline styles, curly in particular, e.g.: ![image](https://github.com/microsoft/terminal/assets/11453922/1ef33c14-04d0-4156-8f86-53750e0f3578) ### Actual Behavior Curly is rendered as single in both OpenConsole and WT: ![image](https://github.com/microsoft/terminal/assets/11453922/4a03c331-1690-4ade-b352-8a7e9353ec43) *OpenConsole also renders double underline as single, which may or may not be related.* ------ Other terminals, e.g. wezterm, seemingly have no issues with even smaller sizes: ![image](https://github.com/microsoft/terminal/assets/11453922/419b48b2-42a0-4a78-b4d2-03aa670b0d76) Technically it's not *too small* if the wave height is at least 2 pixels: ![image](https://github.com/microsoft/terminal/assets/11453922/d6782c1a-2c47-44b7-93e3-02de8fa6fdf8) Additionally, OpenConsole with even smaller sizes, e.g. Consolas 15, doesn't render anything but "double" at all: ![image](https://github.com/microsoft/terminal/assets/11453922/62f55908-737b-4281-9ef2-5b0a737fb9c5) Technical limitations are understandable, but, assuming that the key selling point of this feature is spellchecking, any ugly/incorrect/clipping/overlapping rendering would be better than nothing at all.
Author
Owner

@tusharsnx commented on GitHub (Nov 10, 2023):

There are two issues in this Issue

1. Curly line drawn as Singly line

Admittedly, I've a high dpi screen which I use at 175% scaling. I guess the threshold we kept for curly underlines can be fine tuned for 100% display scaling. Something that works for 100% should work for 175% as well 🙂

Can someone try a different value for minCurlyLinePeakHeight, and see which one works better at 100% display scaling?

AtlasEngine (WT)

d14524cd4c/src/renderer/atlas/BackendD3D.cpp (L311-L313)

GDI (Conhost)

d14524cd4c/src/renderer/gdi/state.cpp (L410-L432)

In GDI, we have two conditions to check before drawing curly underline:

  1. Underline width is atleast 1px.
  2. Space between cell bottom and underline position is atleast MinCurlyLinePeakHeight (2px).

2. Underlines not visible at smaller font-sizes in Conhost

Additionally, OpenConsole with even smaller sizes, e.g. Consolas 15, doesn't render anything but "double" at all:

I guess the underline offset we're calculating is making underlines to be drawn below the cell bottom, effectively making them not visible at all. A fix could be to clamp the offset within cell boundary🤔 (For me, this happens at font-size 9px with Consolas.)

@tusharsnx commented on GitHub (Nov 10, 2023): There are two issues in this Issue ### 1. Curly line drawn as Singly line Admittedly, I've a high dpi screen which I use at 175% scaling. I guess the threshold we kept for curly underlines can be fine tuned for 100% display scaling. Something that works for 100% should work for 175% as well 🙂 Can someone try a different value for `minCurlyLinePeakHeight`, and see which one works better at 100% display scaling? AtlasEngine (WT) https://github.com/microsoft/terminal/blob/d14524cd4cc4970bb1b6456f9667e2dd661b9854/src/renderer/atlas/BackendD3D.cpp#L311-L313 GDI (Conhost) https://github.com/microsoft/terminal/blob/d14524cd4cc4970bb1b6456f9667e2dd661b9854/src/renderer/gdi/state.cpp#L410-L432 In GDI, we have two conditions to check before drawing curly underline: 1. Underline width is atleast 1px. 2. Space between cell bottom and underline position is atleast `MinCurlyLinePeakHeight` (2px). ### 2. Underlines not visible at smaller font-sizes in Conhost >Additionally, OpenConsole with even smaller sizes, e.g. Consolas 15, doesn't render anything but "double" at all: I guess the underline offset we're calculating is making underlines to be drawn below the cell bottom, effectively making them not visible at all. A fix could be to clamp the offset within cell boundary🤔 (For me, this happens at font-size 9px with Consolas.)
Author
Owner

@j4james commented on GitHub (Nov 10, 2023):

The line offsets should have already been set to their correct positions based on the provided font metrics in the GdiEngine::UpdateFont method. The problem is that we've now added an additional offset at render time here:

d14524cd4c/src/renderer/gdi/paint.cpp (L622-L626)

That's almost certainly wrong. Even if if wasn't pushing the offsets out of range, it doesn't make sense to be altering the value here. What was the reason for this change?

Edit: I see now it's probably because the single and double underline are now rendered with LineTo calls rather than PatBlt. But there must be something wrong with that calculation, because the original line offset should definitely have been in range. Also, if we need that additional half-width offset, that calculation should really be done in advance in the UpdateFont method. There's surely no need to keep recalculating it every time an underline is rendered?

@j4james commented on GitHub (Nov 10, 2023): The line offsets should have already been set to their correct positions based on the provided font metrics in the `GdiEngine::UpdateFont` method. The problem is that we've now added an additional offset at render time here: https://github.com/microsoft/terminal/blob/d14524cd4cc4970bb1b6456f9667e2dd661b9854/src/renderer/gdi/paint.cpp#L622-L626 That's almost certainly wrong. Even if if wasn't pushing the offsets out of range, it doesn't make sense to be altering the value here. What was the reason for this change? Edit: I see now it's probably because the single and double underline are now rendered with `LineTo` calls rather than `PatBlt`. But there must be something wrong with that calculation, because the original line offset should definitely have been in range. Also, if we need that additional half-width offset, that calculation should really be done in advance in the `UpdateFont` method. There's surely no need to keep recalculating it every time an underline is rendered?
Author
Owner

@j4james commented on GitHub (Nov 10, 2023):

Also, assuming you're looking at this code again, note that the underlineWidth should never be less than 1. We've got a check for that here:

d14524cd4c/src/renderer/gdi/state.cpp (L379-L383)

So I think the test below should never be necessary.

d14524cd4c/src/renderer/gdi/state.cpp (L409-L413)

@j4james commented on GitHub (Nov 10, 2023): Also, assuming you're looking at this code again, note that the `underlineWidth` should never be less than 1. We've got a check for that here: https://github.com/microsoft/terminal/blob/d14524cd4cc4970bb1b6456f9667e2dd661b9854/src/renderer/gdi/state.cpp#L379-L383 So I think the test below should never be necessary. https://github.com/microsoft/terminal/blob/d14524cd4cc4970bb1b6456f9667e2dd661b9854/src/renderer/gdi/state.cpp#L409-L413
Author
Owner

@DHowett commented on GitHub (Nov 13, 2023):

I'm gonna pull this one out of the triage queue and assign it to you, Tushar! Let me know if you have any objections. Thanks for working on underlines!

@DHowett commented on GitHub (Nov 13, 2023): I'm gonna pull this one out of the triage queue and assign it to you, Tushar! Let me know if you have any objections. Thanks for working on underlines!
Author
Owner

@DHowett commented on GitHub (Dec 8, 2023):

Hey @tusharsnx, I've got a crazy plan... but it might need this bug fixed for me to pull it off 😁

(are you able to look into it?)

@DHowett commented on GitHub (Dec 8, 2023): Hey @tusharsnx, I've got a crazy plan... but it might need this bug fixed for me to pull it off 😁 (are you able to look into it?)
Author
Owner

@tusharsnx commented on GitHub (Dec 8, 2023):

@DHowett

(are you able to look into it?)

Almost ready! 🙂

@tusharsnx commented on GitHub (Dec 8, 2023): @DHowett > (are you able to look into it?) Almost ready! 🙂
Author
Owner

@DHowett commented on GitHub (Dec 8, 2023):

Okay I definitely thought that's what you meant on Twitter, I just had to make sure!

@DHowett commented on GitHub (Dec 8, 2023): Okay I definitely thought that's what you meant on Twitter, I just had to make sure!
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#20786