Merge pull request #1088 from troosan/add_support_for_contextual_spacing
Add support for contextual spacing
This commit is contained in:
commit
ce492133a6
@ -77,6 +77,7 @@ See ``\PhpOffice\PhpWord\SimpleType\Jc`` class for the details.
|
|||||||
- ``spaceAfter``. Space after paragraph.
|
- ``spaceAfter``. Space after paragraph.
|
||||||
- ``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*.
|
||||||
|
|
||||||
.. _table-style:
|
.. _table-style:
|
||||||
|
|
||||||
|
|||||||
@ -157,6 +157,13 @@ class Paragraph extends Border
|
|||||||
* @var \PhpOffice\PhpWord\Style\Shading
|
* @var \PhpOffice\PhpWord\Style\Shading
|
||||||
*/
|
*/
|
||||||
private $shading;
|
private $shading;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Ignore Spacing Above and Below When Using Identical Styles
|
||||||
|
*
|
||||||
|
* @var bool
|
||||||
|
*/
|
||||||
|
private $contextualSpacing = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set Style value
|
* Set Style value
|
||||||
@ -208,6 +215,7 @@ class Paragraph extends Border
|
|||||||
),
|
),
|
||||||
'tabs' => $this->getTabs(),
|
'tabs' => $this->getTabs(),
|
||||||
'shading' => $this->getShading(),
|
'shading' => $this->getShading(),
|
||||||
|
'contextualSpacing' => $this->hasContextualSpacing(),
|
||||||
);
|
);
|
||||||
|
|
||||||
return $styles;
|
return $styles;
|
||||||
@ -731,4 +739,27 @@ class Paragraph extends Border
|
|||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get contextualSpacing
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function hasContextualSpacing()
|
||||||
|
{
|
||||||
|
return $this->contextualSpacing;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set contextualSpacing
|
||||||
|
*
|
||||||
|
* @param bool $contextualSpacing
|
||||||
|
* @return self
|
||||||
|
*/
|
||||||
|
public function setContextualSpacing($contextualSpacing)
|
||||||
|
{
|
||||||
|
$this->contextualSpacing = $contextualSpacing;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -106,6 +106,9 @@ class Paragraph extends AbstractStyle
|
|||||||
}
|
}
|
||||||
$xmlWriter->endElement();
|
$xmlWriter->endElement();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Paragraph contextualSpacing
|
||||||
|
$xmlWriter->writeElementIf($styles['contextualSpacing'] === true, 'w:contextualSpacing');
|
||||||
|
|
||||||
// Child style: alignment, indentation, spacing, and shading
|
// Child style: alignment, indentation, spacing, and shading
|
||||||
$this->writeChildStyle($xmlWriter, 'Indentation', $styles['indentation']);
|
$this->writeChildStyle($xmlWriter, 'Indentation', $styles['indentation']);
|
||||||
|
|||||||
@ -43,13 +43,14 @@ class ParagraphTest extends \PHPUnit_Framework_TestCase
|
|||||||
$object = new Paragraph();
|
$object = new Paragraph();
|
||||||
|
|
||||||
$attributes = array(
|
$attributes = array(
|
||||||
'widowControl' => true,
|
'widowControl' => true,
|
||||||
'keepNext' => false,
|
'keepNext' => false,
|
||||||
'keepLines' => false,
|
'keepLines' => false,
|
||||||
'pageBreakBefore' => false,
|
'pageBreakBefore' => false,
|
||||||
|
'contextualSpacing' => false,
|
||||||
);
|
);
|
||||||
foreach ($attributes as $key => $default) {
|
foreach ($attributes as $key => $default) {
|
||||||
$get = "get{$key}";
|
$get = $this->findGetter($key, $default, $object);
|
||||||
$object->setStyleValue($key, null);
|
$object->setStyleValue($key, null);
|
||||||
$this->assertEquals($default, $object->$get());
|
$this->assertEquals($default, $object->$get());
|
||||||
$object->setStyleValue($key, '');
|
$object->setStyleValue($key, '');
|
||||||
@ -65,22 +66,23 @@ class ParagraphTest extends \PHPUnit_Framework_TestCase
|
|||||||
$object = new Paragraph();
|
$object = new Paragraph();
|
||||||
|
|
||||||
$attributes = array(
|
$attributes = array(
|
||||||
'spaceAfter' => 240,
|
'spaceAfter' => 240,
|
||||||
'spaceBefore' => 240,
|
'spaceBefore' => 240,
|
||||||
'indent' => 1,
|
'indent' => 1,
|
||||||
'hanging' => 1,
|
'hanging' => 1,
|
||||||
'spacing' => 120,
|
'spacing' => 120,
|
||||||
'basedOn' => 'Normal',
|
'basedOn' => 'Normal',
|
||||||
'next' => 'Normal',
|
'next' => 'Normal',
|
||||||
'numStyle' => 'numStyle',
|
'numStyle' => 'numStyle',
|
||||||
'numLevel' => 1,
|
'numLevel' => 1,
|
||||||
'widowControl' => false,
|
'widowControl' => false,
|
||||||
'keepNext' => true,
|
'keepNext' => true,
|
||||||
'keepLines' => true,
|
'keepLines' => true,
|
||||||
'pageBreakBefore' => true,
|
'pageBreakBefore' => true,
|
||||||
|
'contextualSpacing' => true,
|
||||||
);
|
);
|
||||||
foreach ($attributes as $key => $value) {
|
foreach ($attributes as $key => $value) {
|
||||||
$get = "get{$key}";
|
$get = $this->findGetter($key, $value, $object);
|
||||||
$object->setStyleValue("$key", $value);
|
$object->setStyleValue("$key", $value);
|
||||||
if ('indent' == $key || 'hanging' == $key) {
|
if ('indent' == $key || 'hanging' == $key) {
|
||||||
$value = $value * 720;
|
$value = $value * 720;
|
||||||
@ -91,6 +93,18 @@ class ParagraphTest extends \PHPUnit_Framework_TestCase
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function findGetter($key, $value, $object)
|
||||||
|
{
|
||||||
|
if (is_bool($value)) {
|
||||||
|
if (method_exists($object, "is{$key}")) {
|
||||||
|
return "is{$key}";
|
||||||
|
} else if (method_exists($object, "has{$key}")) {
|
||||||
|
return "has{$key}";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return "get{$key}";
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test get null style value
|
* Test get null style value
|
||||||
*/
|
*/
|
||||||
@ -100,7 +114,7 @@ class ParagraphTest extends \PHPUnit_Framework_TestCase
|
|||||||
|
|
||||||
$attributes = array('spacing', 'indent', 'hanging', 'spaceBefore', 'spaceAfter');
|
$attributes = array('spacing', 'indent', 'hanging', 'spaceBefore', 'spaceAfter');
|
||||||
foreach ($attributes as $key) {
|
foreach ($attributes as $key) {
|
||||||
$get = "get{$key}";
|
$get = $this->findGetter($key, null, $object);
|
||||||
$this->assertNull($object->$get());
|
$this->assertNull($object->$get());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user