Skip to content

Commit 9917f6d

Browse files
committed
#279 : ODPresentation Writer : Support for rotation for RichText
1 parent 6c46ff2 commit 9917f6d

File tree

4 files changed

+46
-2
lines changed

4 files changed

+46
-2
lines changed

samples/Sample_11_Shape.php

+20
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,25 @@ function fnSlideRichTextLineSpacing(PhpPresentation $objPHPPresentation)
8181
$shape->createTextRun('Line Spacing 300');
8282
}
8383

84+
function fnSlideRichTextRotation(PhpPresentation $objPHPPresentation)
85+
{
86+
// Create templated slide
87+
echo date('H:i:s') . ' Create templated slide' . EOL;
88+
$currentSlide = createTemplatedSlide($objPHPPresentation);
89+
90+
// Create a shape (text)
91+
echo date('H:i:s') . ' Create a shape (rich text) with rotation' . EOL;
92+
$shape = $currentSlide->createRichTextShape();
93+
$shape->setHeight(100);
94+
$shape->setWidth(400);
95+
$shape->setOffsetX(100);
96+
$shape->setOffsetY(100);
97+
$shape->getActiveParagraph()->getAlignment()->setHorizontal(Alignment::HORIZONTAL_LEFT);
98+
$shape->setRotation(45);
99+
100+
$shape->createTextRun('RichText with rotation');
101+
}
102+
84103
function fnSlideRichTextShadow(PhpPresentation $objPHPPresentation)
85104
{
86105
// Create templated slide
@@ -143,6 +162,7 @@ function fnSlideRichTextList(PhpPresentation $objPHPPresentation)
143162

144163
fnSlideRichText($objPHPPresentation);
145164
fnSlideRichTextLineSpacing($objPHPPresentation);
165+
fnSlideRichTextRotation($objPHPPresentation);
146166
fnSlideRichTextShadow($objPHPPresentation);
147167
fnSlideRichTextList($objPHPPresentation);
148168

samples/Sample_Header.php

+10-2
Original file line numberDiff line numberDiff line change
@@ -87,13 +87,21 @@
8787
if (preg_match('/^Sample_\d+_/', $file)) {
8888
$name = str_replace('_', ' ', preg_replace('/(Sample_|\.php)/', '', $file));
8989
$group = substr($name, 0, 1);
90+
$id = substr($name, 0, 2);
9091
if (!isset($files[$group])) {
91-
$files[$group] = '';
92+
$files[$group] = array();
9293
}
93-
$files[$group] .= "<li><a href='{$file}'>{$name}</a></li>";
94+
if (!isset($files[$group][$id])) {
95+
$files[$group][$id] = '';
96+
}
97+
$files[$group][$id] .= "<li><a href='{$file}'>{$name}</a></li>";
98+
ksort($files[$group]);
9499
}
95100
}
96101
closedir($handle);
102+
foreach ($files as $keyGroup => $arrayGroup) {
103+
$files[$keyGroup] = implode('', $arrayGroup);
104+
}
97105
}
98106

99107
/**

src/PhpPresentation/Writer/ODPresentation/Content.php

+4
Original file line numberDiff line numberDiff line change
@@ -454,6 +454,10 @@ public function writeShapeTxt(XMLWriter $objWriter, RichText $shape): void
454454
$objWriter->writeAttribute('svg:height', Text::numberFormat(CommonDrawing::pixelsToCentimeters($shape->getHeight()), 3) . 'cm');
455455
$objWriter->writeAttribute('svg:x', Text::numberFormat(CommonDrawing::pixelsToCentimeters($shape->getOffsetX()), 3) . 'cm');
456456
$objWriter->writeAttribute('svg:y', Text::numberFormat(CommonDrawing::pixelsToCentimeters($shape->getOffsetY()), 3) . 'cm');
457+
if ($shape->getRotation() != 0) {
458+
$rotRad = deg2rad($shape->getRotation());
459+
$objWriter->writeAttribute('draw:transform', 'rotate ('.$rotRad.')');
460+
}
457461
// draw:text-box
458462
$objWriter->startElement('draw:text-box');
459463

tests/PhpPresentation/Tests/Writer/ODPresentation/ContentTest.php

+12
Original file line numberDiff line numberDiff line change
@@ -418,6 +418,18 @@ public function testRichTextBorder(): void
418418
$this->assertIsSchemaOpenDocumentValid('1.2');
419419
}
420420

421+
public function testRichTextRotation(): void
422+
{
423+
$expectedValue = rand(1, 360);
424+
$oRichText1 = $this->oPresentation->getActiveSlide()->createRichTextShape();
425+
$oRichText1->setRotation($expectedValue);
426+
427+
$element = '/office:document-content/office:body/office:presentation/draw:page/draw:frame';
428+
$this->assertZipXmlElementExists('content.xml', $element);
429+
$this->assertZipXmlAttributeExists('content.xml', $element, 'draw:transform');
430+
$this->assertZipXmlAttributeEquals('content.xml', $element, 'draw:transform', 'rotate ('.deg2rad(360 - $expectedValue).')');
431+
}
432+
421433
public function testRichTextShadow(): void
422434
{
423435
$randAlpha = mt_rand(0, 100);

0 commit comments

Comments
 (0)