Repository navigation
Align inline text with vertical-align keywords, and indent cells and hanging lines with text-indent #608
Copy link
Copy link
Open
Labels
enhancementNew feature or requestNew feature or request
Description
Part of #552 (step 28, missing support, medium priority).
Two inline-layout gaps:
vertical-alignon inline text.middle,top,bottom,text-topandtext-bottomdo nothing; they work on images.text-indent. It is ignored in table cells, andhangingoreach-linedrop the whole declaration.
Icons set beside text with vertical-align: middle, and hanging indents in references and numbered clauses, come out wrong.
Measured on gravitypdf at 60b82630, PHP 8.5.4, from the Td operators and the positions text is drawn at.
| Rule | Browser | mPDF |
|---|---|---|
a 7pt <span style="vertical-align:middle"> in a 20pt paragraph |
the span's middle at the parent's baseline plus half its x-height | on the baseline: the same Td y as unstyled text |
a 7pt <span style="vertical-align:top"> |
its top at the line box's top | on the baseline |
vertical-align: super on the same span |
raised | raised (works) |
td { text-indent: 20mm } |
first line indented 20 mm | not indented |
div { width: 30mm; text-indent: 10mm hanging } |
every line but the first indented | no indent at all |
div { width: 30mm; text-indent: 10mm } |
first line indented | first line indented (works) |
Cause.
vertical-align.setCSS()handlesSUPER,SUBandBASELINE. Anything else goes to the length branch, whereSizeConverterreads a keyword as 0 (src/Mpdf.php:19515-19550). Images take the keywords fromTag::ALIGN(src/Tag/Tag.php:74-85), and the line code places them.text-indent.setCSS()stores it only for blocks, not cells (if ($type != 'INLINE' && $type != 'TABLECELL'),src/Mpdf.php:19377-19381), andTddoes not read it. The line code applies it only when!$is_table(:7547,:7749,:8907,:9505). A keyword makes the value unparseable. After Drop a declaration mPDF cannot read so the value it would replace still applies #565 the declaration is dropped; today it converts to 0.
Fix.
vertical-alignkeywords on text. They depend on the line box, which is only known once the line is complete.- Mark the run with the keyword, as
superandsubmark it intextvar. - When the line's height is worked out (
_setInlineBlockHeights(),src/Mpdf.php:12364), place the run:middlefrom the parent's baseline and x-height;text-topandtext-bottomfrom the parent's font box;topandbottomfrom the line box once the rest is placed. - A run with
toporbottomcan make the line taller, which the same pass accounts for. line-heighton an inline element does not change the height of its line #548 changes how inline boxes size the line; do this after it, or in the same code.
- Mark the run with the keyword, as
text-indentin cells. Read it inTd::open()onto the cell, inherit it into the cell's blocks, and drop the!$is_tableconditions so the cell's first line is indented.hangingandeach-line. Accept the keywords with a length.hangingindents every line except the first.each-linealso indents the first line after each forced break (<br>).- Both reuse the line code's first-line check with the condition inverted or widened.
- Drop a declaration mPDF cannot read so the value it would replace still applies #565's validation must let these keywords through.
Tests. Each row above, vertical-align with a length and a percentage (unchanged), middle on a span containing an image, top in a line with a taller image, text-indent in an rtl cell, hanging with a negative length, and each-line after <br>.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or request
Activity