Merge branch 'show_hide_spelling_grammatical_errors' into develop
This commit is contained in:
commit
91f79d85cf
|
|
@ -183,3 +183,16 @@ points to twips.
|
||||||
$sectionStyle->setMarginLeft(\PhpOffice\PhpWord\Shared\Converter::inchToTwip(.5));
|
$sectionStyle->setMarginLeft(\PhpOffice\PhpWord\Shared\Converter::inchToTwip(.5));
|
||||||
// 2 cm right margin
|
// 2 cm right margin
|
||||||
$sectionStyle->setMarginRight(\PhpOffice\PhpWord\Shared\Converter::cmToTwip(2));
|
$sectionStyle->setMarginRight(\PhpOffice\PhpWord\Shared\Converter::cmToTwip(2));
|
||||||
|
|
||||||
|
Language
|
||||||
|
--------
|
||||||
|
|
||||||
|
You can hide spelling errors:
|
||||||
|
|
||||||
|
.. code-block:: php
|
||||||
|
\PhpOffice\PhpWord\Settings::setSpellingErrorsHidden(true);
|
||||||
|
|
||||||
|
And hide grammatical errors:
|
||||||
|
|
||||||
|
.. code-block:: php
|
||||||
|
\PhpOffice\PhpWord\Settings::setGrammaticalErrorsHidden(true);
|
||||||
|
|
|
||||||
|
|
@ -119,6 +119,18 @@ class Settings
|
||||||
*/
|
*/
|
||||||
private static $defaultFontSize = self::DEFAULT_FONT_SIZE;
|
private static $defaultFontSize = self::DEFAULT_FONT_SIZE;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Hide spelling errors
|
||||||
|
* @var boolean
|
||||||
|
*/
|
||||||
|
private static $spellingErrorsHidden = false;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Hide grammatical errors
|
||||||
|
* @var boolean
|
||||||
|
*/
|
||||||
|
private static $grammaticalErrorsHidden = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The user defined temporary directory.
|
* The user defined temporary directory.
|
||||||
*
|
*
|
||||||
|
|
@ -393,6 +405,46 @@ class Settings
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Are spelling errors hidden
|
||||||
|
*
|
||||||
|
* @return boolean
|
||||||
|
*/
|
||||||
|
public static function isSpellingErrorsHidden()
|
||||||
|
{
|
||||||
|
return self::$spellingErrorsHidden;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Hide spelling errors
|
||||||
|
*
|
||||||
|
* @param boolean $spellingErrorsHidden
|
||||||
|
*/
|
||||||
|
public static function setSpellingErrorsHidden($spellingErrorsHidden)
|
||||||
|
{
|
||||||
|
self::$spellingErrorsHidden = $spellingErrorsHidden;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Are grammatical errors hidden
|
||||||
|
*
|
||||||
|
* @return boolean
|
||||||
|
*/
|
||||||
|
public static function isGrammaticalErrorsHidden()
|
||||||
|
{
|
||||||
|
return self::$grammaticalErrorsHidden;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Hide grammatical errors
|
||||||
|
*
|
||||||
|
* @param boolean $grammaticalErrorsHidden
|
||||||
|
*/
|
||||||
|
public static function setGrammaticalErrorsHidden($grammaticalErrorsHidden)
|
||||||
|
{
|
||||||
|
self::$grammaticalErrorsHidden = $grammaticalErrorsHidden;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Load setting from phpword.yml or phpword.yml.dist
|
* Load setting from phpword.yml or phpword.yml.dist
|
||||||
*
|
*
|
||||||
|
|
|
||||||
|
|
@ -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
|
||||||
*
|
*
|
||||||
|
|
@ -104,6 +106,8 @@ class Settings extends AbstractPart
|
||||||
'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:themeFontLang' => array('@attributes' => array('w:val' => 'en-US')),
|
'w:themeFontLang' => array('@attributes' => array('w:val' => 'en-US')),
|
||||||
|
'w:hideSpellingErrors' => array('@attributes' => array('w:val' => DocumentSettings::isSpellingErrorsHidden() ? 'true' : 'false')),
|
||||||
|
'w:hideGrammaticalErrors' => array('@attributes' => array('w:val' => DocumentSettings::isGrammaticalErrorsHidden() ? 'true' : 'false')),
|
||||||
'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' => ';')),
|
||||||
'w:compat' => array(),
|
'w:compat' => array(),
|
||||||
|
|
|
||||||
|
|
@ -114,6 +114,20 @@ class SettingsTest extends \PHPUnit_Framework_TestCase
|
||||||
$this->assertFalse(Settings::setDefaultFontSize(null));
|
$this->assertFalse(Settings::setDefaultFontSize(null));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test set/get spelling and grammar
|
||||||
|
*/
|
||||||
|
public function testSetGetSpellingGrammar()
|
||||||
|
{
|
||||||
|
$this->assertFalse(Settings::isSpellingErrorsHidden());
|
||||||
|
Settings::setSpellingErrorsHidden(true);
|
||||||
|
$this->assertTrue(Settings::isSpellingErrorsHidden());
|
||||||
|
|
||||||
|
$this->assertFalse(Settings::isGrammaticalErrorsHidden());
|
||||||
|
Settings::setGrammaticalErrorsHidden(true);
|
||||||
|
$this->assertTrue(Settings::isGrammaticalErrorsHidden());
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test load config
|
* Test load config
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
|
|
@ -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,41 @@ 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 language
|
||||||
|
*/
|
||||||
|
public function testLanguage()
|
||||||
|
{
|
||||||
|
$phpWord = new PhpWord();
|
||||||
|
|
||||||
|
$doc = TestHelperDOCX::getDocument($phpWord);
|
||||||
|
|
||||||
|
$file = 'word/settings.xml';
|
||||||
|
|
||||||
|
$path = '/w:settings/w:themeFontLang';
|
||||||
|
$this->assertTrue($doc->elementExists($path, $file));
|
||||||
|
$element = $doc->getElement($path, $file);
|
||||||
|
|
||||||
|
$this->assertEquals('en-US', $element->getAttribute('w:val'));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test spelling
|
||||||
|
*/
|
||||||
|
public function testSpelling()
|
||||||
|
{
|
||||||
|
$phpWord = new PhpWord();
|
||||||
|
Settings::setSpellingErrorsHidden(true);
|
||||||
|
|
||||||
|
$doc = TestHelperDOCX::getDocument($phpWord);
|
||||||
|
|
||||||
|
$file = 'word/settings.xml';
|
||||||
|
|
||||||
|
$path = '/w:settings/w:hideSpellingErrors';
|
||||||
|
$this->assertTrue($doc->elementExists($path, $file));
|
||||||
|
$element = $doc->getElement($path, $file);
|
||||||
|
|
||||||
|
$this->assertEquals('true', $element->getAttribute('w:val'));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue