Source for file Box.php

Documentation is available at Box.php

  1. <?php
  2. /**
  3.  * $Source: /cvsroot/svggrapher/svggrapher/mains/Box.php,v $
  4.  *
  5.  * box
  6.  *
  7.  * @version CVS: $Id: Box.php,v 1.3 2007/10/18 16:32:03 geelweb Exp $
  8.  * @filesource
  9.  * @author Guillaume Luchet. <guillaume@geelweb.org>
  10.  * @copyright Copyright (c) 2007, Guillaume Luchet.
  11.  * @license http://opensource.org/licenses/bsd-license.php BSD License
  12.  * @package SvgGrapher
  13.  */
  14.  
  15. /**
  16.  * Box
  17.  *
  18.  * This class is the representation of a box. a box is a rectangular zone with
  19.  * abscisse, ordinate, width, height, etc.
  20.  * 
  21.  * @todo add helper method (translate, rotate, etc)
  22.  *
  23.  * @version $Id: Box.php,v 1.3 2007/10/18 16:32:03 geelweb Exp $
  24.  * @copyright Copyright (c) 2007, Guillaume Luchet
  25.  * @author guillaume luchet <guillaume@geelweb.org>
  26.  * @license http://opensource.org/licenses/bsd-license.php BSD License
  27.  * @package SvgGrapher
  28.  */
  29. class Box 
  30. {
  31.     // Box::Properties {{{
  32.  
  33.     /**
  34.      * width
  35.      *
  36.      * Width of the box
  37.      * 
  38.      * @var mixed 
  39.      * @access public
  40.      */
  41.     public $width;
  42.  
  43.     /**
  44.      * height
  45.      *
  46.      * Height of the box
  47.      * 
  48.      * @var mixed 
  49.      * @access public
  50.      */
  51.     public $height;
  52.  
  53.     /**
  54.      * x
  55.      *
  56.      * Upper left corner abscisse of the box
  57.      * 
  58.      * @var mixed 
  59.      * @access public
  60.      */
  61.     public $x;
  62.  
  63.     /**
  64.      * y
  65.      *
  66.      * Upper left corner ordinate of the box
  67.      * 
  68.      * @var mixed 
  69.      * @access public
  70.      */
  71.     public $y;
  72.  
  73.     /**
  74.      * padding
  75.      *
  76.      * padding of the box
  77.      * 
  78.      * @var string 
  79.      * @access public
  80.      */
  81.     protected $padding = array(
  82.         'top'    => 0,
  83.         'right'  => 0,
  84.         'bottom' => 0,
  85.         'left'   => 0);
  86.  
  87.     // }}}
  88.     // Box::__construct() {{{
  89.  
  90.     /**
  91.      * __construct
  92.      *
  93.      * Build the box
  94.      *
  95.      * params:
  96.      * <code>
  97.      * array(
  98.      *     'height'  => 10,
  99.      *     'width'   => 20,
  100.      *     'x'       => 5,
  101.      *     'y'       => 5,
  102.      *     'padding' => array('left'=>10, 'top'=>12)
  103.      * );
  104.      * </code>
  105.      * 
  106.      * @param array $params box params
  107.      * @access public
  108.      * @return void 
  109.      */
  110.     public function __construct($params array()) 
  111.     {
  112.         if(isset($params['width'])) {
  113.             $this->width = $params['width'];
  114.         }
  115.         if(isset($params['height'])) {
  116.             $this->height = $params['height'];
  117.         }
  118.         if(isset($params['x'])) {
  119.             $this->x = $params['x'];
  120.         }
  121.         if(isset($params['y'])) {
  122.             $this->y = $params['y'];
  123.         }
  124.         if(isset($params['padding']&& is_array($params['padding'])) {
  125.             $this->padding = $params['padding'];
  126.         }
  127.     }
  128.  
  129.     // }}}
  130.     // Box::__set() {{{
  131.  
  132.     /**
  133.      * __set
  134.      * 
  135.      * @param string $property 
  136.      * @param mixed $value 
  137.      * @access public
  138.      * @return mixed 
  139.      */
  140.     public function __set($property$value
  141.     {
  142.         $method 'set' $property;
  143.         if(method_exists($this$method)) {
  144.             return $this->$method($value);
  145.         }
  146.         return $this->$property $value;
  147.     }
  148.  
  149.     // }}}
  150.     // Box::__get() {{{
  151.  
  152.     /**
  153.      * __get
  154.      * 
  155.      * @param string $property 
  156.      * @access public
  157.      * @return mixed 
  158.      */
  159.     public function __get($property
  160.     {
  161.         $method 'get' $property;
  162.         if(method_exists($this$method)) {
  163.             return $this->$method();
  164.         }
  165.         return $this->$property;
  166.     }
  167.  
  168.     // }}}
  169.     // Box::setPadding() {{{
  170.     
  171.     /**
  172.      * setPadding
  173.      * 
  174.      * set the padding property
  175.      *
  176.      * $padding can be:
  177.      * - numeric: all the elements of the $padding array take the value
  178.      * - comma separated string: the elements take the value of each value in
  179.      * the order top, right, bottom, left
  180.      * - array of keys / values: for each element of the array, the element of the $padding array
  181.      * width the key take the value
  182.      *
  183.      * examples:
  184.      * <code>
  185.      * $box = new Box();
  186.      * $box->padding = 10;
  187.      * print_r($box->padding); // array('top'=>10, 'right'=>10, 'bottom'=>10, 'left'=>10);
  188.      *
  189.      * $box->padding = '4, 5, 1, 10';
  190.      * print_r($box->padding); // array('top'=>4, 'right'=>5, 'bottom'=>1, 'left'=>10);
  191.      *
  192.      * $box->padding = '5, 10'; // the unspecified values take the last value
  193.      * print_r($box->padding); // array('top'=>5, 'right'=>10, 'bottom'=>10, 'left'=>10);
  194.      *
  195.      * $box->padding = array('bottom'=>12); // the unspecified values not change
  196.      * print_r($box->padding); // array('top'=>5, 'right'=>10, 'bottom'=>12, 'left'=>10);
  197.      * </code>
  198.      * 
  199.      * @param mixed $padding 
  200.      * @access public
  201.      * @return void 
  202.      */
  203.     public function setPadding($padding
  204.     {
  205.         if(is_numeric($padding)) {
  206.             foreach($this->padding as $k=>$v{
  207.                 $this->padding[$k$padding;
  208.             }
  209.         elseif(is_string($padding)) {
  210.             $p explode(','$padding);
  211.             $n count($p);
  212.             for($i=$n $i $i++{
  213.                 $p[$i$p[$n-1];
  214.             }
  215.             $this->padding['top'$p[0];
  216.             $this->padding['right'$p[1];
  217.             $this->padding['bottom'$p[2];
  218.             $this->padding['left'$p[3];
  219.         elseif(is_array($padding)) {
  220.             foreach($padding as $k=>$v{
  221.                 $this->padding[$k$v;
  222.             }
  223.         }
  224.     }
  225.     
  226.     // }}}
  227. }
  228.  
  229. ?>

Documentation generated on Tue, 23 Oct 2007 11:31:53 +0200 by phpDocumentor 1.4.0