Skip to content

Commit

Permalink
#279 : ODPresentation Writer : Support for rotation for RichText
Browse files Browse the repository at this point in the history
  • Loading branch information
Progi1984 committed Oct 13, 2017
1 parent ee77db7 commit c56a079
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
- PowerPoint2007 Reader : Support for fill for image - @Progi1984 GH-370
- ODPresentation Writer : Support for fill for transparent image - @Progi1984 GH-370
- PowerPoint2007 Writer : Support for fill for transparent image - @JewrassicPark GH-370
- ODPresentation Writer : Support for rotation for RichText - @Progi1984 GH-279

## 0.9.0 - 2017-07-05

Expand Down
20 changes: 20 additions & 0 deletions samples/Sample_11_Shape.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,25 @@ function fnSlideRichTextLineSpacing(PhpPresentation $objPHPPresentation)
$shape->createTextRun('Line Spacing 300');
}

function fnSlideRichTextRotation(PhpPresentation $objPHPPresentation)
{
// Create templated slide
echo date('H:i:s') . ' Create templated slide' . EOL;
$currentSlide = createTemplatedSlide($objPHPPresentation);

// Create a shape (text)
echo date('H:i:s') . ' Create a shape (rich text) with rotation' . EOL;
$shape = $currentSlide->createRichTextShape();
$shape->setHeight(100);
$shape->setWidth(400);
$shape->setOffsetX(100);
$shape->setOffsetY(100);
$shape->getActiveParagraph()->getAlignment()->setHorizontal(Alignment::HORIZONTAL_LEFT);
$shape->setRotation(45);

$shape->createTextRun('RichText with rotation');
}

function fnSlideRichTextShadow(PhpPresentation $objPHPPresentation)
{
// Create templated slide
Expand Down Expand Up @@ -143,6 +162,7 @@ function fnSlideRichTextList(PhpPresentation $objPHPPresentation)

fnSlideRichText($objPHPPresentation);
fnSlideRichTextLineSpacing($objPHPPresentation);
fnSlideRichTextRotation($objPHPPresentation);
fnSlideRichTextShadow($objPHPPresentation);
fnSlideRichTextList($objPHPPresentation);

Expand Down
12 changes: 10 additions & 2 deletions samples/Sample_Header.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,21 @@
if (preg_match('/^Sample_\d+_/', $file)) {
$name = str_replace('_', ' ', preg_replace('/(Sample_|\.php)/', '', $file));
$group = substr($name, 0, 1);
$id = substr($name, 0, 2);
if (!isset($files[$group])) {
$files[$group] = '';
$files[$group] = array();
}
$files[$group] .= "<li><a href='{$file}'>{$name}</a></li>";
if (!isset($files[$group][$id])) {
$files[$group][$id] = '';
}
$files[$group][$id] .= "<li><a href='{$file}'>{$name}</a></li>";
ksort($files[$group]);
}
}
closedir($handle);
foreach ($files as $keyGroup => $arrayGroup) {
$files[$keyGroup] = implode('', $arrayGroup);
}
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/PhpPresentation/Shape/RichText/TextElement.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ public function getHyperlink()
*
* @param \PhpOffice\PhpPresentation\Shape\Hyperlink $pHyperlink
* @throws \Exception
* @return \PhpOffice\PhpPresentation\AbstractShape
* @return $this
*/
public function setHyperlink(Hyperlink $pHyperlink = null)
{
Expand Down
4 changes: 4 additions & 0 deletions src/PhpPresentation/Writer/ODPresentation/Content.php
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,10 @@ public function writeShapeTxt(XMLWriter $objWriter, RichText $shape)
$objWriter->writeAttribute('svg:height', Text::numberFormat(CommonDrawing::pixelsToCentimeters($shape->getHeight()), 3) . 'cm');
$objWriter->writeAttribute('svg:x', Text::numberFormat(CommonDrawing::pixelsToCentimeters($shape->getOffsetX()), 3) . 'cm');
$objWriter->writeAttribute('svg:y', Text::numberFormat(CommonDrawing::pixelsToCentimeters($shape->getOffsetY()), 3) . 'cm');
if ($shape->getRotation() != 0) {
$rotRad = deg2rad($shape->getRotation());
$objWriter->writeAttribute('draw:transform', 'rotate ('.$rotRad.')');
}
// draw:text-box
$objWriter->startElement('draw:text-box');

Expand Down
12 changes: 12 additions & 0 deletions tests/PhpPresentation/Tests/Writer/ODPresentation/ContentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,18 @@ public function testRichTextBorder()
$this->assertZipXmlAttributeStartsWith('content.xml', $element, 'draw:stroke-dash', 'strokeDash_');
$this->assertZipXmlAttributeEndsWith('content.xml', $element, 'draw:stroke-dash', $oRichText1->getBorder()->getDashStyle());
}

public function testRichTextRotation()
{
$expectedValue = rand(1, 360);
$oRichText1 = $this->oPresentation->getActiveSlide()->createRichTextShape();
$oRichText1->setRotation($expectedValue);

$element = '/office:document-content/office:body/office:presentation/draw:page/draw:frame';
$this->assertZipXmlElementExists('content.xml', $element);
$this->assertZipXmlAttributeExists('content.xml', $element, 'draw:transform');
$this->assertZipXmlAttributeEquals('content.xml', $element, 'draw:transform', 'rotate ('.deg2rad(360 - $expectedValue).')');
}

public function testRichTextShadow()
{
Expand Down

0 comments on commit c56a079

Please sign in to comment.