diff --git a/CHANGELOG.md b/CHANGELOG.md index af109b3f..5e39ed3f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 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 diff --git a/docs/styles.rst b/docs/styles.rst index f223574f..6166f5c9 100644 --- a/docs/styles.rst +++ b/docs/styles.rst @@ -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*. diff --git a/src/PhpWord/Element/Field.php b/src/PhpWord/Element/Field.php index 726938b5..d51cba8d 100644 --- a/src/PhpWord/Element/Field.php +++ b/src/PhpWord/Element/Field.php @@ -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() { diff --git a/src/PhpWord/Metadata/Settings.php b/src/PhpWord/Metadata/Settings.php index 412f5c52..33f72cca 100644 --- a/src/PhpWord/Metadata/Settings.php +++ b/src/PhpWord/Metadata/Settings.php @@ -91,7 +91,7 @@ class Settings /** * Spelling and Grammatical Checking State * - * @var \PhpOffice\PhpWord\Metadata\ProofState + * @var \PhpOffice\PhpWord\ComplexType\ProofState */ private $proofState; diff --git a/src/PhpWord/Shared/Html.php b/src/PhpWord/Shared/Html.php index 479e0f46..5319c879 100644 --- a/src/PhpWord/Shared/Html.php +++ b/src/PhpWord/Shared/Html.php @@ -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) { diff --git a/src/PhpWord/SimpleType/LineSpacingRule.php b/src/PhpWord/SimpleType/LineSpacingRule.php new file mode 100644 index 00000000..f2cc5e63 --- /dev/null +++ b/src/PhpWord/SimpleType/LineSpacingRule.php @@ -0,0 +1,45 @@ +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 * diff --git a/src/PhpWord/Style/Spacing.php b/src/PhpWord/Style/Spacing.php index e0eee374..a932eb1a 100644 --- a/src/PhpWord/Style/Spacing.php +++ b/src/PhpWord/Style/Spacing.php @@ -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; } diff --git a/src/PhpWord/Writer/HTML/Element/AbstractElement.php b/src/PhpWord/Writer/HTML/Element/AbstractElement.php index f6e06258..47f0f93c 100644 --- a/src/PhpWord/Writer/HTML/Element/AbstractElement.php +++ b/src/PhpWord/Writer/HTML/Element/AbstractElement.php @@ -50,7 +50,7 @@ abstract class AbstractElement protected $withoutP = false; /** - * @var \Zend\Escaper\Escaper + * @var \Zend\Escaper\Escaper|\PhpOffice\PhpWord\Escaper\AbstractEscaper */ protected $escaper; diff --git a/src/PhpWord/Writer/Word2007/Style/Spacing.php b/src/PhpWord/Writer/Word2007/Style/Spacing.php index 8db78161..c18339bd 100644 --- a/src/PhpWord/Writer/Word2007/Style/Spacing.php +++ b/src/PhpWord/Writer/Word2007/Style/Spacing.php @@ -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(); } diff --git a/tests/PhpWord/Style/ParagraphTest.php b/tests/PhpWord/Style/ParagraphTest.php index 48acc600..68c0c12e 100644 --- a/tests/PhpWord/Style/ParagraphTest.php +++ b/tests/PhpWord/Style/ParagraphTest.php @@ -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', diff --git a/tests/PhpWord/Style/SpacingTest.php b/tests/PhpWord/Style/SpacingTest.php index 2c26f68b..65be8092 100644 --- a/tests/PhpWord/Style/SpacingTest.php +++ b/tests/PhpWord/Style/SpacingTest.php @@ -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;