richTextParagraphs = array( new Paragraph() ); $this->activeParagraph = 0; // Initialize parent parent::__construct(); } /** * Get active paragraph index * * @return int */ public function getActiveParagraphIndex() { return $this->activeParagraph; } /** * Get active paragraph * * @return \PhpOffice\PhpPresentation\Shape\RichText\Paragraph */ public function getActiveParagraph() { return $this->richTextParagraphs[$this->activeParagraph]; } /** * Set active paragraph * * @param int $index * @throws \Exception * @return \PhpOffice\PhpPresentation\Shape\RichText\Paragraph */ public function setActiveParagraph($index = 0) { if ($index >= count($this->richTextParagraphs)) { throw new \Exception("Invalid paragraph count."); } $this->activeParagraph = $index; return $this->getActiveParagraph(); } /** * Get paragraph * * @param int $index * @throws \Exception * @return \PhpOffice\PhpPresentation\Shape\RichText\Paragraph */ public function getParagraph($index = 0) { if ($index >= count($this->richTextParagraphs)) { throw new \Exception("Invalid paragraph count."); } return $this->richTextParagraphs[$index]; } /** * Create paragraph * * @return \PhpOffice\PhpPresentation\Shape\RichText\Paragraph * @throws \Exception */ public function createParagraph() { $numParagraphs = count($this->richTextParagraphs); if ($numParagraphs > 0) { $alignment = clone $this->getActiveParagraph()->getAlignment(); $font = clone $this->getActiveParagraph()->getFont(); $bulletStyle = clone $this->getActiveParagraph()->getBulletStyle(); } $this->richTextParagraphs[] = new Paragraph(); $this->activeParagraph = count($this->richTextParagraphs) - 1; if (isset($alignment)) { $this->getActiveParagraph()->setAlignment($alignment); } if (isset($font)) { $this->getActiveParagraph()->setFont($font); } if (isset($bulletStyle)) { $this->getActiveParagraph()->setBulletStyle($bulletStyle); } return $this->getActiveParagraph(); } /** * Add text * * @param \PhpOffice\PhpPresentation\Shape\RichText\TextElementInterface $pText Rich text element * @throws \Exception * @return \PhpOffice\PhpPresentation\Shape\RichText */ public function addText(TextElementInterface $pText = null) { $this->richTextParagraphs[$this->activeParagraph]->addText($pText); return $this; } /** * Create text (can not be formatted !) * * @param string $pText Text * @return \PhpOffice\PhpPresentation\Shape\RichText\TextElement * @throws \Exception */ public function createText($pText = '') { return $this->richTextParagraphs[$this->activeParagraph]->createText($pText); } /** * Create break * * @return \PhpOffice\PhpPresentation\Shape\RichText\BreakElement * @throws \Exception */ public function createBreak() { return $this->richTextParagraphs[$this->activeParagraph]->createBreak(); } /** * Create text run (can be formatted) * * @param string $pText Text * @return \PhpOffice\PhpPresentation\Shape\RichText\Run * @throws \Exception */ public function createTextRun($pText = '') { return $this->richTextParagraphs[$this->activeParagraph]->createTextRun($pText); } /** * Get plain text * * @return string */ public function getPlainText() { // Return value $returnValue = ''; // Loop trough all \PhpOffice\PhpPresentation\Shape\RichText\Paragraph foreach ($this->richTextParagraphs as $p) { $returnValue .= $p->getPlainText(); } // Return return $returnValue; } /** * Convert to string * * @return string */ public function __toString() { return $this->getPlainText(); } /** * Get paragraphs * * @return \PhpOffice\PhpPresentation\Shape\RichText\Paragraph[] */ public function getParagraphs() { return $this->richTextParagraphs; } /** * Set paragraphs * * @param \PhpOffice\PhpPresentation\Shape\RichText\Paragraph[] $paragraphs Array of paragraphs * @throws \Exception * @return \PhpOffice\PhpPresentation\Shape\RichText */ public function setParagraphs($paragraphs = null) { if (!is_array($paragraphs)) { throw new \Exception("Invalid \PhpOffice\PhpPresentation\Shape\RichText\Paragraph[] array passed."); } $this->richTextParagraphs = $paragraphs; $this->activeParagraph = count($this->richTextParagraphs) - 1; return $this; } /** * Get text wrapping * * @return string */ public function getWrap() { return $this->wrap; } /** * Set text wrapping * * @param $value string * @return \PhpOffice\PhpPresentation\Shape\RichText */ public function setWrap($value = self::WRAP_SQUARE) { $this->wrap = $value; return $this; } /** * Get autofit * * @return string */ public function getAutoFit() { return $this->autoFit; } /** * Get pourcentage of fontScale * * @return float */ public function getFontScale() { return $this->fontScale; } /** * Get pourcentage of the line space reduction * * @return float */ public function getLineSpaceReduction() { return $this->lnSpcReduction; } /** * Set autofit * * @param $value string * @param $fontScale float * @param $lnSpcReduction float * @return \PhpOffice\PhpPresentation\Shape\RichText */ public function setAutoFit($value = self::AUTOFIT_DEFAULT, $fontScale = null, $lnSpcReduction = null) { $this->autoFit = $value; if (!is_null($fontScale)) { $this->fontScale = $fontScale; } if (!is_null($lnSpcReduction)) { $this->lnSpcReduction = $lnSpcReduction; } return $this; } /** * Get horizontal overflow * * @return string */ public function getHorizontalOverflow() { return $this->horizontalOverflow; } /** * Set horizontal overflow * * @param $value string * @return \PhpOffice\PhpPresentation\Shape\RichText */ public function setHorizontalOverflow($value = self::OVERFLOW_OVERFLOW) { $this->horizontalOverflow = $value; return $this; } /** * Get vertical overflow * * @return string */ public function getVerticalOverflow() { return $this->verticalOverflow; } /** * Set vertical overflow * * @param $value string * @return \PhpOffice\PhpPresentation\Shape\RichText */ public function setVerticalOverflow($value = self::OVERFLOW_OVERFLOW) { $this->verticalOverflow = $value; return $this; } /** * Get upright * * @return boolean */ public function isUpright() { return $this->upright; } /** * Set vertical * * @param $value boolean * @return \PhpOffice\PhpPresentation\Shape\RichText */ public function setUpright($value = false) { $this->upright = $value; return $this; } /** * Get vertical * * @return boolean */ public function isVertical() { return $this->vertical; } /** * Set vertical * * @param $value boolean * @return \PhpOffice\PhpPresentation\Shape\RichText */ public function setVertical($value = false) { $this->vertical = $value; return $this; } /** * Get columns * * @return int */ public function getColumns() { return $this->columns; } /** * Set columns * * @param $value int * @throws \Exception * @return \PhpOffice\PhpPresentation\Shape\RichText */ public function setColumns($value = 1) { if ($value > 16 || $value < 1) { throw new \Exception('Number of columns should be 1-16'); } $this->columns = $value; return $this; } /** * Get bottom inset * * @return float */ public function getInsetBottom() { return $this->bottomInset; } /** * Set bottom inset * * @param $value float * @return \PhpOffice\PhpPresentation\Shape\RichText */ public function setInsetBottom($value = 4.8) { $this->bottomInset = $value; return $this; } /** * Get left inset * * @return float */ public function getInsetLeft() { return $this->leftInset; } /** * Set left inset * * @param $value float * @return \PhpOffice\PhpPresentation\Shape\RichText */ public function setInsetLeft($value = 9.6) { $this->leftInset = $value; return $this; } /** * Get right inset * * @return float */ public function getInsetRight() { return $this->rightInset; } /** * Set left inset * * @param $value float * @return \PhpOffice\PhpPresentation\Shape\RichText */ public function setInsetRight($value = 9.6) { $this->rightInset = $value; return $this; } /** * Get top inset * * @return float */ public function getInsetTop() { return $this->topInset; } /** * Set top inset * * @param $value float * @return \PhpOffice\PhpPresentation\Shape\RichText */ public function setInsetTop($value = 4.8) { $this->topInset = $value; return $this; } /** * Set horizontal auto shrink * @param bool $value * @return RichText */ public function setAutoShrinkHorizontal($value = null) { if (is_bool($value)) { $this->autoShrinkHorizontal = $value; } return $this; } /** * Get horizontal auto shrink * @return bool */ public function hasAutoShrinkHorizontal() { return $this->autoShrinkHorizontal; } /** * Set vertical auto shrink * @param bool $value * @return RichText */ public function setAutoShrinkVertical($value = null) { if (is_bool($value)) { $this->autoShrinkVertical = $value; } return $this; } /** * Set vertical auto shrink * @return bool */ public function hasAutoShrinkVertical() { return $this->autoShrinkVertical; } /** * Get hash code * * @return string Hash code */ public function getHashCode() { $hashElements = ''; foreach ($this->richTextParagraphs as $element) { $hashElements .= $element->getHashCode(); } return md5($hashElements . $this->wrap . $this->autoFit . $this->horizontalOverflow . $this->verticalOverflow . ($this->upright ? '1' : '0') . ($this->vertical ? '1' : '0') . $this->columns . $this->bottomInset . $this->leftInset . $this->rightInset . $this->topInset . parent::getHashCode() . __CLASS__); } }