Issues (459)

src/text/LanguageConv.php (1 issue)

Labels
Severity
1
<?php
2
3
/**
4
 * JPGraph v4.0.3
5
 */
6
7
namespace Amenadiel\JpGraph\Text;
8
9
use Amenadiel\JpGraph\Util;
10
11
/**
12
 * @class LanguageConv
13
 * // Description:
14
 * // Converts various character encoding into proper
15
 * // UTF-8 depending on how the library have been configured and
16
 * // what font family is being used
17
 */
18
class LanguageConv
19
{
20
    private $g2312;
21
22 21
    public function Convert($aTxt, $aFF)
23
    {
24 21
        if (LANGUAGE_GREEK) {
25
            if (GREEK_FROM_WINDOWS) {
26
                $unistring = LanguageConv::gr_win2uni($aTxt);
27
            } else {
28
                $unistring = LanguageConv::gr_iso2uni($aTxt);
29
            }
30
31
            return $unistring;
32
        }
33 21
        if (LANGUAGE_CYRILLIC) {
34
            if (CYRILLIC_FROM_WINDOWS && (!defined('LANGUAGE_CHARSET') || stristr(LANGUAGE_CHARSET, 'windows-1251'))) {
0 ignored issues
show
Amenadiel\JpGraph\Text\LANGUAGE_CHARSET of type null is incompatible with the type string expected by parameter $haystack of stristr(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

34
            if (CYRILLIC_FROM_WINDOWS && (!defined('LANGUAGE_CHARSET') || stristr(/** @scrutinizer ignore-type */ LANGUAGE_CHARSET, 'windows-1251'))) {
Loading history...
35
                $aTxt = convert_cyr_string($aTxt, 'w', 'k');
36
            }
37
            if (!defined('LANGUAGE_CHARSET') || stristr(LANGUAGE_CHARSET, 'koi8-r') || stristr(LANGUAGE_CHARSET, 'windows-1251')) {
38
                $isostring = convert_cyr_string($aTxt, 'k', 'i');
39
                $unistring = LanguageConv::iso2uni($isostring);
40
            } else {
41
                $unistring = $aTxt;
42
            }
43
44
            return $unistring;
45
        }
46 21
        if ($aFF === FF_SIMSUN) {
47
            // Do Chinese conversion
48
            if ($this->g2312 == null) {
49
                $this->g2312 = new GB2312toUTF8();
50
            }
51
52
            return $this->g2312->gb2utf8($aTxt);
53
        }
54 21
        if ($aFF === FF_BIG5) {
55
            if (!function_exists('iconv')) {
56
                Util\JpGraphError::RaiseL(25006);
57
                //('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).');
58
            }
59
60
            return iconv('BIG5', 'UTF-8', $aTxt);
61
        }
62 21
        if (ASSUME_EUCJP_ENCODING &&
63 21
            ($aFF == FF_MINCHO || $aFF == FF_GOTHIC || $aFF == FF_PMINCHO || $aFF == FF_PGOTHIC)) {
64
            if (!function_exists('mb_convert_encoding')) {
65
                Util\JpGraphError::RaiseL(25127);
66
            }
67
68
            return mb_convert_encoding($aTxt, 'UTF-8', 'EUC-JP');
69
        }
70 21
        if ($aFF == FF_DAVID || $aFF == FF_MIRIAM || $aFF == FF_AHRON) {
71
            return LanguageConv::heb_iso2uni($aTxt);
72
        }
73
74 21
        return $aTxt;
75
    }
76
77
    // Translate iso encoding to unicode
78
    public static function iso2uni($isoline)
79
    {
80
        $uniline = '';
81
        for ($i = 0; $i < strlen($isoline); ++$i) {
82
            $thischar = substr($isoline, $i, 1);
83
            $charcode = ord($thischar);
84
            $uniline .= ($charcode > 175) ? '&#' . (1040 + ($charcode - 176)) . ';' : $thischar;
85
        }
86
87
        return $uniline;
88
    }
89
90
    // Translate greek iso encoding to unicode
91
    public static function gr_iso2uni($isoline)
92
    {
93
        $uniline = '';
94
        for ($i = 0; $i < strlen($isoline); ++$i) {
95
            $thischar = substr($isoline, $i, 1);
96
            $charcode = ord($thischar);
97
            $uniline .= ($charcode > 179 && $charcode != 183 && $charcode != 187 && $charcode != 189) ? '&#' . (900 + ($charcode - 180)) . ';' : $thischar;
98
        }
99
100
        return $uniline;
101
    }
102
103
    // Translate greek win encoding to unicode
104
    public static function gr_win2uni($winline)
105
    {
106
        $uniline = '';
107
        for ($i = 0; $i < strlen($winline); ++$i) {
108
            $thischar = substr($winline, $i, 1);
109
            $charcode = ord($thischar);
110
            if ($charcode == 161 || $charcode == 162) {
111
                $uniline .= '&#' . (740 + $charcode) . ';';
112
            } else {
113
                $uniline .= (($charcode > 183 && $charcode != 187 && $charcode != 189) || $charcode == 180) ? '&#' . (900 + ($charcode - 180)) . ';' : $thischar;
114
            }
115
        }
116
117
        return $uniline;
118
    }
119
120
    public static function heb_iso2uni($isoline)
121
    {
122
        $isoline = hebrev($isoline);
123
        $o       = '';
124
125
        $n = strlen($isoline);
126
        for ($i = 0; $i < $n; ++$i) {
127
            $c = ord(substr($isoline, $i, 1));
128
            $o .= ($c > 223) && ($c < 251) ? '&#' . (1264 + $c) . ';' : chr($c);
129
        }
130
131
        return utf8_encode($o);
132
    }
133
}
134