Skip to content

Commit 670d46e

Browse files
committed
add getter/setter on paragraph for child spacing rule
1 parent ac357d1 commit 670d46e

File tree

12 files changed

+120
-17
lines changed

12 files changed

+120
-17
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ This is the last version to support PHP 5.3
1818
- Support for Comments - @troosan #1067
1919
- Support for paragraph textAlignment - @troosan #1165
2020
- Add support for HTML underline tag <u> in addHtml - @zNightFalLz #1186
21+
- Allow to change cell width unit - guillaume-ro-fr #986
22+
- Allow to change the line height rule @troosan
2123

2224
### Fixed
2325
- Loosen dependency to Zend

docs/styles.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,8 @@ Available Paragraph style options:
7979
- ``pageBreakBefore``. Start paragraph on next page, *true* or *false*.
8080
- ``spaceBefore``. Space before paragraph.
8181
- ``spaceAfter``. Space after paragraph.
82+
- ``spacing``. Space between lines.
83+
- ``spacingLineRule``. Line Spacing Rule. *auto*, *exact*, *atLeast*
8284
- ``tabs``. Set of custom tab stops.
8385
- ``widowControl``. Allow first/last line to display on a separate page, *true* or *false*.
8486
- ``contextualSpacing``. Ignore Spacing Above and Below When Using Identical Styles, *true* or *false*.

src/PhpWord/Element/Field.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -206,10 +206,10 @@ public function getOptions()
206206
/**
207207
* Set Field text
208208
*
209-
* @param string | TextRun $text
209+
* @param string|TextRun $text
210210
*
211211
* @throws \InvalidArgumentException
212-
* @return string | TextRun
212+
* @return string|TextRun
213213
*/
214214
public function setText($text)
215215
{
@@ -227,7 +227,7 @@ public function setText($text)
227227
/**
228228
* Get Field text
229229
*
230-
* @return string | TextRun
230+
* @return string|TextRun
231231
*/
232232
public function getText()
233233
{

src/PhpWord/Metadata/Settings.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ class Settings
9191
/**
9292
* Spelling and Grammatical Checking State
9393
*
94-
* @var \PhpOffice\PhpWord\Metadata\ProofState
94+
* @var \PhpOffice\PhpWord\ComplexType\ProofState
9595
*/
9696
private $proofState;
9797

src/PhpWord/Shared/Html.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
use PhpOffice\PhpWord\Element\Row;
2222
use PhpOffice\PhpWord\Element\Table;
2323
use PhpOffice\PhpWord\SimpleType\Jc;
24+
use PhpOffice\PhpWord\Element\Cell;
2425

2526
/**
2627
* Common Html functions
@@ -276,8 +277,7 @@ private static function parseSpan($node, &$styles)
276277
* @param \DOMNode $node
277278
* @param \PhpOffice\PhpWord\Element\AbstractContainer $element
278279
* @param array &$styles
279-
* @param string $argument1 Method name
280-
* @return \PhpOffice\PhpWord\Element\AbstractContainer $element
280+
* @return Table $element
281281
*
282282
* @todo As soon as TableItem, RowItem and CellItem support relative width and height
283283
*/
@@ -308,7 +308,7 @@ private static function parseTable($node, $element, &$styles)
308308
* @param \DOMNode $node
309309
* @param \PhpOffice\PhpWord\Element\Table $element
310310
* @param array &$styles
311-
* @return \PhpOffice\PhpWord\Element\AbstractContainer $element
311+
* @return Row $element
312312
*/
313313
private static function parseRow($node, $element, &$styles)
314314
{
@@ -326,7 +326,7 @@ private static function parseRow($node, $element, &$styles)
326326
* @param \DOMNode $node
327327
* @param \PhpOffice\PhpWord\Element\Table $element
328328
* @param array &$styles
329-
* @return \PhpOffice\PhpWord\Element\AbstractContainer $element
329+
* @return Cell $element
330330
*/
331331
private static function parseCell($node, $element, &$styles)
332332
{
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<?php
2+
/**
3+
* This file is part of PHPWord - A pure PHP library for reading and writing
4+
* word processing documents.
5+
*
6+
* PHPWord is free software distributed under the terms of the GNU Lesser
7+
* General Public License version 3 as published by the Free Software Foundation.
8+
*
9+
* For the full copyright and license information, please read the LICENSE
10+
* file that was distributed with this source code. For the full list of
11+
* contributors, visit https://github.com/PHPOffice/PHPWord/contributors.
12+
*
13+
* @see https://github.com/PHPOffice/PHPWord
14+
* @copyright 2010-2017 PHPWord contributors
15+
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
16+
*/
17+
18+
namespace PhpOffice\PhpWord\SimpleType;
19+
20+
use PhpOffice\PhpWord\Shared\AbstractEnum;
21+
22+
/**
23+
* Line Spacing Rule
24+
*
25+
* @since 0.14.0
26+
*
27+
* @see http://www.datypic.com/sc/ooxml/t-w_ST_LineSpacingRule.html
28+
*/
29+
final class LineSpacingRule extends AbstractEnum
30+
{
31+
/**
32+
* Automatically Determined Line Height
33+
*/
34+
const AUTO = 'auto';
35+
36+
/**
37+
* Exact Line Height
38+
*/
39+
const EXACT = 'exact';
40+
41+
/**
42+
* Minimum Line Height
43+
*/
44+
const AT_LEAST = 'atLeast';
45+
}

src/PhpWord/Style/Paragraph.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
use PhpOffice\PhpWord\Exception\InvalidStyleException;
2222
use PhpOffice\PhpWord\SimpleType\Jc;
2323
use PhpOffice\PhpWord\SimpleType\TextAlignment;
24+
use PhpOffice\PhpWord\SimpleType\LineSpacingRule;
2425

2526
/**
2627
* Paragraph style
@@ -489,6 +490,27 @@ public function setSpacing($value = null)
489490
return $this->setSpace(array('line' => $value));
490491
}
491492

493+
/**
494+
* Get spacing line rule
495+
*
496+
* @return string
497+
*/
498+
public function getSpacingLineRule()
499+
{
500+
return $this->getChildStyleValue($this->spacing, 'lineRule');
501+
}
502+
503+
/**
504+
* Set the spacing line rule
505+
*
506+
* @param string $value Possible values are defined in LineSpacingRule
507+
* @return \PhpOffice\PhpWord\Style\Paragraph
508+
*/
509+
public function setSpacingLineRule($value)
510+
{
511+
return $this->setSpace(array('lineRule' => $value));
512+
}
513+
492514
/**
493515
* Get line height
494516
*

src/PhpWord/Style/Spacing.php

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,12 @@
1717

1818
namespace PhpOffice\PhpWord\Style;
1919

20+
use PhpOffice\PhpWord\SimpleType\LineSpacingRule;
21+
2022
/**
2123
* Spacing between lines and above/below paragraph style
2224
*
23-
* @see http://www.schemacentral.com/sc/ooxml/t-w_CT_Spacing.html
25+
* @see http://www.datypic.com/sc/ooxml/t-w_CT_Spacing.html
2426
* @since 0.10.0
2527
*/
2628
class Spacing extends AbstractStyle
@@ -51,7 +53,7 @@ class Spacing extends AbstractStyle
5153
*
5254
* @var string
5355
*/
54-
private $rule = 'auto';
56+
private $lineRule = LineSpacingRule::AUTO;
5557

5658
/**
5759
* Create a new instance
@@ -137,6 +139,32 @@ public function setLine($value = null)
137139
*
138140
* @return string
139141
*/
142+
public function getLineRule()
143+
{
144+
return $this->lineRule;
145+
}
146+
147+
/**
148+
* Set line rule
149+
*
150+
* @param string $value
151+
* @return self
152+
*/
153+
public function setLineRule($value = null)
154+
{
155+
LineSpacingRule::validate($value);
156+
$this->lineRule = $value;
157+
158+
return $this;
159+
}
160+
161+
/**
162+
* Get line rule
163+
*
164+
* @return string
165+
* @deprecated Use getLineRule() instead
166+
* @codeCoverageIgnore
167+
*/
140168
public function getRule()
141169
{
142170
return $this->rule;
@@ -147,10 +175,12 @@ public function getRule()
147175
*
148176
* @param string $value
149177
* @return self
178+
* @deprecated Use setLineRule() instead
179+
* @codeCoverageIgnore
150180
*/
151181
public function setRule($value = null)
152182
{
153-
$this->rule = $value;
183+
$this->rule = value;
154184

155185
return $this;
156186
}

src/PhpWord/Writer/HTML/Element/AbstractElement.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ abstract class AbstractElement
5050
protected $withoutP = false;
5151

5252
/**
53-
* @var \Zend\Escaper\Escaper
53+
* @var \Zend\Escaper\Escaper|\PhpOffice\PhpWord\Escaper\AbstractEscaper
5454
*/
5555
protected $escaper;
5656

src/PhpWord/Writer/Word2007/Style/Spacing.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public function write()
4646
$line = $style->getLine();
4747
$xmlWriter->writeAttributeIf(!is_null($line), 'w:line', $line);
4848

49-
$xmlWriter->writeAttributeIf(!is_null($line), 'w:lineRule', $style->getRule());
49+
$xmlWriter->writeAttributeIf(!is_null($line), 'w:lineRule', $style->getLineRule());
5050

5151
$xmlWriter->endElement();
5252
}

0 commit comments

Comments
 (0)