add getter/setter on paragraph for child spacing rule

This commit is contained in:
troosan 2017-11-22 00:14:31 +01:00
parent ac357d10d5
commit 670d46e543
12 changed files with 120 additions and 17 deletions

View File

@ -18,6 +18,8 @@ This is the last version to support PHP 5.3
- Support for Comments - @troosan #1067 - Support for Comments - @troosan #1067
- Support for paragraph textAlignment - @troosan #1165 - Support for paragraph textAlignment - @troosan #1165
- Add support for HTML underline tag <u> in addHtml - @zNightFalLz #1186 - Add support for HTML underline tag <u> in addHtml - @zNightFalLz #1186
- Allow to change cell width unit - guillaume-ro-fr #986
- Allow to change the line height rule @troosan
### Fixed ### Fixed
- Loosen dependency to Zend - Loosen dependency to Zend

View File

@ -79,6 +79,8 @@ Available Paragraph style options:
- ``pageBreakBefore``. Start paragraph on next page, *true* or *false*. - ``pageBreakBefore``. Start paragraph on next page, *true* or *false*.
- ``spaceBefore``. Space before paragraph. - ``spaceBefore``. Space before paragraph.
- ``spaceAfter``. Space after paragraph. - ``spaceAfter``. Space after paragraph.
- ``spacing``. Space between lines.
- ``spacingLineRule``. Line Spacing Rule. *auto*, *exact*, *atLeast*
- ``tabs``. Set of custom tab stops. - ``tabs``. Set of custom tab stops.
- ``widowControl``. Allow first/last line to display on a separate page, *true* or *false*. - ``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*. - ``contextualSpacing``. Ignore Spacing Above and Below When Using Identical Styles, *true* or *false*.

View File

@ -91,7 +91,7 @@ class Settings
/** /**
* Spelling and Grammatical Checking State * Spelling and Grammatical Checking State
* *
* @var \PhpOffice\PhpWord\Metadata\ProofState * @var \PhpOffice\PhpWord\ComplexType\ProofState
*/ */
private $proofState; private $proofState;

View File

@ -21,6 +21,7 @@ use PhpOffice\PhpWord\Element\AbstractContainer;
use PhpOffice\PhpWord\Element\Row; use PhpOffice\PhpWord\Element\Row;
use PhpOffice\PhpWord\Element\Table; use PhpOffice\PhpWord\Element\Table;
use PhpOffice\PhpWord\SimpleType\Jc; use PhpOffice\PhpWord\SimpleType\Jc;
use PhpOffice\PhpWord\Element\Cell;
/** /**
* Common Html functions * Common Html functions
@ -276,8 +277,7 @@ class Html
* @param \DOMNode $node * @param \DOMNode $node
* @param \PhpOffice\PhpWord\Element\AbstractContainer $element * @param \PhpOffice\PhpWord\Element\AbstractContainer $element
* @param array &$styles * @param array &$styles
* @param string $argument1 Method name * @return Table $element
* @return \PhpOffice\PhpWord\Element\AbstractContainer $element
* *
* @todo As soon as TableItem, RowItem and CellItem support relative width and height * @todo As soon as TableItem, RowItem and CellItem support relative width and height
*/ */
@ -308,7 +308,7 @@ class Html
* @param \DOMNode $node * @param \DOMNode $node
* @param \PhpOffice\PhpWord\Element\Table $element * @param \PhpOffice\PhpWord\Element\Table $element
* @param array &$styles * @param array &$styles
* @return \PhpOffice\PhpWord\Element\AbstractContainer $element * @return Row $element
*/ */
private static function parseRow($node, $element, &$styles) private static function parseRow($node, $element, &$styles)
{ {
@ -326,7 +326,7 @@ class Html
* @param \DOMNode $node * @param \DOMNode $node
* @param \PhpOffice\PhpWord\Element\Table $element * @param \PhpOffice\PhpWord\Element\Table $element
* @param array &$styles * @param array &$styles
* @return \PhpOffice\PhpWord\Element\AbstractContainer $element * @return Cell $element
*/ */
private static function parseCell($node, $element, &$styles) private static function parseCell($node, $element, &$styles)
{ {

View File

@ -0,0 +1,45 @@
<?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.
*
* @see https://github.com/PHPOffice/PHPWord
* @copyright 2010-2017 PHPWord contributors
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/
namespace PhpOffice\PhpWord\SimpleType;
use PhpOffice\PhpWord\Shared\AbstractEnum;
/**
* Line Spacing Rule
*
* @since 0.14.0
*
* @see http://www.datypic.com/sc/ooxml/t-w_ST_LineSpacingRule.html
*/
final class LineSpacingRule extends AbstractEnum
{
/**
* Automatically Determined Line Height
*/
const AUTO = 'auto';
/**
* Exact Line Height
*/
const EXACT = 'exact';
/**
* Minimum Line Height
*/
const AT_LEAST = 'atLeast';
}

View File

@ -21,6 +21,7 @@ use PhpOffice\Common\Text;
use PhpOffice\PhpWord\Exception\InvalidStyleException; use PhpOffice\PhpWord\Exception\InvalidStyleException;
use PhpOffice\PhpWord\SimpleType\Jc; use PhpOffice\PhpWord\SimpleType\Jc;
use PhpOffice\PhpWord\SimpleType\TextAlignment; use PhpOffice\PhpWord\SimpleType\TextAlignment;
use PhpOffice\PhpWord\SimpleType\LineSpacingRule;
/** /**
* Paragraph style * Paragraph style
@ -489,6 +490,27 @@ class Paragraph extends Border
return $this->setSpace(array('line' => $value)); return $this->setSpace(array('line' => $value));
} }
/**
* Get spacing line rule
*
* @return string
*/
public function getSpacingLineRule()
{
return $this->getChildStyleValue($this->spacing, 'lineRule');
}
/**
* Set the spacing line rule
*
* @param string $value Possible values are defined in LineSpacingRule
* @return \PhpOffice\PhpWord\Style\Paragraph
*/
public function setSpacingLineRule($value)
{
return $this->setSpace(array('lineRule' => $value));
}
/** /**
* Get line height * Get line height
* *

View File

@ -17,10 +17,12 @@
namespace PhpOffice\PhpWord\Style; namespace PhpOffice\PhpWord\Style;
use PhpOffice\PhpWord\SimpleType\LineSpacingRule;
/** /**
* Spacing between lines and above/below paragraph style * Spacing between lines and above/below paragraph style
* *
* @see http://www.schemacentral.com/sc/ooxml/t-w_CT_Spacing.html * @see http://www.datypic.com/sc/ooxml/t-w_CT_Spacing.html
* @since 0.10.0 * @since 0.10.0
*/ */
class Spacing extends AbstractStyle class Spacing extends AbstractStyle
@ -51,7 +53,7 @@ class Spacing extends AbstractStyle
* *
* @var string * @var string
*/ */
private $rule = 'auto'; private $lineRule = LineSpacingRule::AUTO;
/** /**
* Create a new instance * Create a new instance
@ -137,6 +139,32 @@ class Spacing extends AbstractStyle
* *
* @return string * @return string
*/ */
public function getLineRule()
{
return $this->lineRule;
}
/**
* Set line rule
*
* @param string $value
* @return self
*/
public function setLineRule($value = null)
{
LineSpacingRule::validate($value);
$this->lineRule = $value;
return $this;
}
/**
* Get line rule
*
* @return string
* @deprecated Use getLineRule() instead
* @codeCoverageIgnore
*/
public function getRule() public function getRule()
{ {
return $this->rule; return $this->rule;
@ -147,10 +175,12 @@ class Spacing extends AbstractStyle
* *
* @param string $value * @param string $value
* @return self * @return self
* @deprecated Use setLineRule() instead
* @codeCoverageIgnore
*/ */
public function setRule($value = null) public function setRule($value = null)
{ {
$this->rule = $value; $this->rule = value;
return $this; return $this;
} }

View File

@ -50,7 +50,7 @@ abstract class AbstractElement
protected $withoutP = false; protected $withoutP = false;
/** /**
* @var \Zend\Escaper\Escaper * @var \Zend\Escaper\Escaper|\PhpOffice\PhpWord\Escaper\AbstractEscaper
*/ */
protected $escaper; protected $escaper;

View File

@ -46,7 +46,7 @@ class Spacing extends AbstractStyle
$line = $style->getLine(); $line = $style->getLine();
$xmlWriter->writeAttributeIf(!is_null($line), 'w:line', $line); $xmlWriter->writeAttributeIf(!is_null($line), 'w:line', $line);
$xmlWriter->writeAttributeIf(!is_null($line), 'w:lineRule', $style->getRule()); $xmlWriter->writeAttributeIf(!is_null($line), 'w:lineRule', $style->getLineRule());
$xmlWriter->endElement(); $xmlWriter->endElement();
} }

View File

@ -19,6 +19,7 @@ namespace PhpOffice\PhpWord\Style;
use PhpOffice\PhpWord\PhpWord; use PhpOffice\PhpWord\PhpWord;
use PhpOffice\PhpWord\TestHelperDOCX; use PhpOffice\PhpWord\TestHelperDOCX;
use PhpOffice\PhpWord\SimpleType\LineSpacingRule;
/** /**
* Test class for PhpOffice\PhpWord\Style\Paragraph * Test class for PhpOffice\PhpWord\Style\Paragraph
@ -71,6 +72,7 @@ class ParagraphTest extends \PHPUnit\Framework\TestCase
'indent' => 1, 'indent' => 1,
'hanging' => 1, 'hanging' => 1,
'spacing' => 120, 'spacing' => 120,
'spacingLineRule' => LineSpacingRule::AT_LEAST,
'basedOn' => 'Normal', 'basedOn' => 'Normal',
'next' => 'Normal', 'next' => 'Normal',
'numStyle' => 'numStyle', 'numStyle' => 'numStyle',

View File

@ -34,7 +34,7 @@ class SpacingTest extends \PHPUnit\Framework\TestCase
'before' => array(null, 10), 'before' => array(null, 10),
'after' => array(null, 10), 'after' => array(null, 10),
'line' => array(null, 10), 'line' => array(null, 10),
'rule' => array('auto', 'exact'), 'lineRule' => array('auto', 'exact'),
); );
foreach ($properties as $property => $value) { foreach ($properties as $property => $value) {
list($default, $expected) = $value; list($default, $expected) = $value;