Skip to content

Commit

Permalink
Merge branch 'master' into wordunimplemented2
Browse files Browse the repository at this point in the history
  • Loading branch information
oleibman authored Jan 25, 2025
2 parents d1a16fe + 10ae499 commit 93daccb
Show file tree
Hide file tree
Showing 14 changed files with 665 additions and 76 deletions.
8 changes: 8 additions & 0 deletions docs/changes/1.x/1.4.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,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)
- Added support for PHP 8.4 by [@Progi1984](https://github.com/Progi1984) in [#2660](https://github.com/PHPOffice/PHPWord/pull/2660)
- 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)

Expand All @@ -16,10 +17,17 @@
- 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)
- 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)
- 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)
- 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)
- 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)

### Miscellaneous

- 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)
- 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)

### Deprecations
- Deprecate `PhpOffice\PhpWord\Style\Paragraph::getIndent()` : Use `PhpOffice\PhpWord\Style\Paragraph::getIndentLeft()`
- Deprecate `PhpOffice\PhpWord\Style\Paragraph::setHanging()` : Use `PhpOffice\PhpWord\Style\Paragraph::setIndentHanging()`
- Deprecate `PhpOffice\PhpWord\Style\Paragraph::setIndent()` : Use `PhpOffice\PhpWord\Style\Paragraph::setIndentLeft()`

### BC Breaks
2 changes: 1 addition & 1 deletion src/PhpWord/Element/AbstractContainer.php
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ private function checkValidity($method)
'Footnote' => ['Section', 'TextRun', 'Cell', 'ListItemRun'],
'Endnote' => ['Section', 'TextRun', 'Cell'],
'PreserveText' => ['Section', 'Header', 'Footer', 'Cell'],
'Title' => ['Section', 'Cell'],
'Title' => ['Section', 'Cell', 'Header'],
'TOC' => ['Section'],
'PageBreak' => ['Section'],
'Chart' => ['Section', 'Cell'],
Expand Down
6 changes: 4 additions & 2 deletions src/PhpWord/Reader/Word2007/AbstractPart.php
Original file line number Diff line number Diff line change
Expand Up @@ -662,8 +662,10 @@ protected function readParagraphStyle(XMLReader $xmlReader, DOMElement $domNode)
'alignment' => [self::READ_VALUE, 'w:jc'],
'basedOn' => [self::READ_VALUE, 'w:basedOn'],
'next' => [self::READ_VALUE, 'w:next'],
'indent' => [self::READ_VALUE, 'w:ind', 'w:left'],
'hanging' => [self::READ_VALUE, 'w:ind', 'w:hanging'],
'indentLeft' => [self::READ_VALUE, 'w:ind', 'w:left'],
'indentRight' => [self::READ_VALUE, 'w:ind', 'w:right'],
'indentHanging' => [self::READ_VALUE, 'w:ind', 'w:hanging'],
'indentFirstLine' => [self::READ_VALUE, 'w:ind', 'w:firstLine'],
'spaceAfter' => [self::READ_VALUE, 'w:spacing', 'w:after'],
'spaceBefore' => [self::READ_VALUE, 'w:spacing', 'w:before'],
'widowControl' => [self::READ_FALSE, 'w:widowControl'],
Expand Down
52 changes: 52 additions & 0 deletions src/PhpWord/Shared/Html.php
Original file line number Diff line number Diff line change
Expand Up @@ -931,6 +931,58 @@ 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);

Expand Down
3 changes: 1 addition & 2 deletions src/PhpWord/Style/AbstractStyle.php
Original file line number Diff line number Diff line change
Expand Up @@ -332,12 +332,11 @@ protected function setEnumVal($value = null, $enum = [], $default = null)
* Set object value.
*
* @param mixed $value
* @param string $styleName
* @param mixed &$style
*
* @return mixed
*/
protected function setObjectVal($value, $styleName, &$style)
protected function setObjectVal($value, string $styleName, &$style)
{
$styleClass = substr(static::class, 0, (int) strrpos(static::class, '\\')) . '\\' . $styleName;
if (is_array($value)) {
Expand Down
100 changes: 100 additions & 0 deletions src/PhpWord/Style/Cell.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,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.
*
Expand Down Expand Up @@ -357,4 +377,84 @@ public function getNoWrap(): bool
{
return $this->noWrap;
}

/**
* Get style padding-top.
*/
public function getPaddingTop(): ?int
{
return $this->paddingTop;
}

/**
* Set style padding-top.
*
* @return $this
*/
public function setPaddingTop(int $value): self
{
$this->paddingTop = $value;

return $this;
}

/**
* Get style padding-bottom.
*/
public function getPaddingBottom(): ?int
{
return $this->paddingBottom;
}

/**
* Set style padding-bottom.
*
* @return $this
*/
public function setPaddingBottom(int $value): self
{
$this->paddingBottom = $value;

return $this;
}

/**
* Get style padding-left.
*/
public function getPaddingLeft(): ?int
{
return $this->paddingLeft;
}

/**
* Set style padding-left.
*
* @return $this
*/
public function setPaddingLeft(int $value): self
{
$this->paddingLeft = $value;

return $this;
}

/**
* Get style padding-right.
*/
public function getPaddingRight(): ?int
{
return $this->paddingRight;
}

/**
* Set style padding-right.
*
* @return $this
*/
public function setPaddingRight(int $value): self
{
$this->paddingRight = $value;

return $this;
}
}
58 changes: 17 additions & 41 deletions src/PhpWord/Style/Indentation.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,30 +29,30 @@ class Indentation extends AbstractStyle
/**
* Left indentation (twip).
*
* @var float|int
* @var null|float
*/
private $left = 0;

/**
* Right indentation (twip).
*
* @var float|int
* @var null|float
*/
private $right = 0;

/**
* Additional first line indentation (twip).
*
* @var float|int
* @var null|float
*/
private $firstLine = 0;

/**
* Indentation removed from first line (twip).
*
* @var float|int
* @var null|float
*/
private $hanging;
private $hanging = 0;

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

/**
* Get left.
*
* @return float|int
*/
public function getLeft()
public function getLeft(): ?float
{
return $this->left;
}

/**
* Set left.
*
* @param float|int $value
*
* @return self
*/
public function setLeft($value)
public function setLeft(?float $value): self
{
$this->left = $this->setNumericVal($value, $this->left);
$this->left = $this->setNumericVal($value);

return $this;
}

/**
* Get right.
*
* @return float|int
*/
public function getRight()
public function getRight(): ?float
{
return $this->right;
}

/**
* Set right.
*
* @param float|int $value
*
* @return self
*/
public function setRight($value)
public function setRight(?float $value): self
{
$this->right = $this->setNumericVal($value, $this->right);
$this->right = $this->setNumericVal($value);

return $this;
}

/**
* Get first line.
*
* @return float|int
*/
public function getFirstLine()
public function getFirstLine(): ?float
{
return $this->firstLine;
}

/**
* Set first line.
*
* @param float|int $value
*
* @return self
*/
public function setFirstLine($value)
public function setFirstLine(?float $value): self
{
$this->firstLine = $this->setNumericVal($value, $this->firstLine);
$this->firstLine = $this->setNumericVal($value);

return $this;
}

/**
* Get hanging.
*
* @return float|int
*/
public function getHanging()
public function getHanging(): ?float
{
return $this->hanging;
}

/**
* Set hanging.
*
* @param float|int $value
*
* @return self
*/
public function setHanging($value = null)
public function setHanging(?float $value = null): self
{
$this->hanging = $this->setNumericVal($value, $this->hanging);
$this->hanging = $this->setNumericVal($value);

return $this;
}
Expand Down
Loading

0 comments on commit 93daccb

Please sign in to comment.