Allow to set "autoHyphenation" setting (#1282)

* Allow to set "autoHyphenation" for document
* Allow to set "consecutiveHyphenLimit" for document
* Allow to set "hyphenationZone" for document
* Allow to set "doNotHyphenateCaps" for document
* Allow to set "suppressAutoHyphens" for paragraph
* randomize the tempDir more
* Word2007 parsing title formatting (#1297)
* Improve Title parsing
- Title should be able to contain TextRun
- Style 'Title' should be treated the same with as Heading
- Add tests for Heading/Title reader
* update the documentation and the changelog
* PHP 7.2 build should not fail anymore
* fix parsing of footnotes and endnotes
* add method to remove an element from a section
* add method to allow sorting of sections
This commit is contained in:
Frank Liepert 2018-03-06 22:19:40 +01:00 committed by troosan
parent 250fbd49b1
commit 6a6497956d
20 changed files with 506 additions and 114 deletions

View File

@ -15,6 +15,7 @@ v0.15.0 (?? ??? 2018)
- Add parsing of formatting inside lists @atomicalnet @troosan #594
- Added support for Vertically Raised or Lowered Text (w:position) @anrikun @troosan #640
- Add support for MACROBUTTON field @phryneas @troosan #1021
- Add support for Hyphenation @Trainmaster #1282 (Document: `autoHyphenation`, `consecutiveHyphenLimit`, `hyphenationZone`, `doNotHyphenateCaps`, Paragraph: `suppressAutoHyphens`)
### Fixed
- Fix reading of docx default style - @troosan #1238
@ -477,4 +478,4 @@ This is the first release after a long development hiatus in [CodePlex](https://
- Basic CI with Travis - @Progi1984
- Added PHPWord_Exception and exception when could not copy the template - @Progi1984
- IMPROVED: Moved examples out of Classes directory - @Progi1984
- IMPROVED: Advanced string replace in setValue for Template - @Esmeraldo [#49](http://phpword.codeplex.com/workitem/49)
- IMPROVED: Advanced string replace in setValue for Template - @Esmeraldo [#49](http://phpword.codeplex.com/workitem/49)

View File

@ -217,10 +217,10 @@ The default language of the document can be change with the following.
$phpWord->getSettings()->setThemeFontLang(new Language(Language::FR_BE));
``Languge`` has 3 parameters, one for Latin languages, one for East Asian languages and one for Complex (Bi-Directional) languages.
``Language`` has 3 parameters, one for Latin languages, one for East Asian languages and one for Complex (Bi-Directional) languages.
A couple of language codes are provided in the ``PhpOffice\PhpWord\ComplexType\Language`` class but any valid code/ID can be used.
In case you are generating an RTF document the Language need to be set differently.
In case you are generating an RTF document the language need to be set differently.
.. code-block:: php
@ -290,3 +290,45 @@ To force an update of the fields present in the document, set updateFields to tr
.. code-block:: php
$phpWord->getSettings()->setUpdateFields(true);
Hyphenation
-----------
Hyphenation describes the process of breaking words with hyphens. There are several options to control hyphenation.
Auto hyphenation
~~~~~~~~~~~~~~~~
To automatically hyphenate text set ``autoHyphenation`` to ``true``.
.. code-block:: php
$phpWord->getSettings()->setAutoHyphenation(true);
Consecutive Hyphen Limit
~~~~~~~~~~~~~~~~~~~~~~~~
The maximum number of consecutive lines of text ending with a hyphen can be controlled by the ``consecutiveHyphenLimit`` option.
There is no limit if the option is not set or the provided value is ``0``.
.. code-block:: php
$phpWord->getSettings()->setConsecutiveHyphenLimit(2);
Hyphenation Zone
~~~~~~~~~~~~~~~~
The hyphenation zone (in *twip*) is the allowed amount of whitespace before hyphenation is applied.
The smaller the hyphenation zone the more words are hyphenated. Or in other words, the wider the hyphenation zone the less words are hyphenated.
.. code-block:: php
$phpWord->getSettings()->setHyphenationZone(\PhpOffice\PhpWord\Shared\Converter::cmToTwip(1));
Hyphenate Caps
~~~~~~~~~~~~~~
To control whether or not words in all capital letters shall be hyphenated use the `doNotHyphenateCaps` option.
.. code-block:: php
$phpWord->getSettings()->setDoNotHyphenateCaps(true);

View File

@ -82,6 +82,7 @@ Available Paragraph style options:
- ``spaceAfter``. Space after paragraph in *twip*.
- ``spacing``. Space between lines.
- ``spacingLineRule``. Line Spacing Rule. *auto*, *exact*, *atLeast*
- ``suppressAutoHyphens``. Hyphenation for paragraph, *true* or *false*.
- ``tabs``. Set of custom tab stops.
- ``widowControl``. Allow first/last line to display on a separate page, *true* or *false*.
- ``contextualSpacing``. Ignore Spacing Above and Below When Using Identical Styles, *true* or *false*.

View File

@ -17,8 +17,6 @@
namespace PhpOffice\PhpWord\Element;
use PhpOffice\PhpWord\Style\Font;
/**
* Field element
*
@ -215,46 +213,6 @@ class Field extends AbstractElement
return $this->options;
}
/**
* Set Text style
*
* @param \PhpOffice\PhpWord\Style\Font $style
* @return \PhpOffice\PhpWord\Style\Font
*/
public function setFontStyle($style = null)
{
if (!$style instanceof Font) {
throw new \InvalidArgumentException('font style must be of type Font');
}
if ($style->isNoProof()) {
$this->fontStyle = $style;
} else {
// make a copy of the font so the original is not altered
$this->fontStyle = clone $style;
$this->fontStyle->setNoProof(true);
}
return $this->fontStyle;
}
/**
* Get Text style
*
* @return \PhpOffice\PhpWord\Style\Font
*/
public function getFontStyle()
{
if ($this->fontStyle == null) {
$font = new Font();
$font->setNoProof(true);
return $font;
}
return $this->fontStyle;
}
/**
* Set Field text
*

View File

@ -130,6 +130,32 @@ class Settings
*/
private $decimalSymbol = '.';
/**
* Automatically hyphenate document contents when displayed
*
* @var bool|null
*/
private $autoHyphenation;
/**
* Maximum number of consecutively hyphenated lines
*
* @var int|null
*/
private $consecutiveHyphenLimit;
/**
* The allowed amount of whitespace before hyphenation is applied
* @var float|null
*/
private $hyphenationZone;
/**
* Do not hyphenate words in all capital letters
* @var bool|null
*/
private $doNotHyphenateCaps;
/**
* @return Protection
*/
@ -387,4 +413,68 @@ class Settings
{
$this->decimalSymbol = $decimalSymbol;
}
/**
* @return bool|null
*/
public function hasAutoHyphenation()
{
return $this->autoHyphenation;
}
/**
* @param bool $autoHyphenation
*/
public function setAutoHyphenation($autoHyphenation)
{
$this->autoHyphenation = (bool) $autoHyphenation;
}
/**
* @return int|null
*/
public function getConsecutiveHyphenLimit()
{
return $this->consecutiveHyphenLimit;
}
/**
* @param int $consecutiveHyphenLimit
*/
public function setConsecutiveHyphenLimit($consecutiveHyphenLimit)
{
$this->consecutiveHyphenLimit = (int) $consecutiveHyphenLimit;
}
/**
* @return float|null
*/
public function getHyphenationZone()
{
return $this->hyphenationZone;
}
/**
* @param float $hyphenationZone Measurement unit is twip
*/
public function setHyphenationZone($hyphenationZone)
{
$this->hyphenationZone = $hyphenationZone;
}
/**
* @return null|bool
*/
public function hasDoNotHyphenateCaps()
{
return $this->doNotHyphenateCaps;
}
/**
* @param bool $doNotHyphenateCaps
*/
public function setDoNotHyphenateCaps($doNotHyphenateCaps)
{
$this->doNotHyphenateCaps = (bool) $doNotHyphenateCaps;
}
}

View File

@ -242,6 +242,17 @@ class PhpWord
return $section;
}
/**
* Sorts the sections using the callable passed
*
* @see http://php.net/manual/en/function.usort.php for usage
* @param callable $sorter
*/
public function sortSections($sorter)
{
usort($this->sections, $sorter);
}
/**
* Get default font name
*

View File

@ -364,20 +364,21 @@ abstract class AbstractPart
$styleNode = $xmlReader->getElement('w:pPr', $domNode);
$styleDefs = array(
'styleName' => array(self::READ_VALUE, array('w:pStyle', 'w:name')),
'alignment' => array(self::READ_VALUE, 'w:jc'),
'basedOn' => array(self::READ_VALUE, 'w:basedOn'),
'next' => array(self::READ_VALUE, 'w:next'),
'indent' => array(self::READ_VALUE, 'w:ind', 'w:left'),
'hanging' => array(self::READ_VALUE, 'w:ind', 'w:hanging'),
'spaceAfter' => array(self::READ_VALUE, 'w:spacing', 'w:after'),
'spaceBefore' => array(self::READ_VALUE, 'w:spacing', 'w:before'),
'widowControl' => array(self::READ_FALSE, 'w:widowControl'),
'keepNext' => array(self::READ_TRUE, 'w:keepNext'),
'keepLines' => array(self::READ_TRUE, 'w:keepLines'),
'pageBreakBefore' => array(self::READ_TRUE, 'w:pageBreakBefore'),
'contextualSpacing' => array(self::READ_TRUE, 'w:contextualSpacing'),
'bidi' => array(self::READ_TRUE, 'w:bidi'),
'styleName' => array(self::READ_VALUE, array('w:pStyle', 'w:name')),
'alignment' => array(self::READ_VALUE, 'w:jc'),
'basedOn' => array(self::READ_VALUE, 'w:basedOn'),
'next' => array(self::READ_VALUE, 'w:next'),
'indent' => array(self::READ_VALUE, 'w:ind', 'w:left'),
'hanging' => array(self::READ_VALUE, 'w:ind', 'w:hanging'),
'spaceAfter' => array(self::READ_VALUE, 'w:spacing', 'w:after'),
'spaceBefore' => array(self::READ_VALUE, 'w:spacing', 'w:before'),
'widowControl' => array(self::READ_FALSE, 'w:widowControl'),
'keepNext' => array(self::READ_TRUE, 'w:keepNext'),
'keepLines' => array(self::READ_TRUE, 'w:keepLines'),
'pageBreakBefore' => array(self::READ_TRUE, 'w:pageBreakBefore'),
'contextualSpacing' => array(self::READ_TRUE, 'w:contextualSpacing'),
'bidi' => array(self::READ_TRUE, 'w:bidi'),
'suppressAutoHyphens' => array(self::READ_TRUE, 'w:suppressAutoHyphens'),
);
return $this->readStyleDefs($xmlReader, $styleNode, $styleDefs);
@ -578,7 +579,7 @@ abstract class AbstractPart
*
* @param string $method
* @ignoreScrutinizerPatch
* @param mixed $attributeValue
* @param string|null $attributeValue
* @param mixed $expected
* @return mixed
*/

View File

@ -29,7 +29,18 @@ use PhpOffice\PhpWord\Style\Language;
*/
class Settings extends AbstractPart
{
private static $booleanProperties = array('hideSpellingErrors', 'hideGrammaticalErrors', 'trackRevisions', 'doNotTrackMoves', 'doNotTrackFormatting', 'evenAndOddHeaders');
private static $booleanProperties = array(
'mirrorMargins',
'hideSpellingErrors',
'hideGrammaticalErrors',
'trackRevisions',
'doNotTrackMoves',
'doNotTrackFormatting',
'evenAndOddHeaders',
'updateFields',
'autoHyphenation',
'doNotHyphenateCaps',
);
/**
* Read settings.xml.
@ -157,4 +168,32 @@ class Settings extends AbstractPart
$revisionView->setInkAnnotations(filter_var($xmlReader->getAttribute('w:inkAnnotations', $node), FILTER_VALIDATE_BOOLEAN));
$phpWord->getSettings()->setRevisionView($revisionView);
}
/**
* @param XMLReader $xmlReader
* @param PhpWord $phpWord
* @param \DOMElement $node
*/
protected function setConsecutiveHyphenLimit(XMLReader $xmlReader, PhpWord $phpWord, \DOMElement $node)
{
$value = $xmlReader->getAttribute('w:val', $node);
if ($value !== null) {
$phpWord->getSettings()->setConsecutiveHyphenLimit($value);
}
}
/**
* @param XMLReader $xmlReader
* @param PhpWord $phpWord
* @param \DOMElement $node
*/
protected function setHyphenationZone(XMLReader $xmlReader, PhpWord $phpWord, \DOMElement $node)
{
$value = $xmlReader->getAttribute('w:val', $node);
if ($value !== null) {
$phpWord->getSettings()->setHyphenationZone($value);
}
}
}

View File

@ -252,7 +252,7 @@ class Html
$styles['font'] = self::recursiveParseStylesInHierarchy($node, $styles['font']);
//alignment applies on paragraph, not on font. Let's copy it there
if (isset($styles['font']['alignment'])) {
if (isset($styles['font']['alignment']) && is_array($styles['paragraph'])) {
$styles['paragraph']['alignment'] = $styles['font']['alignment'];
}

View File

@ -180,6 +180,13 @@ class Paragraph extends Border
*/
private $textAlignment;
/**
* Suppress hyphenation for paragraph
*
* @var bool
*/
private $suppressAutoHyphens = false;
/**
* Set Style value
*
@ -212,27 +219,28 @@ class Paragraph extends Border
public function getStyleValues()
{
$styles = array(
'name' => $this->getStyleName(),
'basedOn' => $this->getBasedOn(),
'next' => $this->getNext(),
'alignment' => $this->getAlignment(),
'indentation' => $this->getIndentation(),
'spacing' => $this->getSpace(),
'pagination' => array(
'widowControl' => $this->hasWidowControl(),
'keepNext' => $this->isKeepNext(),
'keepLines' => $this->isKeepLines(),
'pageBreak' => $this->hasPageBreakBefore(),
'name' => $this->getStyleName(),
'basedOn' => $this->getBasedOn(),
'next' => $this->getNext(),
'alignment' => $this->getAlignment(),
'indentation' => $this->getIndentation(),
'spacing' => $this->getSpace(),
'pagination' => array(
'widowControl' => $this->hasWidowControl(),
'keepNext' => $this->isKeepNext(),
'keepLines' => $this->isKeepLines(),
'pageBreak' => $this->hasPageBreakBefore(),
),
'numbering' => array(
'style' => $this->getNumStyle(),
'level' => $this->getNumLevel(),
'numbering' => array(
'style' => $this->getNumStyle(),
'level' => $this->getNumLevel(),
),
'tabs' => $this->getTabs(),
'shading' => $this->getShading(),
'contextualSpacing' => $this->hasContextualSpacing(),
'bidi' => $this->isBidi(),
'textAlignment' => $this->getTextAlignment(),
'tabs' => $this->getTabs(),
'shading' => $this->getShading(),
'contextualSpacing' => $this->hasContextualSpacing(),
'bidi' => $this->isBidi(),
'textAlignment' => $this->getTextAlignment(),
'suppressAutoHyphens' => $this->hasSuppressAutoHyphens(),
);
return $styles;
@ -848,4 +856,20 @@ class Paragraph extends Border
return $this;
}
/**
* @return bool
*/
public function hasSuppressAutoHyphens()
{
return $this->suppressAutoHyphens;
}
/**
* @param bool $suppressAutoHyphens
*/
public function setSuppressAutoHyphens($suppressAutoHyphens)
{
$this->suppressAutoHyphens = (bool) $suppressAutoHyphens;
}
}

View File

@ -222,8 +222,8 @@ class Content extends AbstractPart
* Table style can be null or string of the style name
*
* @param \PhpOffice\PhpWord\Element\AbstractContainer $container
* @param int &$paragraphStyleCount
* @param int &$fontStyleCount
* @param int $paragraphStyleCount
* @param int $fontStyleCount
* @todo Simplify the logic
*/
private function getContainerStyle($container, &$paragraphStyleCount, &$fontStyleCount)
@ -254,9 +254,9 @@ class Content extends AbstractPart
/**
* Get style of individual element
*
* @param \PhpOffice\PhpWord\Element\Text &$element
* @param int &$paragraphStyleCount
* @param int &$fontStyleCount
* @param \PhpOffice\PhpWord\Element\Text $element
* @param int $paragraphStyleCount
* @param int $fontStyleCount
*/
private function getElementStyle(&$element, &$paragraphStyleCount, &$fontStyleCount)
{

View File

@ -149,12 +149,16 @@ class Settings extends AbstractPart
$this->setOnOffValue('w:doNotTrackFormatting', $documentSettings->hasDoNotTrackFormatting());
$this->setOnOffValue('w:evenAndOddHeaders', $documentSettings->hasEvenAndOddHeaders());
$this->setOnOffValue('w:updateFields', $documentSettings->hasUpdateFields());
$this->setOnOffValue('w:autoHyphenation', $documentSettings->hasAutoHyphenation());
$this->setOnOffValue('w:doNotHyphenateCaps', $documentSettings->hasDoNotHyphenateCaps());
$this->setThemeFontLang($documentSettings->getThemeFontLang());
$this->setRevisionView($documentSettings->getRevisionView());
$this->setDocumentProtection($documentSettings->getDocumentProtection());
$this->setProofState($documentSettings->getProofState());
$this->setZoom($documentSettings->getZoom());
$this->setConsecutiveHyphenLimit($documentSettings->getConsecutiveHyphenLimit());
$this->setHyphenationZone($documentSettings->getHyphenationZone());
$this->setCompatibility();
}
@ -162,16 +166,18 @@ class Settings extends AbstractPart
* Adds a boolean attribute to the settings array
*
* @param string $settingName
* @param bool $booleanValue
* @param bool|null $booleanValue
*/
private function setOnOffValue($settingName, $booleanValue)
{
if ($booleanValue !== null && is_bool($booleanValue)) {
if ($booleanValue) {
$this->settings[$settingName] = array('@attributes' => array());
} else {
$this->settings[$settingName] = array('@attributes' => array('w:val' => 'false'));
}
if (!is_bool($booleanValue)) {
return;
}
if ($booleanValue) {
$this->settings[$settingName] = array('@attributes' => array());
} else {
$this->settings[$settingName] = array('@attributes' => array('w:val' => 'false'));
}
}
@ -278,6 +284,34 @@ class Settings extends AbstractPart
}
}
/**
* @param int|null $consecutiveHyphenLimit
*/
private function setConsecutiveHyphenLimit($consecutiveHyphenLimit)
{
if ($consecutiveHyphenLimit === null) {
return;
}
$this->settings['w:consecutiveHyphenLimit'] = array(
'@attributes' => array('w:val' => $consecutiveHyphenLimit),
);
}
/**
* @param float|null $hyphenationZone
*/
private function setHyphenationZone($hyphenationZone)
{
if ($hyphenationZone === null) {
return;
}
$this->settings['w:hyphenationZone'] = array(
'@attributes' => array('w:val' => $hyphenationZone),
);
}
/**
* Get compatibility setting.
*/

View File

@ -112,6 +112,9 @@ class Paragraph extends AbstractStyle
//Paragraph textAlignment
$xmlWriter->writeElementIf($styles['textAlignment'] !== null, 'w:textAlignment', 'w:val', $styles['textAlignment']);
// Hyphenation
$xmlWriter->writeElementIf($styles['suppressAutoHyphens'] === true, 'w:suppressAutoHyphens');
// Child style: alignment, indentation, spacing, and shading
$this->writeChildStyle($xmlWriter, 'Indentation', $styles['indentation']);
$this->writeChildStyle($xmlWriter, 'Spacing', $styles['spacing']);

View File

@ -184,11 +184,11 @@ class SectionTest extends \PHPUnit\Framework\TestCase
public function testRemoveElementByElement()
{
$section = new Section(1);
$fistText = $section->addText('firstText');
$firstText = $section->addText('firstText');
$secondText = $section->addText('secondText');
$this->assertEquals(2, $section->countElements());
$section->removeElement($fistText);
$section->removeElement($firstText);
$this->assertEquals(1, $section->countElements());
$this->assertEquals($secondText->getElementId(), $section->getElement(1)->getElementId());

View File

@ -172,4 +172,58 @@ class SettingsTest extends \PHPUnit\Framework\TestCase
$oSettings->setUpdateFields(true);
$this->assertTrue($oSettings->hasUpdateFields());
}
public function testAutoHyphenation()
{
$oSettings = new Settings();
$oSettings->setAutoHyphenation(true);
$this->assertTrue($oSettings->hasAutoHyphenation());
}
public function testDefaultAutoHyphenation()
{
$oSettings = new Settings();
$this->assertNull($oSettings->hasAutoHyphenation());
}
public function testConsecutiveHyphenLimit()
{
$consecutiveHypenLimit = 2;
$oSettings = new Settings();
$oSettings->setConsecutiveHyphenLimit($consecutiveHypenLimit);
$this->assertSame($consecutiveHypenLimit, $oSettings->getConsecutiveHyphenLimit());
}
public function testDefaultConsecutiveHyphenLimit()
{
$oSettings = new Settings();
$this->assertNull($oSettings->getConsecutiveHyphenLimit());
}
public function testHyphenationZone()
{
$hyphenationZoneInTwip = 100;
$oSettings = new Settings();
$oSettings->setHyphenationZone($hyphenationZoneInTwip);
$this->assertSame($hyphenationZoneInTwip, $oSettings->getHyphenationZone());
}
public function testDefaultHyphenationZone()
{
$oSettings = new Settings();
$this->assertNull($oSettings->getHyphenationZone());
}
public function testDoNotHyphenateCaps()
{
$oSettings = new Settings();
$oSettings->setDoNotHyphenateCaps(true);
$this->assertTrue($oSettings->hasDoNotHyphenateCaps());
}
public function testDefaultDoNotHyphenateCaps()
{
$oSettings = new Settings();
$this->assertNull($oSettings->hasDoNotHyphenateCaps());
}
}

View File

@ -171,4 +171,58 @@ class PhpWordTest extends \PHPUnit\Framework\TestCase
$phpWord = new PhpWord();
$phpWord->undefinedMethod();
}
/**
* @covers \PhpOffice\PhpWord\PhpWord::getSection
*/
public function testGetNotExistingSection()
{
$phpWord = new PhpWord();
$section = $phpWord->getSection(0);
$this->assertNull($section);
}
/**
* @covers \PhpOffice\PhpWord\PhpWord::getSection
*/
public function testGetSection()
{
$phpWord = new PhpWord();
$phpWord->addSection();
$section = $phpWord->getSection(0);
$this->assertNotNull($section);
}
/**
* @covers \PhpOffice\PhpWord\PhpWord::sortSections
*/
public function testSortSections()
{
$phpWord = new PhpWord();
$section1 = $phpWord->addSection();
$section1->addText('test1');
$section2 = $phpWord->addSection();
$section2->addText('test2');
$section2->addText('test3');
$this->assertEquals(1, $phpWord->getSection(0)->countElements());
$this->assertEquals(2, $phpWord->getSection(1)->countElements());
$phpWord->sortSections(function ($a, $b) {
$numElementsInA = $a->countElements();
$numElementsInB = $b->countElements();
if ($numElementsInA === $numElementsInB) {
return 0;
} elseif ($numElementsInA > $numElementsInB) {
return -1;
}
return 1;
});
$this->assertEquals(2, $phpWord->getSection(0)->countElements());
$this->assertEquals(1, $phpWord->getSection(1)->countElements());
}
}

View File

@ -81,9 +81,9 @@ class StyleTest extends AbstractTestReader
</w:r>
</w:p>';
$phpWord = $this->getDocumentFromString($documentXml);
$phpWord = $this->getDocumentFromString(array('document' => $documentXml));
$elements = $this->get($phpWord->getSections(), 0)->getElements();
$elements = $phpWord->getSection(0)->getElements();
$this->assertInstanceOf('PhpOffice\PhpWord\Element\Text', $elements[0]);
$this->assertInstanceOf('PhpOffice\PhpWord\Style\Font', $elements[0]->getFontStyle());
/** @var \PhpOffice\PhpWord\Style\Font $fontStyle */

View File

@ -67,23 +67,24 @@ class ParagraphTest extends \PHPUnit\Framework\TestCase
$object = new Paragraph();
$attributes = array(
'spaceAfter' => 240,
'spaceBefore' => 240,
'indent' => 1,
'hanging' => 1,
'spacing' => 120,
'spacingLineRule' => LineSpacingRule::AT_LEAST,
'basedOn' => 'Normal',
'next' => 'Normal',
'numStyle' => 'numStyle',
'numLevel' => 1,
'widowControl' => false,
'keepNext' => true,
'keepLines' => true,
'pageBreakBefore' => true,
'contextualSpacing' => true,
'textAlignment' => 'auto',
'bidi' => true,
'spaceAfter' => 240,
'spaceBefore' => 240,
'indent' => 1,
'hanging' => 1,
'spacing' => 120,
'spacingLineRule' => LineSpacingRule::AT_LEAST,
'basedOn' => 'Normal',
'next' => 'Normal',
'numStyle' => 'numStyle',
'numLevel' => 1,
'widowControl' => false,
'keepNext' => true,
'keepLines' => true,
'pageBreakBefore' => true,
'contextualSpacing' => true,
'textAlignment' => 'auto',
'bidi' => true,
'suppressAutoHyphens' => true,
);
foreach ($attributes as $key => $value) {
$get = $this->findGetter($key, $value, $object);

View File

@ -330,4 +330,68 @@ class SettingsTest extends \PHPUnit\Framework\TestCase
$element = $doc->getElement($path, $file);
$this->assertNotEquals('false', $element->getAttribute('w:val'));
}
public function testAutoHyphenation()
{
$phpWord = new PhpWord();
$phpWord->getSettings()->setAutoHyphenation(true);
$doc = TestHelperDOCX::getDocument($phpWord);
$file = 'word/settings.xml';
$path = '/w:settings/w:autoHyphenation';
$this->assertTrue($doc->elementExists($path, $file));
$element = $doc->getElement($path, $file);
$this->assertNotEquals('false', $element->getAttribute('w:val'));
}
public function testConsecutiveHyphenLimit()
{
$phpWord = new PhpWord();
$phpWord->getSettings()->setConsecutiveHyphenLimit(2);
$doc = TestHelperDOCX::getDocument($phpWord);
$file = 'word/settings.xml';
$path = '/w:settings/w:consecutiveHyphenLimit';
$this->assertTrue($doc->elementExists($path, $file));
$element = $doc->getElement($path, $file);
$this->assertSame('2', $element->getAttribute('w:val'));
}
public function testHyphenationZone()
{
$phpWord = new PhpWord();
$phpWord->getSettings()->setHyphenationZone(100);
$doc = TestHelperDOCX::getDocument($phpWord);
$file = 'word/settings.xml';
$path = '/w:settings/w:hyphenationZone';
$this->assertTrue($doc->elementExists($path, $file));
$element = $doc->getElement($path, $file);
$this->assertSame('100', $element->getAttribute('w:val'));
}
public function testDoNotHyphenateCaps()
{
$phpWord = new PhpWord();
$phpWord->getSettings()->setDoNotHyphenateCaps(true);
$doc = TestHelperDOCX::getDocument($phpWord);
$file = 'word/settings.xml';
$path = '/w:settings/w:doNotHyphenateCaps';
$this->assertTrue($doc->elementExists($path, $file));
$element = $doc->getElement($path, $file);
$this->assertNotEquals('false', $element->getAttribute('w:val'));
}
}

View File

@ -17,6 +17,7 @@
namespace PhpOffice\PhpWord\Writer\Word2007\Style;
use PhpOffice\PhpWord\Style\Paragraph as ParagraphStyle;
use PhpOffice\PhpWord\TestHelperDOCX;
/**
@ -49,4 +50,18 @@ class ParagraphTest extends \PHPUnit\Framework\TestCase
$path = '/w:document/w:body/w:p/w:pPr/w:numPr/w:ilvl';
$this->assertTrue($doc->elementExists($path));
}
public function testSuppressAutoHyphens()
{
$paragraphStyle = new ParagraphStyle();
$paragraphStyle->setSuppressAutoHyphens(true);
$phpWord = new \PhpOffice\PhpWord\PhpWord();
$section = $phpWord->addSection();
$section->addText('test', null, $paragraphStyle);
$doc = TestHelperDOCX::getDocument($phpWord, 'Word2007');
$path = '/w:document/w:body/w:p/w:pPr/w:suppressAutoHyphens';
$this->assertTrue($doc->elementExists($path));
}
}