add reader for settings
This commit is contained in:
parent
e9cc289243
commit
b919d58bac
@ -90,7 +90,7 @@ class Settings
|
|||||||
*/
|
*/
|
||||||
public function setHideSpellingErrors($hideSpellingErrors)
|
public function setHideSpellingErrors($hideSpellingErrors)
|
||||||
{
|
{
|
||||||
$this->hideSpellingErrors = $hideSpellingErrors;
|
$this->hideSpellingErrors = $hideSpellingErrors === null ? true : $hideSpellingErrors;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -110,7 +110,7 @@ class Settings
|
|||||||
*/
|
*/
|
||||||
public function setHideGrammaticalErrors($hideGrammaticalErrors)
|
public function setHideGrammaticalErrors($hideGrammaticalErrors)
|
||||||
{
|
{
|
||||||
$this->hideGrammaticalErrors = $hideGrammaticalErrors;
|
$this->hideGrammaticalErrors = $hideGrammaticalErrors === null ? true : $hideGrammaticalErrors;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -126,6 +126,6 @@ class Settings
|
|||||||
*/
|
*/
|
||||||
public function setEvenAndOddHeaders($evenAndOddHeaders)
|
public function setEvenAndOddHeaders($evenAndOddHeaders)
|
||||||
{
|
{
|
||||||
$this->evenAndOddHeaders = $evenAndOddHeaders;
|
$this->evenAndOddHeaders = $evenAndOddHeaders === null ? true : $evenAndOddHeaders;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -55,6 +55,7 @@ class Word2007 extends AbstractReader implements ReaderInterface
|
|||||||
array('stepPart' => 'document', 'stepItems' => array(
|
array('stepPart' => 'document', 'stepItems' => array(
|
||||||
'endnotes' => 'Endnotes',
|
'endnotes' => 'Endnotes',
|
||||||
'footnotes' => 'Footnotes',
|
'footnotes' => 'Footnotes',
|
||||||
|
'settings' => 'Settings',
|
||||||
)),
|
)),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
76
src/PhpWord/Reader/Word2007/Settings.php
Normal file
76
src/PhpWord/Reader/Word2007/Settings.php
Normal file
@ -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://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);
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user