Skip to content

Commit

Permalink
Added Line Spacing to RichText Paragraphs
Browse files Browse the repository at this point in the history
  • Loading branch information
Justin Hurlburt committed Mar 20, 2015
1 parent db1b18f commit 2caa93c
Show file tree
Hide file tree
Showing 3 changed files with 153 additions and 0 deletions.
33 changes: 33 additions & 0 deletions src/PhpPowerpoint/Shape/RichText/Paragraph.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
use PhpOffice\PhpPowerpoint\Style\Alignment;
use PhpOffice\PhpPowerpoint\Style\Bullet;
use PhpOffice\PhpPowerpoint\Style\Font;
use PhpOffice\PhpPowerpoint\Style\Spacing;

/**
* \PhpOffice\PhpPowerpoint\Shape\RichText\Paragraph
Expand Down Expand Up @@ -48,6 +49,13 @@ class Paragraph implements ComparableInterface
*/
private $font;

/**
* Spacing
*
* @var \PhpOffice\PhpPowerpoint\Style\Spacing
*/
private $spacing;

/**
* Bullet style
*
Expand All @@ -71,6 +79,7 @@ public function __construct()
$this->richTextElements = array();
$this->alignment = new Alignment();
$this->font = new Font();
$this->spacing = new Spacing();
$this->bulletStyle = new Bullet();
}

Expand Down Expand Up @@ -121,6 +130,30 @@ public function setFont(Font $pFont = null)
return $this;
}

/**
* Get spacing
*
* @return \PhpOffice\PhpPowerpoint\Style\Spacing
*/
public function getSpacing()
{
return $this->spacing;
}

/**
* Set spacing
*
* @param \PhpOffice\PhpPowerpoint\Style\Spacing $pFont Spacing
* @throws \Exception
* @return \PhpOffice\PhpPowerpoint\Shape\RichText\Paragraph
*/
public function setSpacing(Spacing $pSpacing = null)
{
$this->spacing = $pSpacing;

return $this;
}

/**
* Get bullet style
*
Expand Down
114 changes: 114 additions & 0 deletions src/PhpPowerpoint/Style/Spacing.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
<?php
/**
* This file is part of PHPPowerPoint - A pure PHP library for reading and writing
* presentations documents.
*
* PHPPowerPoint is free software distributed under the terms of the GNU Lesser
* General Public License version 3 as published by the Free Software Foundation.
*
* For the full copyright and license information, please read the LICENSE
* file that was distributed with this source code. For the full list of
* contributors, visit https://github.com/PHPOffice/PHPWord/contributors.
*
* @link https://github.com/PHPOffice/PHPPowerPoint
* @copyright 2009-2014 PHPPowerPoint contributors
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/

namespace PhpOffice\PhpPowerpoint\Style;

use PhpOffice\PhpPowerpoint\ComparableInterface;

/**
* \PhpOffice\PhpPowerpoint\Style\Spacing
*/
class Spacing implements ComparableInterface
{
/* Line Heights */
const HEIGHT_SINGLE = 100000;
const HEIGHT_SESQUISINGLE = 150000;
const HEIGHT_DOUBLE = 200000;

/**
* Line Height
*
* @var int
*/
private $lineHeight;

/**
* Hash index
*
* @var string
*/
private $hashIndex;

/**
* Create a new \PhpOffice\PhpPowerpoint\Style\Spacing
*/
public function __construct()
{
// Initialise values
$this->lineHeight = self::HEIGHT_SINGLE;
}

/**
* Get Spacing
*
* @return int
*/
public function getSpacing()
{
return $this->lineHeight;
}
/**
* Set Spacing
*
* @param int $pValue
* @return \PhpOffice\PhpPowerpoint\Style\Spacing
*/
public function setSpacing($pValue = self::HEIGHT_SINGLE)
{
if ( !is_numeric( $pValue ) ) {
$pValue = self::HEIGHT_SINGLE;
}
$this->lineHeight = $pValue;

return $this;
}
/**
* Get hash code
*
* @return string Hash code
*/
public function getHashCode()
{
return md5($this->lineHeight . __CLASS__);
}

/**
* Get hash index
*
* Note that this index may vary during script execution! Only reliable moment is
* while doing a write of a workbook and when changes are not allowed.
*
* @return string Hash index
*/
public function getHashIndex()
{
return $this->hashIndex;
}

/**
* Set hash index
*
* Note that this index may vary during script execution! Only reliable moment is
* while doing a write of a workbook and when changes are not allowed.
*
* @param string $value Hash index
*/
public function setHashIndex($value)
{
$this->hashIndex = $value;
}
}
6 changes: 6 additions & 0 deletions src/PhpPowerpoint/Writer/PowerPoint2007/Slide.php
Original file line number Diff line number Diff line change
Expand Up @@ -827,6 +827,12 @@ private function writeParagraphs(XMLWriter $objWriter, $paragraphs)
$objWriter->writeAttribute('indent', SharedDrawing::pixelsToEmu($paragraph->getAlignment()->getIndent()));
$objWriter->writeAttribute('lvl', $paragraph->getAlignment()->getLevel());

$objWriter->startElement('a:lnSpc');
$objWriter->startElement('a:spcPct');
$objWriter->writeAttribute('val', $paragraph->getSpacing()->getSpacing());
$objWriter->endElement();
$objWriter->endElement();

// Bullet type specified?
if ($paragraph->getBulletStyle()->getBulletType() != Bullet::TYPE_NONE) {
// a:buFont
Expand Down

0 comments on commit 2caa93c

Please sign in to comment.