add possibility to write w:evenAndOddHeaders in settings.xml

This commit is contained in:
antoine 2017-01-29 14:34:19 +01:00
parent 6da9d8a0bf
commit aef7a0ba76
4 changed files with 57 additions and 1 deletions

View File

@ -133,7 +133,14 @@ class Settings
* @var bool * @var bool
*/ */
private static $outputEscapingEnabled = false; private static $outputEscapingEnabled = false;
/**
* Enables different header for odd and even pages.
*
* @var bool
*/
private static $evenAndOddHeaders = false;
/** /**
* Return the compatibility option used by the XMLWriter * Return the compatibility option used by the XMLWriter
* *
@ -340,6 +347,22 @@ class Settings
self::$outputEscapingEnabled = $outputEscapingEnabled; self::$outputEscapingEnabled = $outputEscapingEnabled;
} }
/**
* @return boolean
*/
public static function isEvenAndOddHeaders()
{
return self::$evenAndOddHeaders;
}
/**
* @param boolean $evenAndOddHeaders
*/
public static function setEvenAndOddHeaders($evenAndOddHeaders)
{
self::$evenAndOddHeaders = $evenAndOddHeaders;
}
/** /**
* Get default font name * Get default font name
* *

View File

@ -17,6 +17,8 @@
namespace PhpOffice\PhpWord\Writer\Word2007\Part; namespace PhpOffice\PhpWord\Writer\Word2007\Part;
use PhpOffice\PhpWord\Settings as DocumentSettings;
/** /**
* Word2007 settings part writer: word/settings.xml * Word2007 settings part writer: word/settings.xml
* *
@ -103,6 +105,7 @@ class Settings extends AbstractPart
'w:defaultTabStop' => array('@attributes' => array('w:val' => '708')), 'w:defaultTabStop' => array('@attributes' => array('w:val' => '708')),
'w:hyphenationZone' => array('@attributes' => array('w:val' => '425')), 'w:hyphenationZone' => array('@attributes' => array('w:val' => '425')),
'w:characterSpacingControl' => array('@attributes' => array('w:val' => 'doNotCompress')), 'w:characterSpacingControl' => array('@attributes' => array('w:val' => 'doNotCompress')),
'w:evenAndOddHeaders' => array('@attributes' => array('w:val' => DocumentSettings::isEvenAndOddHeaders() ? 'true': 'false')),
'w:themeFontLang' => array('@attributes' => array('w:val' => 'en-US')), 'w:themeFontLang' => array('@attributes' => array('w:val' => 'en-US')),
'w:decimalSymbol' => array('@attributes' => array('w:val' => '.')), 'w:decimalSymbol' => array('@attributes' => array('w:val' => '.')),
'w:listSeparator' => array('@attributes' => array('w:val' => ';')), 'w:listSeparator' => array('@attributes' => array('w:val' => ';')),

View File

@ -114,6 +114,16 @@ class SettingsTest extends \PHPUnit_Framework_TestCase
$this->assertFalse(Settings::setDefaultFontSize(null)); $this->assertFalse(Settings::setDefaultFontSize(null));
} }
/**
* Test set/get even and odd headers
*/
public function testSetGetEvenAndOddHeaders()
{
$this->assertFalse(Settings::isEvenAndOddHeaders());
Settings::setEvenAndOddHeaders(true);
$this->assertTrue(Settings::isEvenAndOddHeaders());
}
/** /**
* Test load config * Test load config
*/ */

View File

@ -18,6 +18,7 @@ namespace PhpOffice\PhpWord\Writer\Word2007\Part;
use PhpOffice\PhpWord\PhpWord; use PhpOffice\PhpWord\PhpWord;
use PhpOffice\PhpWord\TestHelperDOCX; use PhpOffice\PhpWord\TestHelperDOCX;
use PhpOffice\PhpWord\Settings;
/** /**
* Test class for PhpOffice\PhpWord\Writer\Word2007\Part\Settings * Test class for PhpOffice\PhpWord\Writer\Word2007\Part\Settings
@ -66,4 +67,23 @@ class SettingsTest extends \PHPUnit_Framework_TestCase
$this->assertTrue($doc->elementExists($path, $file)); $this->assertTrue($doc->elementExists($path, $file));
$this->assertEquals($phpWord->getCompatibility()->getOoxmlVersion(), 15); $this->assertEquals($phpWord->getCompatibility()->getOoxmlVersion(), 15);
} }
/**
* Test even and odd headers
*/
public function testEvenAndOddHeaders()
{
$phpWord = new PhpWord();
Settings::setEvenAndOddHeaders(true);
$doc = TestHelperDOCX::getDocument($phpWord);
$file = 'word/settings.xml';
$path = '/w:settings/w:evenAndOddHeaders';
$this->assertTrue($doc->elementExists($path, $file));
$element = $doc->getElement($path, $file);
$this->assertEquals('true', $element->getAttribute('w:val'));
}
} }