PHPPresentation icon indicating copy to clipboard operation
PHPPresentation copied to clipboard

Linespacing not working (not implemented)

Open tkeil69575 opened this issue 5 years ago • 1 comments

$shape->getActiveParagraph()->setLineSpacing(300); has no effect on the line spacing of a paragraph;

tkeil69575 avatar Dec 08 '19 15:12 tkeil69575

I managed to fix it (implement line spacing for both odp and pptx) by adding in

$objWriter->writeAttribute('fo:line-height', $item->getLineSpacing().'%');

to /src/PhpPresentation/Writer/ODPresentation/Content.php in the Switch statement (from line 201) for paragraph properties, e.g.,

switch ($item->getAlignment()->getHorizontal()) {
  case Alignment::HORIZONTAL_LEFT:
       $objWriter->writeAttribute('fo:text-align', 'left');
       $objWriter->writeAttribute('fo:line-height', $item->getLineSpacing().'%'); //added
       break;
  case Alignment::HORIZONTAL_RIGHT:
       $objWriter->writeAttribute('fo:text-align', 'right');
       $objWriter->writeAttribute('fo:line-height', $item->getLineSpacing().'%'); //added
       break;
  case Alignment::HORIZONTAL_CENTER:
       $objWriter->writeAttribute('fo:text-align', 'center');
       $objWriter->writeAttribute('fo:line-height', $item->getLineSpacing().'%'); //added
       break;
  case Alignment::HORIZONTAL_JUSTIFY:
       $objWriter->writeAttribute('fo:text-align', 'justify');
       $objWriter->writeAttribute('fo:line-height', $item->getLineSpacing().'%'); //added
       break;
  case Alignment::HORIZONTAL_DISTRIBUTED:
       $objWriter->writeAttribute('fo:text-align', 'justify');
       $objWriter->writeAttribute('fo:line-height', $item->getLineSpacing().'%'); /added
       break;
  default:
      $objWriter->writeAttribute('fo:text-align', 'left');
      $objWriter->writeAttribute('fo:line-height', $item->getLineSpacing().'%'); //added
      break;
}

and then for pptx, I changed line 526 in /src/PhpPresentation/Writer/PowerPoint2007/AbstractSlide.php to:

//$objWriter->writeAttribute('val', $paragraph->getLineSpacing() . "%");
$objWriter->writeAttribute('val', $paragraph->getLineSpacing()*1000);

Voila.

In the actual presentation script to change the line spacing for a paragraph, it needs to be called "after" the paragraph in question, e.g.,

$shape->createTextRun('the paragraph that should have increased line spacing'); $shape->getActiveParagraph()->setLineSpacing(150); // 150 = 1.5 x times normal line spacing

hope this helps someone.

tkeil69575 avatar Dec 10 '19 11:12 tkeil69575