1818
1919namespace PhpOffice \PhpWord \Writer \ODText \Style ;
2020
21+ use PhpOffice \PhpWord \Style ;
22+
2123/**
2224 * Font style writer.
2325 *
@@ -31,21 +33,21 @@ class Font extends AbstractStyle
3133 public function write (): void
3234 {
3335 $ style = $ this ->getStyle ();
34- if (!$ style instanceof \ PhpOffice \ PhpWord \ Style \Font) {
36+ if (!$ style instanceof Style \Font) {
3537 return ;
3638 }
3739 $ xmlWriter = $ this ->getXmlWriter ();
3840
3941 $ stylep = $ style ->getParagraph ();
40- if ($ stylep instanceof \ PhpOffice \ PhpWord \ Style \Paragraph) {
42+ if ($ stylep instanceof Style \Paragraph) {
4143 $ temp1 = clone $ stylep ;
4244 $ temp1 ->setStyleName ($ style ->getStyleName ());
4345 $ temp2 = new Paragraph ($ xmlWriter , $ temp1 );
4446 $ temp2 ->write ();
4547 }
4648
4749 $ xmlWriter ->startElement ('style:style ' );
48- $ xmlWriter ->writeAttribute ('style:name ' , $ style ->getStyleName ());
50+ $ xmlWriter ->writeAttribute ('style:name ' , Style:: alternateName ( $ style ->getStyleName () ));
4951 $ xmlWriter ->writeAttribute ('style:family ' , 'text ' );
5052 $ xmlWriter ->startElement ('style:text-properties ' );
5153
@@ -100,9 +102,9 @@ public function write(): void
100102 $ xmlWriter ->writeAttribute ('style:country-complex ' , 'none ' );
101103 }
102104
103- // @todo Foreground-Color
104-
105- // @todo Background color
105+ // Foreground-Color (which is really background color)
106+ $ fgColor = $ style -> getFgColor ();
107+ $ xmlWriter -> writeAttributeIf ( $ fgColor != '' , ' fo:background- color' , ' # ' . \ PhpOffice \ PhpWord \ Shared \Converter:: stringToRgb ( $ fgColor ));
106108
107109 $ xmlWriter ->endElement (); // style:text-properties
108110 $ xmlWriter ->endElement (); // style:style
0 commit comments