Skip to content

Add appear animation to phppresentation for Powerpoint2007 writer #178

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 13 commits into from
Closed

Add appear animation to phppresentation for Powerpoint2007 writer #178

wants to merge 13 commits into from

Conversation

JewrassicPark
Copy link
Contributor

Added animation class, added animation tags to Powerpoint2007 Slide Writer, added animation objects to Slide.php

This only supports appear. Shapes can be grouped to appear together or sequentially by order they're added as animations.

Use:

$animation = new Animation(); //create the animation
$currentSlide = $this->pp->getActiveSlide();  //get the current slide
$currentSlide->addAnimation($animation); //add the animation to the current slide
/*
* add n shapes to animation
* every shape in an animation will appear at the same time on click
*/
$animation->addShape($shape); 
$animation->addShape($shape2); 

@Progi1984
Copy link
Member

@JewrassicPark Before merging, you need to fix PHPCS & PHPMd errors :
https://travis-ci.org/PHPOffice/PHPPresentation/jobs/105507570

fixed style issues
fixed style issues
updated for style
@JewrassicPark
Copy link
Contributor Author

ive updated the style in my fork

removed whitespace on line 23
corrected for style
update for style
updated style errors on line 278
Added to writeNote function to add in xml to display slide preview above notes when printing slide
public function getAnimations()
{
return $this->animations;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That lacks a setAnimations(array $animations = array())

@Progi1984
Copy link
Member

@JewrassicPark Could you add a sample ? Which type of animation could you define ?

@JewrassicPark
Copy link
Contributor Author

It only does appear animation currently

Here is a use example:

<?php


    $root = "/php/PHPPresentation/PHPPresentation-develop-Jan-2016";

    use PhpOffice\PhpPresentation\PhpPresentation;
    use PhpOffice\PhpPresentation\Shape\RichText;
    use PhpOffice\PhpPresentation\IOFactory;
    use PhpOffice\PhpPresentation\Style\Fill;
    use PhpOffice\PhpPresentation\Slide\Animation;

    require_once $root.'/src/PhpPresentation/Autoloader.php';
    \PhpOffice\PhpPresentation\Autoloader::register();

    use PhpOffice\Common;
    $commonRoot = "/php/PHPOffice-Common-7-29-2015";
    require_once $commonRoot.'/src/Common/Autoloader.php';
    \PhpOffice\Common\Autoloader::register(); 

    //Create Presentation
    $pp = new PhpPresentation();
    $pp->getProperties()->setCreator('Test')
              ->setLastModifiedBy('Test')
              ->setTitle('Test Animation PPT')
              ->setSubject('Test Animation Example')
              ->setDescription('Testing the appear animation')
              ->setKeywords('powerpoint animation test')
              ->setCategory('Testing');

    //Start Example
    $currentSlide = $pp->getActiveSlide(); 

    //add a shape to apply the animation to
    $shape = $currentSlide->createRichTextShape()->setWidth(100)->setHeight(100)->setOffsetX(100)->setOffsetY(100)->setAutoFit(RichText::AUTOFIT_NOAUTOFIT);
    $shape->getFill()->setFillType(Fill::FILL_SOLID);
    $shape->getFill()->getStartColor()->setRGB('FF0000');

    //add a shape to demonstrate shape grouping 
    $shape2 = $currentSlide->createRichTextShape()->setWidth(100)->setHeight(100)->setOffsetX(300)->setOffsetY(300)->setAutoFit(RichText::AUTOFIT_NOAUTOFIT);
    $shape2->getFill()->setFillType(Fill::FILL_SOLID);
    $shape2->getFill()->getStartColor()->setRGB('FF0000');


    //create animation object
    $animation = new Animation();
    //add the shape we made to the animtion
    $animation->addShape($shape);
    //add the second shape 
    $animation->addShape($shape2); 


    //add the animation to the slide
    $currentSlide->addAnimation($animation);

    //create another shape to demonstrate animation order 
    $shape3 = $currentSlide->createRichTextShape()->setWidth(100)->setHeight(100)->setOffsetX(400)->setOffsetY(400)->setAutoFit(RichText::AUTOFIT_NOAUTOFIT);
    $shape3->getFill()->setFillType(Fill::FILL_SOLID);
    $shape3->getFill()->getStartColor()->setRGB('00FF00');

    //make second animation 
    $animation2 = new Animation(); 
    //add the new shape
    $animation2->addShape($shape3);
    //add the second animation to the slid
    $currentSlide->addAnimation($animation2); 

    //save powerpoint
    $fullPath = "test-ppt.pptx";
    @unlink($fullPath);
    $oWriterPPTX = IOFactory::createWriter($pp, 'PowerPoint2007');
    $oWriterPPTX->save($fullPath);      
?>

@Progi1984
Copy link
Member

I'll work with #179 before this one :)

@Progi1984 Progi1984 modified the milestone: 0.7.0 Mar 8, 2016
@@ -180,7 +180,7 @@ public function writeSlide(SlideElement $pSlide = null)
$objWriter->endElement();

// Loop shapes
$shapeId = 0;
$shapeId = 1;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JewrassicPark Why have you changed this ?

@JewrassicPark
Copy link
Contributor Author

It seemed like powerpoint was treating shape 0 as the slide itself. IIRC I couldn't get the animations to work when the shape index started at 0.

@Progi1984
Copy link
Member

@JewrassicPark Animations or Slide notes ?

@JewrassicPark
Copy link
Contributor Author

I believe that was changed specifically for animations. I'm not sure if it affects the slide notes either way.

@Progi1984
Copy link
Member

@JewrassicPark Could you update your PR with the latest version of the develop branch ?

@JewrassicPark
Copy link
Contributor Author

I made a new pull request with a fork from the latest branch. I deleted my old fork, forked from the latest dev branch, added in my changes for animation and tested it. Is there a better way to do that? It was a pain in the ass and I'm not going to be doing it often.

@Progi1984 Progi1984 closed this Apr 1, 2016
@JewrassicPark JewrassicPark mentioned this pull request Apr 4, 2016
@Progi1984 Progi1984 self-assigned this Apr 5, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

2 participants