Example #1
0
 /**
  * Test get/set width
  */
 public function testSetGetWidth()
 {
     $object = new Outline();
     $this->assertNull($object->getWidth());
     $value = rand(1, 100);
     $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Style\\Outline', $object->setWidth($value));
     $this->assertEquals($value, $object->getWidth());
     $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Style\\Outline', $object->setWidth(1.5));
     $this->assertEquals(1, $object->getWidth());
 }
 public function testTypeScatterSeriesOutline()
 {
     $expectedWidth = rand(1, 100);
     $expectedWidthEmu = Drawing::pixelsToEmu(Drawing::pointsToPixels($expectedWidth));
     $expectedElement = '/c:chartSpace/c:chart/c:plotArea/c:scatterChart/c:ser/c:spPr/a:ln';
     $oOutline = new Outline();
     // Define the color
     $oOutline->getFill()->setFillType(Fill::FILL_SOLID);
     $oOutline->getFill()->setStartColor(new Color(Color::COLOR_YELLOW));
     // Define the width (in points)
     $oOutline->setWidth($expectedWidth);
     $oSlide = $this->oPresentation->getActiveSlide();
     $oShape = $oSlide->createChartShape();
     $oShape->setResizeProportional(false)->setHeight(550)->setWidth(700)->setOffsetX(120)->setOffsetY(80);
     $oScatter = new Scatter();
     $oSeries = new Series('Downloads', $this->seriesData);
     $oScatter->addSeries($oSeries);
     $oShape->getPlotArea()->setType($oScatter);
     $oXMLDoc = TestHelperDOCX::getDocument($this->oPresentation, 'PowerPoint2007');
     $this->assertTrue($oXMLDoc->fileExists('ppt/charts/' . $oShape->getIndexedFilename()));
     $this->assertFalse($oXMLDoc->elementExists($expectedElement, 'ppt/charts/' . $oShape->getIndexedFilename()));
     $oSeries->setOutline($oOutline);
     $oScatter->setSeries(array($oSeries));
     $oXMLDoc = TestHelperDOCX::getDocument($this->oPresentation, 'PowerPoint2007');
     $this->assertTrue($oXMLDoc->fileExists('ppt/charts/' . $oShape->getIndexedFilename()));
     $this->assertTrue($oXMLDoc->elementExists($expectedElement, 'ppt/charts/' . $oShape->getIndexedFilename()));
     $this->assertEquals($expectedWidthEmu, $oXMLDoc->getElementAttribute($expectedElement, 'w', 'ppt/charts/' . $oShape->getIndexedFilename()));
     $this->assertTrue($oXMLDoc->elementExists($expectedElement . '/a:solidFill', 'ppt/charts/' . $oShape->getIndexedFilename()));
 }
 /**
  * Write Outline
  * @param XMLWriter $objWriter
  * @param Outline $oOutline
  */
 protected function writeOutline(XMLWriter $objWriter, $oOutline)
 {
     if (!$oOutline instanceof Outline) {
         return;
     }
     // Width : pts
     $width = $oOutline->getWidth();
     // Width : pts => px
     $width = CommonDrawing::pointsToPixels($width);
     // Width : px => emu
     $width = CommonDrawing::pixelsToEmu($width);
     // a:ln
     $objWriter->startElement('a:ln');
     $objWriter->writeAttribute('w', $width);
     // Fill
     $this->writeFill($objWriter, $oOutline->getFill());
     // > a:ln
     $objWriter->endElement();
 }
 public function testTypeScatterSeriesOutline()
 {
     $expectedWidth = rand(1, 100);
     $expectedWidthCm = number_format(CommonDrawing::pointsToCentimeters($expectedWidth), 3, '.', '') . 'cm';
     $expectedElement = '/office:document-content/office:automatic-styles/style:style[@style:name=\'styleSeries0\'][@style:family=\'chart\']/style:graphic-properties';
     $oColor = new Color(Color::COLOR_YELLOW);
     $oOutline = new Outline();
     // Define the color
     $oOutline->getFill()->setFillType(Fill::FILL_SOLID);
     $oOutline->getFill()->setStartColor($oColor);
     // Define the width (in points)
     $oOutline->setWidth($expectedWidth);
     $oPhpPresentation = new PhpPresentation();
     $oSlide = $oPhpPresentation->getActiveSlide();
     $oShape = $oSlide->createChartShape();
     $oShape->setResizeProportional(false)->setHeight(550)->setWidth(700)->setOffsetX(120)->setOffsetY(80);
     $oScatter = new Scatter();
     $oSeries = new Series('Downloads', array('A' => 1, 'B' => 2, 'C' => 4, 'D' => 3, 'E' => 2));
     $oScatter->addSeries($oSeries);
     $oShape->getPlotArea()->setType($oScatter);
     $oXMLDoc = TestHelperDOCX::getDocument($oPhpPresentation, 'ODPresentation');
     $this->assertTrue($oXMLDoc->fileExists('Object 1/content.xml'));
     $this->assertTrue($oXMLDoc->elementExists($expectedElement, 'Object 1/content.xml'));
     $this->assertTrue($oXMLDoc->attributeElementExists($expectedElement, 'svg:stroke-width', 'Object 1/content.xml'));
     $this->assertEquals('0.079cm', $oXMLDoc->getElementAttribute($expectedElement, 'svg:stroke-width', 'Object 1/content.xml'));
     $this->assertTrue($oXMLDoc->attributeElementExists($expectedElement, 'svg:stroke-color', 'Object 1/content.xml'));
     $this->assertEquals('#4a7ebb', $oXMLDoc->getElementAttribute($expectedElement, 'svg:stroke-color', 'Object 1/content.xml'));
     $oSeries->setOutline($oOutline);
     $oScatter->setSeries(array($oSeries));
     $oXMLDoc = TestHelperDOCX::getDocument($oPhpPresentation, 'ODPresentation');
     $this->assertTrue($oXMLDoc->fileExists('Object 1/content.xml'));
     $this->assertTrue($oXMLDoc->elementExists($expectedElement, 'Object 1/content.xml'));
     $this->assertTrue($oXMLDoc->attributeElementExists($expectedElement, 'svg:stroke-width', 'Object 1/content.xml'));
     $this->assertEquals($expectedWidthCm, $oXMLDoc->getElementAttribute($expectedElement, 'svg:stroke-width', 'Object 1/content.xml'));
     $this->assertTrue($oXMLDoc->attributeElementExists($expectedElement, 'svg:stroke-color', 'Object 1/content.xml'));
     $this->assertEquals('#' . $oColor->getRGB(), $oXMLDoc->getElementAttribute($expectedElement, 'svg:stroke-color', 'Object 1/content.xml'));
 }