Put the final touches on GDI's underlines#16475
Merged
Conversation
1 task
Member
Author
Member
Author
DHowett
approved these changes
Dec 15, 2023
Member
Member
Member
Member
Author
|
Should be fixed in the latest commits. |
Member
|
Re-tested Consolas McTinyfont and it is perfect |
DHowett
approved these changes
Dec 15, 2023
carlos-zamora
approved these changes
Dec 15, 2023
DHowett
pushed a commit
that referenced
this pull request
Dec 15, 2023
While #16444 left wavy lines in an amazing state already, there were a few more things that could be done to make GDI look more consistent with other well known Windows applications. But before that, a couple unrelated, but helpful changes were made: * `GdiEngine::UpdateFont` was heavily modified to do all calculations in floats. All modern CPUs have fast FPUs and even the fairly slow `lroundf` function is so fast (relatively) nowadays that in a cold path like this, we can liberally call it to convert back to `int`s. This makes intermediate calculation more accurate and consistent. * `GdiEngine::PaintBufferGridLines` was exception-unsafe due to its use of a `std::vector` with catch clause and this PR fixes that. Additionally, the vector was swapped out with a `til::small_vector` to reduce heap allocations. (Arena allocators!) * RenderingTests was updated to cover styled underlines With that in place, these improvements were done: * Word's double-underline algorithm was ported over from `AtlasEngine`. It uses a half underline-width (aka `thinLineWidth`) which will now also be used for wavy lines to make them look a bit more filigrane. * The Bézier curve for wavy/curly underlines was modified to use control points at (0.5,0.5) and (0.5,-0.5) respectively. This results in a maxima at y=0.1414 which is much closer to a sine curve with a maxima at 1/(2pi) = 0.1592. Previously, the maxima was a lot higher (roughly 4x) depending on the aspect ratio of the glyphs. * Wavy underlines don't depend on the aspect ratio of glyphs anymore. This previously led to several problems depending on the exact font. The old renderer would draw exactly 3 periods of the wave into each cell which would also ensure continuity between cells. Unfortunately, this meant that waves could look inconsistent. The new approach always uses the aforementioned sine-like waves. * The wavy underline offset was clamped so that it's never outside of bounds of a line. This avoids clipping. * Compile RenderingTests and run it * Using Consolas, MS Gothic and Cascadia Code while Ctrl+Scrolling up and down works as expected without clipping ✅ (cherry picked from commit 99193c9) Service-Card-Id: 91356394 Service-Version: 1.19
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.










While #16444 left wavy lines in an amazing state already, there were
a few more things that could be done to make GDI look more consistent
with other well known Windows applications.
But before that, a couple unrelated, but helpful changes were made:
GdiEngine::UpdateFontwas heavily modified to do all calculationsin floats. All modern CPUs have fast FPUs and even the fairly slow
lroundffunction is so fast (relatively) nowadays that in a coldpath like this, we can liberally call it to convert back to
ints.This makes intermediate calculation more accurate and consistent.
GdiEngine::PaintBufferGridLineswas exception-unsafe due to itsuse of a
std::vectorwith catch clause and this PR fixes that.Additionally, the vector was swapped out with a
til::small_vectorto reduce heap allocations. (Arena allocators!)
With that in place, these improvements were done:
AtlasEngine.It uses a half underline-width (aka
thinLineWidth) which will nowalso be used for wavy lines to make them look a bit more filigrane.
control points at (0.5,0.5) and (0.5,-0.5) respectively. This results
in a maxima at y=0.1414 which is much closer to a sine curve with a
maxima at 1/(2pi) = 0.1592. Previously, the maxima was a lot higher
(roughly 4x) depending on the aspect ratio of the glyphs.
This previously led to several problems depending on the exact font.
The old renderer would draw exactly 3 periods of the wave into
each cell which would also ensure continuity between cells.
Unfortunately, this meant that waves could look inconsistent.
The new approach always uses the aforementioned sine-like waves.
bounds of a line. This avoids clipping.
Validation Steps Performed
up and down works as expected without clipping ✅