Esempio n. 1
0
 /**
  */
 public function testDegreesAngle()
 {
     $value = rand(1, 100);
     $this->assertEquals(0, Drawing::degreesToAngle());
     $this->assertEquals((int) round($value * 60000), Drawing::degreesToAngle($value));
     $this->assertEquals(0, Drawing::angleToDegrees());
     $this->assertEquals(round($value / 60000), Drawing::angleToDegrees($value));
 }
Esempio n. 2
0
 /**
  * Write chart to XML format
  *
  * @param  \PhpOffice\PhpPowerpoint\Shape\Chart $chart
  * @return string                    XML Output
  * @throws \Exception
  */
 public function writeChart(ShapeChart $chart = null)
 {
     // Check slide
     if (is_null($chart)) {
         throw new \Exception("Invalid \\PhpOffice\\PhpPowerpoint\\Shape\\Chart object passed.");
     }
     // Create XML writer
     $objWriter = $this->getXMLWriter();
     // XML header
     $objWriter->startDocument('1.0', 'UTF-8', 'yes');
     // c:chartSpace
     $objWriter->startElement('c:chartSpace');
     $objWriter->writeAttribute('xmlns:c', 'http://schemas.openxmlformats.org/drawingml/2006/chart');
     $objWriter->writeAttribute('xmlns:a', 'http://schemas.openxmlformats.org/drawingml/2006/main');
     $objWriter->writeAttribute('xmlns:r', 'http://schemas.openxmlformats.org/officeDocument/2006/relationships');
     // c:date1904
     $objWriter->startElement('c:date1904');
     $objWriter->writeAttribute('val', '1');
     $objWriter->endElement();
     // c:lang
     $objWriter->startElement('c:lang');
     $objWriter->writeAttribute('val', 'en-US');
     $objWriter->endElement();
     // c:chart
     $objWriter->startElement('c:chart');
     // Title?
     if ($chart->getTitle()->isVisible()) {
         // Write title
         $this->writeTitle($objWriter, $chart->getTitle());
     }
     // c:autoTitleDeleted
     $objWriter->startElement('c:autoTitleDeleted');
     $objWriter->writeAttribute('val', '0');
     $objWriter->endElement();
     // c:view3D
     $objWriter->startElement('c:view3D');
     // c:rotX
     $objWriter->startElement('c:rotX');
     $objWriter->writeAttribute('val', $chart->getView3D()->getRotationX());
     $objWriter->endElement();
     // c:hPercent
     $objWriter->startElement('c:hPercent');
     $objWriter->writeAttribute('val', $chart->getView3D()->getHeightPercent());
     $objWriter->endElement();
     // c:rotY
     $objWriter->startElement('c:rotY');
     $objWriter->writeAttribute('val', $chart->getView3D()->getRotationY());
     $objWriter->endElement();
     // c:depthPercent
     $objWriter->startElement('c:depthPercent');
     $objWriter->writeAttribute('val', $chart->getView3D()->getDepthPercent());
     $objWriter->endElement();
     // c:rAngAx
     $objWriter->startElement('c:rAngAx');
     $objWriter->writeAttribute('val', $chart->getView3D()->hasRightAngleAxes() ? '1' : '0');
     $objWriter->endElement();
     // c:perspective
     $objWriter->startElement('c:perspective');
     $objWriter->writeAttribute('val', $chart->getView3D()->getPerspective());
     $objWriter->endElement();
     $objWriter->endElement();
     // Write plot area
     $this->writePlotArea($objWriter, $chart->getPlotArea(), $chart);
     // Legend?
     if ($chart->getLegend()->isVisible()) {
         // Write legend
         $this->writeLegend($objWriter, $chart->getLegend());
     }
     // c:plotVisOnly
     $objWriter->startElement('c:plotVisOnly');
     $objWriter->writeAttribute('val', '1');
     $objWriter->endElement();
     $objWriter->endElement();
     // c:spPr
     $objWriter->startElement('c:spPr');
     // Fill
     $this->writeFill($objWriter, $chart->getFill());
     // Border
     if ($chart->getBorder()->getLineStyle() != Border::LINE_NONE) {
         $this->writeBorder($objWriter, $chart->getBorder(), '');
     }
     // Shadow
     if ($chart->getShadow()->isVisible()) {
         // a:effectLst
         $objWriter->startElement('a:effectLst');
         // a:outerShdw
         $objWriter->startElement('a:outerShdw');
         $objWriter->writeAttribute('blurRad', SharedDrawing::pixelsToEmu($chart->getShadow()->getBlurRadius()));
         $objWriter->writeAttribute('dist', SharedDrawing::pixelsToEmu($chart->getShadow()->getDistance()));
         $objWriter->writeAttribute('dir', SharedDrawing::degreesToAngle($chart->getShadow()->getDirection()));
         $objWriter->writeAttribute('algn', $chart->getShadow()->getAlignment());
         $objWriter->writeAttribute('rotWithShape', '0');
         // a:srgbClr
         $objWriter->startElement('a:srgbClr');
         $objWriter->writeAttribute('val', $chart->getShadow()->getColor()->getRGB());
         // a:alpha
         $objWriter->startElement('a:alpha');
         $objWriter->writeAttribute('val', $chart->getShadow()->getAlpha() * 1000);
         $objWriter->endElement();
         $objWriter->endElement();
         $objWriter->endElement();
         $objWriter->endElement();
     }
     $objWriter->endElement();
     // External data?
     if ($chart->hasIncludedSpreadsheet()) {
         // c:externalData
         $objWriter->startElement('c:externalData');
         $objWriter->writeAttribute('r:id', 'rId1');
         // c:autoUpdate
         $objWriter->startElement('c:autoUpdate');
         $objWriter->writeAttribute('val', '0');
         $objWriter->endElement();
         $objWriter->endElement();
     }
     $objWriter->endElement();
     // Return
     return $objWriter->getData();
 }
Esempio n. 3
0
 /**
  * Write Gradient Fill
  *
  * @param  \PhpOffice\PhpPowerpoint\Shared\XMLWriter $objWriter XML Writer
  * @param  \PhpOffice\PhpPowerpoint\Style\Fill       $pFill     Fill style
  * @throws \Exception
  */
 protected function writeGradientFill(XMLWriter $objWriter, Fill $pFill)
 {
     // a:gradFill
     $objWriter->startElement('a:gradFill');
     // a:gsLst
     $objWriter->startElement('a:gsLst');
     // a:gs
     $objWriter->startElement('a:gs');
     $objWriter->writeAttribute('pos', '0');
     // srgbClr
     $objWriter->startElement('a:srgbClr');
     $objWriter->writeAttribute('val', $pFill->getStartColor()->getRGB());
     $objWriter->endElement();
     $objWriter->endElement();
     // a:gs
     $objWriter->startElement('a:gs');
     $objWriter->writeAttribute('pos', '100000');
     // srgbClr
     $objWriter->startElement('a:srgbClr');
     $objWriter->writeAttribute('val', $pFill->getEndColor()->getRGB());
     $objWriter->endElement();
     $objWriter->endElement();
     $objWriter->endElement();
     // a:lin
     $objWriter->startElement('a:lin');
     $objWriter->writeAttribute('ang', SharedDrawing::degreesToAngle($pFill->getRotation()));
     $objWriter->writeAttribute('scaled', '0');
     $objWriter->endElement();
     $objWriter->endElement();
 }