Skip to content

Commit

Permalink
add reader for settings
Browse files Browse the repository at this point in the history
  • Loading branch information
troosan committed Jul 6, 2017
1 parent e9cc289 commit b919d58
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/PhpWord/Metadata/Settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public function hasHideSpellingErrors()
*/
public function setHideSpellingErrors($hideSpellingErrors)
{
$this->hideSpellingErrors = $hideSpellingErrors;
$this->hideSpellingErrors = $hideSpellingErrors === null ? true : $hideSpellingErrors;
}

/**
Expand All @@ -110,7 +110,7 @@ public function hasHideGrammaticalErrors()
*/
public function setHideGrammaticalErrors($hideGrammaticalErrors)
{
$this->hideGrammaticalErrors = $hideGrammaticalErrors;
$this->hideGrammaticalErrors = $hideGrammaticalErrors === null ? true : $hideGrammaticalErrors;
}

/**
Expand All @@ -126,6 +126,6 @@ public function hasEvenAndOddHeaders()
*/
public function setEvenAndOddHeaders($evenAndOddHeaders)
{
$this->evenAndOddHeaders = $evenAndOddHeaders;
$this->evenAndOddHeaders = $evenAndOddHeaders === null ? true : $evenAndOddHeaders;
}
}
1 change: 1 addition & 0 deletions src/PhpWord/Reader/Word2007.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ public function load($docFile)
array('stepPart' => 'document', 'stepItems' => array(
'endnotes' => 'Endnotes',
'footnotes' => 'Footnotes',
'settings' => 'Settings',
)),
);

Expand Down
76 changes: 76 additions & 0 deletions src/PhpWord/Reader/Word2007/Settings.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
<?php
/**
* This file is part of PHPWord - A pure PHP library for reading and writing
* word processing documents.
*
* PHPWord is free software distributed under the terms of the GNU Lesser
* General Public License version 3 as published by the Free Software Foundation.
*
* For the full copyright and license information, please read the LICENSE
* file that was distributed with this source code. For the full list of
* contributors, visit https://github.com/PHPOffice/PHPWord/contributors.
*
* @link https://github.com/PHPOffice/PHPWord
* @copyright 2010-2016 PHPWord contributors
* @license http:https://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/

namespace PhpOffice\PhpWord\Reader\Word2007;

use PhpOffice\Common\XMLReader;
use PhpOffice\PhpWord\PhpWord;
use PhpOffice\PhpWord\Metadata\Protection;

/**
* Settings reader
*
* @since 0.14.0
*/
class Settings extends AbstractPart
{

private static $booleanProperties = array('hideSpellingErrors', 'hideGrammaticalErrors', 'evenAndOddHeaders');
private static $decimalProperties = array('zoom');

/**
* Read settings.xml.
*
* @param \PhpOffice\PhpWord\PhpWord $phpWord
* @return void
*/
public function read(PhpWord $phpWord)
{
$xmlReader = new XMLReader();
$xmlReader->getDomFromZip($this->docFile, $this->xmlFile);

$docSettings = $phpWord->getSettings();

$nodes = $xmlReader->getElements('*');
if ($nodes->length > 0) {
foreach ($nodes as $node) {
$name = str_replace('w:', '', $node->nodeName);
$value = $xmlReader->getAttribute('w:val', $node);
$method = 'set' . $name;

if (in_array($name, $this::$booleanProperties)) {
if ($value == 'false') {
$docSettings->$method(false);
} else {
$docSettings->$method(true);
}
} else if (method_exists($this, $method)) {
$this->$method($xmlReader, $phpWord, $node);
} else if (method_exists($this, $method)) {
$docSettings->$method($value);
}
}
}
}

private function setDocumentProtection(XMLReader $xmlReader, PhpWord $phpWord, \DOMNode $node) {
$documentProtection = $phpWord->getSettings()->getDocumentProtection();

$edit = $xmlReader->getAttribute('w:edit', $node);
$documentProtection->setEditing($edit);
}
}

0 comments on commit b919d58

Please sign in to comment.