@@ -440,7 +440,6 @@ protected function loadSlide(string $sPart, string $baseFile): void
440
440
$ oSlide = $ this ->oPhpPresentation ->createSlide ();
441
441
$ this ->oPhpPresentation ->setActiveSlideIndex ($ this ->oPhpPresentation ->getSlideCount () - 1 );
442
442
$ oSlide ->setRelsIndex ('ppt/slides/_rels/ ' . $ baseFile . '.rels ' );
443
-
444
443
// Background
445
444
$ oElement = $ xmlReader ->getElement ('/p:sld/p:cSld/p:bg/p:bgPr ' );
446
445
if ($ oElement instanceof DOMElement) {
@@ -482,23 +481,24 @@ protected function loadSlide(string $sPart, string $baseFile): void
482
481
}
483
482
$ pathImage = implode ('/ ' , $ pathImage );
484
483
$ contentImg = $ this ->oZip ->getFromName ($ pathImage );
484
+ $ fileName = basename ($ pathImage );
485
+
486
+ $ tmpFile = new Gd ();
487
+ $ tmpFile ->loadFromContent ($ contentImg , $ fileName );
485
488
486
- $ tmpBkgImg = tempnam (sys_get_temp_dir (), 'PhpPresentationReaderPpt2007Bkg ' );
487
- file_put_contents ($ tmpBkgImg , $ contentImg );
488
489
// Background
489
490
$ oBackground = new Slide \Background \Image ();
490
- $ oBackground ->setPath ($ tmpBkgImg );
491
+ $ oBackground ->setImage ($ tmpFile );
492
+
491
493
// Slide Background
492
494
$ oSlide = $ this ->oPhpPresentation ->getActiveSlide ();
493
495
$ oSlide ->setBackground ($ oBackground );
494
496
}
495
497
}
496
498
}
497
-
498
499
// Shapes
499
500
$ arrayElements = $ xmlReader ->getElements ('/p:sld/p:cSld/p:spTree/* ' );
500
501
$ this ->loadSlideShapes ($ oSlide , $ arrayElements , $ xmlReader );
501
-
502
502
// Layout
503
503
$ oSlide = $ this ->oPhpPresentation ->getActiveSlide ();
504
504
foreach ($ this ->arrayRels ['ppt/slides/_rels/ ' . $ baseFile . '.rels ' ] as $ valueRel ) {
@@ -507,7 +507,6 @@ protected function loadSlide(string $sPart, string $baseFile): void
507
507
if (array_key_exists ($ layoutBasename , $ this ->arraySlideLayouts )) {
508
508
$ oSlide ->setSlideLayout ($ this ->arraySlideLayouts [$ layoutBasename ]);
509
509
}
510
-
511
510
break ;
512
511
}
513
512
}
@@ -555,15 +554,13 @@ protected function loadMasterSlide(string $sPart, string $baseFile): void
555
554
continue ;
556
555
}
557
556
$ oRTParagraph = new Paragraph ();
558
-
559
557
if ('a:defPPr ' == $ oElementLvl ->nodeName ) {
560
558
$ level = 0 ;
561
559
} else {
562
560
$ level = str_replace ('a:lvl ' , '' , $ oElementLvl ->nodeName );
563
561
$ level = str_replace ('pPr ' , '' , $ level );
564
562
$ level = (int ) $ level ;
565
563
}
566
-
567
564
if ($ oElementLvl ->hasAttribute ('algn ' )) {
568
565
$ oRTParagraph ->getAlignment ()->setHorizontal ($ oElementLvl ->getAttribute ('algn ' ));
569
566
}
@@ -602,7 +599,6 @@ protected function loadMasterSlide(string $sPart, string $baseFile): void
602
599
$ oRTParagraph ->getFont ()->setColor ($ oSchemeColor );
603
600
}
604
601
}
605
-
606
602
switch ($ oElementTxStyle ->nodeName ) {
607
603
case 'p:bodyStyle ' :
608
604
$ oSlideMaster ->getTextStyles ()->setBodyStyleAtLvl ($ oRTParagraph , $ level );
@@ -627,7 +623,6 @@ protected function loadMasterSlide(string $sPart, string $baseFile): void
627
623
if (false !== $ pptTheme ) {
628
624
$ this ->loadTheme ($ pptTheme , $ oSlideMaster );
629
625
}
630
-
631
626
break ;
632
627
}
633
628
}
@@ -692,7 +687,6 @@ protected function loadLayoutSlide(string $sPart, string $baseFile, SlideMaster
692
687
693
688
return $ oSlideLayout ;
694
689
}
695
-
696
690
// @phpstan-ignore-next-line
697
691
return null ;
698
692
}
@@ -764,12 +758,15 @@ protected function loadSlideBackground(XMLReader $xmlReader, DOMElement $oElemen
764
758
}
765
759
$ pathImage = implode ('/ ' , $ pathImage );
766
760
$ contentImg = $ this ->oZip ->getFromName ($ pathImage );
761
+ $ fileName = basename ($ pathImage );
762
+
763
+ $ tmpFile = new Gd ();
764
+ $ tmpFile ->loadFromContent ($ contentImg , $ fileName );
767
765
768
- $ tmpBkgImg = tempnam (sys_get_temp_dir (), 'PhpPresentationReaderPpt2007Bkg ' );
769
- file_put_contents ($ tmpBkgImg , $ contentImg );
770
766
// Background
771
767
$ oBackground = new Slide \Background \Image ();
772
- $ oBackground ->setPath ($ tmpBkgImg );
768
+ $ oBackground ->setImage ($ tmpFile );
769
+
773
770
// Slide Background
774
771
$ oSlide ->setBackground ($ oBackground );
775
772
}
@@ -783,7 +780,6 @@ protected function loadSlideNote(string $baseFile, Slide $oSlide): void
783
780
// @phpstan-ignore-next-line
784
781
if ($ xmlReader ->getDomFromString ($ sPart )) {
785
782
$ oNote = $ oSlide ->getNote ();
786
-
787
783
$ arrayElements = $ xmlReader ->getElements ('/p:notes/p:cSld/p:spTree/* ' );
788
784
$ this ->loadSlideShapes ($ oNote , $ arrayElements , $ xmlReader );
789
785
}
@@ -805,12 +801,10 @@ protected function loadShapeDrawing(XMLReader $document, DOMElement $node, Abstr
805
801
$ oShape ->getShadow ()->setVisible (false );
806
802
// Variables
807
803
$ fileRels = $ oSlide ->getRelsIndex ();
808
-
809
804
$ oElement = $ document ->getElement ('p:nvPicPr/p:cNvPr ' , $ node );
810
805
if ($ oElement instanceof DOMElement) {
811
806
$ oShape ->setName ($ oElement ->hasAttribute ('name ' ) ? $ oElement ->getAttribute ('name ' ) : '' );
812
807
$ oShape ->setDescription ($ oElement ->hasAttribute ('descr ' ) ? $ oElement ->getAttribute ('descr ' ) : '' );
813
-
814
808
// Hyperlink
815
809
$ oElementHlinkClick = $ document ->getElement ('a:hlinkClick ' , $ oElement );
816
810
if (is_object ($ oElementHlinkClick )) {
@@ -819,26 +813,22 @@ protected function loadShapeDrawing(XMLReader $document, DOMElement $node, Abstr
819
813
);
820
814
}
821
815
}
822
-
823
816
if ($ oShape instanceof Media) {
824
817
$ oShape = $ this ->loadShapeDrawingEmbed ($ embedNode , $ fileRels , $ oShape );
825
818
} else {
826
819
$ oShape = $ this ->loadShapeDrawingImage ($ document , $ node , $ fileRels , $ oShape );
827
820
}
828
-
829
821
$ oElement = $ document ->getElement ('p:spPr ' , $ node );
830
822
if ($ oElement instanceof DOMElement) {
831
823
$ oFill = $ this ->loadStyleFill ($ document , $ oElement );
832
824
$ oShape ->setFill ($ oFill );
833
825
}
834
-
835
826
$ oElement = $ document ->getElement ('p:spPr/a:xfrm ' , $ node );
836
827
if ($ oElement instanceof DOMElement) {
837
828
if ($ oElement ->hasAttribute ('rot ' )) {
838
829
$ oShape ->setRotation ((int ) CommonDrawing::angleToDegrees ((int ) $ oElement ->getAttribute ('rot ' )));
839
830
}
840
831
}
841
-
842
832
$ oElement = $ document ->getElement ('p:spPr/a:xfrm/a:off ' , $ node );
843
833
if ($ oElement instanceof DOMElement) {
844
834
if ($ oElement ->hasAttribute ('x ' )) {
@@ -848,7 +838,6 @@ protected function loadShapeDrawing(XMLReader $document, DOMElement $node, Abstr
848
838
$ oShape ->setOffsetY (CommonDrawing::emuToPixels ((int ) $ oElement ->getAttribute ('y ' )));
849
839
}
850
840
}
851
-
852
841
$ oElement = $ document ->getElement ('p:spPr/a:xfrm/a:ext ' , $ node );
853
842
if ($ oElement instanceof DOMElement) {
854
843
if ($ oElement ->hasAttribute ('cx ' )) {
@@ -878,7 +867,6 @@ protected function loadShapeDrawingEmbed(DOMElement $oElement, string $fileRels,
878
867
}
879
868
880
869
$ embedPath = $ this ->arrayRels [$ fileRels ][$ oElement ->getAttribute ('r:embed ' )]['Target ' ];
881
-
882
870
$ pathEmbed = "ppt/slides/ {$ embedPath }" ;
883
871
884
872
$ pathEmbed = explode ('/ ' , $ pathEmbed );
@@ -889,17 +877,9 @@ protected function loadShapeDrawingEmbed(DOMElement $oElement, string $fileRels,
889
877
}
890
878
$ pathEmbed = implode ('/ ' , $ pathEmbed );
891
879
$ contentEmbed = $ this ->oZip ->getFromName ($ pathEmbed );
892
-
893
- $ tmpEmbed = tempnam (sys_get_temp_dir (), 'PhpPresentationReaderPPT2007Embed ' );
894
-
895
- file_put_contents ($ tmpEmbed , $ contentEmbed );
896
-
897
880
$ fileName = basename ($ embedPath );
898
881
899
- $ oShape
900
- ->setName ($ fileName )
901
- ->setFileName ($ fileName )
902
- ->setPath ($ tmpEmbed , false );
882
+ $ oShape ->loadFromContent ($ contentEmbed , $ fileName );
903
883
904
884
return $ oShape ;
905
885
}
@@ -926,29 +906,14 @@ protected function loadShapeDrawingImage(XMLReader $document, DOMElement $node,
926
906
}
927
907
$ pathImage = implode ('/ ' , $ pathImage );
928
908
$ imageFile = $ this ->oZip ->getFromName ($ pathImage );
909
+ $ fileName = basename ($ pathImage );
910
+
929
911
if (!$ imageFile ) {
930
912
return $ oShape ;
931
913
}
932
914
933
915
if ($ oShape instanceof Gd) {
934
- $ info = getimagesizefromstring ($ imageFile );
935
- if (!$ info ) {
936
- return $ oShape ;
937
- }
938
- $ oShape ->setMimeType ($ info ['mime ' ]);
939
- $ oShape ->setRenderingFunction (str_replace ('/ ' , '' , $ info ['mime ' ]));
940
- if (!@imagecreatefromstring ($ imageFile )) {
941
- return $ oShape ;
942
- }
943
-
944
- $ tmpEmbed = tempnam (sys_get_temp_dir (), 'PhpPresentationReaderPPT2007ImageGd ' );
945
- file_put_contents ($ tmpEmbed , $ imageFile );
946
-
947
- $ fileName = basename ($ pathImage );
948
-
949
- $ oShape
950
- ->setName ($ fileName )
951
- ->setPath ($ tmpEmbed );
916
+ $ oShape ->loadFromContent ($ imageFile , $ fileName );
952
917
} elseif ($ oShape instanceof Base64) {
953
918
$ oShape ->setData ('data:image/svg+xml;base64, ' . base64_encode ($ imageFile ));
954
919
}
@@ -1106,7 +1071,6 @@ protected function loadShapeRichText(XMLReader $document, DOMElement $node, $oSl
1106
1071
protected function loadShapeTable (XMLReader $ document , DOMElement $ node , AbstractSlide $ oSlide ): void
1107
1072
{
1108
1073
$ this ->fileRels = $ oSlide ->getRelsIndex ();
1109
-
1110
1074
$ oShape = $ oSlide ->createTableShape ();
1111
1075
1112
1076
$ oElement = $ document ->getElement ('p:cNvPr ' , $ node );
@@ -1331,6 +1295,7 @@ protected function loadParagraph(XMLReader $document, DOMElement $oElement, $oSh
1331
1295
$ oParagraph ->getBulletStyle ()->setBulletColor ($ oColor );
1332
1296
}
1333
1297
}
1298
+
1334
1299
$ arraySubElements = $ document ->getElements ('(a:r|a:br) ' , $ oElement );
1335
1300
foreach ($ arraySubElements as $ oSubElement ) {
1336
1301
if (!($ oSubElement instanceof DOMElement)) {
@@ -1343,7 +1308,6 @@ protected function loadParagraph(XMLReader $document, DOMElement $oElement, $oSh
1343
1308
$ oElementrPr = $ document ->getElement ('a:rPr ' , $ oSubElement );
1344
1309
if (is_object ($ oElementrPr )) {
1345
1310
$ oText = $ oParagraph ->createTextRun ();
1346
-
1347
1311
if ($ oElementrPr ->hasAttribute ('b ' )) {
1348
1312
$ att = $ oElementrPr ->getAttribute ('b ' );
1349
1313
$ oText ->getFont ()->setBold ('true ' == $ att || '1 ' == $ att ? true : false );
@@ -1420,7 +1384,6 @@ protected function loadParagraph(XMLReader $document, DOMElement $oElement, $oSh
1420
1384
$ oText ->getFont ()->setCharset ((int ) $ oElementFont ->getAttribute ('charset ' ));
1421
1385
}
1422
1386
}
1423
-
1424
1387
$ oSubSubElement = $ document ->getElement ('a:t ' , $ oSubElement );
1425
1388
$ oText ->setText ($ oSubSubElement ->nodeValue );
1426
1389
}
0 commit comments