richTextElements = array(); $this->alignment = new Alignment(); $this->font = new Font(); $this->bulletStyle = new Bullet(); } /** * Get alignment * * @return \PhpOffice\PhpPresentation\Style\Alignment */ public function getAlignment() { return $this->alignment; } /** * Set alignment * * @param \PhpOffice\PhpPresentation\Style\Alignment $alignment * @return \PhpOffice\PhpPresentation\Shape\RichText\Paragraph */ public function setAlignment(Alignment $alignment) { $this->alignment = $alignment; return $this; } /** * Get font * * @return \PhpOffice\PhpPresentation\Style\Font */ public function getFont() { return $this->font; } /** * Set font * * @param \PhpOffice\PhpPresentation\Style\Font $pFont Font * @throws \Exception * @return \PhpOffice\PhpPresentation\Shape\RichText\Paragraph */ public function setFont(Font $pFont = null) { $this->font = $pFont; return $this; } /** * Get bullet style * * @return \PhpOffice\PhpPresentation\Style\Bullet */ public function getBulletStyle() { return $this->bulletStyle; } /** * Set bullet style * * @param \PhpOffice\PhpPresentation\Style\Bullet $style * @throws \Exception * @return \PhpOffice\PhpPresentation\Shape\RichText\Paragraph */ public function setBulletStyle(Bullet $style = null) { $this->bulletStyle = $style; return $this; } /** * Create text (can not be formatted !) * * @param string $pText Text * @return \PhpOffice\PhpPresentation\Shape\RichText\TextElement * @throws \Exception */ public function createText($pText = '') { $objText = new TextElement($pText); $this->addText($objText); return $objText; } /** * Add text * * @param \PhpOffice\PhpPresentation\Shape\RichText\TextElementInterface $pText Rich text element * @throws \Exception * @return \PhpOffice\PhpPresentation\Shape\RichText\Paragraph */ public function addText(TextElementInterface $pText = null) { $this->richTextElements[] = $pText; return $this; } /** * Create break * * @return \PhpOffice\PhpPresentation\Shape\RichText\BreakElement * @throws \Exception */ public function createBreak() { $objText = new BreakElement(); $this->addText($objText); return $objText; } /** * Create text run (can be formatted) * * @param string $pText Text * @return \PhpOffice\PhpPresentation\Shape\RichText\Run * @throws \Exception */ public function createTextRun($pText = '') { $objText = new Run($pText); $objText->setFont(clone $this->font); $this->addText($objText); return $objText; } /** * Convert to string * * @return string */ public function __toString() { return $this->getPlainText(); } /** * Get plain text * * @return string */ public function getPlainText() { // Return value $returnValue = ''; // Loop trough all \PhpOffice\PhpPresentation\Shape\RichText\TextElementInterface foreach ($this->richTextElements as $text) { if ($text instanceof TextElementInterface) { $returnValue .= $text->getText(); } } // Return return $returnValue; } /** * Get Rich Text elements * * @return \PhpOffice\PhpPresentation\Shape\RichText\TextElementInterface[] */ public function getRichTextElements() { return $this->richTextElements; } /** * Set Rich Text elements * * @param \PhpOffice\PhpPresentation\Shape\RichText\TextElementInterface[] $pElements Array of elements * @throws \Exception * @return \PhpOffice\PhpPresentation\Shape\RichText\Paragraph */ public function setRichTextElements($pElements = null) { if (!is_array($pElements)) { throw new \Exception("Invalid \PhpOffice\PhpPresentation\Shape\RichText\TextElementInterface[] array passed."); } $this->richTextElements = $pElements; return $this; } /** * Get hash code * * @return string Hash code */ public function getHashCode() { $hashElements = ''; foreach ($this->richTextElements as $element) { $hashElements .= $element->getHashCode(); } return md5($hashElements . $this->font->getHashCode() . __CLASS__); } /** * Get hash index * * Note that this index may vary during script execution! Only reliable moment is * while doing a write of a workbook and when changes are not allowed. * * @return string Hash index */ public function getHashIndex() { return $this->hashIndex; } /** * Set hash index * * Note that this index may vary during script execution! Only reliable moment is * while doing a write of a workbook and when changes are not allowed. * * @param string $value Hash index */ public function setHashIndex($value) { $this->hashIndex = $value; } /** * @return int */ public function getLineSpacing() { return $this->lineSpacing; } /** * @param int $lineSpacing * @return Paragraph */ public function setLineSpacing($lineSpacing) { $this->lineSpacing = $lineSpacing; return $this; } }