Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change group shape extents to reflect content width/height. #451

Merged
merged 1 commit into from
Feb 5, 2018

Conversation

jsnke
Copy link

@jsnke jsnke commented Feb 5, 2018

Previously the group extents where calculated based on the extents of the containing shapes, which uses the slide/container of the group as the point of reference. This would result in the group being larger than
needed; especially noticeable for a large X or Y offset.

Example selected group in PowerPoint 2016 before these changes:

2018-02-05 14_04_46-group_test_pre pptx - powerpoint

The same example and selection after the code changes:

2018-02-05 14_03_33-group_test_post pptx - powerpoint

The code that generated the above two files was a slight modification of samples/Sample_08_Group.php to move the first image further away from the left and top so as to more clearly show the effect:

<?php

include_once 'Sample_Header.php';

use PhpOffice\PhpPresentation\PhpPresentation;
use PhpOffice\PhpPresentation\Style\Alignment;
use PhpOffice\PhpPresentation\Style\Color;

// Create new PHPPresentation object
echo date('H:i:s') . ' Create new PHPPresentation object' . EOL;
$objPHPPresentation = new PhpPresentation();

// Set properties
echo date('H:i:s') . ' Set properties'.EOL;
$objPHPPresentation->getDocumentProperties()->setCreator('PHPOffice')
                                  ->setLastModifiedBy('PHPPresentation Team')
                                  ->setTitle('Sample 01 Title')
                                  ->setSubject('Sample 01 Subject')
                                  ->setDescription('Sample 01 Description')
                                  ->setKeywords('office 2007 openxml libreoffice odt php')
                                  ->setCategory('Sample Category');

// Create slide
echo date('H:i:s') . ' Create slide'.EOL;
$currentGroup = $objPHPPresentation->getActiveSlide()->createGroup();

// Create a shape (drawing)
echo date('H:i:s') . ' Create a shape (drawing)'.EOL;
$shape = $currentGroup->createDrawingShape();
$shape->setName('PHPPresentation logo')
      ->setDescription('PHPPresentation logo')
      ->setPath('./resources/phppowerpoint_logo.gif')
      ->setHeight(36)
      ->setOffsetX(200)
      ->setOffsetY(100);
$shape->getShadow()->setVisible(true)
                   ->setDirection(45)
                   ->setDistance(10);

// Create a shape (drawing #2)
echo date('H:i:s') . ' Create a shape (drawing #2)'.EOL;
$shape = $currentGroup->createDrawingShape();
$shape->setName('PHPPresentation logo 2')
      ->setDescription('PHPPresentation logo 2')
      ->setPath('./resources/phppowerpoint_logo.gif')
      ->setHeight(36)
      ->setOffsetX(600)
      ->setOffsetY(200);
$shape->getShadow()->setVisible(true)
                   ->setDirection(45)
                   ->setDistance(10);

// Save file
echo write($objPHPPresentation, basename(__FILE__, '.php'), $writers);
if (!CLI) {
	include_once 'Sample_Footer.php';
}

Previously the group extents where calculated based on the extents of
the containing shapes using the slide/container of the group as the
point of reference. This would result in the group being larger than
needed; especially noticable for a large X or Y offest.
@Progi1984
Copy link
Member

Wow ! Good job. Thanks

@Progi1984 Progi1984 merged commit 006a348 into PHPOffice:develop Feb 5, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants