- modules/fotolab updated imagej to current version & some cod fixes to make it work
[care2x.git] / Care2007 / include / inc_ttf_ar2uni.php
blob02c1fa28b60ee2686636c44fdc9a2c24e5294d36
1 <?php
2 #====================================================================================================#
3 # ar2uni v0.1 (Arabic-win1256 encoder to Unicode) #
4 #====================================================================================================#
5 # Information: #
6 # This is PHP function for covert Arabic encoding string to #
7 # unicode that can use to show Arabic charactor in function ImageTTFText(). #
8 # It Tested and worked with Multilanguage arial.ttf V2.98 #
9 # #
10 # Version History: #
11 # version 0.1 : First release. created on ( 22/01/2004) By Walid Fathalla #
12 # #
13 # Bug Report and Suggestion to: #
14 # Walid Fathalla #
15 # fathalla_w@hotmail.com #
16 # #
17 #====================================================================================================#
18 # Example: #
19 # include_once($root_path.'inc_ttf_ar2uni.php'); #
20 # ImageTTFText ($image, 8, 0, 3, 15, $white, "arial.ttf",ar2uni("$ArabicString")); #
21 #====================================================================================================#
22 # For Arabic Website: If you thing this module useful to you, please send to #
23 # me back to my email fathalla_w@hotmail.com. #
24 # #
25 #====================================================================================================#
27 #================================================// Arabic character maps//=============================================
28 $ar2unimap = array( // One bit character isolated form
29 ',' => "&#1548;", 'º' => "&#1563;", '¿' => "&#1567;", 'Á' => "&#1569;", 'Â' => "&#1570;", 'Ã' => "&#1571;", 'Ä' => "&#1572;",
30 'Å' => "&#1573;", 'Æ' => "&#1574;", 'Ç' => "&#1575;", 'È' => "&#1576;", 'É' => "&#1577;", 'Ê' => "&#1578;", 'Ë' => "&#1579;",
31 'Ì' => "&#1580;", 'Í' => "&#1581;", 'Î' => "&#1582;", 'Ï' => "&#1583;", 'Ð' => "&#1584;", 'Ñ' => "&#1585;", 'Ò' => "&#1586;",
32 'Ó' => "&#1587;", 'Ô' => "&#1588;", 'Õ' => "&#1589;", 'Ö' => "&#1590;", 'Ø' => "&#1591;", 'Ù' => "&#1592;", 'Ú' => "&#1593;",
33 'Û' => "&#1594;", 'Ü' => "&#1600;", 'Ý' => "&#1601;", 'Þ' => "&#1602;", 'ß' => "&#1603;", 'á' => "&#1604;", 'ã' => "&#1605;",
34 'ä' => "&#1606;", 'å' => "&#1607;", 'æ' => "&#1608;", 'ì' => "&#1609;", 'í' => "&#1610;", 'ð' => "&#1611;", 'ñ' => "&#1612;",
35 'ò' => "&#1613;", 'ó' => "&#1614;", 'õ' => "&#1615;", 'ö' => "&#1616;", 'ø' => "&#1617;", 'ú' => "&#1618;");
37 $ar2unimap2 = array( // One bit character initial form
38 'Â' => "&#65153;", 'Ã' => "&#65155;", 'Ä' => "&#65157;", 'Å' => "&#65159;", 'Æ' => "&#65163;", 'Ç' => "&#65165;", 'È' => "&#65169;",
39 'Ê' => "&#65175;", 'Ë' => "&#65179;", 'Ì' => "&#65183;", 'Í' => "&#65187;", 'Î' => "&#65191;", 'Ï' => "&#65193;", 'Ð' => "&#65195;",
40 'Ñ' => "&#65197;", 'Ò' => "&#65199;", 'Ó' => "&#65203;", 'Ô' => "&#65207;", 'Õ' => "&#65211;", 'Ö' => "&#65215;", 'Ø' => "&#65219;",
41 'Ù' => "&#65223;", 'Ú' => "&#65227;", 'Û' => "&#65231;", 'Ý' => "&#65235;", 'Þ' => "&#65239;", 'ß' => "&#65243;", 'á' => "&#65247;",
42 'ã' => "&#65251;", 'ä' => "&#65255;", 'å' => "&#65259;", 'æ' => "&#65261;", 'í' => "&#65267;");
44 $ar2unimap3 = array( // One bit character medial form
45 'Æ' => "&#65164;", 'È' => "&#65170;", 'Ê' => "&#65176;", 'Ë' => "&#65180;", 'Ì' => "&#65184;", 'Í' => "&#65188;", 'Î' => "&#65192;",
46 'Ó' => "&#65204;", 'Ô' => "&#65208;", 'Õ' => "&#65212;", 'Ö' => "&#65216;", 'Ø' => "&#65220;", 'Ù' => "&#65224;", 'Ú' => "&#65228;",
47 'Û' => "&#65232;", 'Ý' => "&#65236;", 'Þ' => "&#65240;", 'ß' => "&#65244;", 'á' => "&#65248;", 'ã' => "&#65252;", 'ä' => "&#65256;",
48 'å' => "&#65260;", 'í' => "&#65268;");
50 $ar2unimap4 = array( // One bit character final form
51 'Â' => "&#65154;", 'Ã' => "&#65156;", 'Ä' => "&#65158;", 'Å' => "&#65160;", 'Æ' => "&#65162;", 'Ç' => "&#65166;", 'È' => "&#65168;",
52 'É' => "&#65172;", 'Ê' => "&#65174;", 'Ë' => "&#65178;", 'Ì' => "&#65182;", 'Í' => "&#65186;", 'Î' => "&#65190;", 'Ï' => "&#65194;",
53 'Ð' => "&#65196;", 'Ñ' => "&#65198;", 'Ò' => "&#65200;", 'Ó' => "&#65202;", 'Ô' => "&#65206;", 'Õ' => "&#65210;", 'Ö' => "&#65214;",
54 'Ø' => "&#65218;", 'Ù' => "&#65222;", 'Ú' => "&#65226;", 'Û' => "&#65230;", 'Ý' => "&#65234;", 'Þ' => "&#65238;", 'ß' => "&#65242;",
55 'á' => "&#65246;", 'ã' => "&#65250;", 'ä' => "&#65254;", 'å' => "&#65258;", 'æ' => "&#65262;", 'ì' => "&#65264;", 'í' => "&#65266;");
57 $ar2unimap5 = array( // Two bit character isolated & initial form
58 'áÂ' => "&#65269;",
59 'áÃ' => "&#65271;",
60 'áÅ' => "&#65273;",
61 'áÇ' => "&#65275;");
63 $ar2unimap6 = array( // Two bit character final form
64 'áÂ' => "&#65270;",
65 'áÃ' => "&#65272;",
66 'áÅ' => "&#65274;",
67 'áÇ' => "&#65276;");
68 #================================================// end of character maps//=============================================
70 function ar2uni($sti){
71 global $ar2unimap,$ar2unimap2,$ar2unimap3,$ar2unimap4,$ar2unimap5,$ar2unimap6;
73 # START: (FIX) By Tarek Alwerfally on 16/12/2005
74 if( ($sti[0]>='A' && $sti[0]<='Z') || ($sti[0]>='a' && $sti[0]<='z') ) return( $sti );
75 # END: By Tarek Alwerfally on 16/12/2005
77 # Patch by Elpidio 2004-02-06
78 # If the text is encoded in unicode, reverse the order and return
79 if(strstr($sti,'&#')&&strstr($sti,';')){
80 $buf=explode(';',$sti);
81 $buf=array_reverse($buf);
82 # Remove the first element which is empty
83 unset($buf[0]);
84 $sti=implode(';',$buf);
85 return trim($sti).';';
86 }else{
88 $sti .= " ";
89 $temp = $sti;
90 $sti = strrev($temp);
91 $sti .= " ";
92 $sto='';
93 $len=strlen($sti);
95 for ($i=1; $i < $len-1; $i++){
96 #=========================// for one bit character have 4 forms//================
97 if($ar2unimap3[$sti{$i}]){
99 if($sti{$i-1}==" " and $sti{$i+1}==" "){
100 $sto .=$ar2unimap[$sti{$i}];
102 }elseif($sti{$i-1}==" "){
104 if($ar2unimap3[$sti{$i+1}]){
105 $sto .=$ar2unimap4[$sti{$i}];
106 }else{
107 $sto .=$ar2unimap[$sti{$i}];
110 }elseif($sti{$i+1}==" "){
111 $sto .=$ar2unimap2[$sti{$i}];
112 }else{
114 if($ar2unimap3[$sti{$i+1}]){
115 $sto .=$ar2unimap3[$sti{$i}];
116 }else{
117 $sto .=$ar2unimap2[$sti{$i}];
120 #=========================// for one bit character have 3 forms//================
121 }elseif($ar2unimap2[$sti{$i}]){
123 if($sti{$i-1}==" " and $sti{$i+1}==" "){
124 $sto .=$ar2unimap[$sti{$i}];
126 }elseif($sti{$i-1}==" "){
128 if($ar2unimap3[$sti{$i+1}]){
130 if($sti{$i}=="Â" and $sti{$i+1}=="á"){// to check lam alef Two bit character
131 if($ar2unimap3[$sti{$i+2}]){
132 $sto .=$ar2unimap6["áÂ"];
133 }else{
134 $sto .=$ar2unimap5["áÂ"];
136 $i++;
137 }elseif($sti{$i}=="Ã" and $sti{$i+1}=="á"){
138 if($ar2unimap3[$sti{$i+2}]){
139 $sto .=$ar2unimap6["áÃ"];
140 }else{
141 $sto .=$ar2unimap5["áÃ"];
143 $i++;
144 }elseif($sti{$i}=="Å" and $sti{$i+1}=="á"){
145 if($ar2unimap3[$sti{$i+2}]){
146 $sto .=$ar2unimap6["áÅ"];
147 }else{
148 $sto .=$ar2unimap5["áÅ"];
150 $i++;
151 }elseif($sti{$i}=="Ç" and $sti{$i+1}=="á"){
152 if($ar2unimap3[$sti{$i+2}]){
153 $sto .=$ar2unimap6["áÇ"];
154 }else{
155 $sto .=$ar2unimap5["áÇ"];
157 $i++;
158 }else{
159 $sto .=$ar2unimap4[$sti{$i}];
162 }else{
163 $sto .=$ar2unimap[$sti{$i}];
166 }elseif($sti{$i+1}==" "){
167 $sto .=$ar2unimap[$sti{$i}];
168 }else{
170 if($ar2unimap3[$sti{$i+1}]){
172 if($sti{$i}=="Â" and $sti{$i+1}=="á"){// to check lam alef Two bit character
173 if($ar2unimap3[$sti{$i+2}]){
174 $sto .=$ar2unimap6["áÂ"];
175 }else{
176 $sto .=$ar2unimap5["áÂ"];
178 $i++;
179 }elseif($sti{$i}=="Ã" and $sti{$i+1}=="á"){
180 if($ar2unimap3[$sti{$i+2}]){
181 $sto .=$ar2unimap6["áÃ"];
182 }else{
183 $sto .=$ar2unimap5["áÃ"];
185 $i++;
186 }elseif($sti{$i}=="Å" and $sti{$i+1}=="á"){
187 if($ar2unimap3[$sti{$i+2}]){
188 $sto .=$ar2unimap6["áÅ"];
189 }else{
190 $sto .=$ar2unimap5["áÅ"];
192 $i++;
193 }elseif($sti{$i}=="Ç" and $sti{$i+1}=="á"){
194 if($ar2unimap3[$sti{$i+2}]){
195 $sto .=$ar2unimap6["áÇ"];
196 }else{
197 $sto .=$ar2unimap5["áÇ"];
199 $i++;
200 }else{
201 $sto .=$ar2unimap4[$sti{$i}];
204 }else{
205 $sto .=$ar2unimap[$sti{$i}];
208 #=========================// for one bit character have 2forms//================
209 }elseif($ar2unimap4[$sti{$i}]){
211 if($sti{$i-1}==" " and $sti{$i+1}==" "){
212 $sto .=$ar2unimap[$sti{$i}];
214 }elseif($sti{$i-1}==" "){
216 if($ar2unimap3[$sti{$i+1}]){
217 $sto .=$ar2unimap4[$sti{$i}];
218 }else{
219 $sto .=$ar2unimap[$sti{$i}];
222 }elseif($sti{$i+1}==" "){
223 $sto .=$ar2unimap[$sti{$i}];
224 }else{
226 if($ar2unimap3[$sti{$i+1}]){
227 $sto .=$ar2unimap4[$sti{$i}];
228 }else{
229 $sto .=$ar2unimap[$sti{$i}];
232 #=========================// for one bit character have 1 form//================
233 }elseif($ar2unimap[$sti{$i}]){
234 $sto .=$ar2unimap[$sti{$i}];
235 }else{
236 $sto .= $sti{$i};
239 return $sto;