This commit is contained in:
Dominik Bonsch 2013-02-09 12:26:15 +01:00
parent b9970417c3
commit 49783efbd2

View File

@ -21,7 +21,7 @@
* @category PHPExcel * @category PHPExcel
* @package PHPExcel_RichText * @package PHPExcel_RichText
* @copyright Copyright (c) 2006 - 2012 PHPExcel (http://www.codeplex.com/PHPExcel) * @copyright Copyright (c) 2006 - 2012 PHPExcel (http://www.codeplex.com/PHPExcel)
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version ##VERSION##, ##DATE## * @version ##VERSION##, ##DATE##
*/ */
@ -35,77 +35,77 @@
*/ */
class PHPExcel_RichText implements PHPExcel_IComparable class PHPExcel_RichText implements PHPExcel_IComparable
{ {
/** /**
* Rich text elements * Rich text elements
* *
* @var PHPExcel_RichText_ITextElement[] * @var PHPExcel_RichText_ITextElement[]
*/ */
private $_richTextElements; private $_richTextElements;
/** /**
* Create a new PHPExcel_RichText instance * Create a new PHPExcel_RichText instance
* *
* @param PHPExcel_Cell $pParent * @param PHPExcel_Cell $pParent
* @throws PHPExcel_Exception * @throws PHPExcel_Exception
*/ */
public function __construct(PHPExcel_Cell $pCell = null) public function __construct(PHPExcel_Cell $pCell = null)
{ {
// Initialise variables // Initialise variables
$this->_richTextElements = array(); $this->_richTextElements = array();
// Rich-Text string attached to cell? // Rich-Text string attached to cell?
if ($pCell !== NULL) { if ($pCell !== NULL) {
// Add cell text and style // Add cell text and style
if ($pCell->getValue() != "") { if ($pCell->getValue() != "") {
$objRun = new PHPExcel_RichText_Run($pCell->getValue()); $objRun = new PHPExcel_RichText_Run($pCell->getValue());
$objRun->setFont(clone $pCell->getParent()->getStyle($pCell->getCoordinate())->getFont()); $objRun->setFont(clone $pCell->getParent()->getStyle($pCell->getCoordinate())->getFont());
$this->addText($objRun); $this->addText($objRun);
} }
// Set parent value // Set parent value
$pCell->setValueExplicit($this, PHPExcel_Cell_DataType::TYPE_STRING); $pCell->setValueExplicit($this, PHPExcel_Cell_DataType::TYPE_STRING);
} }
} }
/** /**
* Add text * Add text
* *
* @param PHPExcel_RichText_ITextElement $pText Rich text element * @param PHPExcel_RichText_ITextElement $pText Rich text element
* @throws PHPExcel_Exception * @throws PHPExcel_Exception
* @return PHPExcel_RichText * @return PHPExcel_RichText
*/ */
public function addText(PHPExcel_RichText_ITextElement $pText = null) public function addText(PHPExcel_RichText_ITextElement $pText = null)
{ {
$this->_richTextElements[] = $pText; $this->_richTextElements[] = $pText;
return $this; return $this;
} }
/** /**
* Create text * Create text
* *
* @param string $pText Text * @param string $pText Text
* @return PHPExcel_RichText_TextElement * @return PHPExcel_RichText_TextElement
* @throws PHPExcel_Exception * @throws PHPExcel_Exception
*/ */
public function createText($pText = '') public function createText($pText = '')
{ {
$objText = new PHPExcel_RichText_TextElement($pText); $objText = new PHPExcel_RichText_TextElement($pText);
$this->addText($objText); $this->addText($objText);
return $objText; return $objText;
} }
/** /**
* Create text run * Create text run
* *
* @param string $pText Text * @param string $pText Text
* @return PHPExcel_RichText_Run * @return PHPExcel_RichText_Run
* @throws PHPExcel_Exception * @throws PHPExcel_Exception
*/ */
public function createTextRun($pText = '') public function createTextRun($pText = '')
{ {
$objText = new PHPExcel_RichText_Run($pText); $objText = new PHPExcel_RichText_Run($pText);
$this->addText($objText); $this->addText($objText);
return $objText; return $objText;
} }
/** /**
@ -115,16 +115,16 @@ class PHPExcel_RichText implements PHPExcel_IComparable
*/ */
public function getPlainText() public function getPlainText()
{ {
// Return value // Return value
$returnValue = ''; $returnValue = '';
// Loop through all PHPExcel_RichText_ITextElement // Loop through all PHPExcel_RichText_ITextElement
foreach ($this->_richTextElements as $text) { foreach ($this->_richTextElements as $text) {
$returnValue .= $text->getText(); $returnValue .= $text->getText();
} }
// Return // Return
return $returnValue; return $returnValue;
} }
/** /**
@ -132,8 +132,9 @@ class PHPExcel_RichText implements PHPExcel_IComparable
* *
* @return string * @return string
*/ */
public function __toString() { public function __toString()
return $this->getPlainText(); {
return $this->getPlainText();
} }
/** /**
@ -143,54 +144,56 @@ class PHPExcel_RichText implements PHPExcel_IComparable
*/ */
public function getRichTextElements() public function getRichTextElements()
{ {
return $this->_richTextElements; return $this->_richTextElements;
} }
/** /**
* Set Rich Text elements * Set Rich Text elements
* *
* @param PHPExcel_RichText_ITextElement[] $pElements Array of elements * @param PHPExcel_RichText_ITextElement[] $pElements Array of elements
* @throws PHPExcel_Exception * @throws PHPExcel_Exception
* @return PHPExcel_RichText * @return PHPExcel_RichText
*/ */
public function setRichTextElements($pElements = null) public function setRichTextElements($pElements = null)
{ {
if (is_array($pElements)) { if (is_array($pElements)) {
$this->_richTextElements = $pElements; $this->_richTextElements = $pElements;
} else { } else {
throw new PHPExcel_Exception("Invalid PHPExcel_RichText_ITextElement[] array passed."); throw new PHPExcel_Exception("Invalid PHPExcel_RichText_ITextElement[] array passed.");
} }
return $this; return $this;
} }
/** /**
* Get hash code * Get hash code
* *
* @return string Hash code * @return string Hash code
*/ */
public function getHashCode() { public function getHashCode()
$hashElements = ''; {
foreach ($this->_richTextElements as $element) { $hashElements = '';
$hashElements .= $element->getHashCode(); foreach ($this->_richTextElements as $element) {
} $hashElements .= $element->getHashCode();
}
return md5( return md5(
$hashElements $hashElements
. __CLASS__ . __CLASS__
); );
} }
/** /**
* Implement PHP __clone to create a deep clone, not just a shallow copy. * Implement PHP __clone to create a deep clone, not just a shallow copy.
*/ */
public function __clone() { public function __clone()
$vars = get_object_vars($this); {
foreach ($vars as $key => $value) { $vars = get_object_vars($this);
if (is_object($value)) { foreach ($vars as $key => $value) {
$this->$key = clone $value; if (is_object($value)) {
} else { $this->$key = clone $value;
$this->$key = $value; } else {
} $this->$key = $value;
} }
} }
}
} }