예제 #1
0
 /**
  * Write the default style information for a RichText shape
  *
  * @param \PhpOffice\Common\XMLWriter $objWriter
  * @param \PhpOffice\PhpPowerpoint\Shape\RichText $shape
  */
 public function writeTxtStyle(XMLWriter $objWriter, RichText $shape)
 {
     // style:style
     $objWriter->startElement('style:style');
     $objWriter->writeAttribute('style:name', 'gr' . $this->shapeId);
     $objWriter->writeAttribute('style:family', 'graphic');
     $objWriter->writeAttribute('style:parent-style-name', 'standard');
     // style:graphic-properties
     $objWriter->startElement('style:graphic-properties');
     if ($shape->getShadow()->isVisible()) {
         $this->writeStylePartShadow($objWriter, $shape->getShadow());
     }
     if (is_bool($shape->hasAutoShrinkVertical())) {
         $objWriter->writeAttribute('draw:auto-grow-height', var_export($shape->hasAutoShrinkVertical(), true));
     }
     if (is_bool($shape->hasAutoShrinkHorizontal())) {
         $objWriter->writeAttribute('draw:auto-grow-width', var_export($shape->hasAutoShrinkHorizontal(), true));
     }
     // Fill
     switch ($shape->getFill()->getFillType()) {
         case Fill::FILL_GRADIENT_LINEAR:
         case Fill::FILL_GRADIENT_PATH:
             $objWriter->writeAttribute('draw:fill', 'gradient');
             $objWriter->writeAttribute('draw:fill-gradient-name', 'gradient_' . $shape->getFill()->getHashCode());
             break;
         case Fill::FILL_SOLID:
             $objWriter->writeAttribute('draw:fill', 'solid');
             $objWriter->writeAttribute('draw:fill-color', '#' . $shape->getFill()->getStartColor()->getRGB());
             break;
         case Fill::FILL_NONE:
         default:
             $objWriter->writeAttribute('draw:fill', 'none');
             $objWriter->writeAttribute('draw:fill-color', '#' . $shape->getFill()->getStartColor()->getRGB());
             break;
     }
     // Border
     if ($shape->getBorder()->getLineStyle() == Border::LINE_NONE) {
         $objWriter->writeAttribute('draw:stroke', 'none');
     } else {
         $objWriter->writeAttribute('svg:stroke-color', '#' . $shape->getBorder()->getColor()->getRGB());
         $objWriter->writeAttribute('svg:stroke-width', number_format(CommonDrawing::pointsToCentimeters($shape->getBorder()->getLineWidth()), 3, '.', '') . 'cm');
         switch ($shape->getBorder()->getDashStyle()) {
             case Border::DASH_SOLID:
                 $objWriter->writeAttribute('draw:stroke', 'solid');
                 break;
             case Border::DASH_DASH:
             case Border::DASH_DASHDOT:
             case Border::DASH_DOT:
             case Border::DASH_LARGEDASH:
             case Border::DASH_LARGEDASHDOT:
             case Border::DASH_LARGEDASHDOTDOT:
             case Border::DASH_SYSDASH:
             case Border::DASH_SYSDASHDOT:
             case Border::DASH_SYSDASHDOTDOT:
             case Border::DASH_SYSDOT:
                 $objWriter->writeAttribute('draw:stroke', 'dash');
                 $objWriter->writeAttribute('draw:stroke-dash', 'strokeDash_' . $shape->getBorder()->getDashStyle());
                 break;
             default:
                 $objWriter->writeAttribute('draw:stroke', 'none');
                 break;
         }
     }
     $objWriter->writeAttribute('fo:wrap-option', 'wrap');
     // > style:graphic-properties
     $objWriter->endElement();
     // > style:style
     $objWriter->endElement();
     $paragraphs = $shape->getParagraphs();
     $paragraphId = 0;
     foreach ($paragraphs as $paragraph) {
         ++$paragraphId;
         // Style des paragraphes
         if (!isset($this->arrStyleParagraph[$paragraph->getHashCode()])) {
             $this->arrStyleParagraph[$paragraph->getHashCode()] = $paragraph;
         }
         // Style des listes
         if (!isset($this->arrStyleBullet[$paragraph->getBulletStyle()->getHashCode()])) {
             $this->arrStyleBullet[$paragraph->getBulletStyle()->getHashCode()]['oStyle'] = $paragraph->getBulletStyle();
             $this->arrStyleBullet[$paragraph->getBulletStyle()->getHashCode()]['level'] = '';
         }
         if (strpos($this->arrStyleBullet[$paragraph->getBulletStyle()->getHashCode()]['level'], ';' . $paragraph->getAlignment()->getLevel()) === false) {
             $this->arrStyleBullet[$paragraph->getBulletStyle()->getHashCode()]['level'] .= ';' . $paragraph->getAlignment()->getLevel();
             $this->arrStyleBullet[$paragraph->getBulletStyle()->getHashCode()]['oAlign_' . $paragraph->getAlignment()->getLevel()] = $paragraph->getAlignment();
         }
         $richtexts = $paragraph->getRichTextElements();
         $richtextId = 0;
         foreach ($richtexts as $richtext) {
             ++$richtextId;
             // Not a line break
             if ($richtext instanceof Run) {
                 // Style des font text
                 if (!isset($this->arrStyleTextFont[$richtext->getFont()->getHashCode()])) {
                     $this->arrStyleTextFont[$richtext->getFont()->getHashCode()] = $richtext->getFont();
                 }
             }
         }
     }
 }
예제 #2
0
 /**
  */
 public function testPointsCentimeters()
 {
     $value = rand(1, 100);
     $this->assertEquals(0, Drawing::pointsToCentimeters());
     $this->assertEquals($value * 1.333333333 / Drawing::DPI_96 * 2.54, Drawing::pointsToCentimeters($value));
 }
예제 #3
0
 /**
  * @param Chart $chart
  * @param Chart\Series $series
  */
 private function writeSeriesStyle(Chart $chart, Chart\Series $series)
 {
     $chartType = $chart->getPlotArea()->getType();
     // style:style
     $this->xmlContent->startElement('style:style');
     $this->xmlContent->writeAttribute('style:name', 'styleSeries' . $this->numSeries);
     $this->xmlContent->writeAttribute('style:family', 'chart');
     // style:chart-properties
     $this->xmlContent->startElement('style:chart-properties');
     $this->xmlContent->writeAttribute('chart:data-label-number', 'value');
     $this->xmlContent->writeAttribute('chart:label-position', 'center');
     if ($chartType instanceof AbstractTypePie) {
         $this->xmlContent->writeAttribute('chart:pie-offset', $chartType->getExplosion());
     }
     if ($chartType instanceof Line || $chartType instanceof Scatter) {
         $oMarker = $series->getMarker();
         /**
          * @link : http://www.datypic.com/sc/odf/a-chart_symbol-type.html
          */
         $this->xmlContent->writeAttributeIf($oMarker->getSymbol() == Chart\Marker::SYMBOL_NONE, 'chart:symbol-type', 'none');
         /**
          * @link : http://www.datypic.com/sc/odf/a-chart_symbol-name.html
          */
         $this->xmlContent->writeAttributeIf($oMarker->getSymbol() != Chart\Marker::SYMBOL_NONE, 'chart:symbol-type', 'named-symbol');
         if ($oMarker->getSymbol() != Chart\Marker::SYMBOL_NONE) {
             switch ($oMarker->getSymbol()) {
                 case Chart\Marker::SYMBOL_DASH:
                     $symbolName = 'horizontal-bar';
                     break;
                 case Chart\Marker::SYMBOL_DOT:
                     $symbolName = 'circle';
                     break;
                 case Chart\Marker::SYMBOL_TRIANGLE:
                     $symbolName = 'arrow-up';
                     break;
                 default:
                     $symbolName = $oMarker->getSymbol();
                     break;
             }
             $this->xmlContent->writeAttribute('chart:symbol-name', $symbolName);
             $symbolSize = number_format(CommonDrawing::pointsToCentimeters($oMarker->getSize()), 2, '.', '');
             $this->xmlContent->writeAttribute('chart:symbol-width', $symbolSize . 'cm');
             $this->xmlContent->writeAttribute('chart:symbol-height', $symbolSize . 'cm');
         }
     }
     // > style:chart-properties
     $this->xmlContent->endElement();
     // style:graphic-properties
     $this->xmlContent->startElement('style:graphic-properties');
     if ($chartType instanceof Line || $chartType instanceof Scatter) {
         $outlineWidth = '';
         $outlineColor = '';
         $oOutline = $series->getOutline();
         if ($oOutline instanceof Outline) {
             $outlineWidth = $oOutline->getWidth();
             if (!empty($outlineWidth)) {
                 $outlineWidth = number_format(CommonDrawing::pointsToCentimeters($outlineWidth), 3, '.', '');
             }
             $outlineColor = $oOutline->getFill()->getStartColor()->getRGB();
         }
         if (empty($outlineWidth)) {
             $outlineWidth = '0.079';
         }
         if (empty($outlineColor)) {
             $outlineColor = '4a7ebb';
         }
         $this->xmlContent->writeAttribute('svg:stroke-width', $outlineWidth . 'cm');
         $this->xmlContent->writeAttribute('svg:stroke-color', '#' . $outlineColor);
     } else {
         $this->xmlContent->writeAttribute('draw:stroke', 'none');
         if (!$chartType instanceof Area) {
             $this->xmlContent->writeAttribute('draw:fill', $series->getFill()->getFillType());
         }
     }
     $this->xmlContent->writeAttribute('draw:fill-color', '#' . $series->getFill()->getStartColor()->getRGB());
     // > style:graphic-properties
     $this->xmlContent->endElement();
     // style:text-properties
     $this->xmlContent->startElement('style:text-properties');
     $this->xmlContent->writeAttribute('fo:color', '#' . $series->getFont()->getColor()->getRGB());
     $this->xmlContent->writeAttribute('fo:font-family', $series->getFont()->getName());
     $this->xmlContent->writeAttribute('fo:font-size', $series->getFont()->getSize() . 'pt');
     // > style:text-properties
     $this->xmlContent->endElement();
     // > style:style
     $this->xmlContent->endElement();
     foreach ($series->getDataPointFills() as $idx => $oFill) {
         // style:style
         $this->xmlContent->startElement('style:style');
         $this->xmlContent->writeAttribute('style:name', 'styleSeries' . $this->numSeries . '_' . $idx);
         $this->xmlContent->writeAttribute('style:family', 'chart');
         // style:graphic-properties
         $this->xmlContent->startElement('style:graphic-properties');
         $this->xmlContent->writeAttribute('draw:fill', $oFill->getFillType());
         $this->xmlContent->writeAttribute('draw:fill-color', '#' . $oFill->getStartColor()->getRGB());
         // > style:graphic-properties
         $this->xmlContent->endElement();
         // > style:style
         $this->xmlContent->endElement();
     }
 }
예제 #4
0
 public function testRichTextBorder()
 {
     $phpPresentation = new PhpPresentation();
     $oSlide = $phpPresentation->getActiveSlide();
     $oRichText1 = $oSlide->createRichTextShape();
     $element = '/office:document-content/office:automatic-styles/style:style[@style:name=\'gr1\']/style:graphic-properties';
     $oRichText1->getBorder()->setColor(new Color('FF4672A8'))->setDashStyle(Border::DASH_SOLID)->setLineStyle(Border::LINE_NONE);
     $pres = TestHelperDOCX::getDocument($phpPresentation, 'ODPresentation');
     $this->assertTrue($pres->elementExists($element, 'content.xml'));
     $this->assertFalse($pres->attributeElementExists($element, 'svg:stroke-color', 'content.xml'));
     $this->assertFalse($pres->attributeElementExists($element, 'svg:stroke-width', 'content.xml'));
     $this->assertTrue($pres->attributeElementExists($element, 'draw:stroke', 'content.xml'));
     $this->assertEquals('none', $pres->getElementAttribute($element, 'draw:stroke', 'content.xml'));
     $oRichText1->getBorder()->setColor(new Color('FF4672A8'))->setDashStyle(Border::DASH_SOLID)->setLineStyle(Border::LINE_SINGLE);
     $pres = TestHelperDOCX::getDocument($phpPresentation, 'ODPresentation');
     $this->assertTrue($pres->elementExists($element, 'content.xml'));
     $this->assertTrue($pres->attributeElementExists($element, 'svg:stroke-color', 'content.xml'));
     $this->assertEquals('#' . $oRichText1->getBorder()->getColor()->getRGB(), $pres->getElementAttribute($element, 'svg:stroke-color', 'content.xml'));
     $this->assertTrue($pres->attributeElementExists($element, 'svg:stroke-width', 'content.xml'));
     $this->assertStringEndsWith('cm', $pres->getElementAttribute($element, 'svg:stroke-width', 'content.xml'));
     $this->assertStringStartsWith((string) number_format(CommonDrawing::pointsToCentimeters($oRichText1->getBorder()->getLineWidth()), 3, '.', ''), $pres->getElementAttribute($element, 'svg:stroke-width', 'content.xml'));
     $this->assertTrue($pres->attributeElementExists($element, 'draw:stroke', 'content.xml'));
     $this->assertEquals('solid', $pres->getElementAttribute($element, 'draw:stroke', 'content.xml'));
     $this->assertFalse($pres->attributeElementExists($element, 'draw:stroke-dash', 'content.xml'));
     $oRichText1->getBorder()->setColor(new Color('FF4672A8'))->setDashStyle(Border::DASH_DASH);
     $pres = TestHelperDOCX::getDocument($phpPresentation, 'ODPresentation');
     $element = '/office:document-content/office:automatic-styles/style:style[@style:name=\'gr1\']/style:graphic-properties';
     $this->assertEquals('dash', $pres->getElementAttribute($element, 'draw:stroke', 'content.xml'));
     $this->assertTrue($pres->attributeElementExists($element, 'draw:stroke-dash', 'content.xml'));
     $this->assertStringStartsWith('strokeDash_', $pres->getElementAttribute($element, 'draw:stroke-dash', 'content.xml'));
     $this->assertStringEndsWith($oRichText1->getBorder()->getDashStyle(), $pres->getElementAttribute($element, 'draw:stroke-dash', 'content.xml'));
 }
예제 #5
0
 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'));
 }