Example #1
0
 public function testTransition()
 {
     $object = new Slide();
     $oTransition = new Transition();
     $this->assertNull($object->getTransition());
     $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Slide', $object->setTransition());
     $this->assertNull($object->getTransition());
     $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Slide', $object->setTransition($oTransition));
     $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Slide\\Transition', $object->getTransition());
     $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Slide', $object->setTransition(null));
     $this->assertNull($object->getTransition());
 }
Example #2
0
 /**
  * Write style of a slide
  * @param XMLWriter $objWriter
  * @param Slide $slide
  * @param int $incPage
  */
 public function writeStyleSlide(XMLWriter $objWriter, Slide $slide, $incPage)
 {
     // style:style
     $objWriter->startElement('style:style');
     $objWriter->writeAttribute('style:family', 'drawing-page');
     $objWriter->writeAttribute('style:name', 'stylePage' . $incPage);
     // style:style/style:drawing-page-properties
     $objWriter->startElement('style:drawing-page-properties');
     if (!is_null($oTransition = $slide->getTransition())) {
         $objWriter->writeAttribute('presentation:duration', 'PT' . number_format($oTransition->getAdvanceTimeTrigger() / 1000, 6, '.', '') . 'S');
         if ($oTransition->hasManualTrigger()) {
             $objWriter->writeAttribute('presentation:transition-type', 'manual');
         } elseif ($oTransition->hasTimeTrigger()) {
             $objWriter->writeAttribute('presentation:transition-type', 'automatic');
         }
         switch ($oTransition->getSpeed()) {
             case Transition::SPEED_FAST:
                 $objWriter->writeAttribute('presentation:transition-speed', 'fast');
                 break;
             case Transition::SPEED_MEDIUM:
                 $objWriter->writeAttribute('presentation:transition-speed', 'medium');
                 break;
             case Transition::SPEED_SLOW:
                 $objWriter->writeAttribute('presentation:transition-speed', 'slow');
                 break;
         }
         /**
          * http://docs.oasis-open.org/office/v1.2/os/OpenDocument-v1.2-os-part1.html#property-presentation_transition-style
          */
         switch ($oTransition->getTransitionType()) {
             case Transition::TRANSITION_BLINDS_HORIZONTAL:
                 $objWriter->writeAttribute('presentation:transition-style', 'horizontal-stripes');
                 break;
             case Transition::TRANSITION_BLINDS_VERTICAL:
                 $objWriter->writeAttribute('presentation:transition-style', 'vertical-stripes');
                 break;
             case Transition::TRANSITION_CHECKER_HORIZONTAL:
                 $objWriter->writeAttribute('presentation:transition-style', 'horizontal-checkerboard');
                 break;
             case Transition::TRANSITION_CHECKER_VERTICAL:
                 $objWriter->writeAttribute('presentation:transition-style', 'vertical-checkerboard');
                 break;
             case Transition::TRANSITION_CIRCLE_HORIZONTAL:
                 $objWriter->writeAttribute('presentation:transition-style', 'none');
                 break;
             case Transition::TRANSITION_CIRCLE_VERTICAL:
                 $objWriter->writeAttribute('presentation:transition-style', 'none');
                 break;
             case Transition::TRANSITION_COMB_HORIZONTAL:
                 $objWriter->writeAttribute('presentation:transition-style', 'none');
                 break;
             case Transition::TRANSITION_COMB_VERTICAL:
                 $objWriter->writeAttribute('presentation:transition-style', 'none');
                 break;
             case Transition::TRANSITION_COVER_DOWN:
                 $objWriter->writeAttribute('presentation:transition-style', 'uncover-to-bottom');
                 break;
             case Transition::TRANSITION_COVER_LEFT:
                 $objWriter->writeAttribute('presentation:transition-style', 'uncover-to-left');
                 break;
             case Transition::TRANSITION_COVER_LEFT_DOWN:
                 $objWriter->writeAttribute('presentation:transition-style', 'uncover-to-lowerleft');
                 break;
             case Transition::TRANSITION_COVER_LEFT_UP:
                 $objWriter->writeAttribute('presentation:transition-style', 'uncover-to-upperleft');
                 break;
             case Transition::TRANSITION_COVER_RIGHT:
                 $objWriter->writeAttribute('presentation:transition-style', 'uncover-to-right');
                 break;
             case Transition::TRANSITION_COVER_RIGHT_DOWN:
                 $objWriter->writeAttribute('presentation:transition-style', 'uncover-to-lowerright');
                 break;
             case Transition::TRANSITION_COVER_RIGHT_UP:
                 $objWriter->writeAttribute('presentation:transition-style', 'uncover-to-upperright');
                 break;
             case Transition::TRANSITION_COVER_UP:
                 $objWriter->writeAttribute('presentation:transition-style', 'uncover-to-top');
                 break;
             case Transition::TRANSITION_CUT:
                 $objWriter->writeAttribute('presentation:transition-style', 'none');
                 break;
             case Transition::TRANSITION_DIAMOND:
                 $objWriter->writeAttribute('presentation:transition-style', 'none');
                 break;
             case Transition::TRANSITION_DISSOLVE:
                 $objWriter->writeAttribute('presentation:transition-style', 'dissolve');
                 break;
             case Transition::TRANSITION_FADE:
                 $objWriter->writeAttribute('presentation:transition-style', 'fade-from-center');
                 break;
             case Transition::TRANSITION_NEWSFLASH:
                 $objWriter->writeAttribute('presentation:transition-style', 'none');
                 break;
             case Transition::TRANSITION_PLUS:
                 $objWriter->writeAttribute('presentation:transition-style', 'close');
                 break;
             case Transition::TRANSITION_PULL_DOWN:
                 $objWriter->writeAttribute('presentation:transition-style', 'stretch-from-bottom');
                 break;
             case Transition::TRANSITION_PULL_LEFT:
                 $objWriter->writeAttribute('presentation:transition-style', 'stretch-from-left');
                 break;
             case Transition::TRANSITION_PULL_RIGHT:
                 $objWriter->writeAttribute('presentation:transition-style', 'stretch-from-right');
                 break;
             case Transition::TRANSITION_PULL_UP:
                 $objWriter->writeAttribute('presentation:transition-style', 'stretch-from-top');
                 break;
             case Transition::TRANSITION_PUSH_DOWN:
                 $objWriter->writeAttribute('presentation:transition-style', 'roll-from-bottom');
                 break;
             case Transition::TRANSITION_PUSH_LEFT:
                 $objWriter->writeAttribute('presentation:transition-style', 'roll-from-left');
                 break;
             case Transition::TRANSITION_PUSH_RIGHT:
                 $objWriter->writeAttribute('presentation:transition-style', 'roll-from-right');
                 break;
             case Transition::TRANSITION_PUSH_UP:
                 $objWriter->writeAttribute('presentation:transition-style', 'roll-from-top');
                 break;
             case Transition::TRANSITION_RANDOM:
                 $objWriter->writeAttribute('presentation:transition-style', 'random');
                 break;
             case Transition::TRANSITION_RANDOMBAR_HORIZONTAL:
                 $objWriter->writeAttribute('presentation:transition-style', 'horizontal-lines');
                 break;
             case Transition::TRANSITION_RANDOMBAR_VERTICAL:
                 $objWriter->writeAttribute('presentation:transition-style', 'vertical-lines');
                 break;
             case Transition::TRANSITION_SPLIT_IN_HORIZONTAL:
                 $objWriter->writeAttribute('presentation:transition-style', 'close-horizontal');
                 break;
             case Transition::TRANSITION_SPLIT_OUT_HORIZONTAL:
                 $objWriter->writeAttribute('presentation:transition-style', 'open-horizontal');
                 break;
             case Transition::TRANSITION_SPLIT_IN_VERTICAL:
                 $objWriter->writeAttribute('presentation:transition-style', 'close-vertical');
                 break;
             case Transition::TRANSITION_SPLIT_OUT_VERTICAL:
                 $objWriter->writeAttribute('presentation:transition-style', 'open-vertical');
                 break;
             case Transition::TRANSITION_STRIPS_LEFT_DOWN:
                 $objWriter->writeAttribute('presentation:transition-style', 'none');
                 break;
             case Transition::TRANSITION_STRIPS_LEFT_UP:
                 $objWriter->writeAttribute('presentation:transition-style', 'none');
                 break;
             case Transition::TRANSITION_STRIPS_RIGHT_DOWN:
                 $objWriter->writeAttribute('presentation:transition-style', 'none');
                 break;
             case Transition::TRANSITION_STRIPS_RIGHT_UP:
                 $objWriter->writeAttribute('presentation:transition-style', 'none');
                 break;
             case Transition::TRANSITION_WEDGE:
                 $objWriter->writeAttribute('presentation:transition-style', 'none');
                 break;
             case Transition::TRANSITION_WIPE_DOWN:
                 $objWriter->writeAttribute('presentation:transition-style', 'fade-from-bottom');
                 break;
             case Transition::TRANSITION_WIPE_LEFT:
                 $objWriter->writeAttribute('presentation:transition-style', 'fade-from-left');
                 break;
             case Transition::TRANSITION_WIPE_RIGHT:
                 $objWriter->writeAttribute('presentation:transition-style', 'fade-from-right');
                 break;
             case Transition::TRANSITION_WIPE_UP:
                 $objWriter->writeAttribute('presentation:transition-style', 'fade-from-top');
                 break;
             case Transition::TRANSITION_ZOOM_IN:
                 $objWriter->writeAttribute('presentation:transition-style', 'none');
                 break;
             case Transition::TRANSITION_ZOOM_OUT:
                 $objWriter->writeAttribute('presentation:transition-style', 'none');
                 break;
         }
     }
     $oBackground = $slide->getBackground();
     if ($oBackground instanceof Slide\AbstractBackground) {
         $objWriter->writeAttribute('presentation:background-visible', 'true');
         if ($oBackground instanceof Slide\Background\Color) {
             $objWriter->writeAttribute('draw:fill', 'solid');
             $objWriter->writeAttribute('draw:fill-color', '#' . $oBackground->getColor()->getRGB());
         }
         if ($oBackground instanceof Slide\Background\Image) {
             $objWriter->writeAttribute('draw:fill', 'bitmap');
             $objWriter->writeAttribute('draw:fill-image-name', 'background_' . $incPage);
             $objWriter->writeAttribute('style:repeat', 'stretch');
         }
     }
     $objWriter->endElement();
     // > style:style
     $objWriter->endElement();
 }
Example #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');
     // 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();
 }
Example #4
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();
 }