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

Source for file TextShape.php

Documentation is available at TextShape.php

  1. <?php
  2.  
  3. /**
  4.  * TextShape class
  5.  *
  6.  * Description: Base class for Chart shape elements with text
  7.  *
  8.  * @author
  9.  * @copyright (c) 1995-2010 by Steema Software SL. All Rights Reserved. <info@steema.com>
  10.  * @version 1.0
  11.  * @package TeeChartPHP
  12.  * @link http://www.steema.com
  13.  */
  14.  
  15. class TextShape extends TeeShape {
  16.  
  17.     private $DEFAULTROUNDSIZE 16;
  18.     protected $drawText = true;
  19.     public $defaultText = "";
  20.  
  21.     private $lines;
  22.     private $shapeStyle;
  23.     private $font;
  24.     private $textFormat;
  25.  
  26.     // Interceptors
  27.     function __get$property {
  28.       $method ="get{$property}";
  29.       if method_exists$this$method ) ) {
  30.         return $this->$method();
  31.       }
  32.     }
  33.  
  34.     function __set $property,$value {
  35.       $method ="set{$property}";
  36.       if method_exists$this$method ) ) {
  37.         return $this->$method($value);
  38.       }
  39.     }
  40.  
  41.     /**
  42.     * The class constructor.
  43.     */
  44.     public function TextShape($c=null{
  45.         $this->lines array();
  46.         $this->shapeStyle TextShapeStyle::$RECTANGLE;
  47.         $this->textFormat TextFormatted::$NORMAL;
  48.  
  49.         parent::__construct($c);
  50.         $this->readResolve();
  51.     }
  52.  
  53.     protected function readResolve({
  54.         $this->drawText = true;
  55.         $this->defaultText = "";
  56.         return $this;
  57.     }
  58.  
  59.     public function setChart($c{
  60.         parent::setChart($c);
  61.         if ($this->font != null{
  62.             $this->font->setChart($this->chart);
  63.         }
  64.     }
  65.  
  66.     /**
  67.      * Shape may be rectagular or rounded rectangular in shape. <br>
  68.      * Default value: TextShapeStyle.Rectangle
  69.      *
  70.      * @return TextShapeStyle 
  71.      */
  72.     public function getShapeStyle({
  73.         return $this->shapeStyle;
  74.     }
  75.  
  76.     public function setDrawText($value{
  77.         $this->drawText = $value;
  78.     }
  79.  
  80.     /**
  81.      * Shape may be rectagular or rounded rectangular in shape. <br>
  82.      * Default value: TextShapeStyle.Rectangle
  83.      *
  84.      * @param value TextShapeStyle
  85.      */
  86.     public function setShapeStyle($value{
  87.         if ($this->shapeStyle != $value{
  88.             $this->shapeStyle $value;
  89.             $this->invalidate();
  90.         }
  91.     }
  92.  
  93.     /**
  94.      * Determines if Text is drawn as Normal or HTML styles.
  95.      * Default value: TextFormatted::$Normal
  96.      */
  97.     public function getTextFormat(){
  98.         return $this->textFormat;
  99.     }
  100.  
  101.     public function setTextFormat($value{
  102.         if ($this->textFormat != $value)
  103.             $this->textFormat $value;
  104.         $this->invalidate();
  105.     }
  106.  
  107.     /**
  108.      * Obsolete.&nbsp;Please use Shadow.<!-- -->Size.
  109.      *
  110.      * @return int 
  111.      */
  112.     public function getShadowSize({
  113.         return $this->getShadow()->getWidth();
  114.     }
  115.  
  116.     /**
  117.      * Obsolete.&nbsp;Please use Shadow.<!-- -->Size.
  118.      *
  119.      * @param value int
  120.      */
  121.     public function setShadowSize($value{
  122.         $this->getShadow()->setWidth($value);
  123.     }
  124.  
  125.     protected function getLinesLength({
  126.         return ($this->lines == nullcount($this->lines);
  127.     }
  128.  
  129.     static private function stringJoin($separator$source{
  130.         $result "";
  131.         for ($t 0$t sizeof($source)$t++{
  132.             $result $result $source[$t$separator;
  133.         }
  134.         return $result;
  135.     }
  136.  
  137.     /**
  138.      * Displays customized strings inside Shapes. <br>
  139.      * You can use Font and Aligment to control Text display.  <br><br>
  140.      * Note: You would maybe need to change Shape Font size to a different
  141.      * value when creating metafiles or when zooming Charts.
  142.      *
  143.      * @return String 
  144.      */
  145.     public function getText({
  146.        /* TODO  correct line, temp code added      
  147.           return ($this->getLinesLength() == 0) ? "" : $this->stringJoin($Language->getString("crlf"), $this->lines);
  148.        */
  149.        return ($this->getLinesLength(== 0"" $this->lines[0];
  150.     }
  151.  
  152.     /**
  153.      * Displays customized strings inside Shapes. <br>
  154.      *
  155.      * @param value String
  156.      */
  157.     public function setText($value{
  158.         if ($this->getText()!=$value{
  159.             $this->lines null;
  160.  
  161.             /* TODO
  162.             One separator can be single char, so use a trick and replace \r\n with \n            
  163.             $istr = $value->replaceAll($Language->getString("crlf"), $Language->getString("LineSeparator"));
  164.             $this->lines = $StringFormat->split($istr, $Language->getString("LineSeparator"));
  165.             */
  166.             $this->lines[]=$value;
  167.             $this->invalidate();
  168.         }
  169.     }
  170.  
  171.     /**
  172.      * Accesses the array of Text lines.<br>
  173.      * Use lines to add multiline text to TeeChart's text objects
  174.      * (TeeChart Header, TeeChart Axis Titles etc.). <br>
  175.      * Default value: null
  176.      *
  177.      * @return String[] 
  178.      */
  179.     public function getLines({
  180.         return $this->lines;
  181.     }
  182.  
  183.     /**
  184.      * Accesses the array of Text lines.<br>
  185.      * Default value: null
  186.  
  187.      * @param value String[]
  188.      */
  189.     public function setLines($value{
  190.         $this->lines[$value;
  191.         $this->invalidate();
  192.     }
  193.  
  194.     /**
  195.      * Determines the font attributes used to output
  196.      * ShapeSeries.<!-- -->Text Strings.
  197.      *
  198.      * @return ChartFont 
  199.      */
  200.     public function getFont({
  201.         if ($this->font == null{
  202.             $this->font new ChartFont($this->chart);
  203.         }
  204.         return $this->font;
  205.     }
  206.  
  207.     /**
  208.      * Assign all properties from a TextShape to another.
  209.      *
  210.      * @param TextShape
  211.      */
  212.     public function assign($s{
  213.         if ($s != null{
  214.             parent::assign($s);
  215.  
  216.             if ($s->font != null{
  217.                 $this->getFont()->assign($s->font);
  218.             }
  219.             $this->lines $s->lines;
  220.             $this->shapeStyle $s->shapeStyle;
  221.         }
  222.     }
  223.  
  224.     /**
  225.      * Paints the TextShape object on the Chart Canvas.
  226.      */
  227.     public function paint({
  228.         $this->_paint($this->chart->getGraphics3D()$this->getShapeBounds());
  229.     }
  230.  
  231.     /**
  232.      * Paints the TextShape object on the Chart Canvas.
  233.      *
  234.      * @param IGraphics3D
  235.      * @param rect Rectangle
  236.      */
  237.     public function _paint($gd$rect$animations=null{
  238.         $tmpText=$this->getText();
  239.         
  240.         if ($this->drawText && ($this->lines != null)) {
  241.             $gd->setFont($this->font);
  242.  
  243.             $tmpW $gd->textWidth($tmpText);
  244.             $x $rect->getRight();
  245.  
  246.             $rect->width $tmpW;
  247.             $rect->height $gd->textHeight($tmpText);
  248.  
  249.             $rect->(($rect->$x2$tmpW;
  250.         }
  251.  
  252.         if ($this->bBevel != null{
  253.             if ($this->bBevel->getInner(!= BevelStyle::$NONE{
  254.                 $rect->grow(11);
  255.             }
  256.             if ($this->bBevel->getOuter(!= BevelStyle::$NONE{
  257.                 $rect->grow(11);
  258.             }
  259.         }
  260.  
  261.         //CDI Fix for TextShapeStyle
  262.         if ($this->shapeStyle == TextShapeStyle::$RECTANGLE{
  263.             if ($this->getBorderRound()!=0{
  264.                $this->setBorderRound(0);
  265.             }
  266.         else
  267.         if ($this->shapeStyle == TextShapeStyle::$ROUNDRECTANGLE{
  268.             if ($this->getBorderRound()!=8{
  269.               $this->setBorderRound(8);
  270.             }
  271.         }
  272.  
  273.         // super.paint(g, rect);  Not valid here !!!
  274.  
  275.         $this->drawRectRotated($gd$rect00$animations);
  276.  
  277.         if ($this->drawText && ($this->lines != null)) {
  278.             $gd->textOut($rect->x$rect->20$tmpText);
  279.         }
  280.     }
  281.  
  282.     private function internalDrawShape($gd$aRect$defaultRoundSize$angle$aZ,$animations=null{
  283.  
  284.         if ($angle 0{
  285.             $gd->polygonZ($aZ$gd->rotateRectangle($aRect$angle));
  286.         else {
  287.             if ($gd->getSupportsFullRotation()) {
  288.                 $gd->rectangleWithZ($aRect$aZ);
  289.             else {
  290.                 if ($this->shapeStyle == TextShapeStyle::$RECTANGLE{
  291.                     $gd->rectangle($aRect);  // $animations
  292.                 else {
  293.                     $gd->roundRectangle($aRect,$defaultRoundSize,$defaultRoundSize);
  294.                 }
  295.             }
  296.         }
  297.     }
  298.  
  299.     /**
  300.      * Draws the Shape rectangle rotated by Angle degrees.
  301.      *
  302.      * @param IGraphics3D
  303.      * @param rect Rectangle
  304.      * @param angle int
  305.      * @param aZ int
  306.      */
  307.     public function drawRectRotated($gd$rect$angle$aZ$animations=null{
  308.         if (!$this->bTransparent{
  309.             if ($this->getShadow()->getVisible(&& $this->getBrush()->getVisible()) {
  310.                 if (!$gd->getSupportsFullRotation()) {
  311.                     $this->shadow->draw($gd$rect$angle$aZ)// internaldrawshape !
  312.                 }
  313.             }
  314.  
  315. //            if (($this->getGradient()->getVisible()) && ($angle == 0)) {
  316.          //       $this->getGradient()->fill($gd->img,
  317.          //       $this->getGradient()->getDirection(),
  318.          //       $this->getGradient()->getStartColor(),
  319.          //       $this->getGradient()->getEndColor());
  320.  
  321.          //       $gd->getBrush()->setVisible(false);
  322.   //          } else {
  323.                 $gd->setBrush($this->getBrush());
  324.     //        }
  325.  
  326.             $gd->setPen($this->getPen());
  327.  
  328.             $this->internalDrawShape($gd$rect$this->DEFAULTROUNDSIZE$angle$aZ$animations);
  329.         }
  330.  
  331.         if ($this->bBevel != null{
  332.             $this->bBevel->draw($gd$rect);
  333.         }
  334.     }
  335. }
  336. ?>

Documentation generated on Wed, 16 Jun 2010 12:08:49 +0200 by phpDocumentor 1.4.1