Skip to content

Commit

Permalink
#370 : ODPresentation Writer : Support for fill for transparent image
Browse files Browse the repository at this point in the history
  • Loading branch information
Progi1984 committed Sep 7, 2017
1 parent d7247d2 commit e39627c
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 8 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
- ODPresentation Writer : Support for the position of Legend - @Progi1984 GH-355
- ODPresentation Writer : Support for DoughnutChart - @Progi1984 GH-355
- PowerPoint2007 Writer : Support for DoughnutChart - @Progi1984 GH-355
- ODPresentation Writer : Support for fill for transparent image - @Progi1984 GH-370
- PowerPoint2007 Writer : Support for fill for transparent image - @JewrassicPark GH-370

## 0.9.0 - 2017-07-05
Expand Down
Binary file added samples/resources/logo_ubuntu_transparent.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
35 changes: 27 additions & 8 deletions src/PhpPresentation/Writer/ODPresentation/Content.php
Original file line number Diff line number Diff line change
Expand Up @@ -814,9 +814,7 @@ public function writeTxtStyle(XMLWriter $objWriter, RichText $shape)
$objWriter->writeAttribute('style:parent-style-name', 'standard');
// style:graphic-properties
$objWriter->startElement('style:graphic-properties');
if ($shape->getShadow()->isVisible()) {
$this->writeStylePartShadow($objWriter, $shape->getShadow());
}
$this->writeStylePartShadow($objWriter, $shape->getShadow());
if (is_bool($shape->hasAutoShrinkVertical())) {
$objWriter->writeAttribute('draw:auto-grow-height', var_export($shape->hasAutoShrinkVertical(), true));
}
Expand Down Expand Up @@ -915,7 +913,7 @@ public function writeTxtStyle(XMLWriter $objWriter, RichText $shape)
* Write the default style information for an AbstractDrawingAdapter
*
* @param \PhpOffice\Common\XMLWriter $objWriter
* @param \PhpOffice\PhpPresentation\Shape\AbstractDrawingAdapter $shape
* @param AbstractDrawingAdapter $shape
*/
public function writeDrawingStyle(XMLWriter $objWriter, AbstractDrawingAdapter $shape)
{
Expand All @@ -928,10 +926,8 @@ public function writeDrawingStyle(XMLWriter $objWriter, AbstractDrawingAdapter $
// style:graphic-properties
$objWriter->startElement('style:graphic-properties');
$objWriter->writeAttribute('draw:stroke', 'none');
$objWriter->writeAttribute('draw:fill', 'none');
if ($shape->getShadow()->isVisible()) {
$this->writeStylePartShadow($objWriter, $shape->getShadow());
}
$this->writeStylePartFill($objWriter, $shape->getFill());
$this->writeStylePartShadow($objWriter, $shape->getShadow());
$objWriter->endElement();

$objWriter->endElement();
Expand Down Expand Up @@ -1305,13 +1301,36 @@ public function writeStyleSlide(XMLWriter $objWriter, Slide $slide, $incPage)
}


/**
* @param XMLWriter $objWriter
* @param Fill $oFill
*/
protected function writeStylePartFill(XMLWriter $objWriter, Fill $oFill)
{
switch ($oFill->getFillType()) {
case Fill::FILL_SOLID:
$objWriter->writeAttribute('draw:fill', 'solid');
$objWriter->writeAttribute('draw:fill-color', '#' . $oFill->getStartColor()->getRGB());
break;
case Fill::FILL_NONE:
default:
$objWriter->writeAttribute('draw:fill', 'none');
break;
}
$objWriter->writeAttribute('style:mirror', 'none');
}


/**
* @param XMLWriter $objWriter
* @param Shadow $oShadow
* @todo Improve for supporting any direction (https://sinepost.wordpress.com/2012/02/16/theyve-got-atan-you-want-atan2/)
*/
protected function writeStylePartShadow(XMLWriter $objWriter, Shadow $oShadow)
{
if (!$oShadow->isVisible()) {
return;
}
$objWriter->writeAttribute('draw:shadow', 'visible');
$objWriter->writeAttribute('draw:shadow-color', '#' . $oShadow->getColor()->getRGB());

Expand Down
22 changes: 22 additions & 0 deletions tests/PhpPresentation/Tests/Writer/ODPresentation/ContentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,28 @@ public function testDrawingWithHyperlink()
$this->assertZipXmlAttributeEquals('content.xml', $element, 'xlink:href', 'https://github.com/PHPOffice/PHPPresentation/');
}

public function testDrawingShapeFill()
{
$oSlide = $this->oPresentation->getActiveSlide();
$oShape = $oSlide->createDrawingShape();
$oShape->setPath(PHPPRESENTATION_TESTS_BASE_DIR . '/resources/images/PhpPresentationLogo.png');

$element = '/office:document-content/office:automatic-styles/style:style/style:graphic-properties';
$this->assertZipXmlElementExists('content.xml', $element);
$this->assertZipXmlAttributeEquals('content.xml', $element, 'draw:fill', 'none');

$oColor = new Color(Color::COLOR_DARKRED);
$oColor->setAlpha(rand(0, 100));
$oShape->getFill()->setFillType(Fill::FILL_SOLID)->setStartColor($oColor);
$this->resetPresentationFile();

$element = '/office:document-content/office:automatic-styles/style:style/style:graphic-properties';
$this->assertZipXmlElementExists('content.xml', $element);
$this->assertZipXmlAttributeEquals('content.xml', $element, 'draw:fill', 'solid');
$this->assertZipXmlAttributeStartsWith('content.xml', $element, 'draw:fill-color', '#');
$this->assertZipXmlAttributeEndsWith('content.xml', $element, 'draw:fill-color', $oColor->getRGB());
}

public function testComment()
{
$expectedName = 'Name';
Expand Down

0 comments on commit e39627c

Please sign in to comment.