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

Implement alpha channel to Fills #203

Merged
merged 2 commits into from
Apr 1, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions src/PhpPresentation/Style/Color.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,21 @@ public function setARGB($pValue = self::COLOR_BLACK)
return $this;
}

/**
* Get the alpha % of the ARGB
* Will return 100 if no ARGB
* @return integer
*/
public function getAlpha()
{
$alpha = 100;
if (strlen($this->argb) >= 6) {
$dec = hexdec(substr($this->argb, 0, 2));
$alpha = number_format(( $dec/255 ) * 100, 2);
}
return $alpha;
}

/**
* Get RGB
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,12 @@ protected function writeSolidFill(XMLWriter $objWriter, Fill $pFill)
// srgbClr
$objWriter->startElement('a:srgbClr');
$objWriter->writeAttribute('val', $pFill->getStartColor()->getRGB());

// a:alpha
$objWriter->startElement('a:alpha');
$objWriter->writeAttribute('val', $pFill->getStartColor()->getAlpha() * 1000);
$objWriter->endElement();

$objWriter->endElement();

$objWriter->endElement();
Expand All @@ -181,6 +187,12 @@ protected function writeGradientFill(XMLWriter $objWriter, Fill $pFill)
// srgbClr
$objWriter->startElement('a:srgbClr');
$objWriter->writeAttribute('val', $pFill->getStartColor()->getRGB());

// a:alpha
$objWriter->startElement('a:alpha');
$objWriter->writeAttribute('val', $pFill->getStartColor()->getAlpha() * 1000);
$objWriter->endElement();

$objWriter->endElement();

$objWriter->endElement();
Expand All @@ -192,6 +204,12 @@ protected function writeGradientFill(XMLWriter $objWriter, Fill $pFill)
// srgbClr
$objWriter->startElement('a:srgbClr');
$objWriter->writeAttribute('val', $pFill->getEndColor()->getRGB());

// a:alpha
$objWriter->startElement('a:alpha');
$objWriter->writeAttribute('val', $pFill->getEndColor()->getAlpha() * 1000);
$objWriter->endElement();

$objWriter->endElement();

$objWriter->endElement();
Expand Down Expand Up @@ -225,6 +243,12 @@ protected function writePatternFill(XMLWriter $objWriter, Fill $pFill)
// srgbClr
$objWriter->startElement('a:srgbClr');
$objWriter->writeAttribute('val', $pFill->getStartColor()->getRGB());

// a:alpha
$objWriter->startElement('a:alpha');
$objWriter->writeAttribute('val', $pFill->getStartColor()->getAlpha() * 1000);
$objWriter->endElement();

$objWriter->endElement();

$objWriter->endElement();
Expand All @@ -235,6 +259,12 @@ protected function writePatternFill(XMLWriter $objWriter, Fill $pFill)
// srgbClr
$objWriter->startElement('a:srgbClr');
$objWriter->writeAttribute('val', $pFill->getEndColor()->getRGB());

// a:alpha
$objWriter->startElement('a:alpha');
$objWriter->writeAttribute('val', $pFill->getEndColor()->getAlpha() * 1000);
$objWriter->endElement();

$objWriter->endElement();

$objWriter->endElement();
Expand Down