Skip to content

Measure the content before computing the shrink-to-fit width - #294

Merged
eXpl0it3r merged 1 commit into
masterfrom
fix/shrink-to-fit-width
Nov 20, 2026
Merged

eXpl0it3r merged 1 commit into
masterfrom
fix/shrink-to-fit-width

Conversation

@eXpl0it3r

@eXpl0it3r eXpl0it3r commented Nov 17, 2026 •

Copy link
Copy Markdown
Collaborator

Floats and absolutely positioned boxes with an auto width weren't drawn at all. Their shrink-to-fit width (CSS 2.1 §10.3.5 and §10.3.7) was computed before the words of their inline content were measured, so the word widths were still 0 and the word spacing still NaN, which made the box width NaN. Text split over several inline elements ended up with a width of 0 instead.

The fix measures the descendants' words before GetMinMaxWidth, the same way the table layout already did for its column widths. The recursive measuring moved from CssLayoutEngineTable to CssBox.MeasureDescendantWords, so both use the same code.

Nothing caught this, because every positioning test set an explicit width. The two gap tests for it, AutoWidthFloat_ShrinksToFitItsContent and Absolute_WithAutoWidth_ShrinksToFitItsContent, are now enabled, and the gaps are removed from the CSS 2.1, Position 3, Sizing 3 and Sizing 4 manifests. The image regression baselines don't change.

Note that an absolutely positioned box with left and right both auto still goes to the containing block's edge instead of its static position, that's a separate gap.

Closes #203

How to test this PR?

CI should succeed. The HTML from #203 should put the paragraphs at 200px from the left, both with HtmlRenderer.PdfSharp and HtmlRenderer.WinForms.

@eXpl0it3r
eXpl0it3r merged commit 46675e0 into master Nov 20, 2026
46 of 48 checks passed
@eXpl0it3r
eXpl0it3r deleted the fix/shrink-to-fit-width branch November 20, 2026 07:13
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.

The library ignores position:absolute styling

1 participant