/** * Get paragraph style */ public function testParagraph() { $oText = new Text('text', 'fontStyle', 'paragraphStyle'); $this->assertEquals($oText->getParagraphStyle(), 'paragraphStyle'); $oText->setParagraphStyle(array('align' => 'center', 'spaceAfter' => 100)); $this->assertInstanceOf('PhpOffice\\PhpWord\\Style\\Paragraph', $oText->getParagraphStyle()); }
/** * Get paragraph style */ public function testParagraph() { $oText = new Text(htmlspecialchars('text', ENT_COMPAT, 'UTF-8'), 'fontStyle', 'paragraphStyle'); $this->assertEquals('paragraphStyle', $oText->getParagraphStyle()); $oText->setParagraphStyle(array('alignment' => Jc::CENTER, 'spaceAfter' => 100)); $this->assertInstanceOf('PhpOffice\\PhpWord\\Style\\Paragraph', $oText->getParagraphStyle()); }
/** * Add text element * * @param string $text * @param mixed $fontStyle * @param mixed $paragraphStyle * @return Text */ public function addText($text, $fontStyle = null, $paragraphStyle = null) { $this->checkValidity('text'); // Reset paragraph style for footnote and textrun. They have their own if (in_array($this->container, array('textrun', 'footnote', 'endnote'))) { $paragraphStyle = null; } $text = String::toUTF8($text); $textObject = new Text($text, $fontStyle, $paragraphStyle); $textObject->setDocPart($this->getDocPart(), $this->getDocPartId()); $this->addElement($textObject); return $textObject; }
/** * Create new instance * * @param string $name * @param string $text * @param mixed $fontStyle * @param mixed $paragraphStyle * @return self */ public function __construct($name = null, $text = null, $fontStyle = null, $paragraphStyle = null) { $this->setName($name); parent::__construct($text, $fontStyle, $paragraphStyle); }
/** * Get text * * @return string * @since 0.11.0 */ public function getText() { return $this->textObject->getText(); }
/** * Get style of individual element * * @param \PhpOffice\PhpWord\Element\Text $element * @param int $paragraphStyleCount * @param int $fontStyleCount */ private function getElementStyle(&$element, &$paragraphStyleCount, &$fontStyleCount) { $fontStyle = $element->getFontStyle(); $paragraphStyle = $element->getParagraphStyle(); $phpWord = $this->getParentWriter()->getPhpWord(); // Font if ($fontStyle instanceof Font) { $fontStyleCount++; $style = $phpWord->addFontStyle("T{$fontStyleCount}", $fontStyle); $style->setAuto(); $element->setFontStyle("T{$fontStyleCount}"); // Paragraph } elseif ($paragraphStyle instanceof Paragraph) { $paragraphStyleCount++; $style = $phpWord->addParagraphStyle("P{$paragraphStyleCount}", array()); $style->setAuto(); $element->setParagraphStyle("P{$paragraphStyleCount}"); } }