diff --git a/CHANGELOG.md b/CHANGELOG.md index a81b5e8d5..2ee7ea307 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,9 @@ ### Bugfix - PowerPoint2007 Writer : The presentation need repairs on Mac @jrking4 GH-266 GH-276 +### Features +- PowerPoint2007 Writer : Implement character spacing - @jvanoostrom GH-301 + ## 0.7.0 - 2016-09-12 ### Bugfix diff --git a/src/PhpPresentation/Style/Font.php b/src/PhpPresentation/Style/Font.php index 226ae3df2..966c7a90f 100644 --- a/src/PhpPresentation/Style/Font.php +++ b/src/PhpPresentation/Style/Font.php @@ -107,6 +107,13 @@ class Font implements ComparableInterface */ private $color; + /** + * Character Spacing + * + * @var int + */ + private $characterSpacing; + /** * Hash index * @@ -120,15 +127,16 @@ class Font implements ComparableInterface public function __construct() { // Initialise values - $this->name = 'Calibri'; - $this->size = 10; - $this->bold = false; - $this->italic = false; - $this->superScript = false; - $this->subScript = false; - $this->underline = self::UNDERLINE_NONE; - $this->strikethrough = false; - $this->color = new Color(Color::COLOR_BLACK); + $this->name = 'Calibri'; + $this->size = 10; + $this->characterSpacing = 0; + $this->bold = false; + $this->italic = false; + $this->superScript = false; + $this->subScript = false; + $this->underline = self::UNDERLINE_NONE; + $this->strikethrough = false; + $this->color = new Color(Color::COLOR_BLACK); } /** @@ -156,6 +164,32 @@ public function setName($pValue = 'Calibri') return $this; } + + /** + * Get Character Spacing + * + * @return double + */ + public function getCharacterSpacing() + { + return $this->characterSpacing; + } + + /** + * Set Character Spacing + * Value in pt + * @param float|int $pValue + * @return \PhpOffice\PhpPresentation\Style\Font + */ + public function setCharacterSpacing($pValue = 0) + { + if ($pValue == '') { + $pValue = 0; + } + $this->characterSpacing = $pValue * 100; + + return $this; + } /** * Get Size diff --git a/src/PhpPresentation/Writer/PowerPoint2007/PptSlides.php b/src/PhpPresentation/Writer/PowerPoint2007/PptSlides.php index b104b4c80..8db42367d 100644 --- a/src/PhpPresentation/Writer/PowerPoint2007/PptSlides.php +++ b/src/PhpPresentation/Writer/PowerPoint2007/PptSlides.php @@ -1477,6 +1477,9 @@ protected function writeParagraphs(XMLWriter $objWriter, $paragraphs, $bIsPlaceh // Size $objWriter->writeAttribute('sz', ($element->getFont()->getSize() * 100)); + + // Character spacing + $objWriter->writeAttribute('spc', $element->getFont()->getCharacterSpacing()); // Underline $objWriter->writeAttribute('u', $element->getFont()->getUnderline()); diff --git a/tests/PhpPresentation/Tests/Style/FontTest.php b/tests/PhpPresentation/Tests/Style/FontTest.php index ba064fc89..6f1b1e6a7 100644 --- a/tests/PhpPresentation/Tests/Style/FontTest.php +++ b/tests/PhpPresentation/Tests/Style/FontTest.php @@ -41,6 +41,7 @@ public function testConstruct() $this->assertFalse($object->isSubScript()); $this->assertFalse($object->isStrikethrough()); $this->assertEquals(Font::UNDERLINE_NONE, $object->getUnderline()); + $this->assertEquals(0, $object->getCharacterSpacing()); $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Style\\Color', $object->getColor()); $this->assertEquals(Color::COLOR_BLACK, $object->getColor()->getARGB()); } @@ -56,6 +57,21 @@ public function testSetGetColorException() $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Style\\Font', $object->setColor()); } + /** + * Test get/set Character Spacing + */ + public function testSetGetCharacterSpacing() + { + $object = new Font(); + $this->assertEquals(0, $object->getCharacterSpacing()); + $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Style\\Font', $object->setCharacterSpacing(0)); + $this->assertEquals(0, $object->getCharacterSpacing()); + $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Style\\Font', $object->setCharacterSpacing(10)); + $this->assertEquals(1000, $object->getCharacterSpacing()); + $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Style\\Font', $object->setCharacterSpacing()); + $this->assertEquals(0, $object->getCharacterSpacing()); + } + /** * Test get/set color */ diff --git a/tests/PhpPresentation/Tests/Writer/PowerPoint2007/PptSlidesTest.php b/tests/PhpPresentation/Tests/Writer/PowerPoint2007/PptSlidesTest.php index 194f6cbca..625e12622 100644 --- a/tests/PhpPresentation/Tests/Writer/PowerPoint2007/PptSlidesTest.php +++ b/tests/PhpPresentation/Tests/Writer/PowerPoint2007/PptSlidesTest.php @@ -717,6 +717,27 @@ public function testSlideLayoutExists() $this->assertTrue($pres->fileExists('ppt/slideLayouts/slideLayout1.xml')); } + public function testStyleCharacterSpacing() + { + $element = '/p:sld/p:cSld/p:spTree/p:sp/p:txBody/a:p/a:r/a:rPr'; + + $oPhpPresentation = new PhpPresentation(); + $oSlide = $oPhpPresentation->getActiveSlide(); + $oRichText = $oSlide->createRichTextShape(); + $oRun = $oRichText->createTextRun('pText'); + // Default : $oRun->getFont()->setCharacterSpacing(0); + + $pres = TestHelperDOCX::getDocument($oPhpPresentation, 'PowerPoint2007'); + $this->assertTrue($pres->elementExists($element, 'ppt/slides/slide1.xml')); + $this->assertEquals('0', $pres->getElementAttribute($element, 'spc', 'ppt/slides/slide1.xml')); + + $oRun->getFont()->setCharacterSpacing(42); + + $pres = TestHelperDOCX::getDocument($oPhpPresentation, 'PowerPoint2007'); + $this->assertTrue($pres->elementExists($element, 'ppt/slides/slide1.xml')); + $this->assertEquals('4200', $pres->getElementAttribute($element, 'spc', 'ppt/slides/slide1.xml')); + } + public function testStyleSubScript() { $oPhpPresentation = new PhpPresentation();