Skip to content

Commit 6122baf

Browse files
authored
Merge pull request #2 from Progi1984/develop
PR from @vincentKool
2 parents 2482614 + 0774464 commit 6122baf

File tree

7 files changed

+67
-20
lines changed

7 files changed

+67
-20
lines changed

src/PhpPresentation/Writer/PowerPoint2007/AbstractSlide.php

Lines changed: 40 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,14 @@
2020
use PhpOffice\Common\Text;
2121
use PhpOffice\Common\XMLWriter;
2222
use PhpOffice\PhpPresentation\Shape\AbstractDrawing;
23+
use PhpOffice\PhpPresentation\Shape\AbstractGraphic;
2324
use PhpOffice\PhpPresentation\Shape\Chart as ShapeChart;
2425
use PhpOffice\PhpPresentation\Shape\Comment;
2526
use PhpOffice\PhpPresentation\Shape\Drawing\Gd as ShapeDrawingGd;
2627
use PhpOffice\PhpPresentation\Shape\Drawing\File as ShapeDrawingFile;
2728
use PhpOffice\PhpPresentation\Shape\Group;
2829
use PhpOffice\PhpPresentation\Shape\Line;
30+
use PhpOffice\PhpPresentation\Shape\Media;
2931
use PhpOffice\PhpPresentation\Shape\Placeholder;
3032
use PhpOffice\PhpPresentation\Shape\RichText;
3133
use PhpOffice\PhpPresentation\Shape\RichText\BreakElement;
@@ -114,9 +116,13 @@ protected function writeDrawingRelations(AbstractSlideAlias $pSlideMaster, $objW
114116
* @param XMLWriter $objWriter
115117
* @param \ArrayObject|\PhpOffice\PhpPresentation\AbstractShape[] $shapes
116118
* @param int $shapeId
119+
* @throws \Exception
117120
*/
118121
protected function writeShapeCollection(XMLWriter $objWriter, $shapes = array(), &$shapeId = 0)
119122
{
123+
if (count($shapes) == 0) {
124+
return;
125+
}
120126
foreach ($shapes as $shape) {
121127
// Increment $shapeId
122128
++$shapeId;
@@ -129,10 +135,14 @@ protected function writeShapeCollection(XMLWriter $objWriter, $shapes = array(),
129135
$this->writeShapeLine($objWriter, $shape, $shapeId);
130136
} elseif ($shape instanceof ShapeChart) {
131137
$this->writeShapeChart($objWriter, $shape, $shapeId);
132-
} elseif ($shape instanceof AbstractDrawing) {
138+
} elseif ($shape instanceof AbstractGraphic) {
133139
$this->writeShapePic($objWriter, $shape, $shapeId);
134140
} elseif ($shape instanceof Group) {
135141
$this->writeShapeGroup($objWriter, $shape, $shapeId);
142+
} elseif ($shape instanceof Comment) {
143+
return;
144+
} else {
145+
throw new \Exception("Unknown Shape type: {get_class($shape)}");
136146
}
137147
}
138148
}
@@ -875,11 +885,11 @@ protected function writeShapeChart(XMLWriter $objWriter, ShapeChart $shape, $sha
875885
* Write pic
876886
*
877887
* @param \PhpOffice\Common\XMLWriter $objWriter XML Writer
878-
* @param \PhpOffice\PhpPresentation\Shape\AbstractDrawing $shape
888+
* @param \PhpOffice\PhpPresentation\Shape\AbstractGraphic $shape
879889
* @param int $shapeId
880890
* @throws \Exception
881891
*/
882-
protected function writeShapePic(XMLWriter $objWriter, AbstractDrawing $shape, $shapeId)
892+
protected function writeShapePic(XMLWriter $objWriter, AbstractGraphic $shape, $shapeId)
883893
{
884894
// p:pic
885895
$objWriter->startElement('p:pic');
@@ -903,7 +913,33 @@ protected function writeShapePic(XMLWriter $objWriter, AbstractDrawing $shape, $
903913
$objWriter->endElement();
904914
$objWriter->endElement();
905915
// p:nvPr
906-
$objWriter->writeElement('p:nvPr', null);
916+
$objWriter->startElement('p:nvPr');
917+
/**
918+
* @link : https://github.com/stefslon/exportToPPTX/blob/master/exportToPPTX.m#L2128
919+
*/
920+
if ($shape instanceof Media) {
921+
// p:nvPr > a:videoFile
922+
$objWriter->startElement('a:videoFile');
923+
$objWriter->writeAttribute('r:link', $shape->relationId);
924+
$objWriter->endElement();
925+
// p:nvPr > p:extLst
926+
$objWriter->startElement('p:extLst');
927+
// p:nvPr > p:extLst > p:ext
928+
$objWriter->startElement('p:ext');
929+
$objWriter->writeAttribute('uri', '{DAA4B4D4-6D71-4841-9C94-3DE7FCFB9230}');
930+
// p:nvPr > p:extLst > p:ext > p14:media
931+
$objWriter->startElement('p14:media');
932+
$objWriter->writeAttribute('r:embed', $shape->relationId);
933+
$objWriter->writeAttribute('xmlns:p14', 'http://schemas.microsoft.com/office/powerpoint/2010/main');
934+
// p:nvPr > p:extLst > p:ext > ##p14:media
935+
$objWriter->endElement();
936+
// p:nvPr > p:extLst > ##p:ext
937+
$objWriter->endElement();
938+
// p:nvPr > ##p:extLst
939+
$objWriter->endElement();
940+
}
941+
// ##p:nvPr
942+
$objWriter->endElement();
907943
$objWriter->endElement();
908944
// p:blipFill
909945
$objWriter->startElement('p:blipFill');

src/PhpPresentation/Writer/PowerPoint2007/ContentTypes.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public function render()
6969
$oSlideMaster->setRelsIndex($idx + 1);
7070
$this->writeOverrideContentType($objWriter, '/ppt/slideMasters/slideMaster' . $oSlideMaster->getRelsIndex() . '.xml', 'application/vnd.openxmlformats-officedocument.presentationml.slideMaster+xml');
7171
$this->writeOverrideContentType($objWriter, '/ppt/theme/theme' . $oSlideMaster->getRelsIndex() . '.xml', 'application/vnd.openxmlformats-officedocument.theme+xml');
72-
foreach ($oSlideMaster->getAllSlideLayouts() as &$oSlideLayout) {
72+
foreach ($oSlideMaster->getAllSlideLayouts() as $oSlideLayout) {
7373
$oSlideLayout->layoutNr = ++$sldLayoutNr;
7474
$oSlideLayout->layoutId = ++$sldLayoutId;
7575
$this->writeOverrideContentType($objWriter, '/ppt/slideLayouts/slideLayout' . $oSlideLayout->layoutNr . '.xml', 'application/vnd.openxmlformats-officedocument.presentationml.slideLayout+xml');

src/PhpPresentation/Writer/PowerPoint2007/PptSlideLayouts.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class PptSlideLayouts extends AbstractSlide
1616
public function render()
1717
{
1818
foreach ($this->oPresentation->getAllMasterSlides() as $oSlideMaster) {
19-
foreach ($oSlideMaster->getAllSlideLayouts() as &$oSlideLayout) {
19+
foreach ($oSlideMaster->getAllSlideLayouts() as $oSlideLayout) {
2020
$this->oZip->addFromString('ppt/slideLayouts/_rels/slideLayout' . $oSlideLayout->layoutNr . '.xml.rels', $this->writeSlideLayoutRelationships($oSlideLayout->layoutNr, $oSlideMaster->getRelsIndex()));
2121
$this->oZip->addFromString('ppt/slideLayouts/slideLayout' . $oSlideLayout->layoutNr . '.xml', $this->writeSlideLayout($oSlideLayout));
2222
}

src/PhpPresentation/Writer/PowerPoint2007/PptSlides.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ protected function writeSlideRelationships(Slide $pSlide)
7878
$idxSlide = $pSlide->getParent()->getIndex($pSlide);
7979

8080
// Write slideLayout relationship
81-
if (!empty($pSlide->getSlideLayout())) {
81+
if (($pSlide->getSlideLayout())) {
8282
$layoutId = $pSlide->getSlideLayout()->layoutNr;
8383
$this->writeRelationship($objWriter, $relId++, 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/slideLayout', '../slideLayouts/slideLayout' . $layoutId . '.xml');
8484
}

tests/PhpPresentation/Tests/SlideTest.php

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -56,15 +56,16 @@ public function testParent()
5656
$this->assertInstanceOf('PhpOffice\\PhpPresentation\\PhpPresentation', $object->getParent());
5757
}
5858

59-
public function testSlideLayout()
60-
{
61-
$object = new Slide();
62-
$this->assertEquals(Slide\Layout::BLANK, $object->getSlideLayout());
63-
$this->assertInstanceOf('PhpOffice\\PhpPresentation\\Slide', $object->setSlideLayout());
64-
$this->assertEquals(Slide\Layout::BLANK, $object->getSlideLayout());
65-
$this->assertInstanceOf('PhpOffice\\PhpPresentation\\Slide', $object->setSlideLayout(Slide\Layout::TITLE_SLIDE));
66-
$this->assertEquals(Slide\Layout::TITLE_SLIDE, $object->getSlideLayout());
67-
}
59+
// Standard Layouts have been removed
60+
// public function testSlideLayout()
61+
// {
62+
// $object = new Slide();
63+
// $this->assertEquals(Slide\Layout::BLANK, $object->getSlideLayout());
64+
// $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Slide', $object->setSlideLayout());
65+
// $this->assertEquals(Slide\Layout::BLANK, $object->getSlideLayout());
66+
// $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Slide', $object->setSlideLayout(Slide\Layout::TITLE_SLIDE));
67+
// $this->assertEquals(Slide\Layout::TITLE_SLIDE, $object->getSlideLayout());
68+
// }
6869

6970
public function testSlideMasterId()
7071
{

tests/PhpPresentation/Tests/Style/FontTest.php

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,22 @@ public function testConstruct()
4747

4848
/**
4949
* Test get/set color
50+
* @expectedException \Exception
51+
* @expectedExceptionMessage $pValue must be an instance of \PhpOffice\PhpPresentation\Style\Color
5052
*/
51-
public function testSetGetColor()
53+
public function testSetGetColorException()
5254
{
5355
$object = new Font();
5456
$this->assertInstanceOf('PhpOffice\\PhpPresentation\\Style\\Font', $object->setColor());
55-
$this->assertNull($object->getColor());
57+
}
58+
59+
/**
60+
* Test get/set color
61+
*/
62+
public function testSetGetColor()
63+
{
64+
$object = new Font();
65+
$this->assertEquals(Color::COLOR_BLACK, $object->getColor()->getARGB());
5666
$this->assertInstanceOf('PhpOffice\\PhpPresentation\\Style\\Font', $object->setColor(new Color(Color::COLOR_BLUE)));
5767
$this->assertInstanceOf('PhpOffice\\PhpPresentation\\Style\\Color', $object->getColor());
5868
$this->assertEquals(Color::COLOR_BLUE, $object->getColor()->getARGB());

tests/PhpPresentation/Tests/Writer/PowerPoint2007/PptSlidesTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ public function testDrawingWithHyperlink()
188188

189189
$element = '/p:sld/p:cSld/p:spTree/p:pic/p:nvPicPr/p:cNvPr/a:hlinkClick';
190190
$this->assertTrue($pres->elementExists($element, 'ppt/slides/slide1.xml'));
191-
$this->assertEquals('rId3', $pres->getElementAttribute($element, 'r:id', 'ppt/slides/slide1.xml'));
191+
$this->assertEquals('rId2', $pres->getElementAttribute($element, 'r:id', 'ppt/slides/slide1.xml'));
192192
}
193193

194194
public function testDrawingShapeBorder()
@@ -828,7 +828,7 @@ public function testTableWithHyperlink()
828828

829829
$element = '/p:sld/p:cSld/p:spTree/p:graphicFrame/a:graphic/a:graphicData/a:tbl/a:tr/a:tc/a:txBody/a:p/a:r/a:rPr/a:hlinkClick';
830830
$this->assertTrue($pres->elementExists($element, 'ppt/slides/slide1.xml'));
831-
$this->assertEquals('rId2', $pres->getElementAttribute($element, 'r:id', 'ppt/slides/slide1.xml'));
831+
$this->assertEquals('rId1', $pres->getElementAttribute($element, 'r:id', 'ppt/slides/slide1.xml'));
832832
}
833833

834834
public function testTransition()

0 commit comments

Comments
 (0)