Additional type checks in style writers
This commit is contained in:
parent
7d5c62ab34
commit
c243a11e57
|
|
@ -17,7 +17,6 @@
|
||||||
|
|
||||||
namespace PhpOffice\PhpWord\Element;
|
namespace PhpOffice\PhpWord\Element;
|
||||||
|
|
||||||
use PhpOffice\PhpWord\Shared\String;
|
|
||||||
use PhpOffice\PhpWord\Style\ListItem as ListItemStyle;
|
use PhpOffice\PhpWord\Style\ListItem as ListItemStyle;
|
||||||
use PhpOffice\PhpWord\Style\Paragraph;
|
use PhpOffice\PhpWord\Style\Paragraph;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -153,14 +153,14 @@ class XMLWriter
|
||||||
/**
|
/**
|
||||||
* Write element if ...
|
* Write element if ...
|
||||||
*
|
*
|
||||||
* @param bool $condition
|
* @param bool|null $condition
|
||||||
* @param string $element
|
* @param string $element
|
||||||
* @param string $attribute
|
* @param string $attribute
|
||||||
* @param string $value
|
* @param string $value
|
||||||
*/
|
*/
|
||||||
public function writeElementIf($condition, $element, $attribute = null, $value = null)
|
public function writeElementIf($condition, $element, $attribute = null, $value = null)
|
||||||
{
|
{
|
||||||
if ($condition) {
|
if ($condition == true) {
|
||||||
if (is_null($attribute)) {
|
if (is_null($attribute)) {
|
||||||
$this->xmlWriter->writeElement($element, $value);
|
$this->xmlWriter->writeElement($element, $value);
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -174,13 +174,13 @@ class XMLWriter
|
||||||
/**
|
/**
|
||||||
* Write attribute if ...
|
* Write attribute if ...
|
||||||
*
|
*
|
||||||
* @param bool $condition
|
* @param bool|null $condition
|
||||||
* @param string $attribute
|
* @param string $attribute
|
||||||
* @param string $value
|
* @param string $value
|
||||||
*/
|
*/
|
||||||
public function writeAttributeIf($condition, $attribute, $value)
|
public function writeAttributeIf($condition, $attribute, $value)
|
||||||
{
|
{
|
||||||
if ($condition) {
|
if ($condition == true) {
|
||||||
$this->xmlWriter->writeAttribute($attribute, $value);
|
$this->xmlWriter->writeAttribute($attribute, $value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -651,7 +651,7 @@ class Font extends AbstractStyle
|
||||||
/**
|
/**
|
||||||
* Toggle $target property to false when $source true
|
* Toggle $target property to false when $source true
|
||||||
*
|
*
|
||||||
* @param bool $target Target property
|
* @param bool|null $target Target property
|
||||||
* @param bool $sourceValue
|
* @param bool $sourceValue
|
||||||
*/
|
*/
|
||||||
private function toggleFalse(&$target, $sourceValue)
|
private function toggleFalse(&$target, $sourceValue)
|
||||||
|
|
|
||||||
|
|
@ -87,12 +87,12 @@ abstract class AbstractStyle
|
||||||
/**
|
/**
|
||||||
* Get value if ...
|
* Get value if ...
|
||||||
*
|
*
|
||||||
* @param bool $condition
|
* @param bool|null $condition
|
||||||
* @param string $value
|
* @param string $value
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
protected function getValueIf($condition, $value)
|
protected function getValueIf($condition, $value)
|
||||||
{
|
{
|
||||||
return $condition ? $value : '';
|
return $condition == true ? $value : '';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -42,7 +42,7 @@ class Image extends AbstractStyle
|
||||||
if (!$style instanceof \PhpOffice\PhpWord\Style\Image) {
|
if (!$style instanceof \PhpOffice\PhpWord\Style\Image) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
$this->writeStyle();
|
$this->writeStyle($style);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -65,10 +65,9 @@ class Image extends AbstractStyle
|
||||||
/**
|
/**
|
||||||
* Write style attribute
|
* Write style attribute
|
||||||
*/
|
*/
|
||||||
protected function writeStyle()
|
protected function writeStyle(ImageStyle $style)
|
||||||
{
|
{
|
||||||
$xmlWriter = $this->getXmlWriter();
|
$xmlWriter = $this->getXmlWriter();
|
||||||
$style = $this->getStyle();
|
|
||||||
|
|
||||||
// Default style array
|
// Default style array
|
||||||
$styleArray = array(
|
$styleArray = array(
|
||||||
|
|
@ -77,7 +76,7 @@ class Image extends AbstractStyle
|
||||||
'mso-width-relative' => 'margin',
|
'mso-width-relative' => 'margin',
|
||||||
'mso-height-relative' => 'margin',
|
'mso-height-relative' => 'margin',
|
||||||
);
|
);
|
||||||
$styleArray = array_merge($styleArray, $this->getElementStyle());
|
$styleArray = array_merge($styleArray, $this->getElementStyle($style));
|
||||||
|
|
||||||
// Absolute/relative positioning
|
// Absolute/relative positioning
|
||||||
$positioning = $style->getPositioning();
|
$positioning = $style->getPositioning();
|
||||||
|
|
@ -123,9 +122,8 @@ class Image extends AbstractStyle
|
||||||
*
|
*
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
private function getElementStyle()
|
private function getElementStyle(ImageStyle $style)
|
||||||
{
|
{
|
||||||
$style = $this->getStyle();
|
|
||||||
$styles = array();
|
$styles = array();
|
||||||
$styleValues = array(
|
$styleValues = array(
|
||||||
'width' => $style->getWidth(),
|
'width' => $style->getWidth(),
|
||||||
|
|
|
||||||
|
|
@ -35,8 +35,8 @@ class TextBox extends Image
|
||||||
if (!$style instanceof \PhpOffice\PhpWord\Style\TextBox) {
|
if (!$style instanceof \PhpOffice\PhpWord\Style\TextBox) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
$this->writeStyle();
|
$this->writeStyle($style);
|
||||||
$this->writeBorder();
|
$this->writeBorder($style);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -50,6 +50,9 @@ class TextBox extends Image
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
$style = $this->getStyle();
|
$style = $this->getStyle();
|
||||||
|
if (!$style instanceof \PhpOffice\PhpWord\Style\TextBox) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
$relativePositions = array(
|
$relativePositions = array(
|
||||||
TextBoxStyle::POSITION_RELATIVE_TO_MARGIN => 'margin',
|
TextBoxStyle::POSITION_RELATIVE_TO_MARGIN => 'margin',
|
||||||
|
|
@ -88,7 +91,7 @@ class TextBox extends Image
|
||||||
public function writeInnerMargin()
|
public function writeInnerMargin()
|
||||||
{
|
{
|
||||||
$style = $this->getStyle();
|
$style = $this->getStyle();
|
||||||
if (!$style->hasInnerMargins()) {
|
if (!$style instanceof \PhpOffice\PhpWord\Style\TextBox || !$style->hasInnerMargins()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -100,10 +103,9 @@ class TextBox extends Image
|
||||||
/**
|
/**
|
||||||
* Writer border
|
* Writer border
|
||||||
*/
|
*/
|
||||||
private function writeBorder()
|
private function writeBorder(TextBoxStyle $style)
|
||||||
{
|
{
|
||||||
$xmlWriter = $this->getXmlWriter();
|
$xmlWriter = $this->getXmlWriter();
|
||||||
$style = $this->getStyle();
|
|
||||||
|
|
||||||
// Border size
|
// Border size
|
||||||
$borderSize = $style->getBorderSize();
|
$borderSize = $style->getBorderSize();
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue