Fix: Calculate em unit based on font size rather than line height#242
Open
chenjt2001 wants to merge 1 commit into
Open
Fix: Calculate em unit based on font size rather than line height#242chenjt2001 wants to merge 1 commit into
chenjt2001 wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
Updates how GetEmHeight() computes the “em” height for layout calculations in the CSS box model.
Changes:
- Changed
GetEmHeight()from usingActualFont.Heightto aSize * 96/72conversion formula.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+1435
to
+1436
| return ActualFont.Size * 96d / 72d; | ||
| } |
Comment on lines
+1435
to
+1436
| return ActualFont.Size * 96d / 72d; | ||
| } |
fdecd29 to
135db3e
Compare
135db3e to
37a5b82
Compare
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.
Description
This PR fixes an issue where the
emunit was incorrectly calculated using the font's line height (ActualFont.Height) instead of the font size.Motivation
I discovered this bug when applying
text-indent: 2em;to a<p>tag. The resulting indentation was noticeably larger than the expected width of two full-width characters.The root cause was in
CssBoxProperties.GetEmHeight(), which returned the line height. By updating the calculation toActualFont.Size * 96d / 72d(converting points to pixels), theemunit now matches the actual font size.Before Fix:

After Fix:
