add getter/setter on paragraph for child spacing rule
This commit is contained in:
parent
ac357d10d5
commit
670d46e543
|
|
@ -18,6 +18,8 @@ This is the last version to support PHP 5.3
|
|||
- Support for Comments - @troosan #1067
|
||||
- Support for paragraph textAlignment - @troosan #1165
|
||||
- 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
|
||||
- Loosen dependency to Zend
|
||||
|
|
|
|||
|
|
@ -79,6 +79,8 @@ Available Paragraph style options:
|
|||
- ``pageBreakBefore``. Start paragraph on next page, *true* or *false*.
|
||||
- ``spaceBefore``. Space before paragraph.
|
||||
- ``spaceAfter``. Space after paragraph.
|
||||
- ``spacing``. Space between lines.
|
||||
- ``spacingLineRule``. Line Spacing Rule. *auto*, *exact*, *atLeast*
|
||||
- ``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*.
|
||||
|
|
|
|||
|
|
@ -206,10 +206,10 @@ class Field extends AbstractElement
|
|||
/**
|
||||
* Set Field text
|
||||
*
|
||||
* @param string | TextRun $text
|
||||
* @param string|TextRun $text
|
||||
*
|
||||
* @throws \InvalidArgumentException
|
||||
* @return string | TextRun
|
||||
* @return string|TextRun
|
||||
*/
|
||||
public function setText($text)
|
||||
{
|
||||
|
|
@ -227,7 +227,7 @@ class Field extends AbstractElement
|
|||
/**
|
||||
* Get Field text
|
||||
*
|
||||
* @return string | TextRun
|
||||
* @return string|TextRun
|
||||
*/
|
||||
public function getText()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -91,7 +91,7 @@ class Settings
|
|||
/**
|
||||
* Spelling and Grammatical Checking State
|
||||
*
|
||||
* @var \PhpOffice\PhpWord\Metadata\ProofState
|
||||
* @var \PhpOffice\PhpWord\ComplexType\ProofState
|
||||
*/
|
||||
private $proofState;
|
||||
|
||||
|
|
|
|||
|
|
@ -21,6 +21,7 @@ use PhpOffice\PhpWord\Element\AbstractContainer;
|
|||
use PhpOffice\PhpWord\Element\Row;
|
||||
use PhpOffice\PhpWord\Element\Table;
|
||||
use PhpOffice\PhpWord\SimpleType\Jc;
|
||||
use PhpOffice\PhpWord\Element\Cell;
|
||||
|
||||
/**
|
||||
* Common Html functions
|
||||
|
|
@ -276,8 +277,7 @@ class Html
|
|||
* @param \DOMNode $node
|
||||
* @param \PhpOffice\PhpWord\Element\AbstractContainer $element
|
||||
* @param array &$styles
|
||||
* @param string $argument1 Method name
|
||||
* @return \PhpOffice\PhpWord\Element\AbstractContainer $element
|
||||
* @return Table $element
|
||||
*
|
||||
* @todo As soon as TableItem, RowItem and CellItem support relative width and height
|
||||
*/
|
||||
|
|
@ -308,7 +308,7 @@ class Html
|
|||
* @param \DOMNode $node
|
||||
* @param \PhpOffice\PhpWord\Element\Table $element
|
||||
* @param array &$styles
|
||||
* @return \PhpOffice\PhpWord\Element\AbstractContainer $element
|
||||
* @return Row $element
|
||||
*/
|
||||
private static function parseRow($node, $element, &$styles)
|
||||
{
|
||||
|
|
@ -326,7 +326,7 @@ class Html
|
|||
* @param \DOMNode $node
|
||||
* @param \PhpOffice\PhpWord\Element\Table $element
|
||||
* @param array &$styles
|
||||
* @return \PhpOffice\PhpWord\Element\AbstractContainer $element
|
||||
* @return Cell $element
|
||||
*/
|
||||
private static function parseCell($node, $element, &$styles)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -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';
|
||||
}
|
||||
|
|
@ -21,6 +21,7 @@ use PhpOffice\Common\Text;
|
|||
use PhpOffice\PhpWord\Exception\InvalidStyleException;
|
||||
use PhpOffice\PhpWord\SimpleType\Jc;
|
||||
use PhpOffice\PhpWord\SimpleType\TextAlignment;
|
||||
use PhpOffice\PhpWord\SimpleType\LineSpacingRule;
|
||||
|
||||
/**
|
||||
* Paragraph style
|
||||
|
|
@ -489,6 +490,27 @@ class Paragraph extends Border
|
|||
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
|
||||
*
|
||||
|
|
|
|||
|
|
@ -17,10 +17,12 @@
|
|||
|
||||
namespace PhpOffice\PhpWord\Style;
|
||||
|
||||
use PhpOffice\PhpWord\SimpleType\LineSpacingRule;
|
||||
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
class Spacing extends AbstractStyle
|
||||
|
|
@ -51,7 +53,7 @@ class Spacing extends AbstractStyle
|
|||
*
|
||||
* @var string
|
||||
*/
|
||||
private $rule = 'auto';
|
||||
private $lineRule = LineSpacingRule::AUTO;
|
||||
|
||||
/**
|
||||
* Create a new instance
|
||||
|
|
@ -137,6 +139,32 @@ class Spacing extends AbstractStyle
|
|||
*
|
||||
* @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()
|
||||
{
|
||||
return $this->rule;
|
||||
|
|
@ -147,10 +175,12 @@ class Spacing extends AbstractStyle
|
|||
*
|
||||
* @param string $value
|
||||
* @return self
|
||||
* @deprecated Use setLineRule() instead
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
public function setRule($value = null)
|
||||
{
|
||||
$this->rule = $value;
|
||||
$this->rule = value;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -50,7 +50,7 @@ abstract class AbstractElement
|
|||
protected $withoutP = false;
|
||||
|
||||
/**
|
||||
* @var \Zend\Escaper\Escaper
|
||||
* @var \Zend\Escaper\Escaper|\PhpOffice\PhpWord\Escaper\AbstractEscaper
|
||||
*/
|
||||
protected $escaper;
|
||||
|
||||
|
|
|
|||
|
|
@ -46,7 +46,7 @@ class Spacing extends AbstractStyle
|
|||
$line = $style->getLine();
|
||||
$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();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,6 +19,7 @@ namespace PhpOffice\PhpWord\Style;
|
|||
|
||||
use PhpOffice\PhpWord\PhpWord;
|
||||
use PhpOffice\PhpWord\TestHelperDOCX;
|
||||
use PhpOffice\PhpWord\SimpleType\LineSpacingRule;
|
||||
|
||||
/**
|
||||
* Test class for PhpOffice\PhpWord\Style\Paragraph
|
||||
|
|
@ -71,6 +72,7 @@ class ParagraphTest extends \PHPUnit\Framework\TestCase
|
|||
'indent' => 1,
|
||||
'hanging' => 1,
|
||||
'spacing' => 120,
|
||||
'spacingLineRule' => LineSpacingRule::AT_LEAST,
|
||||
'basedOn' => 'Normal',
|
||||
'next' => 'Normal',
|
||||
'numStyle' => 'numStyle',
|
||||
|
|
|
|||
|
|
@ -31,10 +31,10 @@ class SpacingTest extends \PHPUnit\Framework\TestCase
|
|||
{
|
||||
$object = new Spacing();
|
||||
$properties = array(
|
||||
'before' => array(null, 10),
|
||||
'after' => array(null, 10),
|
||||
'line' => array(null, 10),
|
||||
'rule' => array('auto', 'exact'),
|
||||
'before' => array(null, 10),
|
||||
'after' => array(null, 10),
|
||||
'line' => array(null, 10),
|
||||
'lineRule' => array('auto', 'exact'),
|
||||
);
|
||||
foreach ($properties as $property => $value) {
|
||||
list($default, $expected) = $value;
|
||||
|
|
|
|||
Loading…
Reference in New Issue