[ Index ]
 

Code source de PRADO 3.0.6

Accédez au Source d'autres logiciels libresSoutenez Angelica Josefina !

title

Body

[fermer]

/framework/Web/UI/WebControls/ -> TFont.php (source)

   1  <?php
   2  /**
   3   * TFont class file.
   4   *
   5   * @author Qiang Xue <qiang.xue@gmail.com>
   6   * @link http://www.pradosoft.com/
   7   * @copyright Copyright &copy; 2005 PradoSoft
   8   * @license http://www.pradosoft.com/license/
   9   * @version $Id: TFont.php 1397 2006-09-07 07:55:53Z wei $
  10   * @package System.Web.UI.WebControls
  11   */
  12  
  13  /**
  14   * TFont class
  15   *
  16   * TFont encapsulates the CSS style fields related with font settings.
  17   *
  18   * @author Qiang Xue <qiang.xue@gmail.com>
  19   * @version $Id: TFont.php 1397 2006-09-07 07:55:53Z wei $
  20   * @package System.Web.UI.WebControls
  21   * @since 3.0
  22   */
  23  class TFont extends TComponent
  24  {
  25      /**
  26       * Bits indicating the font states.
  27       */
  28      const IS_BOLD=0x01;
  29      const IS_ITALIC=0x02;
  30      const IS_OVERLINE=0x04;
  31      const IS_STRIKEOUT=0x08;
  32      const IS_UNDERLINE=0x10;
  33  
  34      /**
  35       * Bits indicating whether particular font states are changed.
  36       */
  37      const IS_SET_BOLD=0x01000;
  38      const IS_SET_ITALIC=0x02000;
  39      const IS_SET_OVERLINE=0x04000;
  40      const IS_SET_STRIKEOUT=0x08000;
  41      const IS_SET_UNDERLINE=0x10000;
  42      const IS_SET_SIZE=0x20000;
  43      const IS_SET_NAME=0x40000;
  44  
  45      /**
  46       * @var integer bits representing various states
  47       */
  48      private $_flags=0;
  49      /**
  50       * @var string font name
  51       */
  52      private $_name='';
  53      /**
  54       * @var string font size
  55       */
  56      private $_size='';
  57  
  58      /**
  59       * @return boolean whether the font is in bold face. Defaults to false.
  60       */
  61  	public function getBold()
  62      {
  63          return ($this->_flags & self::IS_BOLD)!==0;
  64      }
  65  
  66      /**
  67       * @param boolean whether the font is in bold face
  68       */
  69  	public function setBold($value)
  70      {
  71          $this->_flags |= self::IS_SET_BOLD;
  72          if(TPropertyValue::ensureBoolean($value))
  73              $this->_flags |= self::IS_BOLD;
  74          else
  75              $this->_flags &= ~self::IS_BOLD;
  76      }
  77  
  78      /**
  79       * @return boolean whether the font is in italic face. Defaults to false.
  80       */
  81  	public function getItalic()
  82      {
  83          return ($this->_flags & self::IS_ITALIC)!==0;
  84      }
  85  
  86      /**
  87       * @param boolean whether the font is italic
  88       */
  89  	public function setItalic($value)
  90      {
  91          $this->_flags |= self::IS_SET_ITALIC;
  92          if(TPropertyValue::ensureBoolean($value))
  93              $this->_flags |= self::IS_ITALIC;
  94          else
  95              $this->_flags &= ~self::IS_ITALIC;
  96      }
  97  
  98      /**
  99       * @return boolean whether the font is overlined. Defaults to false.
 100       */
 101  	public function getOverline()
 102      {
 103          return ($this->_flags & self::IS_OVERLINE)!==0;
 104      }
 105  
 106      /**
 107       * @param boolean whether the font is overlined
 108       */
 109  	public function setOverline($value)
 110      {
 111          $this->_flags |= self::IS_SET_OVERLINE;
 112          if(TPropertyValue::ensureBoolean($value))
 113              $this->_flags |= self::IS_OVERLINE;
 114          else
 115              $this->_flags &= ~self::IS_OVERLINE;
 116      }
 117  
 118      /**
 119       * @return string the font size
 120       */
 121  	public function getSize()
 122      {
 123          return $this->_size;
 124      }
 125  
 126      /**
 127       * @param string the font size
 128       */
 129  	public function setSize($value)
 130      {
 131          $this->_flags |= self::IS_SET_SIZE;
 132          $this->_size=$value;
 133      }
 134  
 135      /**
 136       * @return boolean whether the font is strikeout. Defaults to false.
 137       */
 138  	public function getStrikeout()
 139      {
 140          return ($this->_flags & self::IS_STRIKEOUT)!==0;
 141      }
 142  
 143      /**
 144       * @param boolean whether the font is strikeout
 145       */
 146  	public function setStrikeout($value)
 147      {
 148          $this->_flags |= self::IS_SET_STRIKEOUT;
 149          if(TPropertyValue::ensureBoolean($value))
 150              $this->_flags |= self::IS_STRIKEOUT;
 151          else
 152              $this->_flags &= ~self::IS_STRIKEOUT;
 153      }
 154  
 155      /**
 156       * @return boolean whether the font is underlined. Defaults to false.
 157       */
 158  	public function getUnderline()
 159      {
 160          return ($this->_flags & self::IS_UNDERLINE)!==0;
 161      }
 162  
 163      /**
 164       * @param boolean whether the font is underlined
 165       */
 166  	public function setUnderline($value)
 167      {
 168          $this->_flags |= self::IS_SET_UNDERLINE;
 169          if(TPropertyValue::ensureBoolean($value))
 170              $this->_flags |= self::IS_UNDERLINE;
 171          else
 172              $this->_flags &= ~self::IS_UNDERLINE;
 173      }
 174  
 175      /**
 176       * @return string the font name (family)
 177       */
 178  	public function getName()
 179      {
 180          return $this->_name;
 181      }
 182  
 183      /**
 184       * @param string the font name (family)
 185       */
 186  	public function setName($value)
 187      {
 188          $this->_flags |= self::IS_SET_NAME;
 189          $this->_name=$value;
 190      }
 191  
 192      /**
 193       * @return boolean whether the font is empty
 194       */
 195  	public function getIsEmpty()
 196      {
 197          return !$this->_flags;
 198      }
 199  
 200      /**
 201       * Clears up the font.
 202       */
 203  	public function reset()
 204      {
 205          $this->_flags=0;
 206          $this->_name='';
 207          $this->_size='';
 208      }
 209  
 210      /**
 211       * Merges the font with a new one.
 212       * If a font field is not set in the font, it will be overwritten with
 213       * the new one.
 214       * @param TFont the new font
 215       */
 216  	public function mergeWith($font)
 217      {
 218          if($font===null || $font->_flags===0)
 219              return;
 220          if(!($this->_flags & self::IS_SET_BOLD) && ($font->_flags & self::IS_SET_BOLD))
 221              $this->setBold($font->getBold());
 222          if(!($this->_flags & self::IS_SET_ITALIC) && ($font->_flags & self::IS_SET_ITALIC))
 223              $this->setItalic($font->getItalic());
 224          if(!($this->_flags & self::IS_SET_OVERLINE) && ($font->_flags & self::IS_SET_OVERLINE))
 225              $this->setOverline($font->getOverline());
 226          if(!($this->_flags & self::IS_SET_STRIKEOUT) && ($font->_flags & self::IS_SET_STRIKEOUT))
 227              $this->setStrikeout($font->getStrikeout());
 228          if(!($this->_flags & self::IS_SET_UNDERLINE) && ($font->_flags & self::IS_SET_UNDERLINE))
 229              $this->setUnderline($font->getUnderline());
 230          if(!($this->_flags & self::IS_SET_SIZE) && ($font->_flags & self::IS_SET_SIZE))
 231              $this->setSize($font->getSize());
 232          if(!($this->_flags & self::IS_SET_NAME) && ($font->_flags & self::IS_SET_NAME))
 233              $this->setName($font->getName());
 234      }
 235  
 236      /**
 237       * Copies the fields in a new font to this font.
 238       * If a font field is set in the new font, the corresponding field
 239       * in this font will be overwritten.
 240       * @param TFont the new font
 241       */
 242  	public function copyFrom($font)
 243      {
 244          if($font===null || $font->_flags===0)
 245              return;
 246          if($font->_flags & self::IS_SET_BOLD)
 247              $this->setBold($font->getBold());
 248          if($font->_flags & self::IS_SET_ITALIC)
 249              $this->setItalic($font->getItalic());
 250          if($font->_flags & self::IS_SET_OVERLINE)
 251              $this->setOverline($font->getOverline());
 252          if($font->_flags & self::IS_SET_STRIKEOUT)
 253              $this->setStrikeout($font->getStrikeout());
 254          if($font->_flags & self::IS_SET_UNDERLINE)
 255              $this->setUnderline($font->getUnderline());
 256          if($font->_flags & self::IS_SET_SIZE)
 257              $this->setSize($font->getSize());
 258          if($font->_flags & self::IS_SET_NAME)
 259              $this->setName($font->getName());
 260      }
 261  
 262      /**
 263       * @return string the font in a css style string representation.
 264       */
 265  	public function toString()
 266      {
 267          if($this->_flags===0)
 268              return '';
 269          $str='';
 270          if($this->_flags & self::IS_SET_BOLD)
 271              $str.='font-weight:'.(($this->_flags & self::IS_BOLD)?'bold;':'normal;');
 272          if($this->_flags & self::IS_SET_ITALIC)
 273              $str.='font-style:'.(($this->_flags & self::IS_ITALIC)?'italic;':'normal;');
 274          $textDec='';
 275          if($this->_flags & self::IS_UNDERLINE)
 276              $textDec.='underline';
 277          if($this->_flags & self::IS_OVERLINE)
 278              $textDec.=' overline';
 279          if($this->_flags & self::IS_STRIKEOUT)
 280              $textDec.=' line-through';
 281          $textDec=ltrim($textDec);
 282          if($textDec!=='')
 283              $str.='text-decoration:'.$textDec.';';
 284          if($this->_size!=='')
 285              $str.='font-size:'.$this->_size.';';
 286          if($this->_name!=='')
 287              $str.='font-family:'.$this->_name.';';
 288          return $str;
 289      }
 290  
 291      /**
 292       * Adds attributes related to CSS styles to renderer.
 293       * @param THtmlWriter the writer used for the rendering purpose
 294       */
 295  	public function addAttributesToRender($writer)
 296      {
 297          if($this->_flags===0)
 298              return;
 299          if($this->_flags & self::IS_SET_BOLD)
 300              $writer->addStyleAttribute('font-weight',(($this->_flags & self::IS_BOLD)?'bold':'normal'));
 301          if($this->_flags & self::IS_SET_ITALIC)
 302              $writer->addStyleAttribute('font-style',(($this->_flags & self::IS_ITALIC)?'italic':'normal'));
 303          $textDec='';
 304          if($this->_flags & self::IS_UNDERLINE)
 305              $textDec.='underline';
 306          if($this->_flags & self::IS_OVERLINE)
 307              $textDec.=' overline';
 308          if($this->_flags & self::IS_STRIKEOUT)
 309              $textDec.=' line-through';
 310          $textDec=ltrim($textDec);
 311          if($textDec!=='')
 312              $writer->addStyleAttribute('text-decoration',$textDec);
 313          if($this->_size!=='')
 314              $writer->addStyleAttribute('font-size',$this->_size);
 315          if($this->_name!=='')
 316              $writer->addStyleAttribute('font-family',$this->_name);
 317      }
 318  }
 319  ?>


Généré le : Sun Feb 25 21:07:04 2007 par Balluche grâce à PHPXref 0.7