/** * 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 testGetSetVAutoShrink() { $object = new RichText(); $this->assertInstanceOf('PhpOffice\\PhpPowerpoint\\Shape\\RichText', $object->setAutoShrinkVertical()); $this->assertNull($object->hasAutoShrinkVertical()); $this->assertInstanceOf('PhpOffice\\PhpPowerpoint\\Shape\\RichText', $object->setAutoShrinkVertical(2)); $this->assertNull($object->hasAutoShrinkVertical()); $this->assertInstanceOf('PhpOffice\\PhpPowerpoint\\Shape\\RichText', $object->setAutoShrinkVertical(true)); $this->assertTrue($object->hasAutoShrinkVertical()); $this->assertInstanceOf('PhpOffice\\PhpPowerpoint\\Shape\\RichText', $object->setAutoShrinkVertical(false)); $this->assertFalse($object->hasAutoShrinkVertical()); }