Skip to content

Commit

Permalink
Suppress run breaking for abs. differences < 0.001 in advance (micros…
Browse files Browse the repository at this point in the history
…oft#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 microsoft#4806.
  • Loading branch information
DHowett authored and abhijeetviswam committed Mar 12, 2020
1 parent c7773c0 commit 68a2d94
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/renderer/dx/CustomTextLayout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

Expand Down

0 comments on commit 68a2d94

Please sign in to comment.