示例#1
0
 public function testOffset()
 {
     $object = new Slide();
     $this->assertNotNull($object->getOffsetX());
     $object = new Slide();
     $this->assertNotNull($object->getOffsetY());
 }
示例#2
0
 /**
  * Write slide to XML format
  *
  * @param  \PhpOffice\PhpPresentation\Slide $pSlide
  * @return string              XML Output
  * @throws \Exception
  */
 public function writeSlide(Slide $pSlide)
 {
     // Create XML writer
     $objWriter = new XMLWriter(XMLWriter::STORAGE_MEMORY);
     // XML header
     $objWriter->startDocument('1.0', 'UTF-8', 'yes');
     // p:sld
     $objWriter->startElement('p:sld');
     $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');
     // p:cSld
     $objWriter->startElement('p:cSld');
     // Background
     if ($pSlide->getBackground() instanceof Slide\AbstractBackground) {
         $oBackground = $pSlide->getBackground();
         // p:bg
         $objWriter->startElement('p:bg');
         // p:bgPr
         $objWriter->startElement('p:bgPr');
         if ($oBackground instanceof Slide\Background\Color) {
             // a:solidFill
             $objWriter->startElement('a:solidFill');
             // a:srgbClr
             $objWriter->startElement('a:srgbClr');
             $objWriter->writeAttribute('val', $oBackground->getColor()->getRGB());
             $objWriter->endElement();
             // > a:solidFill
             $objWriter->endElement();
         }
         if ($oBackground instanceof Slide\Background\Image) {
             // a:blipFill
             $objWriter->startElement('a:blipFill');
             // a:blip
             $objWriter->startElement('a:blip');
             $objWriter->writeAttribute('r:embed', $oBackground->relationId);
             // > a:blipFill
             $objWriter->endElement();
             // a:stretch
             $objWriter->startElement('a:stretch');
             // a:fillRect
             $objWriter->writeElement('a:fillRect');
             // > a:stretch
             $objWriter->endElement();
             // > a:blipFill
             $objWriter->endElement();
         }
         // > p:bgPr
         $objWriter->endElement();
         // > p:bg
         $objWriter->endElement();
     }
     // p:spTree
     $objWriter->startElement('p:spTree');
     // p:nvGrpSpPr
     $objWriter->startElement('p:nvGrpSpPr');
     // p:cNvPr
     $objWriter->startElement('p:cNvPr');
     $objWriter->writeAttribute('id', '1');
     $objWriter->writeAttribute('name', '');
     $objWriter->endElement();
     // p:cNvGrpSpPr
     $objWriter->writeElement('p:cNvGrpSpPr', null);
     // p:nvPr
     $objWriter->writeElement('p:nvPr', null);
     $objWriter->endElement();
     // p:grpSpPr
     $objWriter->startElement('p:grpSpPr');
     // a:xfrm
     $objWriter->startElement('a:xfrm');
     // a:off
     $objWriter->startElement('a:off');
     $objWriter->writeAttribute('x', CommonDrawing::pixelsToEmu($pSlide->getOffsetX()));
     $objWriter->writeAttribute('y', CommonDrawing::pixelsToEmu($pSlide->getOffsetY()));
     $objWriter->endElement();
     // a:off
     // a:ext
     $objWriter->startElement('a:ext');
     $objWriter->writeAttribute('cx', CommonDrawing::pixelsToEmu($pSlide->getExtentX()));
     $objWriter->writeAttribute('cy', CommonDrawing::pixelsToEmu($pSlide->getExtentY()));
     $objWriter->endElement();
     // a:ext
     // a:chOff
     $objWriter->startElement('a:chOff');
     $objWriter->writeAttribute('x', CommonDrawing::pixelsToEmu($pSlide->getOffsetX()));
     $objWriter->writeAttribute('y', CommonDrawing::pixelsToEmu($pSlide->getOffsetY()));
     $objWriter->endElement();
     // a:chOff
     // a:chExt
     $objWriter->startElement('a:chExt');
     $objWriter->writeAttribute('cx', CommonDrawing::pixelsToEmu($pSlide->getExtentX()));
     $objWriter->writeAttribute('cy', CommonDrawing::pixelsToEmu($pSlide->getExtentY()));
     $objWriter->endElement();
     // a:chExt
     $objWriter->endElement();
     $objWriter->endElement();
     // Loop shapes
     $shapeId = 0;
     $shapes = $pSlide->getShapeCollection();
     foreach ($shapes as $shape) {
         // Increment $shapeId
         ++$shapeId;
         // Check type
         if ($shape instanceof RichText) {
             $this->writeShapeText($objWriter, $shape, $shapeId);
         } elseif ($shape instanceof ShapeTable) {
             $this->writeShapeTable($objWriter, $shape, $shapeId);
         } elseif ($shape instanceof Line) {
             $this->writeShapeLine($objWriter, $shape, $shapeId);
         } elseif ($shape instanceof ShapeChart) {
             $this->writeShapeChart($objWriter, $shape, $shapeId);
         } elseif ($shape instanceof AbstractDrawing) {
             $this->writeShapePic($objWriter, $shape, $shapeId);
         } elseif ($shape instanceof Group) {
             $this->writeShapeGroup($objWriter, $shape, $shapeId);
         }
     }
     // TODO
     $objWriter->endElement();
     $objWriter->endElement();
     // p:clrMapOvr
     $objWriter->startElement('p:clrMapOvr');
     // a:masterClrMapping
     $objWriter->writeElement('a:masterClrMapping', null);
     $objWriter->endElement();
     if (!is_null($pSlide->getTransition())) {
         $this->writeTransition($objWriter, $pSlide->getTransition());
     }
     $objWriter->endElement();
     // Return
     return $objWriter->getData();
 }
示例#3
0
 /**
  * Write slide to XML format
  *
  * @param  \PhpOffice\PhpPresentation\Slide $pSlide
  * @return string              XML Output
  * @throws \Exception
  */
 public function writeSlide(Slide $pSlide)
 {
     // Create XML writer
     $objWriter = new XMLWriter(XMLWriter::STORAGE_MEMORY);
     // XML header
     $objWriter->startDocument('1.0', 'UTF-8', 'yes');
     // p:sld
     $objWriter->startElement('p:sld');
     $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->writeAttributeIf(!$pSlide->isVisible(), 'show', 0);
     // p:sld/p:cSld
     $objWriter->startElement('p:cSld');
     // Background
     if ($pSlide->getBackground() instanceof Slide\AbstractBackground) {
         $oBackground = $pSlide->getBackground();
         // p:bg
         $objWriter->startElement('p:bg');
         // p:bgPr
         $objWriter->startElement('p:bgPr');
         if ($oBackground instanceof Slide\Background\Color) {
             // a:solidFill
             $objWriter->startElement('a:solidFill');
             $this->writeColor($objWriter, $oBackground->getColor());
             // > a:solidFill
             $objWriter->endElement();
         }
         if ($oBackground instanceof Slide\Background\Image) {
             // a:blipFill
             $objWriter->startElement('a:blipFill');
             // a:blip
             $objWriter->startElement('a:blip');
             $objWriter->writeAttribute('r:embed', $oBackground->relationId);
             // > a:blipFill
             $objWriter->endElement();
             // a:stretch
             $objWriter->startElement('a:stretch');
             // a:fillRect
             $objWriter->writeElement('a:fillRect');
             // > a:stretch
             $objWriter->endElement();
             // > a:blipFill
             $objWriter->endElement();
         }
         // > p:bgPr
         $objWriter->endElement();
         // > p:bg
         $objWriter->endElement();
     }
     // p:spTree
     $objWriter->startElement('p:spTree');
     // p:nvGrpSpPr
     $objWriter->startElement('p:nvGrpSpPr');
     // p:cNvPr
     $objWriter->startElement('p:cNvPr');
     $objWriter->writeAttribute('id', '1');
     $objWriter->writeAttribute('name', '');
     $objWriter->endElement();
     // p:cNvGrpSpPr
     $objWriter->writeElement('p:cNvGrpSpPr', null);
     // p:nvPr
     $objWriter->writeElement('p:nvPr', null);
     $objWriter->endElement();
     // p:grpSpPr
     $objWriter->startElement('p:grpSpPr');
     // a:xfrm
     $objWriter->startElement('a:xfrm');
     // a:off
     $objWriter->startElement('a:off');
     $objWriter->writeAttribute('x', CommonDrawing::pixelsToEmu($pSlide->getOffsetX()));
     $objWriter->writeAttribute('y', CommonDrawing::pixelsToEmu($pSlide->getOffsetY()));
     $objWriter->endElement();
     // a:off
     // a:ext
     $objWriter->startElement('a:ext');
     $objWriter->writeAttribute('cx', CommonDrawing::pixelsToEmu($pSlide->getExtentX()));
     $objWriter->writeAttribute('cy', CommonDrawing::pixelsToEmu($pSlide->getExtentY()));
     $objWriter->endElement();
     // a:ext
     // a:chOff
     $objWriter->startElement('a:chOff');
     $objWriter->writeAttribute('x', CommonDrawing::pixelsToEmu($pSlide->getOffsetX()));
     $objWriter->writeAttribute('y', CommonDrawing::pixelsToEmu($pSlide->getOffsetY()));
     $objWriter->endElement();
     // a:chOff
     // a:chExt
     $objWriter->startElement('a:chExt');
     $objWriter->writeAttribute('cx', CommonDrawing::pixelsToEmu($pSlide->getExtentX()));
     $objWriter->writeAttribute('cy', CommonDrawing::pixelsToEmu($pSlide->getExtentY()));
     $objWriter->endElement();
     // a:chExt
     $objWriter->endElement();
     $objWriter->endElement();
     // Loop shapes
     $this->writeShapeCollection($objWriter, $pSlide->getShapeCollection());
     // TODO
     $objWriter->endElement();
     $objWriter->endElement();
     // p:clrMapOvr
     $objWriter->startElement('p:clrMapOvr');
     // p:clrMapOvr\a:masterClrMapping
     $objWriter->writeElement('a:masterClrMapping', null);
     // ##p:clrMapOvr
     $objWriter->endElement();
     $this->writeSlideTransition($objWriter, $pSlide->getTransition());
     $this->writeSlideAnimations($objWriter, $pSlide);
     $objWriter->endElement();
     // Return
     return $objWriter->getData();
 }