source: trunk/client/modules/Elezioni/grafici/jpgraph_ttf.inc.php@ 158

Last change on this file since 158 was 2, checked in by root, 15 years ago

importo il progetto

File size: 13.1 KB
Line 
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 1091 2009-01-18 22:57:40Z ljp $
7//
8// Copyright (c) Aditus Consulting. All rights reserved.
9//========================================================================
10
11// TTF Font families
12define("FF_COURIER",10);
13define("FF_VERDANA",11);
14define("FF_TIMES",12);
15define("FF_COMIC",14);
16define("FF_ARIAL",15);
17define("FF_GEORGIA",16);
18define("FF_TREBUCHE",17);
19
20// Gnome Vera font
21// Available from http://www.gnome.org/fonts/
22define("FF_VERA",18);
23define("FF_VERAMONO",19);
24define("FF_VERASERIF",20);
25
26// Chinese font
27define("FF_SIMSUN",30);
28define("FF_CHINESE",31);
29define("FF_BIG5",31);
30
31// Japanese font
32define("FF_MINCHO",40);
33define("FF_PMINCHO",41);
34define("FF_GOTHIC",42);
35define("FF_PGOTHIC",43);
36
37// Hebrew fonts
38define("FF_DAVID",44);
39define("FF_MIRIAM",45);
40define("FF_AHRON",46);
41
42// Dejavu-fonts http://sourceforge.net/projects/dejavu
43define("FF_DV_SANSSERIF",47);
44define("FF_DV_SERIF",48);
45define("FF_DV_SANSSERIFMONO",49);
46define("FF_DV_SERIFCOND",50);
47define("FF_DV_SANSSERIFCOND",51);
48
49// Extra fonts
50// Download fonts from
51// http://www.webfontlist.com
52// http://www.webpagepublicity.com/free-fonts.html
53
54define("FF_SPEEDO",71); // This font is also known as Bauer (Used for gauge fascia)
55define("FF_DIGITAL",72); // Digital readout font
56define("FF_COMPUTER",73); // The classic computer font
57define("FF_CALCULATOR",74); // Triad font
58
59define("FF_USERFONT",90);
60define("FF_USERFONT1",90);
61define("FF_USERFONT2",91);
62define("FF_USERFONT3",92);
63
64// Limits for fonts
65define("_FIRST_FONT",10);
66define("_LAST_FONT",99);
67
68// TTF Font styles
69define("FS_NORMAL",9001);
70define("FS_BOLD",9002);
71define("FS_ITALIC",9003);
72define("FS_BOLDIT",9004);
73define("FS_BOLDITALIC",9004);
74
75//Definitions for internal font
76define("FF_FONT0",1);
77define("FF_FONT1",2);
78define("FF_FONT2",4);
79
80//=================================================================
81// CLASS LanguageConv
82// Description:
83// Converts various character encoding into proper
84// UTF-8 depending on how the library have been configured and
85// what font family is being used
86//=================================================================
87class LanguageConv {
88 private $g2312 = null ;
89
90 function Convert($aTxt,$aFF) {
91 if( LANGUAGE_GREEK ) {
92 if( GREEK_FROM_WINDOWS ) {
93 $unistring = LanguageConv::gr_win2uni($aTxt);
94 } else {
95 $unistring = LanguageConv::gr_iso2uni($aTxt);
96 }
97 return $unistring;
98 } elseif( LANGUAGE_CYRILLIC ) {
99 if( CYRILLIC_FROM_WINDOWS && (!defined('LANGUAGE_CHARSET') || stristr(LANGUAGE_CHARSET, 'windows-1251')) ) {
100 $aTxt = convert_cyr_string($aTxt, "w", "k");
101 }
102 if( !defined('LANGUAGE_CHARSET') || stristr(LANGUAGE_CHARSET, 'koi8-r') || stristr(LANGUAGE_CHARSET, 'windows-1251')) {
103 $isostring = convert_cyr_string($aTxt, "k", "i");
104 $unistring = LanguageConv::iso2uni($isostring);
105 }
106 else {
107 $unistring = $aTxt;
108 }
109 return $unistring;
110 }
111 elseif( $aFF === FF_SIMSUN ) {
112 // Do Chinese conversion
113 if( $this->g2312 == null ) {
114 include_once 'jpgraph_gb2312.php' ;
115 $this->g2312 = new GB2312toUTF8();
116 }
117 return $this->g2312->gb2utf8($aTxt);
118 }
119 elseif( $aFF === FF_CHINESE ) {
120 if( !function_exists('iconv') ) {
121 JpGraphError::RaiseL(25006);
122//('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).');
123 }
124 return iconv('BIG5','UTF-8',$aTxt);
125 }
126 elseif( ASSUME_EUCJP_ENCODING &&
127 ($aFF == FF_MINCHO || $aFF == FF_GOTHIC || $aFF == FF_PMINCHO || $aFF == FF_PGOTHIC) ) {
128 if( !function_exists('mb_convert_encoding') ) {
129 JpGraphError::RaiseL(25127);
130 }
131 return mb_convert_encoding($aTxt, 'UTF-8','EUC-JP');
132 }
133 elseif( $aFF == FF_DAVID || $aFF == FF_MIRIAM || $aFF == FF_AHRON ) {
134 return LanguageConv::heb_iso2uni($aTxt);
135 }
136 else
137 return $aTxt;
138 }
139
140 // Translate iso encoding to unicode
141 public static function iso2uni ($isoline){
142 $uniline='';
143 for ($i=0; $i < strlen($isoline); $i++){
144 $thischar=substr($isoline,$i,1);
145 $charcode=ord($thischar);
146 $uniline.=($charcode>175) ? "&#" . (1040+($charcode-176)). ";" : $thischar;
147 }
148 return $uniline;
149 }
150
151 // Translate greek iso encoding to unicode
152 public static function gr_iso2uni ($isoline) {
153 $uniline='';
154 for ($i=0; $i < strlen($isoline); $i++) {
155 $thischar=substr($isoline,$i,1);
156 $charcode=ord($thischar);
157 $uniline.=($charcode>179 && $charcode!=183 && $charcode!=187 && $charcode!=189) ? "&#" . (900+($charcode-180)). ";" : $thischar;
158 }
159 return $uniline;
160 }
161
162 // Translate greek win encoding to unicode
163 public static function gr_win2uni ($winline) {
164 $uniline='';
165 for ($i=0; $i < strlen($winline); $i++) {
166 $thischar=substr($winline,$i,1);
167 $charcode=ord($thischar);
168 if ($charcode==161 || $charcode==162) {
169 $uniline.="&#" . (740+$charcode). ";";
170 }
171 else {
172 $uniline.=(($charcode>183 && $charcode!=187 && $charcode!=189) || $charcode==180) ? "&#" . (900+($charcode-180)). ";" : $thischar;
173 }
174 }
175 return $uniline;
176 }
177
178 public static function heb_iso2uni($isoline) {
179 $isoline = hebrev($isoline);
180 $o = '';
181
182 $n = strlen($isoline);
183 for($i=0; $i < $n; $i++) {
184 $c=ord( substr($isoline,$i,1) );
185 $o .= ($c > 223) && ($c < 251) ? '&#'.(1264+$c).';' : chr($c);
186 }
187 return utf8_encode($o);
188 }
189}
190
191//=============================================================
192// CLASS TTF
193// Description: Handle TTF font names and mapping and loading of
194// font files
195//=============================================================
196class TTF {
197 private $font_files,$style_names;
198
199//---------------
200// CONSTRUCTOR
201 function TTF() {
202
203 // String names for font styles to be used in error messages
204 $this->style_names=array(FS_NORMAL =>'normal',
205 FS_BOLD =>'bold',
206 FS_ITALIC =>'italic',
207 FS_BOLDITALIC =>'bolditalic');
208
209 // File names for available fonts
210 $this->font_files=array(
211 FF_COURIER => array(FS_NORMAL =>'cour.ttf',
212 FS_BOLD =>'courbd.ttf',
213 FS_ITALIC =>'couri.ttf',
214 FS_BOLDITALIC =>'courbi.ttf' ),
215 FF_GEORGIA => array(FS_NORMAL =>'georgia.ttf',
216 FS_BOLD =>'georgiab.ttf',
217 FS_ITALIC =>'georgiai.ttf',
218 FS_BOLDITALIC =>'' ),
219 FF_TREBUCHE =>array(FS_NORMAL =>'trebuc.ttf',
220 FS_BOLD =>'trebucbd.ttf',
221 FS_ITALIC =>'trebucit.ttf',
222 FS_BOLDITALIC =>'trebucbi.ttf' ),
223 FF_VERDANA => array(FS_NORMAL =>'verdana.ttf',
224 FS_BOLD =>'verdanab.ttf',
225 FS_ITALIC =>'verdanai.ttf',
226 FS_BOLDITALIC =>'' ),
227 FF_TIMES => array(FS_NORMAL =>'times.ttf',
228 FS_BOLD =>'timesbd.ttf',
229 FS_ITALIC =>'timesi.ttf',
230 FS_BOLDITALIC =>'timesbi.ttf' ),
231 FF_COMIC => array(FS_NORMAL =>'comic.ttf',
232 FS_BOLD =>'comicbd.ttf',
233 FS_ITALIC =>'',
234 FS_BOLDITALIC =>'' ),
235 FF_ARIAL => array(FS_NORMAL =>'arial.ttf',
236 FS_BOLD =>'arialbd.ttf',
237 FS_ITALIC =>'ariali.ttf',
238 FS_BOLDITALIC =>'arialbi.ttf' ) ,
239 FF_VERA => array(FS_NORMAL =>'Vera.ttf',
240 FS_BOLD =>'VeraBd.ttf',
241 FS_ITALIC =>'VeraIt.ttf',
242 FS_BOLDITALIC =>'VeraBI.ttf' ),
243 FF_VERAMONO => array(FS_NORMAL =>'VeraMono.ttf',
244 FS_BOLD =>'VeraMoBd.ttf',
245 FS_ITALIC =>'VeraMoIt.ttf',
246 FS_BOLDITALIC =>'VeraMoBI.ttf' ),
247 FF_VERASERIF=> array(FS_NORMAL =>'VeraSe.ttf',
248 FS_BOLD =>'VeraSeBd.ttf',
249 FS_ITALIC =>'',
250 FS_BOLDITALIC =>'' ) ,
251
252 /* Chinese fonts */
253 FF_SIMSUN => array(FS_NORMAL =>'simsun.ttc',
254 FS_BOLD =>'simhei.ttf',
255 FS_ITALIC =>'',
256 FS_BOLDITALIC =>'' ),
257 FF_CHINESE => array(FS_NORMAL =>CHINESE_TTF_FONT,
258 FS_BOLD =>'',
259 FS_ITALIC =>'',
260 FS_BOLDITALIC =>'' ),
261
262 /* Japanese fonts */
263 FF_MINCHO => array(FS_NORMAL =>MINCHO_TTF_FONT,
264 FS_BOLD =>'',
265 FS_ITALIC =>'',
266 FS_BOLDITALIC =>'' ),
267 FF_PMINCHO => array(FS_NORMAL =>PMINCHO_TTF_FONT,
268 FS_BOLD =>'',
269 FS_ITALIC =>'',
270 FS_BOLDITALIC =>'' ),
271 FF_GOTHIC => array(FS_NORMAL =>GOTHIC_TTF_FONT,
272 FS_BOLD =>'',
273 FS_ITALIC =>'',
274 FS_BOLDITALIC =>'' ),
275 FF_PGOTHIC => array(FS_NORMAL =>PGOTHIC_TTF_FONT,
276 FS_BOLD =>'',
277 FS_ITALIC =>'',
278 FS_BOLDITALIC =>'' ),
279 FF_MINCHO => array(FS_NORMAL =>PMINCHO_TTF_FONT,
280 FS_BOLD =>'',
281 FS_ITALIC =>'',
282 FS_BOLDITALIC =>'' ),
283
284 /* Hebrew fonts */
285 FF_DAVID => array(FS_NORMAL =>'DAVIDNEW.TTF',
286 FS_BOLD =>'',
287 FS_ITALIC =>'',
288 FS_BOLDITALIC =>'' ),
289
290 FF_MIRIAM => array(FS_NORMAL =>'MRIAMY.TTF',
291 FS_BOLD =>'',
292 FS_ITALIC =>'',
293 FS_BOLDITALIC =>'' ),
294
295 FF_AHRON => array(FS_NORMAL =>'ahronbd.ttf',
296 FS_BOLD =>'',
297 FS_ITALIC =>'',
298 FS_BOLDITALIC =>'' ),
299
300 /* Misc fonts */
301 FF_DIGITAL => array(FS_NORMAL =>'DIGIRU__.TTF',
302 FS_BOLD =>'Digirtu_.ttf',
303 FS_ITALIC =>'Digir___.ttf',
304 FS_BOLDITALIC =>'DIGIRT__.TTF' ),
305 FF_SPEEDO => array(FS_NORMAL =>'Speedo.ttf',
306 FS_BOLD =>'',
307 FS_ITALIC =>'',
308 FS_BOLDITALIC =>'' ),
309 FF_COMPUTER => array(FS_NORMAL =>'COMPUTER.TTF',
310 FS_BOLD =>'',
311 FS_ITALIC =>'',
312 FS_BOLDITALIC =>'' ),
313 FF_CALCULATOR => array(FS_NORMAL =>'Triad_xs.ttf',
314 FS_BOLD =>'',
315 FS_ITALIC =>'',
316 FS_BOLDITALIC =>'' ),
317
318 /* Dejavu fonts */
319 FF_DV_SANSSERIF => array(FS_NORMAL =>'DejaVuSans.ttf',
320 FS_BOLD =>'DejaVuSans-Bold.ttf',
321 FS_ITALIC =>'DejaVuSans-Oblique.ttf',
322 FS_BOLDITALIC =>'DejaVuSans-BoldOblique.ttf' ),
323
324 FF_DV_SANSSERIFMONO => array(FS_NORMAL =>'DejaVuSansMono.ttf',
325 FS_BOLD =>'DejaVuSansMono-Bold.ttf',
326 FS_ITALIC =>'DejaVuSansMono-Oblique.ttf',
327 FS_BOLDITALIC =>'DejaVuSansMono-BoldOblique.ttf' ),
328
329 FF_DV_SANSSERIFCOND => array(FS_NORMAL =>'DejaVuSansCondensed.ttf',
330 FS_BOLD =>'DejaVuSansCondensed-Bold.ttf',
331 FS_ITALIC =>'DejaVuSansCondensed-Oblique.ttf',
332 FS_BOLDITALIC =>'DejaVuSansCondensed-BoldOblique.ttf' ),
333
334 FF_DV_SERIF => array(FS_NORMAL =>'DejaVuSerif.ttf',
335 FS_BOLD =>'DejaVuSerif-Bold.ttf',
336 FS_ITALIC =>'DejaVuSerif-Italic.ttf',
337 FS_BOLDITALIC =>'DejaVuSerif-BoldItalic.ttf' ),
338
339 FF_DV_SERIFCOND => array(FS_NORMAL =>'DejaVuSerifCondensed.ttf',
340 FS_BOLD =>'DejaVuSerifCondensed-Bold.ttf',
341 FS_ITALIC =>'DejaVuSerifCondensed-Italic.ttf',
342 FS_BOLDITALIC =>'DejaVuSerifCondensed-BoldItalic.ttf' ),
343
344
345 /* User defined font */
346 FF_USERFONT1 => array(FS_NORMAL =>'',
347 FS_BOLD =>'',
348 FS_ITALIC =>'',
349 FS_BOLDITALIC =>'' ),
350
351 FF_USERFONT2 => array(FS_NORMAL =>'',
352 FS_BOLD =>'',
353 FS_ITALIC =>'',
354 FS_BOLDITALIC =>'' ),
355
356 FF_USERFONT3 => array(FS_NORMAL =>'',
357 FS_BOLD =>'',
358 FS_ITALIC =>'',
359 FS_BOLDITALIC =>'' ),
360
361 );
362 }
363
364//---------------
365// PUBLIC METHODS
366 // Create the TTF file from the font specification
367 function File($family,$style=FS_NORMAL) {
368 $fam = @$this->font_files[$family];
369 if( !$fam ) {
370 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/");
371 }
372 $f = @$fam[$style];
373
374 if( $f==='' )
375 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].'.');
376 if( !$f ) {
377 JpGraphError::RaiseL(25048,$fam);//("Unknown font style specification [$fam].");
378 }
379
380 if ($family >= FF_MINCHO && $family <= FF_PGOTHIC) {
381 $f = MBTTF_DIR.$f;
382 } else {
383 $f = TTF_DIR.$f;
384 }
385
386 if( file_exists($f) === false || is_readable($f) === false ) {
387 JpGraphError::RaiseL(25049,$f);//("Font file \"$f\" is not readable or does not exist.");
388 }
389 return $f;
390 }
391
392 function SetUserFont($aNormal,$aBold='',$aItalic='',$aBoldIt='') {
393 $this->font_files[FF_USERFONT] =
394 array(FS_NORMAL => $aNormal,
395 FS_BOLD => $aBold,
396 FS_ITALIC => $aItalic,
397 FS_BOLDITALIC => $aBoldIt ) ;
398 }
399
400 function SetUserFont1($aNormal,$aBold='',$aItalic='',$aBoldIt='') {
401 $this->font_files[FF_USERFONT1] =
402 array(FS_NORMAL => $aNormal,
403 FS_BOLD => $aBold,
404 FS_ITALIC => $aItalic,
405 FS_BOLDITALIC => $aBoldIt ) ;
406 }
407
408 function SetUserFont2($aNormal,$aBold='',$aItalic='',$aBoldIt='') {
409 $this->font_files[FF_USERFONT2] =
410 array(FS_NORMAL => $aNormal,
411 FS_BOLD => $aBold,
412 FS_ITALIC => $aItalic,
413 FS_BOLDITALIC => $aBoldIt ) ;
414 }
415
416 function SetUserFont3($aNormal,$aBold='',$aItalic='',$aBoldIt='') {
417 $this->font_files[FF_USERFONT3] =
418 array(FS_NORMAL => $aNormal,
419 FS_BOLD => $aBold,
420 FS_ITALIC => $aItalic,
421 FS_BOLDITALIC => $aBoldIt ) ;
422 }
423
424} // Class
425
426
427
428?>
Note: See TracBrowser for help on using the repository browser.