From ab9e012974e532e0090abe927d0dcd1b64f3407d Mon Sep 17 00:00:00 2001 From: OlisaevAG Date: Tue, 19 Nov 2024 17:23:41 +0300 Subject: [PATCH] Support for padding in a table cell. fix code style --- src/PhpWord/Shared/Html.php | 23 +++++++++++++-------- src/PhpWord/Style/Cell.php | 24 ++++++++++++++-------- src/PhpWord/Writer/Word2007/Style/Cell.php | 10 ++++----- 3 files changed, 34 insertions(+), 23 deletions(-) diff --git a/src/PhpWord/Shared/Html.php b/src/PhpWord/Shared/Html.php index 80848cd33f..9893ca9dab 100644 --- a/src/PhpWord/Shared/Html.php +++ b/src/PhpWord/Shared/Html.php @@ -805,24 +805,24 @@ protected static function parseStyleDeclarations(array $selectors, array $styles break; case 'padding': - $valueTop = $valueRight = $valueBottom = $valueLeft = null; - $cValue = preg_replace('# +#', ' ', trim($value)); - $paddingArr = explode(' ', $cValue); + $valueTop = $valueRight = $valueBottom = $valueLeft = null; + $cValue = preg_replace('# +#', ' ', trim($value)); + $paddingArr = explode(' ', $cValue); $countParams = count($paddingArr); if ($countParams == 1) { $valueTop = $valueRight = $valueBottom = $valueLeft = $paddingArr[0]; } elseif ($countParams == 2) { - $valueTop = $valueBottom = $paddingArr[0]; + $valueTop = $valueBottom = $paddingArr[0]; $valueRight = $valueLeft = $paddingArr[1]; } elseif ($countParams == 3) { - $valueTop = $paddingArr[0]; - $valueRight = $valueLeft = $paddingArr[1]; + $valueTop = $paddingArr[0]; + $valueRight = $valueLeft = $paddingArr[1]; $valueBottom = $paddingArr[2]; } elseif ($countParams == 4) { - $valueTop = $paddingArr[0]; - $valueRight = $paddingArr[1]; + $valueTop = $paddingArr[0]; + $valueRight = $paddingArr[1]; $valueBottom = $paddingArr[2]; - $valueLeft = $paddingArr[3]; + $valueLeft = $paddingArr[3]; } if ($valueTop !== null) { $styles['paddingTop'] = Converter::cssToTwip($valueTop); @@ -836,18 +836,23 @@ protected static function parseStyleDeclarations(array $selectors, array $styles if ($valueLeft !== null) { $styles['paddingLeft'] = Converter::cssToTwip($valueLeft); } + break; case 'padding-top': $styles['paddingTop'] = Converter::cssToTwip($value); + break; case 'padding-right': $styles['paddingRight'] = Converter::cssToTwip($value); + break; case 'padding-bottom': $styles['paddingBottom'] = Converter::cssToTwip($value); + break; case 'padding-left': $styles['paddingLeft'] = Converter::cssToTwip($value); + break; case 'border-color': diff --git a/src/PhpWord/Style/Cell.php b/src/PhpWord/Style/Cell.php index d404c4cf3a..7fb863349f 100644 --- a/src/PhpWord/Style/Cell.php +++ b/src/PhpWord/Style/Cell.php @@ -377,60 +377,66 @@ public function getNoWrap(): bool return $this->noWrap; } - /** * Get style padding-top. + * * @return mixed */ public function getPaddingTop() { return $this->paddingTop; } + /** * Set style padding-top. - * @param int $value * * @return $this */ - public function setPaddingTop(int $value): Cell + public function setPaddingTop(int $value): self { $this->paddingTop = $value; + return $this; } + /** * Get style padding-bottom. + * * @return mixed */ public function getPaddingBottom() { return $this->paddingBottom; } + /** * Set style padding-bottom. - * @param int $value * * @return $this */ - public function setPaddingBottom(int $value): Cell + public function setPaddingBottom(int $value): self { $this->paddingBottom = $value; + return $this; } + /** * Get style padding-left. + * * @return mixed */ public function getPaddingLeft() { return $this->paddingLeft; } + /** * Set style padding-left. - * @param int $value * * @return $this */ - public function setPaddingLeft(int $value): Cell + public function setPaddingLeft(int $value): self { $this->paddingLeft = $value; @@ -439,6 +445,7 @@ public function setPaddingLeft(int $value): Cell /** * Get style padding-right. + * * @return mixed */ public function getPaddingRight() @@ -448,11 +455,10 @@ public function getPaddingRight() /** * Set style padding-right. - * @param int $value * * @return $this */ - public function setPaddingRight(int $value): Cell + public function setPaddingRight(int $value): self { $this->paddingRight = $value; diff --git a/src/PhpWord/Writer/Word2007/Style/Cell.php b/src/PhpWord/Writer/Word2007/Style/Cell.php index 43611cc6e6..a7d6c90b9e 100644 --- a/src/PhpWord/Writer/Word2007/Style/Cell.php +++ b/src/PhpWord/Writer/Word2007/Style/Cell.php @@ -59,27 +59,27 @@ public function write(): void $paddingBottom = $style->getPaddingBottom(); $paddingRight = $style->getPaddingRight(); - if($paddingTop !== null || $paddingLeft !== null || $paddingBottom !== null || $paddingRight !== null){ + if ($paddingTop !== null || $paddingLeft !== null || $paddingBottom !== null || $paddingRight !== null) { $xmlWriter->startElement('w:tcMar'); - if($paddingTop !== null) { + if ($paddingTop !== null) { $xmlWriter->startElement('w:top'); $xmlWriter->writeAttribute('w:w', $paddingTop); $xmlWriter->writeAttribute('w:type', \PhpOffice\PhpWord\SimpleType\TblWidth::TWIP); $xmlWriter->endElement(); // w:top } - if($paddingLeft !== null) { + if ($paddingLeft !== null) { $xmlWriter->startElement('w:start'); $xmlWriter->writeAttribute('w:w', $paddingLeft); $xmlWriter->writeAttribute('w:type', \PhpOffice\PhpWord\SimpleType\TblWidth::TWIP); $xmlWriter->endElement(); // w:start } - if($paddingBottom !== null) { + if ($paddingBottom !== null) { $xmlWriter->startElement('w:bottom'); $xmlWriter->writeAttribute('w:w', $paddingBottom); $xmlWriter->writeAttribute('w:type', \PhpOffice\PhpWord\SimpleType\TblWidth::TWIP); $xmlWriter->endElement(); // w:bottom } - if($paddingRight !== null){ + if ($paddingRight !== null) { $xmlWriter->startElement('w:end'); $xmlWriter->writeAttribute('w:w', $paddingRight); $xmlWriter->writeAttribute('w:type', \PhpOffice\PhpWord\SimpleType\TblWidth::TWIP);