Skip to content

Commit ab9e012

Browse files
OlisaevAGOlisaevAG
OlisaevAG
authored and
OlisaevAG
committed
Support for padding in a table cell. fix code style
1 parent 3e182f0 commit ab9e012

File tree

3 files changed

+34
-23
lines changed

3 files changed

+34
-23
lines changed

src/PhpWord/Shared/Html.php

+14-9
Original file line numberDiff line numberDiff line change
@@ -805,24 +805,24 @@ protected static function parseStyleDeclarations(array $selectors, array $styles
805805
break;
806806

807807
case 'padding':
808-
$valueTop = $valueRight = $valueBottom = $valueLeft = null;
809-
$cValue = preg_replace('# +#', ' ', trim($value));
810-
$paddingArr = explode(' ', $cValue);
808+
$valueTop = $valueRight = $valueBottom = $valueLeft = null;
809+
$cValue = preg_replace('# +#', ' ', trim($value));
810+
$paddingArr = explode(' ', $cValue);
811811
$countParams = count($paddingArr);
812812
if ($countParams == 1) {
813813
$valueTop = $valueRight = $valueBottom = $valueLeft = $paddingArr[0];
814814
} elseif ($countParams == 2) {
815-
$valueTop = $valueBottom = $paddingArr[0];
815+
$valueTop = $valueBottom = $paddingArr[0];
816816
$valueRight = $valueLeft = $paddingArr[1];
817817
} elseif ($countParams == 3) {
818-
$valueTop = $paddingArr[0];
819-
$valueRight = $valueLeft = $paddingArr[1];
818+
$valueTop = $paddingArr[0];
819+
$valueRight = $valueLeft = $paddingArr[1];
820820
$valueBottom = $paddingArr[2];
821821
} elseif ($countParams == 4) {
822-
$valueTop = $paddingArr[0];
823-
$valueRight = $paddingArr[1];
822+
$valueTop = $paddingArr[0];
823+
$valueRight = $paddingArr[1];
824824
$valueBottom = $paddingArr[2];
825-
$valueLeft = $paddingArr[3];
825+
$valueLeft = $paddingArr[3];
826826
}
827827
if ($valueTop !== null) {
828828
$styles['paddingTop'] = Converter::cssToTwip($valueTop);
@@ -836,18 +836,23 @@ protected static function parseStyleDeclarations(array $selectors, array $styles
836836
if ($valueLeft !== null) {
837837
$styles['paddingLeft'] = Converter::cssToTwip($valueLeft);
838838
}
839+
839840
break;
840841
case 'padding-top':
841842
$styles['paddingTop'] = Converter::cssToTwip($value);
843+
842844
break;
843845
case 'padding-right':
844846
$styles['paddingRight'] = Converter::cssToTwip($value);
847+
845848
break;
846849
case 'padding-bottom':
847850
$styles['paddingBottom'] = Converter::cssToTwip($value);
851+
848852
break;
849853
case 'padding-left':
850854
$styles['paddingLeft'] = Converter::cssToTwip($value);
855+
851856
break;
852857

853858
case 'border-color':

src/PhpWord/Style/Cell.php

+15-9
Original file line numberDiff line numberDiff line change
@@ -377,60 +377,66 @@ public function getNoWrap(): bool
377377
return $this->noWrap;
378378
}
379379

380-
381380
/**
382381
* Get style padding-top.
382+
*
383383
* @return mixed
384384
*/
385385
public function getPaddingTop()
386386
{
387387
return $this->paddingTop;
388388
}
389+
389390
/**
390391
* Set style padding-top.
391-
* @param int $value
392392
*
393393
* @return $this
394394
*/
395-
public function setPaddingTop(int $value): Cell
395+
public function setPaddingTop(int $value): self
396396
{
397397
$this->paddingTop = $value;
398+
398399
return $this;
399400
}
401+
400402
/**
401403
* Get style padding-bottom.
404+
*
402405
* @return mixed
403406
*/
404407
public function getPaddingBottom()
405408
{
406409
return $this->paddingBottom;
407410
}
411+
408412
/**
409413
* Set style padding-bottom.
410-
* @param int $value
411414
*
412415
* @return $this
413416
*/
414-
public function setPaddingBottom(int $value): Cell
417+
public function setPaddingBottom(int $value): self
415418
{
416419
$this->paddingBottom = $value;
420+
417421
return $this;
418422
}
423+
419424
/**
420425
* Get style padding-left.
426+
*
421427
* @return mixed
422428
*/
423429
public function getPaddingLeft()
424430
{
425431
return $this->paddingLeft;
426432
}
433+
427434
/**
428435
* Set style padding-left.
429-
* @param int $value
430436
*
431437
* @return $this
432438
*/
433-
public function setPaddingLeft(int $value): Cell
439+
public function setPaddingLeft(int $value): self
434440
{
435441
$this->paddingLeft = $value;
436442

@@ -439,6 +445,7 @@ public function setPaddingLeft(int $value): Cell
439445

440446
/**
441447
* Get style padding-right.
448+
*
442449
* @return mixed
443450
*/
444451
public function getPaddingRight()
@@ -448,11 +455,10 @@ public function getPaddingRight()
448455

449456
/**
450457
* Set style padding-right.
451-
* @param int $value
452458
*
453459
* @return $this
454460
*/
455-
public function setPaddingRight(int $value): Cell
461+
public function setPaddingRight(int $value): self
456462
{
457463
$this->paddingRight = $value;
458464

src/PhpWord/Writer/Word2007/Style/Cell.php

+5-5
Original file line numberDiff line numberDiff line change
@@ -59,27 +59,27 @@ public function write(): void
5959
$paddingBottom = $style->getPaddingBottom();
6060
$paddingRight = $style->getPaddingRight();
6161

62-
if($paddingTop !== null || $paddingLeft !== null || $paddingBottom !== null || $paddingRight !== null){
62+
if ($paddingTop !== null || $paddingLeft !== null || $paddingBottom !== null || $paddingRight !== null) {
6363
$xmlWriter->startElement('w:tcMar');
64-
if($paddingTop !== null) {
64+
if ($paddingTop !== null) {
6565
$xmlWriter->startElement('w:top');
6666
$xmlWriter->writeAttribute('w:w', $paddingTop);
6767
$xmlWriter->writeAttribute('w:type', \PhpOffice\PhpWord\SimpleType\TblWidth::TWIP);
6868
$xmlWriter->endElement(); // w:top
6969
}
70-
if($paddingLeft !== null) {
70+
if ($paddingLeft !== null) {
7171
$xmlWriter->startElement('w:start');
7272
$xmlWriter->writeAttribute('w:w', $paddingLeft);
7373
$xmlWriter->writeAttribute('w:type', \PhpOffice\PhpWord\SimpleType\TblWidth::TWIP);
7474
$xmlWriter->endElement(); // w:start
7575
}
76-
if($paddingBottom !== null) {
76+
if ($paddingBottom !== null) {
7777
$xmlWriter->startElement('w:bottom');
7878
$xmlWriter->writeAttribute('w:w', $paddingBottom);
7979
$xmlWriter->writeAttribute('w:type', \PhpOffice\PhpWord\SimpleType\TblWidth::TWIP);
8080
$xmlWriter->endElement(); // w:bottom
8181
}
82-
if($paddingRight !== null){
82+
if ($paddingRight !== null) {
8383
$xmlWriter->startElement('w:end');
8484
$xmlWriter->writeAttribute('w:w', $paddingRight);
8585
$xmlWriter->writeAttribute('w:type', \PhpOffice\PhpWord\SimpleType\TblWidth::TWIP);

0 commit comments

Comments
 (0)