Skip to content

Commit

Permalink
Merge pull request #301 from jvanoostrom/develop
Browse files Browse the repository at this point in the history
Implement character spacing
  • Loading branch information
Progi1984 authored Jan 15, 2017
2 parents 16387e4 + 68f1364 commit 0f4f109
Show file tree
Hide file tree
Showing 5 changed files with 86 additions and 9 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
- PowerPoint2007 Writer : Fixed the axis title in bar chart - @pgee70 GH-267
- PowerPoint2007 Writer : Fixed the label position in bar chart - @pgee70 GH-268

### Features
- PowerPoint2007 Writer : Implement character spacing - @jvanoostrom GH-301

## 0.7.0 - 2016-09-12

### Bugfix
Expand Down
52 changes: 43 additions & 9 deletions src/PhpPresentation/Style/Font.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,13 @@ class Font implements ComparableInterface
*/
private $color;

/**
* Character Spacing
*
* @var int
*/
private $characterSpacing;

/**
* Hash index
*
Expand All @@ -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);
}

/**
Expand Down Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions src/PhpPresentation/Writer/PowerPoint2007/PptSlides.php
Original file line number Diff line number Diff line change
Expand Up @@ -1485,6 +1485,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());
Expand Down
16 changes: 16 additions & 0 deletions tests/PhpPresentation/Tests/Style/FontTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
Expand All @@ -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
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit 0f4f109

Please sign in to comment.