Skip to content

Commit 6738a06

Browse files
authored
Merge pull request #788 from Progi1984/pr684
PowerPoint 2007 Reader/Writer : Improvements on Font, RichText, Thumbnail, Presentation Properties & Shadow
2 parents 2b4ef2e + ec4700e commit 6738a06

File tree

77 files changed

+1389
-593
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

77 files changed

+1389
-593
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ Desktop.ini
99
### Continuous Integration
1010
build/
1111
phpunit.xml
12+
php-cs-fixer.phar
1213
.php-cs-fixer.cache
1314
.phpunit.result.cache
1415
composer.phar

docs/changes/1.1.0.md

+15
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,24 @@
1717
- PowerPoint2007 Reader
1818
- PowerPoint2007 Writer
1919
- PowerPoint2007 Writer: Enable style and position of a Placeholder - [@qmachard](https://github.com/qmachard) in [#787](https://github.com/PHPOffice/PHPPresentation/pull/787)
20+
- PowerPoint2007 Reader: Added support for thumbnail image - [@devX2712](https://github.com/devX2712) in [#788](https://github.com/PHPOffice/PHPPresentation/pull/787)
2021

2122
## Improvements
2223
- Slide : Raised max value for identifier rand call - [@Scheissy](https://github.com/Scheissy) in [#777](https://github.com/PHPOffice/PHPPresentation/pull/777)
24+
- Document Properties : Support for Revision & Status - [@devX2712](https://github.com/devX2712) in [#788](https://github.com/PHPOffice/PHPPresentation/pull/787)
25+
- PowerPoint2007 Reader
26+
- PowerPoint2007 Writer
27+
- Presentation Properties : Added support to define content of the thumbnail - [@devX2712](https://github.com/devX2712) in [#788](https://github.com/PHPOffice/PHPPresentation/pull/787)
28+
- Font : Support for Capitalization, Strikethrough, Pitch Family, Charset & Panose - [@devX2712](https://github.com/devX2712) in [#788](https://github.com/PHPOffice/PHPPresentation/pull/787)
29+
- PowerPoint2007 Reader
30+
- PowerPoint2007 Writer
31+
- Font : Replaced Superscript/Subscript by baseline in PowerPoint2007 Writer - [@devX2712](https://github.com/devX2712) in [#788](https://github.com/PHPOffice/PHPPresentation/pull/787)
32+
- RichText : Support for Vertical Align - [@devX2712](https://github.com/devX2712) in [#788](https://github.com/PHPOffice/PHPPresentation/pull/787)
33+
- PowerPoint2007 Reader
34+
- PowerPoint2007 Writer
35+
- Shadow : Support for Type Inner & Reflection - [@devX2712](https://github.com/devX2712) in [#788](https://github.com/PHPOffice/PHPPresentation/pull/787)
36+
- PowerPoint2007 Reader
37+
- PowerPoint2007 Writer
2338

2439
## Bugfixes
2540

docs/usage/presentation.md

+31-1
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ $properties->setCreated(mktime(0, 0, 0, 3, 12, 2014));
6262
$properties->setModified(mktime(0, 0, 0, 3, 14, 2014));
6363
$properties->setSubject('My subject');
6464
$properties->setKeywords('my, key, word');
65+
$properties->setStatus('Work in Progress');
66+
$properties->setRevision('Version 1.2.3');
6567
```
6668

6769
### Custom Properties
@@ -203,16 +205,44 @@ echo $properties->getSlideshowType();
203205

204206
You can define the thumbnail of the presentation with the method `setThumbnailPath`.
205207

208+
209+
#### From a file
206210
``` php
207211
<?php
208212

213+
use PhpOffice\PhpPresentation\PresentationProperties;
214+
209215
$presentation = new PhpPresentation();
210216

211217
$properties = $presentation->getPresentationProperties();
212218
// Set path of the thumbnail
213-
$properties->setThumbnailPath(__DIR__.'\resources\phppowerpoint_logo.gif');
219+
$properties->setThumbnailPath(
220+
__DIR__.'\resources\phppowerpoint_logo.gif',
221+
PresentationProperties::THUMBNAIL_FILE
222+
);
214223
// Get path of the thumbnail
215224
echo $properties->getThumbnailPath();
225+
// Get content of the thumbnail
226+
echo $properties->getThumbnail();
227+
```
228+
229+
#### From the content of the file
230+
``` php
231+
<?php
232+
233+
use PhpOffice\PhpPresentation\PresentationProperties;
234+
235+
$presentation = new PhpPresentation();
236+
237+
$properties = $presentation->getPresentationProperties();
238+
// Set path of the thumbnail
239+
$properties->setThumbnailPath(
240+
'',
241+
PresentationProperties::THUMBNAIL_DATA,
242+
file_get_contents(__DIR__.'\resources\phppowerpoint_logo.gif')
243+
);
244+
// Get content of the thumbnail
245+
echo $properties->getThumbnail();
216246
```
217247

218248
### Zoom

docs/usage/styles.md

+32-3
Original file line numberDiff line numberDiff line change
@@ -97,12 +97,24 @@ echo $alignment->isRTL();
9797
- `name`
9898
- `bold`
9999
- `italic`
100-
- `superScript`
101-
- `subScript`
100+
- `superScript` (deprecated)
101+
- `subScript` (deprecated)
102102
- `underline`
103103
- `strikethrough`
104104
- `color`
105-
- `capitalization`
105+
- `pitchFamily`
106+
- `charset`
107+
108+
### Baseline
109+
110+
The baseline set the position relative to the line.
111+
The value is a percentage.
112+
113+
You can use some predefined values :
114+
115+
* `Font::BASELINE_SUPERSCRIPT` (= 300000 = 300%)
116+
* `Font::BASELINE_SUBSCRIPT` (= -250000 = -250%)
117+
106118

107119
### Capitalization
108120

@@ -145,6 +157,23 @@ $font->setFormat(Font::FORMAT_EAST_ASIAN);
145157
// Get format of font
146158
echo $font->getFormat();
147159
```
160+
161+
### Panose
162+
The support of Panose 1.0 is only used.
163+
164+
``` php
165+
<?php
166+
167+
use PhpOffice\PhpPresentation\Style\Font;
168+
169+
$font = new Font();
170+
171+
// Set panose of font
172+
$font->setPanose('4494D72242');
173+
// Get panose of font
174+
echo $font->getPanose();
175+
```
176+
148177
## Bullet
149178

150179
- `bulletType`

samples/Sample_04_Table.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@
8585
$oCell->createTextRun('R2C1');
8686
$oCell->getActiveParagraph()->getAlignment()
8787
->setMarginLeft(30)
88-
->setTextDirection(\PhpOffice\PhpPresentation\Style\Alignment::TEXT_DIRECTION_VERTICAL_270);
88+
->setTextDirection(PhpOffice\PhpPresentation\Style\Alignment::TEXT_DIRECTION_VERTICAL_270);
8989
$oCell = $row->nextCell();
9090
$oCell->createTextRun('R2C2');
9191
$oCell->getActiveParagraph()->getAlignment()

samples/Sample_05_Chart.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ function fnSlide_BarHorizontal(PhpPresentation $objPHPPresentation): void
132132

133133
// Create a bar chart (that should be inserted in a shape)
134134
echo date('H:i:s') . ' Create a horizontal bar chart (that should be inserted in a chart shape) ' . EOL;
135-
$barChartHorz = clone $objPHPPresentation->getSlide(1)->getShapeCollection()->offsetGet(1)->getPlotArea()->getType();
135+
$barChartHorz = clone $objPHPPresentation->getSlide(1)->getShapeCollection()[1]->getPlotArea()->getType();
136136
$barChartHorz->setBarDirection(Bar3D::DIRECTION_HORIZONTAL);
137137

138138
// Create templated slide
@@ -363,7 +363,7 @@ function fnSlide_Bar3DHorizontal(PhpPresentation $objPHPPresentation): void
363363

364364
// Create a bar chart (that should be inserted in a shape)
365365
echo date('H:i:s') . ' Create a horizontal bar chart (that should be inserted in a chart shape) ' . EOL;
366-
$bar3DChartHorz = clone $objPHPPresentation->getSlide(5)->getShapeCollection()->offsetGet(1)->getPlotArea()->getType();
366+
$bar3DChartHorz = clone $objPHPPresentation->getSlide(5)->getShapeCollection()[1]->getPlotArea()->getType();
367367
$bar3DChartHorz->setBarDirection(Bar3D::DIRECTION_HORIZONTAL);
368368

369369
// Create templated slide

samples/Sample_17_Comment.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,13 @@
1414
$oSlide1->addShape(clone $oShapeDrawing);
1515
$oSlide1->addShape(clone $oShapeRichText);
1616

17-
$oAuthor = new \PhpOffice\PhpPresentation\Shape\Comment\Author();
17+
$oAuthor = new PhpOffice\PhpPresentation\Shape\Comment\Author();
1818
$oAuthor->setName('Progi1984');
1919
$oAuthor->setInitials('P');
2020

2121
// Add Comment 1
2222
echo date('H:i:s') . ' Add Comment 1' . EOL;
23-
$oComment1 = new \PhpOffice\PhpPresentation\Shape\Comment();
23+
$oComment1 = new PhpOffice\PhpPresentation\Shape\Comment();
2424
$oComment1->setText('Text A');
2525
$oComment1->setOffsetX(10);
2626
$oComment1->setOffsetY(55);
@@ -30,7 +30,7 @@
3030

3131
// Add Comment
3232
echo date('H:i:s') . ' Add Comment 2' . EOL;
33-
$oComment2 = new \PhpOffice\PhpPresentation\Shape\Comment();
33+
$oComment2 = new PhpOffice\PhpPresentation\Shape\Comment();
3434
$oComment2->setText('Text B');
3535
$oComment2->setOffsetX(170);
3636
$oComment2->setOffsetY(180);

samples/Sample_22_ExternalSlide.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
$objPHPPresentation = new PhpPresentation();
1010
$objPHPPresentation->removeSlideByIndex(0);
1111

12-
$oReader = \PhpOffice\PhpPresentation\IOFactory::createReader('PowerPoint2007');
12+
$oReader = PhpOffice\PhpPresentation\IOFactory::createReader('PowerPoint2007');
1313
$oPresentation04 = $oReader->load(__DIR__ . '/results/Sample_04_Table.pptx');
1414

1515
foreach ($oPresentation04->getAllSlides() as $oSlide) {

samples/Sample_Header.php

+7-6
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
} else {
3232
if (is_file(__DIR__ . '/../../Common/src/Common/Autoloader.php')) {
3333
include_once __DIR__ . '/../../Common/src/Common/Autoloader.php';
34-
\PhpOffice\Common\Autoloader::register();
34+
PhpOffice\Common\Autoloader::register();
3535
} else {
3636
throw new Exception('Can not find the vendor or the common folder!');
3737
}
@@ -109,7 +109,7 @@
109109
/**
110110
* Write documents.
111111
*
112-
* @param \PhpOffice\PhpPresentation\PhpPresentation $phpPresentation
112+
* @param PhpPresentation $phpPresentation
113113
* @param string $filename
114114
* @param array $writers
115115
*
@@ -180,7 +180,7 @@ function getEndingNotes($writers)
180180
/**
181181
* Creates a templated slide.
182182
*/
183-
function createTemplatedSlide(PHPPresentation $objPHPPresentation): Slide
183+
function createTemplatedSlide(PhpPresentation $objPHPPresentation): Slide
184184
{
185185
// Create slide
186186
$slide = $objPHPPresentation->createSlide();
@@ -326,7 +326,7 @@ protected function displayPhpPresentationInfo(PhpPresentation $oPHPPpt): void
326326
}
327327
}
328328
$oNote = $oSlide->getNote();
329-
if ($oNote->getShapeCollection()->count() > 0) {
329+
if (count($oNote->getShapeCollection()) > 0) {
330330
$this->append('<dt>Notes</dt>');
331331
foreach ($oNote->getShapeCollection() as $oShape) {
332332
if ($oShape instanceof RichText) {
@@ -366,11 +366,11 @@ protected function displayShapeInfo(AbstractShape $oShape): void
366366
$this->append('<dd>None</dd>');
367367
} else {
368368
switch ($oShape->getFill()->getFillType()) {
369-
case \PhpOffice\PhpPresentation\Style\Fill::FILL_NONE:
369+
case PhpOffice\PhpPresentation\Style\Fill::FILL_NONE:
370370
$this->append('<dd>None</dd>');
371371

372372
break;
373-
case \PhpOffice\PhpPresentation\Style\Fill::FILL_SOLID:
373+
case PhpOffice\PhpPresentation\Style\Fill::FILL_SOLID:
374374
$this->append('<dd>Solid (');
375375
$this->append('Color : #' . $oShape->getFill()->getStartColor()->getRGB());
376376
$this->append(' - Alpha : ' . $oShape->getFill()->getStartColor()->getAlpha() . '%');
@@ -442,6 +442,7 @@ protected function displayShapeInfo(AbstractShape $oShape): void
442442
$this->append('<abbr title="Italic">Italic</abbr> : ' . ($oRichText->getFont()->isItalic() ? 'Y' : 'N') . ' - ');
443443
$this->append('<abbr title="Underline">Underline</abbr> : Underline::' . $this->getConstantName('\PhpOffice\PhpPresentation\Style\Font', $oRichText->getFont()->getUnderline()) . ' - ');
444444
$this->append('<abbr title="Strikethrough">Strikethrough</abbr> : ' . ($oRichText->getFont()->isStrikethrough() ? 'Y' : 'N') . ' - ');
445+
$this->append('<abbr title="Baseline">Baseline</abbr> : ' . $oRichText->getFont()->getBaseline() . ' - ');
445446
$this->append('<abbr title="SubScript">SubScript</abbr> : ' . ($oRichText->getFont()->isSubScript() ? 'Y' : 'N') . ' - ');
446447
$this->append('<abbr title="SuperScript">SuperScript</abbr> : ' . ($oRichText->getFont()->isSuperScript() ? 'Y' : 'N'));
447448
$this->append('</dd>');

src/PhpPresentation/AbstractShape.php

+47-10
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
namespace PhpOffice\PhpPresentation;
2121

2222
use PhpOffice\PhpPresentation\Exception\ShapeContainerAlreadyAssignedException;
23+
use PhpOffice\PhpPresentation\Shape\Group;
2324
use PhpOffice\PhpPresentation\Shape\Hyperlink;
2425
use PhpOffice\PhpPresentation\Shape\Placeholder;
2526
use PhpOffice\PhpPresentation\Style\Border;
@@ -109,6 +110,13 @@ abstract class AbstractShape implements ComparableInterface
109110
*/
110111
private $hashIndex;
111112

113+
/**
114+
* Name.
115+
*
116+
* @var string
117+
*/
118+
protected $name = '';
119+
112120
/**
113121
* Create a new self.
114122
*/
@@ -118,7 +126,8 @@ public function __construct()
118126
$this->fill = new Fill();
119127
$this->shadow = new Shadow();
120128
$this->border = new Border();
121-
$this->border->setLineStyle(Style\Border::LINE_NONE);
129+
130+
$this->border->setLineStyle(Border::LINE_NONE);
122131
}
123132

124133
/**
@@ -127,9 +136,20 @@ public function __construct()
127136
public function __clone()
128137
{
129138
$this->container = null;
130-
$this->fill = clone $this->fill;
139+
$this->name = $this->name;
131140
$this->border = clone $this->border;
132-
$this->shadow = clone $this->shadow;
141+
if (isset($this->fill)) {
142+
$this->fill = clone $this->fill;
143+
}
144+
if (isset($this->shadow)) {
145+
$this->shadow = clone $this->shadow;
146+
}
147+
if (isset($this->placeholder)) {
148+
$this->placeholder = clone $this->placeholder;
149+
}
150+
if (isset($this->hyperlink)) {
151+
$this->hyperlink = clone $this->hyperlink;
152+
}
133153
}
134154

135155
/**
@@ -153,21 +173,18 @@ public function setContainer(?ShapeContainerInterface $pValue = null, $pOverride
153173
// Add drawing to ShapeContainerInterface
154174
$this->container = $pValue;
155175
if (null !== $this->container) {
156-
$this->container->getShapeCollection()->append($this);
176+
$this->container->addShape($this);
157177
}
158178
} else {
159179
if ($pOverrideOld) {
160180
// Remove drawing from old ShapeContainerInterface
161-
$iterator = $this->container->getShapeCollection()->getIterator();
162-
163-
while ($iterator->valid()) {
164-
if ($iterator->current()->getHashCode() == $this->getHashCode()) {
165-
$this->container->getShapeCollection()->offsetUnset($iterator->key());
181+
foreach ($this->container->getShapeCollection() as $key => $shape) {
182+
if ($shape->getHashCode() == $this->getHashCode()) {
183+
$this->container->unsetShape($key);
166184
$this->container = null;
167185

168186
break;
169187
}
170-
$iterator->next();
171188
}
172189

173190
// Set new \PhpOffice\PhpPresentation\Slide
@@ -180,6 +197,26 @@ public function setContainer(?ShapeContainerInterface $pValue = null, $pOverride
180197
return $this;
181198
}
182199

200+
/**
201+
* Get Name.
202+
*/
203+
public function getName(): string
204+
{
205+
return $this->name;
206+
}
207+
208+
/**
209+
* Set Name.
210+
*
211+
* @return static
212+
*/
213+
public function setName(string $pValue = ''): self
214+
{
215+
$this->name = $pValue;
216+
217+
return $this;
218+
}
219+
183220
/**
184221
* Get OffsetX.
185222
*/

0 commit comments

Comments
 (0)