예제 #1
0
 /**
  */
 public function testPixelsPoints()
 {
     $value = rand(1, 100);
     $this->assertEquals(0, Drawing::pixelsToPoints());
     $this->assertEquals($value * 0.6777777699999999, Drawing::pixelsToPoints($value));
     $this->assertEquals(0, Drawing::pointsToPixels());
     $this->assertEquals($value * 1.333333333, Drawing::pointsToPixels($value));
 }
예제 #2
0
 /**
  * Write the default style information for a Table shape
  *
  * @param XMLWriter $objWriter
  * @param Table $shape
  */
 public function writeTableStyle(XMLWriter $objWriter, Table $shape)
 {
     foreach ($shape->getRows() as $keyRow => $shapeRow) {
         // style:style
         $objWriter->startElement('style:style');
         $objWriter->writeAttribute('style:name', 'gr' . $this->shapeId . 'r' . $keyRow);
         $objWriter->writeAttribute('style:family', 'table-row');
         // style:table-row-properties
         $objWriter->startElement('style:table-row-properties');
         $objWriter->writeAttribute('style:row-height', String::numberFormat(CommonDrawing::pixelsToCentimeters(CommonDrawing::pointsToPixels($shapeRow->getHeight())), 3) . 'cm');
         $objWriter->endElement();
         $objWriter->endElement();
         foreach ($shapeRow->getCells() as $keyCell => $shapeCell) {
             // style:style
             $objWriter->startElement('style:style');
             $objWriter->writeAttribute('style:name', 'gr' . $this->shapeId . 'r' . $keyRow . 'c' . $keyCell);
             $objWriter->writeAttribute('style:family', 'table-cell');
             // style:graphic-properties
             $objWriter->startElement('style:graphic-properties');
             if ($shapeCell->getFill()->getFillType() == Fill::FILL_SOLID) {
                 $objWriter->writeAttribute('draw:fill', 'solid');
                 $objWriter->writeAttribute('draw:fill-color', '#' . $shapeCell->getFill()->getStartColor()->getRGB());
             }
             if ($shapeCell->getFill()->getFillType() == Fill::FILL_GRADIENT_LINEAR) {
                 $objWriter->writeAttribute('draw:fill', 'gradient');
                 $objWriter->writeAttribute('draw:fill-gradient-name', 'gradient_' . $shapeCell->getFill()->getHashCode());
             }
             $objWriter->endElement();
             // <style:graphic-properties
             // style:paragraph-properties
             $objWriter->startElement('style:paragraph-properties');
             if ($shapeCell->getBorders()->getBottom()->getHashCode() == $shapeCell->getBorders()->getTop()->getHashCode() && $shapeCell->getBorders()->getBottom()->getHashCode() == $shapeCell->getBorders()->getLeft()->getHashCode() && $shapeCell->getBorders()->getBottom()->getHashCode() == $shapeCell->getBorders()->getRight()->getHashCode()) {
                 $lineStyle = 'none';
                 $lineWidth = String::numberFormat($shapeCell->getBorders()->getBottom()->getLineWidth() / 1.75, 2);
                 $lineColor = $shapeCell->getBorders()->getBottom()->getColor()->getRGB();
                 switch ($shapeCell->getBorders()->getBottom()->getLineStyle()) {
                     case Border::LINE_SINGLE:
                         $lineStyle = 'solid';
                 }
                 $objWriter->writeAttribute('fo:border', $lineWidth . 'pt ' . $lineStyle . ' #' . $lineColor);
             } else {
                 $lineStyle = 'none';
                 $lineWidth = String::numberFormat($shapeCell->getBorders()->getBottom()->getLineWidth() / 1.75, 2);
                 $lineColor = $shapeCell->getBorders()->getBottom()->getColor()->getRGB();
                 switch ($shapeCell->getBorders()->getBottom()->getLineStyle()) {
                     case Border::LINE_SINGLE:
                         $lineStyle = 'solid';
                 }
                 $objWriter->writeAttribute('fo:border-bottom', $lineWidth . 'pt ' . $lineStyle . ' #' . $lineColor);
                 // TOP
                 $lineStyle = 'none';
                 $lineWidth = String::numberFormat($shapeCell->getBorders()->getTop()->getLineWidth() / 1.75, 2);
                 $lineColor = $shapeCell->getBorders()->getTop()->getColor()->getRGB();
                 switch ($shapeCell->getBorders()->getTop()->getLineStyle()) {
                     case Border::LINE_SINGLE:
                         $lineStyle = 'solid';
                 }
                 $objWriter->writeAttribute('fo:border-top', $lineWidth . 'pt ' . $lineStyle . ' #' . $lineColor);
                 // RIGHT
                 $lineStyle = 'none';
                 $lineWidth = String::numberFormat($shapeCell->getBorders()->getRight()->getLineWidth() / 1.75, 2);
                 $lineColor = $shapeCell->getBorders()->getRight()->getColor()->getRGB();
                 switch ($shapeCell->getBorders()->getRight()->getLineStyle()) {
                     case Border::LINE_SINGLE:
                         $lineStyle = 'solid';
                 }
                 $objWriter->writeAttribute('fo:border-right', $lineWidth . 'pt ' . $lineStyle . ' #' . $lineColor);
                 // LEFT
                 $lineStyle = 'none';
                 $lineWidth = String::numberFormat($shapeCell->getBorders()->getLeft()->getLineWidth() / 1.75, 2);
                 $lineColor = $shapeCell->getBorders()->getLeft()->getColor()->getRGB();
                 switch ($shapeCell->getBorders()->getLeft()->getLineStyle()) {
                     case Border::LINE_SINGLE:
                         $lineStyle = 'solid';
                 }
                 $objWriter->writeAttribute('fo:border-left', $lineWidth . 'pt ' . $lineStyle . ' #' . $lineColor);
             }
             $objWriter->endElement();
             $objWriter->endElement();
             foreach ($shapeCell->getParagraphs() as $shapeParagraph) {
                 foreach ($shapeParagraph->getRichTextElements() as $shapeRichText) {
                     if ($shapeRichText instanceof Run) {
                         // Style des font text
                         if (!isset($this->arrStyleTextFont[$shapeRichText->getFont()->getHashCode()])) {
                             $this->arrStyleTextFont[$shapeRichText->getFont()->getHashCode()] = $shapeRichText->getFont();
                         }
                     }
                 }
             }
         }
     }
 }
예제 #3
0
 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();
 }