Inheritance: extends AbstractSlide, implements PhpOffice\PhpPresentation\ComparableInterface, implements PhpOffice\PhpPresentation\ShapeContainerInterface
Exemplo n.º 1
0
 public function testLayoutName()
 {
     // Mocks
     $mockSlideMaster = $this->getMockForAbstractClass('PhpOffice\\PhpPresentation\\Slide\\SlideMaster');
     // Expected
     $expectedLayoutName = 'Title' . rand(1, 100);
     $object = new SlideLayout($mockSlideMaster);
     $this->assertNull($object->getLayoutName());
     $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Slide\\SlideLayout', $object->setLayoutName($expectedLayoutName));
     $this->assertEquals($expectedLayoutName, $object->getLayoutName());
 }
Exemplo n.º 2
0
 /**
  * Write slide to XML format
  *
  * @param  \PhpOffice\PhpPresentation\Slide\SlideLayout $pSlideLayout
  * @return string XML Output
  * @throws \Exception
  */
 public function writeSlideLayout(SlideLayout $pSlideLayout)
 {
     // Create XML writer
     $objWriter = new XMLWriter(XMLWriter::STORAGE_MEMORY);
     // XML header
     $objWriter->startDocument('1.0', 'UTF-8', 'yes');
     // p:sldLayout
     $objWriter->startElement('p:sldLayout');
     $objWriter->writeAttribute('xmlns:a', 'http://schemas.openxmlformats.org/drawingml/2006/main');
     $objWriter->writeAttribute('xmlns:r', 'http://schemas.openxmlformats.org/officeDocument/2006/relationships');
     $objWriter->writeAttribute('xmlns:p', 'http://schemas.openxmlformats.org/presentationml/2006/main');
     $objWriter->writeAttribute('preserve', 1);
     // p:sldLayout\p:cSld
     $objWriter->startElement('p:cSld');
     $objWriter->writeAttributeIf($pSlideLayout->getLayoutName() != '', 'name', $pSlideLayout->getLayoutName());
     // Background
     $this->writeSlideBackground($pSlideLayout, $objWriter);
     // p:sldLayout\p:cSld\p:spTree
     $objWriter->startElement('p:spTree');
     // p:sldLayout\p:cSld\p:spTree\p:nvGrpSpPr
     $objWriter->startElement('p:nvGrpSpPr');
     // p:sldLayout\p:cSld\p:spTree\p:nvGrpSpPr\p:cNvPr
     $objWriter->startElement('p:cNvPr');
     $objWriter->writeAttribute('id', '1');
     $objWriter->writeAttribute('name', '');
     $objWriter->endElement();
     // p:sldLayout\p:cSld\p:spTree\p:nvGrpSpPr\p:cNvGrpSpPr
     $objWriter->writeElement('p:cNvGrpSpPr', null);
     // p:sldLayout\p:cSld\p:spTree\p:nvGrpSpPr\p:nvPr
     $objWriter->writeElement('p:nvPr', null);
     // p:sldLayout\p:cSld\p:spTree\p:nvGrpSpPr
     $objWriter->endElement();
     // p:sldLayout\p:cSld\p:spTree\p:grpSpPr
     $objWriter->startElement('p:grpSpPr');
     // p:sldLayout\p:cSld\p:spTree\p:grpSpPr\a:xfrm
     $objWriter->startElement('a:xfrm');
     // p:sldLayout\p:cSld\p:spTree\p:grpSpPr\a:xfrm\a:off
     $objWriter->startElement('a:off');
     $objWriter->writeAttribute('x', CommonDrawing::pixelsToEmu($pSlideLayout->getOffsetX()));
     $objWriter->writeAttribute('y', CommonDrawing::pixelsToEmu($pSlideLayout->getOffsetY()));
     $objWriter->endElement();
     // p:sldLayout\p:cSld\p:spTree\p:grpSpPr\a:xfrm\a:ext
     $objWriter->startElement('a:ext');
     $objWriter->writeAttribute('cx', CommonDrawing::pixelsToEmu($pSlideLayout->getExtentX()));
     $objWriter->writeAttribute('cy', CommonDrawing::pixelsToEmu($pSlideLayout->getExtentY()));
     $objWriter->endElement();
     // p:sldLayout\p:cSld\p:spTree\p:grpSpPr\a:xfrm\a:chOff
     $objWriter->startElement('a:chOff');
     $objWriter->writeAttribute('x', CommonDrawing::pixelsToEmu($pSlideLayout->getOffsetX()));
     $objWriter->writeAttribute('y', CommonDrawing::pixelsToEmu($pSlideLayout->getOffsetY()));
     $objWriter->endElement();
     // p:sldLayout\p:cSld\p:spTree\p:grpSpPr\a:xfrm\a:chExt
     $objWriter->startElement('a:chExt');
     $objWriter->writeAttribute('cx', CommonDrawing::pixelsToEmu($pSlideLayout->getExtentX()));
     $objWriter->writeAttribute('cy', CommonDrawing::pixelsToEmu($pSlideLayout->getExtentY()));
     $objWriter->endElement();
     // p:sldLayout\p:cSld\p:spTree\p:grpSpPr\a:xfrm\
     $objWriter->endElement();
     // p:sldLayout\p:cSld\p:spTree\p:grpSpPr\
     $objWriter->endElement();
     // Loop shapes
     $this->writeShapeCollection($objWriter, $pSlideLayout->getShapeCollection());
     // p:sldLayout\p:cSld\p:spTree\
     $objWriter->endElement();
     // p:sldLayout\p:cSld\
     $objWriter->endElement();
     // p:sldLayout\p:clrMapOvr
     $objWriter->startElement('p:clrMapOvr');
     $arrayDiff = array_diff_assoc(ColorMap::$mappingDefault, $pSlideLayout->colorMap->getMapping());
     if (!empty($arrayDiff)) {
         // p:sldLayout\p:clrMapOvr\a:overrideClrMapping
         $objWriter->startElement('a:overrideClrMapping');
         foreach ($pSlideLayout->colorMap->getMapping() as $n => $v) {
             $objWriter->writeAttribute($n, $v);
         }
         $objWriter->endElement();
     } else {
         // p:sldLayout\p:clrMapOvr\a:masterClrMapping
         $objWriter->writeElement('a:masterClrMapping');
     }
     // p:sldLayout\p:clrMapOvr\
     $objWriter->endElement();
     if (!is_null($pSlideLayout->getTransition())) {
         $this->writeTransition($objWriter, $pSlideLayout->getTransition());
     }
     // p:sldLayout\
     $objWriter->endElement();
     return $objWriter->getData();
 }
Exemplo n.º 3
0
 private function loadLayoutSlide($sPart, $baseFile, SlideMaster $oSlideMaster)
 {
     $xmlReader = new XMLReader();
     if ($xmlReader->getDomFromString($sPart)) {
         // Core
         $oSlideLayout = new SlideLayout($oSlideMaster);
         $oSlideLayout->setRelsIndex('ppt/slideLayouts/_rels/' . $baseFile . '.rels');
         // Name
         $oElement = $xmlReader->getElement('/p:sldLayout/p:cSld');
         if ($oElement && $oElement->hasAttribute('name')) {
             $oSlideLayout->setLayoutName($oElement->getAttribute('name'));
         }
         // Background
         $oElement = $xmlReader->getElement('/p:sldLayout/p:cSld/p:bg');
         if ($oElement) {
             $this->loadSlideBackground($xmlReader, $oElement, $oSlideLayout);
         }
         // ColorMapping
         $oElement = $xmlReader->getElement('/p:sldLayout/p:clrMapOvr/a:overrideClrMapping');
         if ($oElement && $oElement->hasAttributes()) {
             $colorMap = array();
             foreach ($oElement->attributes as $attr) {
                 $colorMap[$attr->nodeName] = $attr->nodeValue;
             }
             $oSlideLayout->colorMap->setMapping($colorMap);
         }
         // Shapes
         $oElements = $xmlReader->getElements('/p:sldLayout/p:cSld/p:spTree/*');
         if ($oElements) {
             $this->loadSlideShapes($oSlideLayout, $oElements, $xmlReader);
         }
         $this->arraySlideLayouts[$baseFile] =& $oSlideLayout;
         return $oSlideLayout;
     }
     return null;
 }