Skip to content

Commit f20e1e9

Browse files
committed
#192 : Image Adapter (Feature)
1 parent def4684 commit f20e1e9

30 files changed

+654
-357
lines changed

samples/Sample_01_Simple.php

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -11,48 +11,48 @@
1111
$objPHPPresentation = new PhpPresentation();
1212

1313
// Set properties
14-
echo date('H:i:s') . ' Set properties'.EOL;
15-
$objPHPPresentation->getProperties()->setCreator('PHPOffice')
16-
->setLastModifiedBy('PHPPresentation Team')
17-
->setTitle('Sample 01 Title')
18-
->setSubject('Sample 01 Subject')
19-
->setDescription('Sample 01 Description')
20-
->setKeywords('office 2007 openxml libreoffice odt php')
21-
->setCategory('Sample Category');
14+
echo date('H:i:s') . ' Set properties' . EOL;
15+
$objPHPPresentation->getDocumentProperties()->setCreator('PHPOffice')
16+
->setLastModifiedBy('PHPPresentation Team')
17+
->setTitle('Sample 01 Title')
18+
->setSubject('Sample 01 Subject')
19+
->setDescription('Sample 01 Description')
20+
->setKeywords('office 2007 openxml libreoffice odt php')
21+
->setCategory('Sample Category');
2222

2323
// Create slide
24-
echo date('H:i:s') . ' Create slide'.EOL;
24+
echo date('H:i:s') . ' Create slide' . EOL;
2525
$currentSlide = $objPHPPresentation->getActiveSlide();
2626

2727
// Create a shape (drawing)
28-
echo date('H:i:s') . ' Create a shape (drawing)'.EOL;
28+
echo date('H:i:s') . ' Create a shape (drawing)' . EOL;
2929
$shape = $currentSlide->createDrawingShape();
3030
$shape->setName('PHPPresentation logo')
31-
->setDescription('PHPPresentation logo')
32-
->setPath('./resources/phppowerpoint_logo.gif')
33-
->setHeight(36)
34-
->setOffsetX(10)
35-
->setOffsetY(10);
31+
->setDescription('PHPPresentation logo')
32+
->setPath('./resources/phppowerpoint_logo.gif')
33+
->setHeight(36)
34+
->setOffsetX(10)
35+
->setOffsetY(10);
3636
$shape->getShadow()->setVisible(true)
37-
->setDirection(45)
38-
->setDistance(10);
37+
->setDirection(45)
38+
->setDistance(10);
3939
$shape->getHyperlink()->setUrl('https://github.com/PHPOffice/PHPPresentation/')->setTooltip('PHPPresentation');
4040

4141
// Create a shape (text)
42-
echo date('H:i:s') . ' Create a shape (rich text)'.EOL;
42+
echo date('H:i:s') . ' Create a shape (rich text)' . EOL;
4343
$shape = $currentSlide->createRichTextShape()
44-
->setHeight(300)
45-
->setWidth(600)
46-
->setOffsetX(170)
47-
->setOffsetY(180);
48-
$shape->getActiveParagraph()->getAlignment()->setHorizontal( Alignment::HORIZONTAL_CENTER );
44+
->setHeight(300)
45+
->setWidth(600)
46+
->setOffsetX(170)
47+
->setOffsetY(180);
48+
$shape->getActiveParagraph()->getAlignment()->setHorizontal(Alignment::HORIZONTAL_CENTER);
4949
$textRun = $shape->createTextRun('Thank you for using PHPPresentation!');
5050
$textRun->getFont()->setBold(true)
51-
->setSize(60)
52-
->setColor( new Color( 'FFE06B20' ) );
51+
->setSize(60)
52+
->setColor(new Color('FFE06B20'));
5353

5454
// Save file
5555
echo write($objPHPPresentation, basename(__FILE__, '.php'), $writers);
5656
if (!CLI) {
57-
include_once 'Sample_Footer.php';
57+
include_once 'Sample_Footer.php';
5858
}

samples/Sample_03_Image.php

Lines changed: 19 additions & 8 deletions
Large diffs are not rendered by default.

samples/Sample_Header.php

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
$pageTitle .= 'PHPPresentation';
4444
$pageHeading = IS_INDEX ? '' : "<h1>{$pageHeading}</h1>";
4545

46-
$oShapeDrawing = new Drawing();
46+
$oShapeDrawing = new Drawing\File();
4747
$oShapeDrawing->setName('PHPPresentation logo')
4848
->setDescription('PHPPresentation logo')
4949
->setPath('./resources/phppowerpoint_logo.gif')
@@ -241,14 +241,18 @@ protected function displayPhpPresentation(PhpPresentation $oPHPPpt)
241241

242242
protected function displayShape(AbstractShape $shape)
243243
{
244-
if($shape instanceof MemoryDrawing) {
245-
$this->append('<li><span class="shape" id="div'.$shape->getHashCode().'">Shape "MemoryDrawing"</span></li>');
246-
} elseif($shape instanceof Drawing) {
247-
$this->append('<li><span class="shape" id="div'.$shape->getHashCode().'">Shape "Drawing"</span></li>');
244+
if($shape instanceof Drawing\Gd) {
245+
$this->append('<li><span class="shape" id="div'.$shape->getHashCode().'">Shape "Drawing\Gd"</span></li>');
246+
} elseif($shape instanceof Drawing\File) {
247+
$this->append('<li><span class="shape" id="div'.$shape->getHashCode().'">Shape "Drawing\File"</span></li>');
248+
} elseif($shape instanceof Drawing\Base64) {
249+
$this->append('<li><span class="shape" id="div'.$shape->getHashCode().'">Shape "Drawing\Base64"</span></li>');
250+
} elseif($shape instanceof Drawing\Zip) {
251+
$this->append('<li><span class="shape" id="div'.$shape->getHashCode().'">Shape "Drawing\Zip"</span></li>');
248252
} elseif($shape instanceof RichText) {
249253
$this->append('<li><span class="shape" id="div'.$shape->getHashCode().'">Shape "RichText"</span></li>');
250254
} else {
251-
var_export($shape);
255+
var_dump($shape);
252256
}
253257
}
254258

samples/resources/SamplePassword.pptx

36.5 KB
Binary file not shown.

src/PhpPresentation/AbstractShape.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -407,7 +407,7 @@ public function setHyperlink(Hyperlink $pHyperlink = null)
407407
*/
408408
public function getHashCode()
409409
{
410-
return md5((is_object($this->container)?$this->container->getHashCode():'') . $this->offsetX . $this->offsetY . $this->width . $this->height . $this->rotation . $this->getFill()->getHashCode() . (is_null($this->shadow) ? '' : $this->shadow->getHashCode()) . (is_null($this->hyperlink) ? '' : $this->hyperlink->getHashCode()) . __CLASS__);
410+
return md5((is_object($this->container)?$this->container->getHashCode():'') . $this->offsetX . $this->offsetY . $this->width . $this->height . $this->rotation . (is_null($this->getFill()) ? '' : $this->getFill()->getHashCode()) . (is_null($this->shadow) ? '' : $this->shadow->getHashCode()) . (is_null($this->hyperlink) ? '' : $this->hyperlink->getHashCode()) . __CLASS__);
411411
}
412412

413413
/**

src/PhpPresentation/Reader/ODPresentation.php

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,14 @@
2121
use PhpOffice\Common\XMLReader;
2222
use PhpOffice\Common\Drawing as CommonDrawing;
2323
use PhpOffice\PhpPresentation\PhpPresentation;
24-
use PhpOffice\PhpPresentation\Shape\Hyperlink;
25-
use PhpOffice\PhpPresentation\Shape\MemoryDrawing;
24+
use PhpOffice\PhpPresentation\Shape\Drawing\Gd;
25+
use PhpOffice\PhpPresentation\Shape\RichText;
26+
use PhpOffice\PhpPresentation\Shape\RichText\Paragraph;
2627
use PhpOffice\PhpPresentation\Style\Bullet;
2728
use PhpOffice\PhpPresentation\Style\Color;
2829
use PhpOffice\PhpPresentation\Style\Font;
2930
use PhpOffice\PhpPresentation\Style\Shadow;
3031
use PhpOffice\PhpPresentation\Style\Alignment;
31-
use PhpOffice\PhpPresentation\Style\PhpOffice\PhpPresentation\Style;
32-
use PhpOffice\PhpPresentation\Shape\RichText;
33-
use PhpOffice\PhpPresentation\Shape\RichText\Paragraph;
34-
use PhpOffice\Common\PhpOffice\Common;
3532

3633
/**
3734
* Serialized format reader
@@ -365,9 +362,9 @@ protected function loadSlide(\DOMElement $nodeSlide)
365362
protected function loadShapeDrawing(\DOMElement $oNodeFrame)
366363
{
367364
// Core
368-
$oShape = new MemoryDrawing();
365+
$oShape = new Gd();
369366
$oShape->getShadow()->setVisible(false);
370-
367+
371368
$oNodeImage = $this->oXMLReader->getElement('draw:image', $oNodeFrame);
372369
if ($oNodeImage) {
373370
if ($oNodeImage->hasAttribute('xlink:href')) {

src/PhpPresentation/Reader/PowerPoint2007.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@
1717

1818
namespace PhpOffice\PhpPresentation\Reader;
1919

20+
use PhpOffice\PhpPresentation\Shape\Drawing\Gd;
2021
use ZipArchive;
2122
use PhpOffice\Common\XMLReader;
2223
use PhpOffice\Common\Drawing as CommonDrawing;
2324
use PhpOffice\PhpPresentation\PhpPresentation;
24-
use PhpOffice\PhpPresentation\Shape\MemoryDrawing;
2525
use PhpOffice\PhpPresentation\Style\Bullet;
2626
use PhpOffice\PhpPresentation\Style\Color;
2727
use PhpOffice\PhpPresentation\Writer\PowerPoint2007\LayoutPack\TemplateBased;
@@ -328,7 +328,7 @@ protected function loadSlide($sPart, $baseFile)
328328
protected function loadShapeDrawing(XMLReader $document, \DOMElement $node, $baseFile)
329329
{
330330
// Core
331-
$oShape = new MemoryDrawing();
331+
$oShape = new Gd();
332332
$oShape->getShadow()->setVisible(false);
333333
// Variables
334334
$fileRels = 'ppt/slides/_rels/'.$baseFile.'.rels';

src/PhpPresentation/Reader/PowerPoint97.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
use PhpOffice\Common\Microsoft\OLERead;
2121
use PhpOffice\PhpPresentation\Shape\Drawing;
2222
use PhpOffice\PhpPresentation\PhpPresentation;
23-
use PhpOffice\PhpPresentation\Shape\MemoryDrawing;
2423
use PhpOffice\PhpPresentation\Style\Alignment;
2524
use PhpOffice\PhpPresentation\Style\Color;
2625
use PhpOffice\PhpPresentation\Shape\RichText;
@@ -1422,7 +1421,7 @@ private function readRecordOfficeArtSpContainer($stream, $pos)
14221421
$drawingPib = $shpPrimaryOptions['pib'];
14231422
if (isset($this->arrayPictures[$drawingPib - 1])) {
14241423
$gdImage = imagecreatefromstring($this->arrayPictures[$drawingPib - 1]);
1425-
$arrayReturn['shape'] = new MemoryDrawing();
1424+
$arrayReturn['shape'] = new Drawing\Gd();
14261425
$arrayReturn['shape']->setImageResource($gdImage);
14271426
}
14281427
} elseif (isset($shpPrimaryOptions['line']) && $shpPrimaryOptions['line']) {

src/PhpPresentation/Shape/AbstractDrawing.php renamed to src/PhpPresentation/Shape/AbstractGraphic.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
/**
2424
* Abstract drawing
2525
*/
26-
abstract class AbstractDrawing extends AbstractShape implements ComparableInterface
26+
abstract class AbstractGraphic extends AbstractShape implements ComparableInterface
2727
{
2828
/**
2929
* Image counter

src/PhpPresentation/Shape/Chart.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
namespace PhpOffice\PhpPresentation\Shape;
1919

20+
use PhpOffice\PhpPresentation\AbstractShape;
2021
use PhpOffice\PhpPresentation\ComparableInterface;
2122
use PhpOffice\PhpPresentation\Shape\Chart\Legend;
2223
use PhpOffice\PhpPresentation\Shape\Chart\PlotArea;
@@ -26,7 +27,7 @@
2627
/**
2728
* Chart element
2829
*/
29-
class Chart extends AbstractDrawing implements ComparableInterface
30+
class Chart extends AbstractGraphic implements ComparableInterface
3031
{
3132
/**
3233
* Title
@@ -64,7 +65,7 @@ class Chart extends AbstractDrawing implements ComparableInterface
6465
private $includeSpreadsheet = false;
6566

6667
/**
67-
* Create a new \PhpOffice\PhpPresentation\Slide\MemoryDrawing
68+
* Create a new Chart
6869
*/
6970
public function __construct()
7071
{

0 commit comments

Comments
 (0)