-
Notifications
You must be signed in to change notification settings - Fork 8.4k
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
DBCS characters rendered incorrectly when scrolling horizontally in conhost #8390
Comments
As far as I can tell, the problem is in the terminal/src/renderer/base/renderer.cpp Lines 767 to 783 in 26ca73b
But as you can see, if the X position is already in column 0, it instead moves forward one position and "skips" that character. At least that's the intention, but the code doesn't actually increment the iterator, so it just ends up rendering the character in the wrong place. And even if it worked as intended, at best you're going to end up with half a character not rendered. My suggested fix for this is just to drop that check. If the X position is already in column 0, let it go negative. It should then paint the character exactly as expected, with half of it off screen. At least that seems to work for the GDI engine. But that brings us to the next problem. When we're dealing with the second half of a DBCS char, the terminal/src/renderer/base/renderer.cpp Lines 797 to 799 in 26ca73b
My suggested fix is to use the it += std::max<size_t>(it->Columns(), 1); I'm not sure if we still need to make sure the increment is non-zero, but it probably wouldn't harm. |
I believe @miniksa changed something in here recently (after 1836x, as you've observed) that fixed an issue with ConPTY; blame might be enlightening here. 😄 Otherwise, this looks like the right fix. I hope we have test coverage for the ConPTY thing! |
@DHowett I think the PR you're thinking of is #4668, but that didn't introduce this bug. It was an attempt to fix a related issue with fullwidth glyphs (#2191), but didn't correctly handle this particular case. I've now created a PR with my proposed changes, and confirmed that the test cases described in #2191 are still working correctly with those changes. However, I should note that the #2191 issue is no longer reproducible in Terminal even with this whole section commented out (i.e. the fix introduced in #4668). I suspect that might be because the DX engine now always invalidates a full line at a time. I could reproduce the problem with the GDI engine in conhost, though, so could confirm that the fix does still work there. |
When the renderer is called on to render part of a line starting halfway through a DBCS character (as can occur in conhost when the viewport is offset horizontally), it could result in the character not being displayed, and/or with following the characters drawn in the wrong place. This PR is an attempt to fix those problems. The original code for handling the trailing half of fullwidth glyphs was introduced in PR #4668 to fix issue #2191. When the content being rendered starts with the trailing half of a DBCS character, the renderer tries to move the `screenPoint` back a position, so it can instead render the full character, but instructing the render engine to trim off the left half of it. If the X position was already in column 0, though, it would instead move forward one position, intending to skip that character. At best this would mean the half character wouldn't be rendered, but since the iterator wasn't incremented correctly, it actually just ended up rendering the character in the wrong place. The fix for this was simply to drop the check for the X position being in column 0, and allow it go negative. The rendering engine would then just start rendering the character partially off screen, and only the second half of it would be displayed, which is exactly what is needed. The second problem was that the code incrementing the iterator was using the `columnCount` variable rather than the `it->Columns()` value for the current position. When dealing with the trailing half of a DBCS character, the `columnCount` is 2, but the `Columns()` value is 1. If you use the former rather than the later, then the renderer may skip the following character. ## Validation Steps Performed I've developed a more easily reproducible version of the test case described in #8390, and confirmed that the problem no longer occurs when this PR is applied. I've also manually confirmed that the problem described in #2191 that was fixed by PR #4668 is still working correctly now. Closes #8390
🎉This issue was addressed in #8438, which has now been successfully released as Handy links: |
Environment
Windows build number: Version 10.0.18363.1198
Windows Terminal version (if applicable): Commit 1fbcf34
Steps to reproduce
子小尒尢
).I should add that I just picked these characters at random from charmap, so my apologies if they mean anything offensive.
Expected behavior
The characters should always be rendered correctly.
Actual behavior
Sometimes the characters get chopped in half, or rendered in the wrong place so they're overlapping other characters.
I can't reproduce this in the conhost that comes with my current version of Windows, so it looks like it might be a regression. But I also checked out the initial commit of OpenConsole and it seems to have already been broken then. Is it possible my version of Windows is so old that it's prior to the first open source release?
Anyway, I think I know what the problem is - a couple of problems actually. I'll try and write up an explanation later with my proposed fix.
The text was updated successfully, but these errors were encountered: