From 3e182f0ef6c28b5642b7707a2ebe3d96f54c293a Mon Sep 17 00:00:00 2001 From: OlisaevAG Date: Tue, 19 Nov 2024 16:40:25 +0300 Subject: [PATCH 01/14] Support for padding in a table cell --- src/PhpWord/Shared/Html.php | 47 ++++++++++ src/PhpWord/Style/Cell.php | 102 +++++++++++++++++++++ src/PhpWord/Writer/Word2007/Style/Cell.php | 34 +++++++ 3 files changed, 183 insertions(+) diff --git a/src/PhpWord/Shared/Html.php b/src/PhpWord/Shared/Html.php index 334f5c269e..80848cd33f 100644 --- a/src/PhpWord/Shared/Html.php +++ b/src/PhpWord/Shared/Html.php @@ -803,6 +803,53 @@ protected static function parseStyleDeclarations(array $selectors, array $styles $styles['spaceAfter'] = Converter::cssToTwip($value); break; + + case 'padding': + $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]; + $valueRight = $valueLeft = $paddingArr[1]; + } elseif ($countParams == 3) { + $valueTop = $paddingArr[0]; + $valueRight = $valueLeft = $paddingArr[1]; + $valueBottom = $paddingArr[2]; + } elseif ($countParams == 4) { + $valueTop = $paddingArr[0]; + $valueRight = $paddingArr[1]; + $valueBottom = $paddingArr[2]; + $valueLeft = $paddingArr[3]; + } + if ($valueTop !== null) { + $styles['paddingTop'] = Converter::cssToTwip($valueTop); + } + if ($valueRight !== null) { + $styles['paddingRight'] = Converter::cssToTwip($valueRight); + } + if ($valueBottom !== null) { + $styles['paddingBottom'] = Converter::cssToTwip($valueBottom); + } + 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': self::mapBorderColor($styles, $value); diff --git a/src/PhpWord/Style/Cell.php b/src/PhpWord/Style/Cell.php index 0888d52083..d404c4cf3a 100644 --- a/src/PhpWord/Style/Cell.php +++ b/src/PhpWord/Style/Cell.php @@ -73,6 +73,26 @@ class Cell extends Border */ private $vAlign; + /** + * @var null|int + */ + private $paddingTop; + + /** + * @var null|int + */ + private $paddingBottom; + + /** + * @var null|int + */ + private $paddingLeft; + + /** + * @var null|int + */ + private $paddingRight; + /** * Text Direction. * @@ -356,4 +376,86 @@ 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 + { + $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 + { + $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 + { + $this->paddingLeft = $value; + + return $this; + } + + /** + * Get style padding-right. + * @return mixed + */ + public function getPaddingRight() + { + return $this->paddingRight; + } + + /** + * Set style padding-right. + * @param int $value + * + * @return $this + */ + public function setPaddingRight(int $value): Cell + { + $this->paddingRight = $value; + + return $this; + } } diff --git a/src/PhpWord/Writer/Word2007/Style/Cell.php b/src/PhpWord/Writer/Word2007/Style/Cell.php index 6e22597dd3..43611cc6e6 100644 --- a/src/PhpWord/Writer/Word2007/Style/Cell.php +++ b/src/PhpWord/Writer/Word2007/Style/Cell.php @@ -54,6 +54,40 @@ public function write(): void $xmlWriter->endElement(); // w:tcW } + $paddingTop = $style->getPaddingTop(); + $paddingLeft = $style->getPaddingLeft(); + $paddingBottom = $style->getPaddingBottom(); + $paddingRight = $style->getPaddingRight(); + + if($paddingTop !== null || $paddingLeft !== null || $paddingBottom !== null || $paddingRight !== null){ + $xmlWriter->startElement('w:tcMar'); + 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) { + $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) { + $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){ + $xmlWriter->startElement('w:end'); + $xmlWriter->writeAttribute('w:w', $paddingRight); + $xmlWriter->writeAttribute('w:type', \PhpOffice\PhpWord\SimpleType\TblWidth::TWIP); + $xmlWriter->endElement(); // w:end + } + $xmlWriter->endElement(); // w:tcMar + } + // Text direction $textDir = $style->getTextDirection(); $xmlWriter->writeElementIf(null !== $textDir, 'w:textDirection', 'w:val', $textDir); From ab9e012974e532e0090abe927d0dcd1b64f3407d Mon Sep 17 00:00:00 2001 From: OlisaevAG Date: Tue, 19 Nov 2024 17:23:41 +0300 Subject: [PATCH 02/14] 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); From c02637dc6532f5e34b8f47c81b093a0436451959 Mon Sep 17 00:00:00 2001 From: OlisaevAG Date: Tue, 19 Nov 2024 17:42:58 +0300 Subject: [PATCH 03/14] feat: Support for padding in a table cell. Addition for changelog --- docs/changes/1.x/1.4.0.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/changes/1.x/1.4.0.md b/docs/changes/1.x/1.4.0.md index 8db845337d..bd1704c8be 100644 --- a/docs/changes/1.x/1.4.0.md +++ b/docs/changes/1.x/1.4.0.md @@ -6,6 +6,7 @@ - Writer ODText: Support for ListItemRun by [@Progi1984](https://github.com/Progi1984) fixing [#2159](https://github.com/PHPOffice/PHPWord/issues/2159), [#2620](https://github.com/PHPOffice/PHPWord/issues/2620) in [#2669](https://github.com/PHPOffice/PHPWord/pull/2669) - Writer HTML: Support for vAlign in Tables by [@SpraxDev](https://github.com/SpraxDev) in [#2675](https://github.com/PHPOffice/PHPWord/pull/2675) +- Writer Word2007: Support for padding in Table Cell by [@Azamat8405](https://github.com/Azamat8405) in [#2697](https://github.com/PHPOffice/PHPWord/pull/2697) ### Bug fixes From 4e24657a2c956add83b99832c8320770b1f97419 Mon Sep 17 00:00:00 2001 From: OlisaevAG Date: Tue, 19 Nov 2024 18:49:22 +0300 Subject: [PATCH 04/14] feat: Support for padding in a table cell. Test file --- .../Writer/Word2007/Style/TableCellTest.php | 88 +++++++++++++++++++ 1 file changed, 88 insertions(+) create mode 100644 tests/PhpWordTests/Writer/Word2007/Style/TableCellTest.php diff --git a/tests/PhpWordTests/Writer/Word2007/Style/TableCellTest.php b/tests/PhpWordTests/Writer/Word2007/Style/TableCellTest.php new file mode 100644 index 0000000000..b58ffa4b42 --- /dev/null +++ b/tests/PhpWordTests/Writer/Word2007/Style/TableCellTest.php @@ -0,0 +1,88 @@ +addSection(); + $table = $section->addTable(); + $table->addRow(); + + $testValTop = Converter::pixelToTwip(10); + $testValRight = Converter::pixelToTwip(11); + $testValBottom = Converter::pixelToTwip(12); + $testValLeft = Converter::pixelToTwip(13); + + $cellStyle = [ + 'paddingTop' => $testValTop, + 'paddingRight' => $testValRight, + 'paddingBottom' => $testValBottom, + 'paddingLeft' => $testValLeft + ]; + $table->addCell(null, $cellStyle)->addText('Some text'); + $doc = TestHelperDOCX::getDocument($phpWord, 'Word2007'); + + $path = '/w:document/w:body/w:tbl/w:tr/w:tc/w:tcPr/w:tcMar/w:top'; + self::assertTrue($doc->elementExists($path)); + self::assertEquals($testValTop, $doc->getElementAttribute($path, 'w:w')); + self::assertEquals(TblWidth::TWIP, $doc->getElementAttribute($path, 'w:type')); + + $path = '/w:document/w:body/w:tbl/w:tr/w:tc/w:tcPr/w:tcMar/w:start'; + self::assertTrue($doc->elementExists($path)); + self::assertEquals($testValLeft, $doc->getElementAttribute($path, 'w:w')); + self::assertEquals(TblWidth::TWIP, $doc->getElementAttribute($path, 'w:type')); + + $path = '/w:document/w:body/w:tbl/w:tr/w:tc/w:tcPr/w:tcMar/w:bottom'; + self::assertTrue($doc->elementExists($path)); + self::assertEquals($testValBottom, $doc->getElementAttribute($path, 'w:w')); + self::assertEquals(TblWidth::TWIP, $doc->getElementAttribute($path, 'w:type')); + + $path = '/w:document/w:body/w:tbl/w:tr/w:tc/w:tcPr/w:tcMar/w:end'; + self::assertTrue($doc->elementExists($path)); + self::assertEquals($testValRight, $doc->getElementAttribute($path, 'w:w')); + self::assertEquals(TblWidth::TWIP, $doc->getElementAttribute($path, 'w:type')); + } +} From 29e979a1cf520c3510d1c2fbbe6f81b207c0848e Mon Sep 17 00:00:00 2001 From: OlisaevAG Date: Tue, 19 Nov 2024 18:56:11 +0300 Subject: [PATCH 05/14] feat: Support for padding in a table cell. Test file fix code style --- tests/PhpWordTests/Writer/Word2007/Style/TableCellTest.php | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/tests/PhpWordTests/Writer/Word2007/Style/TableCellTest.php b/tests/PhpWordTests/Writer/Word2007/Style/TableCellTest.php index b58ffa4b42..02bf02aa80 100644 --- a/tests/PhpWordTests/Writer/Word2007/Style/TableCellTest.php +++ b/tests/PhpWordTests/Writer/Word2007/Style/TableCellTest.php @@ -17,11 +17,8 @@ namespace PhpOffice\PhpWordTests\Writer\Word2007\Style; -use PhpOffice\PhpWord\ComplexType\TblWidth as TblWidthComplexType; use PhpOffice\PhpWord\Shared\Converter; use PhpOffice\PhpWord\SimpleType\TblWidth; -use PhpOffice\PhpWord\Style\Table; -use PhpOffice\PhpWord\Style\TablePosition; use PhpOffice\PhpWordTests\TestHelperDOCX; /** @@ -60,7 +57,7 @@ public function testCellSpacing(): void 'paddingTop' => $testValTop, 'paddingRight' => $testValRight, 'paddingBottom' => $testValBottom, - 'paddingLeft' => $testValLeft + 'paddingLeft' => $testValLeft, ]; $table->addCell(null, $cellStyle)->addText('Some text'); $doc = TestHelperDOCX::getDocument($phpWord, 'Word2007'); From 11056c26836fd1216e8a65d456fc1ca2911be6f0 Mon Sep 17 00:00:00 2001 From: OlisaevAG Date: Wed, 20 Nov 2024 11:39:41 +0300 Subject: [PATCH 06/14] feat: Support for padding in a table cell. More test file --- tests/PhpWordTests/Shared/HtmlTest.php | 62 +++++++++++++++++++ .../Writer/Word2007/Style/TableCellTest.php | 2 +- 2 files changed, 63 insertions(+), 1 deletion(-) diff --git a/tests/PhpWordTests/Shared/HtmlTest.php b/tests/PhpWordTests/Shared/HtmlTest.php index 2d39701cd1..8d52960dbc 100644 --- a/tests/PhpWordTests/Shared/HtmlTest.php +++ b/tests/PhpWordTests/Shared/HtmlTest.php @@ -21,9 +21,11 @@ use PhpOffice\PhpWord\Element\Section; use PhpOffice\PhpWord\Element\Table; use PhpOffice\PhpWord\PhpWord; +use PhpOffice\PhpWord\Shared\Converter; use PhpOffice\PhpWord\Shared\Html; use PhpOffice\PhpWord\SimpleType\Jc; use PhpOffice\PhpWord\SimpleType\LineSpacingRule; +use PhpOffice\PhpWord\SimpleType\TblWidth; use PhpOffice\PhpWord\Style\Paragraph; use PhpOffice\PhpWordTests\AbstractWebServerEmbeddedTest; use PhpOffice\PhpWordTests\TestHelperDOCX; @@ -249,6 +251,66 @@ public function testParseLineHeight(): void self::assertEquals(LineSpacingRule::AUTO, $doc->getElementAttribute('/w:document/w:body/w:p[5]/w:pPr/w:spacing', 'w:lineRule')); } + public function testParseCellPaddingStyle(): void + { + $phpWord = new PhpWord(); + $section = $phpWord->addSection(); + + $top = 10; + $right = 11; + $bottom = 12; + $left = 13; + + $testValTop = Converter::pixelToTwip($top); + $testValRight = Converter::pixelToTwip($right); + $testValBottom = Converter::pixelToTwip($bottom); + $testValLeft = Converter::pixelToTwip($left); + + $html = ' + + + + + + + + + +
fullmixtopbottomleft
'; + Html::addHtml($section, $html); + + $doc = TestHelperDOCX::getDocument($phpWord, 'Word2007'); + + $path = '/w:document/w:body/w:tbl/w:tr/w:tc[1]/w:tcPr/w:tcMar/w:top'; + self::assertTrue($doc->elementExists($path)); + $path = '/w:document/w:body/w:tbl/w:tr/w:tc[1]/w:tcPr/w:tcMar/w:bottom'; + self::assertTrue($doc->elementExists($path)); + $path = '/w:document/w:body/w:tbl/w:tr/w:tc[1]/w:tcPr/w:tcMar/w:end'; + self::assertTrue($doc->elementExists($path)); + $path = '/w:document/w:body/w:tbl/w:tr/w:tc[1]/w:tcPr/w:tcMar/w:start'; + self::assertTrue($doc->elementExists($path)); + + $path = '/w:document/w:body/w:tbl/w:tr/w:tc[2]/w:tcPr/w:tcMar/w:end'; + self::assertTrue($doc->elementExists($path)); + self::assertEquals($testValRight, $doc->getElementAttribute($path, 'w:w')); + self::assertEquals(TblWidth::TWIP, $doc->getElementAttribute($path, 'w:type')); + + $path = '/w:document/w:body/w:tbl/w:tr/w:tc[3]/w:tcPr/w:tcMar/w:top'; + self::assertTrue($doc->elementExists($path)); + self::assertEquals($testValTop, $doc->getElementAttribute($path, 'w:w')); + self::assertEquals(TblWidth::TWIP, $doc->getElementAttribute($path, 'w:type')); + + $path = '/w:document/w:body/w:tbl/w:tr/w:tc[4]/w:tcPr/w:tcMar/w:bottom'; + self::assertTrue($doc->elementExists($path)); + self::assertEquals($testValBottom, $doc->getElementAttribute($path, 'w:w')); + self::assertEquals(TblWidth::TWIP, $doc->getElementAttribute($path, 'w:type')); + + $path = '/w:document/w:body/w:tbl/w:tr/w:tc[5]/w:tcPr/w:tcMar/w:start'; + self::assertTrue($doc->elementExists($path)); + self::assertEquals($testValLeft, $doc->getElementAttribute($path, 'w:w')); + self::assertEquals(TblWidth::TWIP, $doc->getElementAttribute($path, 'w:type')); + } + /** * Test text-indent style. */ diff --git a/tests/PhpWordTests/Writer/Word2007/Style/TableCellTest.php b/tests/PhpWordTests/Writer/Word2007/Style/TableCellTest.php index 02bf02aa80..f53a2c9895 100644 --- a/tests/PhpWordTests/Writer/Word2007/Style/TableCellTest.php +++ b/tests/PhpWordTests/Writer/Word2007/Style/TableCellTest.php @@ -41,7 +41,7 @@ protected function tearDown(): void /** * Test write styles. */ - public function testCellSpacing(): void + public function testCellPadding(): void { $phpWord = new \PhpOffice\PhpWord\PhpWord(); $section = $phpWord->addSection(); From 01ca7384be7fb365d1afb7c14ae5c02e20059f1f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=90=D0=B7=D0=B0=D0=BC=D0=B0=D1=828405?= Date: Thu, 21 Nov 2024 12:44:04 +0300 Subject: [PATCH 07/14] Update composer.json azamat8405/phpword --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 9633fe01da..f6fa7918d9 100644 --- a/composer.json +++ b/composer.json @@ -1,5 +1,5 @@ { - "name": "phpoffice/phpword", + "name": "azamat8405/phpword", "description": "PHPWord - A pure PHP library for reading and writing word processing documents (OOXML, ODF, RTF, HTML, PDF)", "keywords": [ "PHP", "PHPOffice", "office", "PHPWord", "word", "template", "template processor", "reader", "writer", From 5beb34ea44f18acb55cd4626a62ccbc93ffecde0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=90=D0=B7=D0=B0=D0=BC=D0=B0=D1=828405?= Date: Thu, 21 Nov 2024 14:33:48 +0300 Subject: [PATCH 08/14] Update composer.json azamat8405/phpword --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 9633fe01da..f6fa7918d9 100644 --- a/composer.json +++ b/composer.json @@ -1,5 +1,5 @@ { - "name": "phpoffice/phpword", + "name": "azamat8405/phpword", "description": "PHPWord - A pure PHP library for reading and writing word processing documents (OOXML, ODF, RTF, HTML, PDF)", "keywords": [ "PHP", "PHPOffice", "office", "PHPWord", "word", "template", "template processor", "reader", "writer", From 1d1de82c63eb2a71f37aa4ec2b3ebf4cc48ee8d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=90=D0=B7=D0=B0=D0=BC=D0=B0=D1=828405?= Date: Thu, 21 Nov 2024 19:05:56 +0300 Subject: [PATCH 09/14] Update composer.json fix renaming --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index f6fa7918d9..9633fe01da 100644 --- a/composer.json +++ b/composer.json @@ -1,5 +1,5 @@ { - "name": "azamat8405/phpword", + "name": "phpoffice/phpword", "description": "PHPWord - A pure PHP library for reading and writing word processing documents (OOXML, ODF, RTF, HTML, PDF)", "keywords": [ "PHP", "PHPOffice", "office", "PHPWord", "word", "template", "template processor", "reader", "writer", From 3cce02e70ae47af041aabf0a3d0d881af5e52fcd Mon Sep 17 00:00:00 2001 From: OlisaevAG Date: Tue, 21 Jan 2025 11:59:15 +0300 Subject: [PATCH 10/14] =?UTF-8?q?feat:=20=D0=A1hanges=20for=20the=20code?= =?UTF-8?q?=20review?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/PhpWord/Shared/Html.php | 17 ++++++++--------- src/PhpWord/Style/Cell.php | 8 ++++---- 2 files changed, 12 insertions(+), 13 deletions(-) diff --git a/src/PhpWord/Shared/Html.php b/src/PhpWord/Shared/Html.php index 9893ca9dab..961a36c0c1 100644 --- a/src/PhpWord/Shared/Html.php +++ b/src/PhpWord/Shared/Html.php @@ -825,34 +825,33 @@ protected static function parseStyleDeclarations(array $selectors, array $styles $valueLeft = $paddingArr[3]; } if ($valueTop !== null) { - $styles['paddingTop'] = Converter::cssToTwip($valueTop); + $styles['paddingTop'] = Converter::cssToTwip(self::convertHtmlSize($valueTop)); } if ($valueRight !== null) { - $styles['paddingRight'] = Converter::cssToTwip($valueRight); + $styles['paddingRight'] = Converter::cssToTwip(self::convertHtmlSize($valueRight)); } if ($valueBottom !== null) { - $styles['paddingBottom'] = Converter::cssToTwip($valueBottom); + $styles['paddingBottom'] = Converter::cssToTwip(self::convertHtmlSize($valueBottom)); } if ($valueLeft !== null) { - $styles['paddingLeft'] = Converter::cssToTwip($valueLeft); + $styles['paddingLeft'] = Converter::cssToTwip(self::convertHtmlSize($valueLeft)); } break; case 'padding-top': - $styles['paddingTop'] = Converter::cssToTwip($value); + $styles['paddingTop'] = Converter::cssToTwip(self::convertHtmlSize($value)); break; case 'padding-right': - $styles['paddingRight'] = Converter::cssToTwip($value); + $styles['paddingRight'] = Converter::cssToTwip(self::convertHtmlSize($value)); break; case 'padding-bottom': - $styles['paddingBottom'] = Converter::cssToTwip($value); + $styles['paddingBottom'] = Converter::cssToTwip(self::convertHtmlSize($value)); break; case 'padding-left': - $styles['paddingLeft'] = Converter::cssToTwip($value); - + $styles['paddingLeft'] = Converter::cssToTwip(self::convertHtmlSize($value)); break; case 'border-color': diff --git a/src/PhpWord/Style/Cell.php b/src/PhpWord/Style/Cell.php index 7fb863349f..87acfcb0f1 100644 --- a/src/PhpWord/Style/Cell.php +++ b/src/PhpWord/Style/Cell.php @@ -382,7 +382,7 @@ public function getNoWrap(): bool * * @return mixed */ - public function getPaddingTop() + public function getPaddingTop(): ?int { return $this->paddingTop; } @@ -404,7 +404,7 @@ public function setPaddingTop(int $value): self * * @return mixed */ - public function getPaddingBottom() + public function getPaddingBottom(): ?int { return $this->paddingBottom; } @@ -426,7 +426,7 @@ public function setPaddingBottom(int $value): self * * @return mixed */ - public function getPaddingLeft() + public function getPaddingLeft(): ?int { return $this->paddingLeft; } @@ -448,7 +448,7 @@ public function setPaddingLeft(int $value): self * * @return mixed */ - public function getPaddingRight() + public function getPaddingRight(): ?int { return $this->paddingRight; } From 66d33b3b2658fa0bd9376ebb34908d9b6c8cca54 Mon Sep 17 00:00:00 2001 From: OlisaevAG Date: Tue, 21 Jan 2025 12:13:01 +0300 Subject: [PATCH 11/14] =?UTF-8?q?feat:=20=D0=A1hanges=20for=20the=20code?= =?UTF-8?q?=20review=202?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/PhpWordTests/Style/CellTest.php | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/tests/PhpWordTests/Style/CellTest.php b/tests/PhpWordTests/Style/CellTest.php index d1874d2288..5af055eb69 100644 --- a/tests/PhpWordTests/Style/CellTest.php +++ b/tests/PhpWordTests/Style/CellTest.php @@ -89,4 +89,25 @@ public function testBorderSize(): void $object->setStyleValue('borderSize', $value); self::assertEquals($expected, $object->getBorderSize()); } + /** + * @return void + */ + public function testPadding(): void + { + $object = new Cell(); + $methods = [ + 'paddingTop' => 10, + 'paddingBottom' => 20, + 'paddingLeft' => 30, + 'paddingRight' => 40 + ]; + + foreach($methods as $methodName => $methodValue){ + + $object->setStyleValue($methodName, $methodValue); + $getterName = 'get'.ucfirst($methodName); + + self::assertEquals($methodValue, $object->$getterName()); + } + } } From 68154a3bbc74c08838efaae4d656b60d3c3cd695 Mon Sep 17 00:00:00 2001 From: OlisaevAG Date: Wed, 22 Jan 2025 15:43:47 +0300 Subject: [PATCH 12/14] =?UTF-8?q?feat:=20feat:=20=D0=A1hanges=20for=20the?= =?UTF-8?q?=20code=20review=203?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/PhpWord/Shared/Html.php | 17 +++++++++-------- tests/PhpWordTests/Style/CellTest.php | 7 ++++--- .../Writer/Word2007/Style/TableCellTest.php | 1 + 3 files changed, 14 insertions(+), 11 deletions(-) diff --git a/src/PhpWord/Shared/Html.php b/src/PhpWord/Shared/Html.php index 7a263acb39..d94c13fdf7 100644 --- a/src/PhpWord/Shared/Html.php +++ b/src/PhpWord/Shared/Html.php @@ -826,33 +826,34 @@ protected static function parseStyleDeclarations(array $selectors, array $styles $valueLeft = $paddingArr[3]; } if ($valueTop !== null) { - $styles['paddingTop'] = Converter::cssToTwip(self::convertHtmlSize($valueTop)); + $styles['paddingTop'] = Converter::cssToTwip($valueTop); } if ($valueRight !== null) { - $styles['paddingRight'] = Converter::cssToTwip(self::convertHtmlSize($valueRight)); + $styles['paddingRight'] = Converter::cssToTwip($valueRight); } if ($valueBottom !== null) { - $styles['paddingBottom'] = Converter::cssToTwip(self::convertHtmlSize($valueBottom)); + $styles['paddingBottom'] = Converter::cssToTwip($valueBottom); } if ($valueLeft !== null) { - $styles['paddingLeft'] = Converter::cssToTwip(self::convertHtmlSize($valueLeft)); + $styles['paddingLeft'] = Converter::cssToTwip($valueLeft); } break; case 'padding-top': - $styles['paddingTop'] = Converter::cssToTwip(self::convertHtmlSize($value)); + $styles['paddingTop'] = Converter::cssToTwip($value); break; case 'padding-right': - $styles['paddingRight'] = Converter::cssToTwip(self::convertHtmlSize($value)); + $styles['paddingRight'] = Converter::cssToTwip($value); break; case 'padding-bottom': - $styles['paddingBottom'] = Converter::cssToTwip(self::convertHtmlSize($value)); + $styles['paddingBottom'] = Converter::cssToTwip($value); break; case 'padding-left': - $styles['paddingLeft'] = Converter::cssToTwip(self::convertHtmlSize($value)); + $styles['paddingLeft'] = Converter::cssToTwip($value); + break; case 'border-color': diff --git a/tests/PhpWordTests/Style/CellTest.php b/tests/PhpWordTests/Style/CellTest.php index a6efd95afe..686a5b8402 100644 --- a/tests/PhpWordTests/Style/CellTest.php +++ b/tests/PhpWordTests/Style/CellTest.php @@ -93,6 +93,7 @@ public function testBorderSize(): void /** * @return void */ + public function testPadding(): void { $object = new Cell(); @@ -100,13 +101,13 @@ public function testPadding(): void 'paddingTop' => 10, 'paddingBottom' => 20, 'paddingLeft' => 30, - 'paddingRight' => 40 + 'paddingRight' => 40, ]; - foreach($methods as $methodName => $methodValue){ + foreach ($methods as $methodName => $methodValue) { $object->setStyleValue($methodName, $methodValue); - $getterName = 'get'.ucfirst($methodName); + $getterName = 'get' . ucfirst($methodName); self::assertEquals($methodValue, $object->$getterName()); } diff --git a/tests/PhpWordTests/Writer/Word2007/Style/TableCellTest.php b/tests/PhpWordTests/Writer/Word2007/Style/TableCellTest.php index f53a2c9895..bd3f587b75 100644 --- a/tests/PhpWordTests/Writer/Word2007/Style/TableCellTest.php +++ b/tests/PhpWordTests/Writer/Word2007/Style/TableCellTest.php @@ -1,4 +1,5 @@ Date: Wed, 22 Jan 2025 16:14:13 +0300 Subject: [PATCH 13/14] =?UTF-8?q?feat:=20feat:=20=D0=A1hanges=20for=20the?= =?UTF-8?q?=20code=20review=204?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- composer.json | 2 +- src/PhpWord/Style/Cell.php | 9 ++++----- tests/PhpWordTests/Style/CellTest.php | 5 ++--- 3 files changed, 7 insertions(+), 9 deletions(-) diff --git a/composer.json b/composer.json index 56cc5552e3..efebe941e7 100644 --- a/composer.json +++ b/composer.json @@ -1,5 +1,5 @@ { - "name": "azamat8405/phpword", + "name": "phpoffice/phpword", "description": "PHPWord - A pure PHP library for reading and writing word processing documents (OOXML, ODF, RTF, HTML, PDF)", "keywords": [ "PHP", "PHPOffice", "office", "PHPWord", "word", "template", "template processor", "reader", "writer", diff --git a/src/PhpWord/Style/Cell.php b/src/PhpWord/Style/Cell.php index 680f33f85b..dcc95e572e 100644 --- a/src/PhpWord/Style/Cell.php +++ b/src/PhpWord/Style/Cell.php @@ -377,11 +377,10 @@ public function getNoWrap(): bool { return $this->noWrap; } - /** * Get style padding-top. * - * @return mixed + * @return int|null */ public function getPaddingTop(): ?int { @@ -403,7 +402,7 @@ public function setPaddingTop(int $value): self /** * Get style padding-bottom. * - * @return mixed + * @return int|null */ public function getPaddingBottom(): ?int { @@ -425,7 +424,7 @@ public function setPaddingBottom(int $value): self /** * Get style padding-left. * - * @return mixed + * @return int|null */ public function getPaddingLeft(): ?int { @@ -447,7 +446,7 @@ public function setPaddingLeft(int $value): self /** * Get style padding-right. * - * @return mixed + * @return int|null */ public function getPaddingRight(): ?int { diff --git a/tests/PhpWordTests/Style/CellTest.php b/tests/PhpWordTests/Style/CellTest.php index 686a5b8402..9015d0feea 100644 --- a/tests/PhpWordTests/Style/CellTest.php +++ b/tests/PhpWordTests/Style/CellTest.php @@ -90,10 +90,10 @@ public function testBorderSize(): void $object->setStyleValue('borderSize', $value); self::assertEquals($expected, $object->getBorderSize()); } + /** - * @return void + * Test cell padding. */ - public function testPadding(): void { $object = new Cell(); @@ -105,7 +105,6 @@ public function testPadding(): void ]; foreach ($methods as $methodName => $methodValue) { - $object->setStyleValue($methodName, $methodValue); $getterName = 'get' . ucfirst($methodName); From 9f75457b349b19c25748f3b198bc963aee5bb627 Mon Sep 17 00:00:00 2001 From: OlisaevAG Date: Wed, 22 Jan 2025 16:18:44 +0300 Subject: [PATCH 14/14] =?UTF-8?q?feat:=20feat:=20=D0=A1hanges=20for=20the?= =?UTF-8?q?=20code=20review=205?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/PhpWord/Style/Cell.php | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/src/PhpWord/Style/Cell.php b/src/PhpWord/Style/Cell.php index dcc95e572e..e2b59f417d 100644 --- a/src/PhpWord/Style/Cell.php +++ b/src/PhpWord/Style/Cell.php @@ -377,10 +377,9 @@ public function getNoWrap(): bool { return $this->noWrap; } + /** * Get style padding-top. - * - * @return int|null */ public function getPaddingTop(): ?int { @@ -401,8 +400,6 @@ public function setPaddingTop(int $value): self /** * Get style padding-bottom. - * - * @return int|null */ public function getPaddingBottom(): ?int { @@ -423,8 +420,6 @@ public function setPaddingBottom(int $value): self /** * Get style padding-left. - * - * @return int|null */ public function getPaddingLeft(): ?int { @@ -445,8 +440,6 @@ public function setPaddingLeft(int $value): self /** * Get style padding-right. - * - * @return int|null */ public function getPaddingRight(): ?int {