Skip to content

Commit 93daccb

Browse files
authored
Merge branch 'master' into wordunimplemented2
2 parents d1a16fe + 10ae499 commit 93daccb

File tree

14 files changed

+665
-76
lines changed

14 files changed

+665
-76
lines changed

docs/changes/1.x/1.4.0.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
- 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)
1010
- Writer HTML: Support for vAlign in Tables by [@SpraxDev](https://github.com/SpraxDev) in [#2675](https://github.com/PHPOffice/PHPWord/pull/2675)
11+
- Writer Word2007: Support for padding in Table Cell by [@Azamat8405](https://github.com/Azamat8405) in [#2697](https://github.com/PHPOffice/PHPWord/pull/2697)
1112
- Added support for PHP 8.4 by [@Progi1984](https://github.com/Progi1984) in [#2660](https://github.com/PHPOffice/PHPWord/pull/2660)
1213
- Autoload : Allow to use PHPWord without Composer fixing [#2543](https://github.com/PHPOffice/PHPWord/issues/2543), [#2552](https://github.com/PHPOffice/PHPWord/issues/2552), [#2716](https://github.com/PHPOffice/PHPWord/issues/2716), [#2717](https://github.com/PHPOffice/PHPWord/issues/2717) in [#2722](https://github.com/PHPOffice/PHPWord/pull/2722)
1314

@@ -16,10 +17,17 @@
1617
- Writer ODText: Support for images inside a textRun by [@Progi1984](https://github.com/Progi1984) fixing [#2240](https://github.com/PHPOffice/PHPWord/issues/2240) in [#2668](https://github.com/PHPOffice/PHPWord/pull/2668)
1718
- Allow vAlign and vMerge on Style\Cell to be set to null by [@SpraxDev](https://github.com/SpraxDev) fixing [#2673](https://github.com/PHPOffice/PHPWord/issues/2673) in [#2676](https://github.com/PHPOffice/PHPWord/pull/2676)
1819
- Reader HTML: Support for differents size units for table by [@Progi1984](https://github.com/Progi1984) fixing [#2384](https://github.com/PHPOffice/PHPWord/issues/2384), [#2701](https://github.com/PHPOffice/PHPWord/issues/2701) in [#2725](https://github.com/PHPOffice/PHPWord/pull/2725)
20+
- Reader Word2007 : Respect paragraph indent units by [@tugmaks](https://github.com/tugmaks) & [@Progi1984](https://github.com/Progi1984) fixing [#507](https://github.com/PHPOffice/PHPWord/issues/507) in [#2726](https://github.com/PHPOffice/PHPWord/pull/2726)
21+
- Reader Word2007 : Support Header elements within Title elements by [@SpraxDev](https://github.com/SpraxDev) fixing [#2616](https://github.com/PHPOffice/PHPWord/issues/2616), [#2426](https://github.com/PHPOffice/PHPWord/issues/2426) in [#2674](https://github.com/PHPOffice/PHPWord/pull/2674)
1922

2023
### Miscellaneous
2124

2225
- Bump dompdf/dompdf from 2.0.4 to 3.0.0 by [@dependabot](https://github.com/dependabot) fixing [#2621](https://github.com/PHPOffice/PHPWord/issues/2621) in [#2666](https://github.com/PHPOffice/PHPWord/pull/2666)
2326
- Add test case to make sure vMerge defaults to 'continue' by [@SpraxDev](https://github.com/SpraxDev) in [#2677](https://github.com/PHPOffice/PHPWord/pull/2677)
2427

28+
### Deprecations
29+
- Deprecate `PhpOffice\PhpWord\Style\Paragraph::getIndent()` : Use `PhpOffice\PhpWord\Style\Paragraph::getIndentLeft()`
30+
- Deprecate `PhpOffice\PhpWord\Style\Paragraph::setHanging()` : Use `PhpOffice\PhpWord\Style\Paragraph::setIndentHanging()`
31+
- Deprecate `PhpOffice\PhpWord\Style\Paragraph::setIndent()` : Use `PhpOffice\PhpWord\Style\Paragraph::setIndentLeft()`
32+
2533
### BC Breaks

src/PhpWord/Element/AbstractContainer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ private function checkValidity($method)
254254
'Footnote' => ['Section', 'TextRun', 'Cell', 'ListItemRun'],
255255
'Endnote' => ['Section', 'TextRun', 'Cell'],
256256
'PreserveText' => ['Section', 'Header', 'Footer', 'Cell'],
257-
'Title' => ['Section', 'Cell'],
257+
'Title' => ['Section', 'Cell', 'Header'],
258258
'TOC' => ['Section'],
259259
'PageBreak' => ['Section'],
260260
'Chart' => ['Section', 'Cell'],

src/PhpWord/Reader/Word2007/AbstractPart.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -662,8 +662,10 @@ protected function readParagraphStyle(XMLReader $xmlReader, DOMElement $domNode)
662662
'alignment' => [self::READ_VALUE, 'w:jc'],
663663
'basedOn' => [self::READ_VALUE, 'w:basedOn'],
664664
'next' => [self::READ_VALUE, 'w:next'],
665-
'indent' => [self::READ_VALUE, 'w:ind', 'w:left'],
666-
'hanging' => [self::READ_VALUE, 'w:ind', 'w:hanging'],
665+
'indentLeft' => [self::READ_VALUE, 'w:ind', 'w:left'],
666+
'indentRight' => [self::READ_VALUE, 'w:ind', 'w:right'],
667+
'indentHanging' => [self::READ_VALUE, 'w:ind', 'w:hanging'],
668+
'indentFirstLine' => [self::READ_VALUE, 'w:ind', 'w:firstLine'],
667669
'spaceAfter' => [self::READ_VALUE, 'w:spacing', 'w:after'],
668670
'spaceBefore' => [self::READ_VALUE, 'w:spacing', 'w:before'],
669671
'widowControl' => [self::READ_FALSE, 'w:widowControl'],

src/PhpWord/Shared/Html.php

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -931,6 +931,58 @@ protected static function parseStyleDeclarations(array $selectors, array $styles
931931
$styles['spaceAfter'] = Converter::cssToTwip($value);
932932

933933
break;
934+
935+
case 'padding':
936+
$valueTop = $valueRight = $valueBottom = $valueLeft = null;
937+
$cValue = preg_replace('# +#', ' ', trim($value));
938+
$paddingArr = explode(' ', $cValue);
939+
$countParams = count($paddingArr);
940+
if ($countParams == 1) {
941+
$valueTop = $valueRight = $valueBottom = $valueLeft = $paddingArr[0];
942+
} elseif ($countParams == 2) {
943+
$valueTop = $valueBottom = $paddingArr[0];
944+
$valueRight = $valueLeft = $paddingArr[1];
945+
} elseif ($countParams == 3) {
946+
$valueTop = $paddingArr[0];
947+
$valueRight = $valueLeft = $paddingArr[1];
948+
$valueBottom = $paddingArr[2];
949+
} elseif ($countParams == 4) {
950+
$valueTop = $paddingArr[0];
951+
$valueRight = $paddingArr[1];
952+
$valueBottom = $paddingArr[2];
953+
$valueLeft = $paddingArr[3];
954+
}
955+
if ($valueTop !== null) {
956+
$styles['paddingTop'] = Converter::cssToTwip($valueTop);
957+
}
958+
if ($valueRight !== null) {
959+
$styles['paddingRight'] = Converter::cssToTwip($valueRight);
960+
}
961+
if ($valueBottom !== null) {
962+
$styles['paddingBottom'] = Converter::cssToTwip($valueBottom);
963+
}
964+
if ($valueLeft !== null) {
965+
$styles['paddingLeft'] = Converter::cssToTwip($valueLeft);
966+
}
967+
968+
break;
969+
case 'padding-top':
970+
$styles['paddingTop'] = Converter::cssToTwip($value);
971+
972+
break;
973+
case 'padding-right':
974+
$styles['paddingRight'] = Converter::cssToTwip($value);
975+
976+
break;
977+
case 'padding-bottom':
978+
$styles['paddingBottom'] = Converter::cssToTwip($value);
979+
980+
break;
981+
case 'padding-left':
982+
$styles['paddingLeft'] = Converter::cssToTwip($value);
983+
984+
break;
985+
934986
case 'border-color':
935987
self::mapBorderColor($styles, $value);
936988

src/PhpWord/Style/AbstractStyle.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -332,12 +332,11 @@ protected function setEnumVal($value = null, $enum = [], $default = null)
332332
* Set object value.
333333
*
334334
* @param mixed $value
335-
* @param string $styleName
336335
* @param mixed &$style
337336
*
338337
* @return mixed
339338
*/
340-
protected function setObjectVal($value, $styleName, &$style)
339+
protected function setObjectVal($value, string $styleName, &$style)
341340
{
342341
$styleClass = substr(static::class, 0, (int) strrpos(static::class, '\\')) . '\\' . $styleName;
343342
if (is_array($value)) {

src/PhpWord/Style/Cell.php

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,26 @@ class Cell extends Border
7474
*/
7575
private $vAlign;
7676

77+
/**
78+
* @var null|int
79+
*/
80+
private $paddingTop;
81+
82+
/**
83+
* @var null|int
84+
*/
85+
private $paddingBottom;
86+
87+
/**
88+
* @var null|int
89+
*/
90+
private $paddingLeft;
91+
92+
/**
93+
* @var null|int
94+
*/
95+
private $paddingRight;
96+
7797
/**
7898
* Text Direction.
7999
*
@@ -357,4 +377,84 @@ public function getNoWrap(): bool
357377
{
358378
return $this->noWrap;
359379
}
380+
381+
/**
382+
* Get style padding-top.
383+
*/
384+
public function getPaddingTop(): ?int
385+
{
386+
return $this->paddingTop;
387+
}
388+
389+
/**
390+
* Set style padding-top.
391+
*
392+
* @return $this
393+
*/
394+
public function setPaddingTop(int $value): self
395+
{
396+
$this->paddingTop = $value;
397+
398+
return $this;
399+
}
400+
401+
/**
402+
* Get style padding-bottom.
403+
*/
404+
public function getPaddingBottom(): ?int
405+
{
406+
return $this->paddingBottom;
407+
}
408+
409+
/**
410+
* Set style padding-bottom.
411+
*
412+
* @return $this
413+
*/
414+
public function setPaddingBottom(int $value): self
415+
{
416+
$this->paddingBottom = $value;
417+
418+
return $this;
419+
}
420+
421+
/**
422+
* Get style padding-left.
423+
*/
424+
public function getPaddingLeft(): ?int
425+
{
426+
return $this->paddingLeft;
427+
}
428+
429+
/**
430+
* Set style padding-left.
431+
*
432+
* @return $this
433+
*/
434+
public function setPaddingLeft(int $value): self
435+
{
436+
$this->paddingLeft = $value;
437+
438+
return $this;
439+
}
440+
441+
/**
442+
* Get style padding-right.
443+
*/
444+
public function getPaddingRight(): ?int
445+
{
446+
return $this->paddingRight;
447+
}
448+
449+
/**
450+
* Set style padding-right.
451+
*
452+
* @return $this
453+
*/
454+
public function setPaddingRight(int $value): self
455+
{
456+
$this->paddingRight = $value;
457+
458+
return $this;
459+
}
360460
}

src/PhpWord/Style/Indentation.php

Lines changed: 17 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -29,30 +29,30 @@ class Indentation extends AbstractStyle
2929
/**
3030
* Left indentation (twip).
3131
*
32-
* @var float|int
32+
* @var null|float
3333
*/
3434
private $left = 0;
3535

3636
/**
3737
* Right indentation (twip).
3838
*
39-
* @var float|int
39+
* @var null|float
4040
*/
4141
private $right = 0;
4242

4343
/**
4444
* Additional first line indentation (twip).
4545
*
46-
* @var float|int
46+
* @var null|float
4747
*/
4848
private $firstLine = 0;
4949

5050
/**
5151
* Indentation removed from first line (twip).
5252
*
53-
* @var float|int
53+
* @var null|float
5454
*/
55-
private $hanging;
55+
private $hanging = 0;
5656

5757
/**
5858
* Create a new instance.
@@ -66,96 +66,72 @@ public function __construct($style = [])
6666

6767
/**
6868
* Get left.
69-
*
70-
* @return float|int
7169
*/
72-
public function getLeft()
70+
public function getLeft(): ?float
7371
{
7472
return $this->left;
7573
}
7674

7775
/**
7876
* Set left.
79-
*
80-
* @param float|int $value
81-
*
82-
* @return self
8377
*/
84-
public function setLeft($value)
78+
public function setLeft(?float $value): self
8579
{
86-
$this->left = $this->setNumericVal($value, $this->left);
80+
$this->left = $this->setNumericVal($value);
8781

8882
return $this;
8983
}
9084

9185
/**
9286
* Get right.
93-
*
94-
* @return float|int
9587
*/
96-
public function getRight()
88+
public function getRight(): ?float
9789
{
9890
return $this->right;
9991
}
10092

10193
/**
10294
* Set right.
103-
*
104-
* @param float|int $value
105-
*
106-
* @return self
10795
*/
108-
public function setRight($value)
96+
public function setRight(?float $value): self
10997
{
110-
$this->right = $this->setNumericVal($value, $this->right);
98+
$this->right = $this->setNumericVal($value);
11199

112100
return $this;
113101
}
114102

115103
/**
116104
* Get first line.
117-
*
118-
* @return float|int
119105
*/
120-
public function getFirstLine()
106+
public function getFirstLine(): ?float
121107
{
122108
return $this->firstLine;
123109
}
124110

125111
/**
126112
* Set first line.
127-
*
128-
* @param float|int $value
129-
*
130-
* @return self
131113
*/
132-
public function setFirstLine($value)
114+
public function setFirstLine(?float $value): self
133115
{
134-
$this->firstLine = $this->setNumericVal($value, $this->firstLine);
116+
$this->firstLine = $this->setNumericVal($value);
135117

136118
return $this;
137119
}
138120

139121
/**
140122
* Get hanging.
141-
*
142-
* @return float|int
143123
*/
144-
public function getHanging()
124+
public function getHanging(): ?float
145125
{
146126
return $this->hanging;
147127
}
148128

149129
/**
150130
* Set hanging.
151-
*
152-
* @param float|int $value
153-
*
154-
* @return self
155131
*/
156-
public function setHanging($value = null)
132+
public function setHanging(?float $value = null): self
157133
{
158-
$this->hanging = $this->setNumericVal($value, $this->hanging);
134+
$this->hanging = $this->setNumericVal($value);
159135

160136
return $this;
161137
}

0 commit comments

Comments
 (0)