Add possibility to show/hide spelling and grammatical errors (#985)
* Add possibility to show/hide spelling and grammatical errors
This commit is contained in:
parent
6a3135bff2
commit
e7c551a0bf
|
|
@ -11,6 +11,7 @@ composer.lock
|
|||
composer.phar
|
||||
vendor
|
||||
/report
|
||||
/build
|
||||
/samples/resources
|
||||
/samples/results
|
||||
/.settings
|
||||
|
|
|
|||
|
|
@ -109,8 +109,8 @@ Zip class
|
|||
By default, PHPWord uses `Zip extension <http://php.net/manual/en/book.zip.php>`__
|
||||
to deal with ZIP compressed archives and files inside them. If you can't have
|
||||
Zip extension installed on your server, you can use pure PHP library
|
||||
alternative, `PclZip <http://www.phpconcept.net/pclzip/>`__, which
|
||||
included with PHPWord.
|
||||
alternative, `PclZip <http://www.phpconcept.net/pclzip/>`__, which is
|
||||
included in PHPWord.
|
||||
|
||||
.. code-block:: php
|
||||
|
||||
|
|
@ -130,6 +130,17 @@ To turn it on set ``outputEscapingEnabled`` option to ``true`` in your PHPWord c
|
|||
|
||||
\PhpOffice\PhpWord\Settings::setOutputEscapingEnabled(true);
|
||||
|
||||
Spelling and grammatical checks
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
By default spelling and grammatical errors are shown as soon as you open a word document.
|
||||
For big documents this can slow down the opening of the document. You can hide the spelling and/or grammatical errors with:
|
||||
|
||||
.. code-block:: php
|
||||
|
||||
\PhpOffice\PhpWord\Settings::setSpellingErrorsHidden(true);
|
||||
\PhpOffice\PhpWord\Settings::setGrammaticalErrorsHidden(true);
|
||||
|
||||
Default font
|
||||
~~~~~~~~~~~~
|
||||
|
||||
|
|
@ -183,3 +194,16 @@ points to twips.
|
|||
$sectionStyle->setMarginLeft(\PhpOffice\PhpWord\Shared\Converter::inchToTwip(.5));
|
||||
// 2 cm right margin
|
||||
$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;
|
||||
|
||||
/**
|
||||
* Hide spelling errors
|
||||
* @var boolean
|
||||
*/
|
||||
private static $spellingErrorsHidden = false;
|
||||
|
||||
/**
|
||||
* Hide grammatical errors
|
||||
* @var boolean
|
||||
*/
|
||||
private static $grammaticalErrorsHidden = false;
|
||||
|
||||
/**
|
||||
* The user defined temporary directory.
|
||||
*
|
||||
|
|
@ -416,6 +428,46 @@ class Settings
|
|||
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
|
||||
*
|
||||
|
|
|
|||
|
|
@ -107,6 +107,8 @@ class Settings extends AbstractPart
|
|||
'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: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:listSeparator' => array('@attributes' => array('w:val' => ';')),
|
||||
'w:compat' => array(),
|
||||
|
|
|
|||
|
|
@ -114,6 +114,20 @@ class SettingsTest extends \PHPUnit_Framework_TestCase
|
|||
$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 set/get even and odd headers
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -68,6 +68,43 @@ class SettingsTest extends \PHPUnit_Framework_TestCase
|
|||
$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'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test even and odd headers
|
||||
*/
|
||||
|
|
|
|||
Loading…
Reference in New Issue