public function testRichTextShadow()
{
$randAlpha = rand(0, 100);
$phpPresentation = new PhpPresentation();
$oSlide = $phpPresentation->getActiveSlide();
$oRichText = $oSlide->createRichTextShape();
$oRichText->createTextRun('AAA');
$oRichText->getShadow()->setVisible(true)->setAlpha($randAlpha)->setBlurRadius(2);
$element = '/office:document-content/office:automatic-styles/style:style[@style:name=\'gr1\']/style:graphic-properties';
for ($inc = 0; $inc <= 360; $inc += 45) {
$randDistance = rand(0, 100);
$oRichText->getShadow()->setDirection($inc)->setDistance($randDistance);
$pres = TestHelperDOCX::getDocument($phpPresentation, 'ODPresentation');
$this->assertTrue($pres->elementExists($element, 'content.xml'));
$this->assertEquals('visible', $pres->getElementAttribute($element, 'draw:shadow', 'content.xml'));
$this->assertEquals('none', $pres->getElementAttribute($element, 'style:mirror', 'content.xml'));
// Opacity
$this->assertStringStartsWith((string) (100 - $randAlpha), $pres->getElementAttribute($element, 'draw:shadow-opacity', 'content.xml'));
$this->assertStringEndsWith('%', $pres->getElementAttribute($element, 'draw:shadow-opacity', 'content.xml'));
// Color
$this->assertStringStartsWith('#', $pres->getElementAttribute($element, 'draw:shadow-color', 'content.xml'));
// X
$xOffset = $pres->getElementAttribute($element, 'draw:shadow-offset-x', 'content.xml');
if ($inc == 90 || $inc == 270) {
$this->assertEquals('0cm', $xOffset);
} else {
if ($inc > 90 && $inc < 270) {
$this->assertEquals('-' . Drawing::pixelsToCentimeters($randDistance) . 'cm', $xOffset);
} else {
$this->assertEquals(Drawing::pixelsToCentimeters($randDistance) . 'cm', $xOffset);
}
}
// Y
$yOffset = $pres->getElementAttribute($element, 'draw:shadow-offset-y', 'content.xml');
if ($inc == 0 || $inc == 180 || $inc == 360) {
$this->assertEquals('0cm', $yOffset);
} else {
if ($inc > 0 && $inc < 180 || $inc == 360) {
$this->assertEquals(Drawing::pixelsToCentimeters($randDistance) . 'cm', $yOffset);
} else {
$this->assertEquals('-' . Drawing::pixelsToCentimeters($randDistance) . 'cm', $yOffset);
}
}
}
}