[ Index ] |
|
Code source de eZ Publish 3.9.0 |
1 <?php 2 // 3 // Definition of eZImageFont class 4 // 5 // Created on: <03-Oct-2002 15:05:09 amos> 6 // 7 // SOFTWARE NAME: eZ publish 8 // SOFTWARE RELEASE: 3.9.0 9 // BUILD VERSION: 17785 10 // COPYRIGHT NOTICE: Copyright (C) 1999-2006 eZ systems AS 11 // SOFTWARE LICENSE: GNU General Public License v2.0 12 // NOTICE: > 13 // This program is free software; you can redistribute it and/or 14 // modify it under the terms of version 2.0 of the GNU General 15 // Public License as published by the Free Software Foundation. 16 // 17 // This program is distributed in the hope that it will be useful, 18 // but WITHOUT ANY WARRANTY; without even the implied warranty of 19 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 20 // GNU General Public License for more details. 21 // 22 // You should have received a copy of version 2.0 of the GNU General 23 // Public License along with this program; if not, write to the Free 24 // Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 25 // MA 02110-1301, USA. 26 // 27 // 28 29 /*! \file ezimagefont.php 30 */ 31 32 /*! 33 \class eZImageFont ezimagefont.php 34 \ingroup eZImageObject 35 \brief Specifies a font used for drawing text 36 37 Font attributes are encapsulated for use with the eZImageInterface::drawText function. 38 The class stores the family, pointsize and path. Alternatively an x and y adjustment may 39 be specified incase the font rendering is wrong. 40 41 Typical usage: 42 \code 43 if ( eZImageFont::exists( 'arial', 'design/standard/fonts' ) ) 44 $font = new eZImageFont( 'arial', 30, 'design/standard/fonts' ); 45 \enccode 46 47 All attributes can be modified later on with setFamily, setPath, setPointSize, setXAdjustment and setYAdjustment. 48 */ 49 50 class eZImageFont 51 { 52 /*! 53 Initializes the object with a family, point size and path. 54 X and y adjustment may also be specified. 55 */ 56 function eZImageFont( $family, $size, $path, 57 $xAdjustment = 0, $yAdjustment = 0 ) 58 { 59 $this->FontFamily = $family; 60 $this->FontPath = $path; 61 $this->PointSize = $size; 62 63 $this->XAdjustment = $xAdjustment; 64 $this->YAdjustment = $yAdjustment; 65 66 $this->initialize(); 67 } 68 69 /*! 70 \return the font family, eg. arial, times 71 */ 72 function family() 73 { 74 return $this->FontFamily; 75 } 76 77 /*! 78 \return the path to font files, it may be a string or an array of strings. 79 */ 80 function path() 81 { 82 return $this->FontPath; 83 } 84 85 /*! 86 \return the font file if it has been initialized. 87 \sa realFile, fontFile, initialize. 88 */ 89 function file() 90 { 91 return $this->FontFile; 92 } 93 94 /*! 95 Similar to file but returns the absolute path to the font file. 96 This is required for GD font handling. 97 */ 98 function realFile() 99 { 100 return realpath( "." ) . "/" . $this->FontFile; 101 } 102 103 /*! 104 \return the point size of the font. 105 */ 106 function pointSize() 107 { 108 return $this->PointSize; 109 } 110 111 /*! 112 \return the number of pixels in the x direction to adjust the font output. 113 \sa yAdjustment 114 */ 115 function xAdjustment() 116 { 117 return $this->XAdjustment; 118 } 119 120 /*! 121 \return the number of pixels in the y direction to adjust the font output. 122 \sa xAdjustment 123 */ 124 function yAdjustment() 125 { 126 return $this->YAdjustment; 127 } 128 129 /*! 130 Sets the font family to \a $family. 131 \note Changing the font family will reinitialize the font. 132 */ 133 function setFamily( $family ) 134 { 135 $this->FontFamily = $family; 136 $this->initialize(); 137 } 138 139 /*! 140 Sets the font path which is used when searching for fonts, the path can either be 141 a string or an array of strings. 142 \note Changing the font path will reinitialize the font. 143 */ 144 function setPath( $path ) 145 { 146 $this->FontPath = $path; 147 $this->initialize(); 148 } 149 150 /*! 151 Sets the point size of the font to \a $size. 152 */ 153 function setPointSize( $size ) 154 { 155 $this->PointSize = $size; 156 } 157 158 /*! 159 Sets the number of pixels in the x direction to adjust the font output to \a $adjustment. 160 \sa setYAdjustment 161 */ 162 function setXAdjustment( $adjustment ) 163 { 164 $this->XAdjustment = $adjustment; 165 } 166 167 /*! 168 Sets the number of pixels in the y direction to adjust the font output to \a $adjustment. 169 \sa setXAdjustment 170 */ 171 function setYAdjustment( $adjustment ) 172 { 173 $this->YAdjustment = $adjustment; 174 } 175 176 /*! 177 Sets the number of pixels to adjust the font output to \a $xAdjustment and \a $yAdjustment. 178 \sa setXAdjustment, setYAdjustment 179 */ 180 function setAdjustment( $xAdjustment, $yAdjustment ) 181 { 182 $this->XAdjustment = $xAdjustment; 183 $this->YAdjustment = $yAdjustment; 184 } 185 186 /*! 187 \static 188 \return true if the font family \a $fontFamily exists in the path \a $fontPath. 189 The path can be specified as a string or an array of strings. 190 */ 191 function exists( $fontFamily, $fontPath ) 192 { 193 return eZImageFont::fontFile( $fontFamily, $fontPath ) != false; 194 } 195 196 /*! 197 \private 198 Initializes the font file attribute by searching for the font. 199 */ 200 function initialize() 201 { 202 $this->FontFile = eZImageFont::fontFile( $this->FontFamily, $this->FontPath ); 203 } 204 205 /*! 206 \static 207 \return the file path for the font if it is found or \c false if no font could be used. 208 The font must be named equal to the \a $fontFamily parameter 209 with the .ttf suffix, eg. arial.ttf. 210 \param fontPath The path to the fonts or an array of paths. 211 */ 212 function fontFile( $fontFamily, $fontPath ) 213 { 214 if ( preg_match( '/\.ttf$/i', $fontFamily ) ) 215 $family_file = $fontFamily; 216 else 217 $family_file = $fontFamily . '.ttf'; 218 if ( $fontPath != null ) 219 { 220 if ( !is_array( $fontPath ) ) 221 $fontPath = array( $fontPath ); 222 foreach ( $fontPath as $singleFontPath ) 223 { 224 $font = $singleFontPath . "/$family_file"; 225 if ( !file_exists( $font ) ) 226 $font = false; 227 else 228 return $font; 229 } 230 } 231 else 232 $font = $fontFamily; 233 return $font; 234 } 235 236 /// \privatesection 237 /// The current font family 238 var $FontFamily; 239 /// The path or path array to the fonts 240 var $FontPath; 241 /// The path to the font file one was found 242 var $FontFile; 243 /// The size of the font in points. 244 var $PointSize; 245 /// Adjustment in the x direction 246 var $XAdjustment; 247 /// Adjustment in the y direction 248 var $YAdjustment; 249 } 250 251 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Sat Feb 24 10:30:04 2007 | par Balluche grâce à PHPXref 0.7 |