Skip to content
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

PowerPoint 2007 Reader/Writer : Improvements on Font, RichText, Thumbnail, Presentation Properties & Shadow #788

Merged
merged 23 commits into from
Jan 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
715e943
Add read/write Revision document attribut
devX2712 Aug 14, 2020
71fee9c
Conserve thumbnail if already exist in file
devX2712 Aug 14, 2020
24839e6
BUGFIX whe setting image ressource
devX2712 Aug 16, 2020
8e8ae7c
EVOL Move Shape name to AbstractShape
devX2712 Aug 16, 2020
25c99a2
BUGFIX - Name, in shape, is not preserved if not a placeholder
devX2712 Sep 12, 2020
0231826
CHG-Load also richtext shape without text
devX2712 Sep 12, 2020
3f1ff7b
ADD-Preserve shape properties (background color, etc.) for richttext
devX2712 Sep 12, 2020
b237d34
ADD-Shape RichtText preserve spelling lang while loading
devX2712 Sep 12, 2020
cef70f6
ADD-Preserve shape richtext font face while loading file
devX2712 Sep 12, 2020
33c4619
EVOL-Allow different style of strick paragraph
devX2712 Sep 13, 2020
cd9a17f
EVOL-Define const for strike types
devX2712 Sep 13, 2020
5aecc8d
EVOL-Super script and sub script for paragraph
devX2712 Sep 13, 2020
afc58c0
ADD Property 'status' reading and writing
devX2712 Jan 27, 2021
db96a0a
BUGFIX while cloning an existant slide
devX2712 Feb 1, 2021
9f3f686
ADD Read also texte zone margin RLTB
devX2712 Feb 2, 2021
cdaa211
ADD Vertical alignment for shape RichText
devX2712 Feb 2, 2021
3dfc5f5
ADD Effect managment to Shape,Paragraph and Text
devX2712 Feb 2, 2021
0be11d0
BUGFIX for duplacting slide
devX2712 Feb 3, 2021
a49854f
ADD vertical alos need horz sometimes
devX2712 Feb 3, 2021
7a31dbb
ADD Get more font attributs
devX2712 Feb 3, 2021
0e03232
BUGFIX Forgot clone for effect shape
devX2712 Feb 3, 2021
0e5dd85
ADD usefull function te search shape into a slide
devX2712 Feb 3, 2021
ec4700e
Feedbacks from @Progi1984
Progi1984 Dec 13, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ Desktop.ini
### Continuous Integration
build/
phpunit.xml
php-cs-fixer.phar
.php-cs-fixer.cache
.phpunit.result.cache
composer.phar
Expand Down
15 changes: 15 additions & 0 deletions docs/changes/1.1.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,24 @@
- PowerPoint2007 Reader
- PowerPoint2007 Writer
- PowerPoint2007 Writer: Enable style and position of a Placeholder - [@qmachard](https://github.com/qmachard) in [#787](https://github.com/PHPOffice/PHPPresentation/pull/787)
- PowerPoint2007 Reader: Added support for thumbnail image - [@devX2712](https://github.com/devX2712) in [#788](https://github.com/PHPOffice/PHPPresentation/pull/787)

## Improvements
- Slide : Raised max value for identifier rand call - [@Scheissy](https://github.com/Scheissy) in [#777](https://github.com/PHPOffice/PHPPresentation/pull/777)
- Document Properties : Support for Revision & Status - [@devX2712](https://github.com/devX2712) in [#788](https://github.com/PHPOffice/PHPPresentation/pull/787)
- PowerPoint2007 Reader
- PowerPoint2007 Writer
- Presentation Properties : Added support to define content of the thumbnail - [@devX2712](https://github.com/devX2712) in [#788](https://github.com/PHPOffice/PHPPresentation/pull/787)
- Font : Support for Capitalization, Strikethrough, Pitch Family, Charset & Panose - [@devX2712](https://github.com/devX2712) in [#788](https://github.com/PHPOffice/PHPPresentation/pull/787)
- PowerPoint2007 Reader
- PowerPoint2007 Writer
- Font : Replaced Superscript/Subscript by baseline in PowerPoint2007 Writer - [@devX2712](https://github.com/devX2712) in [#788](https://github.com/PHPOffice/PHPPresentation/pull/787)
- RichText : Support for Vertical Align - [@devX2712](https://github.com/devX2712) in [#788](https://github.com/PHPOffice/PHPPresentation/pull/787)
- PowerPoint2007 Reader
- PowerPoint2007 Writer
- Shadow : Support for Type Inner & Reflection - [@devX2712](https://github.com/devX2712) in [#788](https://github.com/PHPOffice/PHPPresentation/pull/787)
- PowerPoint2007 Reader
- PowerPoint2007 Writer

## Bugfixes

Expand Down
32 changes: 31 additions & 1 deletion docs/usage/presentation.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ $properties->setCreated(mktime(0, 0, 0, 3, 12, 2014));
$properties->setModified(mktime(0, 0, 0, 3, 14, 2014));
$properties->setSubject('My subject');
$properties->setKeywords('my, key, word');
$properties->setStatus('Work in Progress');
$properties->setRevision('Version 1.2.3');
```

### Custom Properties
Expand Down Expand Up @@ -203,16 +205,44 @@ echo $properties->getSlideshowType();

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


#### From a file
``` php
<?php

use PhpOffice\PhpPresentation\PresentationProperties;

$presentation = new PhpPresentation();

$properties = $presentation->getPresentationProperties();
// Set path of the thumbnail
$properties->setThumbnailPath(__DIR__.'\resources\phppowerpoint_logo.gif');
$properties->setThumbnailPath(
__DIR__.'\resources\phppowerpoint_logo.gif',
PresentationProperties::THUMBNAIL_FILE
);
// Get path of the thumbnail
echo $properties->getThumbnailPath();
// Get content of the thumbnail
echo $properties->getThumbnail();
```

#### From the content of the file
``` php
<?php

use PhpOffice\PhpPresentation\PresentationProperties;

$presentation = new PhpPresentation();

$properties = $presentation->getPresentationProperties();
// Set path of the thumbnail
$properties->setThumbnailPath(
'',
PresentationProperties::THUMBNAIL_DATA,
file_get_contents(__DIR__.'\resources\phppowerpoint_logo.gif')
);
// Get content of the thumbnail
echo $properties->getThumbnail();
```

### Zoom
Expand Down
35 changes: 32 additions & 3 deletions docs/usage/styles.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,12 +97,24 @@ echo $alignment->isRTL();
- `name`
- `bold`
- `italic`
- `superScript`
- `subScript`
- `superScript` (deprecated)
- `subScript` (deprecated)
- `underline`
- `strikethrough`
- `color`
- `capitalization`
- `pitchFamily`
- `charset`

### Baseline

The baseline set the position relative to the line.
The value is a percentage.

You can use some predefined values :

* `Font::BASELINE_SUPERSCRIPT` (= 300000 = 300%)
* `Font::BASELINE_SUBSCRIPT` (= -250000 = -250%)


### Capitalization

Expand Down Expand Up @@ -145,6 +157,23 @@ $font->setFormat(Font::FORMAT_EAST_ASIAN);
// Get format of font
echo $font->getFormat();
```

### Panose
The support of Panose 1.0 is only used.

``` php
<?php

use PhpOffice\PhpPresentation\Style\Font;

$font = new Font();

// Set panose of font
$font->setPanose('4494D72242');
// Get panose of font
echo $font->getPanose();
```

## Bullet

- `bulletType`
Expand Down
2 changes: 1 addition & 1 deletion samples/Sample_04_Table.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@
$oCell->createTextRun('R2C1');
$oCell->getActiveParagraph()->getAlignment()
->setMarginLeft(30)
->setTextDirection(\PhpOffice\PhpPresentation\Style\Alignment::TEXT_DIRECTION_VERTICAL_270);
->setTextDirection(PhpOffice\PhpPresentation\Style\Alignment::TEXT_DIRECTION_VERTICAL_270);
$oCell = $row->nextCell();
$oCell->createTextRun('R2C2');
$oCell->getActiveParagraph()->getAlignment()
Expand Down
4 changes: 2 additions & 2 deletions samples/Sample_05_Chart.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ function fnSlide_BarHorizontal(PhpPresentation $objPHPPresentation): void

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

// Create templated slide
Expand Down Expand Up @@ -363,7 +363,7 @@ function fnSlide_Bar3DHorizontal(PhpPresentation $objPHPPresentation): void

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

// Create templated slide
Expand Down
6 changes: 3 additions & 3 deletions samples/Sample_17_Comment.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@
$oSlide1->addShape(clone $oShapeDrawing);
$oSlide1->addShape(clone $oShapeRichText);

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

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

// Add Comment
echo date('H:i:s') . ' Add Comment 2' . EOL;
$oComment2 = new \PhpOffice\PhpPresentation\Shape\Comment();
$oComment2 = new PhpOffice\PhpPresentation\Shape\Comment();
$oComment2->setText('Text B');
$oComment2->setOffsetX(170);
$oComment2->setOffsetY(180);
Expand Down
2 changes: 1 addition & 1 deletion samples/Sample_22_ExternalSlide.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
$objPHPPresentation = new PhpPresentation();
$objPHPPresentation->removeSlideByIndex(0);

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

foreach ($oPresentation04->getAllSlides() as $oSlide) {
Expand Down
13 changes: 7 additions & 6 deletions samples/Sample_Header.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
} else {
if (is_file(__DIR__ . '/../../Common/src/Common/Autoloader.php')) {
include_once __DIR__ . '/../../Common/src/Common/Autoloader.php';
\PhpOffice\Common\Autoloader::register();
PhpOffice\Common\Autoloader::register();
} else {
throw new Exception('Can not find the vendor or the common folder!');
}
Expand Down Expand Up @@ -109,7 +109,7 @@
/**
* Write documents.
*
* @param \PhpOffice\PhpPresentation\PhpPresentation $phpPresentation
* @param PhpPresentation $phpPresentation
* @param string $filename
* @param array $writers
*
Expand Down Expand Up @@ -180,7 +180,7 @@ function getEndingNotes($writers)
/**
* Creates a templated slide.
*/
function createTemplatedSlide(PHPPresentation $objPHPPresentation): Slide
function createTemplatedSlide(PhpPresentation $objPHPPresentation): Slide
{
// Create slide
$slide = $objPHPPresentation->createSlide();
Expand Down Expand Up @@ -326,7 +326,7 @@ protected function displayPhpPresentationInfo(PhpPresentation $oPHPPpt): void
}
}
$oNote = $oSlide->getNote();
if ($oNote->getShapeCollection()->count() > 0) {
if (count($oNote->getShapeCollection()) > 0) {
$this->append('<dt>Notes</dt>');
foreach ($oNote->getShapeCollection() as $oShape) {
if ($oShape instanceof RichText) {
Expand Down Expand Up @@ -366,11 +366,11 @@ protected function displayShapeInfo(AbstractShape $oShape): void
$this->append('<dd>None</dd>');
} else {
switch ($oShape->getFill()->getFillType()) {
case \PhpOffice\PhpPresentation\Style\Fill::FILL_NONE:
case PhpOffice\PhpPresentation\Style\Fill::FILL_NONE:
$this->append('<dd>None</dd>');

break;
case \PhpOffice\PhpPresentation\Style\Fill::FILL_SOLID:
case PhpOffice\PhpPresentation\Style\Fill::FILL_SOLID:
$this->append('<dd>Solid (');
$this->append('Color : #' . $oShape->getFill()->getStartColor()->getRGB());
$this->append(' - Alpha : ' . $oShape->getFill()->getStartColor()->getAlpha() . '%');
Expand Down Expand Up @@ -442,6 +442,7 @@ protected function displayShapeInfo(AbstractShape $oShape): void
$this->append('<abbr title="Italic">Italic</abbr> : ' . ($oRichText->getFont()->isItalic() ? 'Y' : 'N') . ' - ');
$this->append('<abbr title="Underline">Underline</abbr> : Underline::' . $this->getConstantName('\PhpOffice\PhpPresentation\Style\Font', $oRichText->getFont()->getUnderline()) . ' - ');
$this->append('<abbr title="Strikethrough">Strikethrough</abbr> : ' . ($oRichText->getFont()->isStrikethrough() ? 'Y' : 'N') . ' - ');
$this->append('<abbr title="Baseline">Baseline</abbr> : ' . $oRichText->getFont()->getBaseline() . ' - ');
$this->append('<abbr title="SubScript">SubScript</abbr> : ' . ($oRichText->getFont()->isSubScript() ? 'Y' : 'N') . ' - ');
$this->append('<abbr title="SuperScript">SuperScript</abbr> : ' . ($oRichText->getFont()->isSuperScript() ? 'Y' : 'N'));
$this->append('</dd>');
Expand Down
57 changes: 47 additions & 10 deletions src/PhpPresentation/AbstractShape.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
namespace PhpOffice\PhpPresentation;

use PhpOffice\PhpPresentation\Exception\ShapeContainerAlreadyAssignedException;
use PhpOffice\PhpPresentation\Shape\Group;
use PhpOffice\PhpPresentation\Shape\Hyperlink;
use PhpOffice\PhpPresentation\Shape\Placeholder;
use PhpOffice\PhpPresentation\Style\Border;
Expand Down Expand Up @@ -109,6 +110,13 @@ abstract class AbstractShape implements ComparableInterface
*/
private $hashIndex;

/**
* Name.
*
* @var string
*/
protected $name = '';

/**
* Create a new self.
*/
Expand All @@ -118,7 +126,8 @@ public function __construct()
$this->fill = new Fill();
$this->shadow = new Shadow();
$this->border = new Border();
$this->border->setLineStyle(Style\Border::LINE_NONE);

$this->border->setLineStyle(Border::LINE_NONE);
}

/**
Expand All @@ -127,9 +136,20 @@ public function __construct()
public function __clone()
{
$this->container = null;
$this->fill = clone $this->fill;
$this->name = $this->name;
$this->border = clone $this->border;
$this->shadow = clone $this->shadow;
if (isset($this->fill)) {
$this->fill = clone $this->fill;
}
if (isset($this->shadow)) {
$this->shadow = clone $this->shadow;
}
if (isset($this->placeholder)) {
$this->placeholder = clone $this->placeholder;
}
if (isset($this->hyperlink)) {
$this->hyperlink = clone $this->hyperlink;
}
}

/**
Expand All @@ -153,21 +173,18 @@ public function setContainer(?ShapeContainerInterface $pValue = null, $pOverride
// Add drawing to ShapeContainerInterface
$this->container = $pValue;
if (null !== $this->container) {
$this->container->getShapeCollection()->append($this);
$this->container->addShape($this);
}
} else {
if ($pOverrideOld) {
// Remove drawing from old ShapeContainerInterface
$iterator = $this->container->getShapeCollection()->getIterator();

while ($iterator->valid()) {
if ($iterator->current()->getHashCode() == $this->getHashCode()) {
$this->container->getShapeCollection()->offsetUnset($iterator->key());
foreach ($this->container->getShapeCollection() as $key => $shape) {
if ($shape->getHashCode() == $this->getHashCode()) {
$this->container->unsetShape($key);
$this->container = null;

break;
}
$iterator->next();
}

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

/**
* Get Name.
*/
public function getName(): string
{
return $this->name;
}

/**
* Set Name.
*
* @return static
*/
public function setName(string $pValue = ''): self
{
$this->name = $pValue;

return $this;
}

/**
* Get OffsetX.
*/
Expand Down
Loading
Loading