- <?
- /**
- * Class CFont definition module
- *
- * @copyright sptpl_clsFont.php is part of Sptpl project {@link http://www.andrioli.com/en/sptpl.html} and it is LGPL
- * @author Andrioli Darvin <darvin (inside) andrioli (dot) com>
- * @version $Header: d:\cvs/classistd/sptpl/sptpl_clsFont.php,v 2.7 2005/03/17 12:46:48 Darvin Exp $
- */
- /*
- * +-------------------------------------------------------------------------+
- * | Sptpl |
- * +-------------------------------------------------------------------------+
- * | Copyright (c) 2003-2005 Andrioli Darvin |
- * | Email <darvin (inside) andrioli (dot) com> |
- * | Web http://www.andrioli.com/en/sptpl.html |
- * | Download http://www.phpclasses.org/browse.html/package/1326.html |
- * | |
- * +-------------------------------------------------------------------------+
- * | This library is free software; you can redistribute it and/or modify |
- * | it under the terms of the GNU Lesser General Public License as |
- * | published by the Free Software Foundation; either version 2 of the |
- * | License, or (at your option) any later version. |
- * | |
- * | This library is distributed in the hope that it will be useful, but |
- * | WITHOUT ANY WARRANTY; without even the implied warranty of |
- * | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
- * | Lesser General Public License for more details. |
- * | |
- * | You should have received a copy of the GNU Lesser General Public |
- * | License along with this library; if not, write to the Free Software |
- * | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
- * +-------------------------------------------------------------------------+
- */
-
-
-
- class CFont {
-
- /**
- * Font identifier, used as key to access to this font
- * from CRow
- * @var string $Id
- */
- var $Id;
- /**
- * Font face
- * @var string $Face
- */
- var $Face;
- /**
- * Font size
- * @var int $Size
- */
- var $Size;
- /**
- * Font width
- * @var int $Size
- */
- var $width;
- /**
- * Font height
- * @var int $Height
- */
- var $Height;
- /**
- * Is the font bold
- * @var boolean $Bold
- */
- var $Bold;
- /**
- * Is the font underlined
- * @var boolean $Underline
- */
- var $Underline;
- /**
- * Is the font italic
- * @var boolean $Italic
- */
- var $Italic;
-
- /**
- * class initializer
- *
- * @param object DomNode $node DOMXML node holding the configuration information
- * for the font
- * @access public
- */
- function CFont($node=NULL)
- {
- $this->Id='';
- $this->Face='Courier New';
- $this->Size='12';
- $this->Height=ceil($this->Size/2);
- $this->Bold=FALSE;
- $this->Underline=FALSE;
- $this->Italic=FALSE;
- if($node!=NULL)
- $this->ParseXml($node);
- }
-
- /**
- * Parse the configuration file
- *
- * @param object CXml2Array $Cfg CXml2Array node holding the configuration information
- * for the font
- * @access public
- */
- function ParseXml($Cfg)
- {
- // Check some attribute
- while(($ret=$Cfg->EachAttribute())!=FALSE)
- {
- list($AttribName,$value)=$ret;
- switch(strtolower($AttribName))
- {
- case 'id' :
- $this->Id=$value;
- break;
- case 'face' :
- $this->Face=$value;
- break;
- case 'size' :
- $this->Size=$value;
- $this->Height=$value;
- if(!is_numeric($this->Size))
- trigger_error('Configuration error: font with attribute size not numeric',E_USER_ERROR);
- $this->Width=$this->Size;
- break;
- case 'underline' :
- $this->Underline=(strtolower($value)=='n')?FALSE:TRUE;
- break;
- case 'bold' :
- $this->Bold=(strtolower($value)=='n')?FALSE:TRUE;
- break;
- case 'italic' :
- $this->Italic=(strtolower($value)=='n')?FALSE:TRUE;
- break;
- }
-
- }
- if($this->Id=='')
- trigger_error('Configuration error: font without attribute id',E_USER_ERROR);
- if(!is_numeric($this->Size))
- trigger_error('Configuration error: font with attribute size not numeric',E_USER_ERROR);
- }
-
- /**
- * Return the identifier for this font. The id is the key to
- * access to this font from the row
- *
- * @access public
- */
-
- function GetId()
- {
- return($this->Id);
- }
-
- /**
- * Property Face get value
- * @access public
- * @return string
- */
- function GetFace()
- {
- return($this->Face);
- }
- /**
- * Property Size get value
- * @access public
- * @return string
- */
- function GetSize()
- {
- return($this->Size);
- }
- /**
- * Property width get value
- * @access public
- * @return string
- */
- function GetWidth()
- {
- return($this->width);
- }
- /**
- * Property Height get value
- * @access public
- * @return string
- */
- function GetHeight()
- {
- return($this->Height);
- }
- /**
- * Property Bold get value
- * @access public
- * @return string
- */
- function GetBold()
- {
- return($this->Bold);
- }
- /**
- * Property Underline get value
- * @access public
- * @return string
- */
- function GetUnderline()
- {
- return($this->Underline);
- }
- /**
- * Property Italic get value
- * @access public
- * @return string
- */
- function GetItalic()
- {
- return($this->Italic);
- }
-
- /**
- * return the string length
- * @param string
- * @return integer
- * @access public
- */
- function strlen($text)
- {
- return(strlen($text)*$this->Width);
- }
-
- /**
- * return the high the characters
- * @return integer
- * @access public
- */
- function GetFontHeight($text='')
- {
- return($this->Height);
- }
- }
-
- /**
- * Extension of the font class used to support the Printer output. Used by CPagePrinter
- */
- class CPrFont extends CFont
- {
-
- function CPrFont($node=NULL)
- {
- parent::CFont($node);
- }
-
- /**
- * Parse the configuration file. Call the parent parsing function.
- * The real difference betwenn the base class: the size si multiply by 20
- *
- * @param object CXml2Array $Cfg CXml2Array node holding the configuration information
- * for the font
- * @access public
- */
- function ParseXml($Cfg)
- {
- parent::ParseXml($Cfg);
- $this->Width=ceil($this->Size/2);
- $this->Height*=20;
- $this->Width*=20;
- $this->Size*=20;
- }
-
- }
- /
- * Extension of the font class used the PostScript output
- */
-
- class CPsFont extends CFont
- {
- /**
- * private handler of the ps module used to get the real size of the
- * font
- * @var object Ps
- */
- var $clsPs;
- /**
- * Postscript font handler
- * @var resource
- */
- var $psfont;
- function CPsFont($node=NULL)
- {
- parent::CFont($node);
- if(strtolower(substr($this->Face,-4))=='.afm')
- {
- // wipe out the extension from the fonr name. the ps module doesn't need it.
- $this->Face=substr($this->Face,0,-4);
- }
- }
- /**
- * Set the PostScript module handler from pagemanager
- * @var resource
- */
- function SetPsHandler($Handler)
- {
- $this->clsPs=$Handler;
- $this->psfont=ps_findfont($this->clsPs, $this->Face, "", 0);
- $text='Wgq';
- ps_setfont($this->clsPs, $this->psfont, $this->Size);
- $size=ps_string_geometry($this->clsPs,$text);
- $this->Height=floor((abs($size['descender'])+$size['ascender']+5)*20);
- }
- /**
- * Property Size get value
- * @access public
- * @return string
- */
- function GetSize()
- {
- return($this->Size*20);
- }
- /**
- * Property width get value
- * @access public
- * @return string
- */
- function GetWidth()
- {
- return($this->width*20);
- }
- /**
- * Property Height get value
- * @access public
- * @return string
- */
- function GetHeight()
- {
- return($this->Height);
- }
- /**
- * Parse the configuration file. Call the parent parsing function. At the end
- * set the font into its own Cpdf istance
- *
- * @param object CXml2Array $Cfg CXml2Array node holding the configuration information
- * for the font
- * @access public
- */
- function ParseXml($Cfg)
- {
- parent::ParseXml($Cfg);
- }
- /**
- * return the string length
- * @param string
- * @return integer
- * @access public
- */
- function strlen($text)
- {
- $o=ps_setfont($this->clsPs, $this->psfont, $this->Size);
-
- if(strlen($text)>0)
- {
- switch($this->Size)
- {
- case 8: $fix=1.6;
- break;
- case 9: $fix=1.6;
- break;
- case 10: $fix=1.5;
- break;
- case 11: $fix=1.5;
- break;
- case 12: $fix=1.4;
- break;
- default:
- if($this->Size<8)
- $fix=1.6;
- if($this->Size>12)
- $fix=1.3;
- }
- $txtlen=ps_stringwidth($this->clsPs,$text)*$fix;
- }
- else
- $txtlen=0;
- // echo "\n->$text<- $o - ".$this->Size." - ".$this->Face." - ".floor($txtlen*20);
- return(floor($txtlen*20));
- }
-
- /**
- * return the high the characters
- * @return integer
- * @access public
- */
- function GetFontHeight($text='Wgq')
- {
- ps_setfont($this->clsPs, $this->psfont, $this->Size);
- $size=ps_string_geometry($this->clsPs,$text);
- $this->Height=floor((abs($size['descender'])+$size['ascender']+10)*20);
- return($this->Height);
- }
- }
-
- /**
- * Extension of the font class used to support the Pdf output. Used by CPagePdf
- */
- class CPdfFont extends CFont
- {
-
- /**
- * private instance of the pdf class used to get the real size of the
- * font
- * @var object Cpdf
- */
- var $clsPdf;
- function CPdfFont($node=NULL)
- {
- parent::CFont($node);
- }
-
- /**
- * Parse the configuration file. Call the parent parsing function. At the end
- * set the font into its own Cpdf istance
- *
- * @param object CXml2Array $Cfg CXml2Array node holding the configuration information
- * for the font
- * @access public
- */
- function ParseXml($Cfg)
- {
- parent::ParseXml($Cfg);
- $this->clsPdf=new Cpdf();
- $this->clsPdf->selectFont(PDFFONTDIR.$this->Face);
- }
-
- /**
- * return the string length
- * @param string
- * @return integer
- * @access public
- */
- function strlen($text)
- {
- if(strlen($text)>0)
- $txtlen=$this->clsPdf->getTextWidth($this->Size,$text);
- else
- $txtlen=0;
- return($txtlen);
- }
-
- /**
- * return the high the characters
- * @return integer
- * @access public
- */
- function GetFontHeight($text='')
- {
- return($this->clsPdf->getFontHeight($this->Size));
- }
- /
-
- }
- ?>