Repository navigation
Description
Part of #552 (step 28, values read wrongly). This also covers overflow clipping in normal flow, from the audit's medium list, because that clipping needs a fixed height first.
height on a block in normal flow has two faults:
- A percentage resolves against the page area, not the parent.
- The value is used as a minimum: taller content grows the box, and
overflow: hiddenclips nothing.
Positioned blocks and table cells are not affected.
Measured on gravitypdf at 60b82630, PHP 8.5.4, from the filled rectangles and the positions text is drawn at.
| Document | Browser | mPDF |
|---|---|---|
<div style="height:40mm"><div style="height:50%">aa</div></div> |
inner box 20 mm tall | inner box 132.5 mm tall, 50% of the 265 mm page area. The outer box grows to hold it |
<div style="height:50%">aa</div> with no parent height |
auto: one line tall |
132.5 mm |
<div style="height:10mm;overflow:hidden"> with six lines, then <p>next</p> |
a 10 mm box, the lines past it clipped, next 10 mm below the box's top |
a 30.9 mm box, all six lines drawn, next below them |
<div style="height:10mm"> with six lines |
a 10 mm box, the lines overflowing it visibly, next 10 mm below the box's top |
as above |
Cause.
BlockTag::open()convertsHEIGHTagainst$this->mpdf->h - tMargin - bMargin(src/Tag/BlockTag.php:558-563).finishFlowingBlock()only ever adds space. When the content is shorter thancss_set_height, it pads the bottom out to it (src/Mpdf.php:7914-7925). When the content is taller, nothing happens.overflowis read only for positioned blocks (WriteFixedPosHTML(),src/Mpdf.php:15238) and for tables.
Fix.
- Resolve a percentage against the parent's
css_set_heightwhen the parent has one, and treat it asautowhen it does not. - When a block with a set height closes, move
yto the box's top plus its height, padding and borders, whatever the content's height. The content keeps its drawn position; content that ends lower overflows the box. - For
overflow: hidden,clipandauto, clip the content to the padding box. The clip has to start before the block's content is drawn.PaintDivBB()writes the background into the page after the content (___BACKGROUND___PATTERNS), so it cannot be used for this.scrollandautohave no meaning on paper and clip ashiddendoes. - Decide what happens when a block with a set height meets a page break. Today,
BlockTag::open()moves a block that does not fit to a new page (src/Tag/BlockTag.php:565-569).
This changes the output of documents that rely on height acting as a minimum. Many do, because min-height on blocks is not supported (#593). Say so in the PR, and list the snapshot fixtures that change.
Tests. A % height with and without a parent height, and inside a table cell. Content shorter and taller than the height, with overflow visible and hidden. A block with a set height that reaches the foot of the page. A nested block with a set height inside one with overflow: hidden.
Activity
Add the pull request to the changelog entry for #587
Add a snapshot of blocks with a set height and clipped overflow (#587)