Subversion-Projekte lars-tiefland.php_share

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
1 lars 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 806 2006-11-28 07:51:57Z 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",19);
23
DEFINE("FF_VERAMONO",20);
24
DEFINE("FF_VERASERIF",21);
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 TTF fonts
53
DEFINE('_FF_FIRST',10);
54
DEFINE('_FF_LAST',53);
55
 
56
// Older deprecated fonts
57
DEFINE("FF_BOOK",91);    // Deprecated fonts from 1.9
58
DEFINE("FF_HANDWRT",92); // Deprecated fonts from 1.9
59
 
60
// TTF Font styles
61
DEFINE("FS_NORMAL",9001);
62
DEFINE("FS_BOLD",9002);
63
DEFINE("FS_ITALIC",9003);
64
DEFINE("FS_BOLDIT",9004);
65
DEFINE("FS_BOLDITALIC",9004);
66
 
67
//Definitions for internal font
68
DEFINE("FF_FONT0",1);
69
DEFINE("FF_FONT1",2);
70
DEFINE("FF_FONT2",4);
71
 
72
 
73
//===================================================
74
// CLASS LanguageConv
75
// Description:
76
// Converts variouscharacter encoding into proper
77
// UTF-8 depending on how the library have been configured.
78
//===================================================
79
class LanguageConv {
80
    var $g2312 = null ;
81
 
82
    function Convert($aTxt,$aFF) {
83
	if( LANGUAGE_GREEK ) {
84
	    if( GREEK_FROM_WINDOWS ) {
85
		$unistring = LanguageConv::gr_win2uni($aTxt);
86
	    } else  {
87
		$unistring = LanguageConv::gr_iso2uni($aTxt);
88
	    }
89
	    return $unistring;
90
	} elseif( LANGUAGE_CYRILLIC ) {
91
	    if( CYRILLIC_FROM_WINDOWS && (!defined('CYRILLIC_LANGUAGE_CHARSET') || stristr(CYRILLIC_LANGUAGE_CHARSET, 'windows-1251')) ) {
92
		$aTxt = convert_cyr_string($aTxt, "w", "k");
93
	    }
94
	    if( !defined('CYRILLIC_LANGUAGE_CHARSET') || stristr(CYRILLIC_LANGUAGE_CHARSET, 'koi8-r') || stristr(CYRILLIC_LANGUAGE_CHARSET, 'windows-1251')) {
95
		$isostring = convert_cyr_string($aTxt, "k", "i");
96
		$unistring = LanguageConv::iso2uni($isostring);
97
	    }
98
	    else {
99
		$unistring = $aTxt;
100
	    }
101
	    return $unistring;
102
	}
103
	elseif( $aFF === FF_SIMSUN ) {
104
	    // Do Chinese conversion
105
	    if( $this->g2312 == null ) {
106
		include_once 'jpgraph_gb2312.php' ;
107
		$this->g2312 = new GB2312toUTF8();
108
	    }
109
	    return $this->g2312->gb2utf8($aTxt);
110
	}
111
	elseif( $aFF === FF_CHINESE ) {
112
	    if( !function_exists('iconv') ) {
113
		JpGraphError::RaiseL(25006);
114
//('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).');
115
	    }
116
	    return iconv('BIG5','UTF-8',$aTxt);
117
	}
118
	elseif( ASSUME_EUCJP_ENCODING &&
119
		($aFF == FF_MINCHO || $aFF == FF_GOTHIC || $aFF == FF_PMINCHO || $aFF == FF_PGOTHIC) ) {
120
	    if( !function_exists('mb_convert_encoding') ) {
121
		JpGraphError::RaiseL(25127);
122
	    }
123
	    return mb_convert_encoding($aTxt, 'UTF-8','EUC-JP');
124
	}
125
	elseif( $aFF == FF_DAVID || $aFF == FF_MIRIAM || $aFF == FF_AHRON ) {
126
	    return $this->heb_iso2uni($aTxt);
127
	}
128
	else
129
	    return $aTxt;
130
    }
131
 
132
    // Translate iso encoding to unicode
133
    function iso2uni ($isoline){
134
	$uniline='';
135
	for ($i=0; $i < strlen($isoline); $i++){
136
	    $thischar = substr($isoline,$i,1);
137
	    $charcode = ord($thischar);
138
	    $uniline .= ($charcode>175) ? "&#" . (1040+($charcode-176)). ";" : $thischar;
139
	}
140
	return $uniline;
141
    }
142
 
143
    // Translate greek iso encoding to unicode
144
    function gr_iso2uni ($isoline) {
145
	$uniline='';
146
	for ($i=0; $i < strlen($isoline); $i++)	{
147
	    $thischar=substr($isoline,$i,1);
148
	    $charcode=ord($thischar);
149
	    $uniline.=($charcode>179 && $charcode!=183 && $charcode!=187 && $charcode!=189) ? "&#" . (900+($charcode-180)). ";" : $thischar;
150
	}
151
	return $uniline;
152
    }
153
 
154
    // Translate greek win encoding to unicode
155
    function gr_win2uni ($winline) {
156
	$uniline='';
157
	$n = strlen($winline);
158
	for ($i=0; $i < $n; $i++) {
159
	    $thischar=substr($winline,$i,1);
160
	    $charcode=ord($thischar);
161
	    if ($charcode==161 || $charcode==162) {
162
		$uniline.="&#" . (740+$charcode). ";";
163
	    }
164
	    else {
165
		$uniline.=(($charcode>183 && $charcode!=187 && $charcode!=189) || $charcode==180) ? "&#" . (900+($charcode-180)). ";" : $thischar;
166
	    }
167
	}
168
	return $uniline;
169
    }
170
 
171
    function heb_iso2uni($isoline) {
172
	$isoline = hebrev($isoline);
173
	$o = '';
174
 
175
	$n = strlen($isoline);
176
	for($i=0; $i < $n; $i++) {
177
	    $c=ord( substr($isoline,$i,1) );
178
	    $o .= ($c > 223) && ($c < 251) ? '&#'.(1264+$c).';' : chr($c);
179
	}
180
	return utf8_encode($o);
181
    }
182
}
183
 
184
//=================================================================
185
// CLASS TTF
186
// Description: Handle TTF font names and loading of font files
187
//=================================================================
188
class TTF {
189
    var $font_files,$style_names;
190
 
191
//---------------
192
// CONSTRUCTOR
193
    function TTF() {
194
 
195
	// String names for font styles to be used in error messages
196
	$this->style_names=array(FS_NORMAL	=>'normal',
197
				 FS_BOLD	=>'bold',
198
				 FS_ITALIC	=>'italic',
199
				 FS_BOLDITALIC	=>'bolditalic');
200
 
201
	// File names for available fonts
202
	$this->font_files=array(
203
	    FF_COURIER => array(FS_NORMAL	=>'cour.ttf',
204
				FS_BOLD		=>'courbd.ttf',
205
				FS_ITALIC	=>'couri.ttf',
206
				FS_BOLDITALIC	=>'courbi.ttf' ),
207
	    FF_GEORGIA => array(FS_NORMAL	=>'georgia.ttf',
208
				FS_BOLD		=>'georgiab.ttf',
209
				FS_ITALIC	=>'georgiai.ttf',
210
				FS_BOLDITALIC	=>'' ),
211
	    FF_TREBUCHE	=>array(FS_NORMAL	=>'trebuc.ttf',
212
				FS_BOLD		=>'trebucbd.ttf',
213
				FS_ITALIC	=>'trebucit.ttf',
214
				FS_BOLDITALIC	=>'trebucbi.ttf' ),
215
	    FF_VERDANA 	=> array(FS_NORMAL	=>'verdana.ttf',
216
				FS_BOLD		=>'verdanab.ttf',
217
				FS_ITALIC	=>'verdanai.ttf',
218
				FS_BOLDITALIC	=>'' ),
219
	    FF_TIMES =>   array(FS_NORMAL	=>'times.ttf',
220
				FS_BOLD		=>'timesbd.ttf',
221
				FS_ITALIC	=>'timesi.ttf',
222
				FS_BOLDITALIC	=>'timesbi.ttf' ),
223
	    FF_COMIC =>   array(FS_NORMAL	=>'comic.ttf',
224
				FS_BOLD		=>'comicbd.ttf',
225
				FS_ITALIC	=>'',
226
				FS_BOLDITALIC	=>'' ),
227
	    FF_ARIAL =>   array(FS_NORMAL	=>'arial.ttf',
228
				FS_BOLD		=>'arialbd.ttf',
229
				FS_ITALIC	=>'ariali.ttf',
230
				FS_BOLDITALIC	=>'arialbi.ttf' ) ,
231
	    FF_VERA =>    array(FS_NORMAL	=>'Vera.ttf',
232
				FS_BOLD		=>'VeraBd.ttf',
233
				FS_ITALIC	=>'VeraIt.ttf',
234
				FS_BOLDITALIC	=>'VeraBI.ttf' ),
235
	    FF_VERAMONO	=> array(FS_NORMAL	=>'VeraMono.ttf',
236
				 FS_BOLD	=>'VeraMoBd.ttf',
237
				 FS_ITALIC	=>'VeraMoIt.ttf',
238
				 FS_BOLDITALIC	=>'VeraMoBI.ttf' ),
239
	    FF_VERASERIF=>  array(FS_NORMAL	=>'VeraSe.ttf',
240
				  FS_BOLD	=>'VeraSeBd.ttf',
241
				  FS_ITALIC	=>'',
242
				  FS_BOLDITALIC	=>'' ) ,
243
 
244
	    /* Chinese fonts */
245
	    FF_SIMSUN 	=>  array(FS_NORMAL	=>'simsun.ttc',
246
				  FS_BOLD	=>'simhei.ttf',
247
				  FS_ITALIC	=>'',
248
				  FS_BOLDITALIC	=>'' ),
249
	    FF_CHINESE 	=>  array(FS_NORMAL	=>CHINESE_TTF_FONT,
250
				  FS_BOLD	=>'',
251
				  FS_ITALIC	=>'',
252
				  FS_BOLDITALIC	=>'' ),
253
 
254
	    /* Japanese fonts */
255
 	    FF_MINCHO 	=>  array(FS_NORMAL	=>MINCHO_TTF_FONT,
256
				  FS_BOLD	=>'',
257
				  FS_ITALIC	=>'',
258
				  FS_BOLDITALIC	=>'' ),
259
 	    FF_PMINCHO 	=>  array(FS_NORMAL	=>PMINCHO_TTF_FONT,
260
				  FS_BOLD	=>'',
261
				  FS_ITALIC	=>'',
262
				  FS_BOLDITALIC	=>'' ),
263
 	    FF_GOTHIC  	=>   array(FS_NORMAL	=>GOTHIC_TTF_FONT,
264
				  FS_BOLD	=>'',
265
				  FS_ITALIC	=>'',
266
				  FS_BOLDITALIC	=>'' ),
267
 	    FF_PGOTHIC 	=>  array(FS_NORMAL	=>PGOTHIC_TTF_FONT,
268
				  FS_BOLD	=>'',
269
				  FS_ITALIC	=>'',
270
				  FS_BOLDITALIC	=>'' ),
271
 	    FF_MINCHO 	=>  array(FS_NORMAL	=>PMINCHO_TTF_FONT,
272
				  FS_BOLD	=>'',
273
				  FS_ITALIC	=>'',
274
				  FS_BOLDITALIC	=>'' ),
275
 
276
	    /* Hebrew fonts */
277
	    FF_DAVID 	=>  array(FS_NORMAL	=>'DAVIDNEW.TTF',
278
				  FS_BOLD	=>'',
279
				  FS_ITALIC	=>'',
280
				  FS_BOLDITALIC	=>'' ),
281
 
282
	    FF_MIRIAM 	=>  array(FS_NORMAL	=>'MRIAMY.TTF',
283
				  FS_BOLD	=>'',
284
				  FS_ITALIC	=>'',
285
				  FS_BOLDITALIC	=>'' ),
286
 
287
	    FF_AHRON 	=>  array(FS_NORMAL	=>'ahronbd.ttf',
288
				  FS_BOLD	=>'',
289
				  FS_ITALIC	=>'',
290
				  FS_BOLDITALIC	=>'' ),
291
 
292
	    /* Misc fonts */
293
 	    FF_DIGITAL =>   array(FS_NORMAL	=>'DIGIRU__.TTF',
294
				  FS_BOLD	=>'Digirtu_.ttf',
295
				  FS_ITALIC	=>'Digir___.ttf',
296
				  FS_BOLDITALIC	=>'DIGIRT__.TTF' ),
297
 	    FF_SPEEDO =>    array(FS_NORMAL	=>'Speedo.ttf',
298
				  FS_BOLD	=>'',
299
				  FS_ITALIC	=>'',
300
				  FS_BOLDITALIC	=>'' ),
301
 	    FF_COMPUTER  =>  array(FS_NORMAL	=>'COMPUTER.TTF',
302
				  FS_BOLD	=>'',
303
				  FS_ITALIC	=>'',
304
				  FS_BOLDITALIC	=>'' ),
305
 	    FF_CALCULATOR =>array(FS_NORMAL	=>'Triad_xs.ttf',
306
				  FS_BOLD	=>'',
307
				  FS_ITALIC	=>'',
308
				  FS_BOLDITALIC	=>'' ),
309
	    );
310
    }
311
 
312
//---------------
313
// PUBLIC METHODS
314
    // Create the TTF file from the font specification
315
    function File($family,$style=FS_NORMAL) {
316
 
317
	if( $family == FF_HANDWRT || $family==FF_BOOK ) {
318
	    JpGraphError::RaiseL(25045);//('Font families FF_HANDWRT and FF_BOOK are no longer available due to copyright problem with these fonts. Fonts can no longer be distributed with JpGraph. Please download fonts from http://corefonts.sourceforge.net/');
319
	}
320
 
321
	$fam = @$this->font_files[$family];
322
	if( !$fam ) {
323
	    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/");
324
	}
325
	$f = @$fam[$style];
326
 
327
	if( $f==='' )
328
	    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].'.');
329
	if( !$f ) {
330
	    JpGraphError::RaiseL(25048,$fam);//("Unknown font style specification [$fam].");
331
	}
332
 
333
	if ($family >= FF_MINCHO && $family <= FF_PGOTHIC) {
334
	    $f = MBTTF_DIR.$f;
335
	} else {
336
	    $f = TTF_DIR.$f;
337
	}
338
 
339
	if( file_exists($f) === false || is_readable($f) === false ) {
340
	    JpGraphError::RaiseL(25049,$f);//("Font file \"$f\" is not readable or does not exist.");
341
	}
342
	return $f;
343
    }
344
} // Class
345
 
346
?>