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: Fix uneven baselines when scaling glyphs #14039

Merged
1 commit merged into from Sep 21, 2022

Conversation

lhecker
Copy link
Member

@lhecker lhecker commented Sep 19, 2022

This commit changes the glyph scale algorithm to prefer aligning glyphs to
their baseline. This improves the visual appearance of simulated italic glyphs.
However wide Emojis in narrow cells now look slightly worse without centering.

Closes #13987

Validation Steps Performed

  • Use FiraCode which has no italic variant and instead uses simulated italics
  • Write italic text
  • Baseline is consistent ✅

@lhecker
Copy link
Member Author

lhecker commented Sep 19, 2022

atlas_engine_baseline

@ghost ghost added Area-AtlasEngine Area-Fonts Related to the font Issue-Bug It either shouldn't be doing this or needs an investigation. Priority-3 A description (P3) Product-Terminal The new Windows Terminal. labels Sep 19, 2022
@DHowett
Copy link
Member

DHowett commented Sep 19, 2022

in "new" the vertical stems of letters (primarily r) become more blurry.

@lhecker
Copy link
Member Author

lhecker commented Sep 19, 2022

Ah woops... "Old" is using ClearType and "New" isn't, which makes "Old" appear more crisp. If you open the image in a new tab and zoom in, you can see that the stems are practically identical.

@DHowett
Copy link
Member

DHowett commented Sep 20, 2022

Well, it looks less weird... !

@lhecker
Copy link
Member Author

lhecker commented Sep 20, 2022

Yep, agreed. I'll try to make it work properly and as expected without downsizing in a follow-up PR, but that's probably only for 1.17 by then.

@DHowett DHowett added this to To Cherry Pick in 1.16 Servicing Pipeline via automation Sep 20, 2022
@@ -627,34 +623,27 @@ AtlasEngine::CachedGlyphLayout AtlasEngine::_getCachedGlyphLayout(const wchar_t*
// --> offsetY = 0
// --> scale = layoutBox.y / (layoutBox.y + left + right)
// = 0.69f
offset.x = clampedOverhang.left - clampedOverhang.right;
offset.y = clampedOverhang.top - clampedOverhang.bottom;
offset.x = std::max(0.0f, overhang.left) - std::max(0.0f, overhang.right);
Copy link
Member

Choose a reason for hiding this comment

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

This changes how overhangs are dealt with; do we need to update the explanatory comment above? Specifically I notice that the "bar diacritic" part has a negative left value...

Copy link
Member Author

Choose a reason for hiding this comment

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

No the big comment is still up to date. This particular change (for offset.x) is equivalent to the old code. clampedOverhang used to be computed as:

const DWRITE_OVERHANG_METRICS clampedOverhang{
    std::max(0.0f, overhang.left),
    std::max(0.0f, overhang.top),
    std::max(0.0f, overhang.right),
    std::max(0.0f, overhang.bottom),
};

}
if ((actualSize.y - layoutBox.y) > _r.dipPerPixel)
if (overhang.top > _r.dipPerPixel || overhang.bottom > _r.dipPerPixel)
Copy link
Member

Choose a reason for hiding this comment

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

this is after the overhangs have been sign-adjusted, right?

Copy link
Member Author

Choose a reason for hiding this comment

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

You mean clamped? In that case: No, these are the raw overhangs and a positive value indicates that the glyph clips outside of the layout box we've given it.

// (https://en.wikipedia.org/wiki/ClearType#How_ClearType_works)
offset.x = roundf(offset.x * _r.pixelPerDIP) * _r.dipPerPixel;
// As explained below, we use D2D1_DRAW_TEXT_OPTIONS_NO_SNAP to prevent a weird issue with baseline snapping.
// But we do want it technically, so this re-implements baseline snapping... I think?
Copy link
Member

Choose a reason for hiding this comment

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

reviewer note: comment is not new, don't think too hard about the `... I think?"

@DHowett DHowett added the AutoMerge Marked for automatic merge by the bot when requirements are met label Sep 21, 2022
@ghost
Copy link

ghost commented Sep 21, 2022

Hello @DHowett!

Because this pull request has the AutoMerge label, I will be glad to assist with helping to merge this pull request once all check-in policies pass.

p.s. you can customize the way I help with merging this pull request, such as holding this pull request until a specific person approves. Simply @mention me (@msftbot) and give me an instruction to get started! Learn more here.

@ghost ghost merged commit 97dc5c8 into main Sep 21, 2022
@ghost ghost deleted the dev/lhecker/13987-wavy-baseline branch September 21, 2022 22:30
@DHowett DHowett moved this from To Cherry Pick to Cherry Picked in 1.16 Servicing Pipeline Sep 21, 2022
DHowett pushed a commit that referenced this pull request Sep 21, 2022
This commit changes the glyph scale algorithm to prefer aligning glyphs to
their baseline. This improves the visual appearance of simulated italic glyphs.
However wide Emojis in narrow cells now look slightly worse without centering.

Closes #13987

## Validation Steps Performed
* Use FiraCode which has no italic variant and instead uses simulated italics
* Write italic text
* Baseline is consistent ✅

(cherry picked from commit 97dc5c8)
Service-Card-Id: 85767343
Service-Version: 1.16
@ghost
Copy link

ghost commented Sep 23, 2022

🎉Windows Terminal Preview v1.16.2641.0 has been released which incorporates this pull request.:tada:

Handy links:

@DHowett DHowett moved this from Cherry Picked to Shipped in 1.16 Servicing Pipeline Dec 1, 2022
This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-AtlasEngine Area-Fonts Related to the font AutoMerge Marked for automatic merge by the bot when requirements are met Issue-Bug It either shouldn't be doing this or needs an investigation. Priority-3 A description (P3) Product-Terminal The new Windows Terminal.
Projects
No open projects
Development

Successfully merging this pull request may close these issues.

Some fonts' italic text has wavy baselines
3 participants