Пример #1
0
 /**
  * Register
  */
 public function testConstruct()
 {
     $object = new RichText();
     $this->assertNull($object->getSlide());
     $this->assertEquals(0, $object->getOffsetX());
     $this->assertEquals(0, $object->getOffsetY());
     $this->assertEquals(0, $object->getHeight());
     $this->assertEquals(0, $object->getRotation());
     $this->assertEquals(0, $object->getWidth());
     $this->assertInstanceOf('PhpOffice\\PhpPowerpoint\\Style\\Border', $object->getBorder());
     $this->assertEquals(Border::LINE_NONE, $object->getBorder()->getLineStyle());
     $this->assertInstanceOf('PhpOffice\\PhpPowerpoint\\Style\\Fill', $object->getFill());
     $this->assertInstanceOf('PhpOffice\\PhpPowerpoint\\Style\\Shadow', $object->getShadow());
 }
Пример #2
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();
                 }
             }
         }
     }
 }
Пример #3
0
 /**
  * Write the default style information for a RichText shape
  *
  * @param XMLWriter $objWriter
  * @param RichText $shape
  */
 public function writeRichTextStyle(XMLWriter $objWriter, RichText $shape)
 {
     if ($shape->getFill()->getFillType() == Fill::FILL_GRADIENT_LINEAR || $shape->getFill()->getFillType() == Fill::FILL_GRADIENT_PATH) {
         if (!in_array($shape->getFill()->getHashCode(), $this->arrayGradient)) {
             $this->writeGradientFill($objWriter, $shape->getFill());
         }
     }
     if ($shape->getBorder()->getDashStyle() != Border::DASH_SOLID) {
         if (!in_array($shape->getBorder()->getDashStyle(), $this->arrayStrokeDash)) {
             $objWriter->startElement('draw:stroke-dash');
             $objWriter->writeAttribute('draw:name', 'strokeDash_' . $shape->getBorder()->getDashStyle());
             $objWriter->writeAttribute('draw:style', 'rect');
             switch ($shape->getBorder()->getDashStyle()) {
                 case Border::DASH_DASH:
                     $objWriter->writeAttribute('draw:distance', '0.105cm');
                     $objWriter->writeAttribute('draw:dots2', '1');
                     $objWriter->writeAttribute('draw:dots2-length', '0.14cm');
                     break;
                 case Border::DASH_DASHDOT:
                     $objWriter->writeAttribute('draw:distance', '0.105cm');
                     $objWriter->writeAttribute('draw:dots1', '1');
                     $objWriter->writeAttribute('draw:dots1-length', '0.035cm');
                     $objWriter->writeAttribute('draw:dots2', '1');
                     $objWriter->writeAttribute('draw:dots2-length', '0.14cm');
                     break;
                 case Border::DASH_DOT:
                     $objWriter->writeAttribute('draw:distance', '0.105cm');
                     $objWriter->writeAttribute('draw:dots1', '1');
                     $objWriter->writeAttribute('draw:dots1-length', '0.035cm');
                     break;
                 case Border::DASH_LARGEDASH:
                     $objWriter->writeAttribute('draw:distance', '0.105cm');
                     $objWriter->writeAttribute('draw:dots2', '1');
                     $objWriter->writeAttribute('draw:dots2-length', '0.28cm');
                     break;
                 case Border::DASH_LARGEDASHDOT:
                     $objWriter->writeAttribute('draw:distance', '0.105cm');
                     $objWriter->writeAttribute('draw:dots1', '1');
                     $objWriter->writeAttribute('draw:dots1-length', '0.035cm');
                     $objWriter->writeAttribute('draw:dots2', '1');
                     $objWriter->writeAttribute('draw:dots2-length', '0.28cm');
                     break;
                 case Border::DASH_LARGEDASHDOTDOT:
                     $objWriter->writeAttribute('draw:distance', '0.105cm');
                     $objWriter->writeAttribute('draw:dots1', '2');
                     $objWriter->writeAttribute('draw:dots1-length', '0.035cm');
                     $objWriter->writeAttribute('draw:dots2', '1');
                     $objWriter->writeAttribute('draw:dots2-length', '0.28cm');
                     break;
                 case Border::DASH_SYSDASH:
                     $objWriter->writeAttribute('draw:distance', '0.035cm');
                     $objWriter->writeAttribute('draw:dots2', '1');
                     $objWriter->writeAttribute('draw:dots2-length', '0.105cm');
                     break;
                 case Border::DASH_SYSDASHDOT:
                     $objWriter->writeAttribute('draw:distance', '0.035cm');
                     $objWriter->writeAttribute('draw:dots1', '1');
                     $objWriter->writeAttribute('draw:dots1-length', '0.035cm');
                     $objWriter->writeAttribute('draw:dots2', '1');
                     $objWriter->writeAttribute('draw:dots2-length', '0.105cm');
                     break;
                 case Border::DASH_SYSDASHDOTDOT:
                     $objWriter->writeAttribute('draw:distance', '0.035cm');
                     $objWriter->writeAttribute('draw:dots1', '2');
                     $objWriter->writeAttribute('draw:dots1-length', '0.035cm');
                     $objWriter->writeAttribute('draw:dots2', '1');
                     $objWriter->writeAttribute('draw:dots2-length', '0.105cm');
                     break;
                 case Border::DASH_SYSDOT:
                     $objWriter->writeAttribute('draw:distance', '0.035cm');
                     $objWriter->writeAttribute('draw:dots1', '1');
                     $objWriter->writeAttribute('draw:dots1-length', '0.035cm');
                     break;
             }
             $objWriter->endElement();
             $this->arrayStrokeDash[] = $shape->getBorder()->getDashStyle();
         }
     }
 }