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

Vertical alignment does not work if it is a placeholder #799

Open
NigelSwinson opened this issue Mar 30, 2024 · 2 comments
Open

Vertical alignment does not work if it is a placeholder #799

NigelSwinson opened this issue Mar 30, 2024 · 2 comments

Comments

@NigelSwinson
Copy link

NigelSwinson commented Mar 30, 2024

The following sample demonstrates that if you have an entity in a slide (or a slide layout) which has Alignment::Vertical_CENTER, then it will only be aligned center if the object does not also have a PlaceHolder. Horizontal alignment is however respected in both cases.

<?php

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

include_once 'Sample_Header.php';

// 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 20 SlideLayout')
->setSubject('Sample 20 Subject')
->setDescription('Sample 20 Description')
->setKeywords('office 2007 openxml libreoffice odt php')
->setCategory('Sample Category');

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

echo date('H:i:s') . ' Create SlideLayout' . EOL;
$slideLayout = $objPHPPresentation->getAllMasterSlides()[0]->createSlideLayout();
$slideLayout->setLayoutName('Sample Layout');

$slides = array($slideLayout, $objPHPPresentation->getActiveSlide());

foreach ($slides as $slide) {
	echo date('H:i:s') . ' Create Footer' . EOL;
	$footerTextShape = $slide->createRichTextShape();
	$footerTextShape->setPlaceHolder(new Placeholder(Placeholder::PH_TYPE_FOOTER));
	
	$footerTextShape
	->setOffsetX(77)
	->setOffsetY(0)
	->setWidth(448)
	->setHeight(223);
	
	$footerTextRun = $footerTextShape->createTextRun('With setPlaceholder');
	$footerTextRun->getFont()
	->setName('Calibri')
	->setSize(9)
	->setColor(new Color(Color::COLOR_DARKGREEN))
	->setBold(true);
	$footerTextShape->getActiveParagraph()->getAlignment()
	->setVertical(Alignment::VERTICAL_CENTER);
	
	$footerTextShape = $slide->createRichTextShape();
	//$footerTextShape->setPlaceHolder(new Placeholder(Placeholder::PH_TYPE_FOOTER));
	
	$footerTextShape
	->setOffsetX(77)
	->setOffsetY(479)
	->setWidth(448)
	->setHeight(223);
	
	$footerTextRun = $footerTextShape->createTextRun('Without placeholder');
	$footerTextRun->getFont()
	->setName('Calibri')
	->setSize(9)
	->setColor(new Color(Color::COLOR_DARKGREEN))
	->setBold(true);
	$footerTextShape->getActiveParagraph()->getAlignment()
	->setVertical(Alignment::VERTICAL_CENTER);
}

echo date('H:i:s') . ' Apply Layout' . EOL;
$currentSlide->setSlideLayout($slideLayout);

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

I think it's possible the <a:bodyPr/> tag needs to have an anchor="ctr" attribute.

@NigelSwinson
Copy link
Author

Note my testing was done here against the develop branch. The master branch seemed to have a lot more bugs in this area; so great to see/benefit from progress here.

By amending AbstractSlide.php to remove the if (!$shape->isPlaceholder()) { command in writeShapeText, this seems to work. It feels like it is on the same lines as what @devX2712 was trying to do on the 13th December 2023 with other commits in the same file. I'm hoping his expert advice here might conclude that these type of changes should be expanded further.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

1 participant