Skip to content

Commit 7f482f2

Browse files
committed
#35 : Fix Vertical Alignment for RichText Shapes in PowerPoint2007
1 parent b647374 commit 7f482f2

File tree

2 files changed

+52
-0
lines changed

2 files changed

+52
-0
lines changed

src/PhpPowerpoint/Writer/PowerPoint2007/Slide.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -419,6 +419,7 @@ private function writeShapeText(XMLWriter $objWriter, RichText $shape, $shapeId)
419419

420420
// a:bodyPr
421421
$objWriter->startElement('a:bodyPr');
422+
$objWriter->writeAttribute('anchor', $shape->getActiveParagraph()->getAlignment()->getVertical());
422423
$objWriter->writeAttribute('wrap', $shape->getWrap());
423424
$objWriter->writeAttribute('rtlCol', '0');
424425

tests/PhpPowerpoint/Tests/Writer/PowerPoint2007/SlideTest.php

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,57 @@ public function testConstructException()
5454
$oSlide->writeSlide();
5555
}
5656

57+
/**
58+
* @link https://github.com/PHPOffice/PHPPowerPoint/issues/35
59+
*/
60+
public function testAlignmentShapeBottom()
61+
{
62+
$phpPowerPoint = new PhpPowerpoint();
63+
$oSlide = $phpPowerPoint->getActiveSlide();
64+
$oShape = $oSlide->createRichTextShape()->setWidth(400)->setHeight(400)->setOffsetX(100)->setOffsetY(100);
65+
$oShape->createTextRun('this text should be vertically aligned');
66+
$oShape->getActiveParagraph()->getAlignment()->setVertical(Alignment::VERTICAL_BOTTOM);
67+
68+
$pres = TestHelperDOCX::getDocument($phpPowerPoint, 'PowerPoint2007');
69+
$element = '/p:sld/p:cSld/p:spTree/p:sp/p:txBody/a:bodyPr';
70+
$this->assertTrue($pres->elementExists($element, 'ppt/slides/slide1.xml'));
71+
$this->assertEquals(Alignment::VERTICAL_BOTTOM, $pres->getElementAttribute($element, 'anchor', 'ppt/slides/slide1.xml'));
72+
}
73+
74+
/**
75+
* @link https://github.com/PHPOffice/PHPPowerPoint/issues/35
76+
*/
77+
public function testAlignmentShapeCenter()
78+
{
79+
$phpPowerPoint = new PhpPowerpoint();
80+
$oSlide = $phpPowerPoint->getActiveSlide();
81+
$oShape = $oSlide->createRichTextShape()->setWidth(400)->setHeight(400)->setOffsetX(100)->setOffsetY(100);
82+
$oShape->createTextRun('this text should be vertically aligned');
83+
$oShape->getActiveParagraph()->getAlignment()->setVertical(Alignment::VERTICAL_CENTER);
84+
85+
$pres = TestHelperDOCX::getDocument($phpPowerPoint, 'PowerPoint2007');
86+
$element = '/p:sld/p:cSld/p:spTree/p:sp/p:txBody/a:bodyPr';
87+
$this->assertTrue($pres->elementExists($element, 'ppt/slides/slide1.xml'));
88+
$this->assertEquals(Alignment::VERTICAL_CENTER, $pres->getElementAttribute($element, 'anchor', 'ppt/slides/slide1.xml'));
89+
}
90+
91+
/**
92+
* @link https://github.com/PHPOffice/PHPPowerPoint/issues/35
93+
*/
94+
public function testAlignmentShapeTop()
95+
{
96+
$phpPowerPoint = new PhpPowerpoint();
97+
$oSlide = $phpPowerPoint->getActiveSlide();
98+
$oShape = $oSlide->createRichTextShape()->setWidth(400)->setHeight(400)->setOffsetX(100)->setOffsetY(100);
99+
$oShape->createTextRun('this text should be vertically aligned');
100+
$oShape->getActiveParagraph()->getAlignment()->setVertical(Alignment::VERTICAL_TOP);
101+
102+
$pres = TestHelperDOCX::getDocument($phpPowerPoint, 'PowerPoint2007');
103+
$element = '/p:sld/p:cSld/p:spTree/p:sp/p:txBody/a:bodyPr';
104+
$this->assertTrue($pres->elementExists($element, 'ppt/slides/slide1.xml'));
105+
$this->assertEquals(Alignment::VERTICAL_TOP, $pres->getElementAttribute($element, 'anchor', 'ppt/slides/slide1.xml'));
106+
}
107+
57108
public function testDrawingShapeBorder()
58109
{
59110
$phpPowerPoint = new PhpPowerpoint();

0 commit comments

Comments
 (0)