Skip to content

Commit d8f3c44

Browse files
committed
Refactor writeColorScheme() to take data from array/variable
Can refactor this data out of the method later
1 parent e78a8b2 commit d8f3c44

File tree

1 file changed

+32
-38
lines changed

1 file changed

+32
-38
lines changed

src/PhpWord/Writer/Word2007/Part/Theme.php

Lines changed: 32 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@
1818

1919
namespace PhpOffice\PhpWord\Writer\Word2007\Part;
2020

21+
use PhpOffice\PhpWord\Style\Colors\Hex;
22+
use PhpOffice\PhpWord\Style\Colors\SystemColor;
23+
2124
/**
2225
* Word2007 theme writer: word/theme/theme1.xml
2326
*
@@ -56,45 +59,36 @@ public function write()
5659
*/
5760
private function writeColorScheme()
5861
{
59-
$str = '';
62+
$name = 'Office';
63+
$colors = array(
64+
'dk1' => new SystemColor('windowText', new Hex('000')),
65+
'lt1' => new SystemColor('window', new Hex('fff')),
66+
'dk2' => new Hex('1F497D'),
67+
'lt2' => new Hex('EEECE1'),
68+
'accent1' => new Hex('4F81BD'),
69+
'accent2' => new Hex('C0504D'),
70+
'accent3' => new Hex('9BBB59'),
71+
'accent4' => new Hex('8064A2'),
72+
'accent5' => new Hex('4BACC6'),
73+
'accent6' => new Hex('F79646'),
74+
'hlink' => new Hex('0000FF'),
75+
'folHlink' => new Hex('800080'),
76+
);
77+
78+
$str = '<a:clrScheme name="' . htmlentities($name, ENT_XML1) . '">';
79+
80+
foreach ($colors as $tag => $color) {
81+
$str .= '<a:' . htmlentities($tag, ENT_XML1) . '>';
82+
83+
if ($color instanceof SystemColor) {
84+
$str .= '<a:sysClr val="' . htmlentities($color->getName(), ENT_XML1) . '" lastClr="' . htmlentities($color->getLastColor()->toHex() ?? 'auto', ENT_XML1) . '" />';
85+
} else {
86+
$str .= '<a:srgbClr val="' . htmlentities($color->toHex() ?? 'auto', ENT_XML1) . '" />';
87+
}
88+
89+
$str .= '</a:dk1>';
90+
}
6091

61-
$str .= '<a:clrScheme name="Office">';
62-
$str .= '<a:dk1>';
63-
$str .= '<a:sysClr val="windowText" lastClr="000000" />';
64-
$str .= '</a:dk1>';
65-
$str .= '<a:lt1>';
66-
$str .= '<a:sysClr val="window" lastClr="FFFFFF" />';
67-
$str .= '</a:lt1>';
68-
$str .= '<a:dk2>';
69-
$str .= '<a:srgbClr val="1F497D" />';
70-
$str .= '</a:dk2>';
71-
$str .= '<a:lt2>';
72-
$str .= '<a:srgbClr val="EEECE1" />';
73-
$str .= '</a:lt2>';
74-
$str .= '<a:accent1>';
75-
$str .= '<a:srgbClr val="4F81BD" />';
76-
$str .= '</a:accent1>';
77-
$str .= '<a:accent2>';
78-
$str .= '<a:srgbClr val="C0504D" />';
79-
$str .= '</a:accent2>';
80-
$str .= '<a:accent3>';
81-
$str .= '<a:srgbClr val="9BBB59" />';
82-
$str .= '</a:accent3>';
83-
$str .= '<a:accent4>';
84-
$str .= '<a:srgbClr val="8064A2" />';
85-
$str .= '</a:accent4>';
86-
$str .= '<a:accent5>';
87-
$str .= '<a:srgbClr val="4BACC6" />';
88-
$str .= '</a:accent5>';
89-
$str .= '<a:accent6>';
90-
$str .= '<a:srgbClr val="F79646" />';
91-
$str .= '</a:accent6>';
92-
$str .= '<a:hlink>';
93-
$str .= '<a:srgbClr val="0000FF" />';
94-
$str .= '</a:hlink>';
95-
$str .= '<a:folHlink>';
96-
$str .= '<a:srgbClr val="800080" />';
97-
$str .= '</a:folHlink>';
9892
$str .= '</a:clrScheme>';
9993

10094
return $str;

0 commit comments

Comments
 (0)