From 75160b12821f7f4299cce7f0b69c83c1502ae071 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anton=20Luka=20=C5=A0ijanec?= Date: Mon, 27 May 2024 13:08:29 +0200 Subject: 2024-02-19 upstream --- .../src/PhpSpreadsheet/RichText/ITextElement.php | 36 +++++ .../src/PhpSpreadsheet/RichText/RichText.php | 170 +++++++++++++++++++++ .../src/PhpSpreadsheet/RichText/Run.php | 65 ++++++++ .../src/PhpSpreadsheet/RichText/TextElement.php | 86 +++++++++++ 4 files changed, 357 insertions(+) create mode 100644 vendor/phpoffice/phpspreadsheet/src/PhpSpreadsheet/RichText/ITextElement.php create mode 100644 vendor/phpoffice/phpspreadsheet/src/PhpSpreadsheet/RichText/RichText.php create mode 100644 vendor/phpoffice/phpspreadsheet/src/PhpSpreadsheet/RichText/Run.php create mode 100644 vendor/phpoffice/phpspreadsheet/src/PhpSpreadsheet/RichText/TextElement.php (limited to 'vendor/phpoffice/phpspreadsheet/src/PhpSpreadsheet/RichText') diff --git a/vendor/phpoffice/phpspreadsheet/src/PhpSpreadsheet/RichText/ITextElement.php b/vendor/phpoffice/phpspreadsheet/src/PhpSpreadsheet/RichText/ITextElement.php new file mode 100644 index 0000000..df58317 --- /dev/null +++ b/vendor/phpoffice/phpspreadsheet/src/PhpSpreadsheet/RichText/ITextElement.php @@ -0,0 +1,36 @@ +richTextElements = []; + + // Rich-Text string attached to cell? + if ($pCell !== null) { + // Add cell text and style + if ($pCell->getValue() != '') { + $objRun = new Run($pCell->getValue()); + $objRun->setFont(clone $pCell->getWorksheet()->getStyle($pCell->getCoordinate())->getFont()); + $this->addText($objRun); + } + + // Set parent value + $pCell->setValueExplicit($this, DataType::TYPE_STRING); + } + } + + /** + * Add text. + * + * @param ITextElement $pText Rich text element + * + * @return $this + */ + public function addText(ITextElement $pText) + { + $this->richTextElements[] = $pText; + + return $this; + } + + /** + * Create text. + * + * @param string $pText Text + * + * @return TextElement + */ + public function createText($pText) + { + $objText = new TextElement($pText); + $this->addText($objText); + + return $objText; + } + + /** + * Create text run. + * + * @param string $pText Text + * + * @return Run + */ + public function createTextRun($pText) + { + $objText = new Run($pText); + $this->addText($objText); + + return $objText; + } + + /** + * Get plain text. + * + * @return string + */ + public function getPlainText() + { + // Return value + $returnValue = ''; + + // Loop through all ITextElements + foreach ($this->richTextElements as $text) { + $returnValue .= $text->getText(); + } + + return $returnValue; + } + + /** + * Convert to string. + * + * @return string + */ + public function __toString() + { + return $this->getPlainText(); + } + + /** + * Get Rich Text elements. + * + * @return ITextElement[] + */ + public function getRichTextElements() + { + return $this->richTextElements; + } + + /** + * Set Rich Text elements. + * + * @param ITextElement[] $textElements Array of elements + * + * @return $this + */ + public function setRichTextElements(array $textElements) + { + $this->richTextElements = $textElements; + + return $this; + } + + /** + * Get hash code. + * + * @return string Hash code + */ + public function getHashCode() + { + $hashElements = ''; + foreach ($this->richTextElements as $element) { + $hashElements .= $element->getHashCode(); + } + + return md5( + $hashElements . + __CLASS__ + ); + } + + /** + * Implement PHP __clone to create a deep clone, not just a shallow copy. + */ + public function __clone() + { + $vars = get_object_vars($this); + foreach ($vars as $key => $value) { + if (is_object($value)) { + $this->$key = clone $value; + } else { + $this->$key = $value; + } + } + } +} diff --git a/vendor/phpoffice/phpspreadsheet/src/PhpSpreadsheet/RichText/Run.php b/vendor/phpoffice/phpspreadsheet/src/PhpSpreadsheet/RichText/Run.php new file mode 100644 index 0000000..c280b52 --- /dev/null +++ b/vendor/phpoffice/phpspreadsheet/src/PhpSpreadsheet/RichText/Run.php @@ -0,0 +1,65 @@ +font = new Font(); + } + + /** + * Get font. + * + * @return null|\PhpOffice\PhpSpreadsheet\Style\Font + */ + public function getFont() + { + return $this->font; + } + + /** + * Set font. + * + * @param Font $pFont Font + * + * @return $this + */ + public function setFont(?Font $pFont = null) + { + $this->font = $pFont; + + return $this; + } + + /** + * Get hash code. + * + * @return string Hash code + */ + public function getHashCode() + { + return md5( + $this->getText() . + $this->font->getHashCode() . + __CLASS__ + ); + } +} diff --git a/vendor/phpoffice/phpspreadsheet/src/PhpSpreadsheet/RichText/TextElement.php b/vendor/phpoffice/phpspreadsheet/src/PhpSpreadsheet/RichText/TextElement.php new file mode 100644 index 0000000..c737959 --- /dev/null +++ b/vendor/phpoffice/phpspreadsheet/src/PhpSpreadsheet/RichText/TextElement.php @@ -0,0 +1,86 @@ +text = $pText; + } + + /** + * Get text. + * + * @return string Text + */ + public function getText() + { + return $this->text; + } + + /** + * Set text. + * + * @param $text string Text + * + * @return $this + */ + public function setText($text) + { + $this->text = $text; + + return $this; + } + + /** + * Get font. + * + * @return null|\PhpOffice\PhpSpreadsheet\Style\Font + */ + public function getFont() + { + return null; + } + + /** + * Get hash code. + * + * @return string Hash code + */ + public function getHashCode() + { + return md5( + $this->text . + __CLASS__ + ); + } + + /** + * Implement PHP __clone to create a deep clone, not just a shallow copy. + */ + public function __clone() + { + $vars = get_object_vars($this); + foreach ($vars as $key => $value) { + if (is_object($value)) { + $this->$key = clone $value; + } else { + $this->$key = $value; + } + } + } +} -- cgit v1.2.3