Skip to content

Fix: Calculate em unit based on font size rather than line height#242

Open
chenjt2001 wants to merge 1 commit into
ArthurHub:masterfrom
chenjt2001:fix/em-unit-calculation
Open

Fix: Calculate em unit based on font size rather than line height#242
chenjt2001 wants to merge 1 commit into
ArthurHub:masterfrom
chenjt2001:fix/em-unit-calculation

Conversation

@chenjt2001
Copy link
Copy Markdown

Description

This PR fixes an issue where the em unit 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 to ActualFont.Size * 96d / 72d (converting points to pixels), the em unit now matches the actual font size.

Before Fix:
图片

After Fix:
图片

Copilot AI review requested due to automatic review settings June 4, 2026 11:24
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

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 using ActualFont.Height to a Size * 96/72 conversion 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;
}
Comment thread Source/HtmlRenderer/Core/Dom/CssBoxProperties.cs Outdated
@chenjt2001 chenjt2001 force-pushed the fix/em-unit-calculation branch from fdecd29 to 135db3e Compare June 4, 2026 11:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants