Skip to content

Commit a4178cb

Browse files
committed
Html Font background-color
Code to support it was missing, and is now added.
1 parent 17030ba commit a4178cb

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

src/PhpWord/Writer/HTML/Style/Font.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,13 @@ public function write()
7373
} elseif ($style->isRTL() === false) {
7474
$css['direction'] = 'ltr';
7575
}
76+
$shading = $style->getShading();
77+
if ($shading !== null) {
78+
$fill = $shading->getFill();
79+
if (!empty($fill)) {
80+
$css['background-color'] = preg_match('/^[0-9a-fA-F]{6}$/', $fill) ? "#$fill" : $fill;
81+
}
82+
}
7683

7784
return $this->assembleCss($css);
7885
}

tests/PhpWordTests/Shared/Html2402Test.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ public function testParseTableBorder0(): void
7373
self::assertSame($expected, $count);
7474
$substring2 = 'border-top-style: dotted; border-top-color: #FF0000; border-left-style: dotted; border-left-color: #FF0000; border-bottom-style: dotted; border-bottom-color: #FF0000; border-right-style: dotted; border-right-color: #FF0000;';
7575
self::assertSame(1, substr_count($content, $substring2));
76+
self::assertStringContainsString('style="background-color: #00FF00;">header c</span>', $content);
7677
}
7778

7879
public function testParseTableStyleBorderNone(): void

0 commit comments

Comments
 (0)