[ Index ] |
|
Code source de jpGraph 2.2 |
1 <?php 2 //======================================================================= 3 // File: jpgraph_ttf.inc.php 4 // Description: Handling of TTF fonts 5 // Created: 2006-11-19 6 // Ver: $Id: jpgraph_ttf.inc.php 805 2006-11-28 07:45:54Z ljp $ 7 // 8 // Copyright (c) Aditus Consulting. All rights reserved. 9 //======================================================================== 10 11 // TTF Font families 12 DEFINE("FF_COURIER",10); 13 DEFINE("FF_VERDANA",11); 14 DEFINE("FF_TIMES",12); 15 DEFINE("FF_COMIC",14); 16 DEFINE("FF_ARIAL",15); 17 DEFINE("FF_GEORGIA",16); 18 DEFINE("FF_TREBUCHE",17); 19 20 // Gnome Vera font 21 // Available from http://www.gnome.org/fonts/ 22 DEFINE("FF_VERA",18); 23 DEFINE("FF_VERAMONO",19); 24 DEFINE("FF_VERASERIF",20); 25 26 // Chinese font 27 DEFINE("FF_SIMSUN",30); 28 DEFINE("FF_CHINESE",31); 29 DEFINE("FF_BIG5",31); 30 31 // Japanese font 32 DEFINE("FF_MINCHO",40); 33 DEFINE("FF_PMINCHO",41); 34 DEFINE("FF_GOTHIC",42); 35 DEFINE("FF_PGOTHIC",43); 36 37 // Hebrew fonts 38 DEFINE("FF_DAVID",44); 39 DEFINE("FF_MIRIAM",45); 40 DEFINE("FF_AHRON",46); 41 42 // Extra fonts 43 // Download fonts from 44 // http://www.webfontlist.com 45 // http://www.webpagepublicity.com/free-fonts.html 46 47 DEFINE("FF_SPEEDO",50); // This font is also known as Bauer (Used for gauge fascia) 48 DEFINE("FF_DIGITAL",51); // Digital readout font 49 DEFINE("FF_COMPUTER",52); // The classic computer font 50 DEFINE("FF_CALCULATOR",53); // Triad font 51 52 // Limits for fonts 53 DEFINE("_FIRST_FONT",10); 54 DEFINE("_LAST_FONT",53); 55 56 // TTF Font styles 57 DEFINE("FS_NORMAL",9001); 58 DEFINE("FS_BOLD",9002); 59 DEFINE("FS_ITALIC",9003); 60 DEFINE("FS_BOLDIT",9004); 61 DEFINE("FS_BOLDITALIC",9004); 62 63 //Definitions for internal font 64 DEFINE("FF_FONT0",1); 65 DEFINE("FF_FONT1",2); 66 DEFINE("FF_FONT2",4); 67 68 //================================================================= 69 // CLASS LanguageConv 70 // Description: 71 // Converts various character encoding into proper 72 // UTF-8 depending on how the library have been configured and 73 // what font family is being used 74 //================================================================= 75 class LanguageConv { 76 private $g2312 = null ; 77 78 function Convert($aTxt,$aFF) { 79 if( LANGUAGE_GREEK ) { 80 if( GREEK_FROM_WINDOWS ) { 81 $unistring = LanguageConv::gr_win2uni($aTxt); 82 } else { 83 $unistring = LanguageConv::gr_iso2uni($aTxt); 84 } 85 return $unistring; 86 } elseif( LANGUAGE_CYRILLIC ) { 87 if( CYRILLIC_FROM_WINDOWS && (!defined('LANGUAGE_CHARSET') || stristr(LANGUAGE_CHARSET, 'windows-1251')) ) { 88 $aTxt = convert_cyr_string($aTxt, "w", "k"); 89 } 90 if( !defined('LANGUAGE_CHARSET') || stristr(LANGUAGE_CHARSET, 'koi8-r') || stristr(LANGUAGE_CHARSET, 'windows-1251')) { 91 $isostring = convert_cyr_string($aTxt, "k", "i"); 92 $unistring = LanguageConv::iso2uni($isostring); 93 } 94 else { 95 $unistring = $aTxt; 96 } 97 return $unistring; 98 } 99 elseif( $aFF === FF_SIMSUN ) { 100 // Do Chinese conversion 101 if( $this->g2312 == null ) { 102 include_once 'jpgraph_gb2312.php' ; 103 $this->g2312 = new GB2312toUTF8(); 104 } 105 return $this->g2312->gb2utf8($aTxt); 106 } 107 elseif( $aFF === FF_CHINESE ) { 108 if( !function_exists('iconv') ) { 109 JpGraphError::RaiseL(25006); 110 //('Usage of FF_CHINESE (FF_BIG5) font family requires that your PHP setup has the iconv() function. By default this is not compiled into PHP (needs the "--width-iconv" when configured).'); 111 } 112 return iconv('BIG5','UTF-8',$aTxt); 113 } 114 elseif( ASSUME_EUCJP_ENCODING && 115 ($aFF == FF_MINCHO || $aFF == FF_GOTHIC || $aFF == FF_PMINCHO || $aFF == FF_PGOTHIC) ) { 116 if( !function_exists('mb_convert_encoding') ) { 117 JpGraphError::RaiseL(25127); 118 } 119 return mb_convert_encoding($aTxt, 'UTF-8','EUC-JP'); 120 } 121 elseif( $aFF == FF_DAVID || $aFF == FF_MIRIAM || $aFF == FF_AHRON ) { 122 return LanguageConv::heb_iso2uni($aTxt); 123 } 124 else 125 return $aTxt; 126 } 127 128 // Translate iso encoding to unicode 129 public static function iso2uni ($isoline){ 130 $uniline=''; 131 for ($i=0; $i < strlen($isoline); $i++){ 132 $thischar=substr($isoline,$i,1); 133 $charcode=ord($thischar); 134 $uniline.=($charcode>175) ? "&#" . (1040+($charcode-176)). ";" : $thischar; 135 } 136 return $uniline; 137 } 138 139 // Translate greek iso encoding to unicode 140 public static function gr_iso2uni ($isoline) { 141 $uniline=''; 142 for ($i=0; $i < strlen($isoline); $i++) { 143 $thischar=substr($isoline,$i,1); 144 $charcode=ord($thischar); 145 $uniline.=($charcode>179 && $charcode!=183 && $charcode!=187 && $charcode!=189) ? "&#" . (900+($charcode-180)). ";" : $thischar; 146 } 147 return $uniline; 148 } 149 150 // Translate greek win encoding to unicode 151 public static function gr_win2uni ($winline) { 152 $uniline=''; 153 for ($i=0; $i < strlen($winline); $i++) { 154 $thischar=substr($winline,$i,1); 155 $charcode=ord($thischar); 156 if ($charcode==161 || $charcode==162) { 157 $uniline.="&#" . (740+$charcode). ";"; 158 } 159 else { 160 $uniline.=(($charcode>183 && $charcode!=187 && $charcode!=189) || $charcode==180) ? "&#" . (900+($charcode-180)). ";" : $thischar; 161 } 162 } 163 return $uniline; 164 } 165 166 public static function heb_iso2uni($isoline) { 167 $isoline = hebrev($isoline); 168 $o = ''; 169 170 $n = strlen($isoline); 171 for($i=0; $i < $n; $i++) { 172 $c=ord( substr($isoline,$i,1) ); 173 $o .= ($c > 223) && ($c < 251) ? '&#'.(1264+$c).';' : chr($c); 174 } 175 return utf8_encode($o); 176 } 177 } 178 179 //============================================================= 180 // CLASS TTF 181 // Description: Handle TTF font names and mapping and loading of 182 // font files 183 //============================================================= 184 class TTF { 185 private $font_files,$style_names; 186 187 //--------------- 188 // CONSTRUCTOR 189 function TTF() { 190 191 // String names for font styles to be used in error messages 192 $this->style_names=array(FS_NORMAL =>'normal', 193 FS_BOLD =>'bold', 194 FS_ITALIC =>'italic', 195 FS_BOLDITALIC =>'bolditalic'); 196 197 // File names for available fonts 198 $this->font_files=array( 199 FF_COURIER => array(FS_NORMAL =>'cour.ttf', 200 FS_BOLD =>'courbd.ttf', 201 FS_ITALIC =>'couri.ttf', 202 FS_BOLDITALIC =>'courbi.ttf' ), 203 FF_GEORGIA => array(FS_NORMAL =>'georgia.ttf', 204 FS_BOLD =>'georgiab.ttf', 205 FS_ITALIC =>'georgiai.ttf', 206 FS_BOLDITALIC =>'' ), 207 FF_TREBUCHE =>array(FS_NORMAL =>'trebuc.ttf', 208 FS_BOLD =>'trebucbd.ttf', 209 FS_ITALIC =>'trebucit.ttf', 210 FS_BOLDITALIC =>'trebucbi.ttf' ), 211 FF_VERDANA => array(FS_NORMAL =>'verdana.ttf', 212 FS_BOLD =>'verdanab.ttf', 213 FS_ITALIC =>'verdanai.ttf', 214 FS_BOLDITALIC =>'' ), 215 FF_TIMES => array(FS_NORMAL =>'times.ttf', 216 FS_BOLD =>'timesbd.ttf', 217 FS_ITALIC =>'timesi.ttf', 218 FS_BOLDITALIC =>'timesbi.ttf' ), 219 FF_COMIC => array(FS_NORMAL =>'comic.ttf', 220 FS_BOLD =>'comicbd.ttf', 221 FS_ITALIC =>'', 222 FS_BOLDITALIC =>'' ), 223 FF_ARIAL => array(FS_NORMAL =>'arial.ttf', 224 FS_BOLD =>'arialbd.ttf', 225 FS_ITALIC =>'ariali.ttf', 226 FS_BOLDITALIC =>'arialbi.ttf' ) , 227 FF_VERA => array(FS_NORMAL =>'Vera.ttf', 228 FS_BOLD =>'VeraBd.ttf', 229 FS_ITALIC =>'VeraIt.ttf', 230 FS_BOLDITALIC =>'VeraBI.ttf' ), 231 FF_VERAMONO => array(FS_NORMAL =>'VeraMono.ttf', 232 FS_BOLD =>'VeraMoBd.ttf', 233 FS_ITALIC =>'VeraMoIt.ttf', 234 FS_BOLDITALIC =>'VeraMoBI.ttf' ), 235 FF_VERASERIF=> array(FS_NORMAL =>'VeraSe.ttf', 236 FS_BOLD =>'VeraSeBd.ttf', 237 FS_ITALIC =>'', 238 FS_BOLDITALIC =>'' ) , 239 240 /* Chinese fonts */ 241 FF_SIMSUN => array(FS_NORMAL =>'simsun.ttc', 242 FS_BOLD =>'simhei.ttf', 243 FS_ITALIC =>'', 244 FS_BOLDITALIC =>'' ), 245 FF_CHINESE => array(FS_NORMAL =>CHINESE_TTF_FONT, 246 FS_BOLD =>'', 247 FS_ITALIC =>'', 248 FS_BOLDITALIC =>'' ), 249 250 /* Japanese fonts */ 251 FF_MINCHO => array(FS_NORMAL =>MINCHO_TTF_FONT, 252 FS_BOLD =>'', 253 FS_ITALIC =>'', 254 FS_BOLDITALIC =>'' ), 255 FF_PMINCHO => array(FS_NORMAL =>PMINCHO_TTF_FONT, 256 FS_BOLD =>'', 257 FS_ITALIC =>'', 258 FS_BOLDITALIC =>'' ), 259 FF_GOTHIC => array(FS_NORMAL =>GOTHIC_TTF_FONT, 260 FS_BOLD =>'', 261 FS_ITALIC =>'', 262 FS_BOLDITALIC =>'' ), 263 FF_PGOTHIC => array(FS_NORMAL =>PGOTHIC_TTF_FONT, 264 FS_BOLD =>'', 265 FS_ITALIC =>'', 266 FS_BOLDITALIC =>'' ), 267 FF_MINCHO => array(FS_NORMAL =>PMINCHO_TTF_FONT, 268 FS_BOLD =>'', 269 FS_ITALIC =>'', 270 FS_BOLDITALIC =>'' ), 271 272 /* Hebrew fonts */ 273 FF_DAVID => array(FS_NORMAL =>'DAVIDNEW.TTF', 274 FS_BOLD =>'', 275 FS_ITALIC =>'', 276 FS_BOLDITALIC =>'' ), 277 278 FF_MIRIAM => array(FS_NORMAL =>'MRIAMY.TTF', 279 FS_BOLD =>'', 280 FS_ITALIC =>'', 281 FS_BOLDITALIC =>'' ), 282 283 FF_AHRON => array(FS_NORMAL =>'ahronbd.ttf', 284 FS_BOLD =>'', 285 FS_ITALIC =>'', 286 FS_BOLDITALIC =>'' ), 287 288 /* Misc fonts */ 289 FF_DIGITAL => array(FS_NORMAL =>'DIGIRU__.TTF', 290 FS_BOLD =>'Digirtu_.ttf', 291 FS_ITALIC =>'Digir___.ttf', 292 FS_BOLDITALIC =>'DIGIRT__.TTF' ), 293 FF_SPEEDO => array(FS_NORMAL =>'Speedo.ttf', 294 FS_BOLD =>'', 295 FS_ITALIC =>'', 296 FS_BOLDITALIC =>'' ), 297 FF_COMPUTER => array(FS_NORMAL =>'COMPUTER.TTF', 298 FS_BOLD =>'', 299 FS_ITALIC =>'', 300 FS_BOLDITALIC =>'' ), 301 FF_CALCULATOR => array(FS_NORMAL =>'Triad_xs.ttf', 302 FS_BOLD =>'', 303 FS_ITALIC =>'', 304 FS_BOLDITALIC =>'' ), 305 ); 306 } 307 308 //--------------- 309 // PUBLIC METHODS 310 // Create the TTF file from the font specification 311 function File($family,$style=FS_NORMAL) { 312 $fam = @$this->font_files[$family]; 313 if( !$fam ) { 314 JpGraphError::RaiseL(25046,$family);//("Specified TTF font family (id=$family) is unknown or does not exist. Please note that TTF fonts are not distributed with JpGraph for copyright reasons. You can find the MS TTF WEB-fonts (arial, courier etc) for download at http://corefonts.sourceforge.net/"); 315 } 316 $f = @$fam[$style]; 317 318 if( $f==='' ) 319 JpGraphError::RaiseL(25047,$this->style_names[$style],$this->font_files[$family][FS_NORMAL]);//('Style "'.$this->style_names[$style].'" is not available for font family '.$this->font_files[$family][FS_NORMAL].'.'); 320 if( !$f ) { 321 JpGraphError::RaiseL(25048,$fam);//("Unknown font style specification [$fam]."); 322 } 323 324 if ($family >= FF_MINCHO && $family <= FF_PGOTHIC) { 325 $f = MBTTF_DIR.$f; 326 } else { 327 $f = TTF_DIR.$f; 328 } 329 330 if( file_exists($f) === false || is_readable($f) === false ) { 331 JpGraphError::RaiseL(25049,$f);//("Font file \"$f\" is not readable or does not exist."); 332 } 333 return $f; 334 } 335 } // Class 336 337 338 339 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Sat Nov 24 09:27:55 2007 | par Balluche grâce à PHPXref 0.7 |
![]() |