PHPPowerPoint_Shape
[ class tree: PHPPowerPoint_Shape ] [ index: PHPPowerPoint_Shape ] [ all elements ]

Source for file RichText.php

Documentation is available at RichText.php

  1. <?php
  2. /**
  3.  * PHPPowerPoint
  4.  *
  5.  * Copyright (c) 2009 - 2010 PHPPowerPoint
  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   PHPPowerPoint
  22.  * @package    PHPPowerPoint_Shape
  23.  * @copyright  Copyright (c) 2009 - 2010 PHPPowerPoint (http://www.codeplex.com/PHPPowerPoint)
  24.  * @license    http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt    LGPL
  25.  * @version    0.1.0, 2009-04-27
  26.  */
  27.  
  28.  
  29. /** PHPPowerPoint_IComparable */
  30. require_once 'PHPPowerPoint/IComparable.php';
  31.  
  32. /** PHPPowerPoint_Shape */
  33. require_once 'PHPPowerPoint/Shape.php';
  34.  
  35. /** PHPPowerPoint_Shape_RichText_ITextElement */
  36. require_once 'PHPPowerPoint/Shape/RichText/ITextElement.php';
  37.  
  38. /** PHPPowerPoint_Shape_RichText_TextElement */
  39. require_once 'PHPPowerPoint/Shape/RichText/TextElement.php';
  40.  
  41. /** PHPPowerPoint_Shape_RichText_Run */
  42. require_once 'PHPPowerPoint/Shape/RichText/Run.php';
  43.  
  44. /** PHPPowerPoint_Shape_RichText_Break */
  45. require_once 'PHPPowerPoint/Shape/RichText/Break.php';
  46.  
  47. /** PHPPowerPoint_Style_Alignment */
  48. require_once 'PHPPowerPoint/Style/Alignment.php';
  49.  
  50. /**
  51.  * PHPPowerPoint_Shape_RichText
  52.  *
  53.  * @category   PHPPowerPoint
  54.  * @package    PHPPowerPoint_RichText
  55.  * @copyright  Copyright (c) 2009 - 2010 PHPPowerPoint (http://www.codeplex.com/PHPPowerPoint)
  56.  */
  57. {
  58.     /**
  59.      * Rich text elements
  60.      *
  61.      * @var PHPPowerPoint_Shape_RichText_ITextElement[] 
  62.      */
  63.     private $_richTextElements;
  64.     
  65.     /**
  66.      * Alignment
  67.      * 
  68.      * @var PHPPowerPoint_Style_Alignment 
  69.      */
  70.     private $_alignment;
  71.        
  72.     /**
  73.      * Create a new PHPPowerPoint_Shape_RichText instance
  74.      */
  75.     public function __construct()
  76.     {
  77.         // Initialise variables
  78.         $this->_richTextElements = array();
  79.         $this->_alignment = new PHPPowerPoint_Style_Alignment();
  80.         
  81.         // Initialize parent
  82.         parent::__construct();
  83.     }
  84.     
  85.     /**
  86.      * Get alignment
  87.      * 
  88.      * @return PHPPowerPoint_Style_Alignment 
  89.      */
  90.     public function getAlignment()
  91.     {
  92.         return $this->_alignment;
  93.     }
  94.     
  95.     /**
  96.      * Add text
  97.      *
  98.      * @param     PHPPowerPoint_Shape_RichText_ITextElement        $pText        Rich text element
  99.      * @throws     Exception
  100.      */
  101.     public function addText(PHPPowerPoint_Shape_RichText_ITextElement $pText null)
  102.     {
  103.         $this->_richTextElements[$pText;
  104.     }
  105.     
  106.     /**
  107.      * Create text (can not be formatted !)
  108.      *
  109.      * @param     string    $pText    Text
  110.      * @return    PHPPowerPoint_Shape_RichText_TextElement 
  111.      * @throws     Exception
  112.      */
  113.     public function createText($pText '')
  114.     {
  115.         $objText new PHPPowerPoint_Shape_RichText_TextElement($pText);
  116.         $this->addText($objText);
  117.         return $objText;
  118.     }
  119.     
  120.     /**
  121.      * Create break
  122.      *
  123.      * @return    PHPPowerPoint_Shape_RichText_Break 
  124.      * @throws     Exception
  125.      */
  126.     public function createBreak()
  127.     {
  128.         $objText new PHPPowerPoint_Shape_RichText_Break();
  129.         $this->addText($objText);
  130.         return $objText;
  131.     }
  132.     
  133.     /**
  134.      * Create text run (can be formatted)
  135.      *
  136.      * @param     string    $pText    Text
  137.      * @return    PHPPowerPoint_Shape_RichText_Run 
  138.      * @throws     Exception
  139.      */
  140.     public function createTextRun($pText '')
  141.     {
  142.         $objText new PHPPowerPoint_Shape_RichText_Run($pText);
  143.         $this->addText($objText);
  144.         return $objText;
  145.     }
  146.     
  147.     /**
  148.      * Get plain text
  149.      *
  150.      * @return string 
  151.      */
  152.     public function getPlainText()
  153.     {
  154.         // Return value
  155.         $returnValue '';
  156.         
  157.         // Loop trough all PHPPowerPoint_Shape_RichText_ITextElement
  158.         foreach ($this->_richTextElements as $text{
  159.             $returnValue .= $text->getText();
  160.         }
  161.         
  162.         // Return
  163.         return $returnValue;
  164.     }
  165.     
  166.     /**
  167.      * Convert to string
  168.      *
  169.      * @return string 
  170.      */
  171.     public function __toString({
  172.         return $this->getPlainText();
  173.     }
  174.     
  175.     /**
  176.      * Get Rich Text elements
  177.      *
  178.      * @return PHPPowerPoint_Shape_RichText_ITextElement[] 
  179.      */
  180.     public function getRichTextElements()
  181.     {
  182.         return $this->_richTextElements;
  183.     }
  184.     
  185.     /**
  186.      * Set Rich Text elements
  187.      *
  188.      * @param     PHPPowerPoint_Shape_RichText_ITextElement[]    $pElements        Array of elements
  189.      * @throws     Exception
  190.      */
  191.     public function setRichTextElements($pElements null)
  192.     {
  193.         if (is_array($pElements)) {
  194.             $this->_richTextElements = $pElements;
  195.         else {
  196.             throw new Exception("Invalid PHPPowerPoint_Shape_RichText_ITextElement[] array passed.");
  197.         }
  198.     }
  199.     
  200.     /**
  201.      * Get hash code
  202.      *
  203.      * @return string    Hash code
  204.      */    
  205.     public function getHashCode({
  206.         $hashElements '';
  207.         foreach ($this->_richTextElements as $element{
  208.             $hashElements .= $element->getHashCode();
  209.         }
  210.         
  211.         return md5(
  212.               $hashElements
  213.             . __CLASS__
  214.         );
  215.     }
  216.     
  217.     /**
  218.      * Hash index
  219.      *
  220.      * @var string 
  221.      */
  222.     private $_hashIndex;
  223.     
  224.     /**
  225.      * Get hash index
  226.      * 
  227.      * Note that this index may vary during script execution! Only reliable moment is
  228.      * while doing a write of a workbook and when changes are not allowed.
  229.      *
  230.      * @return string    Hash index
  231.      */
  232.     public function getHashIndex({
  233.         return $this->_hashIndex;
  234.     }
  235.     
  236.     /**
  237.      * Set hash index
  238.      * 
  239.      * Note that this index may vary during script execution! Only reliable moment is
  240.      * while doing a write of a workbook and when changes are not allowed.
  241.      *
  242.      * @param string    $value    Hash index
  243.      */
  244.     public function setHashIndex($value{
  245.         $this->_hashIndex = $value;
  246.     }
  247.     
  248.     /**
  249.      * Implement PHP __clone to create a deep clone, not just a shallow copy.
  250.      */
  251.     public function __clone({
  252.         $vars get_object_vars($this);
  253.         foreach ($vars as $key => $value{
  254.             if ($key == '_parent'continue;
  255.             
  256.             if (is_object($value)) {
  257.                 $this->$key clone $value;
  258.             else {
  259.                 $this->$key $value;
  260.             }
  261.         }
  262.     }
  263. }

Documentation generated on Sat, 25 Apr 2009 11:37:52 +0200 by phpDocumentor 1.4.1