Example #1
0
 /**
  * Test get/set visible
  */
 public function testSetIsVisible()
 {
     $object = new Shadow();
     $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Style\\Shadow', $object->setVisible());
     $this->assertFalse($object->isVisible());
     $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Style\\Shadow', $object->setVisible(false));
     $this->assertFalse($object->isVisible());
     $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Style\\Shadow', $object->setVisible(true));
     $this->assertTrue($object->isVisible());
 }
 /**
  * Get hash code
  *
  * @return string Hash code
  */
 public function getHashCode()
 {
     return md5((is_object($this->container) ? $this->container->getHashCode() : '') . $this->offsetX . $this->offsetY . $this->width . $this->height . $this->rotation . $this->getFill()->getHashCode() . (is_null($this->shadow) ? '' : $this->shadow->getHashCode()) . (is_null($this->hyperlink) ? '' : $this->hyperlink->getHashCode()) . __CLASS__);
 }
Example #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();
 }
    $shape->getLegend()->getBorder()->setLineStyle(Border::LINE_SINGLE);
    $shape->getLegend()->getFont()->setItalic(true);
}
// Create new PHPPresentation object
echo date('H:i:s') . ' Create new PHPPresentation object' . EOL;
$objPHPPresentation = new PhpPresentation();
// Set properties
echo date('H:i:s') . ' Set properties' . EOL;
$objPHPPresentation->getProperties()->setCreator('PHPOffice')->setLastModifiedBy('PHPPresentation Team')->setTitle('Sample 07 Title')->setSubject('Sample 07 Subject')->setDescription('Sample 07 Description')->setKeywords('office 2007 openxml libreoffice odt php')->setCategory('Sample Category');
// Remove first slide
echo date('H:i:s') . ' Remove first slide' . EOL;
$objPHPPresentation->removeSlideByIndex(0);
// Set Style
$oFill = new Fill();
$oFill->setFillType(Fill::FILL_SOLID)->setStartColor(new Color('FFE06B20'));
$oShadow = new Shadow();
$oShadow->setVisible(true)->setDirection(45)->setDistance(10);
fnSlide_Area($objPHPPresentation);
fnSlide_Bar($objPHPPresentation);
fnSlide_BarStacked($objPHPPresentation);
fnSlide_BarPercentStacked($objPHPPresentation);
fnSlide_BarHorizontal($objPHPPresentation);
fnSlide_Bar3D($objPHPPresentation);
fnSlide_Bar3DHorizontal($objPHPPresentation);
fnSlide_Pie3D($objPHPPresentation);
fnSlide_Pie($objPHPPresentation);
fnSlide_Scatter($objPHPPresentation);
// Save file
echo write($objPHPPresentation, basename(__FILE__, '.php'), $writers);
if (!CLI) {
    include_once 'Sample_Footer.php';
 /**
  * Extract style
  * @param \DOMElement $nodeStyle
  */
 protected function loadStyle(\DOMElement $nodeStyle)
 {
     $keyStyle = $nodeStyle->getAttribute('style:name');
     $nodeDrawingPageProps = $this->oXMLReader->getElement('style:drawing-page-properties', $nodeStyle);
     if ($nodeDrawingPageProps) {
         // Read Background Color
         if ($nodeDrawingPageProps->hasAttribute('draw:fill-color') && $nodeDrawingPageProps->getAttribute('draw:fill') == 'solid') {
             $oBackground = new \PhpOffice\PhpPresentation\Slide\Background\Color();
             $oColor = new Color();
             $oColor->setRGB(substr($nodeDrawingPageProps->getAttribute('draw:fill-color'), -6));
             $oBackground->setColor($oColor);
         }
         // Read Background Image
         if ($nodeDrawingPageProps->getAttribute('draw:fill') == 'bitmap' && $nodeDrawingPageProps->hasAttribute('draw:fill-image-name')) {
             $nameStyle = $nodeDrawingPageProps->getAttribute('draw:fill-image-name');
             if (!empty($this->arrayCommonStyles[$nameStyle]) && $this->arrayCommonStyles[$nameStyle]['type'] == 'image' && !empty($this->arrayCommonStyles[$nameStyle]['path'])) {
                 $tmpBkgImg = tempnam(sys_get_temp_dir(), 'PhpPresentationReaderODPBkg');
                 $contentImg = $this->oZip->getFromName($this->arrayCommonStyles[$nameStyle]['path']);
                 file_put_contents($tmpBkgImg, $contentImg);
                 $oBackground = new Image();
                 $oBackground->setPath($tmpBkgImg);
             }
         }
     }
     $nodeGraphicProps = $this->oXMLReader->getElement('style:graphic-properties', $nodeStyle);
     if ($nodeGraphicProps) {
         // Read Shadow
         if ($nodeGraphicProps->hasAttribute('draw:shadow') && $nodeGraphicProps->getAttribute('draw:shadow') == 'visible') {
             $oShadow = new Shadow();
             $oShadow->setVisible(true);
             if ($nodeGraphicProps->hasAttribute('draw:shadow-color')) {
                 $oShadow->getColor()->setRGB(substr($nodeGraphicProps->getAttribute('draw:shadow-color'), -6));
             }
             if ($nodeGraphicProps->hasAttribute('draw:shadow-opacity')) {
                 $oShadow->setAlpha(100 - (int) substr($nodeGraphicProps->getAttribute('draw:shadow-opacity'), 0, -1));
             }
             if ($nodeGraphicProps->hasAttribute('draw:shadow-offset-x') && $nodeGraphicProps->hasAttribute('draw:shadow-offset-y')) {
                 $offsetX = substr($nodeGraphicProps->getAttribute('draw:shadow-offset-x'), 0, -2);
                 $offsetY = substr($nodeGraphicProps->getAttribute('draw:shadow-offset-y'), 0, -2);
                 $distance = 0;
                 if ($offsetX != 0) {
                     $distance = $offsetX < 0 ? $offsetX * -1 : $offsetX;
                 } elseif ($offsetY != 0) {
                     $distance = $offsetY < 0 ? $offsetY * -1 : $offsetY;
                 }
                 $oShadow->setDirection(rad2deg(atan2($offsetY, $offsetX)));
                 $oShadow->setDistance(CommonDrawing::centimetersToPixels($distance));
             }
         }
     }
     $nodeTextProperties = $this->oXMLReader->getElement('style:text-properties', $nodeStyle);
     if ($nodeTextProperties) {
         $oFont = new Font();
         if ($nodeTextProperties->hasAttribute('fo:color')) {
             $oFont->getColor()->setRGB(substr($nodeTextProperties->getAttribute('fo:color'), -6));
         }
         if ($nodeTextProperties->hasAttribute('fo:font-family')) {
             $oFont->setName($nodeTextProperties->getAttribute('fo:font-family'));
         }
         if ($nodeTextProperties->hasAttribute('fo:font-weight') && $nodeTextProperties->getAttribute('fo:font-weight') == 'bold') {
             $oFont->setBold(true);
         }
         if ($nodeTextProperties->hasAttribute('fo:font-size')) {
             $oFont->setSize(substr($nodeTextProperties->getAttribute('fo:font-size'), 0, -2));
         }
     }
     $nodeParagraphProps = $this->oXMLReader->getElement('style:paragraph-properties', $nodeStyle);
     if ($nodeParagraphProps) {
         $oAlignment = new Alignment();
         if ($nodeParagraphProps->hasAttribute('fo:text-align')) {
             $oAlignment->setHorizontal($nodeParagraphProps->getAttribute('fo:text-align'));
         }
     }
     if ($nodeStyle->nodeName == 'text:list-style') {
         $arrayListStyle = array();
         foreach ($this->oXMLReader->getElements('text:list-level-style-bullet', $nodeStyle) as $oNodeListLevel) {
             $oAlignment = new Alignment();
             $oBullet = new Bullet();
             $oBullet->setBulletType(Bullet::TYPE_NONE);
             if ($oNodeListLevel->hasAttribute('text:level')) {
                 $oAlignment->setLevel((int) $oNodeListLevel->getAttribute('text:level') - 1);
             }
             if ($oNodeListLevel->hasAttribute('text:bullet-char')) {
                 $oBullet->setBulletChar($oNodeListLevel->getAttribute('text:bullet-char'));
                 $oBullet->setBulletType(Bullet::TYPE_BULLET);
             }
             $oNodeListProperties = $this->oXMLReader->getElement('style:list-level-properties', $oNodeListLevel);
             if ($oNodeListProperties) {
                 if ($oNodeListProperties->hasAttribute('text:min-label-width')) {
                     $oAlignment->setIndent((int) round(CommonDrawing::centimetersToPixels(substr($oNodeListProperties->getAttribute('text:min-label-width'), 0, -2))));
                 }
                 if ($oNodeListProperties->hasAttribute('text:space-before')) {
                     $iSpaceBefore = CommonDrawing::centimetersToPixels(substr($oNodeListProperties->getAttribute('text:space-before'), 0, -2));
                     $iMarginLeft = $iSpaceBefore + $oAlignment->getIndent();
                     $oAlignment->setMarginLeft($iMarginLeft);
                 }
             }
             $oNodeTextProperties = $this->oXMLReader->getElement('style:text-properties', $oNodeListLevel);
             if ($oNodeTextProperties) {
                 if ($oNodeTextProperties->hasAttribute('fo:font-family')) {
                     $oBullet->setBulletFont($oNodeTextProperties->getAttribute('fo:font-family'));
                 }
             }
             $arrayListStyle[$oAlignment->getLevel()] = array('alignment' => $oAlignment, 'bullet' => $oBullet);
         }
     }
     $this->arrayStyles[$keyStyle] = array('alignment' => isset($oAlignment) ? $oAlignment : null, 'background' => isset($oBackground) ? $oBackground : null, 'font' => isset($oFont) ? $oFont : null, 'shadow' => isset($oShadow) ? $oShadow : null, 'listStyle' => isset($arrayListStyle) ? $arrayListStyle : null);
     return true;
 }
Example #6
0
 /**
  * Extract style
  * @param \DOMElement $nodeStyle
  */
 protected function loadStyle(\DOMElement $nodeStyle)
 {
     $keyStyle = $nodeStyle->getAttribute('style:name');
     $nodeGraphicProps = $this->oXMLReader->getElement('style:graphic-properties', $nodeStyle);
     if ($nodeGraphicProps) {
         // Read Shadow
         if ($nodeGraphicProps->hasAttribute('draw:shadow') && $nodeGraphicProps->getAttribute('draw:shadow') == 'visible') {
             $oShadow = new Shadow();
             $oShadow->setVisible(true);
             if ($nodeGraphicProps->hasAttribute('draw:shadow-color')) {
                 $oShadow->getColor()->setRGB(substr($nodeGraphicProps->getAttribute('draw:shadow-color'), -6));
             }
             if ($nodeGraphicProps->hasAttribute('draw:shadow-opacity')) {
                 $oShadow->setAlpha(100 - (int) substr($nodeGraphicProps->getAttribute('draw:shadow-opacity'), 0, -1));
             }
             if ($nodeGraphicProps->hasAttribute('draw:shadow-offset-x') && $nodeGraphicProps->hasAttribute('draw:shadow-offset-y')) {
                 $offsetX = substr($nodeGraphicProps->getAttribute('draw:shadow-offset-x'), 0, -2);
                 $offsetY = substr($nodeGraphicProps->getAttribute('draw:shadow-offset-y'), 0, -2);
                 $distance = 0;
                 if ($offsetX != 0) {
                     $distance = $offsetX < 0 ? $offsetX * -1 : $offsetX;
                 } elseif ($offsetY != 0) {
                     $distance = $offsetY < 0 ? $offsetY * -1 : $offsetY;
                 }
                 $oShadow->setDirection(rad2deg(atan2($offsetY, $offsetX)));
                 $oShadow->setDistance(CommonDrawing::centimetersToPixels($distance));
             }
         }
     }
     $nodeTextProperties = $this->oXMLReader->getElement('style:text-properties', $nodeStyle);
     if ($nodeTextProperties) {
         $oFont = new Font();
         if ($nodeTextProperties->hasAttribute('fo:color')) {
             $oFont->getColor()->setRGB(substr($nodeTextProperties->getAttribute('fo:color'), -6));
         }
         if ($nodeTextProperties->hasAttribute('fo:font-family')) {
             $oFont->setName($nodeTextProperties->getAttribute('fo:font-family'));
         }
         if ($nodeTextProperties->hasAttribute('fo:font-weight') && $nodeTextProperties->getAttribute('fo:font-weight') == 'bold') {
             $oFont->setBold(true);
         }
         if ($nodeTextProperties->hasAttribute('fo:font-size')) {
             $oFont->setSize(substr($nodeTextProperties->getAttribute('fo:font-size'), 0, -2));
         }
     }
     $nodeParagraphProps = $this->oXMLReader->getElement('style:paragraph-properties', $nodeStyle);
     if ($nodeParagraphProps) {
         $oAlignment = new Alignment();
         if ($nodeParagraphProps->hasAttribute('fo:text-align')) {
             $oAlignment->setHorizontal($nodeParagraphProps->getAttribute('fo:text-align'));
         }
     }
     if ($nodeStyle->nodeName == 'text:list-style') {
         $arrayListStyle = array();
         foreach ($this->oXMLReader->getElements('text:list-level-style-bullet', $nodeStyle) as $oNodeListLevel) {
             $oAlignment = new Alignment();
             $oBullet = new Bullet();
             $oBullet->setBulletType(Bullet::TYPE_NONE);
             if ($oNodeListLevel->hasAttribute('text:level')) {
                 $oAlignment->setLevel((int) $oNodeListLevel->getAttribute('text:level') - 1);
             }
             if ($oNodeListLevel->hasAttribute('text:bullet-char')) {
                 $oBullet->setBulletChar($oNodeListLevel->getAttribute('text:bullet-char'));
                 $oBullet->setBulletType(Bullet::TYPE_BULLET);
             }
             $oNodeListProperties = $this->oXMLReader->getElement('style:list-level-properties', $oNodeListLevel);
             if ($oNodeListProperties) {
                 if ($oNodeListProperties->hasAttribute('text:min-label-width')) {
                     $oAlignment->setIndent((int) round(CommonDrawing::centimetersToPixels(substr($oNodeListProperties->getAttribute('text:min-label-width'), 0, -2))));
                 }
                 if ($oNodeListProperties->hasAttribute('text:space-before')) {
                     $iSpaceBefore = CommonDrawing::centimetersToPixels(substr($oNodeListProperties->getAttribute('text:space-before'), 0, -2));
                     $iMarginLeft = $iSpaceBefore + $oAlignment->getIndent();
                     $oAlignment->setMarginLeft($iMarginLeft);
                 }
             }
             $oNodeTextProperties = $this->oXMLReader->getElement('style:text-properties', $oNodeListLevel);
             if ($oNodeTextProperties) {
                 if ($oNodeTextProperties->hasAttribute('fo:font-family')) {
                     $oBullet->setBulletFont($oNodeTextProperties->getAttribute('fo:font-family'));
                 }
             }
             $arrayListStyle[$oAlignment->getLevel()] = array('alignment' => $oAlignment, 'bullet' => $oBullet);
         }
     }
     $this->arrayStyles[$keyStyle] = array('alignment' => isset($oAlignment) ? $oAlignment : null, 'font' => isset($oFont) ? $oFont : null, 'shadow' => isset($oShadow) ? $oShadow : null, 'listStyle' => isset($arrayListStyle) ? $arrayListStyle : null);
     return true;
 }
Example #7
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');
 }
use PhpOffice\PhpPresentation\Style\Color;
use PhpOffice\PhpPresentation\Style\Fill;
use PhpOffice\PhpPresentation\Style\Shadow;
// Create new PHPPresentation object
echo date('H:i:s') . ' Create new PHPPresentation object' . EOL;
$objPHPPresentation = new PhpPresentation();
// Set properties
echo date('H:i:s') . ' Set properties' . EOL;
$objPHPPresentation->getDocumentProperties()->setCreator('PHPOffice')->setLastModifiedBy('PHPPresentation Team')->setTitle('Sample 07 Title')->setSubject('Sample 07 Subject')->setDescription('Sample 07 Description')->setKeywords('office 2007 openxml libreoffice odt php')->setCategory('Sample Category');
// Remove first slide
echo date('H:i:s') . ' Remove first slide' . EOL;
$objPHPPresentation->removeSlideByIndex(0);
// Set Style
$oFill = new Fill();
$oFill->setFillType(Fill::FILL_SOLID)->setStartColor(new Color('FFE06B20'));
$oShadow = new Shadow();
$oShadow->setVisible(true)->setDirection(45)->setDistance(10);
// Generate sample data for chart
echo date('H:i:s') . ' Generate sample data for chart' . EOL;
$seriesData = array('Monday' => 12, 'Tuesday' => 15, 'Wednesday' => 13, 'Thursday' => 17, 'Friday' => 14, 'Saturday' => 9, 'Sunday' => 7);
// Create templated slide
echo EOL . date('H:i:s') . ' Create templated slide' . EOL;
$currentSlide = createTemplatedSlide($objPHPPresentation);
// Create a line chart (that should be inserted in a shape)
echo date('H:i:s') . ' Create a line chart (that should be inserted in a chart shape)' . EOL;
$lineChart = new Line();
$series = new Series('Downloads', $seriesData);
$series->setShowSeriesName(true);
$series->setShowValue(true);
$lineChart->addSeries($series);
// Create a shape (chart)
 /**
  * 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();
 }