Create a masterslide and add it to this presentation
public createMasterSlide ( ) : |
||
return |
private function loadMasterSlide($sPart, $baseFile) { $xmlReader = new XMLReader(); if ($xmlReader->getDomFromString($sPart)) { // Core $oSlideMaster = $this->oPhpPresentation->createMasterSlide(); $oSlideMaster->setTextStyles(new TextStyle(false)); $oSlideMaster->setRelsIndex('ppt/slideMasters/_rels/' . $baseFile . '.rels'); // Background $oElement = $xmlReader->getElement('/p:sldMaster/p:cSld/p:bg'); if ($oElement) { $this->loadSlideBackground($xmlReader, $oElement, $oSlideMaster); } // Shapes $arrayElements = $xmlReader->getElements('/p:sldMaster/p:cSld/p:spTree/*'); if ($arrayElements) { $this->loadSlideShapes($oSlideMaster, $arrayElements, $xmlReader); } // Header & Footer // ColorMapping $colorMap = array(); $oElement = $xmlReader->getElement('/p:sldMaster/p:clrMap'); if ($oElement->hasAttributes()) { foreach ($oElement->attributes as $attr) { $colorMap[$attr->nodeName] = $attr->nodeValue; } $oSlideMaster->colorMap->setMapping($colorMap); } // TextStyles $arrayElementTxStyles = $xmlReader->getElements('/p:sldMaster/p:txStyles/*'); if ($arrayElementTxStyles) { foreach ($arrayElementTxStyles as $oElementTxStyle) { $arrayElementsLvl = $xmlReader->getElements('/p:sldMaster/p:txStyles/' . $oElementTxStyle->nodeName . '/*'); foreach ($arrayElementsLvl as $oElementLvl) { if ($oElementLvl->nodeName == 'a:extLst') { continue; } $oRTParagraph = new Paragraph(); if ($oElementLvl->nodeName == 'a:defPPr') { $level = 0; } else { $level = str_replace('a:lvl', '', $oElementLvl->nodeName); $level = str_replace('pPr', '', $level); } if ($oElementLvl->hasAttribute('algn')) { $oRTParagraph->getAlignment()->setHorizontal($oElementLvl->getAttribute('algn')); } if ($oElementLvl->hasAttribute('marL')) { $val = $oElementLvl->getAttribute('marL'); $val = CommonDrawing::emuToPixels($val); $oRTParagraph->getAlignment()->setMarginLeft($val); } if ($oElementLvl->hasAttribute('marR')) { $val = $oElementLvl->getAttribute('marR'); $val = CommonDrawing::emuToPixels($val); $oRTParagraph->getAlignment()->setMarginRight($val); } if ($oElementLvl->hasAttribute('indent')) { $val = $oElementLvl->getAttribute('indent'); $val = CommonDrawing::emuToPixels($val); $oRTParagraph->getAlignment()->setIndent($val); } $oElementLvlDefRPR = $xmlReader->getElement('a:defRPr', $oElementLvl); if ($oElementLvlDefRPR) { if ($oElementLvlDefRPR->hasAttribute('sz')) { $oRTParagraph->getFont()->setSize($oElementLvlDefRPR->getAttribute('sz') / 100); } if ($oElementLvlDefRPR->hasAttribute('b') && $oElementLvlDefRPR->getAttribute('b') == 1) { $oRTParagraph->getFont()->setBold(true); } if ($oElementLvlDefRPR->hasAttribute('i') && $oElementLvlDefRPR->getAttribute('i') == 1) { $oRTParagraph->getFont()->setItalic(true); } } $oElementSchemeColor = $xmlReader->getElement('a:defRPr/a:solidFill/a:schemeClr', $oElementLvl); if ($oElementSchemeColor) { if ($oElementSchemeColor->hasAttribute('val')) { $oRTParagraph->getFont()->setColor(new SchemeColor())->getColor()->setValue($oElementSchemeColor->getAttribute('val')); } } switch ($oElementTxStyle->nodeName) { case 'p:bodyStyle': $oSlideMaster->getTextStyles()->setBodyStyleAtLvl($oRTParagraph, $level); break; case 'p:otherStyle': $oSlideMaster->getTextStyles()->setOtherStyleAtLvl($oRTParagraph, $level); break; case 'p:titleStyle': $oSlideMaster->getTextStyles()->setTitleStyleAtLvl($oRTParagraph, $level); break; } } } } // Load the theme foreach ($this->arrayRels[$oSlideMaster->getRelsIndex()] as $arrayRel) { if ($arrayRel['Type'] == 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/theme') { $pptTheme = $this->oZip->getFromName('ppt/' . substr($arrayRel['Target'], strrpos($arrayRel['Target'], '../') + 3)); if ($pptTheme !== false) { $this->loadTheme($pptTheme, $oSlideMaster); } break; } } // Load the Layoutslide foreach ($xmlReader->getElements('/p:sldMaster/p:sldLayoutIdLst/p:sldLayoutId') as $oElement) { $rId = $oElement->getAttribute('r:id'); // Get the path to the masterslide from the array with _rels files $pathLayoutSlide = isset($this->arrayRels[$oSlideMaster->getRelsIndex()][$rId]) ? $this->arrayRels[$oSlideMaster->getRelsIndex()][$rId]['Target'] : ''; if (!empty($pathLayoutSlide)) { $pptLayoutSlide = $this->oZip->getFromName('ppt/' . substr($pathLayoutSlide, strrpos($pathLayoutSlide, '../') + 3)); if ($pptLayoutSlide !== false) { $this->loadRels('ppt/slideLayouts/_rels/' . basename($pathLayoutSlide) . '.rels'); $oSlideMaster->addSlideLayout($this->loadLayoutSlide($pptLayoutSlide, basename($pathLayoutSlide), $oSlideMaster)); } } } } }