|
eZ Publish
[4.0]
|
00001 <?php 00002 // 00003 // Definition of eZImageFont class 00004 // 00005 // Created on: <03-Oct-2002 15:05:09 amos> 00006 // 00007 // ## BEGIN COPYRIGHT, LICENSE AND WARRANTY NOTICE ## 00008 // SOFTWARE NAME: eZ Publish 00009 // SOFTWARE RELEASE: 4.0.x 00010 // COPYRIGHT NOTICE: Copyright (C) 1999-2008 eZ Systems AS 00011 // SOFTWARE LICENSE: GNU General Public License v2.0 00012 // NOTICE: > 00013 // This program is free software; you can redistribute it and/or 00014 // modify it under the terms of version 2.0 of the GNU General 00015 // Public License as published by the Free Software Foundation. 00016 // 00017 // This program is distributed in the hope that it will be useful, 00018 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00019 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00020 // GNU General Public License for more details. 00021 // 00022 // You should have received a copy of version 2.0 of the GNU General 00023 // Public License along with this program; if not, write to the Free 00024 // Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 00025 // MA 02110-1301, USA. 00026 // 00027 // 00028 // ## END COPYRIGHT, LICENSE AND WARRANTY NOTICE ## 00029 // 00030 00031 /*! \file ezimagefont.php 00032 */ 00033 00034 /*! 00035 \class eZImageFont ezimagefont.php 00036 \ingroup eZImageObject 00037 \brief Specifies a font used for drawing text 00038 00039 Font attributes are encapsulated for use with the eZImageInterface::drawText function. 00040 The class stores the family, pointsize and path. Alternatively an x and y adjustment may 00041 be specified incase the font rendering is wrong. 00042 00043 Typical usage: 00044 \code 00045 if ( eZImageFont::exists( 'arial', 'design/standard/fonts' ) ) 00046 $font = new eZImageFont( 'arial', 30, 'design/standard/fonts' ); 00047 \enccode 00048 00049 All attributes can be modified later on with setFamily, setPath, setPointSize, setXAdjustment and setYAdjustment. 00050 */ 00051 00052 class eZImageFont 00053 { 00054 /*! 00055 Initializes the object with a family, point size and path. 00056 X and y adjustment may also be specified. 00057 */ 00058 function eZImageFont( $family, $size, $path, 00059 $xAdjustment = 0, $yAdjustment = 0 ) 00060 { 00061 $this->FontFamily = $family; 00062 $this->FontPath = $path; 00063 $this->PointSize = $size; 00064 00065 $this->XAdjustment = $xAdjustment; 00066 $this->YAdjustment = $yAdjustment; 00067 00068 $this->initialize(); 00069 } 00070 00071 /*! 00072 \return the font family, eg. arial, times 00073 */ 00074 function family() 00075 { 00076 return $this->FontFamily; 00077 } 00078 00079 /*! 00080 \return the path to font files, it may be a string or an array of strings. 00081 */ 00082 function path() 00083 { 00084 return $this->FontPath; 00085 } 00086 00087 /*! 00088 \return the font file if it has been initialized. 00089 \sa realFile, fontFile, initialize. 00090 */ 00091 function file() 00092 { 00093 return $this->FontFile; 00094 } 00095 00096 /*! 00097 Similar to file but returns the absolute path to the font file. 00098 This is required for GD font handling. 00099 */ 00100 function realFile() 00101 { 00102 return realpath( "." ) . "/" . $this->FontFile; 00103 } 00104 00105 /*! 00106 \return the point size of the font. 00107 */ 00108 function pointSize() 00109 { 00110 return $this->PointSize; 00111 } 00112 00113 /*! 00114 \return the number of pixels in the x direction to adjust the font output. 00115 \sa yAdjustment 00116 */ 00117 function xAdjustment() 00118 { 00119 return $this->XAdjustment; 00120 } 00121 00122 /*! 00123 \return the number of pixels in the y direction to adjust the font output. 00124 \sa xAdjustment 00125 */ 00126 function yAdjustment() 00127 { 00128 return $this->YAdjustment; 00129 } 00130 00131 /*! 00132 Sets the font family to \a $family. 00133 \note Changing the font family will reinitialize the font. 00134 */ 00135 function setFamily( $family ) 00136 { 00137 $this->FontFamily = $family; 00138 $this->initialize(); 00139 } 00140 00141 /*! 00142 Sets the font path which is used when searching for fonts, the path can either be 00143 a string or an array of strings. 00144 \note Changing the font path will reinitialize the font. 00145 */ 00146 function setPath( $path ) 00147 { 00148 $this->FontPath = $path; 00149 $this->initialize(); 00150 } 00151 00152 /*! 00153 Sets the point size of the font to \a $size. 00154 */ 00155 function setPointSize( $size ) 00156 { 00157 $this->PointSize = $size; 00158 } 00159 00160 /*! 00161 Sets the number of pixels in the x direction to adjust the font output to \a $adjustment. 00162 \sa setYAdjustment 00163 */ 00164 function setXAdjustment( $adjustment ) 00165 { 00166 $this->XAdjustment = $adjustment; 00167 } 00168 00169 /*! 00170 Sets the number of pixels in the y direction to adjust the font output to \a $adjustment. 00171 \sa setXAdjustment 00172 */ 00173 function setYAdjustment( $adjustment ) 00174 { 00175 $this->YAdjustment = $adjustment; 00176 } 00177 00178 /*! 00179 Sets the number of pixels to adjust the font output to \a $xAdjustment and \a $yAdjustment. 00180 \sa setXAdjustment, setYAdjustment 00181 */ 00182 function setAdjustment( $xAdjustment, $yAdjustment ) 00183 { 00184 $this->XAdjustment = $xAdjustment; 00185 $this->YAdjustment = $yAdjustment; 00186 } 00187 00188 /*! 00189 \static 00190 \return true if the font family \a $fontFamily exists in the path \a $fontPath. 00191 The path can be specified as a string or an array of strings. 00192 */ 00193 static function exists( $fontFamily, $fontPath ) 00194 { 00195 return eZImageFont::fontFile( $fontFamily, $fontPath ) != false; 00196 } 00197 00198 /*! 00199 \private 00200 Initializes the font file attribute by searching for the font. 00201 */ 00202 function initialize() 00203 { 00204 $this->FontFile = eZImageFont::fontFile( $this->FontFamily, $this->FontPath ); 00205 } 00206 00207 /*! 00208 \static 00209 \return the file path for the font if it is found or \c false if no font could be used. 00210 The font must be named equal to the \a $fontFamily parameter 00211 with the .ttf suffix, eg. arial.ttf. 00212 \param fontPath The path to the fonts or an array of paths. 00213 */ 00214 static function fontFile( $fontFamily, $fontPath ) 00215 { 00216 if ( preg_match( '/\.ttf$/i', $fontFamily ) ) 00217 $family_file = $fontFamily; 00218 else 00219 $family_file = $fontFamily . '.ttf'; 00220 if ( $fontPath != null ) 00221 { 00222 if ( !is_array( $fontPath ) ) 00223 $fontPath = array( $fontPath ); 00224 foreach ( $fontPath as $singleFontPath ) 00225 { 00226 $font = $singleFontPath . "/$family_file"; 00227 if ( !file_exists( $font ) ) 00228 $font = false; 00229 else 00230 return $font; 00231 } 00232 } 00233 else 00234 $font = $fontFamily; 00235 return $font; 00236 } 00237 00238 /// \privatesection 00239 /// The current font family 00240 public $FontFamily; 00241 /// The path or path array to the fonts 00242 public $FontPath; 00243 /// The path to the font file one was found 00244 public $FontFile; 00245 /// The size of the font in points. 00246 public $PointSize; 00247 /// Adjustment in the x direction 00248 public $XAdjustment; 00249 /// Adjustment in the y direction 00250 public $YAdjustment; 00251 } 00252 00253 ?>