/** * Register */ public function testConstruct() { $object = new RichText(); $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\\PhpPresentation\\Style\\Border', $object->getBorder()); $this->assertEquals(Border::LINE_NONE, $object->getBorder()->getLineStyle()); $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Style\\Fill', $object->getFill()); $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Style\\Shadow', $object->getShadow()); }
/** * Write the default style information for a RichText shape * * @param XMLWriter $objWriter * @param RichText $shape */ protected function writeRichTextStyle(XMLWriter $objWriter, RichText $shape) { $oFill = $shape->getFill(); if ($oFill->getFillType() == Fill::FILL_GRADIENT_LINEAR || $oFill->getFillType() == Fill::FILL_GRADIENT_PATH) { if (!in_array($oFill->getHashCode(), $this->arrayGradient)) { $this->writeGradientFill($objWriter, $oFill); } } $oBorder = $shape->getBorder(); if ($oBorder->getDashStyle() != Border::DASH_SOLID) { if (!in_array($oBorder->getDashStyle(), $this->arrayStrokeDash)) { $objWriter->startElement('draw:stroke-dash'); $objWriter->writeAttribute('draw:name', 'strokeDash_' . $oBorder->getDashStyle()); $objWriter->writeAttribute('draw:style', 'rect'); switch ($oBorder->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[] = $oBorder->getDashStyle(); } } }
/** * Write the default style information for a RichText shape * * @param \PhpOffice\Common\XMLWriter $objWriter * @param \PhpOffice\PhpPresentation\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(); } } } } }