public function testFill()
 {
     $object = new RichText();
     $this->assertInstanceOf('PhpOffice\\PhpPowerpoint\\AbstractShape', $object->setFill());
     $this->assertNull($object->getFill());
     $this->assertInstanceOf('PhpOffice\\PhpPowerpoint\\AbstractShape', $object->setFill(new Fill()));
     $this->assertInstanceOf('PhpOffice\\PhpPowerpoint\\Style\\Fill', $object->getFill());
 }
 /**
  * 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();
                 }
             }
         }
     }
 }
 public function testHashCode()
 {
     $object = new RichText();
     $hash = $object->getActiveParagraph()->getHashCode();
     $hash .= RichText::WRAP_SQUARE . RichText::AUTOFIT_DEFAULT . RichText::OVERFLOW_OVERFLOW . RichText::OVERFLOW_OVERFLOW . '0014.89.69.64.8';
     $hash .= md5('00000' . $object->getFill()->getHashCode() . $object->getShadow()->getHashCode() . '' . get_parent_class($object));
     $hash .= get_class($object);
     $this->assertEquals(md5($hash), $object->getHashCode());
 }
Exemple #4
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();
         }
     }
 }