Skip to content

Commit cdaa211

Browse files
devX2712Progi1984
authored andcommitted
ADD Vertical alignment for shape RichText
ADD Vertical alignment for RichText position top,middle and bottom position center or not center Reading from file, editing and saving
1 parent 9f3f686 commit cdaa211

File tree

3 files changed

+83
-1
lines changed

3 files changed

+83
-1
lines changed

src/PhpPresentation/Reader/PowerPoint2007.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -981,6 +981,12 @@ protected function loadShapeRichText(XMLReader $document, DOMElement $node, $oSl
981981
if (($bodyPr instanceof \DOMElement) && $bodyPr->hasAttribute('bIns')) {
982982
$oShape->setInsetBottom((int)$bodyPr->getAttribute('bIns'));
983983
}
984+
if (($bodyPr instanceof \DOMElement) && $bodyPr->hasAttribute('anchor')) {
985+
$oShape->setVerticalAlignment($bodyPr->getAttribute('anchor'));
986+
}
987+
if (($bodyPr instanceof \DOMElement) && $bodyPr->hasAttribute('anchorCtr')) {
988+
$oShape->setVerticalAlignCenter((int)$bodyPr->getAttribute('anchorCtr'));
989+
}
984990

985991
$arrayElements = $document->getElements('p:txBody/a:p', $node);
986992
foreach ($arrayElements as $oElement) {

src/PhpPresentation/Shape/RichText.php

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,15 @@ class RichText extends AbstractShape implements ComparableInterface
4343
/** Overflow */
4444
public const OVERFLOW_CLIP = 'clip';
4545
public const OVERFLOW_OVERFLOW = 'overflow';
46+
47+
/** Vertical alignment */
48+
const VALIGN_TOP = 't';
49+
const VALIGN_MIDDLE = 'ctr';
50+
const VALIGN_BOTTOM = 'b';
51+
52+
/** Vertical alignment center */
53+
const VALIGN_CENTER = 1;
54+
const VALIGN_NOTCENTER = 0;
4655

4756
/**
4857
* Rich text paragraphs.
@@ -169,6 +178,17 @@ class RichText extends AbstractShape implements ComparableInterface
169178
* @var null|float
170179
*/
171180
private $lnSpcReduction;
181+
182+
/**
183+
* Define vertical text position into shape (top,center,bottom)
184+
* @var string
185+
*/
186+
private $verticalAlign = self::VALIGN_TOP;
187+
/**
188+
* Define vertical text center position into shape (center,not center)
189+
* @var int
190+
*/
191+
private $verticalAlignCenter = self::VALIGN_NOTCENTER;
172192

173193
/**
174194
* Create a new \PhpOffice\PhpPresentation\Shape\RichText instance.
@@ -486,6 +506,59 @@ public function setVertical(bool $value = false): self
486506

487507
return $this;
488508
}
509+
510+
/**
511+
* Define the vertical alignment
512+
*
513+
* @param string|null $value top,center,bottom
514+
* @return $this
515+
* @see self::VALIGN_TOP, self::VALIGN_MIDLE, self::VALIGN_BOTTOM
516+
*/
517+
public function setVerticalAlignment(?string $value)
518+
{
519+
if (isset($value)) {
520+
$this->verticalAlign = $value;
521+
} else {
522+
$this->verticalAlign = self::VALIGN_TOP;
523+
}
524+
return $this;
525+
}
526+
527+
/**
528+
* Get the vertical alignment
529+
*
530+
* @return string
531+
* @see self::VALIGN_TOP, self::VALIGN_MIDLE, self::VALIGN_BOTTOM
532+
*/
533+
public function getVerticalAlignment():string
534+
{
535+
return $this->verticalAlign;
536+
}
537+
538+
/**
539+
* Define the vertical alignment if centered or not
540+
* @param int|null $value 1=center 0=not center
541+
* @return $this
542+
* @see self::VALIGN_CENTER, self::VALIGN_NOTCENTER
543+
*/
544+
public function setVerticalAlignCenter(?int $value)
545+
{
546+
if (isset($value)) {
547+
$this->verticalAlignCenter = $value;
548+
} else {
549+
$this->verticalAlignCenter = self::VALIGN_NOTCENTER;
550+
}
551+
return $this;
552+
}
553+
554+
/**
555+
* Get the vertical alignment center
556+
* @return int
557+
*/
558+
public function getVerticalAlignCenter():int
559+
{
560+
return $this->verticalAlignCenter;
561+
}
489562

490563
/**
491564
* Get columns.

src/PhpPresentation/Writer/PowerPoint2007/AbstractSlide.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,10 @@ protected function writeShapeText(XMLWriter $objWriter, RichText $shape, int $sh
262262
$objWriter->writeAttribute('lIns', CommonDrawing::pixelsToEmu($shape->getInsetLeft()));
263263
$objWriter->writeAttribute('rIns', CommonDrawing::pixelsToEmu($shape->getInsetRight()));
264264
$objWriter->writeAttribute('tIns', CommonDrawing::pixelsToEmu($shape->getInsetTop()));
265-
if (1 != $shape->getColumns()) {
265+
// Vertical alignment
266+
$objWriter->writeAttribute('anchor', $shape->getVerticalAlignment());
267+
$objWriter->writeAttribute('anchorCtr', (int)$shape->getVerticalAlignCenter());
268+
if ($shape->getColumns() <> 1) {
266269
$objWriter->writeAttribute('numCol', $shape->getColumns());
267270
$objWriter->writeAttribute('spcCol', CommonDrawing::pixelsToEmu($shape->getColumnSpacing()));
268271
}

0 commit comments

Comments
 (0)