PageRenderTime 58ms CodeModel.GetById 11ms RepoModel.GetById 1ms app.codeStats 0ms

/modules/simpleimportproduct/libraries/PHPExcel_1.7.9/Classes/PHPExcel/RichText.php

https://gitlab.com/ptisky/API_prestashop
PHP | 199 lines | 81 code | 17 blank | 101 comment | 7 complexity | 9232f2f57515b182d6d430709c0ebeb8 MD5 | raw file
  1. <?php
  2. /**
  3. * PHPExcel
  4. *
  5. * Copyright (c) 2006 - 2013 PHPExcel
  6. *
  7. * This library is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU Lesser General Public
  9. * License as published by the Free Software Foundation; either
  10. * version 2.1 of the License, or (at your option) any later version.
  11. *
  12. * This library is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * Lesser General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Lesser General Public
  18. * License along with this library; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  20. *
  21. * @category PHPExcel
  22. * @package PHPExcel_RichText
  23. * @copyright Copyright (c) 2006 - 2013 PHPExcel (http://www.codeplex.com/PHPExcel)
  24. * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
  25. * @version 1.7.9, 2013-06-02
  26. */
  27. /**
  28. * PHPExcel_RichText
  29. *
  30. * @category PHPExcel
  31. * @package PHPExcel_RichText
  32. * @copyright Copyright (c) 2006 - 2013 PHPExcel (http://www.codeplex.com/PHPExcel)
  33. */
  34. class PHPExcel_RichText implements PHPExcel_IComparable
  35. {
  36. /**
  37. * Rich text elements
  38. *
  39. * @var PHPExcel_RichText_ITextElement[]
  40. */
  41. private $_richTextElements;
  42. /**
  43. * Create a new PHPExcel_RichText instance
  44. *
  45. * @param PHPExcel_Cell $pCell
  46. * @throws PHPExcel_Exception
  47. */
  48. public function __construct(PHPExcel_Cell $pCell = null)
  49. {
  50. // Initialise variables
  51. $this->_richTextElements = array();
  52. // Rich-Text string attached to cell?
  53. if ($pCell !== NULL) {
  54. // Add cell text and style
  55. if ($pCell->getValue() != "") {
  56. $objRun = new PHPExcel_RichText_Run($pCell->getValue());
  57. $objRun->setFont(clone $pCell->getParent()->getStyle($pCell->getCoordinate())->getFont());
  58. $this->addText($objRun);
  59. }
  60. // Set parent value
  61. $pCell->setValueExplicit($this, PHPExcel_Cell_DataType::TYPE_STRING);
  62. }
  63. }
  64. /**
  65. * Add text
  66. *
  67. * @param PHPExcel_RichText_ITextElement $pText Rich text element
  68. * @throws PHPExcel_Exception
  69. * @return PHPExcel_RichText
  70. */
  71. public function addText(PHPExcel_RichText_ITextElement $pText = null)
  72. {
  73. $this->_richTextElements[] = $pText;
  74. return $this;
  75. }
  76. /**
  77. * Create text
  78. *
  79. * @param string $pText Text
  80. * @return PHPExcel_RichText_TextElement
  81. * @throws PHPExcel_Exception
  82. */
  83. public function createText($pText = '')
  84. {
  85. $objText = new PHPExcel_RichText_TextElement($pText);
  86. $this->addText($objText);
  87. return $objText;
  88. }
  89. /**
  90. * Create text run
  91. *
  92. * @param string $pText Text
  93. * @return PHPExcel_RichText_Run
  94. * @throws PHPExcel_Exception
  95. */
  96. public function createTextRun($pText = '')
  97. {
  98. $objText = new PHPExcel_RichText_Run($pText);
  99. $this->addText($objText);
  100. return $objText;
  101. }
  102. /**
  103. * Get plain text
  104. *
  105. * @return string
  106. */
  107. public function getPlainText()
  108. {
  109. // Return value
  110. $returnValue = '';
  111. // Loop through all PHPExcel_RichText_ITextElement
  112. foreach ($this->_richTextElements as $text) {
  113. $returnValue .= $text->getText();
  114. }
  115. // Return
  116. return $returnValue;
  117. }
  118. /**
  119. * Convert to string
  120. *
  121. * @return string
  122. */
  123. public function __toString()
  124. {
  125. return $this->getPlainText();
  126. }
  127. /**
  128. * Get Rich Text elements
  129. *
  130. * @return PHPExcel_RichText_ITextElement[]
  131. */
  132. public function getRichTextElements()
  133. {
  134. return $this->_richTextElements;
  135. }
  136. /**
  137. * Set Rich Text elements
  138. *
  139. * @param PHPExcel_RichText_ITextElement[] $pElements Array of elements
  140. * @throws PHPExcel_Exception
  141. * @return PHPExcel_RichText
  142. */
  143. public function setRichTextElements($pElements = null)
  144. {
  145. if (is_array($pElements)) {
  146. $this->_richTextElements = $pElements;
  147. } else {
  148. throw new PHPExcel_Exception("Invalid PHPExcel_RichText_ITextElement[] array passed.");
  149. }
  150. return $this;
  151. }
  152. /**
  153. * Get hash code
  154. *
  155. * @return string Hash code
  156. */
  157. public function getHashCode()
  158. {
  159. $hashElements = '';
  160. foreach ($this->_richTextElements as $element) {
  161. $hashElements .= $element->getHashCode();
  162. }
  163. return md5(
  164. $hashElements
  165. . __CLASS__
  166. );
  167. }
  168. /**
  169. * Implement PHP __clone to create a deep clone, not just a shallow copy.
  170. */
  171. public function __clone()
  172. {
  173. $vars = get_object_vars($this);
  174. foreach ($vars as $key => $value) {
  175. if (is_object($value)) {
  176. $this->$key = clone $value;
  177. } else {
  178. $this->$key = $value;
  179. }
  180. }
  181. }
  182. }