From 27840ab7103f4bd46190891c5d80b9f5a2393077 Mon Sep 17 00:00:00 2001 From: Julien Carignan Date: Mon, 24 Mar 2014 13:43:20 -0400 Subject: [PATCH] Font-style addition: bgColor Signed-off-by: Julien Carignan --- Classes/PHPWord/Style/Font.php | 34 ++++++++++++++++++++++++ Classes/PHPWord/Writer/Word2007/Base.php | 10 +++++++ 2 files changed, 44 insertions(+) diff --git a/Classes/PHPWord/Style/Font.php b/Classes/PHPWord/Style/Font.php index 2aa6cbc6..66d82832 100755 --- a/Classes/PHPWord/Style/Font.php +++ b/Classes/PHPWord/Style/Font.php @@ -149,6 +149,18 @@ class PHPWord_Style_Font * @var string */ private $_fgColor = null; + + /** + * Background color + * + * @var string + */ + private $_bgColor = null; + /** + * Text line height + * + * @var int + */ /** * Text line height @@ -468,6 +480,28 @@ class PHPWord_Style_Font $this->_fgColor = $pValue; return $this; } + + /** + * Get background color + * + * @return string + */ + public function getBgColor() + { + return $this->_bgColor; + } + + /** + * Set background color + * + * @param string $pValue + * @return PHPWord_Style_Font + */ + public function setBgColor($pValue = null) + { + $this->_bgColor = $pValue; + return $this; + } /** * Get style type diff --git a/Classes/PHPWord/Writer/Word2007/Base.php b/Classes/PHPWord/Writer/Word2007/Base.php index d829bf92..0102979d 100755 --- a/Classes/PHPWord/Writer/Word2007/Base.php +++ b/Classes/PHPWord/Writer/Word2007/Base.php @@ -398,6 +398,7 @@ class PHPWord_Writer_Word2007_Base extends PHPWord_Writer_Word2007_WriterPart $color = $style->getColor(); $size = $style->getSize(); $fgColor = $style->getFgColor(); + $bgColor = $style->getBgColor(); $strikethrough = $style->getStrikethrough(); $underline = $style->getUnderline(); $superscript = $style->getSuperScript(); @@ -467,6 +468,15 @@ class PHPWord_Writer_Word2007_Base extends PHPWord_Writer_Word2007_WriterPart $objWriter->writeAttribute('w:val', $fgColor); $objWriter->endElement(); } + + // Background-Color + if (!is_null($bgColor)) { + $objWriter->startElement('w:shd'); + $objWriter->writeAttribute('w:val', "clear"); + $objWriter->writeAttribute('w:color', "auto"); + $objWriter->writeAttribute('w:fill', $bgColor); + $objWriter->endElement(); + } // Superscript/subscript if ($superscript || $subscript) {