From b9e19347e05a2a01f29cf7fe5e7916250c17e47b Mon Sep 17 00:00:00 2001 From: Progi1984 Date: Sun, 1 Aug 2021 21:13:22 +0200 Subject: [PATCH] Added column spacing in RichText & line spacing mode & spacing before/after for Paragraph --- composer.json | 2 +- docs/changes/1.0.0.md | 8 + docs/usage/shapes/richtext.md | 52 ++++++- samples/Sample_01_Simple.php | 2 +- src/PhpPresentation/Reader/ODPresentation.php | 96 +++++++++--- src/PhpPresentation/Reader/PowerPoint2007.php | 25 +++- src/PhpPresentation/Shape/RichText.php | 139 ++++++++++++------ .../Shape/RichText/Paragraph.php | 104 ++++++++++++- .../Writer/ODPresentation/Content.php | 22 ++- .../AbstractDecoratorWriter.php | 7 +- .../Writer/PowerPoint2007/AbstractSlide.php | 29 +++- .../Tests/AbstractShapeTest.php | 71 ++++----- .../Tests/Reader/ODPresentationTest.php | 34 ++++- .../Tests/Reader/PowerPoint2007Test.php | 39 +++-- .../Tests/Shape/RichText/ParagraphTest.php | 67 ++++++--- .../Tests/Shape/RichTextTest.php | 92 +++++++----- .../Writer/ODPresentation/ContentTest.php | 42 ++++++ .../Writer/PowerPoint2007/PptChartsTest.php | 10 +- .../Writer/PowerPoint2007/PptSlidesTest.php | 97 ++++++++++-- .../_includes/PhpPresentationTestCase.php | 12 +- 20 files changed, 729 insertions(+), 221 deletions(-) diff --git a/composer.json b/composer.json index 2f1e0f3a8..44799dad8 100644 --- a/composer.json +++ b/composer.json @@ -22,7 +22,7 @@ "php": "^7.1|^8.0", "ext-xml": "*", "ext-zip": "*", - "phpoffice/common": "0.2.*", + "phpoffice/common": "dev-develop", "phpoffice/phpspreadsheet": "^1.9.0" }, "require-dev": { diff --git a/docs/changes/1.0.0.md b/docs/changes/1.0.0.md index 62fb51c96..621fc25c9 100644 --- a/docs/changes/1.0.0.md +++ b/docs/changes/1.0.0.md @@ -52,6 +52,14 @@ - Support for line smooth for line and scatter chart - @ksmeeks0001 GH-626 & @Progi1984 GH-662 - ODPresentation Writer - PowerPoint2007 Writer +- Support for column spacing for RichText - @zoff83 GH-617 & @Progi1984 GH-663 + - PowerPoint2007 Reader + - PowerPoint2007 Writer +- Support for line spacing mode & spacing before/after for Paragraph - @zoff83 GH-617 & @Progi1984 GH-663 + - ODPresentation Reader + - ODPresentation Writer + - PowerPoint2007 Reader + - PowerPoint2007 Writer ## Project Management - Migrated from Travis CI to Github Actions - @Progi1984 GH-635 diff --git a/docs/usage/shapes/richtext.md b/docs/usage/shapes/richtext.md index 21e538401..e44f358e3 100644 --- a/docs/usage/shapes/richtext.md +++ b/docs/usage/shapes/richtext.md @@ -2,6 +2,12 @@ Rich text shapes contain paragraphs of texts. To create a rich text shape, use `createRichTextShape` method of slide. +Each rich text can contain multiples paragraphs. +Each paragraph can contain: +- a `TextElement` +- a `BreakElement` +- a `Run` + Below are the properties that you can set for a rich text shape. - `wrap` @@ -19,15 +25,33 @@ Below are the properties that you can set for a rich text shape. - `topInset` in pixels - `autoShrinkHorizontal` (boolean) - `autoShrinkVertical` (boolean) +- `columnSpacing` see *Column Spacing* Properties that can be set for each paragraphs are as follow. - `alignment` - `bulletStyle` see *[Bullet](#bullet)* -- `lineSpacing` see *[LineSpacing](#linespacing)* +- `lineSpacing` see *Line Spacing* - `font` -## Bullet +## Column Spacing + +For a paragraph, you can define the column spacing. + +Example: + +``` php +setColumnSpacing(200); +$columnSpacing = $richText->getColumnSpacing(); +``` + +## Paragraph +### Bullet For a paragraph, you can define the bullet style. @@ -58,9 +82,10 @@ $paragraph->getBulletStyle()->setBulletType(Bullet::TYPE_BULLET); $paragraph->getBulletStyle()->setBulletColor(new Color(Color::COLOR_RED)); ``` -## LineSpacing +### Line Spacing For a paragraph, you can define the line spacing. +By default, mode is in percent (`Paragraph::LINE_SPACING_MODE_PERCENT`), but you can use the point mode (`Paragraph::LINE_SPACING_MODE_POINT`). Example: @@ -72,6 +97,27 @@ use PhpOffice\PhpPresentation\Shape\RichText\Paragraph; $paragraph = new Paragraph(); $paragraph->setLineSpacing(200); $lineSpacing = $paragraph->getLineSpacing(); + +$paragraph->setLineSpacingMode(Paragraph::LINE_SPACING_MODE_POINT); +$lineSpacingMode = $paragraph->getLineSpacingMode(); +``` + +### Spacing + +For a paragraph, you can define the spacing before and after the paragraph in point +Example: + +``` php +setSpacingAfter(12); +$spacingAfter = $paragraph->getSpacingAfter(); + +$paragraph->setSpacingBefore(34); +$spacingBefore = $paragraph->getSpacingBefore(); ``` ## Run diff --git a/samples/Sample_01_Simple.php b/samples/Sample_01_Simple.php index 1ecb00302..706613782 100644 --- a/samples/Sample_01_Simple.php +++ b/samples/Sample_01_Simple.php @@ -30,7 +30,7 @@ $shape = $currentSlide->createDrawingShape(); $shape->setName('PHPPresentation logo') ->setDescription('PHPPresentation logo') - ->setPath('./resources/phppowerpoint_logo.gif') + ->setPath(__DIR__ . '/resources/phppowerpoint_logo.gif') ->setHeight(36) ->setOffsetX(10) ->setOffsetY(10); diff --git a/src/PhpPresentation/Reader/ODPresentation.php b/src/PhpPresentation/Reader/ODPresentation.php index a7fd1fde6..646d1bf14 100644 --- a/src/PhpPresentation/Reader/ODPresentation.php +++ b/src/PhpPresentation/Reader/ODPresentation.php @@ -269,7 +269,7 @@ protected function loadStyle(DOMElement $nodeStyle) $distance = ($offsetY < 0 ? $offsetY * -1 : $offsetY); } $oShadow->setDirection((int) rad2deg(atan2($offsetY, $offsetX))); - $oShadow->setDistance((int) round(CommonDrawing::centimetersToPixels($distance))); + $oShadow->setDistance(CommonDrawing::centimetersToPixels($distance)); } } // Read Fill @@ -365,6 +365,19 @@ protected function loadStyle(DOMElement $nodeStyle) $nodeParagraphProps = $this->oXMLReader->getElement('style:paragraph-properties', $nodeStyle); if ($nodeParagraphProps instanceof DOMElement) { + if ($nodeParagraphProps->hasAttribute('fo:line-height')) { + $lineHeightUnit = $this->getExpressionUnit($nodeParagraphProps->getAttribute('fo:margin-bottom')); + $lineSpacingMode = $lineHeightUnit == '%' ? Paragraph::LINE_SPACING_MODE_PERCENT : Paragraph::LINE_SPACING_MODE_POINT; + $lineSpacing = $this->getExpressionValue($nodeParagraphProps->getAttribute('fo:margin-bottom')); + } + if ($nodeParagraphProps->hasAttribute('fo:margin-bottom')) { + $spacingAfter = (float) substr($nodeParagraphProps->getAttribute('fo:margin-bottom'), 0, -2); + $spacingAfter = CommonDrawing::centimetersToPoints($spacingAfter); + } + if ($nodeParagraphProps->hasAttribute('fo:margin-top')) { + $spacingBefore = (float) substr($nodeParagraphProps->getAttribute('fo:margin-top'), 0, -2); + $spacingBefore = CommonDrawing::centimetersToPoints($spacingBefore); + } $oAlignment = new Alignment(); if ($nodeParagraphProps->hasAttribute('fo:text-align')) { $oAlignment->setHorizontal($nodeParagraphProps->getAttribute('fo:text-align')); @@ -407,10 +420,10 @@ protected function loadStyle(DOMElement $nodeStyle) $oNodeListProperties = $this->oXMLReader->getElement('style:list-level-properties', $oNodeListLevel); if ($oNodeListProperties instanceof DOMElement) { if ($oNodeListProperties->hasAttribute('text:min-label-width')) { - $oAlignment->setIndent((int) round(CommonDrawing::centimetersToPixels(substr($oNodeListProperties->getAttribute('text:min-label-width'), 0, -2)))); + $oAlignment->setIndent(CommonDrawing::centimetersToPixels((float) substr($oNodeListProperties->getAttribute('text:min-label-width'), 0, -2))); } if ($oNodeListProperties->hasAttribute('text:space-before')) { - $iSpaceBefore = (int) CommonDrawing::centimetersToPixels(substr($oNodeListProperties->getAttribute('text:space-before'), 0, -2)); + $iSpaceBefore = CommonDrawing::centimetersToPixels((float) substr($oNodeListProperties->getAttribute('text:space-before'), 0, -2)); $iMarginLeft = $iSpaceBefore + $oAlignment->getIndent(); $oAlignment->setMarginLeft($iMarginLeft); } @@ -432,12 +445,16 @@ protected function loadStyle(DOMElement $nodeStyle) } $this->arrayStyles[$keyStyle] = [ - 'alignment' => isset($oAlignment) ? $oAlignment : null, - 'background' => isset($oBackground) ? $oBackground : null, - 'fill' => isset($oFill) ? $oFill : null, - 'font' => isset($oFont) ? $oFont : null, - 'shadow' => isset($oShadow) ? $oShadow : null, - 'listStyle' => isset($arrayListStyle) ? $arrayListStyle : null, + 'alignment' => $oAlignment ?? null, + 'background' => $oBackground ?? null, + 'fill' => $oFill ?? null, + 'font' => $oFont ?? null, + 'shadow' => $oShadow ?? null, + 'listStyle' => $arrayListStyle ?? null, + 'spacingAfter' => $spacingAfter ?? null, + 'spacingBefore' => $spacingBefore ?? null, + 'lineSpacingMode' => $lineSpacingMode ?? null, + 'lineSpacing' => $lineSpacing ?? null, ]; return true; @@ -507,11 +524,11 @@ protected function loadShapeDrawing(DOMElement $oNodeFrame): void $oShape->setName($oNodeFrame->hasAttribute('draw:name') ? $oNodeFrame->getAttribute('draw:name') : ''); $oShape->setDescription($oNodeFrame->hasAttribute('draw:name') ? $oNodeFrame->getAttribute('draw:name') : ''); $oShape->setResizeProportional(false); - $oShape->setWidth($oNodeFrame->hasAttribute('svg:width') ? (int) round(CommonDrawing::centimetersToPixels(substr($oNodeFrame->getAttribute('svg:width'), 0, -2))) : ''); - $oShape->setHeight($oNodeFrame->hasAttribute('svg:height') ? (int) round(CommonDrawing::centimetersToPixels(substr($oNodeFrame->getAttribute('svg:height'), 0, -2))) : ''); + $oShape->setWidth($oNodeFrame->hasAttribute('svg:width') ? CommonDrawing::centimetersToPixels((float) substr($oNodeFrame->getAttribute('svg:width'), 0, -2)) : 0); + $oShape->setHeight($oNodeFrame->hasAttribute('svg:height') ? CommonDrawing::centimetersToPixels((float) substr($oNodeFrame->getAttribute('svg:height'), 0, -2)) : 0); $oShape->setResizeProportional(true); - $oShape->setOffsetX($oNodeFrame->hasAttribute('svg:x') ? (int) round(CommonDrawing::centimetersToPixels(substr($oNodeFrame->getAttribute('svg:x'), 0, -2))) : ''); - $oShape->setOffsetY($oNodeFrame->hasAttribute('svg:y') ? (int) round(CommonDrawing::centimetersToPixels(substr($oNodeFrame->getAttribute('svg:y'), 0, -2))) : ''); + $oShape->setOffsetX($oNodeFrame->hasAttribute('svg:x') ? CommonDrawing::centimetersToPixels((float) substr($oNodeFrame->getAttribute('svg:x'), 0, -2)) : 0); + $oShape->setOffsetY($oNodeFrame->hasAttribute('svg:y') ? CommonDrawing::centimetersToPixels((float) substr($oNodeFrame->getAttribute('svg:y'), 0, -2)) : 0); if ($oNodeFrame->hasAttribute('draw:style-name')) { $keyStyle = $oNodeFrame->getAttribute('draw:style-name'); @@ -535,10 +552,10 @@ protected function loadShapeRichText(DOMElement $oNodeFrame): void $oShape = $this->oPhpPresentation->getActiveSlide()->createRichTextShape(); $oShape->setParagraphs([]); - $oShape->setWidth($oNodeFrame->hasAttribute('svg:width') ? (int) round(CommonDrawing::centimetersToPixels(substr($oNodeFrame->getAttribute('svg:width'), 0, -2))) : ''); - $oShape->setHeight($oNodeFrame->hasAttribute('svg:height') ? (int) round(CommonDrawing::centimetersToPixels(substr($oNodeFrame->getAttribute('svg:height'), 0, -2))) : ''); - $oShape->setOffsetX($oNodeFrame->hasAttribute('svg:x') ? (int) round(CommonDrawing::centimetersToPixels(substr($oNodeFrame->getAttribute('svg:x'), 0, -2))) : ''); - $oShape->setOffsetY($oNodeFrame->hasAttribute('svg:y') ? (int) round(CommonDrawing::centimetersToPixels(substr($oNodeFrame->getAttribute('svg:y'), 0, -2))) : ''); + $oShape->setWidth($oNodeFrame->hasAttribute('svg:width') ? CommonDrawing::centimetersToPixels((float) substr($oNodeFrame->getAttribute('svg:width'), 0, -2)) : 0); + $oShape->setHeight($oNodeFrame->hasAttribute('svg:height') ? CommonDrawing::centimetersToPixels((float) substr($oNodeFrame->getAttribute('svg:height'), 0, -2)) : 0); + $oShape->setOffsetX($oNodeFrame->hasAttribute('svg:x') ? CommonDrawing::centimetersToPixels((float) substr($oNodeFrame->getAttribute('svg:x'), 0, -2)) : 0); + $oShape->setOffsetY($oNodeFrame->hasAttribute('svg:y') ? CommonDrawing::centimetersToPixels((float) substr($oNodeFrame->getAttribute('svg:y'), 0, -2)) : 0); foreach ($this->oXMLReader->getElements('draw:text-box/*', $oNodeFrame) as $oNodeParagraph) { $this->levelParagraph = 0; @@ -565,6 +582,23 @@ protected function loadShapeRichText(DOMElement $oNodeFrame): void protected function readParagraph(RichText $oShape, DOMElement $oNodeParent): void { $oParagraph = $oShape->createParagraph(); + if ($oNodeParent->hasAttribute('text:style-name')) { + $keyStyle = $oNodeParent->getAttribute('text:style-name'); + if (isset($this->arrayStyles[$keyStyle])) { + if (!empty($this->arrayStyles[$keyStyle]['spacingAfter'])) { + $oParagraph->setSpacingAfter($this->arrayStyles[$keyStyle]['spacingAfter']); + } + if (!empty($this->arrayStyles[$keyStyle]['spacingBefore'])) { + $oParagraph->setSpacingBefore($this->arrayStyles[$keyStyle]['spacingBefore']); + } + if (!empty($this->arrayStyles[$keyStyle]['lineSpacingMode'])) { + $oParagraph->setLineSpacingMode($this->arrayStyles[$keyStyle]['lineSpacingMode']); + } + if (!empty($this->arrayStyles[$keyStyle]['lineSpacing'])) { + $oParagraph->setLineSpacing($this->arrayStyles[$keyStyle]['lineSpacing']); + } + } + } $oDomList = $this->oXMLReader->getElements('text:span', $oNodeParent); $oDomTextNodes = $this->oXMLReader->getElements('text()', $oNodeParent); foreach ($oDomTextNodes as $oDomTextNode) { @@ -666,4 +700,32 @@ protected function loadStylesFile(): void } } } + + /** + * @param string $expr + * + * @return string + */ + private function getExpressionUnit(string $expr): string + { + if (substr($expr, -1) == '%') { + return '%'; + } + + return substr($expr, -2); + } + + /** + * @param string $expr + * + * @return string + */ + private function getExpressionValue(string $expr): string + { + if (substr($expr, -1) == '%') { + return substr($expr, 0, -1); + } + + return substr($expr, 0, -2); + } } diff --git a/src/PhpPresentation/Reader/PowerPoint2007.php b/src/PhpPresentation/Reader/PowerPoint2007.php index 558ece186..b4ea147e7 100644 --- a/src/PhpPresentation/Reader/PowerPoint2007.php +++ b/src/PhpPresentation/Reader/PowerPoint2007.php @@ -798,7 +798,7 @@ protected function loadShapeDrawing(XMLReader $document, DOMElement $node, Abstr $oElement = $document->getElement('p:spPr/a:xfrm', $node); if ($oElement instanceof DOMElement) { if ($oElement->hasAttribute('rot')) { - $oShape->setRotation(CommonDrawing::angleToDegrees($oElement->getAttribute('rot'))); + $oShape->setRotation((int) CommonDrawing::angleToDegrees($oElement->getAttribute('rot'))); } } @@ -835,7 +835,7 @@ protected function loadShapeDrawing(XMLReader $document, DOMElement $node, Abstr $oShape->getShadow()->setDistance(CommonDrawing::emuToPixels($oSubElement->getAttribute('dist'))); } if ($oSubElement->hasAttribute('dir')) { - $oShape->getShadow()->setDirection(CommonDrawing::angleToDegrees($oSubElement->getAttribute('dir'))); + $oShape->getShadow()->setDirection((int) CommonDrawing::angleToDegrees($oSubElement->getAttribute('dir'))); } if ($oSubElement->hasAttribute('algn')) { $oShape->getShadow()->setAlignment($oSubElement->getAttribute('algn')); @@ -880,7 +880,7 @@ protected function loadShapeRichText(XMLReader $document, DOMElement $node, Abst $oElement = $document->getElement('p:spPr/a:xfrm', $node); if ($oElement instanceof DOMElement && $oElement->hasAttribute('rot')) { - $oShape->setRotation(CommonDrawing::angleToDegrees($oElement->getAttribute('rot'))); + $oShape->setRotation((int) CommonDrawing::angleToDegrees($oElement->getAttribute('rot'))); } $oElement = $document->getElement('p:spPr/a:xfrm/a:off', $node); @@ -1098,6 +1098,25 @@ protected function loadParagraph(XMLReader $document, DOMElement $oElement, $oSh $oParagraph->getAlignment()->setIsRTL((bool) $oSubElement->getAttribute('rtl')); } + $oElementLineSpacingPoints = $document->getElement('a:lnSpc/a:spcPts', $oSubElement); + if ($oElementLineSpacingPoints instanceof DOMElement) { + $oParagraph->setLineSpacingMode(Paragraph::LINE_SPACING_MODE_POINT); + $oParagraph->setLineSpacing($oElementLineSpacingPoints->getAttribute('val') / 100); + } + $oElementLineSpacingPercent = $document->getElement('a:lnSpc/a:spcPct', $oSubElement); + if ($oElementLineSpacingPercent instanceof DOMElement) { + $oParagraph->setLineSpacingMode(Paragraph::LINE_SPACING_MODE_PERCENT); + $oParagraph->setLineSpacing($oElementLineSpacingPercent->getAttribute('val') / 1000); + } + $oElementSpacingBefore = $document->getElement('a:spcBef/a:spcPts', $oSubElement); + if ($oElementSpacingBefore instanceof DOMElement) { + $oParagraph->setSpacingBefore($oElementSpacingBefore->getAttribute('val') / 100); + } + $oElementSpacingAfter = $document->getElement('a:spcAft/a:spcPts', $oSubElement); + if ($oElementSpacingAfter instanceof DOMElement) { + $oParagraph->setSpacingAfter($oElementSpacingAfter->getAttribute('val') / 100); + } + $oParagraph->getBulletStyle()->setBulletType(Bullet::TYPE_NONE); $oElementBuFont = $document->getElement('a:buFont', $oSubElement); diff --git a/src/PhpPresentation/Shape/RichText.php b/src/PhpPresentation/Shape/RichText.php index 1608a38e9..5bd118ee6 100644 --- a/src/PhpPresentation/Shape/RichText.php +++ b/src/PhpPresentation/Shape/RichText.php @@ -105,6 +105,13 @@ class RichText extends AbstractShape implements ComparableInterface */ private $columns = 1; + /** + * The spacing between columns + * + * @var int + */ + private $columnSpacing = 0; + /** * Bottom inset (in pixels). * @@ -181,7 +188,7 @@ public function __construct() * * @return int */ - public function getActiveParagraphIndex() + public function getActiveParagraphIndex(): int { return $this->activeParagraph; } @@ -254,13 +261,13 @@ public function createParagraph(): Paragraph /** * Add text. * - * @param \PhpOffice\PhpPresentation\Shape\RichText\TextElementInterface $pText Rich text element + * @param TextElementInterface|null $pText Rich text element * * @throws \Exception * - * @return \PhpOffice\PhpPresentation\Shape\RichText + * @return self */ - public function addText(TextElementInterface $pText = null) + public function addText(TextElementInterface $pText = null): self { $this->richTextParagraphs[$this->activeParagraph]->addText($pText); @@ -272,11 +279,11 @@ public function addText(TextElementInterface $pText = null) * * @param string $pText Text * - * @return \PhpOffice\PhpPresentation\Shape\RichText\TextElement + * @return RichText\TextElement * * @throws \Exception */ - public function createText($pText = '') + public function createText(string $pText = ''): RichText\TextElement { return $this->richTextParagraphs[$this->activeParagraph]->createText($pText); } @@ -284,11 +291,11 @@ public function createText($pText = '') /** * Create break. * - * @return \PhpOffice\PhpPresentation\Shape\RichText\BreakElement + * @return RichText\BreakElement * * @throws \Exception */ - public function createBreak() + public function createBreak(): RichText\BreakElement { return $this->richTextParagraphs[$this->activeParagraph]->createBreak(); } @@ -298,11 +305,11 @@ public function createBreak() * * @param string $pText Text * - * @return \PhpOffice\PhpPresentation\Shape\RichText\Run + * @return RichText\Run * * @throws \Exception */ - public function createTextRun($pText = '') + public function createTextRun(string $pText = ''): RichText\Run { return $this->richTextParagraphs[$this->activeParagraph]->createTextRun($pText); } @@ -312,7 +319,7 @@ public function createTextRun($pText = '') * * @return string */ - public function getPlainText() + public function getPlainText(): string { // Return value $returnValue = ''; @@ -364,7 +371,7 @@ public function setParagraphs(array $paragraphs = []): self * * @return string */ - public function getWrap() + public function getWrap(): string { return $this->wrap; } @@ -374,9 +381,9 @@ public function getWrap() * * @param string $value * - * @return \PhpOffice\PhpPresentation\Shape\RichText + * @return self */ - public function setWrap($value = self::WRAP_SQUARE) + public function setWrap(string $value = self::WRAP_SQUARE): self { $this->wrap = $value; @@ -388,7 +395,7 @@ public function setWrap($value = self::WRAP_SQUARE) * * @return string */ - public function getAutoFit() + public function getAutoFit(): string { return $this->autoFit; } @@ -416,9 +423,9 @@ public function getLineSpaceReduction(): ?float * @param float|null $fontScale * @param float|null $lnSpcReduction * - * @return \PhpOffice\PhpPresentation\Shape\RichText + * @return self */ - public function setAutoFit($value = self::AUTOFIT_DEFAULT, $fontScale = null, $lnSpcReduction = null) + public function setAutoFit(string $value = self::AUTOFIT_DEFAULT, float $fontScale = null, float $lnSpcReduction = null): self { $this->autoFit = $value; @@ -438,7 +445,7 @@ public function setAutoFit($value = self::AUTOFIT_DEFAULT, $fontScale = null, $l * * @return string */ - public function getHorizontalOverflow() + public function getHorizontalOverflow(): string { return $this->horizontalOverflow; } @@ -448,9 +455,9 @@ public function getHorizontalOverflow() * * @param string $value * - * @return \PhpOffice\PhpPresentation\Shape\RichText + * @return self */ - public function setHorizontalOverflow($value = self::OVERFLOW_OVERFLOW) + public function setHorizontalOverflow(string $value = self::OVERFLOW_OVERFLOW): self { $this->horizontalOverflow = $value; @@ -462,7 +469,7 @@ public function setHorizontalOverflow($value = self::OVERFLOW_OVERFLOW) * * @return string */ - public function getVerticalOverflow() + public function getVerticalOverflow(): string { return $this->verticalOverflow; } @@ -472,9 +479,9 @@ public function getVerticalOverflow() * * @param string $value * - * @return \PhpOffice\PhpPresentation\Shape\RichText + * @return self */ - public function setVerticalOverflow($value = self::OVERFLOW_OVERFLOW) + public function setVerticalOverflow(string $value = self::OVERFLOW_OVERFLOW): self { $this->verticalOverflow = $value; @@ -486,7 +493,7 @@ public function setVerticalOverflow($value = self::OVERFLOW_OVERFLOW) * * @return bool */ - public function isUpright() + public function isUpright(): bool { return $this->upright; } @@ -496,9 +503,9 @@ public function isUpright() * * @param bool $value * - * @return \PhpOffice\PhpPresentation\Shape\RichText + * @return self */ - public function setUpright($value = false) + public function setUpright(bool $value = false): self { $this->upright = $value; @@ -510,7 +517,7 @@ public function setUpright($value = false) * * @return bool */ - public function isVertical() + public function isVertical(): bool { return $this->vertical; } @@ -520,9 +527,9 @@ public function isVertical() * * @param bool $value * - * @return \PhpOffice\PhpPresentation\Shape\RichText + * @return self */ - public function setVertical($value = false) + public function setVertical(bool $value = false): self { $this->vertical = $value; @@ -534,7 +541,7 @@ public function setVertical($value = false) * * @return int */ - public function getColumns() + public function getColumns(): int { return $this->columns; } @@ -546,9 +553,9 @@ public function getColumns() * * @throws \Exception * - * @return \PhpOffice\PhpPresentation\Shape\RichText + * @return self */ - public function setColumns($value = 1) + public function setColumns(int $value = 1): self { if ($value > 16 || $value < 1) { throw new \Exception('Number of columns should be 1-16'); @@ -564,7 +571,7 @@ public function setColumns($value = 1) * * @return float */ - public function getInsetBottom() + public function getInsetBottom(): float { return $this->bottomInset; } @@ -574,9 +581,9 @@ public function getInsetBottom() * * @param float $value * - * @return \PhpOffice\PhpPresentation\Shape\RichText + * @return self */ - public function setInsetBottom($value = 4.8) + public function setInsetBottom(float $value = 4.8): self { $this->bottomInset = $value; @@ -588,7 +595,7 @@ public function setInsetBottom($value = 4.8) * * @return float */ - public function getInsetLeft() + public function getInsetLeft(): float { return $this->leftInset; } @@ -598,9 +605,9 @@ public function getInsetLeft() * * @param float $value * - * @return \PhpOffice\PhpPresentation\Shape\RichText + * @return self */ - public function setInsetLeft($value = 9.6) + public function setInsetLeft(float $value = 9.6): self { $this->leftInset = $value; @@ -612,7 +619,7 @@ public function setInsetLeft($value = 9.6) * * @return float */ - public function getInsetRight() + public function getInsetRight(): float { return $this->rightInset; } @@ -622,9 +629,9 @@ public function getInsetRight() * * @param float $value * - * @return \PhpOffice\PhpPresentation\Shape\RichText + * @return self */ - public function setInsetRight($value = 9.6) + public function setInsetRight(float $value = 9.6): self { $this->rightInset = $value; @@ -636,7 +643,7 @@ public function setInsetRight($value = 9.6) * * @return float */ - public function getInsetTop() + public function getInsetTop(): float { return $this->topInset; } @@ -646,9 +653,9 @@ public function getInsetTop() * * @param float $value * - * @return \PhpOffice\PhpPresentation\Shape\RichText + * @return self */ - public function setInsetTop($value = 4.8) + public function setInsetTop(float $value = 4.8): self { $this->topInset = $value; @@ -687,6 +694,32 @@ public function hasAutoShrinkVertical(): ?bool return $this->autoShrinkVertical; } + /** + * Get spacing between columns + * + * @return int + */ + public function getColumnSpacing(): int + { + return $this->columnSpacing; + } + + /** + * Set spacing between columns + * + * @param int $value + * + * @return self + */ + public function setColumnSpacing(int $value = 0): self + { + if ($value >= 0) { + $this->columnSpacing = $value; + } + + return $this; + } + /** * Get hash code. * @@ -699,6 +732,22 @@ public function getHashCode(): string $hashElements .= $element->getHashCode(); } - return md5($hashElements . $this->wrap . $this->autoFit . $this->horizontalOverflow . $this->verticalOverflow . ($this->upright ? '1' : '0') . ($this->vertical ? '1' : '0') . $this->columns . $this->bottomInset . $this->leftInset . $this->rightInset . $this->topInset . parent::getHashCode() . __CLASS__); + return md5( + $hashElements + . $this->wrap + . $this->autoFit + . $this->horizontalOverflow + . $this->verticalOverflow + . ($this->upright ? '1' : '0') + . ($this->vertical ? '1' : '0') + . $this->columns + . $this->columnSpacing + . $this->bottomInset + . $this->leftInset + . $this->rightInset + . $this->topInset + . parent::getHashCode() + . __CLASS__ + ); } } diff --git a/src/PhpPresentation/Shape/RichText/Paragraph.php b/src/PhpPresentation/Shape/RichText/Paragraph.php index 449008c2b..939d9d874 100644 --- a/src/PhpPresentation/Shape/RichText/Paragraph.php +++ b/src/PhpPresentation/Shape/RichText/Paragraph.php @@ -28,12 +28,15 @@ */ class Paragraph implements ComparableInterface { + public const LINE_SPACING_MODE_PERCENT = 'percent'; + public const LINE_SPACING_MODE_POINT = 'point'; + /** * Rich text elements. * * @var array */ - private $richTextElements; + private $richTextElements = []; /** * Alignment. @@ -52,7 +55,7 @@ class Paragraph implements ComparableInterface /** * Bullet style. * - * @var \PhpOffice\PhpPresentation\Style\Bullet + * @var Bullet */ private $bulletStyle; @@ -61,6 +64,21 @@ class Paragraph implements ComparableInterface */ private $lineSpacing = 100; + /** + * @var string + */ + private $lineSpacingMode = self::LINE_SPACING_MODE_PERCENT; + + /** + * @var int + */ + private $spacingBefore = 0; + + /** + * @var int + */ + private $spacingAfter = 0; + /** * Hash index. * @@ -73,7 +91,6 @@ class Paragraph implements ComparableInterface */ public function __construct() { - $this->richTextElements = []; $this->alignment = new Alignment(); $this->font = new Font(); $this->bulletStyle = new Bullet(); @@ -296,20 +313,95 @@ public function setHashIndex(int $value) /** * @return int */ - public function getLineSpacing() + public function getLineSpacing(): int { return $this->lineSpacing; } /** + * Value in points + * * @param int $lineSpacing * - * @return Paragraph + * @return self */ - public function setLineSpacing($lineSpacing) + public function setLineSpacing($lineSpacing): self { $this->lineSpacing = $lineSpacing; return $this; } + + /** + * @return string + */ + public function getLineSpacingMode(): string + { + return $this->lineSpacingMode; + } + + /** + * @param string $lineSpacingMode + * + * @return self + */ + public function setLineSpacingMode(string $lineSpacingMode): self + { + if (in_array($lineSpacingMode, [ + self::LINE_SPACING_MODE_PERCENT, + self::LINE_SPACING_MODE_POINT, + ])) { + $this->lineSpacingMode = $lineSpacingMode; + } + + return $this; + } + + /** + * Value in points + * + * @return int + */ + public function getSpacingBefore(): int + { + return $this->spacingBefore; + } + + /** + * Value in points + * + * @param int $spacingBefore + * + * @return self + */ + public function setSpacingBefore(int $spacingBefore): self + { + $this->spacingBefore = $spacingBefore; + + return $this; + } + + /** + * Value in points + * + * @return int + */ + public function getSpacingAfter(): int + { + return $this->spacingAfter; + } + + /** + * Value in points + * + * @param int $spacingAfter + * + * @return self + */ + public function setSpacingAfter(int $spacingAfter): self + { + $this->spacingAfter = $spacingAfter; + + return $this; + } } diff --git a/src/PhpPresentation/Writer/ODPresentation/Content.php b/src/PhpPresentation/Writer/ODPresentation/Content.php index 38e6e1a76..cdca2f427 100644 --- a/src/PhpPresentation/Writer/ODPresentation/Content.php +++ b/src/PhpPresentation/Writer/ODPresentation/Content.php @@ -200,6 +200,24 @@ public function writeContent(): string $objWriter->writeAttribute('style:family', 'paragraph'); // style:paragraph-properties $objWriter->startElement('style:paragraph-properties'); + $objWriter->writeAttributeIf( + $item->getLineSpacingMode() === Paragraph::LINE_SPACING_MODE_PERCENT, + 'fo:line-height', + $item->getLineSpacing() . '%' + ); + $objWriter->writeAttributeIf( + $item->getLineSpacingMode() === Paragraph::LINE_SPACING_MODE_POINT, + 'fo:line-height', + $item->getLineSpacing() . 'pt' + ); + $objWriter->writeAttribute( + 'fo:margin-top', + Text::numberFormat(CommonDrawing::pointstoCentimeters($item->getSpacingBefore()), 3) . 'cm' + ); + $objWriter->writeAttribute( + 'fo:margin-bottom', + Text::numberFormat(CommonDrawing::pointstoCentimeters($item->getSpacingAfter()), 3) . 'cm' + ); switch ($item->getAlignment()->getHorizontal()) { case Alignment::HORIZONTAL_LEFT: $objWriter->writeAttribute('fo:text-align', 'left'); @@ -981,7 +999,7 @@ public function writeLineStyle(XMLWriter $objWriter, Line $shape): void break; } $objWriter->writeAttribute('svg:stroke-color', '#' . $shape->getBorder()->getColor()->getRGB()); - $objWriter->writeAttribute('svg:stroke-width', Text::numberFormat(CommonDrawing::pixelsToCentimeters((CommonDrawing::pointsToPixels($shape->getBorder()->getLineWidth()))), 3) . 'cm'); + $objWriter->writeAttribute('svg:stroke-width', Text::numberFormat(CommonDrawing::pointsToCentimeters($shape->getBorder()->getLineWidth()), 3) . 'cm'); $objWriter->endElement(); $objWriter->endElement(); @@ -1000,7 +1018,7 @@ public function writeTableStyle(XMLWriter $objWriter, Table $shape): void // style:table-row-properties $objWriter->startElement('style:table-row-properties'); - $objWriter->writeAttribute('style:row-height', Text::numberFormat(CommonDrawing::pixelsToCentimeters(CommonDrawing::pointsToPixels($shapeRow->getHeight())), 3) . 'cm'); + $objWriter->writeAttribute('style:row-height', Text::numberFormat(CommonDrawing::pointsToCentimeters($shapeRow->getHeight()), 3) . 'cm'); $objWriter->endElement(); $objWriter->endElement(); diff --git a/src/PhpPresentation/Writer/PowerPoint2007/AbstractDecoratorWriter.php b/src/PhpPresentation/Writer/PowerPoint2007/AbstractDecoratorWriter.php index d96ebb1dc..802098b7f 100644 --- a/src/PhpPresentation/Writer/PowerPoint2007/AbstractDecoratorWriter.php +++ b/src/PhpPresentation/Writer/PowerPoint2007/AbstractDecoratorWriter.php @@ -265,11 +265,8 @@ protected function writeOutline(XMLWriter $objWriter, ?Outline $oOutline): void return; } // Width : pts - $width = $oOutline->getWidth(); - // Width : pts => px - $width = CommonDrawing::pointsToPixels($width); - // Width : px => emu - $width = CommonDrawing::pixelsToEmu($width); + $width = $oOutline->getWidth() ?? 0; + $width = CommonDrawing::pointsToEmu($width); // a:ln $objWriter->startElement('a:ln'); diff --git a/src/PhpPresentation/Writer/PowerPoint2007/AbstractSlide.php b/src/PhpPresentation/Writer/PowerPoint2007/AbstractSlide.php index e8838d909..1151af06c 100644 --- a/src/PhpPresentation/Writer/PowerPoint2007/AbstractSlide.php +++ b/src/PhpPresentation/Writer/PowerPoint2007/AbstractSlide.php @@ -262,6 +262,7 @@ protected function writeShapeText(XMLWriter $objWriter, RichText $shape, int $sh $objWriter->writeAttribute('tIns', CommonDrawing::pixelsToEmu($shape->getInsetTop())); if (1 != $shape->getColumns()) { $objWriter->writeAttribute('numCol', $shape->getColumns()); + $objWriter->writeAttribute('spcCol', CommonDrawing::pixelsToEmu($shape->getColumnSpacing())); } // a:spAutoFit $objWriter->startElement('a:' . $shape->getAutoFit()); @@ -384,8 +385,7 @@ protected function writeShapeTable(XMLWriter $objWriter, ShapeTable $shape, int // p:graphicFrame/a:graphic/a:graphicData/a:tbl/a:tblGrid/ $objWriter->endElement(); // Colspan / rowspan containers - $colSpan = []; - $rowSpan = []; + $colSpan = $rowSpan = []; // Default border style $defaultBorder = new Border(); // Write rows @@ -517,6 +517,7 @@ protected function writeParagraphs(XMLWriter $objWriter, array $paragraphs, bool // a:pPr if (!$bIsPlaceholder) { + // a:pPr $objWriter->startElement('a:pPr'); $objWriter->writeAttribute('algn', $paragraph->getAlignment()->getHorizontal()); $objWriter->writeAttribute('rtl', $paragraph->getAlignment()->isRTL() ? '1' : '0'); @@ -526,9 +527,29 @@ protected function writeParagraphs(XMLWriter $objWriter, array $paragraphs, bool $objWriter->writeAttribute('indent', CommonDrawing::pixelsToEmu($paragraph->getAlignment()->getIndent())); $objWriter->writeAttribute('lvl', $paragraph->getAlignment()->getLevel()); + // a:pPr:a:lnSpc $objWriter->startElement('a:lnSpc'); - $objWriter->startElement('a:spcPct'); - $objWriter->writeAttribute('val', $paragraph->getLineSpacing() * 1000); + if ($paragraph->getLineSpacingMode() == Paragraph::LINE_SPACING_MODE_POINT) { + $objWriter->startElement('a:spcPts'); + $objWriter->writeAttribute('val', $paragraph->getLineSpacing() * 100); + $objWriter->endElement(); + } else { + $objWriter->startElement('a:spcPct'); + $objWriter->writeAttribute('val', $paragraph->getLineSpacing() * 1000); + $objWriter->endElement(); + } + // >a:pPr:a:lnSpc + $objWriter->endElement(); + + $objWriter->startElement('a:spcBef'); + $objWriter->startElement('a:spcPts'); + $objWriter->writeAttribute('val', $paragraph->getSpacingBefore() * 100); + $objWriter->endElement(); + $objWriter->endElement(); + + $objWriter->startElement('a:spcAft'); + $objWriter->startElement('a:spcPts'); + $objWriter->writeAttribute('val', $paragraph->getSpacingAfter() * 100); $objWriter->endElement(); $objWriter->endElement(); diff --git a/tests/PhpPresentation/Tests/AbstractShapeTest.php b/tests/PhpPresentation/Tests/AbstractShapeTest.php index 3fb03556b..c003b293e 100644 --- a/tests/PhpPresentation/Tests/AbstractShapeTest.php +++ b/tests/PhpPresentation/Tests/AbstractShapeTest.php @@ -18,6 +18,7 @@ namespace PhpOffice\PhpPresentation\Tests; +use PhpOffice\PhpPresentation\AbstractShape; use PhpOffice\PhpPresentation\Shape\Hyperlink; use PhpOffice\PhpPresentation\Shape\Placeholder; use PhpOffice\PhpPresentation\Shape\RichText; @@ -44,20 +45,20 @@ public function testConstruct(): void $this->assertEquals(0, $object->getHeight()); $this->assertEquals(0, $object->getRotation()); $this->assertEquals(0, $object->getWidth()); - $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Style\\Border', $object->getBorder()); + $this->assertInstanceOf(Border::class, $object->getBorder()); $this->assertEquals(Border::LINE_NONE, $object->getBorder()->getLineStyle()); - $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Style\\Fill', $object->getFill()); - $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Style\\Shadow', $object->getShadow()); + $this->assertInstanceOf(Fill::class, $object->getFill()); + $this->assertInstanceOf(Shadow::class, $object->getShadow()); } public function testFill(): void { $object = new RichText(); - $this->assertInstanceOf('PhpOffice\\PhpPresentation\\AbstractShape', $object->setFill()); + $this->assertInstanceOf(AbstractShape::class, $object->setFill()); $this->assertNull($object->getFill()); - $this->assertInstanceOf('PhpOffice\\PhpPresentation\\AbstractShape', $object->setFill(new Fill())); - $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Style\\Fill', $object->getFill()); + $this->assertInstanceOf(AbstractShape::class, $object->setFill(new Fill())); + $this->assertInstanceOf(Fill::class, $object->getFill()); } public function testHeight(): void @@ -65,9 +66,9 @@ public function testHeight(): void $object = new RichText(); $value = mt_rand(1, 100); - $this->assertInstanceOf('PhpOffice\\PhpPresentation\\AbstractShape', $object->setHeight()); + $this->assertInstanceOf(AbstractShape::class, $object->setHeight()); $this->assertEquals(0, $object->getHeight()); - $this->assertInstanceOf('PhpOffice\\PhpPresentation\\AbstractShape', $object->setHeight($value)); + $this->assertInstanceOf(AbstractShape::class, $object->setHeight($value)); $this->assertEquals($value, $object->getHeight()); } @@ -75,13 +76,13 @@ public function testHyperlink(): void { $object = new RichText(); - $this->assertInstanceOf('PhpOffice\\PhpPresentation\\AbstractShape', $object->setHyperlink()); + $this->assertInstanceOf(AbstractShape::class, $object->setHyperlink()); $this->assertFalse($object->hasHyperlink()); - $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\Hyperlink', $object->getHyperlink()); + $this->assertInstanceOf(Hyperlink::class, $object->getHyperlink()); $this->assertTrue($object->hasHyperlink()); - $this->assertInstanceOf('PhpOffice\\PhpPresentation\\AbstractShape', $object->setHyperlink(new Hyperlink('http://www.google.fr'))); + $this->assertInstanceOf(AbstractShape::class, $object->setHyperlink(new Hyperlink('http://www.google.fr'))); $this->assertTrue($object->hasHyperlink()); - $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\Hyperlink', $object->getHyperlink()); + $this->assertInstanceOf(Hyperlink::class, $object->getHyperlink()); $this->assertTrue($object->hasHyperlink()); } @@ -90,9 +91,9 @@ public function testOffsetX(): void $object = new RichText(); $value = mt_rand(1, 100); - $this->assertInstanceOf('PhpOffice\\PhpPresentation\\AbstractShape', $object->setOffsetX()); + $this->assertInstanceOf(AbstractShape::class, $object->setOffsetX()); $this->assertEquals(0, $object->getOffsetX()); - $this->assertInstanceOf('PhpOffice\\PhpPresentation\\AbstractShape', $object->setOffsetX($value)); + $this->assertInstanceOf(AbstractShape::class, $object->setOffsetX($value)); $this->assertEquals($value, $object->getOffsetX()); } @@ -101,9 +102,9 @@ public function testOffsetY(): void $object = new RichText(); $value = mt_rand(1, 100); - $this->assertInstanceOf('PhpOffice\\PhpPresentation\\AbstractShape', $object->setOffsetY()); + $this->assertInstanceOf(AbstractShape::class, $object->setOffsetY()); $this->assertEquals(0, $object->getOffsetY()); - $this->assertInstanceOf('PhpOffice\\PhpPresentation\\AbstractShape', $object->setOffsetY($value)); + $this->assertInstanceOf(AbstractShape::class, $object->setOffsetY($value)); $this->assertEquals($value, $object->getOffsetY()); } @@ -112,9 +113,9 @@ public function testRotation(): void $object = new RichText(); $value = mt_rand(1, 100); - $this->assertInstanceOf('PhpOffice\\PhpPresentation\\AbstractShape', $object->setRotation()); + $this->assertInstanceOf(AbstractShape::class, $object->setRotation()); $this->assertEquals(0, $object->getRotation()); - $this->assertInstanceOf('PhpOffice\\PhpPresentation\\AbstractShape', $object->setRotation($value)); + $this->assertInstanceOf(AbstractShape::class, $object->setRotation($value)); $this->assertEquals($value, $object->getRotation()); } @@ -122,10 +123,10 @@ public function testShadow(): void { $object = new RichText(); - $this->assertInstanceOf('PhpOffice\\PhpPresentation\\AbstractShape', $object->setShadow()); + $this->assertInstanceOf(AbstractShape::class, $object->setShadow()); $this->assertNull($object->getShadow()); - $this->assertInstanceOf('PhpOffice\\PhpPresentation\\AbstractShape', $object->setShadow(new Shadow())); - $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Style\\Shadow', $object->getShadow()); + $this->assertInstanceOf(AbstractShape::class, $object->setShadow(new Shadow())); + $this->assertInstanceOf(Shadow::class, $object->getShadow()); } public function testWidth(): void @@ -133,9 +134,9 @@ public function testWidth(): void $object = new RichText(); $value = mt_rand(1, 100); - $this->assertInstanceOf('PhpOffice\\PhpPresentation\\AbstractShape', $object->setWidth()); + $this->assertInstanceOf(AbstractShape::class, $object->setWidth()); $this->assertEquals(0, $object->getWidth()); - $this->assertInstanceOf('PhpOffice\\PhpPresentation\\AbstractShape', $object->setWidth($value)); + $this->assertInstanceOf(AbstractShape::class, $object->setWidth($value)); $this->assertEquals($value, $object->getWidth()); } @@ -144,13 +145,13 @@ public function testWidthAndHeight(): void $object = new RichText(); $value = mt_rand(1, 100); - $this->assertInstanceOf('PhpOffice\\PhpPresentation\\AbstractShape', $object->setWidthAndHeight()); + $this->assertInstanceOf(AbstractShape::class, $object->setWidthAndHeight()); $this->assertEquals(0, $object->getWidth()); $this->assertEquals(0, $object->getHeight()); - $this->assertInstanceOf('PhpOffice\\PhpPresentation\\AbstractShape', $object->setWidthAndHeight($value)); + $this->assertInstanceOf(AbstractShape::class, $object->setWidthAndHeight($value)); $this->assertEquals($value, $object->getWidth()); $this->assertEquals(0, $object->getHeight()); - $this->assertInstanceOf('PhpOffice\\PhpPresentation\\AbstractShape', $object->setWidthAndHeight($value, $value)); + $this->assertInstanceOf(AbstractShape::class, $object->setWidthAndHeight($value, $value)); $this->assertEquals($value, $object->getWidth()); $this->assertEquals($value, $object->getHeight()); } @@ -161,20 +162,20 @@ public function testPlaceholder(): void $this->assertFalse($object->isPlaceholder(), 'Standard Shape should not be a placeholder object'); $this->assertNull($object->getPlaceholder()); $this->assertInstanceOf( - 'PhpOffice\\PhpPresentation\\AbstractShape', + AbstractShape::class, $object->setPlaceHolder(new Placeholder(Placeholder::PH_TYPE_TITLE)) ); $this->assertTrue($object->isPlaceholder()); - $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\Placeholder', $object->getPlaceholder()); + $this->assertInstanceOf(Placeholder::class, $object->getPlaceholder()); $this->assertEquals('title', $object->getPlaceholder()->getType()); $object = new RichText(); $this->assertFalse($object->isPlaceholder(), 'Standard Shape should not be a placeholder object'); $placeholder = new Placeholder(Placeholder::PH_TYPE_TITLE); $placeholder->setType(Placeholder::PH_TYPE_SUBTITLE); - $this->assertInstanceOf('PhpOffice\\PhpPresentation\\AbstractShape', $object->setPlaceHolder($placeholder)); + $this->assertInstanceOf(AbstractShape::class, $object->setPlaceHolder($placeholder)); $this->assertTrue($object->isPlaceholder()); - $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\Placeholder', $object->getPlaceholder()); + $this->assertInstanceOf(Placeholder::class, $object->getPlaceholder()); $this->assertEquals('subTitle', $object->getPlaceholder()->getType()); } @@ -187,9 +188,9 @@ public function testContainer(): void $oSlide->addShape($object2); $this->assertNull($object->getContainer()); - $this->assertInstanceOf('PhpOffice\\PhpPresentation\\AbstractShape', $object->setContainer($oSlide)); - $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Slide', $object->getContainer()); - $this->assertInstanceOf('PhpOffice\\PhpPresentation\\AbstractShape', $object->setContainer(null, true)); + $this->assertInstanceOf(AbstractShape::class, $object->setContainer($oSlide)); + $this->assertInstanceOf(Slide::class, $object->getContainer()); + $this->assertInstanceOf(AbstractShape::class, $object->setContainer(null, true)); $this->assertNull($object->getContainer()); } @@ -199,8 +200,8 @@ public function testContainerException(): void $oSlide = new Slide(); $this->assertNull($object->getContainer()); - $this->assertInstanceOf('PhpOffice\\PhpPresentation\\AbstractShape', $object->setContainer($oSlide)); - $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Slide', $object->getContainer()); + $this->assertInstanceOf(AbstractShape::class, $object->setContainer($oSlide)); + $this->assertInstanceOf(Slide::class, $object->getContainer()); $this->expectException(\Exception::class); $this->expectExceptionMessage('A PhpOffice\PhpPresentation\ShapeContainerInterface has already been assigned. Shapes can only exist on one PhpOffice\PhpPresentation\ShapeContainerInterface.'); $object->setContainer(null); diff --git a/tests/PhpPresentation/Tests/Reader/ODPresentationTest.php b/tests/PhpPresentation/Tests/Reader/ODPresentationTest.php index f3b844689..02eadf4d5 100644 --- a/tests/PhpPresentation/Tests/Reader/ODPresentationTest.php +++ b/tests/PhpPresentation/Tests/Reader/ODPresentationTest.php @@ -22,6 +22,7 @@ use PhpOffice\PhpPresentation\Reader\ODPresentation; use PhpOffice\PhpPresentation\Shape\Drawing\Gd; use PhpOffice\PhpPresentation\Shape\RichText; +use PhpOffice\PhpPresentation\Shape\RichText\Paragraph; use PhpOffice\PhpPresentation\Style\Alignment; use PhpOffice\PhpPresentation\Style\Bullet; use PhpOffice\PhpPresentation\Style\Font; @@ -124,11 +125,16 @@ public function testLoadFile01(): void $this->assertEquals(600, $oShape->getWidth()); $this->assertEquals(10, $oShape->getOffsetX()); $this->assertEquals(400, $oShape->getOffsetY()); - $this->assertEquals(Alignment::HORIZONTAL_LEFT, $oShape->getActiveParagraph()->getAlignment()->getHorizontal()); - $this->assertFalse($oShape->getActiveParagraph()->getAlignment()->isRTL()); $arrayParagraphs = $oShape->getParagraphs(); $this->assertCount(1, $arrayParagraphs); $oParagraph = $arrayParagraphs[0]; + $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\RichText\\Paragraph', $oParagraph); + $this->assertEquals(Alignment::HORIZONTAL_LEFT, $oParagraph->getAlignment()->getHorizontal()); + $this->assertFalse($oParagraph->getAlignment()->isRTL()); + $this->assertEquals(0, $oParagraph->getSpacingAfter()); + $this->assertEquals(0, $oParagraph->getSpacingBefore()); + $this->assertEquals(Paragraph::LINE_SPACING_MODE_PERCENT, $oParagraph->getLineSpacingMode()); + $this->assertEquals(100, $oParagraph->getLineSpacing()); $arrayRichText = $oParagraph->getRichTextElements(); $this->assertCount(3, $arrayRichText); // Slide 1 : Shape 2 : Paragraph 1 @@ -290,11 +296,15 @@ public function testLoadFile01(): void $this->assertEquals(930, $oShape->getWidth()); $this->assertEquals(10, $oShape->getOffsetX()); $this->assertEquals(50, $oShape->getOffsetY()); - $this->assertEquals(Alignment::HORIZONTAL_LEFT, $oShape->getActiveParagraph()->getAlignment()->getHorizontal()); - $this->assertFalse($oShape->getActiveParagraph()->getAlignment()->isRTL()); $arrayParagraphs = $oShape->getParagraphs(); $this->assertCount(1, $arrayParagraphs); $oParagraph = $arrayParagraphs[0]; + $this->assertEquals(Alignment::HORIZONTAL_LEFT, $oParagraph->getAlignment()->getHorizontal()); + $this->assertFalse($oParagraph->getAlignment()->isRTL()); + $this->assertEquals(0, $oParagraph->getSpacingAfter()); + $this->assertEquals(0, $oParagraph->getSpacingBefore()); + $this->assertEquals(Paragraph::LINE_SPACING_MODE_PERCENT, $oParagraph->getLineSpacingMode()); + $this->assertEquals(100, $oParagraph->getLineSpacing()); $arrayRichText = $oParagraph->getRichTextElements(); $this->assertCount(1, $arrayRichText); // Slide 3 : Shape 2 : Paragraph 1 @@ -477,11 +487,15 @@ public function testLoadFile01(): void $this->assertEquals(930, $oShape->getWidth()); $this->assertEquals(10, $oShape->getOffsetX()); $this->assertEquals(50, $oShape->getOffsetY()); - $this->assertEquals(Alignment::HORIZONTAL_LEFT, $oShape->getActiveParagraph()->getAlignment()->getHorizontal()); - $this->assertFalse($oShape->getActiveParagraph()->getAlignment()->isRTL()); $arrayParagraphs = $oShape->getParagraphs(); $this->assertCount(1, $arrayParagraphs); $oParagraph = $arrayParagraphs[0]; + $this->assertEquals(Alignment::HORIZONTAL_LEFT, $oParagraph->getAlignment()->getHorizontal()); + $this->assertFalse($oParagraph->getAlignment()->isRTL()); + $this->assertEquals(0, $oParagraph->getSpacingAfter()); + $this->assertEquals(0, $oParagraph->getSpacingBefore()); + $this->assertEquals(Paragraph::LINE_SPACING_MODE_PERCENT, $oParagraph->getLineSpacingMode()); + $this->assertEquals(100, $oParagraph->getLineSpacing()); $arrayRichText = $oParagraph->getRichTextElements(); $this->assertCount(1, $arrayRichText); // Slide 4 : Shape 2 : Paragraph 1 @@ -501,11 +515,15 @@ public function testLoadFile01(): void $this->assertEquals(930, $oShape->getWidth()); $this->assertEquals(10, $oShape->getOffsetX()); $this->assertEquals(130, $oShape->getOffsetY()); - $this->assertEquals(Alignment::HORIZONTAL_LEFT, $oShape->getActiveParagraph()->getAlignment()->getHorizontal()); - $this->assertFalse($oShape->getActiveParagraph()->getAlignment()->isRTL()); $arrayParagraphs = $oShape->getParagraphs(); $this->assertCount(1, $arrayParagraphs); $oParagraph = $arrayParagraphs[0]; + $this->assertEquals(Alignment::HORIZONTAL_LEFT, $oParagraph->getAlignment()->getHorizontal()); + $this->assertFalse($oParagraph->getAlignment()->isRTL()); + $this->assertEquals(0, $oParagraph->getSpacingAfter()); + $this->assertEquals(0, $oParagraph->getSpacingBefore()); + $this->assertEquals(Paragraph::LINE_SPACING_MODE_PERCENT, $oParagraph->getLineSpacingMode()); + $this->assertEquals(100, $oParagraph->getLineSpacing()); $arrayRichText = $oParagraph->getRichTextElements(); $this->assertCount(3, $arrayRichText); // Slide 4 : Shape 3 : Paragraph 1 diff --git a/tests/PhpPresentation/Tests/Reader/PowerPoint2007Test.php b/tests/PhpPresentation/Tests/Reader/PowerPoint2007Test.php index 98fb65ac4..2d2aa1f3a 100644 --- a/tests/PhpPresentation/Tests/Reader/PowerPoint2007Test.php +++ b/tests/PhpPresentation/Tests/Reader/PowerPoint2007Test.php @@ -23,6 +23,7 @@ use PhpOffice\PhpPresentation\Reader\PowerPoint2007; use PhpOffice\PhpPresentation\Shape\Drawing\Gd; use PhpOffice\PhpPresentation\Shape\RichText; +use PhpOffice\PhpPresentation\Shape\RichText\Paragraph; use PhpOffice\PhpPresentation\Style\Alignment; use PhpOffice\PhpPresentation\Style\Bullet; use PhpOffice\PhpPresentation\Style\Font; @@ -128,11 +129,15 @@ public function testLoadFile01(): void $this->assertEquals(600, $oShape->getWidth()); $this->assertEquals(10, $oShape->getOffsetX()); $this->assertEquals(400, $oShape->getOffsetY()); - $this->assertEquals(Alignment::HORIZONTAL_LEFT, $oShape->getActiveParagraph()->getAlignment()->getHorizontal()); - $this->assertFalse($oShape->getActiveParagraph()->getAlignment()->isRTL()); $arrayParagraphs = $oShape->getParagraphs(); $this->assertCount(1, $arrayParagraphs); $oParagraph = $arrayParagraphs[0]; + $this->assertEquals(Alignment::HORIZONTAL_LEFT, $oParagraph->getAlignment()->getHorizontal()); + $this->assertFalse($oParagraph->getAlignment()->isRTL()); + $this->assertEquals(0, $oParagraph->getSpacingAfter()); + $this->assertEquals(0, $oParagraph->getSpacingBefore()); + $this->assertEquals(Paragraph::LINE_SPACING_MODE_PERCENT, $oParagraph->getLineSpacingMode()); + $this->assertEquals(100, $oParagraph->getLineSpacing()); $arrayRichText = $oParagraph->getRichTextElements(); $this->assertCount(3, $arrayRichText); // Slide 1 : Shape 2 : Paragraph 1 @@ -296,11 +301,15 @@ public function testLoadFile01(): void $this->assertEquals(930, $oShape->getWidth()); $this->assertEquals(10, $oShape->getOffsetX()); $this->assertEquals(50, $oShape->getOffsetY()); - $this->assertEquals(Alignment::HORIZONTAL_LEFT, $oShape->getActiveParagraph()->getAlignment()->getHorizontal()); - $this->assertFalse($oShape->getActiveParagraph()->getAlignment()->isRTL()); $arrayParagraphs = $oShape->getParagraphs(); $this->assertCount(1, $arrayParagraphs); $oParagraph = $arrayParagraphs[0]; + $this->assertEquals(Alignment::HORIZONTAL_LEFT, $oParagraph->getAlignment()->getHorizontal()); + $this->assertFalse($oParagraph->getAlignment()->isRTL()); + $this->assertEquals(0, $oParagraph->getSpacingAfter()); + $this->assertEquals(0, $oParagraph->getSpacingBefore()); + $this->assertEquals(Paragraph::LINE_SPACING_MODE_PERCENT, $oParagraph->getLineSpacingMode()); + $this->assertEquals(100, $oParagraph->getLineSpacing()); $arrayRichText = $oParagraph->getRichTextElements(); $this->assertCount(1, $arrayRichText); // Slide 3 : Shape 2 : Paragraph 1 @@ -483,11 +492,15 @@ public function testLoadFile01(): void $this->assertEquals(930, $oShape->getWidth()); $this->assertEquals(10, $oShape->getOffsetX()); $this->assertEquals(50, $oShape->getOffsetY()); - $this->assertEquals(Alignment::HORIZONTAL_LEFT, $oShape->getActiveParagraph()->getAlignment()->getHorizontal()); - $this->assertFalse($oShape->getActiveParagraph()->getAlignment()->isRTL()); $arrayParagraphs = $oShape->getParagraphs(); $this->assertCount(1, $arrayParagraphs); $oParagraph = $arrayParagraphs[0]; + $this->assertEquals(Alignment::HORIZONTAL_LEFT, $oParagraph->getAlignment()->getHorizontal()); + $this->assertFalse($oParagraph->getAlignment()->isRTL()); + $this->assertEquals(0, $oParagraph->getSpacingAfter()); + $this->assertEquals(0, $oParagraph->getSpacingBefore()); + $this->assertEquals(Paragraph::LINE_SPACING_MODE_PERCENT, $oParagraph->getLineSpacingMode()); + $this->assertEquals(100, $oParagraph->getLineSpacing()); $arrayRichText = $oParagraph->getRichTextElements(); $this->assertCount(1, $arrayRichText); // Slide 4 : Shape 2 : Paragraph 1 @@ -496,7 +509,7 @@ public function testLoadFile01(): void $this->assertEquals('Need more info?', $oRichText->getText()); $this->assertTrue($oRichText->getFont()->isBold()); $this->assertEquals(48, $oRichText->getFont()->getSize()); - $this->assertEquals('FF000000', $oShape->getActiveParagraph()->getFont()->getColor()->getARGB()); + $this->assertEquals('FF000000', $oRichText->getFont()->getColor()->getARGB()); $this->assertEquals('Calibri', $oRichText->getFont()->getName()); $this->assertEquals(Font::FORMAT_LATIN, $oRichText->getFont()->getFormat()); // Slide 4 : Shape 3 @@ -507,11 +520,15 @@ public function testLoadFile01(): void $this->assertEquals(930, $oShape->getWidth()); $this->assertEquals(10, $oShape->getOffsetX()); $this->assertEquals(130, $oShape->getOffsetY()); - $this->assertEquals(Alignment::HORIZONTAL_LEFT, $oShape->getActiveParagraph()->getAlignment()->getHorizontal()); - $this->assertFalse($oShape->getActiveParagraph()->getAlignment()->isRTL()); $arrayParagraphs = $oShape->getParagraphs(); $this->assertCount(1, $arrayParagraphs); $oParagraph = $arrayParagraphs[0]; + $this->assertEquals(Alignment::HORIZONTAL_LEFT, $oParagraph->getAlignment()->getHorizontal()); + $this->assertFalse($oParagraph->getAlignment()->isRTL()); + $this->assertEquals(0, $oParagraph->getSpacingAfter()); + $this->assertEquals(0, $oParagraph->getSpacingBefore()); + $this->assertEquals(Paragraph::LINE_SPACING_MODE_PERCENT, $oParagraph->getLineSpacingMode()); + $this->assertEquals(100, $oParagraph->getLineSpacing()); $arrayRichText = $oParagraph->getRichTextElements(); $this->assertCount(3, $arrayRichText); // Slide 4 : Shape 3 : Paragraph 1 @@ -520,7 +537,7 @@ public function testLoadFile01(): void $this->assertEquals('Check the project site on GitHub:', $oRichText->getText()); $this->assertFalse($oRichText->getFont()->isBold()); $this->assertEquals(36, $oRichText->getFont()->getSize()); - $this->assertEquals('FF000000', $oShape->getActiveParagraph()->getFont()->getColor()->getARGB()); + $this->assertEquals('FF000000', $oRichText->getFont()->getColor()->getARGB()); $this->assertEquals('Calibri', $oRichText->getFont()->getName()); $this->assertEquals(Font::FORMAT_LATIN, $oRichText->getFont()->getFormat()); // Slide 4 : Shape 3 : Paragraph 2 @@ -533,7 +550,7 @@ public function testLoadFile01(): void $this->assertEquals('https://github.com/PHPOffice/PHPPresentation/', $oRichText->getText()); $this->assertFalse($oRichText->getFont()->isBold()); $this->assertEquals(32, $oRichText->getFont()->getSize()); - $this->assertEquals('FF000000', $oShape->getActiveParagraph()->getFont()->getColor()->getARGB()); + $this->assertEquals('FF000000', $oRichText->getFont()->getColor()->getARGB()); $this->assertTrue($oRichText->hasHyperlink()); $this->assertEquals('https://github.com/PHPOffice/PHPPresentation/', $oRichText->getHyperlink()->getUrl()); $this->assertEquals('PHPPresentation', $oRichText->getHyperlink()->getTooltip()); diff --git a/tests/PhpPresentation/Tests/Shape/RichText/ParagraphTest.php b/tests/PhpPresentation/Tests/Shape/RichText/ParagraphTest.php index a8de2db35..292cf2a95 100644 --- a/tests/PhpPresentation/Tests/Shape/RichText/ParagraphTest.php +++ b/tests/PhpPresentation/Tests/Shape/RichText/ParagraphTest.php @@ -39,16 +39,16 @@ public function testConstruct(): void { $object = new Paragraph(); $this->assertEmpty($object->getRichTextElements()); - $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Style\\Alignment', $object->getAlignment()); - $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Style\\Font', $object->getFont()); - $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Style\\Bullet', $object->getBulletStyle()); + $this->assertInstanceOf(Alignment::class, $object->getAlignment()); + $this->assertInstanceOf(Font::class, $object->getFont()); + $this->assertInstanceOf(Bullet::class, $object->getBulletStyle()); } public function testAlignment(): void { $object = new Paragraph(); - $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Style\\Alignment', $object->getAlignment()); - $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\RichText\\Paragraph', $object->setAlignment(new Alignment())); + $this->assertInstanceOf(Alignment::class, $object->getAlignment()); + $this->assertInstanceOf(Paragraph::class, $object->setAlignment(new Alignment())); } /** @@ -57,11 +57,11 @@ public function testAlignment(): void public function testBulletStyle(): void { $object = new Paragraph(); - $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Style\\Bullet', $object->getBulletStyle()); - $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\RichText\\Paragraph', $object->setBulletStyle()); + $this->assertInstanceOf(Bullet::class, $object->getBulletStyle()); + $this->assertInstanceOf(Paragraph::class, $object->setBulletStyle()); $this->assertNull($object->getBulletStyle()); - $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\RichText\\Paragraph', $object->setBulletStyle(new Bullet())); - $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Style\\Bullet', $object->getBulletStyle()); + $this->assertInstanceOf(Paragraph::class, $object->setBulletStyle(new Bullet())); + $this->assertInstanceOf(Bullet::class, $object->getBulletStyle()); } /** @@ -70,11 +70,11 @@ public function testBulletStyle(): void public function testFont(): void { $object = new Paragraph(); - $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Style\\Font', $object->getFont()); - $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\RichText\\Paragraph', $object->setFont()); + $this->assertInstanceOf(Font::class, $object->getFont()); + $this->assertInstanceOf(Paragraph::class, $object->setFont()); $this->assertNull($object->getFont()); - $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\RichText\\Paragraph', $object->setFont(new Font())); - $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Style\\Font', $object->getFont()); + $this->assertInstanceOf(Paragraph::class, $object->setFont(new Font())); + $this->assertInstanceOf(Font::class, $object->getFont()); } /** @@ -107,10 +107,25 @@ public function testLineSpacing(): void $object = new Paragraph(); $valueExpected = mt_rand(1, 100); $this->assertEquals(100, $object->getLineSpacing()); - $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\RichText\\Paragraph', $object->setLineSpacing($valueExpected)); + $this->assertInstanceOf(Paragraph::class, $object->setLineSpacing($valueExpected)); $this->assertEquals($valueExpected, $object->getLineSpacing()); } + /** + * Test text methods. + */ + public function testLineSpacingMode(): void + { + $object = new Paragraph(); + $this->assertEquals(Paragraph::LINE_SPACING_MODE_PERCENT, $object->getLineSpacingMode()); + $this->assertInstanceOf(Paragraph::class, $object->setLineSpacingMode(Paragraph::LINE_SPACING_MODE_POINT)); + $this->assertEquals(Paragraph::LINE_SPACING_MODE_POINT, $object->getLineSpacingMode()); + $this->assertInstanceOf(Paragraph::class, $object->setLineSpacingMode(Paragraph::LINE_SPACING_MODE_PERCENT)); + $this->assertEquals(Paragraph::LINE_SPACING_MODE_PERCENT, $object->getLineSpacingMode()); + $this->assertInstanceOf(Paragraph::class, $object->setLineSpacingMode('Unauthorized')); + $this->assertEquals(Paragraph::LINE_SPACING_MODE_PERCENT, $object->getLineSpacingMode()); + } + /** * Test get/set richTextElements. */ @@ -127,21 +142,37 @@ public function testRichTextElements(): void new TextElement(), new TextElement(), ]; - $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\RichText\\Paragraph', $object->setRichTextElements($array)); + $this->assertInstanceOf(Paragraph::class, $object->setRichTextElements($array)); $this->assertCount(3, $object->getRichTextElements()); } + public function testSpacingAfter(): void + { + $object = new Paragraph(); + $this->assertEquals(0, $object->getSpacingAfter()); + $this->assertInstanceOf(Paragraph::class, $object->setSpacingAfter(1)); + $this->assertEquals(1, $object->getSpacingAfter()); + } + + public function testSpacingBefore(): void + { + $object = new Paragraph(); + $this->assertEquals(0, $object->getSpacingBefore()); + $this->assertInstanceOf(Paragraph::class, $object->setSpacingBefore(1)); + $this->assertEquals(1, $object->getSpacingBefore()); + } + /** * Test text methods. */ public function testText(): void { $object = new Paragraph(); - $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\RichText\\Paragraph', $object->addText(new TextElement())); + $this->assertInstanceOf(Paragraph::class, $object->addText(new TextElement())); $this->assertCount(1, $object->getRichTextElements()); - $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\RichText\\TextElement', $object->createText()); + $this->assertInstanceOf(TextElement::class, $object->createText()); $this->assertCount(2, $object->getRichTextElements()); - $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\RichText\\TextElement', $object->createText('AAA')); + $this->assertInstanceOf(TextElement::class, $object->createText('AAA')); $this->assertCount(3, $object->getRichTextElements()); $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\RichText\\BreakElement', $object->createBreak()); $this->assertCount(4, $object->getRichTextElements()); diff --git a/tests/PhpPresentation/Tests/Shape/RichTextTest.php b/tests/PhpPresentation/Tests/Shape/RichTextTest.php index a1ca866e5..88936c78c 100644 --- a/tests/PhpPresentation/Tests/Shape/RichTextTest.php +++ b/tests/PhpPresentation/Tests/Shape/RichTextTest.php @@ -41,15 +41,15 @@ public function testActiveParagraph(): void { $object = new RichText(); $this->assertEquals(0, $object->getActiveParagraphIndex()); - $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\RichText\\Paragraph', $object->createParagraph()); + $this->assertInstanceOf(Paragraph::class, $object->createParagraph()); $this->assertCount(2, $object->getParagraphs()); $value = mt_rand(0, 1); - $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\RichText\\Paragraph', $object->setActiveParagraph($value)); + $this->assertInstanceOf(Paragraph::class, $object->setActiveParagraph($value)); $this->assertEquals($value, $object->getActiveParagraphIndex()); - $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\RichText\\Paragraph', $object->getActiveParagraph()); - $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\RichText\\Paragraph', $object->getParagraph()); + $this->assertInstanceOf(Paragraph::class, $object->getActiveParagraph()); + $this->assertInstanceOf(Paragraph::class, $object->getParagraph()); $value = mt_rand(0, 1); - $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\RichText\\Paragraph', $object->getParagraph($value)); + $this->assertInstanceOf(Paragraph::class, $object->getParagraph($value)); } public function testActiveParagraphException(): void @@ -75,10 +75,22 @@ public function testColumns(): void $object = new RichText(); $value = mt_rand(1, 16); - $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\RichText', $object->setColumns($value)); + $this->assertInstanceOf(RichText::class, $object->setColumns($value)); $this->assertEquals($value, $object->getColumns()); } + public function testColumnSpacing(): void + { + $object = new RichText(); + + $this->assertEquals(0, $object->getColumnSpacing()); + $value = mt_rand(1, 16); + $this->assertInstanceOf(RichText::class, $object->setColumnSpacing($value)); + $this->assertEquals($value, $object->getColumnSpacing()); + $this->assertInstanceOf(RichText::class, $object->setColumnSpacing(-1)); + $this->assertEquals($value, $object->getColumnSpacing()); + } + public function testColumnsException(): void { $this->expectException(\Exception::class); @@ -98,7 +110,7 @@ public function testParagraphs(): void new Paragraph(), ]; - $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\RichText', $object->setParagraphs($array)); + $this->assertInstanceOf(RichText::class, $object->setParagraphs($array)); $this->assertCount(3, $object->getParagraphs()); $this->assertEquals(2, $object->getActiveParagraphIndex()); } @@ -106,9 +118,9 @@ public function testParagraphs(): void public function testText(): void { $object = new RichText(); - $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\RichText', $object->addText()); + $this->assertInstanceOf(RichText::class, $object->addText()); $this->assertCount(1, $object->getActiveParagraph()->getRichTextElements()); - $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\RichText', $object->addText(new TextElement())); + $this->assertInstanceOf(RichText::class, $object->addText(new TextElement())); $this->assertCount(2, $object->getActiveParagraph()->getRichTextElements()); $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\RichText\\TextElement', $object->createText()); $this->assertCount(3, $object->getActiveParagraph()->getRichTextElements()); @@ -128,10 +140,10 @@ public function testGetSetAutoFit(): void { $object = new RichText(); - $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\RichText', $object->setAutoFit()); + $this->assertInstanceOf(RichText::class, $object->setAutoFit()); $this->assertEquals(RichText::AUTOFIT_DEFAULT, $object->getAutoFit()); - $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\RichText', $object->setAutoFit(RichText::AUTOFIT_NORMAL)); + $this->assertInstanceOf(RichText::class, $object->setAutoFit(RichText::AUTOFIT_NORMAL)); $this->assertEquals(RichText::AUTOFIT_NORMAL, $object->getAutoFit()); } @@ -139,16 +151,16 @@ public function testGetSetHAutoShrink(): void { $object = new RichText(); - $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\RichText', $object->setAutoShrinkHorizontal()); + $this->assertInstanceOf(RichText::class, $object->setAutoShrinkHorizontal()); $this->assertNull($object->hasAutoShrinkHorizontal()); - $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\RichText', $object->setAutoShrinkHorizontal(null)); + $this->assertInstanceOf(RichText::class, $object->setAutoShrinkHorizontal(null)); $this->assertNull($object->hasAutoShrinkHorizontal()); - $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\RichText', $object->setAutoShrinkHorizontal(true)); + $this->assertInstanceOf(RichText::class, $object->setAutoShrinkHorizontal(true)); $this->assertTrue($object->hasAutoShrinkHorizontal()); - $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\RichText', $object->setAutoShrinkHorizontal(false)); + $this->assertInstanceOf(RichText::class, $object->setAutoShrinkHorizontal(false)); $this->assertFalse($object->hasAutoShrinkHorizontal()); } @@ -156,16 +168,16 @@ public function testGetSetVAutoShrink(): void { $object = new RichText(); - $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\RichText', $object->setAutoShrinkVertical()); + $this->assertInstanceOf(RichText::class, $object->setAutoShrinkVertical()); $this->assertNull($object->hasAutoShrinkVertical()); - $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\RichText', $object->setAutoShrinkVertical(null)); + $this->assertInstanceOf(RichText::class, $object->setAutoShrinkVertical(null)); $this->assertNull($object->hasAutoShrinkVertical()); - $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\RichText', $object->setAutoShrinkVertical(true)); + $this->assertInstanceOf(RichText::class, $object->setAutoShrinkVertical(true)); $this->assertTrue($object->hasAutoShrinkVertical()); - $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\RichText', $object->setAutoShrinkVertical(false)); + $this->assertInstanceOf(RichText::class, $object->setAutoShrinkVertical(false)); $this->assertFalse($object->hasAutoShrinkVertical()); } @@ -173,10 +185,10 @@ public function testGetSetHOverflow(): void { $object = new RichText(); - $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\RichText', $object->setHorizontalOverflow()); + $this->assertInstanceOf(RichText::class, $object->setHorizontalOverflow()); $this->assertEquals(RichText::OVERFLOW_OVERFLOW, $object->getHorizontalOverflow()); - $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\RichText', $object->setHorizontalOverflow(RichText::OVERFLOW_CLIP)); + $this->assertInstanceOf(RichText::class, $object->setHorizontalOverflow(RichText::OVERFLOW_CLIP)); $this->assertEquals(RichText::OVERFLOW_CLIP, $object->getHorizontalOverflow()); } @@ -185,24 +197,24 @@ public function testGetSetInset(): void $object = new RichText(); // Default - $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\RichText', $object->setInsetBottom()); + $this->assertInstanceOf(RichText::class, $object->setInsetBottom()); $this->assertEquals(4.8, $object->getInsetBottom()); - $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\RichText', $object->setInsetLeft()); + $this->assertInstanceOf(RichText::class, $object->setInsetLeft()); $this->assertEquals(9.6, $object->getInsetLeft()); - $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\RichText', $object->setInsetRight()); + $this->assertInstanceOf(RichText::class, $object->setInsetRight()); $this->assertEquals(9.6, $object->getInsetRight()); - $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\RichText', $object->setInsetTop()); + $this->assertInstanceOf(RichText::class, $object->setInsetTop()); $this->assertEquals(4.8, $object->getInsetTop()); // Value $value = mt_rand(1, 100); - $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\RichText', $object->setInsetBottom($value)); + $this->assertInstanceOf(RichText::class, $object->setInsetBottom($value)); $this->assertEquals($value, $object->getInsetBottom()); - $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\RichText', $object->setInsetLeft($value)); + $this->assertInstanceOf(RichText::class, $object->setInsetLeft($value)); $this->assertEquals($value, $object->getInsetLeft()); - $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\RichText', $object->setInsetRight($value)); + $this->assertInstanceOf(RichText::class, $object->setInsetRight($value)); $this->assertEquals($value, $object->getInsetRight()); - $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\RichText', $object->setInsetTop($value)); + $this->assertInstanceOf(RichText::class, $object->setInsetTop($value)); $this->assertEquals($value, $object->getInsetTop()); } @@ -210,13 +222,13 @@ public function testGetSetUpright(): void { $object = new RichText(); - $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\RichText', $object->setUpright()); + $this->assertInstanceOf(RichText::class, $object->setUpright()); $this->assertFalse($object->isUpright()); - $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\RichText', $object->setUpright(true)); + $this->assertInstanceOf(RichText::class, $object->setUpright(true)); $this->assertTrue($object->isUpright()); - $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\RichText', $object->setUpright(false)); + $this->assertInstanceOf(RichText::class, $object->setUpright(false)); $this->assertFalse($object->isUpright()); } @@ -224,13 +236,13 @@ public function testGetSetVertical(): void { $object = new RichText(); - $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\RichText', $object->setVertical()); + $this->assertInstanceOf(RichText::class, $object->setVertical()); $this->assertFalse($object->isVertical()); - $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\RichText', $object->setVertical(true)); + $this->assertInstanceOf(RichText::class, $object->setVertical(true)); $this->assertTrue($object->isVertical()); - $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\RichText', $object->setVertical(false)); + $this->assertInstanceOf(RichText::class, $object->setVertical(false)); $this->assertFalse($object->isVertical()); } @@ -238,10 +250,10 @@ public function testGetSetVOverflow(): void { $object = new RichText(); - $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\RichText', $object->setVerticalOverflow()); + $this->assertInstanceOf(RichText::class, $object->setVerticalOverflow()); $this->assertEquals(RichText::OVERFLOW_OVERFLOW, $object->getVerticalOverflow()); - $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\RichText', $object->setVerticalOverflow(RichText::OVERFLOW_CLIP)); + $this->assertInstanceOf(RichText::class, $object->setVerticalOverflow(RichText::OVERFLOW_CLIP)); $this->assertEquals(RichText::OVERFLOW_CLIP, $object->getVerticalOverflow()); } @@ -249,10 +261,10 @@ public function testGetSetWrap(): void { $object = new RichText(); - $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\RichText', $object->setWrap()); + $this->assertInstanceOf(RichText::class, $object->setWrap()); $this->assertEquals(RichText::WRAP_SQUARE, $object->getWrap()); - $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\RichText', $object->setWrap(RichText::WRAP_NONE)); + $this->assertInstanceOf(RichText::class, $object->setWrap(RichText::WRAP_NONE)); $this->assertEquals(RichText::WRAP_NONE, $object->getWrap()); } @@ -261,7 +273,7 @@ public function testHashCode(): void $object = new RichText(); $hash = $object->getActiveParagraph()->getHashCode(); - $hash .= RichText::WRAP_SQUARE . RichText::AUTOFIT_DEFAULT . RichText::OVERFLOW_OVERFLOW . RichText::OVERFLOW_OVERFLOW . '0014.89.69.64.8'; + $hash .= RichText::WRAP_SQUARE . RichText::AUTOFIT_DEFAULT . RichText::OVERFLOW_OVERFLOW . RichText::OVERFLOW_OVERFLOW . '00104.89.69.64.8'; $hash .= md5('00000' . $object->getFill()->getHashCode() . $object->getShadow()->getHashCode() . '' . get_parent_class($object)); $hash .= get_class($object); $this->assertEquals(md5($hash), $object->getHashCode()); diff --git a/tests/PhpPresentation/Tests/Writer/ODPresentation/ContentTest.php b/tests/PhpPresentation/Tests/Writer/ODPresentation/ContentTest.php index 198b16f5c..c6271c073 100644 --- a/tests/PhpPresentation/Tests/Writer/ODPresentation/ContentTest.php +++ b/tests/PhpPresentation/Tests/Writer/ODPresentation/ContentTest.php @@ -8,6 +8,7 @@ use PhpOffice\PhpPresentation\PresentationProperties; use PhpOffice\PhpPresentation\Shape\Comment; use PhpOffice\PhpPresentation\Shape\Media; +use PhpOffice\PhpPresentation\Shape\RichText\Paragraph; use PhpOffice\PhpPresentation\Shape\RichText\Run; use PhpOffice\PhpPresentation\Slide\Transition; use PhpOffice\PhpPresentation\Style\Alignment; @@ -274,6 +275,47 @@ public function testNote(): void $this->assertIsSchemaOpenDocumentValid('1.2'); } + public function testParagraphLineSpacing(): void + { + $richText = $this->oPresentation->getActiveSlide()->createRichTextShape(); + $richText->getActiveParagraph()->setLineSpacingMode(Paragraph::LINE_SPACING_MODE_PERCENT); + $richText->getActiveParagraph()->setLineSpacing(200); + + $element = '/office:document-content/office:automatic-styles/style:style[@style:name=\'P_' . $richText->getActiveParagraph()->getHashCode() . '\']/style:paragraph-properties'; + $this->assertZipXmlAttributeExists('content.xml', $element, 'fo:line-height'); + $this->assertZipXmlAttributeEquals('content.xml', $element, 'fo:line-height', '200%'); + $this->assertIsSchemaOpenDocumentValid('1.2'); + + $richText->getActiveParagraph()->setLineSpacingMode(Paragraph::LINE_SPACING_MODE_POINT); + $this->resetPresentationFile(); + + $this->assertZipXmlAttributeExists('content.xml', $element, 'fo:line-height'); + $this->assertZipXmlAttributeEquals('content.xml', $element, 'fo:line-height', '200pt'); + $this->assertIsSchemaOpenDocumentValid('1.2'); + } + + public function testParagraphSpacingBefore(): void + { + $richText = $this->oPresentation->getActiveSlide()->createRichTextShape(); + $richText->getActiveParagraph()->setSpacingBefore(123); + + $element = '/office:document-content/office:automatic-styles/style:style[@style:name=\'P_' . $richText->getActiveParagraph()->getHashCode() . '\']/style:paragraph-properties'; + $this->assertZipXmlAttributeExists('content.xml', $element, 'fo:margin-top'); + $this->assertZipXmlAttributeEquals('content.xml', $element, 'fo:margin-top', '4.339cm'); + $this->assertIsSchemaOpenDocumentValid('1.2'); + } + + public function testParagraphSpacingAfter(): void + { + $richText = $this->oPresentation->getActiveSlide()->createRichTextShape(); + $richText->getActiveParagraph()->setSpacingAfter(123); + + $element = '/office:document-content/office:automatic-styles/style:style[@style:name=\'P_' . $richText->getActiveParagraph()->getHashCode() . '\']/style:paragraph-properties'; + $this->assertZipXmlAttributeExists('content.xml', $element, 'fo:margin-bottom'); + $this->assertZipXmlAttributeEquals('content.xml', $element, 'fo:margin-bottom', '4.339cm'); + $this->assertIsSchemaOpenDocumentValid('1.2'); + } + public function testRichTextAutoShrink(): void { $oRichText1 = $this->oPresentation->getActiveSlide()->createRichTextShape(); diff --git a/tests/PhpPresentation/Tests/Writer/PowerPoint2007/PptChartsTest.php b/tests/PhpPresentation/Tests/Writer/PowerPoint2007/PptChartsTest.php index 8dbac33ba..069493fbb 100644 --- a/tests/PhpPresentation/Tests/Writer/PowerPoint2007/PptChartsTest.php +++ b/tests/PhpPresentation/Tests/Writer/PowerPoint2007/PptChartsTest.php @@ -272,7 +272,7 @@ public function testAxisOutline(): void $this->assertZipXmlElementExists('ppt/charts/' . $oShape->getIndexedFilename(), $element); $element = '/c:chartSpace/c:chart/c:plotArea/c:catAx/c:spPr/a:ln'; $this->assertZipXmlElementExists('ppt/charts/' . $oShape->getIndexedFilename(), $element); - $this->assertZipXmlAttributeEquals('ppt/charts/' . $oShape->getIndexedFilename(), $element, 'w', Drawing::pixelsToEmu(Drawing::pointsToPixels($expectedWidthX))); + $this->assertZipXmlAttributeEquals('ppt/charts/' . $oShape->getIndexedFilename(), $element, 'w', Drawing::pointsToEmu($expectedWidthX)); $element = '/c:chartSpace/c:chart/c:plotArea/c:catAx/c:spPr/a:ln/a:solidFill/a:srgbClr'; $this->assertZipXmlElementExists('ppt/charts/' . $oShape->getIndexedFilename(), $element); $this->assertZipXmlAttributeEquals('ppt/charts/' . $oShape->getIndexedFilename(), $element, 'val', $expectedColorX); @@ -280,7 +280,7 @@ public function testAxisOutline(): void $this->assertZipXmlElementExists('ppt/charts/' . $oShape->getIndexedFilename(), $element); $element = '/c:chartSpace/c:chart/c:plotArea/c:valAx/c:spPr/a:ln'; $this->assertZipXmlElementExists('ppt/charts/' . $oShape->getIndexedFilename(), $element); - $this->assertZipXmlAttributeEquals('ppt/charts/' . $oShape->getIndexedFilename(), $element, 'w', Drawing::pixelsToEmu(Drawing::pointsToPixels($expectedWidthY))); + $this->assertZipXmlAttributeEquals('ppt/charts/' . $oShape->getIndexedFilename(), $element, 'w', Drawing::pointsToEmu($expectedWidthY)); $element = '/c:chartSpace/c:chart/c:plotArea/c:valAx/c:spPr/a:ln/a:solidFill/a:srgbClr'; $this->assertZipXmlElementExists('ppt/charts/' . $oShape->getIndexedFilename(), $element); $this->assertZipXmlAttributeEquals('ppt/charts/' . $oShape->getIndexedFilename(), $element, 'val', $expectedColorY); @@ -799,7 +799,7 @@ public function testTypeLineGridlines(): void $expectedColor = new Color(Color::COLOR_BLUE); foreach ($arrayTests as $arrayTest) { $expectedSizePts = mt_rand(1, 100); - $expectedSizeEmu = round(Drawing::pointsToPixels(Drawing::pixelsToEmu($expectedSizePts))); + $expectedSizeEmu = Drawing::pointsToEmu($expectedSizePts); $this->oPresentation->removeSlideByIndex()->createSlide(); $oShape = $this->oPresentation->getActiveSlide()->createChartShape(); @@ -926,7 +926,7 @@ public function testTypeLineMarkerFill(): void public function testTypeLineSeriesOutline(): void { $expectedWidth = mt_rand(1, 100); - $expectedWidthEmu = Drawing::pixelsToEmu(Drawing::pointsToPixels($expectedWidth)); + $expectedWidthEmu = Drawing::pointsToEmu($expectedWidth); $expectedElement = '/c:chartSpace/c:chart/c:plotArea/c:lineChart/c:ser/c:spPr/a:ln'; $oOutline = new Outline(); @@ -1310,7 +1310,7 @@ public function testTypeScatterSeparator(): void public function testTypeScatterSeriesOutline(): void { $expectedWidth = mt_rand(1, 100); - $expectedWidthEmu = Drawing::pixelsToEmu(Drawing::pointsToPixels($expectedWidth)); + $expectedWidthEmu = Drawing::pointsToEmu($expectedWidth); $expectedElement = '/c:chartSpace/c:chart/c:plotArea/c:scatterChart/c:ser/c:spPr/a:ln'; $oOutline = new Outline(); diff --git a/tests/PhpPresentation/Tests/Writer/PowerPoint2007/PptSlidesTest.php b/tests/PhpPresentation/Tests/Writer/PowerPoint2007/PptSlidesTest.php index c19e16c6c..4383d6463 100644 --- a/tests/PhpPresentation/Tests/Writer/PowerPoint2007/PptSlidesTest.php +++ b/tests/PhpPresentation/Tests/Writer/PowerPoint2007/PptSlidesTest.php @@ -7,6 +7,7 @@ use PhpOffice\PhpPresentation\Shape\Group; use PhpOffice\PhpPresentation\Shape\Media; use PhpOffice\PhpPresentation\Shape\RichText; +use PhpOffice\PhpPresentation\Shape\RichText\Paragraph; use PhpOffice\PhpPresentation\Slide\Animation; use PhpOffice\PhpPresentation\Slide\Transition; use PhpOffice\PhpPresentation\Style\Alignment; @@ -560,6 +561,87 @@ public function testNote(): void $this->assertIsSchemaECMA376Valid(); } + public function testParagraphColumns(): void + { + $richText = $this->oPresentation->getActiveSlide()->createRichTextShape(); + + $element = '/p:sld/p:cSld/p:spTree/p:sp/p:txBody/a:bodyPr'; + $this->assertZipXmlElementExists('ppt/slides/slide1.xml', $element); + $this->assertZipXmlAttributeNotExists('ppt/slides/slide1.xml', $element, 'numCol'); + $this->assertZipXmlAttributeNotExists('ppt/slides/slide1.xml', $element, 'spcCol'); + $this->assertIsSchemaECMA376Valid(); + + $this->resetPresentationFile(); + $richText + ->setColumns(2) + ->setColumnSpacing(123); + + $this->assertZipXmlElementExists('ppt/slides/slide1.xml', $element); + $this->assertZipXmlAttributeExists('ppt/slides/slide1.xml', $element, 'numCol'); + $this->assertZipXmlAttributeEquals('ppt/slides/slide1.xml', $element, 'numCol', '2'); + $this->assertZipXmlAttributeExists('ppt/slides/slide1.xml', $element, 'spcCol'); + $this->assertZipXmlAttributeEquals('ppt/slides/slide1.xml', $element, 'spcCol', '1171575'); + } + + public function testParagraphLineSpacing(): void + { + $expectedLineSpacing = mt_rand(1, 100); + + $oSlide = $this->oPresentation->getActiveSlide(); + $oRichText = $oSlide->createRichTextShape(); + $oRichText->getActiveParagraph() + ->setLineSpacingMode(Paragraph::LINE_SPACING_MODE_PERCENT) + ->setLineSpacing($expectedLineSpacing); + + $element = '/p:sld/p:cSld/p:spTree/p:sp/p:txBody/a:p/a:pPr/a:lnSpc/a:spcPct'; + $this->assertZipXmlElementExists('ppt/slides/slide1.xml', $element); + $this->assertZipXmlAttributeEquals('ppt/slides/slide1.xml', $element, 'val', $expectedLineSpacing * 1000); + $element = '/p:sld/p:cSld/p:spTree/p:sp/p:txBody/a:p/a:pPr/a:lnSpc/a:spcPts'; + $this->assertZipXmlElementNotExists('ppt/slides/slide1.xml', $element); + $this->assertIsSchemaECMA376Valid(); + + $this->resetPresentationFile(); + $oRichText->getActiveParagraph() + ->setLineSpacingMode(Paragraph::LINE_SPACING_MODE_POINT); + + $element = '/p:sld/p:cSld/p:spTree/p:sp/p:txBody/a:p/a:pPr/a:lnSpc/a:spcPct'; + $this->assertZipXmlElementNotExists('ppt/slides/slide1.xml', $element); + $element = '/p:sld/p:cSld/p:spTree/p:sp/p:txBody/a:p/a:pPr/a:lnSpc/a:spcPts'; + $this->assertZipXmlElementExists('ppt/slides/slide1.xml', $element); + $this->assertZipXmlAttributeEquals('ppt/slides/slide1.xml', $element, 'val', $expectedLineSpacing * 100); + $this->assertIsSchemaECMA376Valid(); + } + + public function testParagraphSpacingAfter(): void + { + $expectedVal = mt_rand(1, 100); + + $oSlide = $this->oPresentation->getActiveSlide(); + $oRichText = $oSlide->createRichTextShape(); + $oRichText->getActiveParagraph() + ->setSpacingAfter($expectedVal); + + $element = '/p:sld/p:cSld/p:spTree/p:sp/p:txBody/a:p/a:pPr/a:spcAft/a:spcPts'; + $this->assertZipXmlElementExists('ppt/slides/slide1.xml', $element); + $this->assertZipXmlAttributeEquals('ppt/slides/slide1.xml', $element, 'val', $expectedVal * 100); + $this->assertIsSchemaECMA376Valid(); + } + + public function testParagraphSpacingBefore(): void + { + $expectedVal = mt_rand(1, 100); + + $oSlide = $this->oPresentation->getActiveSlide(); + $oRichText = $oSlide->createRichTextShape(); + $oRichText->getActiveParagraph() + ->setSpacingBefore($expectedVal); + + $element = '/p:sld/p:cSld/p:spTree/p:sp/p:txBody/a:p/a:pPr/a:spcBef/a:spcPts'; + $this->assertZipXmlElementExists('ppt/slides/slide1.xml', $element); + $this->assertZipXmlAttributeEquals('ppt/slides/slide1.xml', $element, 'val', $expectedVal * 100); + $this->assertIsSchemaECMA376Valid(); + } + public function testRichTextAutoFitNormal(): void { $expectedFontScale = 47.5; @@ -599,21 +681,6 @@ public function testRichTextHyperlink(): void $this->assertIsSchemaECMA376Valid(); } - public function testRichTextLineSpacing(): void - { - $expectedLineSpacing = mt_rand(1, 100); - - $oSlide = $this->oPresentation->getActiveSlide(); - $oRichText = $oSlide->createRichTextShape(); - $oRichText->createTextRun('AAA'); - $oRichText->getActiveParagraph()->setLineSpacing($expectedLineSpacing); - - $element = '/p:sld/p:cSld/p:spTree/p:sp/p:txBody/a:p/a:pPr/a:lnSpc/a:spcPct'; - $this->assertZipXmlElementExists('ppt/slides/slide1.xml', $element); - $this->assertZipXmlAttributeEquals('ppt/slides/slide1.xml', $element, 'val', $expectedLineSpacing * 1000); - $this->assertIsSchemaECMA376Valid(); - } - public function testRichTextRunFontFormat(): void { $latinElement = '/p:sld/p:cSld/p:spTree/p:sp/p:txBody/a:p/a:r/a:rPr/a:latin'; diff --git a/tests/PhpPresentation/Tests/_includes/PhpPresentationTestCase.php b/tests/PhpPresentation/Tests/_includes/PhpPresentationTestCase.php index 3d89f9e77..95d2d9968 100644 --- a/tests/PhpPresentation/Tests/_includes/PhpPresentationTestCase.php +++ b/tests/PhpPresentation/Tests/_includes/PhpPresentationTestCase.php @@ -236,7 +236,15 @@ public function assertZipXmlElementExists($filePath, $xPath): void { $this->writePresentationFile($this->oPresentation, $this->writerName); $nodeList = $this->getXmlNodeList($filePath, $xPath); - self::assertNotEquals(0, $nodeList->length); + self::assertNotEquals( + 0, + $nodeList->length, + sprintf( + 'The element "%s" doesn\'t exist in the file "%s"', + $xPath, + $filePath + ) + ); } /** @@ -251,7 +259,7 @@ public function assertZipXmlElementNotExists($filePath, $xPath): void 0, $nodeList->length, sprintf( - 'The element "%s" doesn\'t exist in the file "%s"', + 'The element "%s" exist in the file "%s"', $xPath, $filePath )