Exemplo n.º 1
0
 public function testTransition()
 {
     $object = new Slide();
     $oTransition = new Transition();
     $this->assertNull($object->getTransition());
     $this->assertInstanceOf('PhpOffice\\PhpPowerpoint\\Slide', $object->setTransition());
     $this->assertNull($object->getTransition());
     $this->assertInstanceOf('PhpOffice\\PhpPowerpoint\\Slide', $object->setTransition($oTransition));
     $this->assertInstanceOf('PhpOffice\\PhpPowerpoint\\Slide\\Transition', $object->getTransition());
     $this->assertInstanceOf('PhpOffice\\PhpPowerpoint\\Slide', $object->setTransition(null));
     $this->assertNull($object->getTransition());
 }
Exemplo n.º 2
0
 public function testSlideMasterId()
 {
     $value = rand(1, 100);
     $object = new Slide();
     $this->assertEquals(1, $object->getSlideMasterId());
     $this->assertInstanceOf('PhpOffice\\PhpPowerpoint\\Slide', $object->setSlideMasterId());
     $this->assertEquals(1, $object->getSlideMasterId());
     $this->assertInstanceOf('PhpOffice\\PhpPowerpoint\\Slide', $object->setSlideMasterId($value));
     $this->assertEquals($value, $object->getSlideMasterId());
 }
Exemplo n.º 3
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;
         }
     }
     $objWriter->endElement();
     // > style:style
     $objWriter->endElement();
 }
Exemplo n.º 4
0
 /**
  * Write slide relationships to XML format
  *
  * @param  \PhpOffice\PhpPowerpoint\Slide $pSlide
  * @return string              XML Output
  * @throws \Exception
  */
 public function writeSlideRelationships(SlideElement $pSlide)
 {
     // Create XML writer
     $objWriter = $this->getXMLWriter();
     // XML header
     $objWriter->startDocument('1.0', 'UTF-8', 'yes');
     // Relationships
     $objWriter->startElement('Relationships');
     $objWriter->writeAttribute('xmlns', 'http://schemas.openxmlformats.org/package/2006/relationships');
     // Starting relation id
     $relId = 1;
     // Write slideLayout relationship
     $parentWriter = $this->getParentWriter();
     if ($parentWriter instanceof PowerPoint2007) {
         $layoutPack = $parentWriter->getLayoutPack();
         $layoutIndex = $layoutPack->findlayoutIndex($pSlide->getSlideLayout(), $pSlide->getSlideMasterId());
         $this->writeRelationship($objWriter, $relId++, 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/slideLayout', '../slideLayouts/slideLayout' . ($layoutIndex + 1) . '.xml');
     }
     // Write drawing relationships?
     if ($pSlide->getShapeCollection()->count() > 0) {
         // Loop trough images and write relationships
         $iterator = $pSlide->getShapeCollection()->getIterator();
         while ($iterator->valid()) {
             if ($iterator->current() instanceof ShapeDrawing || $iterator->current() instanceof MemoryDrawing) {
                 // Write relationship for image drawing
                 $this->writeRelationship($objWriter, $relId, 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/image', '../media/' . str_replace(' ', '_', $iterator->current()->getIndexedFilename()));
                 $iterator->current()->relationId = 'rId' . $relId;
                 ++$relId;
             } elseif ($iterator->current() instanceof ShapeChart) {
                 // Write relationship for chart drawing
                 $this->writeRelationship($objWriter, $relId, 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/chart', '../charts/' . $iterator->current()->getIndexedFilename());
                 $iterator->current()->relationId = 'rId' . $relId;
                 ++$relId;
             }
             $iterator->next();
         }
     }
     // Write hyperlink relationships?
     if ($pSlide->getShapeCollection()->count() > 0) {
         // Loop trough hyperlinks and write relationships
         $iterator = $pSlide->getShapeCollection()->getIterator();
         while ($iterator->valid()) {
             // Hyperlink on shape
             if ($iterator->current()->hasHyperlink()) {
                 // Write relationship for hyperlink
                 $hyperlink = $iterator->current()->getHyperlink();
                 $hyperlink->relationId = 'rId' . $relId;
                 if (!$hyperlink->isInternal()) {
                     $this->writeRelationship($objWriter, $relId, 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/hyperlink', $hyperlink->getUrl(), 'External');
                 } else {
                     $this->writeRelationship($objWriter, $relId, 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/slide', 'slide' . $hyperlink->getSlideNumber() . '.xml');
                 }
                 ++$relId;
             }
             // Hyperlink on rich text run
             if ($iterator->current() instanceof RichText) {
                 foreach ($iterator->current()->getParagraphs() as $paragraph) {
                     foreach ($paragraph->getRichTextElements() as $element) {
                         if ($element instanceof Run || $element instanceof TextElement) {
                             if ($element->hasHyperlink()) {
                                 // Write relationship for hyperlink
                                 $hyperlink = $element->getHyperlink();
                                 $hyperlink->relationId = 'rId' . $relId;
                                 if (!$hyperlink->isInternal()) {
                                     $this->writeRelationship($objWriter, $relId, 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/hyperlink', $hyperlink->getUrl(), 'External');
                                 } else {
                                     $this->writeRelationship($objWriter, $relId, 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/slide', 'slide' . $hyperlink->getSlideNumber() . '.xml');
                                 }
                                 ++$relId;
                             }
                         }
                     }
                 }
             }
             $iterator->next();
         }
     }
     $objWriter->endElement();
     // Return
     return $objWriter->getData();
 }
Exemplo n.º 5
0
 /**
  * Get hash code
  *
  * @return string Hash code
  */
 public function getHashCode()
 {
     return md5((is_object($this->slide) ? $this->slide->getHashCode() : '') . $this->offsetX . $this->offsetY . $this->width . $this->height . $this->rotation . $this->getFill()->getHashCode() . $this->shadow->getHashCode() . (is_null($this->hyperlink) ? '' : $this->hyperlink->getHashCode()) . __CLASS__);
 }
Exemplo n.º 6
0
 /**
  * Add external slide
  *
  * @param  \PhpOffice\PhpPowerpoint\Slide $slide External slide to add
  * @throws \Exception
  * @return \PhpOffice\PhpPowerpoint\Slide
  */
 public function addExternalSlide(Slide $slide)
 {
     $slide->rebindParent($this);
     return $this->addSlide($slide);
 }