diff --git a/docs/changes/1.2.0.md b/docs/changes/1.2.0.md index 787e3b376..159a5963b 100644 --- a/docs/changes/1.2.0.md +++ b/docs/changes/1.2.0.md @@ -13,6 +13,7 @@ - ODPresentation Writer : Support for rotation for RichText by [@Progi1984](https://github.com/Progi1984) fixing [#279](https://github.com/PHPOffice/PHPPresentation/pull/279) in [#409](https://github.com/PHPOffice/PHPPresentation/pull/409) - HTML Writer by [@Progi1984](https://github.com/Progi1984) fixing [#221](https://github.com/PHPOffice/PHPPresentation/pull/221), [#567](https://github.com/PHPOffice/PHPPresentation/pull/567), [#644](https://github.com/PHPOffice/PHPPresentation/pull/644) in [#850](https://github.com/PHPOffice/PHPPresentation/pull/855) - PDF Writer by [@Progi1984](https://github.com/Progi1984) fixing [#181](https://github.com/PHPOffice/PHPPresentation/pull/181), [#381](https://github.com/PHPOffice/PHPPresentation/pull/381), [#472](https://github.com/PHPOffice/PHPPresentation/pull/472), [#693](https://github.com/PHPOffice/PHPPresentation/pull/693), [#725](https://github.com/PHPOffice/PHPPresentation/pull/725) in [#850](https://github.com/PHPOffice/PHPPresentation/pull/855) +- PowerPoint2007 Reader : Support for BarChart by [@Progi1984](https://github.com/Progi1984) fixing [#824](https://github.com/PHPOffice/PHPPresentation/pull/824) in [#856](https://github.com/PHPOffice/PHPPresentation/pull/856) ## Bug fixes @@ -30,3 +31,4 @@ - CI: Added ODFValidator by [@Progi1984](https://github.com/Progi1984) fixing [#678](https://github.com/PHPOffice/PHPWord/issues/678) in [#653](https://github.com/PHPOffice/PHPWord/pull/653) ## BC Breaks +- \PhpOffice\PhpPresentation\Style\Border::lineWidth use pixels as reference (and not anymore points) diff --git a/docs/index.md b/docs/index.md index 84d4004d8..29649696f 100644 --- a/docs/index.md +++ b/docs/index.md @@ -86,10 +86,10 @@ Below are the supported features for each file formats. | | Image | :material-check: | :material-check: | :material-check: | | | Hyperlink | :material-check: | :material-check: | :material-check: | | | RichText | :material-check: | :material-check: | :material-check: | -| | Table | | | | +| | Table | | | :material-check: | | | Text | :material-check: | :material-check: | :material-check: | | **Charts** | Area | | | | -| | Bar | | | | +| | Bar | | | :material-check: | | | Bar3D | | | | | | Doughnut | | | | | | Line | | | | diff --git a/phpmd.xml.dist b/phpmd.xml.dist index 2499a0658..ddaebf65e 100644 --- a/phpmd.xml.dist +++ b/phpmd.xml.dist @@ -26,7 +26,7 @@ - + diff --git a/samples/Sample_01_Complex.php b/samples/Sample_01_Complex.php index 15418fedd..33a75a301 100644 --- a/samples/Sample_01_Complex.php +++ b/samples/Sample_01_Complex.php @@ -182,7 +182,7 @@ ->setTooltip('PHPPresentation'); // Save file -echo write($objPHPPresentation, basename(__FILE__, '.php'), $writers); +echo write($objPHPPresentation, basename(__FILE__, '.php')); if (!CLI) { include_once 'Sample_Footer.php'; } diff --git a/samples/Sample_01_Simple.php b/samples/Sample_01_Simple.php index 706613782..4d7d63c52 100644 --- a/samples/Sample_01_Simple.php +++ b/samples/Sample_01_Simple.php @@ -72,7 +72,7 @@ ->setName('B Nazanin'); // Save file -echo write($objPHPPresentation, basename(__FILE__, '.php'), $writers); +echo write($objPHPPresentation, basename(__FILE__, '.php')); if (!CLI) { include_once 'Sample_Footer.php'; } diff --git a/samples/Sample_02_Serialized.php b/samples/Sample_02_Serialized.php index 26ec633f9..75986a1a2 100644 --- a/samples/Sample_02_Serialized.php +++ b/samples/Sample_02_Serialized.php @@ -62,7 +62,7 @@ $objPHPPresentationLoaded = IOFactory::load(__DIR__ . '/results/' . basename(__FILE__, '.php') . '.phppt'); // Save file -echo write($objPHPPresentationLoaded, basename(__FILE__, '.php'), $writers); +echo write($objPHPPresentationLoaded, basename(__FILE__, '.php')); if (!CLI) { include_once 'Sample_Footer.php'; } diff --git a/samples/Sample_03_Image.php b/samples/Sample_03_Image.php index 02a0032a2..f6110f143 100644 --- a/samples/Sample_03_Image.php +++ b/samples/Sample_03_Image.php @@ -96,7 +96,7 @@ $currentSlide->addShape($shape); // Save file -echo write($objPHPPresentation, basename(__FILE__, '.php'), $writers); +echo write($objPHPPresentation, basename(__FILE__, '.php')); if (!CLI) { include_once 'Sample_Footer.php'; } diff --git a/samples/Sample_03_Video.php b/samples/Sample_03_Video.php index c28892c0f..7b8cd0d9e 100644 --- a/samples/Sample_03_Video.php +++ b/samples/Sample_03_Video.php @@ -29,7 +29,7 @@ $currentSlide->addShape($shape); // Save file -echo write($objPHPPresentation, basename(__FILE__, '.php'), $writers); +echo write($objPHPPresentation, basename(__FILE__, '.php')); if (!CLI) { include_once 'Sample_Footer.php'; } diff --git a/samples/Sample_04_Table.php b/samples/Sample_04_Table.php index e6558d623..2a4825879 100644 --- a/samples/Sample_04_Table.php +++ b/samples/Sample_04_Table.php @@ -138,7 +138,7 @@ $textRunC3->getHyperlink()->setUrl('https://google.com')->setTooltip('Google'); // Save file -echo write($objPHPPresentation, basename(__FILE__, '.php'), $writers); +echo write($objPHPPresentation, basename(__FILE__, '.php')); if (!CLI) { include_once 'Sample_Footer.php'; } diff --git a/samples/Sample_05_Chart.php b/samples/Sample_05_Chart.php index ad9c32f74..0dafb9640 100644 --- a/samples/Sample_05_Chart.php +++ b/samples/Sample_05_Chart.php @@ -706,7 +706,7 @@ function fnSlide_Scatter(PhpPresentation $objPHPPresentation): void fnSlide_Scatter($objPHPPresentation); // Save file -echo write($objPHPPresentation, basename(__FILE__, '.php'), $writers); +echo write($objPHPPresentation, basename(__FILE__, '.php')); if (!CLI) { include_once 'Sample_Footer.php'; } diff --git a/samples/Sample_05_Chart_Line.php b/samples/Sample_05_Chart_Line.php index a09084430..76a20f77c 100644 --- a/samples/Sample_05_Chart_Line.php +++ b/samples/Sample_05_Chart_Line.php @@ -225,7 +225,7 @@ $currentSlide->addShape($shape6); // Save file -echo EOL . write($objPHPPresentation, basename(__FILE__, '.php'), $writers); +echo EOL . write($objPHPPresentation, basename(__FILE__, '.php')); if (!CLI) { include_once 'Sample_Footer.php'; diff --git a/samples/Sample_05_Chart_with_PhpSpreadsheet.php b/samples/Sample_05_Chart_with_PhpSpreadsheet.php index bdbf79e75..1d3cf25ef 100644 --- a/samples/Sample_05_Chart_with_PhpSpreadsheet.php +++ b/samples/Sample_05_Chart_with_PhpSpreadsheet.php @@ -112,7 +112,7 @@ $shape->getLegend()->getFont()->setItalic(true); // Save file -echo write($objPHPPresentation, basename(__FILE__, '.php'), $writers); +echo write($objPHPPresentation, basename(__FILE__, '.php')); if (!CLI) { include_once 'Sample_Footer.php'; diff --git a/samples/Sample_06_Fill.php b/samples/Sample_06_Fill.php index 41bc149a6..7ba522ad3 100644 --- a/samples/Sample_06_Fill.php +++ b/samples/Sample_06_Fill.php @@ -69,7 +69,7 @@ } // Save file -echo write($objPHPPresentation, basename(__FILE__, '.php'), $writers); +echo write($objPHPPresentation, basename(__FILE__, '.php')); if (!CLI) { include_once 'Sample_Footer.php'; } diff --git a/samples/Sample_07_Border.php b/samples/Sample_07_Border.php index fff1aa1bb..c994911e6 100644 --- a/samples/Sample_07_Border.php +++ b/samples/Sample_07_Border.php @@ -59,7 +59,7 @@ } // Save file -echo write($objPHPPresentation, basename(__FILE__, '.php'), $writers); +echo write($objPHPPresentation, basename(__FILE__, '.php')); if (!CLI) { include_once 'Sample_Footer.php'; } diff --git a/samples/Sample_08_Group.php b/samples/Sample_08_Group.php index f22196696..c93eff148 100644 --- a/samples/Sample_08_Group.php +++ b/samples/Sample_08_Group.php @@ -51,7 +51,7 @@ ->setColor(new Color('FFE06B20')); // Save file -echo write($objPHPPresentation, basename(__FILE__, '.php'), $writers); +echo write($objPHPPresentation, basename(__FILE__, '.php')); if (!CLI) { include_once 'Sample_Footer.php'; } diff --git a/samples/Sample_09_SlideNote.php b/samples/Sample_09_SlideNote.php index 641c77863..685301de7 100644 --- a/samples/Sample_09_SlideNote.php +++ b/samples/Sample_09_SlideNote.php @@ -60,7 +60,7 @@ $oRichText->createParagraph()->createTextRun('Supports writing to different file formats'); // Save file -echo write($objPHPPresentation, basename(__FILE__, '.php'), $writers); +echo write($objPHPPresentation, basename(__FILE__, '.php')); if (!CLI) { include_once 'Sample_Footer.php'; } diff --git a/samples/Sample_10_Transition.php b/samples/Sample_10_Transition.php index 7cb732ecb..24581d43a 100644 --- a/samples/Sample_10_Transition.php +++ b/samples/Sample_10_Transition.php @@ -65,7 +65,7 @@ $slide1->addShape(clone $shapeRichText); // Save file -echo write($objPHPPresentation, basename(__FILE__, '.php'), $writers); +echo write($objPHPPresentation, basename(__FILE__, '.php')); if (!CLI) { include_once 'Sample_Footer.php'; } diff --git a/samples/Sample_11_Shape.php b/samples/Sample_11_Shape.php index 003746480..a4be8bbd0 100644 --- a/samples/Sample_11_Shape.php +++ b/samples/Sample_11_Shape.php @@ -167,7 +167,7 @@ function fnSlideRichTextList(PhpPresentation $objPHPPresentation): void fnSlideRichTextList($objPHPPresentation); // Save file -echo write($objPHPPresentation, basename(__FILE__, '.php'), $writers); +echo write($objPHPPresentation, basename(__FILE__, '.php')); if (!CLI) { include_once 'Sample_Footer.php'; } diff --git a/samples/Sample_12_Reader_ODPresentation.php b/samples/Sample_12_Reader_ODPresentation.php index e6a66ac5c..5a2232e12 100644 --- a/samples/Sample_12_Reader_ODPresentation.php +++ b/samples/Sample_12_Reader_ODPresentation.php @@ -2,6 +2,7 @@ set_time_limit(10); +include_once __DIR__ . '/Sample_PhpPptTree.php'; include_once __DIR__ . '/Sample_Header.php'; use PhpOffice\PhpPresentation\IOFactory; @@ -9,8 +10,9 @@ $pptReader = IOFactory::createReader('ODPresentation'); $oPHPPresentation = $pptReader->load(__DIR__ . '/resources/Sample_12.odp'); -$oTree = new PhpPptTree($oPHPPresentation); -echo $oTree->display(); if (!CLI) { + $oTree = new Sample_PhpPptTree($oPHPPresentation); + echo $oTree->display(); + include_once 'Sample_Footer.php'; } diff --git a/samples/Sample_12_Reader_PowerPoint2007.php b/samples/Sample_12_Reader_PowerPoint2007.php index 97636393e..c59df58dd 100644 --- a/samples/Sample_12_Reader_PowerPoint2007.php +++ b/samples/Sample_12_Reader_PowerPoint2007.php @@ -2,15 +2,17 @@ set_time_limit(10); -include_once 'Sample_Header.php'; +include_once __DIR__ . '/Sample_PhpPptTree.php'; +include_once __DIR__ . '/Sample_Header.php'; use PhpOffice\PhpPresentation\IOFactory; $pptReader = IOFactory::createReader('PowerPoint2007'); -$oPHPPresentation = $pptReader->load('resources/Sample_12.pptx'); +$oPHPPresentation = $pptReader->load(__DIR__ . '/resources/Sample_12.pptx'); -$oTree = new PhpPptTree($oPHPPresentation); -echo $oTree->display(); if (!CLI) { + $oTree = new Sample_PhpPptTree($oPHPPresentation); + echo $oTree->display(); + include_once 'Sample_Footer.php'; } diff --git a/samples/Sample_12_Reader_PowerPoint97.php b/samples/Sample_12_Reader_PowerPoint97.php index 6ecf74858..574145eea 100644 --- a/samples/Sample_12_Reader_PowerPoint97.php +++ b/samples/Sample_12_Reader_PowerPoint97.php @@ -2,15 +2,17 @@ set_time_limit(10); -include_once 'Sample_Header.php'; +include_once __DIR__ . '/Sample_PhpPptTree.php'; +include_once __DIR__ . '/Sample_Header.php'; use PhpOffice\PhpPresentation\IOFactory; $pptReader = IOFactory::createReader('PowerPoint97'); -$oPHPPresentation = $pptReader->load('resources/Sample_12.ppt'); +$oPHPPresentation = $pptReader->load(__DIR__ . '/resources/Sample_12.ppt'); -$oTree = new PhpPptTree($oPHPPresentation); -echo $oTree->display(); if (!CLI) { + $oTree = new Sample_PhpPptTree($oPHPPresentation); + echo $oTree->display(); + include_once 'Sample_Footer.php'; } diff --git a/samples/Sample_13_MarkAsFinal.php b/samples/Sample_13_MarkAsFinal.php index f8670eba5..f305276ad 100644 --- a/samples/Sample_13_MarkAsFinal.php +++ b/samples/Sample_13_MarkAsFinal.php @@ -18,7 +18,7 @@ $currentSlide->addShape(clone $oShapeRichText); // Save file -echo write($objPHPPresentation, basename(__FILE__, '.php'), $writers); +echo write($objPHPPresentation, basename(__FILE__, '.php')); if (!CLI) { include_once 'Sample_Footer.php'; } diff --git a/samples/Sample_14_Zoom.php b/samples/Sample_14_Zoom.php index a134c2210..2c61723a7 100644 --- a/samples/Sample_14_Zoom.php +++ b/samples/Sample_14_Zoom.php @@ -18,7 +18,7 @@ $currentSlide->addShape(clone $oShapeRichText); // Save file -echo write($objPHPPresentation, basename(__FILE__, '.php'), $writers); +echo write($objPHPPresentation, basename(__FILE__, '.php')); if (!CLI) { include_once 'Sample_Footer.php'; } diff --git a/samples/Sample_15_Background.php b/samples/Sample_15_Background.php index 9e1280fd9..491af0933 100644 --- a/samples/Sample_15_Background.php +++ b/samples/Sample_15_Background.php @@ -35,7 +35,7 @@ $oSlide2->setBackground($oBkgImage); // Save file -echo write($objPHPPresentation, basename(__FILE__, '.php'), $writers); +echo write($objPHPPresentation, basename(__FILE__, '.php')); if (!CLI) { include_once 'Sample_Footer.php'; } diff --git a/samples/Sample_16_Thumbnail.php b/samples/Sample_16_Thumbnail.php index 884deb931..ba82b3e8c 100644 --- a/samples/Sample_16_Thumbnail.php +++ b/samples/Sample_16_Thumbnail.php @@ -18,7 +18,7 @@ $oSlide1->addShape(clone $oShapeRichText); // Save file -echo write($objPHPPresentation, basename(__FILE__, '.php'), $writers); +echo write($objPHPPresentation, basename(__FILE__, '.php')); if (!CLI) { include_once 'Sample_Footer.php'; } diff --git a/samples/Sample_17_Comment.php b/samples/Sample_17_Comment.php index d417c4bfd..f0c892593 100644 --- a/samples/Sample_17_Comment.php +++ b/samples/Sample_17_Comment.php @@ -39,7 +39,7 @@ $oSlide1->addShape($oComment2); // Save file -echo write($objPHPPresentation, basename(__FILE__, '.php'), $writers); +echo write($objPHPPresentation, basename(__FILE__, '.php')); if (!CLI) { include_once 'Sample_Footer.php'; } diff --git a/samples/Sample_18_Animation.php b/samples/Sample_18_Animation.php index f632cb49c..f960b4622 100644 --- a/samples/Sample_18_Animation.php +++ b/samples/Sample_18_Animation.php @@ -54,7 +54,7 @@ $oSlide3->addAnimation($oAnimation5); // Save file -echo write($objPHPPresentation, basename(__FILE__, '.php'), $writers); +echo write($objPHPPresentation, basename(__FILE__, '.php')); if (!CLI) { include_once 'Sample_Footer.php'; } diff --git a/samples/Sample_19_SlideMaster.php b/samples/Sample_19_SlideMaster.php index 9f851ac8e..a44410366 100644 --- a/samples/Sample_19_SlideMaster.php +++ b/samples/Sample_19_SlideMaster.php @@ -106,7 +106,7 @@ $currentSlide->setSlideLayout($oSlideLayout); // Save file -echo write($objPHPPresentation, basename(__FILE__, '.php'), $writers); +echo write($objPHPPresentation, basename(__FILE__, '.php')); if (!CLI) { include_once 'Sample_Footer.php'; } diff --git a/samples/Sample_20_SlideLayout.php b/samples/Sample_20_SlideLayout.php index 1e18ac5b3..c2ea1fb9c 100644 --- a/samples/Sample_20_SlideLayout.php +++ b/samples/Sample_20_SlideLayout.php @@ -67,7 +67,7 @@ $currentSlide->setSlideLayout($slideLayout); // Save file -echo write($objPHPPresentation, basename(__FILE__, '.php'), $writers); +echo write($objPHPPresentation, basename(__FILE__, '.php')); if (!CLI) { include_once 'Sample_Footer.php'; } diff --git a/samples/Sample_21_AutoShape.php b/samples/Sample_21_AutoShape.php index 7a8278f4b..16af2f665 100644 --- a/samples/Sample_21_AutoShape.php +++ b/samples/Sample_21_AutoShape.php @@ -59,7 +59,7 @@ } // Save file -echo write($objPHPPresentation, basename(__FILE__, '.php'), $writers); +echo write($objPHPPresentation, basename(__FILE__, '.php')); if (!CLI) { include_once 'Sample_Footer.php'; } diff --git a/samples/Sample_22_ExternalSlide.php b/samples/Sample_22_ExternalSlide.php index 763234a6b..1864ccaaa 100644 --- a/samples/Sample_22_ExternalSlide.php +++ b/samples/Sample_22_ExternalSlide.php @@ -17,7 +17,7 @@ } // Save file -echo write($objPHPPresentation, basename(__FILE__, '.php'), $writers); +echo write($objPHPPresentation, basename(__FILE__, '.php')); if (!CLI) { include_once 'Sample_Footer.php'; } diff --git a/samples/Sample_Header.php b/samples/Sample_Header.php index 7e33830e3..c9c0ca9cb 100644 --- a/samples/Sample_Header.php +++ b/samples/Sample_Header.php @@ -2,23 +2,20 @@ /** * Header file. */ -use PhpOffice\PhpPresentation\AbstractShape; use PhpOffice\PhpPresentation\Autoloader; -use PhpOffice\PhpPresentation\DocumentLayout; use PhpOffice\PhpPresentation\IOFactory; use PhpOffice\PhpPresentation\PhpPresentation; use PhpOffice\PhpPresentation\Shape\Drawing; -use PhpOffice\PhpPresentation\Shape\Group; use PhpOffice\PhpPresentation\Shape\RichText; -use PhpOffice\PhpPresentation\Shape\RichText\BreakElement; -use PhpOffice\PhpPresentation\Shape\RichText\TextElement; use PhpOffice\PhpPresentation\Slide; use PhpOffice\PhpPresentation\Style\Alignment; -use PhpOffice\PhpPresentation\Style\Bullet; use PhpOffice\PhpPresentation\Style\Color; use PhpOffice\PhpPresentation\Writer\PDF\DomPDF; +ini_set('display_errors', 1); +ini_set('display_startup_errors', 1); error_reporting(E_ALL); + define('CLI', (PHP_SAPI == 'cli') ? true : false); define('EOL', CLI ? PHP_EOL : '
'); define('SCRIPT_FILENAME', basename($_SERVER['SCRIPT_FILENAME'], '.php')); @@ -48,14 +45,6 @@ throw new Exception('The samples folder is not writable!'); } -// Set writers -$writers = [ - 'PowerPoint2007' => 'pptx', - 'ODPresentation' => 'odp', - 'HTML' => 'html', - 'PDF' => 'pdf', -]; - // Set titles and names $pageHeading = str_replace('_', ' ', SCRIPT_FILENAME); $pageTitle = IS_INDEX ? 'Welcome to ' : "{$pageHeading} - "; @@ -116,7 +105,12 @@ /** * Write documents. */ -function write(PhpPresentation $phpPresentation, string $filename, array $writers): string +function write(PhpPresentation $phpPresentation, string $filename, array $writers = [ + 'PowerPoint2007' => 'pptx', + 'ODPresentation' => 'odp', + 'HTML' => 'html', + 'PDF' => 'pdf', +]): string { $result = ''; @@ -206,290 +200,6 @@ function createTemplatedSlide(PhpPresentation $objPHPPresentation): Slide // Return slide return $slide; } - -class Sample_Header -{ - protected $oPhpPresentation; - - protected $htmlOutput; - - public function __construct(PhpPresentation $oPHPPpt) - { - $this->oPhpPresentation = $oPHPPpt; - } - - public function display() - { - $this->append('
'); - $this->append('
'); - $this->append('
'); - $this->append('
'); - $this->append('
    '); - $this->displayPhpPresentation($this->oPhpPresentation); - $this->append('
'); - $this->append('
'); - $this->append('
'); - $this->append('
'); - $this->displayPhpPresentationInfo($this->oPhpPresentation); - $this->append('
'); - $this->append('
'); - $this->append('
'); - - return $this->htmlOutput; - } - - protected function append($sHTML): void - { - $this->htmlOutput .= $sHTML; - } - - protected function displayPhpPresentation(PhpPresentation $oPHPPpt): void - { - $this->append('
  • PhpPresentation'); - $this->append(''); - $this->append('
  • '); - } - - protected function displayShape(AbstractShape $shape): void - { - if ($shape instanceof Drawing\Gd) { - $this->append('
  • Shape "Drawing\Gd"
  • '); - } elseif ($shape instanceof Drawing\File) { - $this->append('
  • Shape "Drawing\File"
  • '); - } elseif ($shape instanceof Drawing\Base64) { - $this->append('
  • Shape "Drawing\Base64"
  • '); - } elseif ($shape instanceof Drawing\ZipFile) { - $this->append('
  • Shape "Drawing\Zip"
  • '); - } elseif ($shape instanceof RichText) { - $this->append('
  • Shape "RichText"
  • '); - } else { - var_dump($shape); - } - } - - protected function displayPhpPresentationInfo(PhpPresentation $oPHPPpt): void - { - $this->append('
    '); - $this->append('
    '); - $this->append('
    Number of slides
    ' . $oPHPPpt->getSlideCount() . '
    '); - $this->append('
    Document Layout Name
    ' . (empty($oPHPPpt->getLayout()->getDocumentLayout()) ? 'Custom' : $oPHPPpt->getLayout()->getDocumentLayout()) . '
    '); - $this->append('
    Document Layout Height
    ' . $oPHPPpt->getLayout()->getCY(DocumentLayout::UNIT_MILLIMETER) . ' mm
    '); - $this->append('
    Document Layout Width
    ' . $oPHPPpt->getLayout()->getCX(DocumentLayout::UNIT_MILLIMETER) . ' mm
    '); - $this->append('
    Properties : Category
    ' . $oPHPPpt->getDocumentProperties()->getCategory() . '
    '); - $this->append('
    Properties : Company
    ' . $oPHPPpt->getDocumentProperties()->getCompany() . '
    '); - $this->append('
    Properties : Created
    ' . $oPHPPpt->getDocumentProperties()->getCreated() . '
    '); - $this->append('
    Properties : Creator
    ' . $oPHPPpt->getDocumentProperties()->getCreator() . '
    '); - $this->append('
    Properties : Description
    ' . $oPHPPpt->getDocumentProperties()->getDescription() . '
    '); - $this->append('
    Properties : Keywords
    ' . $oPHPPpt->getDocumentProperties()->getKeywords() . '
    '); - $this->append('
    Properties : Last Modified By
    ' . $oPHPPpt->getDocumentProperties()->getLastModifiedBy() . '
    '); - $this->append('
    Properties : Modified
    ' . $oPHPPpt->getDocumentProperties()->getModified() . '
    '); - $this->append('
    Properties : Subject
    ' . $oPHPPpt->getDocumentProperties()->getSubject() . '
    '); - $this->append('
    Properties : Title
    ' . $oPHPPpt->getDocumentProperties()->getTitle() . '
    '); - $this->append('
    '); - $this->append('
    '); - - foreach ($oPHPPpt->getAllSlides() as $oSlide) { - $this->append('
    '); - $this->append('
    '); - $this->append('
    HashCode
    ' . $oSlide->getHashCode() . '
    '); - $this->append('
    Slide Layout
    Layout::' . $this->getConstantName('\PhpOffice\PhpPresentation\Slide\Layout', $oSlide->getSlideLayout()) . '
    '); - - $this->append('
    Offset X
    ' . $oSlide->getOffsetX() . '
    '); - $this->append('
    Offset Y
    ' . $oSlide->getOffsetY() . '
    '); - $this->append('
    Extent X
    ' . $oSlide->getExtentX() . '
    '); - $this->append('
    Extent Y
    ' . $oSlide->getExtentY() . '
    '); - $oBkg = $oSlide->getBackground(); - if ($oBkg instanceof Slide\AbstractBackground) { - if ($oBkg instanceof Slide\Background\Color) { - $this->append('
    Background Color
    #' . $oBkg->getColor()->getRGB() . '
    '); - } - if ($oBkg instanceof Slide\Background\Image) { - $sBkgImgContents = file_get_contents($oBkg->getPath()); - $this->append('
    Background Image
    '); - } - } - $oNote = $oSlide->getNote(); - if (count($oNote->getShapeCollection()) > 0) { - $this->append('
    Notes
    '); - foreach ($oNote->getShapeCollection() as $oShape) { - if ($oShape instanceof RichText) { - $this->append('
    ' . $oShape->getPlainText() . '
    '); - } - } - } - - $this->append('
    '); - $this->append('
    '); - - foreach ($oSlide->getShapeCollection() as $oShape) { - if ($oShape instanceof Group) { - foreach ($oShape->getShapeCollection() as $oShapeChild) { - $this->displayShapeInfo($oShapeChild); - } - } else { - $this->displayShapeInfo($oShape); - } - } - } - } - - protected function displayShapeInfo(AbstractShape $oShape): void - { - $this->append('
    '); - $this->append('
    '); - $this->append('
    HashCode
    ' . $oShape->getHashCode() . '
    '); - $this->append('
    Offset X
    ' . $oShape->getOffsetX() . '
    '); - $this->append('
    Offset Y
    ' . $oShape->getOffsetY() . '
    '); - $this->append('
    Height
    ' . $oShape->getHeight() . '
    '); - $this->append('
    Width
    ' . $oShape->getWidth() . '
    '); - $this->append('
    Rotation
    ' . $oShape->getRotation() . '°
    '); - $this->append('
    Hyperlink
    ' . ucfirst(var_export($oShape->hasHyperlink(), true)) . '
    '); - $this->append('
    Fill
    '); - if (null === $oShape->getFill()) { - $this->append('
    None
    '); - } else { - switch ($oShape->getFill()->getFillType()) { - case PhpOffice\PhpPresentation\Style\Fill::FILL_NONE: - $this->append('
    None
    '); - - break; - case PhpOffice\PhpPresentation\Style\Fill::FILL_SOLID: - $this->append('
    Solid ('); - $this->append('Color : #' . $oShape->getFill()->getStartColor()->getRGB()); - $this->append(' - Alpha : ' . $oShape->getFill()->getStartColor()->getAlpha() . '%'); - $this->append(')
    '); - - break; - } - } - $this->append('
    Border
    @Todo
    '); - $this->append('
    IsPlaceholder
    ' . ($oShape->isPlaceholder() ? 'true' : 'false') . '
    '); - if ($oShape instanceof Drawing\Gd) { - $this->append('
    Name
    ' . $oShape->getName() . '
    '); - $this->append('
    Description
    ' . $oShape->getDescription() . '
    '); - ob_start(); - call_user_func($oShape->getRenderingFunction(), $oShape->getImageResource()); - $sShapeImgContents = ob_get_contents(); - ob_end_clean(); - $this->append('
    Mime-Type
    ' . $oShape->getMimeType() . '
    '); - $this->append('
    Image
    '); - if ($oShape->hasHyperlink()) { - $this->append('
    Hyperlink URL
    ' . $oShape->getHyperlink()->getUrl() . '
    '); - $this->append('
    Hyperlink Tooltip
    ' . $oShape->getHyperlink()->getTooltip() . '
    '); - } - } elseif ($oShape instanceof Drawing\AbstractDrawingAdapter) { - $this->append('
    Name
    ' . $oShape->getName() . '
    '); - $this->append('
    Description
    ' . $oShape->getDescription() . '
    '); - } elseif ($oShape instanceof RichText) { - $this->append('
    # of paragraphs
    ' . count($oShape->getParagraphs()) . '
    '); - $this->append('
    Inset (T / R / B / L)
    ' . $oShape->getInsetTop() . 'px / ' . $oShape->getInsetRight() . 'px / ' . $oShape->getInsetBottom() . 'px / ' . $oShape->getInsetLeft() . 'px
    '); - $this->append('
    Text
    '); - $this->append('
    '); - foreach ($oShape->getParagraphs() as $oParagraph) { - $this->append('Paragraph
    '); - $this->append('
    Alignment Horizontal
    Alignment::' . $this->getConstantName('\PhpOffice\PhpPresentation\Style\Alignment', $oParagraph->getAlignment()->getHorizontal()) . '
    '); - $this->append('
    Alignment Vertical
    Alignment::' . $this->getConstantName('\PhpOffice\PhpPresentation\Style\Alignment', $oParagraph->getAlignment()->getVertical()) . '
    '); - $this->append('
    Alignment Margin (L / R)
    ' . $oParagraph->getAlignment()->getMarginLeft() . ' px / ' . $oParagraph->getAlignment()->getMarginRight() . 'px
    '); - $this->append('
    Alignment Indent
    ' . $oParagraph->getAlignment()->getIndent() . ' px
    '); - $this->append('
    Alignment Level
    ' . $oParagraph->getAlignment()->getLevel() . '
    '); - $this->append('
    Bullet Style
    Bullet::' . $this->getConstantName('\PhpOffice\PhpPresentation\Style\Bullet', $oParagraph->getBulletStyle()->getBulletType()) . '
    '); - if (Bullet::TYPE_NONE != $oParagraph->getBulletStyle()->getBulletType()) { - $this->append('
    Bullet Font
    ' . $oParagraph->getBulletStyle()->getBulletFont() . '
    '); - $this->append('
    Bullet Color
    ' . $oParagraph->getBulletStyle()->getBulletColor()->getARGB() . '
    '); - } - if (Bullet::TYPE_BULLET == $oParagraph->getBulletStyle()->getBulletType()) { - $this->append('
    Bullet Char
    ' . $oParagraph->getBulletStyle()->getBulletChar() . '
    '); - } - if (Bullet::TYPE_NUMERIC == $oParagraph->getBulletStyle()->getBulletType()) { - $this->append('
    Bullet Start At
    ' . $oParagraph->getBulletStyle()->getBulletNumericStartAt() . '
    '); - $this->append('
    Bullet Style
    ' . $oParagraph->getBulletStyle()->getBulletNumericStyle() . '
    '); - } - $this->append('
    Line Spacing
    ' . $oParagraph->getLineSpacing() . '
    '); - $this->append('
    RichText
    '); - foreach ($oParagraph->getRichTextElements() as $oRichText) { - if ($oRichText instanceof BreakElement) { - $this->append('
    Break
    '); - } else { - if ($oRichText instanceof TextElement) { - $this->append('
    TextElement
    '); - } else { - $this->append('
    Run
    '); - } - $this->append('
    ' . $oRichText->getText()); - $this->append('
    '); - $this->append('
    Font Name
    ' . $oRichText->getFont()->getName() . '
    '); - $this->append('
    Font Size
    ' . $oRichText->getFont()->getSize() . '
    '); - $this->append('
    Font Color
    #' . $oRichText->getFont()->getColor()->getARGB() . '
    '); - $this->append('
    Font Transform
    '); - $this->append('Bold : ' . ($oRichText->getFont()->isBold() ? 'Y' : 'N') . ' - '); - $this->append('Italic : ' . ($oRichText->getFont()->isItalic() ? 'Y' : 'N') . ' - '); - $this->append('Underline : Underline::' . $this->getConstantName('\PhpOffice\PhpPresentation\Style\Font', $oRichText->getFont()->getUnderline()) . ' - '); - $this->append('Strikethrough : ' . ($oRichText->getFont()->isStrikethrough() ? 'Y' : 'N') . ' - '); - $this->append('Baseline : ' . $oRichText->getFont()->getBaseline() . ' - '); - $this->append('SubScript : ' . ($oRichText->getFont()->isSubScript() ? 'Y' : 'N') . ' - '); - $this->append('SuperScript : ' . ($oRichText->getFont()->isSuperScript() ? 'Y' : 'N')); - $this->append('
    '); - if ($oRichText instanceof TextElement) { - if ($oRichText->hasHyperlink()) { - $this->append('
    Hyperlink URL
    ' . $oRichText->getHyperlink()->getUrl() . '
    '); - $this->append('
    Hyperlink Tooltip
    ' . $oRichText->getHyperlink()->getTooltip() . '
    '); - } - } - $this->append('
    '); - $this->append('
    '); - } - } - $this->append('
    '); - } - $this->append('
    '); - } - // Add another shape - - $this->append('
    '); - $this->append('
    '); - } - - protected function getConstantName($class, $search, $startWith = '') - { - $fooClass = new ReflectionClass($class); - $constants = $fooClass->getConstants(); - $constName = null; - foreach ($constants as $key => $value) { - if ($value == $search) { - if (empty($startWith) || (!empty($startWith) && 0 === strpos($key, $startWith))) { - $constName = $key; - } - - break; - } - } - - return $constName; - } -} ?> <?php echo $pageTitle; ?> diff --git a/samples/Sample_PhpPptTree.php b/samples/Sample_PhpPptTree.php new file mode 100644 index 000000000..0289e25bb --- /dev/null +++ b/samples/Sample_PhpPptTree.php @@ -0,0 +1,296 @@ +oPhpPresentation = $oPHPPpt; + } + + public function display() + { + $this->append('
    '); + $this->append('
    '); + $this->append('
    '); + $this->append('
    '); + $this->append('
      '); + $this->displayPhpPresentation($this->oPhpPresentation); + $this->append('
    '); + $this->append('
    '); + $this->append('
    '); + $this->append('
    '); + $this->displayPhpPresentationInfo($this->oPhpPresentation); + $this->append('
    '); + $this->append('
    '); + $this->append('
    '); + + return $this->htmlOutput; + } + + protected function append($sHTML): void + { + $this->htmlOutput .= $sHTML; + } + + protected function displayPhpPresentation(PhpPresentation $oPHPPpt): void + { + $this->append('
  • PhpPresentation'); + $this->append(''); + $this->append('
  • '); + } + + protected function displayShape(AbstractShape $shape): void + { + if ($shape instanceof Drawing\Gd) { + $this->append('
  • Shape "Drawing\Gd"
  • '); + } elseif ($shape instanceof Drawing\File) { + $this->append('
  • Shape "Drawing\File"
  • '); + } elseif ($shape instanceof Drawing\Base64) { + $this->append('
  • Shape "Drawing\Base64"
  • '); + } elseif ($shape instanceof Drawing\ZipFile) { + $this->append('
  • Shape "Drawing\Zip"
  • '); + } elseif ($shape instanceof RichText) { + $this->append('
  • Shape "RichText"
  • '); + } elseif ($shape instanceof Table) { + $this->append('
  • Shape "Table"
  • '); + } else { + var_dump($shape); + } + } + + protected function displayPhpPresentationInfo(PhpPresentation $oPHPPpt): void + { + $this->append('
    '); + $this->append('
    '); + $this->append('
    Number of slides
    ' . $oPHPPpt->getSlideCount() . '
    '); + $this->append('
    Document Layout Name
    ' . (empty($oPHPPpt->getLayout()->getDocumentLayout()) ? 'Custom' : $oPHPPpt->getLayout()->getDocumentLayout()) . '
    '); + $this->append('
    Document Layout Height
    ' . $oPHPPpt->getLayout()->getCY(DocumentLayout::UNIT_MILLIMETER) . ' mm
    '); + $this->append('
    Document Layout Width
    ' . $oPHPPpt->getLayout()->getCX(DocumentLayout::UNIT_MILLIMETER) . ' mm
    '); + $this->append('
    Properties : Category
    ' . $oPHPPpt->getDocumentProperties()->getCategory() . '
    '); + $this->append('
    Properties : Company
    ' . $oPHPPpt->getDocumentProperties()->getCompany() . '
    '); + $this->append('
    Properties : Created
    ' . $oPHPPpt->getDocumentProperties()->getCreated() . '
    '); + $this->append('
    Properties : Creator
    ' . $oPHPPpt->getDocumentProperties()->getCreator() . '
    '); + $this->append('
    Properties : Description
    ' . $oPHPPpt->getDocumentProperties()->getDescription() . '
    '); + $this->append('
    Properties : Keywords
    ' . $oPHPPpt->getDocumentProperties()->getKeywords() . '
    '); + $this->append('
    Properties : Last Modified By
    ' . $oPHPPpt->getDocumentProperties()->getLastModifiedBy() . '
    '); + $this->append('
    Properties : Modified
    ' . $oPHPPpt->getDocumentProperties()->getModified() . '
    '); + $this->append('
    Properties : Subject
    ' . $oPHPPpt->getDocumentProperties()->getSubject() . '
    '); + $this->append('
    Properties : Title
    ' . $oPHPPpt->getDocumentProperties()->getTitle() . '
    '); + $this->append('
    '); + $this->append('
    '); + + foreach ($oPHPPpt->getAllSlides() as $oSlide) { + $this->append('
    '); + $this->append('
    '); + $this->append('
    HashCode
    ' . $oSlide->getHashCode() . '
    '); + $this->append('
    Slide Layout
    Layout::' . $this->getConstantName('\PhpOffice\PhpPresentation\Slide\Layout', $oSlide->getSlideLayout()) . '
    '); + + $this->append('
    Offset X
    ' . $oSlide->getOffsetX() . '
    '); + $this->append('
    Offset Y
    ' . $oSlide->getOffsetY() . '
    '); + $this->append('
    Extent X
    ' . $oSlide->getExtentX() . '
    '); + $this->append('
    Extent Y
    ' . $oSlide->getExtentY() . '
    '); + $oBkg = $oSlide->getBackground(); + if ($oBkg instanceof Slide\AbstractBackground) { + if ($oBkg instanceof Slide\Background\Color) { + $this->append('
    Background Color
    #' . $oBkg->getColor()->getRGB() . '
    '); + } + if ($oBkg instanceof Slide\Background\Image) { + $sBkgImgContents = file_get_contents($oBkg->getPath()); + $this->append('
    Background Image
    '); + } + } + $oNote = $oSlide->getNote(); + if (count($oNote->getShapeCollection()) > 0) { + $this->append('
    Notes
    '); + foreach ($oNote->getShapeCollection() as $oShape) { + if ($oShape instanceof RichText) { + $this->append('
    ' . $oShape->getPlainText() . '
    '); + } + } + } + + $this->append('
    '); + $this->append('
    '); + + foreach ($oSlide->getShapeCollection() as $oShape) { + if ($oShape instanceof Group) { + foreach ($oShape->getShapeCollection() as $oShapeChild) { + $this->displayShapeInfo($oShapeChild); + } + } else { + $this->displayShapeInfo($oShape); + } + } + } + } + + protected function displayShapeInfo(AbstractShape $oShape): void + { + $this->append('
    '); + $this->append('
    '); + $this->append('
    HashCode
    ' . $oShape->getHashCode() . '
    '); + $this->append('
    Offset X
    ' . $oShape->getOffsetX() . '
    '); + $this->append('
    Offset Y
    ' . $oShape->getOffsetY() . '
    '); + $this->append('
    Height
    ' . $oShape->getHeight() . '
    '); + $this->append('
    Width
    ' . $oShape->getWidth() . '
    '); + $this->append('
    Rotation
    ' . $oShape->getRotation() . '°
    '); + $this->append('
    Hyperlink
    ' . ucfirst(var_export($oShape->hasHyperlink(), true)) . '
    '); + $this->append('
    Fill
    '); + if (null === $oShape->getFill()) { + $this->append('
    None
    '); + } else { + switch ($oShape->getFill()->getFillType()) { + case PhpOffice\PhpPresentation\Style\Fill::FILL_NONE: + $this->append('
    None
    '); + + break; + case PhpOffice\PhpPresentation\Style\Fill::FILL_SOLID: + $this->append('
    Solid ('); + $this->append('Color : #' . $oShape->getFill()->getStartColor()->getRGB()); + $this->append(' - Alpha : ' . $oShape->getFill()->getStartColor()->getAlpha() . '%'); + $this->append(')
    '); + + break; + } + } + $this->append('
    Border
    @Todo
    '); + $this->append('
    IsPlaceholder
    ' . ($oShape->isPlaceholder() ? 'true' : 'false') . '
    '); + if ($oShape instanceof Drawing\Gd) { + $this->append('
    Name
    ' . $oShape->getName() . '
    '); + $this->append('
    Description
    ' . $oShape->getDescription() . '
    '); + ob_start(); + call_user_func($oShape->getRenderingFunction(), $oShape->getImageResource()); + $sShapeImgContents = ob_get_contents(); + ob_end_clean(); + $this->append('
    Mime-Type
    ' . $oShape->getMimeType() . '
    '); + $this->append('
    Image
    '); + if ($oShape->hasHyperlink()) { + $this->append('
    Hyperlink URL
    ' . $oShape->getHyperlink()->getUrl() . '
    '); + $this->append('
    Hyperlink Tooltip
    ' . $oShape->getHyperlink()->getTooltip() . '
    '); + } + } elseif ($oShape instanceof Drawing\AbstractDrawingAdapter) { + $this->append('
    Name
    ' . $oShape->getName() . '
    '); + $this->append('
    Description
    ' . $oShape->getDescription() . '
    '); + } elseif ($oShape instanceof RichText) { + $this->append('
    # of paragraphs
    ' . count($oShape->getParagraphs()) . '
    '); + $this->append('
    Inset (T / R / B / L)
    ' . $oShape->getInsetTop() . 'px / ' . $oShape->getInsetRight() . 'px / ' . $oShape->getInsetBottom() . 'px / ' . $oShape->getInsetLeft() . 'px
    '); + $this->append('
    Text
    '); + $this->append('
    '); + foreach ($oShape->getParagraphs() as $oParagraph) { + $this->append('Paragraph
    '); + $this->append('
    Alignment Horizontal
    Alignment::' . $this->getConstantName('\PhpOffice\PhpPresentation\Style\Alignment', $oParagraph->getAlignment()->getHorizontal()) . '
    '); + $this->append('
    Alignment Vertical
    Alignment::' . $this->getConstantName('\PhpOffice\PhpPresentation\Style\Alignment', $oParagraph->getAlignment()->getVertical()) . '
    '); + $this->append('
    Alignment Margin (L / R)
    ' . $oParagraph->getAlignment()->getMarginLeft() . ' px / ' . $oParagraph->getAlignment()->getMarginRight() . 'px
    '); + $this->append('
    Alignment Indent
    ' . $oParagraph->getAlignment()->getIndent() . ' px
    '); + $this->append('
    Alignment Level
    ' . $oParagraph->getAlignment()->getLevel() . '
    '); + $this->append('
    Bullet Style
    Bullet::' . $this->getConstantName('\PhpOffice\PhpPresentation\Style\Bullet', $oParagraph->getBulletStyle()->getBulletType()) . '
    '); + if (Bullet::TYPE_NONE != $oParagraph->getBulletStyle()->getBulletType()) { + $this->append('
    Bullet Font
    ' . $oParagraph->getBulletStyle()->getBulletFont() . '
    '); + $this->append('
    Bullet Color
    ' . $oParagraph->getBulletStyle()->getBulletColor()->getARGB() . '
    '); + } + if (Bullet::TYPE_BULLET == $oParagraph->getBulletStyle()->getBulletType()) { + $this->append('
    Bullet Char
    ' . $oParagraph->getBulletStyle()->getBulletChar() . '
    '); + } + if (Bullet::TYPE_NUMERIC == $oParagraph->getBulletStyle()->getBulletType()) { + $this->append('
    Bullet Start At
    ' . $oParagraph->getBulletStyle()->getBulletNumericStartAt() . '
    '); + $this->append('
    Bullet Style
    ' . $oParagraph->getBulletStyle()->getBulletNumericStyle() . '
    '); + } + $this->append('
    Line Spacing
    ' . $oParagraph->getLineSpacing() . '
    '); + $this->append('
    RichText
    '); + foreach ($oParagraph->getRichTextElements() as $oRichText) { + if ($oRichText instanceof BreakElement) { + $this->append('
    Break
    '); + } else { + if ($oRichText instanceof TextElement) { + $this->append('
    TextElement
    '); + } else { + $this->append('
    Run
    '); + } + $this->append('
    ' . $oRichText->getText()); + $this->append('
    '); + $this->append('
    Font Name
    ' . $oRichText->getFont()->getName() . '
    '); + $this->append('
    Font Size
    ' . $oRichText->getFont()->getSize() . '
    '); + $this->append('
    Font Color
    #' . $oRichText->getFont()->getColor()->getARGB() . '
    '); + $this->append('
    Font Transform
    '); + $this->append('Bold : ' . ($oRichText->getFont()->isBold() ? 'Y' : 'N') . ' - '); + $this->append('Italic : ' . ($oRichText->getFont()->isItalic() ? 'Y' : 'N') . ' - '); + $this->append('Underline : Underline::' . $this->getConstantName('\PhpOffice\PhpPresentation\Style\Font', $oRichText->getFont()->getUnderline()) . ' - '); + $this->append('Strikethrough : ' . ($oRichText->getFont()->isStrikethrough() ? 'Y' : 'N') . ' - '); + $this->append('Baseline : ' . $oRichText->getFont()->getBaseline() . ' - '); + $this->append('SubScript : ' . ($oRichText->getFont()->isSubScript() ? 'Y' : 'N') . ' - '); + $this->append('SuperScript : ' . ($oRichText->getFont()->isSuperScript() ? 'Y' : 'N')); + $this->append('
    '); + if ($oRichText instanceof TextElement) { + if ($oRichText->hasHyperlink()) { + $this->append('
    Hyperlink URL
    ' . $oRichText->getHyperlink()->getUrl() . '
    '); + $this->append('
    Hyperlink Tooltip
    ' . $oRichText->getHyperlink()->getTooltip() . '
    '); + } + } + $this->append('
    '); + $this->append('
    '); + } + } + $this->append('
    '); + } + $this->append('
    '); + } + // Add another shape + + $this->append('
    '); + $this->append('
    '); + } + + protected function getConstantName($class, $search, $startWith = '') + { + $fooClass = new ReflectionClass($class); + $constants = $fooClass->getConstants(); + $constName = null; + foreach ($constants as $key => $value) { + if ($value == $search) { + if (empty($startWith) || (!empty($startWith) && 0 === strpos($key, $startWith))) { + $constName = $key; + } + + break; + } + } + + return $constName; + } +} diff --git a/src/PhpPresentation/AbstractShape.php b/src/PhpPresentation/AbstractShape.php index 6abde9e83..4b002808f 100644 --- a/src/PhpPresentation/AbstractShape.php +++ b/src/PhpPresentation/AbstractShape.php @@ -227,7 +227,7 @@ public function getOffsetX(): int } /** - * Set OffsetX. + * Set OffsetX (in pixels). * * @return $this */ diff --git a/src/PhpPresentation/Reader/PowerPoint2007.php b/src/PhpPresentation/Reader/PowerPoint2007.php index 16f4ddcca..d93a19168 100644 --- a/src/PhpPresentation/Reader/PowerPoint2007.php +++ b/src/PhpPresentation/Reader/PowerPoint2007.php @@ -33,6 +33,7 @@ use PhpOffice\PhpPresentation\Exception\InvalidFileFormatException; use PhpOffice\PhpPresentation\PhpPresentation; use PhpOffice\PhpPresentation\PresentationProperties; +use PhpOffice\PhpPresentation\Shape\Chart; use PhpOffice\PhpPresentation\Shape\Drawing\Base64; use PhpOffice\PhpPresentation\Shape\Drawing\Gd; use PhpOffice\PhpPresentation\Shape\Hyperlink; @@ -51,6 +52,7 @@ use PhpOffice\PhpPresentation\Style\Color; use PhpOffice\PhpPresentation\Style\Fill; use PhpOffice\PhpPresentation\Style\Font; +use PhpOffice\PhpPresentation\Style\Outline; use PhpOffice\PhpPresentation\Style\SchemeColor; use PhpOffice\PhpPresentation\Style\Shadow; use PhpOffice\PhpPresentation\Style\TextStyle; @@ -441,6 +443,7 @@ protected function loadSlide(string $sPart, string $baseFile): void $xmlReader = new XMLReader(); // @phpstan-ignore-next-line if ($xmlReader->getDomFromString($sPart)) { + $xmlReader->registerNamespace('c', 'http://schemas.openxmlformats.org/drawingml/2006/chart'); // Core $oSlide = $this->oPhpPresentation->createSlide(); $this->oPhpPresentation->setActiveSlideIndex($this->oPhpPresentation->getSlideCount() - 1); @@ -504,7 +507,7 @@ protected function loadSlide(string $sPart, string $baseFile): void // Shapes $arrayElements = $xmlReader->getElements('/p:sld/p:cSld/p:spTree/*'); - $this->loadSlideShapes($oSlide, $arrayElements, $xmlReader); + $this->loadSlideShapes($xmlReader, $oSlide, $arrayElements, $xmlReader); // Layout $oSlide = $this->oPhpPresentation->getActiveSlide(); @@ -539,7 +542,7 @@ protected function loadMasterSlide(string $sPart, string $baseFile): void // Shapes $arrayElements = $xmlReader->getElements('/p:sldMaster/p:cSld/p:spTree/*'); - $this->loadSlideShapes($oSlideMaster, $arrayElements, $xmlReader); + $this->loadSlideShapes($xmlReader, $oSlideMaster, $arrayElements, $xmlReader); // Header & Footer @@ -576,17 +579,17 @@ protected function loadMasterSlide(string $sPart, string $baseFile): void } if ($oElementLvl->hasAttribute('marL')) { $val = (int) $oElementLvl->getAttribute('marL'); - $val = CommonDrawing::emuToPixels((int) $val); + $val = (int) CommonDrawing::emuToPixels((int) $val); $oRTParagraph->getAlignment()->setMarginLeft($val); } if ($oElementLvl->hasAttribute('marR')) { $val = (int) $oElementLvl->getAttribute('marR'); - $val = CommonDrawing::emuToPixels((int) $val); + $val = (int) CommonDrawing::emuToPixels((int) $val); $oRTParagraph->getAlignment()->setMarginRight($val); } if ($oElementLvl->hasAttribute('indent')) { $val = (int) $oElementLvl->getAttribute('indent'); - $val = CommonDrawing::emuToPixels((int) $val); + $val = (int) CommonDrawing::emuToPixels((int) $val); $oRTParagraph->getAlignment()->setIndent($val); } $oElementLvlDefRPR = $xmlReader->getElement('a:defRPr', $oElementLvl); @@ -694,7 +697,7 @@ protected function loadLayoutSlide(string $sPart, string $baseFile, SlideMaster // Shapes $oElements = $xmlReader->getElements('/p:sldLayout/p:cSld/p:spTree/*'); - $this->loadSlideShapes($oSlideLayout, $oElements, $xmlReader); + $this->loadSlideShapes($xmlReader, $oSlideLayout, $oElements, $xmlReader); $this->arraySlideLayouts[$baseFile] = &$oSlideLayout; return $oSlideLayout; @@ -792,7 +795,7 @@ protected function loadSlideNote(string $baseFile, Slide $oSlide): void $oNote = $oSlide->getNote(); $arrayElements = $xmlReader->getElements('/p:notes/p:cSld/p:spTree/*'); - $this->loadSlideShapes($oNote, $arrayElements, $xmlReader); + $this->loadSlideShapes($xmlReader, $oNote, $arrayElements, $xmlReader); } } @@ -871,20 +874,20 @@ protected function loadShapeDrawing(XMLReader $document, DOMElement $node, Abstr $oElement = $document->getElement('p:spPr/a:xfrm/a:off', $node); if ($oElement instanceof DOMElement) { if ($oElement->hasAttribute('x')) { - $oShape->setOffsetX(CommonDrawing::emuToPixels((int) $oElement->getAttribute('x'))); + $oShape->setOffsetX((int) CommonDrawing::emuToPixels((int) $oElement->getAttribute('x'))); } if ($oElement->hasAttribute('y')) { - $oShape->setOffsetY(CommonDrawing::emuToPixels((int) $oElement->getAttribute('y'))); + $oShape->setOffsetY((int) CommonDrawing::emuToPixels((int) $oElement->getAttribute('y'))); } } $oElement = $document->getElement('p:spPr/a:xfrm/a:ext', $node); if ($oElement instanceof DOMElement) { if ($oElement->hasAttribute('cx')) { - $oShape->setWidth(CommonDrawing::emuToPixels((int) $oElement->getAttribute('cx'))); + $oShape->setWidth((int) CommonDrawing::emuToPixels((int) $oElement->getAttribute('cx'))); } if ($oElement->hasAttribute('cy')) { - $oShape->setHeight(CommonDrawing::emuToPixels((int) $oElement->getAttribute('cy'))); + $oShape->setHeight((int) CommonDrawing::emuToPixels((int) $oElement->getAttribute('cy'))); } } // Load shape effects @@ -912,10 +915,10 @@ protected function loadShadow(XMLReader $document, DOMElement $node): ?Shadow $oShadow->setVisible(true); $oShadow->setType($type); if ($nodeShadow->hasAttribute('blurRad')) { - $oShadow->setBlurRadius(CommonDrawing::emuToPixels((int) $nodeShadow->getAttribute('blurRad'))); + $oShadow->setBlurRadius((int) CommonDrawing::emuToPixels((int) $nodeShadow->getAttribute('blurRad'))); } if ($nodeShadow->hasAttribute('dist')) { - $oShadow->setDistance(CommonDrawing::emuToPixels((int) $nodeShadow->getAttribute('dist'))); + $oShadow->setDistance((int) CommonDrawing::emuToPixels((int) $nodeShadow->getAttribute('dist'))); } if ($nodeShadow->hasAttribute('dir')) { $oShadow->setDirection((int) CommonDrawing::angleToDegrees((int) $nodeShadow->getAttribute('dir'))); @@ -972,20 +975,20 @@ protected function loadShapeRichText(XMLReader $document, DOMElement $node, $oSl $oElement = $document->getElement('p:spPr/a:xfrm/a:off', $node); if ($oElement instanceof DOMElement) { if ($oElement->hasAttribute('x')) { - $oShape->setOffsetX(CommonDrawing::emuToPixels((int) $oElement->getAttribute('x'))); + $oShape->setOffsetX((int) CommonDrawing::emuToPixels((int) $oElement->getAttribute('x'))); } if ($oElement->hasAttribute('y')) { - $oShape->setOffsetY(CommonDrawing::emuToPixels((int) $oElement->getAttribute('y'))); + $oShape->setOffsetY((int) CommonDrawing::emuToPixels((int) $oElement->getAttribute('y'))); } } $oElement = $document->getElement('p:spPr/a:xfrm/a:ext', $node); if ($oElement instanceof DOMElement) { if ($oElement->hasAttribute('cx')) { - $oShape->setWidth(CommonDrawing::emuToPixels((int) $oElement->getAttribute('cx'))); + $oShape->setWidth((int) CommonDrawing::emuToPixels((int) $oElement->getAttribute('cx'))); } if ($oElement->hasAttribute('cy')) { - $oShape->setHeight(CommonDrawing::emuToPixels((int) $oElement->getAttribute('cy'))); + $oShape->setHeight((int) CommonDrawing::emuToPixels((int) $oElement->getAttribute('cy'))); } } @@ -1063,20 +1066,20 @@ protected function loadShapeTable(XMLReader $document, DOMElement $node, Abstrac $oElement = $document->getElement('p:xfrm/a:off', $node); if ($oElement instanceof DOMElement) { if ($oElement->hasAttribute('x')) { - $oShape->setOffsetX(CommonDrawing::emuToPixels((int) $oElement->getAttribute('x'))); + $oShape->setOffsetX((int) CommonDrawing::emuToPixels((int) $oElement->getAttribute('x'))); } if ($oElement->hasAttribute('y')) { - $oShape->setOffsetY(CommonDrawing::emuToPixels((int) $oElement->getAttribute('y'))); + $oShape->setOffsetY((int) CommonDrawing::emuToPixels((int) $oElement->getAttribute('y'))); } } $oElement = $document->getElement('p:xfrm/a:ext', $node); if ($oElement instanceof DOMElement) { if ($oElement->hasAttribute('cx')) { - $oShape->setWidth(CommonDrawing::emuToPixels((int) $oElement->getAttribute('cx'))); + $oShape->setWidth((int) CommonDrawing::emuToPixels((int) $oElement->getAttribute('cx'))); } if ($oElement->hasAttribute('cy')) { - $oShape->setHeight(CommonDrawing::emuToPixels((int) $oElement->getAttribute('cy'))); + $oShape->setHeight((int) CommonDrawing::emuToPixels((int) $oElement->getAttribute('cy'))); } } @@ -1085,7 +1088,7 @@ protected function loadShapeTable(XMLReader $document, DOMElement $node, Abstrac $oShape->createRow(); foreach ($arrayElements as $key => $oElement) { if ($oElement instanceof DOMElement && $oElement->getAttribute('w')) { - $oShape->getRow(0)->getCell($key)->setWidth(CommonDrawing::emuToPixels((int) $oElement->getAttribute('w'))); + $oShape->getRow(0)->getCell($key)->setWidth((int) CommonDrawing::emuToPixels((int) $oElement->getAttribute('w'))); } } @@ -1100,7 +1103,7 @@ protected function loadShapeTable(XMLReader $document, DOMElement $node, Abstrac $oRow = $oShape->createRow(); } if ($oElementRow->hasAttribute('h')) { - $oRow->setHeight(CommonDrawing::emuToPixels((int) $oElementRow->getAttribute('h'))); + $oRow->setHeight((int) CommonDrawing::emuToPixels((int) $oElementRow->getAttribute('h'))); } $arrayElementsCell = $document->getElements('a:tc', $oElementRow); foreach ($arrayElementsCell as $keyCell => $oElementCell) { @@ -1133,16 +1136,16 @@ protected function loadShapeTable(XMLReader $document, DOMElement $node, Abstrac $oCell->getParagraph(0)->getAlignment()->setVertical($oElementTcPr->getAttribute('anchor')); } if ($oElementTcPr->hasAttribute('marB')) { - $oCell->getParagraph(0)->getAlignment()->setMarginBottom((int) $oElementTcPr->getAttribute('marB')); + $oCell->getParagraph(0)->getAlignment()->setMarginBottom(CommonDrawing::emuToPixels((int) $oElementTcPr->getAttribute('marB'))); } if ($oElementTcPr->hasAttribute('marL')) { - $oCell->getParagraph(0)->getAlignment()->setMarginLeft((int) $oElementTcPr->getAttribute('marL')); + $oCell->getParagraph(0)->getAlignment()->setMarginLeft(CommonDrawing::emuToPixels((int) $oElementTcPr->getAttribute('marL'))); } if ($oElementTcPr->hasAttribute('marR')) { - $oCell->getParagraph(0)->getAlignment()->setMarginRight((int) $oElementTcPr->getAttribute('marR')); + $oCell->getParagraph(0)->getAlignment()->setMarginRight(CommonDrawing::emuToPixels((int) $oElementTcPr->getAttribute('marR'))); } if ($oElementTcPr->hasAttribute('marT')) { - $oCell->getParagraph(0)->getAlignment()->setMarginTop((int) $oElementTcPr->getAttribute('marT')); + $oCell->getParagraph(0)->getAlignment()->setMarginTop(CommonDrawing::emuToPixels((int) $oElementTcPr->getAttribute('marT'))); } } @@ -1182,6 +1185,232 @@ protected function loadShapeTable(XMLReader $document, DOMElement $node, Abstrac } } + protected function loadShapeChart(XMLReader $document, DOMElement $node, AbstractSlide $oSlide): void + { + $this->fileRels = $oSlide->getRelsIndex(); + + $oShape = new Chart(); + + $oElement = $document->getElement('p:cNvPr', $node); + if ($oElement instanceof DOMElement) { + if ($oElement->hasAttribute('name')) { + $oShape->setName($oElement->getAttribute('name')); + } + if ($oElement->hasAttribute('descr')) { + $oShape->setDescription($oElement->getAttribute('descr')); + } + } + + $oElement = $document->getElement('p:xfrm/a:off', $node); + if ($oElement instanceof DOMElement) { + if ($oElement->hasAttribute('x')) { + $oShape->setOffsetX((int) CommonDrawing::emuToPixels((int) $oElement->getAttribute('x'))); + } + if ($oElement->hasAttribute('y')) { + $oShape->setOffsetY((int) CommonDrawing::emuToPixels((int) $oElement->getAttribute('y'))); + } + } + + $oElement = $document->getElement('p:xfrm/a:ext', $node); + if ($oElement instanceof DOMElement) { + if ($oElement->hasAttribute('cx')) { + $oShape->setWidth((int) CommonDrawing::emuToPixels((int) $oElement->getAttribute('cx'))); + } + if ($oElement->hasAttribute('cy')) { + $oShape->setHeight((int) CommonDrawing::emuToPixels((int) $oElement->getAttribute('cy'))); + } + } + + $chartElement = $document->getElement('a:graphic/a:graphicData/c:chart', $node); + if ($chartElement->hasAttribute('r:id') && isset($this->arrayRels[$this->fileRels][$chartElement->getAttribute('r:id')]['Target'])) { + $pathImage = 'ppt/slides/' . $this->arrayRels[$this->fileRels][$chartElement->getAttribute('r:id')]['Target']; + $pathImage = explode('/', $pathImage); + foreach ($pathImage as $key => $partPath) { + if ('..' == $partPath) { + unset($pathImage[$key - 1], $pathImage[$key]); + } + } + $pathChart = implode('/', $pathImage); + $fileChart = $this->oZip->getFromName($pathChart); + if (false !== $fileChart) { + $xmlReader = new XMLReader(); + // @phpstan-ignore-next-line + if ($xmlReader->getDomFromString($fileChart)) { + if ($oElement = $xmlReader->getElement('/c:chartSpace/c:chart/c:autoTitleDeleted')) { + $oShape->getTitle()->setVisible(false); + } + + if ($oElement = $xmlReader->getElement('/c:chartSpace/c:chart/c:plotArea/c:barChart')) { + $shapeType = new Chart\Type\Bar(); + + $elementBarDir = $xmlReader->getElement('c:barDir', $oElement); + if ($elementBarDir instanceof DOMElement) { + $shapeType->setBarDirection($elementBarDir->getAttribute('val')); + } + + $elementGrouping = $xmlReader->getElement('c:grouping', $oElement); + if ($elementGrouping instanceof DOMElement) { + $shapeType->setBarGrouping($elementGrouping->getAttribute('val')); + } + + $elementSeries = $xmlReader->getElements('c:ser', $oElement); + foreach ($elementSeries as $elementSerie) { + $series = new Chart\Series(); + if ($elementTitle = $xmlReader->getElement('c:tx/c:strRef/c:strCache/c:pt/c:v', $elementSerie)) { + $series->setTitle($elementTitle->nodeValue); + } + + $numPoints = 0; + $elementCategory = $xmlReader->getElement('c:cat/c:strRef/c:strCache', $elementSerie); + if ($elementCategoryNumPoints = $xmlReader->getElement('c:ptCount', $elementCategory)) { + $numPoints = (int) $elementCategoryNumPoints->getAttribute('val'); + } + $elementValue = $xmlReader->getElement('c:val/c:numRef/c:numCache', $elementSerie); + for ($inc = 0; $inc < $numPoints; ++$inc) { + $key = ''; + $val = '0'; + if ($subElementCategory = $xmlReader->getElement('c:pt[@idx="' . $inc . '"]/c:v', $elementCategory)) { + $key = $subElementCategory->nodeValue; + } + if ($subElementValue = $xmlReader->getElement('c:pt[@idx="' . $inc . '"]/c:v', $elementValue)) { + $val = $subElementValue->nodeValue; + } + $series->addValue($key, $val); + } + + if ($elementFill = $xmlReader->getElement('c:spPr', $elementSerie)) { + $series->setFill( + $this->loadStyleFill($xmlReader, $elementFill) + ); + } + + if ($elementFill = $xmlReader->getElement('a:ln', $elementSerie)) { + $series->setOutline( + $this->loadStyleOutline($xmlReader, $elementFill) + ); + } + + if ($elementShowLegendKey = $xmlReader->getElement('c:dLbls/c:showLegendKey', $elementSerie)) { + $series->setShowLegendKey((bool) $elementShowLegendKey->getAttribute('val')); + } + + if ($elementShowVal = $xmlReader->getElement('c:dLbls/c:showVal', $elementSerie)) { + $series->setShowValue((bool) $elementShowVal->getAttribute('val')); + } + + if ($elementShowCatName = $xmlReader->getElement('c:dLbls/c:showCatName', $elementSerie)) { + $series->setShowCategoryName((bool) $elementShowCatName->getAttribute('val')); + } + + if ($elementShowSerName = $xmlReader->getElement('c:dLbls/c:showSerName', $elementSerie)) { + $series->setShowSeriesName((bool) $elementShowSerName->getAttribute('val')); + } + + if ($elementShowPercent = $xmlReader->getElement('c:dLbls/c:showPercent', $elementSerie)) { + $series->setShowPercentage((bool) $elementShowPercent->getAttribute('val')); + } + + if ($elementShowLeaderLines = $xmlReader->getElement('c:dLbls/c:showLeaderLines', $elementSerie)) { + $series->setShowLeaderLines((bool) $elementShowLeaderLines->getAttribute('val')); + } + + $shapeType->addSeries($series); + } + + $elementGapWidth = $xmlReader->getElement('c:gapWidth', $oElement); + if ($elementGapWidth instanceof DOMElement) { + $shapeType->setGapWidthPercent((int) $elementGapWidth->getAttribute('val')); + } + + $elementOverlap = $xmlReader->getElement('c:overlap', $oElement); + if ($elementOverlap instanceof DOMElement) { + $shapeType->setOverlapWidthPercent((int) $elementOverlap->getAttribute('val')); + } + + $oShape->getPlotArea()->setType($shapeType); + } + + if ($oElement = $xmlReader->getElement('/c:chartSpace/c:chart/c:plotArea/c:catAx')) { + if ($elementOrientation = $xmlReader->getElement('c:scaling/c:orientation', $oElement)) { + $oShape->getPlotArea()->getAxisX()->setIsReversedOrder( + (bool) ($elementOrientation->getAttribute('val') === 'maxMin') + ); + } + if ($elementDelete = $xmlReader->getElement('c:delete', $oElement)) { + $oShape->getPlotArea()->getAxisX()->setIsVisible( + (bool) ($elementDelete->getAttribute('val') === '0') + ); + } + if ($elementMajorTickMark = $xmlReader->getElement('c:majorTickMark', $oElement)) { + $oShape->getPlotArea()->getAxisX()->setMajorTickMark($elementMajorTickMark->getAttribute('val')); + } + if ($elementMinorTickMark = $xmlReader->getElement('c:minorTickMark', $oElement)) { + $oShape->getPlotArea()->getAxisX()->setMajorTickMark($elementMinorTickMark->getAttribute('val')); + } + if ($elementTickLabelPosition = $xmlReader->getElement('c:tickLblPos', $oElement)) { + $oShape->getPlotArea()->getAxisX()->setTickLabelPosition($elementTickLabelPosition->getAttribute('val')); + } + if ($elementCrosses = $xmlReader->getElement('c:crosses', $oElement)) { + $oShape->getPlotArea()->getAxisX()->setCrossesAt($elementCrosses->getAttribute('val')); + } + + if ($elementFill = $xmlReader->getElement('c:spPr', $oElement)) { + $outline = $this->loadStyleOutline($xmlReader, $elementFill); + if ($outline) { + $oShape->getPlotArea()->getAxisX()->setOutline($outline); + } + } + } + + if ($oElement = $xmlReader->getElement('/c:chartSpace/c:chart/c:plotArea/c:valAx')) { + if ($elementOrientation = $xmlReader->getElement('c:scaling/c:orientation', $oElement)) { + $oShape->getPlotArea()->getAxisY()->setIsReversedOrder( + (bool) ($elementOrientation->getAttribute('val') === 'maxMin') + ); + } + if ($elementDelete = $xmlReader->getElement('c:delete', $oElement)) { + $oShape->getPlotArea()->getAxisY()->setIsVisible( + (bool) ($elementDelete->getAttribute('val') === '0') + ); + } + if ($elementMajorTickMark = $xmlReader->getElement('c:majorTickMark', $oElement)) { + $oShape->getPlotArea()->getAxisY()->setMajorTickMark($elementMajorTickMark->getAttribute('val')); + } + if ($elementMinorTickMark = $xmlReader->getElement('c:minorTickMark', $oElement)) { + $oShape->getPlotArea()->getAxisY()->setMajorTickMark($elementMinorTickMark->getAttribute('val')); + } + if ($elementTickLabelPosition = $xmlReader->getElement('c:tickLblPos', $oElement)) { + $oShape->getPlotArea()->getAxisY()->setTickLabelPosition($elementTickLabelPosition->getAttribute('val')); + } + if ($elementCrosses = $xmlReader->getElement('c:crosses', $oElement)) { + $oShape->getPlotArea()->getAxisY()->setCrossesAt($elementCrosses->getAttribute('val')); + } + if ($elementFill = $xmlReader->getElement('c:spPr/a:ln', $oElement)) { + if ($outline = $this->loadStyleOutline($xmlReader, $elementFill)) { + $oShape->getPlotArea()->getAxisY()->setOutline($outline); + } + } + } + + if ($oElement = $xmlReader->getElement('/c:chartSpace/c:chart/c:legend')) { + $oShape->getLegend()->setVisible(true); + + if ($elementLegendPos = $xmlReader->getElement('c:legendPos', $oElement)) { + $oShape->getLegend()->setPosition($elementLegendPos->getAttribute('val')); + } + } else { + $oShape->getLegend()->setVisible(false); + } + + if ($oElement = $xmlReader->getElement('/c:chartSpace/c:chart/c:dispBlanksAs')) { + $oShape->setDisplayBlankAs($oElement->getAttribute('val')); + } + } + } + $oSlide->addShape($oShape); + } + } + /** * @param Cell|RichText $oShape */ @@ -1206,7 +1435,7 @@ protected function loadParagraph(XMLReader $document, DOMElement $oElement, $oSh $oParagraph->getAlignment()->setMarginRight(CommonDrawing::emuToPixels((int) $oSubElement->getAttribute('marR'))); } if ($oSubElement->hasAttribute('indent')) { - $oParagraph->getAlignment()->setIndent(CommonDrawing::emuToPixels((int) $oSubElement->getAttribute('indent'))); + $oParagraph->getAlignment()->setIndent((int) CommonDrawing::emuToPixels((int) $oSubElement->getAttribute('indent'))); } if ($oSubElement->hasAttribute('lvl')) { $oParagraph->getAlignment()->setLevel((int) $oSubElement->getAttribute('lvl')); @@ -1390,7 +1619,7 @@ protected function loadHyperlink(XMLReader $xmlReader, DOMElement $element, Hype protected function loadStyleBorder(XMLReader $xmlReader, DOMElement $oElement, Border $oBorder): void { if ($oElement->hasAttribute('w')) { - $oBorder->setLineWidth((int) ((int) $oElement->getAttribute('w') / 12700)); + $oBorder->setLineWidth(CommonDrawing::emuToPixels((int) $oElement->getAttribute('w'))); } if ($oElement->hasAttribute('cmpd')) { $oBorder->setLineStyle($oElement->getAttribute('cmpd')); @@ -1468,6 +1697,24 @@ protected function loadStyleFill(XMLReader $xmlReader, DOMElement $oElement): ?F return null; } + protected function loadStyleOutline(XMLReader $xmlReader, DOMElement $oElement): ?Outline + { + if ($element = $xmlReader->getElement('a:ln', $oElement)) { + $outline = new Outline(); + + $outline->setWidth((int) CommonDrawing::emuToPixels((int) $element->getAttribute('w'))); + + $fill = $this->loadStyleFill($xmlReader, $element); + if ($fill) { + $outline->setFill($fill); + } + + return $outline; + } + + return null; + } + protected function loadRels(string $fileRels): void { $sPart = $this->oZip->getFromName($fileRels); @@ -1494,7 +1741,7 @@ protected function loadRels(string $fileRels): void * * @internal param $baseFile */ - protected function loadSlideShapes($oSlide, DOMNodeList $oElements, XMLReader $xmlReader): void + protected function loadSlideShapes(XMLReader $document, $oSlide, DOMNodeList $oElements, XMLReader $xmlReader): void { foreach ($oElements as $oNode) { if (!($oNode instanceof DOMElement)) { @@ -1503,7 +1750,12 @@ protected function loadSlideShapes($oSlide, DOMNodeList $oElements, XMLReader $x switch ($oNode->tagName) { case 'p:graphicFrame': if ($oSlide instanceof AbstractSlide) { - $this->loadShapeTable($xmlReader, $oNode, $oSlide); + if ($document->elementExists('a:graphic/a:graphicData/a:tbl', $oNode)) { + $this->loadShapeTable($xmlReader, $oNode, $oSlide); + } + if ($document->elementExists('a:graphic/a:graphicData/c:chart', $oNode)) { + $this->loadShapeChart($xmlReader, $oNode, $oSlide); + } } break; diff --git a/src/PhpPresentation/Reader/PowerPoint97.php b/src/PhpPresentation/Reader/PowerPoint97.php index 8a416d7f3..6882c53b7 100644 --- a/src/PhpPresentation/Reader/PowerPoint97.php +++ b/src/PhpPresentation/Reader/PowerPoint97.php @@ -2015,25 +2015,25 @@ private function readRecordOfficeArtFOPT(string $stream, int $pos): array case 0x0081: // Text : dxTextLeft //@link : http://msdn.microsoft.com/en-us/library/dd953234(v=office.12).aspx - $arrayReturn['insetLeft'] = \PhpOffice\Common\Drawing::emuToPixels((int) $opt['op']); + $arrayReturn['insetLeft'] = (int) \PhpOffice\Common\Drawing::emuToPixels((int) $opt['op']); break; case 0x0082: // Text : dyTextTop //@link : http://msdn.microsoft.com/en-us/library/dd925068(v=office.12).aspx - $arrayReturn['insetTop'] = \PhpOffice\Common\Drawing::emuToPixels((int) $opt['op']); + $arrayReturn['insetTop'] = (int) \PhpOffice\Common\Drawing::emuToPixels((int) $opt['op']); break; case 0x0083: // Text : dxTextRight //@link : http://msdn.microsoft.com/en-us/library/dd906782(v=office.12).aspx - $arrayReturn['insetRight'] = \PhpOffice\Common\Drawing::emuToPixels((int) $opt['op']); + $arrayReturn['insetRight'] = (int) \PhpOffice\Common\Drawing::emuToPixels((int) $opt['op']); break; case 0x0084: // Text : dyTextBottom //@link : http://msdn.microsoft.com/en-us/library/dd772858(v=office.12).aspx - $arrayReturn['insetBottom'] = \PhpOffice\Common\Drawing::emuToPixels((int) $opt['op']); + $arrayReturn['insetBottom'] = (int) \PhpOffice\Common\Drawing::emuToPixels((int) $opt['op']); break; case 0x0085: @@ -2194,7 +2194,7 @@ private function readRecordOfficeArtFOPT(string $stream, int $pos): array case 0x01CB: // Line Style : lineWidth //@link : http://msdn.microsoft.com/en-us/library/dd926964(v=office.12).aspx - $arrayReturn['lineWidth'] = \PhpOffice\Common\Drawing::emuToPixels((int) $opt['op']); + $arrayReturn['lineWidth'] = (int) \PhpOffice\Common\Drawing::emuToPixels((int) $opt['op']); break; case 0x01D6: @@ -2220,13 +2220,13 @@ private function readRecordOfficeArtFOPT(string $stream, int $pos): array case 0x0205: // Shadow Style : shadowOffsetX //@link : http://msdn.microsoft.com/en-us/library/dd945280(v=office.12).aspx - $arrayReturn['shadowOffsetX'] = \PhpOffice\Common\Drawing::emuToPixels((int) $opt['op']); + $arrayReturn['shadowOffsetX'] = (int) \PhpOffice\Common\Drawing::emuToPixels((int) $opt['op']); break; case 0x0206: // Shadow Style : shadowOffsetY //@link : http://msdn.microsoft.com/en-us/library/dd907855(v=office.12).aspx - $arrayReturn['shadowOffsetY'] = \PhpOffice\Common\Drawing::emuToPixels((int) $opt['op']); + $arrayReturn['shadowOffsetY'] = (int) \PhpOffice\Common\Drawing::emuToPixels((int) $opt['op']); break; case 0x023F: diff --git a/src/PhpPresentation/Slide.php b/src/PhpPresentation/Slide.php index ea4864913..6927d0e41 100644 --- a/src/PhpPresentation/Slide.php +++ b/src/PhpPresentation/Slide.php @@ -82,7 +82,9 @@ public function __construct(?PhpPresentation $pParent = null) $oMasterSlide = reset($arrayMasterSlides); $arraySlideLayouts = $oMasterSlide->getAllSlideLayouts(); $oSlideLayout = reset($arraySlideLayouts); - $this->setSlideLayout($oSlideLayout); + if ($oSlideLayout) { + $this->setSlideLayout($oSlideLayout); + } } // Set note $this->setNote(new Note()); diff --git a/src/PhpPresentation/Style/Border.php b/src/PhpPresentation/Style/Border.php index 6dea6a395..4961c6c9c 100644 --- a/src/PhpPresentation/Style/Border.php +++ b/src/PhpPresentation/Style/Border.php @@ -48,7 +48,7 @@ class Border implements ComparableInterface /** * Line width. * - * @var int + * @var float */ private $lineWidth = 1; @@ -86,17 +86,17 @@ public function __construct() } /** - * Get line width (in points). + * Get line width (in pixels). */ - public function getLineWidth(): int + public function getLineWidth(): float { return $this->lineWidth; } /** - * Set line width (in points). + * Set line width (in pixels). */ - public function setLineWidth(int $pValue = 1): self + public function setLineWidth(float $pValue = 1): self { $this->lineWidth = $pValue; diff --git a/src/PhpPresentation/Writer/HTML.php b/src/PhpPresentation/Writer/HTML.php index 669423604..fda0ba0ff 100644 --- a/src/PhpPresentation/Writer/HTML.php +++ b/src/PhpPresentation/Writer/HTML.php @@ -109,7 +109,10 @@ protected function getHtmlContent(): string } return '' - . '' + . '' + . '' + . '' + . '' . '' . $this->bodyList . $this->bodySlides . '' . ''; } diff --git a/src/PhpPresentation/Writer/ODPresentation/Styles.php b/src/PhpPresentation/Writer/ODPresentation/Styles.php index 21e1fb2c9..e3f2f8cbe 100644 --- a/src/PhpPresentation/Writer/ODPresentation/Styles.php +++ b/src/PhpPresentation/Writer/ODPresentation/Styles.php @@ -150,8 +150,8 @@ protected function writePart(): string $objWriter->writeAttribute('fo:margin-bottom', '0cm'); $objWriter->writeAttribute('fo:margin-left', '0cm'); $objWriter->writeAttribute('fo:margin-right', '0cm'); - $objWriter->writeAttribute('fo:page-width', Text::numberFormat(CommonDrawing::pixelsToCentimeters(CommonDrawing::emuToPixels((int) $this->getPresentation()->getLayout()->getCX())), 1) . 'cm'); - $objWriter->writeAttribute('fo:page-height', Text::numberFormat(CommonDrawing::pixelsToCentimeters(CommonDrawing::emuToPixels((int) $this->getPresentation()->getLayout()->getCY())), 1) . 'cm'); + $objWriter->writeAttribute('fo:page-width', Text::numberFormat(CommonDrawing::pixelsToCentimeters((int) CommonDrawing::emuToPixels((int) $this->getPresentation()->getLayout()->getCX())), 1) . 'cm'); + $objWriter->writeAttribute('fo:page-height', Text::numberFormat(CommonDrawing::pixelsToCentimeters((int) CommonDrawing::emuToPixels((int) $this->getPresentation()->getLayout()->getCY())), 1) . 'cm'); $printOrientation = 'portrait'; if ($this->getPresentation()->getLayout()->getCX() > $this->getPresentation()->getLayout()->getCY()) { $printOrientation = 'landscape'; diff --git a/src/PhpPresentation/Writer/PowerPoint2007/AbstractDecoratorWriter.php b/src/PhpPresentation/Writer/PowerPoint2007/AbstractDecoratorWriter.php index 115cf0a16..869e0e2b4 100644 --- a/src/PhpPresentation/Writer/PowerPoint2007/AbstractDecoratorWriter.php +++ b/src/PhpPresentation/Writer/PowerPoint2007/AbstractDecoratorWriter.php @@ -76,12 +76,9 @@ protected function writeBorder(XMLWriter $objWriter, Border $pBorder, string $pE $lineStyle = Border::LINE_SINGLE; } - // Line width - $lineWidth = 12700 * $pBorder->getLineWidth(); - // a:ln $pElementName $objWriter->startElement('a:ln' . $pElementName); - $objWriter->writeAttribute('w', $lineWidth); + $objWriter->writeAttribute('w', (int) CommonDrawing::pixelsToEmu($pBorder->getLineWidth())); $objWriter->writeAttribute('cap', 'flat'); $objWriter->writeAttribute('cmpd', $lineStyle); $objWriter->writeAttribute('algn', 'ctr'); @@ -140,12 +137,6 @@ protected function writeColor(XMLWriter $objWriter, Color $color, ?int $alpha = $objWriter->endElement(); } - /** - * Write Fill. - * - * @param XMLWriter $objWriter XML Writer - * @param null|Fill $pFill Fill style - */ protected function writeFill(XMLWriter $objWriter, ?Fill $pFill): void { if (!$pFill) { @@ -177,12 +168,6 @@ protected function writeFill(XMLWriter $objWriter, ?Fill $pFill): void $this->writePatternFill($objWriter, $pFill); } - /** - * Write Solid Fill. - * - * @param XMLWriter $objWriter XML Writer - * @param Fill $pFill Fill style - */ protected function writeSolidFill(XMLWriter $objWriter, Fill $pFill): void { // a:gradFill @@ -191,12 +176,6 @@ protected function writeSolidFill(XMLWriter $objWriter, Fill $pFill): void $objWriter->endElement(); } - /** - * Write Gradient Fill. - * - * @param XMLWriter $objWriter XML Writer - * @param Fill $pFill Fill style - */ protected function writeGradientFill(XMLWriter $objWriter, Fill $pFill): void { // a:gradFill @@ -227,12 +206,6 @@ protected function writeGradientFill(XMLWriter $objWriter, Fill $pFill): void $objWriter->endElement(); } - /** - * Write Pattern Fill. - * - * @param XMLWriter $objWriter XML Writer - * @param Fill $pFill Fill style - */ protected function writePatternFill(XMLWriter $objWriter, Fill $pFill): void { // a:pattFill @@ -255,15 +228,12 @@ protected function writePatternFill(XMLWriter $objWriter, Fill $pFill): void $objWriter->endElement(); } - /** - * Write Outline. - */ protected function writeOutline(XMLWriter $objWriter, ?Outline $oOutline): void { if (!$oOutline) { return; } - // Width : pts + // Width : pixels $width = CommonDrawing::pixelsToEmu($oOutline->getWidth()); // a:ln diff --git a/src/PhpPresentation/Writer/PowerPoint2007/AbstractSlide.php b/src/PhpPresentation/Writer/PowerPoint2007/AbstractSlide.php index 38dc4eec4..2f0544fd7 100644 --- a/src/PhpPresentation/Writer/PowerPoint2007/AbstractSlide.php +++ b/src/PhpPresentation/Writer/PowerPoint2007/AbstractSlide.php @@ -571,7 +571,7 @@ protected function writeParagraphStyles(XMLWriter $objWriter, Paragraph $paragra $objWriter->writeAttribute('fontAlgn', $paragraph->getAlignment()->getVertical()); $objWriter->writeAttribute('marL', CommonDrawing::pixelsToEmu($paragraph->getAlignment()->getMarginLeft())); $objWriter->writeAttribute('marR', CommonDrawing::pixelsToEmu($paragraph->getAlignment()->getMarginRight())); - $objWriter->writeAttribute('indent', CommonDrawing::pixelsToEmu($paragraph->getAlignment()->getIndent())); + $objWriter->writeAttribute('indent', (int) CommonDrawing::pixelsToEmu($paragraph->getAlignment()->getIndent())); $objWriter->writeAttribute('lvl', $paragraph->getAlignment()->getLevel()); $objWriter->startElement('a:lnSpc'); diff --git a/src/PhpPresentation/Writer/PowerPoint2007/PptCharts.php b/src/PhpPresentation/Writer/PowerPoint2007/PptCharts.php index 40ac9d44a..a9a0ec758 100644 --- a/src/PhpPresentation/Writer/PowerPoint2007/PptCharts.php +++ b/src/PhpPresentation/Writer/PowerPoint2007/PptCharts.php @@ -431,7 +431,7 @@ protected function writeTitle(XMLWriter $objWriter, Title $subject): void $objWriter->writeAttribute('fontAlgn', $subject->getAlignment()->getVertical()); $objWriter->writeAttribute('marL', CommonDrawing::pixelsToEmu($subject->getAlignment()->getMarginLeft())); $objWriter->writeAttribute('marR', CommonDrawing::pixelsToEmu($subject->getAlignment()->getMarginRight())); - $objWriter->writeAttribute('indent', CommonDrawing::pixelsToEmu($subject->getAlignment()->getIndent())); + $objWriter->writeAttribute('indent', (int) CommonDrawing::pixelsToEmu($subject->getAlignment()->getIndent())); $objWriter->writeAttribute('lvl', $subject->getAlignment()->getLevel()); // a:defRPr @@ -546,11 +546,6 @@ protected function writePlotArea(XMLWriter $objWriter, PlotArea $subject, Chart $objWriter->endElement(); } - /** - * Write Legend. - * - * @param XMLWriter $objWriter XML Writer - */ protected function writeLegend(XMLWriter $objWriter, Legend $subject): void { // c:legend @@ -600,7 +595,7 @@ protected function writeLegend(XMLWriter $objWriter, Legend $subject): void $objWriter->writeAttribute('fontAlgn', $subject->getAlignment()->getVertical()); $objWriter->writeAttribute('marL', CommonDrawing::pixelsToEmu($subject->getAlignment()->getMarginLeft())); $objWriter->writeAttribute('marR', CommonDrawing::pixelsToEmu($subject->getAlignment()->getMarginRight())); - $objWriter->writeAttribute('indent', CommonDrawing::pixelsToEmu($subject->getAlignment()->getIndent())); + $objWriter->writeAttribute('indent', (int) CommonDrawing::pixelsToEmu($subject->getAlignment()->getIndent())); $objWriter->writeAttribute('lvl', $subject->getAlignment()->getLevel()); // a:defRPr diff --git a/src/PhpPresentation/Writer/PowerPoint2007/PptSlideMasters.php b/src/PhpPresentation/Writer/PowerPoint2007/PptSlideMasters.php index 8c289bfc4..95abfb339 100644 --- a/src/PhpPresentation/Writer/PowerPoint2007/PptSlideMasters.php +++ b/src/PhpPresentation/Writer/PowerPoint2007/PptSlideMasters.php @@ -211,7 +211,7 @@ protected function writeSlideMaster(SlideMaster $pSlide): string $objWriter->writeAttributeIf( 0 != $oParagraph->getAlignment()->getIndent(), 'indent', - CommonDrawing::pixelsToEmu($oParagraph->getAlignment()->getIndent()) + (int) CommonDrawing::pixelsToEmu($oParagraph->getAlignment()->getIndent()) ); $objWriter->startElement('a:defRPr'); $objWriter->writeAttributeIf(10 != $oParagraph->getFont()->getSize(), 'sz', $oParagraph->getFont()->getSize() * 100); diff --git a/tests/PhpPresentation/Tests/Reader/PowerPoint2007Test.php b/tests/PhpPresentation/Tests/Reader/PowerPoint2007Test.php index bdbaf7a96..a4b8ad67b 100644 --- a/tests/PhpPresentation/Tests/Reader/PowerPoint2007Test.php +++ b/tests/PhpPresentation/Tests/Reader/PowerPoint2007Test.php @@ -25,6 +25,7 @@ use PhpOffice\PhpPresentation\Exception\InvalidFileFormatException; use PhpOffice\PhpPresentation\PresentationProperties; use PhpOffice\PhpPresentation\Reader\PowerPoint2007; +use PhpOffice\PhpPresentation\Shape\Chart; use PhpOffice\PhpPresentation\Shape\Drawing\Gd; use PhpOffice\PhpPresentation\Shape\RichText; use PhpOffice\PhpPresentation\Shape\RichText\Paragraph; @@ -594,6 +595,28 @@ public function testLoadFile01(): void self::assertEquals(Font::CAPITALIZATION_NONE, $oRichText->getFont()->getCapitalization()); } + public function testLoadFileChartBar(): void + { + $file = PHPPRESENTATION_TESTS_BASE_DIR . '/resources/files/PPTX_ChartBar.pptx'; + $object = new PowerPoint2007(); + $oPhpPresentation = $object->load($file); + self::assertInstanceOf('PhpOffice\\PhpPresentation\\PhpPresentation', $oPhpPresentation); + // Document Properties + + // Slides + self::assertCount(3, $oPhpPresentation->getAllSlides()); + + // Slide 2 + $oSlide2 = $oPhpPresentation->getSlide(1); + $arrayShape = (array) $oSlide2->getShapeCollection(); + self::assertCount(2, $arrayShape); + // Slide 2 : Shape 2 + /** @var Chart $oShape */ + $oShape = $arrayShape[1]; + self::assertInstanceOf(Chart::class, $oShape); + self::assertInstanceOf(Chart\Type\Bar::class, $oShape->getPlotArea()->getType()); + } + public function testLoadFileWithoutImages(): void { $file = PHPPRESENTATION_TESTS_BASE_DIR . '/resources/files/Sample_12.pptx'; @@ -703,8 +726,8 @@ public function testLoadFileWithoutImages(): void $oParagraph = $arrayParagraphs[0]; self::assertEquals(Alignment::HORIZONTAL_LEFT, $oParagraph->getAlignment()->getHorizontal()); self::assertFalse($oParagraph->getAlignment()->isRTL()); -// $this->assertEquals(25, $oParagraph->getAlignment()->getMarginLeft()); -// $this->assertEquals(-25, $oParagraph->getAlignment()->getIndent()); + // $this->assertEquals(25, $oParagraph->getAlignment()->getMarginLeft()); + // $this->assertEquals(-25, $oParagraph->getAlignment()->getIndent()); self::assertEquals(Bullet::TYPE_BULLET, $oParagraph->getBulletStyle()->getBulletType()); $arrayRichText = $oParagraph->getRichTextElements(); self::assertCount(1, $arrayRichText); @@ -720,8 +743,8 @@ public function testLoadFileWithoutImages(): void $oParagraph = $arrayParagraphs[1]; self::assertEquals(Alignment::HORIZONTAL_LEFT, $oParagraph->getAlignment()->getHorizontal()); self::assertFalse($oParagraph->getAlignment()->isRTL()); -// $this->assertEquals(25, $oParagraph->getAlignment()->getMarginLeft()); -// $this->assertEquals(-25, $oParagraph->getAlignment()->getIndent()); + // $this->assertEquals(25, $oParagraph->getAlignment()->getMarginLeft()); + // $this->assertEquals(-25, $oParagraph->getAlignment()->getIndent()); self::assertEquals(Bullet::TYPE_BULLET, $oParagraph->getBulletStyle()->getBulletType()); $arrayRichText = $oParagraph->getRichTextElements(); self::assertCount(1, $arrayRichText); @@ -737,8 +760,8 @@ public function testLoadFileWithoutImages(): void $oParagraph = $arrayParagraphs[2]; self::assertEquals(Alignment::HORIZONTAL_LEFT, $oParagraph->getAlignment()->getHorizontal()); self::assertFalse($oParagraph->getAlignment()->isRTL()); -// $this->assertEquals(25, $oParagraph->getAlignment()->getMarginLeft()); -// $this->assertEquals(-25, $oParagraph->getAlignment()->getIndent()); + // $this->assertEquals(25, $oParagraph->getAlignment()->getMarginLeft()); + // $this->assertEquals(-25, $oParagraph->getAlignment()->getIndent()); self::assertEquals(Bullet::TYPE_BULLET, $oParagraph->getBulletStyle()->getBulletType()); $arrayRichText = $oParagraph->getRichTextElements(); self::assertCount(1, $arrayRichText); @@ -754,8 +777,8 @@ public function testLoadFileWithoutImages(): void $oParagraph = $arrayParagraphs[3]; self::assertEquals(Alignment::HORIZONTAL_LEFT, $oParagraph->getAlignment()->getHorizontal()); self::assertFalse($oParagraph->getAlignment()->isRTL()); -// $this->assertEquals(25, $oParagraph->getAlignment()->getMarginLeft()); -// $this->assertEquals(-25, $oParagraph->getAlignment()->getIndent()); + // $this->assertEquals(25, $oParagraph->getAlignment()->getMarginLeft()); + // $this->assertEquals(-25, $oParagraph->getAlignment()->getIndent()); self::assertEquals(Bullet::TYPE_BULLET, $oParagraph->getBulletStyle()->getBulletType()); $arrayRichText = $oParagraph->getRichTextElements(); self::assertCount(1, $arrayRichText); @@ -815,8 +838,8 @@ public function testLoadFileWithoutImages(): void $oParagraph = $arrayParagraphs[0]; self::assertEquals(Alignment::HORIZONTAL_LEFT, $oParagraph->getAlignment()->getHorizontal()); self::assertFalse($oParagraph->getAlignment()->isRTL()); -// $this->assertEquals(25, $oParagraph->getAlignment()->getMarginLeft()); -// $this->assertEquals(-25, $oParagraph->getAlignment()->getIndent()); + // $this->assertEquals(25, $oParagraph->getAlignment()->getMarginLeft()); + // $this->assertEquals(-25, $oParagraph->getAlignment()->getIndent()); self::assertEquals(0, $oParagraph->getAlignment()->getLevel()); self::assertEquals(Bullet::TYPE_BULLET, $oParagraph->getBulletStyle()->getBulletType()); $arrayRichText = $oParagraph->getRichTextElements(); @@ -833,8 +856,8 @@ public function testLoadFileWithoutImages(): void $oParagraph = $arrayParagraphs[1]; self::assertEquals(Alignment::HORIZONTAL_LEFT, $oParagraph->getAlignment()->getHorizontal()); self::assertFalse($oParagraph->getAlignment()->isRTL()); -// $this->assertEquals(75, $oParagraph->getAlignment()->getMarginLeft()); -// $this->assertEquals(-25, $oParagraph->getAlignment()->getIndent()); + // $this->assertEquals(75, $oParagraph->getAlignment()->getMarginLeft()); + // $this->assertEquals(-25, $oParagraph->getAlignment()->getIndent()); self::assertEquals(1, $oParagraph->getAlignment()->getLevel()); self::assertEquals(Bullet::TYPE_BULLET, $oParagraph->getBulletStyle()->getBulletType()); $arrayRichText = $oParagraph->getRichTextElements(); @@ -851,8 +874,8 @@ public function testLoadFileWithoutImages(): void $oParagraph = $arrayParagraphs[2]; self::assertEquals(Alignment::HORIZONTAL_LEFT, $oParagraph->getAlignment()->getHorizontal()); self::assertFalse($oParagraph->getAlignment()->isRTL()); -// $this->assertEquals(75, $oParagraph->getAlignment()->getMarginLeft()); -// $this->assertEquals(-25, $oParagraph->getAlignment()->getIndent()); + // $this->assertEquals(75, $oParagraph->getAlignment()->getMarginLeft()); + // $this->assertEquals(-25, $oParagraph->getAlignment()->getIndent()); self::assertEquals(1, $oParagraph->getAlignment()->getLevel()); self::assertEquals(Bullet::TYPE_BULLET, $oParagraph->getBulletStyle()->getBulletType()); $arrayRichText = $oParagraph->getRichTextElements(); @@ -869,8 +892,8 @@ public function testLoadFileWithoutImages(): void $oParagraph = $arrayParagraphs[3]; self::assertEquals(Alignment::HORIZONTAL_LEFT, $oParagraph->getAlignment()->getHorizontal()); self::assertFalse($oParagraph->getAlignment()->isRTL()); -// $this->assertEquals(75, $oParagraph->getAlignment()->getMarginLeft()); -// $this->assertEquals(-25, $oParagraph->getAlignment()->getIndent()); + // $this->assertEquals(75, $oParagraph->getAlignment()->getMarginLeft()); + // $this->assertEquals(-25, $oParagraph->getAlignment()->getIndent()); self::assertEquals(1, $oParagraph->getAlignment()->getLevel()); self::assertEquals(Bullet::TYPE_BULLET, $oParagraph->getBulletStyle()->getBulletType()); $arrayRichText = $oParagraph->getRichTextElements(); @@ -887,8 +910,8 @@ public function testLoadFileWithoutImages(): void $oParagraph = $arrayParagraphs[4]; self::assertEquals(Alignment::HORIZONTAL_LEFT, $oParagraph->getAlignment()->getHorizontal()); self::assertFalse($oParagraph->getAlignment()->isRTL()); -// $this->assertEquals(25, $oParagraph->getAlignment()->getMarginLeft()); -// $this->assertEquals(-25, $oParagraph->getAlignment()->getIndent()); + // $this->assertEquals(25, $oParagraph->getAlignment()->getMarginLeft()); + // $this->assertEquals(-25, $oParagraph->getAlignment()->getIndent()); self::assertEquals(0, $oParagraph->getAlignment()->getLevel()); self::assertEquals(Bullet::TYPE_BULLET, $oParagraph->getBulletStyle()->getBulletType()); $arrayRichText = $oParagraph->getRichTextElements(); @@ -905,8 +928,8 @@ public function testLoadFileWithoutImages(): void $oParagraph = $arrayParagraphs[5]; self::assertEquals(Alignment::HORIZONTAL_LEFT, $oParagraph->getAlignment()->getHorizontal()); self::assertFalse($oParagraph->getAlignment()->isRTL()); -// $this->assertEquals(75, $oParagraph->getAlignment()->getMarginLeft()); -// $this->assertEquals(-25, $oParagraph->getAlignment()->getIndent()); + // $this->assertEquals(75, $oParagraph->getAlignment()->getMarginLeft()); + // $this->assertEquals(-25, $oParagraph->getAlignment()->getIndent()); self::assertEquals(1, $oParagraph->getAlignment()->getLevel()); self::assertEquals(Bullet::TYPE_BULLET, $oParagraph->getBulletStyle()->getBulletType()); $arrayRichText = $oParagraph->getRichTextElements(); @@ -923,8 +946,8 @@ public function testLoadFileWithoutImages(): void $oParagraph = $arrayParagraphs[6]; self::assertEquals(Alignment::HORIZONTAL_LEFT, $oParagraph->getAlignment()->getHorizontal()); self::assertFalse($oParagraph->getAlignment()->isRTL()); -// $this->assertEquals(75, $oParagraph->getAlignment()->getMarginLeft()); -// $this->assertEquals(-25, $oParagraph->getAlignment()->getIndent()); + // $this->assertEquals(75, $oParagraph->getAlignment()->getMarginLeft()); + // $this->assertEquals(-25, $oParagraph->getAlignment()->getIndent()); self::assertEquals(1, $oParagraph->getAlignment()->getLevel()); self::assertEquals(Bullet::TYPE_BULLET, $oParagraph->getBulletStyle()->getBulletType()); $arrayRichText = $oParagraph->getRichTextElements(); @@ -941,8 +964,8 @@ public function testLoadFileWithoutImages(): void $oParagraph = $arrayParagraphs[7]; self::assertEquals(Alignment::HORIZONTAL_LEFT, $oParagraph->getAlignment()->getHorizontal()); self::assertFalse($oParagraph->getAlignment()->isRTL()); -// $this->assertEquals(75, $oParagraph->getAlignment()->getMarginLeft()); -// $this->assertEquals(-25, $oParagraph->getAlignment()->getIndent()); + // $this->assertEquals(75, $oParagraph->getAlignment()->getMarginLeft()); + // $this->assertEquals(-25, $oParagraph->getAlignment()->getIndent()); self::assertEquals(1, $oParagraph->getAlignment()->getLevel()); self::assertEquals(Bullet::TYPE_BULLET, $oParagraph->getBulletStyle()->getBulletType()); $arrayRichText = $oParagraph->getRichTextElements(); diff --git a/tests/PhpPresentation/Tests/Writer/PowerPoint2007/PptChartsTest.php b/tests/PhpPresentation/Tests/Writer/PowerPoint2007/PptChartsTest.php index b540b916d..21ff6c5ac 100644 --- a/tests/PhpPresentation/Tests/Writer/PowerPoint2007/PptChartsTest.php +++ b/tests/PhpPresentation/Tests/Writer/PowerPoint2007/PptChartsTest.php @@ -789,7 +789,7 @@ public function testAxisXUnit(): void public function testAxisYUnit(): void { - $value = mt_rand(0, 100); + $value = mt_rand(1, 100); $oSeries = new Series('Downloads', $this->seriesData); $oLine = new Line(); @@ -1232,7 +1232,7 @@ public function testTypeLineMarkerBorder(): void $oShape->getPlotArea()->setType($oLine); $this->assertZipXmlElementExists('ppt/charts/' . $oShape->getIndexedFilename(), $element); - $this->assertZipXmlAttributeEquals('ppt/charts/' . $oShape->getIndexedFilename(), $element, 'w', 12700); + $this->assertZipXmlAttributeEquals('ppt/charts/' . $oShape->getIndexedFilename(), $element, 'w', 9525); $this->assertZipXmlAttributeEquals('ppt/charts/' . $oShape->getIndexedFilename(), $element, 'cmpd', Border::LINE_SINGLE); $this->assertZipXmlElementExists('ppt/charts/' . $oShape->getIndexedFilename(), $element . '/a:prstDash'); $this->assertZipXmlAttributeEquals('ppt/charts/' . $oShape->getIndexedFilename(), $element . '/a:prstDash', 'val', Border::DASH_SOLID); @@ -1646,7 +1646,7 @@ public function testTypeScatterMarkerBorder(): void $oShape->getPlotArea()->setType($oScatter); $this->assertZipXmlElementExists('ppt/charts/' . $oShape->getIndexedFilename(), $element); - $this->assertZipXmlAttributeEquals('ppt/charts/' . $oShape->getIndexedFilename(), $element, 'w', 12700); + $this->assertZipXmlAttributeEquals('ppt/charts/' . $oShape->getIndexedFilename(), $element, 'w', 9525); $this->assertZipXmlAttributeEquals('ppt/charts/' . $oShape->getIndexedFilename(), $element, 'cmpd', Border::LINE_SINGLE); $this->assertZipXmlElementExists('ppt/charts/' . $oShape->getIndexedFilename(), $element . '/a:prstDash'); $this->assertZipXmlAttributeEquals('ppt/charts/' . $oShape->getIndexedFilename(), $element . '/a:prstDash', 'val', Border::DASH_SOLID); diff --git a/tests/resources/files/PPTX_ChartBar.pptx b/tests/resources/files/PPTX_ChartBar.pptx new file mode 100644 index 000000000..ddd4e4883 Binary files /dev/null and b/tests/resources/files/PPTX_ChartBar.pptx differ