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