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

AtlasEngine: Clip box glyphs to their cells #15343

Merged
merged 1 commit into from
May 15, 2023

Conversation

lhecker
Copy link
Member

@lhecker lhecker commented May 13, 2023

Overhangs for box glyphs can produce unsightly effects, where the
antialiased edges of horizontal and vertical lines overlap between
neighboring glyphs and produce "boldened" intersections.
This avoids the issue in most cases by simply clipping the glyph to the
size of a single cell. The downside is that it fails to work well for
custom line heights, etc.

Validation Steps Performed

  • With Cascadia Code, printing "`u{2593}`n`u{2593}" in pwsh
    doesn't produce a brightened overlap anymore ✅
  • "`e#3`u{2502}`n`e#4`u{2502}" produces a fat vertical line ✅

@lhecker lhecker force-pushed the dev/lhecker/atlas-engine-box-glyphs branch 2 times, most recently from 1e4b8dc to 81ac511 Compare May 15, 2023 16:03
@lhecker
Copy link
Member Author

lhecker commented May 15, 2023

Comparison, Cascadia Code 12pt (note the lines in the left half in particular):

comparison

@lhecker lhecker added this to the Terminal v1.18 milestone May 15, 2023
@lhecker lhecker added the Issue-Bug It either shouldn't be doing this or needs an investigation. label May 15, 2023
Copy link
Member

@DHowett DHowett left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

block for base merge

@microsoft-github-policy-service microsoft-github-policy-service bot added the Needs-Author-Feedback The original author of the issue/PR needs to come back and respond to something label May 15, 2023
@lhecker lhecker force-pushed the dev/lhecker/atlas-engine-box-glyphs branch from 81ac511 to 37a63b7 Compare May 15, 2023 18:52
@microsoft-github-policy-service microsoft-github-policy-service bot removed the Needs-Author-Feedback The original author of the issue/PR needs to come back and respond to something label May 15, 2023
Comment on lines +1377 to +1382
if (needsTransform)
{
transform.dx = (1.0f - transform.m11) * baselineOrigin.x;
transform.dy = (1.0f - transform.m22) * baselineOrigin.y;
_d2dRenderTarget->SetTransform(&transform);
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code moved down from line 1302, because calculating the PushAxisAlignedClip rectangle is much simpler that way (the transform is still in absolute coordinates, instead of being relative to the baseline origin of the glyph).

@lhecker lhecker marked this pull request as ready for review May 15, 2023 18:55
Comment on lines +1148 to +1151
ALLOW_UNINITIALIZED_BEGIN
std::array<u32, 0x100> codepoints;
std::array<u16, 0x100> indices;
ALLOW_UNINITIALIZED_END
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This avoids zero-initializing 1536 bytes of stack. The cost of that alone is almost as much as the entire cost of the function lol (apart from GetGlyphIndicesW which we don't have much control over).

Copy link
Member

@DHowett DHowett left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't work for BackendD2D, does it?

codepoints[i] = 0x2500 + i;
}

THROW_IF_FAILED(fontFaceEntry.fontFace->GetGlyphIndicesW(codepoints.data(), codepoints.size(), indices.data()));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so I understand: this function caches every glyph ID from the font that mapped to a box drawing character?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep exactly. The alternative is to check the codepoints during text shaping, but I felt like that would be just as bad for code complexity. This approach has the additional benefit that it only needs to run the box-glyph specific logic once, when the glyph is rasterized, and not every time the text is shaped. Just like the alternative approach (checking codepoints) it only works for basic cmap mappings though (so no substitutions, etc.).

@lhecker
Copy link
Member Author

lhecker commented May 15, 2023

This doesn't work for BackendD2D, does it?

Yeah, it doesn't. It wouldn't be too difficult to do the same codepoint-caching trick for BackendD2D though, if we ever need the D2D text renderer to be better.

@DHowett
Copy link
Member

DHowett commented May 15, 2023

@lhecker I am marking this one up for 1.18

@lhecker lhecker merged commit 4628ceb into main May 15, 2023
@lhecker lhecker deleted the dev/lhecker/atlas-engine-box-glyphs branch May 15, 2023 22:05
DHowett pushed a commit that referenced this pull request May 15, 2023
Overhangs for box glyphs can produce unsightly effects, where the
antialiased edges of horizontal and vertical lines overlap between
neighboring glyphs and produce "boldened" intersections.
This avoids the issue in most cases by simply clipping the glyph to the
size of a single cell. The downside is that it fails to work well for
custom line heights, etc.

## Validation Steps Performed

* With Cascadia Code, printing ``"`u{2593}`n`u{2593}"`` in pwsh
  doesn't produce a brightened overlap anymore ✅
* ``"`e#3`u{2502}`n`e#4`u{2502}"`` produces a fat vertical line ✅

(cherry picked from commit 4628ceb)
Service-Card-Id: 89213363
Service-Version: 1.18
microsoft-github-policy-service bot pushed a commit that referenced this pull request May 25, 2023
Woops. Regressed in #15343. Fixes #15409.

## Validation Steps Performed
* Run `RenderingTests.exe`
* Soft fonts work ✅
DHowett pushed a commit that referenced this pull request May 25, 2023
Woops. Regressed in #15343. Fixes #15409.

## Validation Steps Performed
* Run `RenderingTests.exe`
* Soft fonts work ✅

(cherry picked from commit 245b13b)
Service-Card-Id: 89323212
Service-Version: 1.18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-AtlasEngine Issue-Bug It either shouldn't be doing this or needs an investigation.
Projects
Development

Successfully merging this pull request may close these issues.

3 participants