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

Using cleartype anti aliasing makes dark foreground invisible on light background. #5098

Closed
alexFrankfurt opened this issue Mar 24, 2020 · 3 comments · Fixed by #5277
Closed
Assignees
Labels
Area-Rendering Text rendering, emoji, complex glyph & font-fallback issues Issue-Bug It either shouldn't be doing this or needs an investigation. Priority-1 A description (P1) Product-Terminal The new Windows Terminal. Resolution-Fix-Committed Fix is checked in, but it might be 3-4 weeks until a release.
Milestone

Comments

@alexFrankfurt
Copy link

alexFrankfurt commented Mar 24, 2020

Environment

Windows build number: 10.0.18363.0
Windows Terminal version: 0.10.781.0
Powershell version: 7.0.0

Steps to reproduce

Setting profile settings to following:

{
    "useAcrylic": false,
    "closeOnExit" : true,
    "colorScheme" : "Campbell",
    "guid": "{a3c89eef-1dbe-4ac1-acc5-2412499f8619}",
    "hidden": false,
    "name": "PowerShell 7",
    "commandline" : "C:\\Program Files\\PowerShell\\7\\pwsh.exe",
    "icon" : "C:\\Program Files\\PowerShell\\7\\assets\\Powershell_av_colors.ico",
    "antialiasingMode": "grayscale",
    "cursorShape" : "bar",
    "cursorColor": "#121005",
    "fontFace" : "Consolas",
    "fontSize" : 10,
    "snapOnInput" : true,
    "historySize" : 9001
}

and theme settings to:

{
    "name" : "Campbell",

    "foreground" : "#020200",
    "background" : "#ffffff",
    "selectionBackground": "#121005",

    "black" : "#0C0C0C",
    "blue" : "#0037DA",
    "brightBlack" : "#767676",
    "brightBlue" : "#3B78FF",
    "brightCyan" : "#61D6D6",
    "brightGreen" : "#16C60C",
    "brightPurple" : "#B4009E",
    "brightRed" : "#E74856",
    "brightWhite" : "#121212",
    "brightYellow" : "#3B78FF",
    "cyan" : "#3A96DD",
    "green" : "#13A10E",
    "purple" : "#881798",
    "red" : "#C50F1F",
    "white" : "#CCCCCC",
    "yellow" : "#C19C00"
}

Expected behavior

Black text F:\> is visible. When antialiasingMode is set to cleartype.

Actual behavior

Black text F:\> is invisible after setting antialiasingMode to cleartype (on the right):
image
Same issue with cmd ("acrylicOpacity" : 0.75):
image

@ghost ghost added Needs-Triage It's a new issue that the core contributor team needs to triage at the next triage meeting Needs-Tag-Fix Doesn't match tag requirements labels Mar 24, 2020
@zadjii-msft zadjii-msft added Area-Rendering Text rendering, emoji, complex glyph & font-fallback issues Issue-Bug It either shouldn't be doing this or needs an investigation. Product-Terminal The new Windows Terminal. labels Mar 24, 2020
@ghost ghost removed the Needs-Tag-Fix Doesn't match tag requirements label Mar 24, 2020
@zadjii-msft zadjii-msft added this to the Terminal v1.0 milestone Mar 24, 2020
@DHowett-MSFT DHowett-MSFT added Priority-1 A description (P1) and removed Needs-Triage It's a new issue that the core contributor team needs to triage at the next triage meeting labels Mar 26, 2020
@zadjii-msft
Copy link
Member

zadjii-msft commented Apr 6, 2020

I'll be damned that repros for me immediately

Huh, seems like we're doing some weird blending for cleartype text:
image

@zadjii-msft zadjii-msft self-assigned this Apr 6, 2020
@zadjii-msft
Copy link
Member

Yikes okay, I'm reading more about this problem and this is sounding harder the more I read about it.

Basically, if you want to use cleartype text, you want to make sure to give the DX target a background behind the cleartext text. Otherwise, it can't really figure out how to blend the cleartype text. We're currently not giving the text a background for the default background color, as to support acrylic. So our dx render target will have a transparent BG, and the entire swapchain is drawn on top of the acrylic background.

I think I can patch this, but I think this basically means that if you want cleartype text, you can't have acrylic, and vice-versa. Since we're able to hot-reload and dynamically change acrylic opacity, but not the antialiasing mode, I think this means we'll need to have cleartype disable acrylic opacity entirely.

Unless there were some way to have the transparent parts of the swapchain not added to the underlying surface, but that's still not the right solution. DWrite just really doesn't want to let us have cleartype on a target where there's no BG already. It also seems like we can't get the rendered acrylic surface before we paint a DX frame to try and manually set that as the background for the target.

Or maybe there's something else I can do with D2D1_LAYER_OPTIONS1_IGNORE_ALPHA? I've got no idea if that'll work

@ghost ghost added the In-PR This issue has a related PR label Apr 7, 2020
@ghost ghost closed this as completed in #5277 Apr 24, 2020
@ghost ghost removed the In-PR This issue has a related PR label Apr 24, 2020
ghost pushed a commit that referenced this issue Apr 24, 2020
## Summary of the Pull Request

When we're on acrylic, we can't have cleartype text unfortunately. This PR changes the DX renderer to force cleartype runs of text that are on a non-opaque background to use grayscale AA instead.

## References

Here are some of the URLS I was referencing as writing this:

* https://stackoverflow.com/q/23587787
* https://docs.microsoft.com/en-us/windows/win32/direct2d/supported-pixel-formats-and-alpha-modes#cleartype-and-alpha-modes
* https://devblogs.microsoft.com/oldnewthing/20150129-00/?p=44803
* https://docs.microsoft.com/en-us/windows/win32/api/d2d1/ne-d2d1-d2d1_layer_options
* https://docs.microsoft.com/en-us/windows/win32/direct2d/direct2d-layers-overview#d2d1_layer_parameters1-and-d2d1_layer_options1
* https://docs.microsoft.com/en-us/windows/win32/api/dcommon/ne-dcommon-d2d1_alpha_mode?redirectedfrom=MSDN#cleartype-and-alpha-modes
* https://stackoverflow.com/a/26523006

Additionally:
* This was introduced in #4711 

## PR Checklist
* [x] Closes #5098
* [x] I work here
* [ ] Tests added/passed
* [n/a] Requires documentation to be updated

## Detailed Description of the Pull Request / Additional comments

Basically, if you use cleartype on a light background, what you'll get today is the text foreground color _added_ to the background. This will make the text look basically invisible. 

So, what I did was use some trickery with `PushLayer` to basically create a layer where the text would be forced to render in grayscale AA. I only enable this layer pushing business when both:
  * The user has enabled cleartype text
  * The background opacity < 1.0

This plumbs some information through from the TermControl to the DX Renderer to make this smooth.

## Validation Steps Performed

Opened both cleartype and grayscale panes SxS, and messed with the opacity liberally.
@ghost ghost added the Resolution-Fix-Committed Fix is checked in, but it might be 3-4 weeks until a release. label Apr 24, 2020
@ghost
Copy link

ghost commented May 5, 2020

🎉This issue was addressed in #5277, which has now been successfully released as Windows Terminal Release Candidate v0.11.1251.0 (1.0rc1).:tada:

Handy links:

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Rendering Text rendering, emoji, complex glyph & font-fallback issues Issue-Bug It either shouldn't be doing this or needs an investigation. Priority-1 A description (P1) Product-Terminal The new Windows Terminal. Resolution-Fix-Committed Fix is checked in, but it might be 3-4 weeks until a release.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants