summaryrefslogtreecommitdiffstats
path: root/vendor/phpoffice/phpspreadsheet/src/PhpSpreadsheet/RichText
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/phpoffice/phpspreadsheet/src/PhpSpreadsheet/RichText')
-rw-r--r--vendor/phpoffice/phpspreadsheet/src/PhpSpreadsheet/RichText/ITextElement.php36
-rw-r--r--vendor/phpoffice/phpspreadsheet/src/PhpSpreadsheet/RichText/RichText.php170
-rw-r--r--vendor/phpoffice/phpspreadsheet/src/PhpSpreadsheet/RichText/Run.php65
-rw-r--r--vendor/phpoffice/phpspreadsheet/src/PhpSpreadsheet/RichText/TextElement.php86
4 files changed, 357 insertions, 0 deletions
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 @@
+<?php
+
+namespace PhpOffice\PhpSpreadsheet\RichText;
+
+interface ITextElement
+{
+ /**
+ * Get text.
+ *
+ * @return string Text
+ */
+ public function getText();
+
+ /**
+ * Set text.
+ *
+ * @param $text string Text
+ *
+ * @return ITextElement
+ */
+ public function setText($text);
+
+ /**
+ * Get font.
+ *
+ * @return null|\PhpOffice\PhpSpreadsheet\Style\Font
+ */
+ public function getFont();
+
+ /**
+ * Get hash code.
+ *
+ * @return string Hash code
+ */
+ public function getHashCode();
+}
diff --git a/vendor/phpoffice/phpspreadsheet/src/PhpSpreadsheet/RichText/RichText.php b/vendor/phpoffice/phpspreadsheet/src/PhpSpreadsheet/RichText/RichText.php
new file mode 100644
index 0000000..2834f7f
--- /dev/null
+++ b/vendor/phpoffice/phpspreadsheet/src/PhpSpreadsheet/RichText/RichText.php
@@ -0,0 +1,170 @@
+<?php
+
+namespace PhpOffice\PhpSpreadsheet\RichText;
+
+use PhpOffice\PhpSpreadsheet\Cell\Cell;
+use PhpOffice\PhpSpreadsheet\Cell\DataType;
+use PhpOffice\PhpSpreadsheet\IComparable;
+
+class RichText implements IComparable
+{
+ /**
+ * Rich text elements.
+ *
+ * @var ITextElement[]
+ */
+ private $richTextElements;
+
+ /**
+ * Create a new RichText instance.
+ *
+ * @param Cell $pCell
+ */
+ public function __construct(?Cell $pCell = null)
+ {
+ // Initialise variables
+ $this->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 @@
+<?php
+
+namespace PhpOffice\PhpSpreadsheet\RichText;
+
+use PhpOffice\PhpSpreadsheet\Style\Font;
+
+class Run extends TextElement implements ITextElement
+{
+ /**
+ * Font.
+ *
+ * @var Font
+ */
+ private $font;
+
+ /**
+ * Create a new Run instance.
+ *
+ * @param string $pText Text
+ */
+ public function __construct($pText = '')
+ {
+ parent::__construct($pText);
+ // Initialise variables
+ $this->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 @@
+<?php
+
+namespace PhpOffice\PhpSpreadsheet\RichText;
+
+class TextElement implements ITextElement
+{
+ /**
+ * Text.
+ *
+ * @var string
+ */
+ private $text;
+
+ /**
+ * Create a new TextElement instance.
+ *
+ * @param string $pText Text
+ */
+ public function __construct($pText = '')
+ {
+ // Initialise variables
+ $this->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;
+ }
+ }
+ }
+}