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 Jul 25, 2021
1 parent 6c46ff2 commit 9917f6d
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 2 deletions.
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 @@ -87,13 +87,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
4 changes: 4 additions & 0 deletions src/PhpPresentation/Writer/ODPresentation/Content.php
Original file line number Diff line number Diff line change
Expand Up @@ -454,6 +454,10 @@ public function writeShapeTxt(XMLWriter $objWriter, RichText $shape): void
$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 @@ -418,6 +418,18 @@ public function testRichTextBorder(): void
$this->assertIsSchemaOpenDocumentValid('1.2');
}

public function testRichTextRotation(): void
{
$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(): void
{
$randAlpha = mt_rand(0, 100);
Expand Down

0 comments on commit 9917f6d

Please sign in to comment.