2 #====================================================================================================#
3 # ar2uni v0.1 (Arabic-win1256 encoder to Unicode) #
4 #====================================================================================================#
6 # This is PHP function for covert Arabic encoding string to #
7 # unicode that can use to show Arabic charactor in PDF Documents. #
8 # It Tested and worked with Multilanguage arial.ttf V2.98 #
11 # version 0.1 : First release. created on ( 22/01/2004) By Walid Fathalla #
13 # Bug Report and Suggestion to: #
15 # fathalla_w@hotmail.com #
17 #====================================================================================================#
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. #
25 #====================================================================================================#
27 #================================================// Arabic character maps//=============================================
29 $ar2unimap = array( // One bit character isolated form
30 ',' => 161, 'º' => 162, '¿' => 163, 'Á' => 164, 'Â' => 165, 'Ã' => 166, 'Ä' => 167,
31 'Å' => 168, 'Æ' => 169, 'Ç' => 170, 'È' => 171, 'É' => 172, 'Ê' => 174, 'Ë' => 176,
32 'Ì' => 177, 'Í' => 178, 'Î' => 179, 'Ï' => 180, 'Ð' => 182, 'Ñ' => 184, 'Ò' => 185,
33 'Ó' => 186, 'Ô' => 187, 'Õ' => 188, 'Ö' => 189, 'Ø' => 190, 'Ù' => 191, 'Ú' => 192,
34 'Û' => 193, 'Ü' => 194, 'Ý' => 195, 'Þ' => 196, 'ß' => 197, 'á' => 198, 'ã' => 199,
35 'ä' => 200, 'å' => 201, 'æ' => 202, 'ì' => 203, 'í' => 204);
37 $ar2unimap2 = array( // One bit character initial form
38 'Â' => 165, 'Ã' => 166, 'Ä' => 167, 'Å' => 168, 'Æ' => 205, 'Ç' => 170, 'È' => 206,
39 'Ê' => 207, 'Ë' => 208, 'Ì' => 209, 'Í' => 210, 'Î' => 211, 'Ï' => 180, 'Ð' => 182,
40 'Ñ' => 184, 'Ò' => 185, 'Ó' => 212, 'Ô' => 213, 'Õ' => 214, 'Ö' => 215, 'Ø' => 190,
41 'Ù' => 191, 'Ú' => 216, 'Û' => 217, 'Ý' => 218, 'Þ' => 219, 'ß' => 220, 'á' => 221,
42 'ã' => 222, 'ä' => 223, 'å' => 224, 'æ' => 202, 'í' => 225);
44 $ar2unimap3 = array( // One bit character medial form
45 'Æ' => 205, 'È' => 206, 'Ê' => 207, 'Ë' => 208, 'Ì' => 209, 'Í' => 210, 'Î' => 211,
46 'Ó' => 212, 'Ô' => 213, 'Õ' => 214, 'Ö' => 215, 'Ø' => 190, 'Ù' => 191, 'Ú' => 226,
47 'Û' => 227, 'Ý' => 228, 'Þ' => 229, 'ß' => 220, 'á' => 221, 'ã' => 222, 'ä' => 223,
48 'å' => 230, 'í' => 225);
50 $ar2unimap4 = array( // One bit character final form
51 'Â' => 231, 'Ã' => 232, 'Ä' => 167, 'Å' => 233, 'Æ' => 234, 'Ç' => 235, 'È' => 171,
52 'É' => 236, 'Ê' => 174, 'Ë' => 176, 'Ì' => 237, 'Í' => 238, 'Î' => 239, 'Ï' => 180,
53 'Ð' => 182, 'Ñ' => 184, 'Ò' => 185, 'Ó' => 186, 'Ô' => 187, 'Õ' => 188, 'Ö' => 189,
54 'Ø' => 190, 'Ù' => 191, 'Ú' => 240, 'Û' => 241, 'Ý' => 195, 'Þ' => 196, 'ß' => 197,
55 'á' => 198, 'ã' => 199, 'ä' => 200, 'å' => 242, 'æ' => 202, 'ì' => 243, 'í' => 244);
57 $ar2unimap5 = array( // Two bit character isolated & initial form
63 $ar2unimap6 = array( // Two bit character final form
71 #================================================// end of character maps//=============================================
73 function ar2uni($sti){
74 global $ar2unimap,$ar2unimap2,$ar2unimap3,$ar2unimap4,$ar2unimap5,$ar2unimap6;
76 # START: (FIX) By Tarek Alwerfally on 16/12/2005
77 if( ($sti[0]>='A' && $sti[0]<='Z') ||
($sti[0]>='a' && $sti[0]<='z') ) return( $sti );
78 # END: By Tarek Alwerfally on 16/12/2005
89 for ($i=1; $i < $len-1; $i++
){
90 #=========================// for one bit character have 4 forms//================
91 if($ar2unimap3[$sti{$i}]){
93 if($sti{$i-1}==" " and $sti{$i+
1}==" "){
94 $sto .=chr($ar2unimap[$sti{$i}]);
96 }elseif($sti{$i-1}==" "){
98 if($ar2unimap3[$sti{$i+
1}]){
99 $sto .=chr($ar2unimap4[$sti{$i}]);
101 $sto .=chr($ar2unimap[$sti{$i}]);
104 }elseif($sti{$i+
1}==" "){
105 $sto .=chr($ar2unimap2[$sti{$i}]);
108 if($ar2unimap3[$sti{$i+
1}]){
109 $sto .=chr($ar2unimap3[$sti{$i}]);
111 $sto .=chr($ar2unimap2[$sti{$i}]);
114 #=========================// for one bit character have 3 forms//================
115 }elseif($ar2unimap2[$sti{$i}]){
117 if($sti{$i-1}==" " and $sti{$i+
1}==" "){
118 $sto .=chr($ar2unimap[$sti{$i}]);
120 }elseif($sti{$i-1}==" "){
122 if($ar2unimap3[$sti{$i+
1}]){
124 if($sti{$i}=="Â" and $sti{$i+
1}=="á"){// to check lam alef Two bit character
125 if($ar2unimap3[$sti{$i+
2}]){
126 $sto .=chr($ar2unimap6["áÂ"]);
128 $sto .=chr($ar2unimap5["áÂ"]);
131 }elseif($sti{$i}=="Ã" and $sti{$i+
1}=="á"){
132 if($ar2unimap3[$sti{$i+
2}]){
133 $sto .=chr($ar2unimap6["áÃ"]);
135 $sto .=chr($ar2unimap5["áÃ"]);
138 }elseif($sti{$i}=="Å" and $sti{$i+
1}=="á"){
139 if($ar2unimap3[$sti{$i+
2}]){
140 $sto .=chr($ar2unimap6["áÅ"]);
142 $sto .=chr($ar2unimap5["áÅ"]);
145 }elseif($sti{$i}=="Ç" and $sti{$i+
1}=="á"){
146 if($ar2unimap3[$sti{$i+
2}]){
147 $sto .=chr($ar2unimap6["áÇ"]);
149 $sto .=chr($ar2unimap5["áÇ"]);
153 $sto .=chr($ar2unimap4[$sti{$i}]);
157 $sto .=chr($ar2unimap[$sti{$i}]);
160 }elseif($sti{$i+
1}==" "){
161 $sto .=chr($ar2unimap[$sti{$i}]);
164 if($ar2unimap3[$sti{$i+
1}]){
166 if($sti{$i}=="Â" and $sti{$i+
1}=="á"){// to check lam alef Two bit character
167 if($ar2unimap3[$sti{$i+
2}]){
168 $sto .=chr($ar2unimap6["áÂ"]);
170 $sto .=chr($ar2unimap5["áÂ"]);
173 }elseif($sti{$i}=="Ã" and $sti{$i+
1}=="á"){
174 if($ar2unimap3[$sti{$i+
2}]){
175 $sto .=chr($ar2unimap6["áÃ"]);
177 $sto .=chr($ar2unimap5["áÃ"]);
180 }elseif($sti{$i}=="Å" and $sti{$i+
1}=="á"){
181 if($ar2unimap3[$sti{$i+
2}]){
182 $sto .=chr($ar2unimap6["áÅ"]);
184 $sto .=chr($ar2unimap5["áÅ"]);
187 }elseif($sti{$i}=="Ç" and $sti{$i+
1}=="á"){
188 if($ar2unimap3[$sti{$i+
2}]){
189 $sto .=chr($ar2unimap6["áÇ"]);
191 $sto .=chr($ar2unimap5["áÇ"]);
195 $sto .=chr($ar2unimap4[$sti{$i}]);
199 $sto .=chr($ar2unimap[$sti{$i}]);
202 #=========================// for one bit character have 2forms//================
203 }elseif($ar2unimap4[$sti{$i}]){
205 if($sti{$i-1}==" " and $sti{$i+
1}==" "){
206 $sto .=chr($ar2unimap[$sti{$i}]);
208 }elseif($sti{$i-1}==" "){
210 if($ar2unimap3[$sti{$i+
1}]){
211 $sto .=chr($ar2unimap4[$sti{$i}]);
213 $sto .=chr($ar2unimap[$sti{$i}]);
216 }elseif($sti{$i+
1}==" "){
217 $sto .=chr($ar2unimap[$sti{$i}]);
220 if($ar2unimap3[$sti{$i+
1}]){
221 $sto .=chr($ar2unimap4[$sti{$i}]);
223 $sto .=chr($ar2unimap[$sti{$i}]);
226 #=========================// for one bit character have 1 form//================
227 }elseif($ar2unimap[$sti{$i}]){
228 $sto .=chr($ar2unimap[$sti{$i}]);