/**
  * 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 \PhpOffice\PhpPresentation\Slide\Background\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;
 }
 /**
  * Extract data from slide
  * @param string $sPart
  * @param string $baseFile
  */
 protected function loadSlide($sPart, $baseFile)
 {
     $xmlReader = new XMLReader();
     if ($xmlReader->getDomFromString($sPart)) {
         // Core
         $this->oPhpPresentation->createSlide();
         $this->oPhpPresentation->setActiveSlideIndex($this->oPhpPresentation->getSlideCount() - 1);
         // Background
         $oElement = $xmlReader->getElement('/p:sld/p:cSld/p:bg/p:bgPr');
         if ($oElement) {
             $oElementColor = $xmlReader->getElement('a:solidFill/a:srgbClr', $oElement);
             if ($oElementColor) {
                 // Color
                 $oColor = new Color();
                 $oColor->setRGB($oElementColor->hasAttribute('val') ? $oElementColor->getAttribute('val') : null);
                 // Background
                 $oBackground = new \PhpOffice\PhpPresentation\Slide\Background\Color();
                 $oBackground->setColor($oColor);
                 // Slide Background
                 $oSlide = $this->oPhpPresentation->getActiveSlide();
                 $oSlide->setBackground($oBackground);
             }
             $oElementImage = $xmlReader->getElement('a:blipFill/a:blip', $oElement);
             if ($oElementImage) {
                 $relImg = $this->arrayRels['ppt/slides/_rels/' . $baseFile . '.rels'][$oElementImage->getAttribute('r:embed')];
                 if (is_array($relImg)) {
                     // File
                     $pathImage = 'ppt/slides/' . $relImg['Target'];
                     $pathImage = explode('/', $pathImage);
                     foreach ($pathImage as $key => $partPath) {
                         if ($partPath == '..') {
                             unset($pathImage[$key - 1]);
                             unset($pathImage[$key]);
                         }
                     }
                     $pathImage = implode('/', $pathImage);
                     $contentImg = $this->oZip->getFromName($pathImage);
                     $tmpBkgImg = tempnam(sys_get_temp_dir(), 'PhpPresentationReaderPpt2007Bkg');
                     file_put_contents($tmpBkgImg, $contentImg);
                     // Background
                     $oBackground = new \PhpOffice\PhpPresentation\Slide\Background\Image();
                     $oBackground->setPath($tmpBkgImg);
                     // Slide Background
                     $oSlide = $this->oPhpPresentation->getActiveSlide();
                     $oSlide->setBackground($oBackground);
                 }
             }
         }
         // Shapes
         foreach ($xmlReader->getElements('/p:sld/p:cSld/p:spTree/*') as $oNode) {
             switch ($oNode->tagName) {
                 case 'p:pic':
                     $this->loadShapeDrawing($xmlReader, $oNode, $baseFile);
                     break;
                 case 'p:sp':
                     $this->loadShapeRichText($xmlReader, $oNode, $baseFile);
                     break;
                 default:
                     //var_export($oNode->tagName);
             }
         }
         // Layout
         $oLayoutPack = new TemplateBased($this->filename);
         $oSlide = $this->oPhpPresentation->getActiveSlide();
         foreach ($this->arrayRels['ppt/slides/_rels/' . $baseFile . '.rels'] as $valueRel) {
             if ($valueRel['Type'] == 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/slideLayout') {
                 $layoutId = $valueRel['Target'];
                 $layoutId = str_replace('../slideLayouts/slideLayout', '', $layoutId);
                 $layoutId = str_replace('.xml', '', $layoutId);
                 $layoutName = $oLayoutPack->findLayoutName((int) $layoutId, $oSlide->getSlideMasterId());
                 $oSlide->setSlideLayout($layoutName);
                 break;
             }
         }
     }
 }