Suppress run breaking for abs. differences < 0.001 in advance (#4861)

With certain font faces at certain sizes, the advances seem to be
slightly more than the pixel grid; Cascadia Code at 13pt (though, 200%
scale) had an advance of 10.000001.

This commit makes it so that anything sub-1/100 of a cell won't make us
break up runs, because doing so results in suboptimal rendering.

Fixes #4806.
This commit is contained in:
Dustin L. Howett (MSFT) 2020-03-10 11:12:16 -07:00 committed by GitHub
parent 61d635367b
commit d954ad68f2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -639,8 +639,12 @@ try
_glyphAdvances.cbegin() + clusterGlyphBegin + clusterGlyphLength,
0.0f);
// With certain font faces at certain sizes, the advances seem to be slightly more than
// the pixel grid; Cascadia Code at 13pt (though, 200% scale) had an advance of 10.000001.
// We don't want anything sub one hundredth of a cell to make us break up runs, because
// doing so results in suboptimal rendering.
// If what we expect is bigger than what we have... pad it out.
if (advanceExpected > advanceActual)
if ((advanceExpected - advanceActual) > 0.001f)
{
// Get the amount of space we have leftover.
const auto diff = advanceExpected - advanceActual;
@ -657,7 +661,7 @@ try
_glyphAdvances.at(static_cast<size_t>(clusterGlyphBegin) + clusterGlyphLength - 1) += diff;
}
// If what we expect is smaller than what we have... rescale the font size to get a smaller glyph to fit.
else if (advanceExpected < advanceActual)
else if ((advanceExpected - advanceActual) < -0.001f)
{
const auto scaleProposed = advanceExpected / advanceActual;