Depreciate MySQL and GD image graphs
[contractdashboard.git] / lib / jpgraph_ttf.inc.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
<?php
//=======================================================================
// File:        jpgraph_ttf.inc.php
// Description: Handling of TTF fonts
// Created:     2006-11-19
// Ver:         $Id: jpgraph_ttf.inc.php 1858 2009-09-28 14:39:51Z ljp $
//
// Copyright (c) Aditus Consulting. All rights reserved.
//========================================================================
 
// TTF Font families
define("FF_COURIER",10);
define("FF_VERDANA",11);
define("FF_TIMES",12);
define("FF_COMIC",14);
define("FF_ARIAL",15);
define("FF_GEORGIA",16);
define("FF_TREBUCHE",17);
 
// Gnome Vera font
// Available from http://www.gnome.org/fonts/
define("FF_VERA",18);
define("FF_VERAMONO",19);
define("FF_VERASERIF",20);
 
// Chinese font
define("FF_SIMSUN",30);
define("FF_CHINESE",31);
define("FF_BIG5",32);
 
// Japanese font
define("FF_MINCHO",40);
define("FF_PMINCHO",41);
define("FF_GOTHIC",42);
define("FF_PGOTHIC",43);
 
// Hebrew fonts
define("FF_DAVID",44);
define("FF_MIRIAM",45);
define("FF_AHRON",46);
 
// Dejavu-fonts http://sourceforge.net/projects/dejavu
define("FF_DV_SANSSERIF",47);
define("FF_DV_SERIF",48);
define("FF_DV_SANSSERIFMONO",49);
define("FF_DV_SERIFCOND",50);
define("FF_DV_SANSSERIFCOND",51);
 
// Extra fonts
// Download fonts from
// http://www.webfontlist.com
// http://www.webpagepublicity.com/free-fonts.html
// http://www.fontonic.com/fonts.asp?width=d&offset=120
// http://www.fontspace.com/category/famous
 
// define("FF_SPEEDO",71);  // This font is also known as Bauer (Used for development gauge fascia)
define("FF_DIGITAL",72); // Digital readout font
define("FF_COMPUTER",73); // The classic computer font
define("FF_CALCULATOR",74); // Triad font
 
define("FF_USERFONT",90);
define("FF_USERFONT1",90);
define("FF_USERFONT2",91);
define("FF_USERFONT3",92);
 
// Limits for fonts
define("_FIRST_FONT",10);
define("_LAST_FONT",99);
 
// TTF Font styles
define("FS_NORMAL",9001);
define("FS_BOLD",9002);
define("FS_ITALIC",9003);
define("FS_BOLDIT",9004);
define("FS_BOLDITALIC",9004);
 
//Definitions for internal font
define("FF_FONT0",1);
define("FF_FONT1",2);
define("FF_FONT2",4);
 
//------------------------------------------------------------------------
// Defines for font setup
//------------------------------------------------------------------------
 
// Actual name of the TTF file used together with FF_CHINESE aka FF_BIG5
// This is the TTF file being used when the font family is specified as
// either FF_CHINESE or FF_BIG5
define('CHINESE_TTF_FONT','bkai00mp.ttf');
 
// Special unicode greek language support
define("LANGUAGE_GREEK",false);
 
// If you are setting this config to true the conversion of greek characters
// will assume that the input text is windows 1251
define("GREEK_FROM_WINDOWS",false);
 
// Special unicode cyrillic language support
define("LANGUAGE_CYRILLIC",false);
 
// If you are setting this config to true the conversion
// will assume that the input text is windows 1251, if
// false it will assume koi8-r
define("CYRILLIC_FROM_WINDOWS",false);
 
// The following constant is used to auto-detect
// whether cyrillic conversion is really necessary
// if enabled. Just replace 'windows-1251' with a variable
// containing the input character encoding string
// of your application calling jpgraph.
// A typical such string would be 'UTF-8' or 'utf-8'.
// The comparison is case-insensitive.
// If this charset is not a 'koi8-r' or 'windows-1251'
// derivate then no conversion is done.
//
// This constant can be very important in multi-user
// multi-language environments where a cyrillic conversion
// could be needed for some cyrillic people
// and resulting in just erraneous conversions
// for not-cyrillic language based people.
//
// Example: In the free project management
// software dotproject.net $locale_char_set is dynamically
// set by the language environment the user has chosen.
//
// Usage: define('LANGUAGE_CHARSET', $locale_char_set);
//
// where $locale_char_set is a GLOBAL (string) variable
// from the application including JpGraph.
//
define('LANGUAGE_CHARSET', null);
 
// Japanese TrueType font used with FF_MINCHO, FF_PMINCHO, FF_GOTHIC, FF_PGOTHIC
// Standard fonts from Infomation-technology Promotion Agency (IPA)
// See http://mix-mplus-ipa.sourceforge.jp/
define('MINCHO_TTF_FONT','ipam.ttf');
define('PMINCHO_TTF_FONT','ipamp.ttf');
define('GOTHIC_TTF_FONT','ipag.ttf');
define('PGOTHIC_TTF_FONT','ipagp.ttf');
 
// Assume that Japanese text have been entered in EUC-JP encoding.
// If this define is true then conversion from EUC-JP to UTF8 is done
// automatically in the library using the mbstring module in PHP.
define('ASSUME_EUCJP_ENCODING',false);
 
 
//=================================================================
// CLASS LanguageConv
// Description:
// Converts various character encoding into proper
// UTF-8 depending on how the library have been configured and
// what font family is being used
//=================================================================
class LanguageConv {
    private $g2312 = null ;
 
    function Convert($aTxt,$aFF) {
        if( LANGUAGE_GREEK ) {
            if( GREEK_FROM_WINDOWS ) {
                $unistring = LanguageConv::gr_win2uni($aTxt);
            } else  {
                $unistring = LanguageConv::gr_iso2uni($aTxt);
            }
            return $unistring;
        } elseif( LANGUAGE_CYRILLIC ) {
            if( CYRILLIC_FROM_WINDOWS && (!defined('LANGUAGE_CHARSET') || stristr(LANGUAGE_CHARSET, 'windows-1251')) ) {
                $aTxt = convert_cyr_string($aTxt, "w", "k");
            }
            if( !defined('LANGUAGE_CHARSET') || stristr(LANGUAGE_CHARSET, 'koi8-r') || stristr(LANGUAGE_CHARSET, 'windows-1251')) {
                $isostring = convert_cyr_string($aTxt, "k", "i");
                $unistring = LanguageConv::iso2uni($isostring);
            }
            else {
                $unistring = $aTxt;
            }
            return $unistring;
        }
        elseif( $aFF === FF_SIMSUN ) {
            // Do Chinese conversion
            if( $this->g2312 == null ) {
                include_once 'jpgraph_gb2312.php' ;
                $this->g2312 = new GB2312toUTF8();
            }
            return $this->g2312->gb2utf8($aTxt);
        }
        elseif( $aFF === FF_BIG5 ) {
            if( !function_exists('iconv') ) {
                JpGraphError::RaiseL(25006);
                //('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).');
            }
            return iconv('BIG5','UTF-8',$aTxt);
        }
        elseif( ASSUME_EUCJP_ENCODING &&
        ($aFF == FF_MINCHO || $aFF == FF_GOTHIC || $aFF == FF_PMINCHO || $aFF == FF_PGOTHIC) ) {
            if( !function_exists('mb_convert_encoding') ) {
                JpGraphError::RaiseL(25127);
            }
            return mb_convert_encoding($aTxt, 'UTF-8','EUC-JP');
        }
        elseif( $aFF == FF_DAVID || $aFF == FF_MIRIAM || $aFF == FF_AHRON ) {
            return LanguageConv::heb_iso2uni($aTxt);
        }
        else
        return $aTxt;
    }
 
    // Translate iso encoding to unicode
    public static function iso2uni ($isoline){
        $uniline='';
        for ($i=0; $i < strlen($isoline); $i++){
            $thischar=substr($isoline,$i,1);
            $charcode=ord($thischar);
            $uniline.=($charcode>175) ? "&#" . (1040+($charcode-176)). ";" : $thischar;
        }
        return $uniline;
    }
 
    // Translate greek iso encoding to unicode
    public static function gr_iso2uni ($isoline) {
        $uniline='';
        for ($i=0; $i < strlen($isoline); $i++) {
            $thischar=substr($isoline,$i,1);
            $charcode=ord($thischar);
            $uniline.=($charcode>179 && $charcode!=183 && $charcode!=187 && $charcode!=189) ? "&#" . (900+($charcode-180)). ";" : $thischar;
        }
        return $uniline;
    }
 
    // Translate greek win encoding to unicode
    public static function gr_win2uni ($winline) {
        $uniline='';
        for ($i=0; $i < strlen($winline); $i++) {
            $thischar=substr($winline,$i,1);
            $charcode=ord($thischar);
            if ($charcode==161 || $charcode==162) {
                $uniline.="&#" . (740+$charcode). ";";
            }
            else {
                $uniline.=(($charcode>183 && $charcode!=187 && $charcode!=189) || $charcode==180) ? "&#" . (900+($charcode-180)). ";" : $thischar;
            }
        }
        return $uniline;
    }
 
    public static function heb_iso2uni($isoline) {
        $isoline = hebrev($isoline);
        $o = '';
 
        $n = strlen($isoline);
        for($i=0; $i < $n; $i++) {
            $c=ord( substr($isoline,$i,1) );
            $o .= ($c > 223) && ($c < 251) ? '&#'.(1264+$c).';' : chr($c);
        }
        return utf8_encode($o);
    }
}
 
//=============================================================
// CLASS TTF
// Description: Handle TTF font names and mapping and loading of
//              font files
//=============================================================
class TTF {
    private $font_files,$style_names;
 
    function __construct() {
 
                // String names for font styles to be used in error messages
            $this->style_names=array(
                FS_NORMAL =>'normal',
                FS_BOLD =>'bold',
                FS_ITALIC =>'italic',
                FS_BOLDITALIC =>'bolditalic');
 
            // File names for available fonts
            $this->font_files=array(
            FF_COURIER => array(FS_NORMAL =>'cour.ttf',
                FS_BOLD  =>'courbd.ttf',
                FS_ITALIC =>'couri.ttf',
                FS_BOLDITALIC =>'courbi.ttf' ),
            FF_GEORGIA => array(FS_NORMAL =>'georgia.ttf',
                FS_BOLD  =>'georgiab.ttf',
                FS_ITALIC =>'georgiai.ttf',
                FS_BOLDITALIC =>'' ),
            FF_TREBUCHE =>array(FS_NORMAL =>'trebuc.ttf',
                FS_BOLD  =>'trebucbd.ttf',
                FS_ITALIC =>'trebucit.ttf',
                FS_BOLDITALIC =>'trebucbi.ttf' ),
            FF_VERDANA  => array(FS_NORMAL =>'verdana.ttf',
                FS_BOLD  =>'verdanab.ttf',
                FS_ITALIC =>'verdanai.ttf',
                FS_BOLDITALIC =>'' ),
            FF_TIMES =>   array(FS_NORMAL =>'times.ttf',
                FS_BOLD  =>'timesbd.ttf',
                FS_ITALIC =>'timesi.ttf',
                FS_BOLDITALIC =>'timesbi.ttf' ),
            FF_COMIC =>   array(FS_NORMAL =>'comic.ttf',
                FS_BOLD  =>'comicbd.ttf',
                FS_ITALIC =>'',
                FS_BOLDITALIC =>'' ),
            FF_ARIAL =>   array(FS_NORMAL =>'arial.ttf',
                FS_BOLD  =>'arialbd.ttf',
                FS_ITALIC =>'ariali.ttf',
                FS_BOLDITALIC =>'arialbi.ttf' ) ,
            FF_VERA =>    array(FS_NORMAL =>'Vera.ttf',
                FS_BOLD  =>'VeraBd.ttf',
                FS_ITALIC =>'VeraIt.ttf',
                FS_BOLDITALIC =>'VeraBI.ttf' ),
            FF_VERAMONO => array(FS_NORMAL =>'VeraMono.ttf',
                FS_BOLD =>'VeraMoBd.ttf',
                FS_ITALIC =>'VeraMoIt.ttf',
                FS_BOLDITALIC =>'VeraMoBI.ttf' ),
            FF_VERASERIF=> array(FS_NORMAL =>'VeraSe.ttf',
                FS_BOLD =>'VeraSeBd.ttf',
                FS_ITALIC =>'',
                FS_BOLDITALIC =>'' ) ,
 
            /* Chinese fonts */
            FF_SIMSUN  =>  array(
                FS_NORMAL =>'simsun.ttc',
                FS_BOLD =><