Skip to content

Commit 258aa89

Browse files
Carry decorations into a block opened inside an inline element, and leave a decoration unseen in inherited transparent
A block inside an underlined span now starts from the span's text state, which #653 sets aside, so it and the text after it are underlined. TextDecorations::seen() reads #651's transparent flag, so a descendant that inherits color: transparent adds no decoration of its own either. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 364d422 commit 258aa89

4 files changed

Lines changed: 36 additions & 9 deletions

File tree

‎CHANGELOG-GRAVITYPDF.md‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,8 @@ Read this section before upgrading from upstream mPDF. Each entry says what chan
6464
* **Text decorations propagate to descendants instead of being inherited**, as in a browser. A link styled `a { text-decoration: none }` inside an underlined paragraph now has the paragraph's underline drawn under it. Set `'cssMode' => \Mpdf\CssMode::LEGACY` to keep the old output, or move the `text-decoration` from the paragraph to the parts of it you want decorated. [#544] [#654]
6565
* An underline, overline or line-through is drawn over the text of every descendant in the flow, in the colour and at the size of the element that set it. A child block used to redraw it in its own colour and size, and lost an overline.
6666
* `text-decoration: none` on a descendant removes only a decoration of its own. A descendant's own decoration is added to its ancestors': `line-through` inside an underlined block is drawn with both lines.
67-
* An element whose `color` is `transparent` adds no decoration of its own, since it would be drawn in that colour.
67+
* An element whose `color` is `transparent`, set or inherited, adds no decoration of its own, since it would be drawn in that colour.
68+
* A block inside an underlined inline element, as in `<span style="text-decoration: underline">…<div>…</div>…</span>`, is underlined too, as is the text after it up to the element's end tag.
6869
* Floats, positioned blocks and inline blocks no longer take the decorations of the element they are in. Tables never did.
6970
* A child block no longer takes its parent's `vertical-align`, which is not inherited.
7071

‎src/Css/TextDecorations.php‎

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -66,19 +66,16 @@ public static function enter(Mpdf $mpdf, array $properties, $parent = null)
6666

6767
/**
6868
* Whether the decorations an element sets are seen. Under CssMode::STANDARD a decoration is drawn in the colour of
69-
* the element that sets it, so an element whose color is transparent draws its own unseen, and the decorations it
70-
* is in stay drawn over its text.
69+
* the element that sets it, so an element whose color is transparent, set or inherited, draws its own unseen, and
70+
* the decorations it is in stay drawn over its text. Call it once Mpdf::setCSS() has applied the element's color.
7171
*
7272
* @param Mpdf $mpdf
73-
* @param array $properties The element's merged CSS
7473
*
7574
* @return bool
7675
*/
77-
public static function seen(Mpdf $mpdf, array $properties)
76+
public static function seen(Mpdf $mpdf)
7877
{
79-
return $mpdf->cssMode === CssMode::LEGACY
80-
|| !isset($properties['COLOR'])
81-
|| strtolower(trim($properties['COLOR'])) !== 'transparent';
78+
return $mpdf->cssMode === CssMode::LEGACY || empty($mpdf->textparam['transparent']);
8279
}
8380

8481
/**

‎src/Mpdf.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20058,7 +20058,7 @@ function setCSS($arrayaux, $type = '', $tag = '')
2005820058
}//end of foreach
2005920059
// mPDF 5.7.3 inline text-decoration parameters
2006020060
// Needs to be set at the end - after vertical-align = super/sub, so that textparam['text-baseline'] is set
20061-
if (isset($arrayaux['TEXT-DECORATION']) && TextDecorations::seen($this, $arrayaux)) {
20061+
if (isset($arrayaux['TEXT-DECORATION']) && TextDecorations::seen($this)) {
2006220062
$v = $arrayaux['TEXT-DECORATION']; // none underline line-through (strikeout) // Does not support: blink
2006320063
if (stristr($v, 'LINE-THROUGH')) {
2006420064
$this->textvar = ($this->textvar | TextVars::FD_LINETHROUGH);

‎tests/Mpdf/TextDecorationPropagationTest.php‎

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,25 @@ public function testALinkWithNoDecorationKeepsTheParagraphsUnderline()
248248
$this->assertSame(['underline' => [self::BLUE, self::ANCESTOR_SIZE]], $legacy['xx']);
249249
}
250250

251+
/**
252+
* A block inside an underlined inline element takes its underline under standard, as it takes the element's other
253+
* text properties (#541), and the text after the block is underlined again. Under legacy the block starts from an
254+
* empty text state, so neither is underlined
255+
*/
256+
public function testABlockInsideAnInlineElementTakesItsDecorations()
257+
{
258+
$html = '<div><span style="color: #f00; text-decoration: underline">zz<div style="color: #00f">qq</div>yy</span> xx</div>';
259+
260+
$standard = $this->drawnDecorations($html, CssMode::STANDARD);
261+
$this->assertSame(['underline' => [self::RED, self::ANCESTOR_SIZE]], $standard['qq']);
262+
$this->assertSame(['underline' => [self::RED, self::ANCESTOR_SIZE]], $standard['yy']);
263+
$this->assertSame([], $standard['xx']);
264+
265+
$legacy = $this->drawnDecorations($html, CssMode::LEGACY);
266+
$this->assertSame([], $legacy['qq']);
267+
$this->assertSame([], $legacy['yy']);
268+
}
269+
251270
/**
252271
* Under standard an element whose colour is transparent draws its own decoration unseen, so none is added for it,
253272
* and the decorations of the elements it is in are drawn over its text in their colour. Under legacy the element's
@@ -299,6 +318,16 @@ public function transparentElements()
299318
$underlined,
300319
$blackUnderline,
301320
],
321+
'an inline element inside a transparent one' => [
322+
'<p style="color: #f00; text-decoration: line-through"><span style="color: transparent">zz <b style="text-decoration: underline">qq</b></span></p>',
323+
$struck,
324+
$underlined + $struck,
325+
],
326+
'a block inside a transparent one' => [
327+
'<div style="color: #f00; text-decoration: line-through"><div style="color: transparent"><p style="text-decoration: underline">qq</p></div></div>',
328+
$struck,
329+
$blackUnderline,
330+
],
302331
];
303332
}
304333

0 commit comments

Comments
 (0)