This project is read-only.

Patch to fix text Vertical Alignment


Centering text vertically does not work for me. I'm using PHPPowerPoint version 0.1.0, 2009-04-27 with Office 2011 for Mac and I found the following code will allow text to be vertically centered on a PHPPowerPoint_Shape_RichText object. I don't know if it is needed or works on other version.

Writer/PowerPoint2007/Slide.php line 415:
if ($shape->getAlignment()->getVertical() == 'ctr') {
    $objWriter->writeAttribute('anchor', 'ctr');


TrevorBradley wrote Feb 21, 2013 at 10:25 PM

I can't seem to replicate this. I get an error if I attempt to place in this code at line 415 of Slide.php. Can you give more context? There's similar code around line 705:
                                            $horizontalAlign = $firstParagraph->getAlignment()->getVertical();
                                            if ($horizontalAlign != PHPPowerPoint_Style_Alignment::VERTICAL_BASE && $horizontalAlign != PHPPowerPoint_Style_Alignment::VERTICAL_AUTO)
                                                $objWriter->writeAttribute('anchor', $horizontalAlign);

TrevorBradley wrote Feb 21, 2013 at 10:42 PM

OK, I had to tweak this to get it working, and start messing with the guts of pptx XML to figure out what was going on, but I have a working patch too... Not sure how yours worked... $shape objects don't have alignments, their paragaraphs do.

Writer/PowerPoint2007/Slide.php close to line 478:
  $objWriter->writeAttribute('wrap', $shape->getWrap());
  if ($shape->getActiveParagraph()->getAlignment()->getVertical() == 'ctr') {
    $objWriter->writeAttribute('anchor', 'ctr');
  $objWriter->writeAttribute('wrap', $shape->getWrap());

kenrightintel wrote Feb 21, 2013 at 11:17 PM

Hmm. My file had only 521 lines. PHPPowerPoint version 0.1.0, 2009-04-27.

Here is the context (Writer/PowerPoint2007/Slide.php lines 408 through 428):
            // p:txBody
                // a:bodyPr
                $objWriter->writeAttribute('wrap', 'square');
                $objWriter->writeAttribute('rtlCol', '0');
                if ($shape->getAlignment()->getVertical() == 'ctr') { // <-- Added this line and the next 2
                    $objWriter->writeAttribute('anchor', 'ctr');
                    // a:spAutoFit
                    $objWriter->writeElement('a:spAutoFit', null);
                // a:lstStyle
                $objWriter->writeElement('a:lstStyle', null);
                // a:p

TrevorBradley wrote Feb 22, 2013 at 12:28 AM

Weird... maybe I have a dev version? (I don't even recall - I just picked up PHP Powerpoint again today after a good year haitus.)

It's easy enough to tweak if you can compare structures of slide1.xml in a test document. I even added letter spacing today. I wish we could contribute back though.

wrote Feb 22, 2013 at 12:34 AM