From c56a0798cbe6bb6623d227a749a1de0d0f14c376 Mon Sep 17 00:00:00 2001 From: Progi1984 Date: Fri, 13 Oct 2017 23:41:46 +0200 Subject: [PATCH] #279 : ODPresentation Writer : Support for rotation for RichText --- CHANGELOG.md | 1 + samples/Sample_11_Shape.php | 20 +++++++++++++++++++ samples/Sample_Header.php | 12 +++++++++-- .../Shape/RichText/TextElement.php | 2 +- .../Writer/ODPresentation/Content.php | 4 ++++ .../Writer/ODPresentation/ContentTest.php | 12 +++++++++++ 6 files changed, 48 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c94c2eec9..da5aaba23 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/samples/Sample_11_Shape.php b/samples/Sample_11_Shape.php index 37dc5a221..35d1a4540 100644 --- a/samples/Sample_11_Shape.php +++ b/samples/Sample_11_Shape.php @@ -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 @@ -143,6 +162,7 @@ function fnSlideRichTextList(PhpPresentation $objPHPPresentation) fnSlideRichText($objPHPPresentation); fnSlideRichTextLineSpacing($objPHPPresentation); +fnSlideRichTextRotation($objPHPPresentation); fnSlideRichTextShadow($objPHPPresentation); fnSlideRichTextList($objPHPPresentation); diff --git a/samples/Sample_Header.php b/samples/Sample_Header.php index 0a237b1b6..a1b9070fb 100644 --- a/samples/Sample_Header.php +++ b/samples/Sample_Header.php @@ -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] .= "
  • {$name}
  • "; + if (!isset($files[$group][$id])) { + $files[$group][$id] = ''; + } + $files[$group][$id] .= "
  • {$name}
  • "; + ksort($files[$group]); } } closedir($handle); + foreach ($files as $keyGroup => $arrayGroup) { + $files[$keyGroup] = implode('', $arrayGroup); + } } /** diff --git a/src/PhpPresentation/Shape/RichText/TextElement.php b/src/PhpPresentation/Shape/RichText/TextElement.php index 2cdbd499b..0da2a2d1e 100644 --- a/src/PhpPresentation/Shape/RichText/TextElement.php +++ b/src/PhpPresentation/Shape/RichText/TextElement.php @@ -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) { diff --git a/src/PhpPresentation/Writer/ODPresentation/Content.php b/src/PhpPresentation/Writer/ODPresentation/Content.php index ca0051de5..e5148d90e 100644 --- a/src/PhpPresentation/Writer/ODPresentation/Content.php +++ b/src/PhpPresentation/Writer/ODPresentation/Content.php @@ -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'); diff --git a/tests/PhpPresentation/Tests/Writer/ODPresentation/ContentTest.php b/tests/PhpPresentation/Tests/Writer/ODPresentation/ContentTest.php index 566945efb..3b43dba52 100644 --- a/tests/PhpPresentation/Tests/Writer/ODPresentation/ContentTest.php +++ b/tests/PhpPresentation/Tests/Writer/ODPresentation/ContentTest.php @@ -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() {