Skip to content

Commit

Permalink
Merge pull request #656 from Progi1984/showType
Browse files Browse the repository at this point in the history
Support for Slideshow Type (Fullscreen/Window/Kiosk mode)
  • Loading branch information
Progi1984 authored Jul 22, 2021
2 parents 743d0cf + 18bc39b commit c0d5bbd
Show file tree
Hide file tree
Showing 14 changed files with 357 additions and 45 deletions.
21 changes: 14 additions & 7 deletions docs/changes/1.0.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,20 @@
- PowerPoint2007 Reader : Load images in their initial format (and not by default in PNG) - @polidog GH-553

## Features
- ODPresentation Writer : Support for the position of Legend - @Progi1984 GH-355
- ODPresentation Writer : Support for DoughnutChart - @Progi1984 GH-355
- PowerPoint2007 Writer : Support for DoughnutChart - @Progi1984 GH-355
- ODPresentation Reader : Support for fill for image - @Progi1984 GH-370
- PowerPoint2007 Reader : Support for fill for image - @Progi1984 GH-370
- ODPresentation Writer : Support for fill for transparent image - @Progi1984 GH-370
- PowerPoint2007 Writer : Support for fill for transparent image - @JewrassicPark GH-370
- Support for the position of Legend in ODPresentation Writer - @Progi1984 GH-355
- Support for DoughnutChart - @Progi1984 GH-355
- ODPresentation Writer
- PowerPoint2007 Writer
- Support for fill for transparent image - @Progi1984 & @JewrassicPark GH-370
- ODPresentation Reader
- ODPresentation Writer
- PowerPoint2007 Reader
- PowerPoint2007 Writer
- Support for Slideshow Type (Fullscreen/Window/Kiosk mode) - @zmip GH-588 & @Progi1986 GH-656
- ODPresentation Reader
- ODPresentation Writer
- PowerPoint2007 Reader
- PowerPoint2007 Writer

## Project Management
- Migrated from Travis CI to Github Actions - @Progi1984 GH-635
Expand Down
Binary file added docs/images/presentation_slideshow_type.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
26 changes: 26 additions & 0 deletions docs/usage/presentation.md
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,32 @@ $state = $presentation->isMarkedAsFinal();
// $state = true
```

### Slideshow type

You can define the type of slideshow you can with the method `setSlideshowType`.

![Slideshow type](/PHPPresentation/images/presentation_slideshow_type.png)

Differents types are available:

* `PresentationProperties::SLIDESHOW_TYPE_PRESENT` for **Presented by a speaker**
* `PresentationProperties::SLIDESHOW_TYPE_BROWSE` for **Browsed by an individual**
* `PresentationProperties::SLIDESHOW_TYPE_KIOSK` for **Browsed at a kiosk**

``` php
<?php

use PhpOffice\PhpPresentation\PresentationProperties;

$presentation = new PhpPresentation();

$properties = $presentation->getPresentationProperties();
// Set type of slideshow
$properties->setSlideshowType(PresentationProperties::SLIDESHOW_TYPE_PRESENT);
// Get type of slideshow
echo $properties->getSlideshowType();
```

### Thumbnail

You can define the thumbnail of the presentation with the method `setThumbnailPath`.
Expand Down
61 changes: 49 additions & 12 deletions src/PhpPresentation/PresentationProperties.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@

namespace PhpOffice\PhpPresentation;

/**
* \PhpOffice\PhpPresentation\PresentationProperties.
*/
class PresentationProperties
{
public const VIEW_HANDOUT = 'handoutView';
Expand All @@ -46,6 +43,19 @@ class PresentationProperties
self::VIEW_SLIDE_THUMBNAIL,
];

public const SLIDESHOW_TYPE_PRESENT = 'present';
public const SLIDESHOW_TYPE_BROWSE = 'browse';
public const SLIDESHOW_TYPE_KIOSK = 'kiosk';

/**
* @var array<int, string>
*/
protected $arraySlideshowTypes = [
self::SLIDESHOW_TYPE_PRESENT,
self::SLIDESHOW_TYPE_BROWSE,
self::SLIDESHOW_TYPE_KIOSK,
];

/**
* @var bool
*/
Expand All @@ -59,7 +69,7 @@ class PresentationProperties
protected $markAsFinal = false;

/**
* @var string
* @var string|null
*/
protected $thumbnail;

Expand All @@ -75,6 +85,11 @@ class PresentationProperties
*/
protected $lastView = self::VIEW_SLIDE;

/**
* @var string
*/
protected $slideshowType = self::SLIDESHOW_TYPE_PRESENT;

/**
* @var bool
*/
Expand All @@ -95,9 +110,9 @@ public function setLoopContinuouslyUntilEsc(bool $value = false): self
/**
* Return the thumbnail file path.
*
* @return string
* @return string|null
*/
public function getThumbnailPath()
public function getThumbnailPath(): ?string
{
return $this->thumbnail;
}
Expand All @@ -107,9 +122,9 @@ public function getThumbnailPath()
*
* @param string $path
*
* @return \PhpOffice\PhpPresentation\PresentationProperties
* @return self
*/
public function setThumbnailPath($path = '')
public function setThumbnailPath(string $path = ''): self
{
if (file_exists($path)) {
$this->thumbnail = $path;
Expand All @@ -133,7 +148,7 @@ public function markAsFinal(bool $state = true): self
*
* @return bool
*/
public function isMarkedAsFinal()
public function isMarkedAsFinal(): bool
{
return $this->markAsFinal;
}
Expand All @@ -159,9 +174,9 @@ public function getZoom(): float
/**
* @param string $value
*
* @return $this
* @return self
*/
public function setLastView($value = self::VIEW_SLIDE)
public function setLastView(string $value = self::VIEW_SLIDE): self
{
if (in_array($value, $this->arrayView)) {
$this->lastView = $value;
Expand All @@ -173,7 +188,7 @@ public function setLastView($value = self::VIEW_SLIDE)
/**
* @return string
*/
public function getLastView()
public function getLastView(): string
{
return $this->lastView;
}
Expand All @@ -189,4 +204,26 @@ public function isCommentVisible(): bool
{
return $this->isCommentVisible;
}

/**
* @return string
*/
public function getSlideshowType(): string
{
return $this->slideshowType;
}

/**
* @param string $value
*
* @return self
*/
public function setSlideshowType(string $value = self::SLIDESHOW_TYPE_PRESENT): self
{
if (in_array($value, $this->arraySlideshowTypes)) {
$this->slideshowType = $value;
}

return $this;
}
}
12 changes: 12 additions & 0 deletions src/PhpPresentation/Reader/ODPresentation.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
use PhpOffice\Common\Drawing as CommonDrawing;
use PhpOffice\Common\XMLReader;
use PhpOffice\PhpPresentation\PhpPresentation;
use PhpOffice\PhpPresentation\PresentationProperties;
use PhpOffice\PhpPresentation\Shape\Drawing\Gd;
use PhpOffice\PhpPresentation\Shape\RichText;
use PhpOffice\PhpPresentation\Shape\RichText\Paragraph;
Expand Down Expand Up @@ -147,6 +148,7 @@ protected function loadFile($pFilename)
$this->oXMLReader = new XMLReader();
if (false !== $this->oXMLReader->getDomFromZip($pFilename, 'content.xml')) {
$this->loadSlides();
$this->loadPresentationProperties();
}

return $this->oPhpPresentation;
Expand Down Expand Up @@ -201,6 +203,16 @@ protected function loadSlides(): void
}
}

protected function loadPresentationProperties(): void
{
$element = $this->oXMLReader->getElement('/office:document-content/office:body/office:presentation/presentation:settings');
if ($element instanceof DOMElement) {
if ($element->getAttribute('presentation:full-screen') === 'false') {
$this->oPhpPresentation->getPresentationProperties()->setSlideshowType(PresentationProperties::SLIDESHOW_TYPE_BROWSE);
}
}
}

/**
* Extract style.
*
Expand Down
40 changes: 40 additions & 0 deletions src/PhpPresentation/Reader/PowerPoint2007.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
use PhpOffice\Common\XMLReader;
use PhpOffice\PhpPresentation\DocumentLayout;
use PhpOffice\PhpPresentation\PhpPresentation;
use PhpOffice\PhpPresentation\PresentationProperties;
use PhpOffice\PhpPresentation\Shape\Drawing\Gd;
use PhpOffice\PhpPresentation\Shape\Placeholder;
use PhpOffice\PhpPresentation\Shape\RichText;
Expand Down Expand Up @@ -164,6 +165,11 @@ protected function loadFile(string $pFilename): PhpPresentation
$this->loadSlides($pptPresentation);
}

$pptPresProps = $this->oZip->getFromName('ppt/presProps.xml');
if (false !== $pptPresProps) {
$this->loadPresentationProperties($pptPresentation);
}

return $this->oPhpPresentation;
}

Expand Down Expand Up @@ -246,6 +252,40 @@ protected function loadCustomProperties(string $sPart): void
}
}

/**
* Read Presentation Properties
*/
protected function loadPresentationProperties(string $sPart): void
{
$xmlReader = new XMLReader();
/* @phpstan-ignore-next-line */
if ($xmlReader->getDomFromString($sPart)) {
$element = $xmlReader->getElement('/p:presentationPr/p:showPr');
if ($element instanceof DOMElement) {
if ($element->hasAttribute('loop')) {
$this->oPhpPresentation->getPresentationProperties()->setLoopContinuouslyUntilEsc(
(bool) $element->getAttribute('loop')
);
}
if (null !== $xmlReader->getElement('p:present', $element)) {
$this->oPhpPresentation->getPresentationProperties()->setSlideshowType(
PresentationProperties::SLIDESHOW_TYPE_PRESENT
);
}
if (null !== $xmlReader->getElement('p:browse', $element)) {
$this->oPhpPresentation->getPresentationProperties()->setSlideshowType(
PresentationProperties::SLIDESHOW_TYPE_BROWSE
);
}
if (null !== $xmlReader->getElement('p:kiosk', $element)) {
$this->oPhpPresentation->getPresentationProperties()->setSlideshowType(
PresentationProperties::SLIDESHOW_TYPE_KIOSK
);
}
}
}
}

/**
* Read View Properties.
*/
Expand Down
14 changes: 10 additions & 4 deletions src/PhpPresentation/Writer/ODPresentation/Content.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use PhpOffice\Common\Drawing as CommonDrawing;
use PhpOffice\Common\Text;
use PhpOffice\Common\XMLWriter;
use PhpOffice\PhpPresentation\PresentationProperties;
use PhpOffice\PhpPresentation\Shape\Chart;
use PhpOffice\PhpPresentation\Shape\Comment;
use PhpOffice\PhpPresentation\Shape\Drawing\AbstractDrawingAdapter;
Expand Down Expand Up @@ -252,7 +253,7 @@ public function writeContent(): string
//===============================================
// office:body
$objWriter->startElement('office:body');
// office:presentation
// office:body > office:presentation
$objWriter->startElement('office:presentation');

// Write slides
Expand Down Expand Up @@ -300,13 +301,18 @@ public function writeContent(): string
$objWriter->endElement();
}

// office:document-content > office:body > office:presentation > presentation:settings
$objWriter->startElement('presentation:settings');
if ($this->getPresentation()->getPresentationProperties()->isLoopContinuouslyUntilEsc()) {
$objWriter->startElement('presentation:settings');
$objWriter->writeAttribute('presentation:endless', 'true');
$objWriter->writeAttribute('presentation:pause', 'P0s');
$objWriter->writeAttribute('presentation:pause', 'PT0S');
$objWriter->writeAttribute('presentation:mouse-visible', 'false');
$objWriter->endElement();
}
if ($this->getPresentation()->getPresentationProperties()->getSlideshowType() === PresentationProperties::SLIDESHOW_TYPE_BROWSE) {
$objWriter->writeAttribute('presentation:full-screen', 'false');
}
$objWriter->endElement();

// > office:presentation
$objWriter->endElement();
// > office:body
Expand Down
11 changes: 9 additions & 2 deletions src/PhpPresentation/Writer/PowerPoint2007/PptPresProps.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,18 @@ public function render()
$objWriter->writeAttribute('xmlns:p', 'http://schemas.openxmlformats.org/presentationml/2006/main');

// p:presentationPr > p:showPr
$objWriter->startElement('p:showPr');
if ($presentationPpts->isLoopContinuouslyUntilEsc()) {
$objWriter->startElement('p:showPr');
$objWriter->writeAttribute('loop', '1');
$objWriter->endElement();
}
// Depends on the slideshow type
// p:presentationPr > p:showPr > p:present
// p:presentationPr > p:showPr > p:browse
// p:presentationPr > p:showPr > p:kiosk
$objWriter->writeElement('p:' . $presentationPpts->getSlideshowType());

// > p:presentationPr > p:showPr
$objWriter->endElement();

// p:extLst
$objWriter->startElement('p:extLst');
Expand Down
Loading

0 comments on commit c0d5bbd

Please sign in to comment.