File tree Expand file tree Collapse file tree 4 files changed +57
-1
lines changed Expand file tree Collapse file tree 4 files changed +57
-1
lines changed Original file line number Diff line number Diff line change @@ -133,7 +133,14 @@ class Settings
133
133
* @var bool
134
134
*/
135
135
private static $ outputEscapingEnabled = false ;
136
-
136
+
137
+ /**
138
+ * Enables different header for odd and even pages.
139
+ *
140
+ * @var bool
141
+ */
142
+ private static $ evenAndOddHeaders = false ;
143
+
137
144
/**
138
145
* Return the compatibility option used by the XMLWriter
139
146
*
@@ -340,6 +347,22 @@ public static function setOutputEscapingEnabled($outputEscapingEnabled)
340
347
self ::$ outputEscapingEnabled = $ outputEscapingEnabled ;
341
348
}
342
349
350
+ /**
351
+ * @return boolean
352
+ */
353
+ public static function isEvenAndOddHeaders ()
354
+ {
355
+ return self ::$ evenAndOddHeaders ;
356
+ }
357
+
358
+ /**
359
+ * @param boolean $evenAndOddHeaders
360
+ */
361
+ public static function setEvenAndOddHeaders ($ evenAndOddHeaders )
362
+ {
363
+ self ::$ evenAndOddHeaders = $ evenAndOddHeaders ;
364
+ }
365
+
343
366
/**
344
367
* Get default font name
345
368
*
Original file line number Diff line number Diff line change 17
17
18
18
namespace PhpOffice \PhpWord \Writer \Word2007 \Part ;
19
19
20
+ use PhpOffice \PhpWord \Settings as DocumentSettings ;
21
+
20
22
/**
21
23
* Word2007 settings part writer: word/settings.xml
22
24
*
@@ -103,6 +105,7 @@ private function getSettings()
103
105
'w:defaultTabStop ' => array ('@attributes ' => array ('w:val ' => '708 ' )),
104
106
'w:hyphenationZone ' => array ('@attributes ' => array ('w:val ' => '425 ' )),
105
107
'w:characterSpacingControl ' => array ('@attributes ' => array ('w:val ' => 'doNotCompress ' )),
108
+ 'w:evenAndOddHeaders ' => array ('@attributes ' => array ('w:val ' => DocumentSettings::isEvenAndOddHeaders () ? 'true ' : 'false ' )),
106
109
'w:themeFontLang ' => array ('@attributes ' => array ('w:val ' => 'en-US ' )),
107
110
'w:decimalSymbol ' => array ('@attributes ' => array ('w:val ' => '. ' )),
108
111
'w:listSeparator ' => array ('@attributes ' => array ('w:val ' => '; ' )),
Original file line number Diff line number Diff line change @@ -114,6 +114,16 @@ public function testSetGetDefaultFontSize()
114
114
$ this ->assertFalse (Settings::setDefaultFontSize (null ));
115
115
}
116
116
117
+ /**
118
+ * Test set/get even and odd headers
119
+ */
120
+ public function testSetGetEvenAndOddHeaders ()
121
+ {
122
+ $ this ->assertFalse (Settings::isEvenAndOddHeaders ());
123
+ Settings::setEvenAndOddHeaders (true );
124
+ $ this ->assertTrue (Settings::isEvenAndOddHeaders ());
125
+ }
126
+
117
127
/**
118
128
* Test load config
119
129
*/
Original file line number Diff line number Diff line change 18
18
19
19
use PhpOffice \PhpWord \PhpWord ;
20
20
use PhpOffice \PhpWord \TestHelperDOCX ;
21
+ use PhpOffice \PhpWord \Settings ;
21
22
22
23
/**
23
24
* Test class for PhpOffice\PhpWord\Writer\Word2007\Part\Settings
@@ -66,4 +67,23 @@ public function testCompatibility()
66
67
$ this ->assertTrue ($ doc ->elementExists ($ path , $ file ));
67
68
$ this ->assertEquals ($ phpWord ->getCompatibility ()->getOoxmlVersion (), 15 );
68
69
}
70
+
71
+ /**
72
+ * Test even and odd headers
73
+ */
74
+ public function testEvenAndOddHeaders ()
75
+ {
76
+ $ phpWord = new PhpWord ();
77
+ Settings::setEvenAndOddHeaders (true );
78
+
79
+ $ doc = TestHelperDOCX::getDocument ($ phpWord );
80
+
81
+ $ file = 'word/settings.xml ' ;
82
+
83
+ $ path = '/w:settings/w:evenAndOddHeaders ' ;
84
+ $ this ->assertTrue ($ doc ->elementExists ($ path , $ file ));
85
+
86
+ $ element = $ doc ->getElement ($ path , $ file );
87
+ $ this ->assertEquals ('true ' , $ element ->getAttribute ('w:val ' ));
88
+ }
69
89
}
You can’t perform that action at this time.
0 commit comments