示例#1
0
 /**
  * Test get/set alpha
  */
 public function testSetGetAlpha()
 {
     $object = new Shadow();
     $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Style\\Shadow', $object->setAlpha());
     $this->assertEquals(0, $object->getAlpha());
     $value = rand(1, 100);
     $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Style\\Shadow', $object->setAlpha($value));
     $this->assertEquals($value, $object->getAlpha());
 }
示例#2
0
 /**
  * @param XMLWriter $objWriter
  * @param Shadow $oShadow
  * @todo Improve for supporting any direction (https://sinepost.wordpress.com/2012/02/16/theyve-got-atan-you-want-atan2/)
  */
 protected function writeStylePartShadow(XMLWriter $objWriter, Shadow $oShadow)
 {
     $objWriter->writeAttribute('draw:shadow', 'visible');
     $objWriter->writeAttribute('draw:shadow-color', '#' . $oShadow->getColor()->getRGB());
     if ($oShadow->getDirection() == 0 || $oShadow->getDirection() == 360) {
         $objWriter->writeAttribute('draw:shadow-offset-x', CommonDrawing::pixelsToCentimeters($oShadow->getDistance()) . 'cm');
         $objWriter->writeAttribute('draw:shadow-offset-y', '0cm');
     } elseif ($oShadow->getDirection() == 45) {
         $objWriter->writeAttribute('draw:shadow-offset-x', CommonDrawing::pixelsToCentimeters($oShadow->getDistance()) . 'cm');
         $objWriter->writeAttribute('draw:shadow-offset-y', CommonDrawing::pixelsToCentimeters($oShadow->getDistance()) . 'cm');
     } elseif ($oShadow->getDirection() == 90) {
         $objWriter->writeAttribute('draw:shadow-offset-x', '0cm');
         $objWriter->writeAttribute('draw:shadow-offset-y', CommonDrawing::pixelsToCentimeters($oShadow->getDistance()) . 'cm');
     } elseif ($oShadow->getDirection() == 135) {
         $objWriter->writeAttribute('draw:shadow-offset-x', '-' . CommonDrawing::pixelsToCentimeters($oShadow->getDistance()) . 'cm');
         $objWriter->writeAttribute('draw:shadow-offset-y', CommonDrawing::pixelsToCentimeters($oShadow->getDistance()) . 'cm');
     } elseif ($oShadow->getDirection() == 180) {
         $objWriter->writeAttribute('draw:shadow-offset-x', '-' . CommonDrawing::pixelsToCentimeters($oShadow->getDistance()) . 'cm');
         $objWriter->writeAttribute('draw:shadow-offset-y', '0cm');
     } elseif ($oShadow->getDirection() == 225) {
         $objWriter->writeAttribute('draw:shadow-offset-x', '-' . CommonDrawing::pixelsToCentimeters($oShadow->getDistance()) . 'cm');
         $objWriter->writeAttribute('draw:shadow-offset-y', '-' . CommonDrawing::pixelsToCentimeters($oShadow->getDistance()) . 'cm');
     } elseif ($oShadow->getDirection() == 270) {
         $objWriter->writeAttribute('draw:shadow-offset-x', '0cm');
         $objWriter->writeAttribute('draw:shadow-offset-y', '-' . CommonDrawing::pixelsToCentimeters($oShadow->getDistance()) . 'cm');
     } elseif ($oShadow->getDirection() == 315) {
         $objWriter->writeAttribute('draw:shadow-offset-x', CommonDrawing::pixelsToCentimeters($oShadow->getDistance()) . 'cm');
         $objWriter->writeAttribute('draw:shadow-offset-y', '-' . CommonDrawing::pixelsToCentimeters($oShadow->getDistance()) . 'cm');
     }
     $objWriter->writeAttribute('draw:shadow-opacity', 100 - $oShadow->getAlpha() . '%');
     $objWriter->writeAttribute('style:mirror', 'none');
 }
示例#3
0
 /**
  * Write Shadow
  * @param XMLWriter $objWriter
  * @param Shadow $oShadow
  */
 protected function writeShadow(XMLWriter $objWriter, Shadow $oShadow)
 {
     // a:effectLst
     $objWriter->startElement('a:effectLst');
     // a:outerShdw
     $objWriter->startElement('a:outerShdw');
     $objWriter->writeAttribute('blurRad', CommonDrawing::pixelsToEmu($oShadow->getBlurRadius()));
     $objWriter->writeAttribute('dist', CommonDrawing::pixelsToEmu($oShadow->getDistance()));
     $objWriter->writeAttribute('dir', CommonDrawing::degreesToAngle($oShadow->getDirection()));
     $objWriter->writeAttribute('algn', $oShadow->getAlignment());
     $objWriter->writeAttribute('rotWithShape', '0');
     // a:srgbClr
     $objWriter->startElement('a:srgbClr');
     $objWriter->writeAttribute('val', $oShadow->getColor()->getRGB());
     // a:alpha
     $objWriter->startElement('a:alpha');
     $objWriter->writeAttribute('val', $oShadow->getAlpha() * 1000);
     $objWriter->endElement();
     $objWriter->endElement();
     $objWriter->endElement();
     $objWriter->endElement();
 }
示例#4
0
 /**
  * Write Shadow
  * @param XMLWriter $objWriter
  * @param Shadow $oShadow
  */
 protected function writeShadow(XMLWriter $objWriter, $oShadow)
 {
     if (!$oShadow instanceof Shadow) {
         return;
     }
     if (!$oShadow->isVisible()) {
         return;
     }
     // a:effectLst
     $objWriter->startElement('a:effectLst');
     // a:outerShdw
     $objWriter->startElement('a:outerShdw');
     $objWriter->writeAttribute('blurRad', CommonDrawing::pixelsToEmu($oShadow->getBlurRadius()));
     $objWriter->writeAttribute('dist', CommonDrawing::pixelsToEmu($oShadow->getDistance()));
     $objWriter->writeAttribute('dir', CommonDrawing::degreesToAngle($oShadow->getDirection()));
     $objWriter->writeAttribute('algn', $oShadow->getAlignment());
     $objWriter->writeAttribute('rotWithShape', '0');
     $this->writeColor($objWriter, $oShadow->getColor(), $oShadow->getAlpha());
     $objWriter->endElement();
     $objWriter->endElement();
 }