Skip to content

Commit 6a3135b

Browse files
authored
Merge pull request #989 from troosan/fix_for_different_even_odd_headers
add possibility to write w:evenAndOddHeaders in settings.xml
2 parents 29f7cfb + aef7a0b commit 6a3135b

File tree

4 files changed

+57
-1
lines changed

4 files changed

+57
-1
lines changed

src/PhpWord/Settings.php

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff 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
*

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717

1818
namespace 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' => ';')),

tests/PhpWord/SettingsTest.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff 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
*/

tests/PhpWord/Writer/Word2007/Part/SettingsTest.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
use PhpOffice\PhpWord\PhpWord;
2020
use 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
}

0 commit comments

Comments
 (0)