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
133133 * @var bool
134134 */
135135 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+
137144 /**
138145 * Return the compatibility option used by the XMLWriter
139146 *
@@ -340,6 +347,22 @@ public static function setOutputEscapingEnabled($outputEscapingEnabled)
340347 self ::$ outputEscapingEnabled = $ outputEscapingEnabled ;
341348 }
342349
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+
343366 /**
344367 * Get default font name
345368 *
Original file line number Diff line number Diff line change 1717
1818namespace PhpOffice \PhpWord \Writer \Word2007 \Part ;
1919
20+ use PhpOffice \PhpWord \Settings as DocumentSettings ;
21+
2022/**
2123 * Word2007 settings part writer: word/settings.xml
2224 *
@@ -103,6 +105,7 @@ private function getSettings()
103105 'w:defaultTabStop ' => array ('@attributes ' => array ('w:val ' => '708 ' )),
104106 'w:hyphenationZone ' => array ('@attributes ' => array ('w:val ' => '425 ' )),
105107 'w:characterSpacingControl ' => array ('@attributes ' => array ('w:val ' => 'doNotCompress ' )),
108+ 'w:evenAndOddHeaders ' => array ('@attributes ' => array ('w:val ' => DocumentSettings::isEvenAndOddHeaders () ? 'true ' : 'false ' )),
106109 'w:themeFontLang ' => array ('@attributes ' => array ('w:val ' => 'en-US ' )),
107110 'w:decimalSymbol ' => array ('@attributes ' => array ('w:val ' => '. ' )),
108111 'w:listSeparator ' => array ('@attributes ' => array ('w:val ' => '; ' )),
Original file line number Diff line number Diff line change @@ -114,6 +114,16 @@ public function testSetGetDefaultFontSize()
114114 $ this ->assertFalse (Settings::setDefaultFontSize (null ));
115115 }
116116
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+
117127 /**
118128 * Test load config
119129 */
Original file line number Diff line number Diff line change 1818
1919use PhpOffice \PhpWord \PhpWord ;
2020use PhpOffice \PhpWord \TestHelperDOCX ;
21+ use PhpOffice \PhpWord \Settings ;
2122
2223/**
2324 * Test class for PhpOffice\PhpWord\Writer\Word2007\Part\Settings
@@ -66,4 +67,23 @@ public function testCompatibility()
6667 $ this ->assertTrue ($ doc ->elementExists ($ path , $ file ));
6768 $ this ->assertEquals ($ phpWord ->getCompatibility ()->getOoxmlVersion (), 15 );
6869 }
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+ }
6989}
You can’t perform that action at this time.
0 commit comments