home *** CD-ROM | disk | FTP | other *** search
/ Cricao de Sites - 650 Layouts Prontos / WebMasters.iso / Servidores / xampp-win32-1.6.7-installer.exe / php / PEAR / Image / Graph / Title.php < prev    next >
Encoding:
PHP Script  |  2008-07-02  |  5.6 KB  |  194 lines

  1. <?php
  2.  
  3. /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
  4.  
  5. /**
  6.  * Image_Graph - Main class for the graph creation.
  7.  *
  8.  * PHP versions 4 and 5
  9.  *
  10.  * LICENSE: This library is free software; you can redistribute it and/or modify
  11.  * it under the terms of the GNU Lesser General Public License as published by
  12.  * the Free Software Foundation; either version 2.1 of the License, or (at your
  13.  * option) any later version. This library is distributed in the hope that it
  14.  * will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
  15.  * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser
  16.  * General Public License for more details. You should have received a copy of
  17.  * the GNU Lesser General Public License along with this library; if not, write
  18.  * to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
  19.  * 02111-1307 USA
  20.  *
  21.  * @category   Images
  22.  * @package    Image_Graph
  23.  * @subpackage Text
  24.  * @author     Jesper Veggerby <pear.nosey@veggerby.dk>
  25.  * @copyright  Copyright (C) 2003, 2004 Jesper Veggerby Hansen
  26.  * @license    http://www.gnu.org/copyleft/lesser.html  LGPL License 2.1
  27.  * @version    CVS: $Id: Title.php,v 1.12 2005/08/24 20:35:56 nosey Exp $
  28.  * @link       http://pear.php.net/package/Image_Graph
  29.  */
  30.  
  31. /**
  32.  * Include file Image/Graph/Layout.php
  33.  */
  34. require_once 'Image/Graph/Layout.php';
  35.  
  36. /**
  37.  * Title
  38.  * 
  39.  * @category   Images
  40.  * @package    Image_Graph
  41.  * @subpackage Text
  42.  * @author     Jesper Veggerby <pear.nosey@veggerby.dk>
  43.  * @copyright  Copyright (C) 2003, 2004 Jesper Veggerby Hansen
  44.  * @license    http://www.gnu.org/copyleft/lesser.html  LGPL License 2.1
  45.  * @version    Release: 0.7.2
  46.  * @link       http://pear.php.net/package/Image_Graph
  47.  */
  48. class Image_Graph_Title extends Image_Graph_Layout
  49. {
  50.  
  51.     /**
  52.      * The text to print
  53.      * @var string
  54.      * @access private
  55.      */
  56.     var $_text;
  57.  
  58.     /**
  59.      * The font to use
  60.      * @var Font
  61.      * @access private
  62.      */
  63.     var $_font;
  64.  
  65.     /**
  66.      * The alignment of the title
  67.      * @var int
  68.      * @access private
  69.      */
  70.     var $_alignment = IMAGE_GRAPH_ALIGN_CENTER_X;
  71.  
  72.     /**
  73.      * Create the title.
  74.      *
  75.      * Pass a Image_Graph_Font object - preferably by-ref (&) as second
  76.      * parameter, the font size in pixels or an associated array with some or
  77.      * all of the followin keys:
  78.      *
  79.      * 'size' The size of the title
  80.      *
  81.      * 'angle' The angle at which to write the title (in degrees or 'vertical')
  82.      *
  83.      * 'color' The font-face color
  84.      *
  85.      * @param sting $text The text to represent the title
  86.      * @param mixed $fontOptions The font to use in the title
  87.      */
  88.     function Image_Graph_Title($text, $fontOptions = false)
  89.     {
  90.         parent::Image_Graph_Layout();
  91.         if (is_object($fontOptions)) {
  92.             $this->_font =& $fontOptions;
  93.         } else {
  94.             if (is_array($fontOptions)) {
  95.                 $this->_fontOptions = $fontOptions;
  96.             } else {
  97.                 $this->_fontOptions['size'] = $fontOptions;
  98.             }
  99.         }
  100.         $this->setText($text);
  101.     }
  102.  
  103.     /**
  104.      * Set the text
  105.      *
  106.      * @param string $text The text to display
  107.      */
  108.     function setText($text)
  109.     {
  110.         $this->_text = $text;
  111.     }
  112.  
  113.     /**
  114.      * Returns the calculated "auto" size
  115.      *
  116.      * @return int The calculated auto size
  117.      * @access private
  118.      */
  119.     function _getAutoSize()
  120.     {
  121.         if ($this->_defaultFontOptions !== false) {
  122.             $this->_canvas->setFont($this->_defaultFontOptions);
  123.         } else {        
  124.             $this->_canvas->setFont($this->_getFont());
  125.         }
  126.  
  127.         return $this->_canvas->textHeight($this->_text);
  128.     }
  129.  
  130.     /**
  131.      * Set the alignment of the legend
  132.      *
  133.      * @param int $alignment The alignment
  134.      */
  135.     function setAlignment($alignment)
  136.     {
  137.         $this->_alignment = $alignment & 0x7;
  138.     }
  139.     
  140.     /**
  141.      * Output the text
  142.      *
  143.      * @return bool Was the output 'good' (true) or 'bad' (false).
  144.      * @access private
  145.      */
  146.     function _done()
  147.     {
  148.         if ($this->_defaultFontOptions !== false) {
  149.             $this->_canvas->setFont($this->_defaultFontOptions);
  150.         } else {        
  151.             $this->_canvas->setFont($this->_getFont());
  152.         }
  153.  
  154.         if (is_a($this->_parent, 'Image_Graph_Plotarea')) {            
  155.             $this->_setCoords(
  156.                 $this->_parent->_left,
  157.                 $this->_parent->_top,
  158.                 $this->_parent->_right,
  159.                 $this->_parent->_top + $this->_canvas->textHeight($this->_text)
  160.             );
  161.         } elseif (!is_a($this->_parent, 'Image_Graph_Layout')) {
  162.             $this->_setCoords(
  163.                 $this->_parent->_fillLeft(),
  164.                 $this->_parent->_fillTop(),
  165.                 $this->_parent->_fillRight(),
  166.                 $this->_parent->_fillTop() + $this->_canvas->textHeight($this->_text)
  167.             );
  168.         }
  169.  
  170.         if (parent::_done() === false) {
  171.             return false;
  172.         }
  173.             
  174.         if ($this->_alignment == IMAGE_GRAPH_ALIGN_CENTER_X) {
  175.             $x = ($this->_left + $this->_right) / 2;
  176.         } elseif ($this->_alignment == IMAGE_GRAPH_ALIGN_LEFT) {
  177.             $x = $this->_left;
  178.         } else {
  179.             $x = $this->_right;
  180.         }
  181.         $y = ($this->_top + $this->_bottom) / 2;
  182.  
  183.         $this->write(
  184.             $x,
  185.             $y,
  186.             $this->_text,
  187.             $this->_alignment + IMAGE_GRAPH_ALIGN_CENTER_Y
  188.         );
  189.         return true;
  190.     }
  191.  
  192. }
  193.  
  194. ?>