source-class-Com.Tecnick.Unicode.Bidi.Shaping.Arabic

It appears that you are using AdBlocking software. The cost of running this website is covered by advertisements. If you like it please feel free to a small amount of money to secure the future of this website.
  1: <?php
  2: /**
  3:  * Arabic.php
  4:  *
  5:  * @since       2011-05-23
  6:  * @category    Library
  7:  * @package     Unicode
  8:  * @author      Nicola Asuni <info@tecnick.com>
  9:  * @copyright   2011-2015 Nicola Asuni - Tecnick.com LTD
 10:  * @license     http://www.gnu.org/copyleft/lesser.html GNU-LGPL v3 (see LICENSE.TXT)
 11:  * @link        https://github.com/tecnickcom/tc-lib-unicode
 12:  *
 13:  * This file is part of tc-lib-unicode software library.
 14:  */
 15: 
 16: namespace Com\Tecnick\Unicode\Bidi\Shaping;
 17: 
 18: use \Com\Tecnick\Unicode\Data\Arabic as UniArabic;
 19: 
 20: /**
 21:  * Com\Tecnick\Unicode\Bidi\Shaping\Arabic
 22:  *
 23:  * @since       2015-07-13
 24:  * @category    Library
 25:  * @package     Unicode
 26:  * @author      Nicola Asuni <info@tecnick.com>
 27:  * @copyright   2011-2015 Nicola Asuni - Tecnick.com LTD
 28:  * @license     http://www.gnu.org/copyleft/lesser.html GNU-LGPL v3 (see LICENSE.TXT)
 29:  * @link        https://github.com/tecnickcom/tc-lib-unicode
 30:  */
 31: abstract class Arabic
 32: {
 33:     /**
 34:      * Check if it is a LAA LETTER
 35:      *
 36:      * @return bool
 37:      */
 38:     protected function isLaaLetter($prevchar, $thischar)
 39:     {
 40:         if (($prevchar !== false)
 41:             && ($prevchar['char'] == UniArabic::LAM)
 42:             && (isset(UniArabic::$laa[$thischar['char']]))
 43:         ) {
 44:             return true;
 45:         }
 46:         return false;
 47:     }
 48: 
 49:     /**
 50:      * Check next char
 51:      *
 52:      * @param int       $thischar Current char
 53:      * @param int|false $nextchar Next char
 54:      *
 55:      * @return bool
 56:      */
 57:     protected function hasNextChar($thischar, $nextchar)
 58:     {
 59:         return (($nextchar !== false)
 60:             && (($nextchar['otype'] == 'AL') || ($nextchar['otype'] == 'NSM'))
 61:             && ($nextchar['type'] == $thischar['type'])
 62:             && ($nextchar['char'] != UniArabic::QUESTION_MARK)
 63:         );
 64:     }
 65: 
 66:     /**
 67:      * Check previous char
 68:      *
 69:      * @param int|false $prevchar Previous char
 70:      * @param int       $thischar Current char
 71:      *
 72:      * @return bool
 73:      */
 74:     protected function hasPrevChar($prevchar, $thischar)
 75:     {
 76:         return ((($prevchar !== false)
 77:             && (($prevchar['otype'] == 'AL') || ($prevchar['otype'] == 'NSM'))
 78:             && ($prevchar['type'] == $thischar['type']))
 79:         );
 80:     }
 81: 
 82:     /**
 83:      * Check if it is a middle character
 84:      *
 85:      * @param int|false $prevchar Previous char
 86:      * @param int       $thischar Current char
 87:      * @param int|false $nextchar Next char
 88:      *
 89:      * @return bool
 90:      */
 91:     protected function isMiddleChar($prevchar, $thischar, $nextchar)
 92:     {
 93:         return ($this->hasPrevChar($prevchar, $thischar) && $this->hasNextChar($thischar, $nextchar));
 94:     }
 95: 
 96:     /**
 97:      * Check if it is a final character
 98:      *
 99:      * @param int|false $prevchar Previous char
100:      * @param int       $thischar Current char
101:      * @param int|false $nextchar Next char
102:      *
103:      * @return bool
104:      */
105:     protected function isFinalChar($prevchar, $thischar, $nextchar)
106:     {
107:         return ($this->hasPrevChar($prevchar, $thischar)
108:             || (($nextchar !== false) && ($nextchar['char'] == UniArabic::QUESTION_MARK))
109:         );
110:     }
111:     
112:     /**
113:      * Set initial or middle char
114:      *
115:      * @param int       $idx       Current index
116:      * @param int|false $prevchar Previous char
117:      * @param int       $thischar Current char
118:      * @param array     $arabicarr Substitution array
119:      */
120:     protected function setMiddleChar($idx, $prevchar, $thischar, $arabicarr)
121:     {
122:         if (in_array($prevchar['char'], UniArabic::$end)) {
123:             if (isset($arabicarr[$thischar['char']][2])) {
124:                 // initial
125:                 $this->newchardata[$idx]['char'] = $arabicarr[$thischar['char']][2];
126:             }
127:         } else {
128:             if (isset($arabicarr[$thischar['char']][3])) {
129:                 // medial
130:                 $this->newchardata[$idx]['char'] = $arabicarr[$thischar['char']][3];
131:             }
132:         }
133:     }
134:     
135:     /**
136:      * Set initial char
137:      *
138:      * @param int       $idx       Current index
139:      * @param int       $thischar Current char
140:      * @param array     $arabicarr Substitution array
141:      */
142:     protected function setInitialChar($idx, $thischar, $arabicarr)
143:     {
144:         if (isset($arabicarr[$this->seq['item'][$idx]['char']][2])) {
145:             $this->newchardata[$idx]['char'] = $arabicarr[$thischar['char']][2];
146:         }
147:     }
148:     
149:     /**
150:      * Set final char
151:      *
152:      * @param int       $idx       Current index
153:      * @param int|false $prevchar  Previous char
154:      * @param int       $thischar  Current char
155:      * @param array     $arabicarr Substitution array
156:      */
157:     protected function setFinalChar($idx, $prevchar, $thischar, $arabicarr)
158:     {
159:         if (($idx > 1)
160:             && ($thischar['char'] == UniArabic::HEH)
161:             && ($this->seq['item'][($idx - 1)]['char'] == UniArabic::LAM)
162:             && ($this->seq['item'][($idx - 2)]['char'] == UniArabic::LAM)
163:         ) {
164:             // Allah Word
165:             $this->newchardata[($idx - 2)]['char'] = false;
166:             $this->newchardata[($idx - 1)]['char'] = false;
167:             $this->newchardata[$idx]['char'] = UniArabic::LIGATURE_ALLAH_ISOLATED_FORM;
168:         } else {
169:             if (($prevchar !== false) && in_array($prevchar['char'], UniArabic::$end)) {
170:                 if (isset($arabicarr[$thischar['char']][0])) {
171:                     // isolated
172:                     $this->newchardata[$idx]['char'] = $arabicarr[$thischar['char']][0];
173:                 }
174:             } else {
175:                 if (isset($arabicarr[$thischar['char']][1])) {
176:                     // final
177:                     $this->newchardata[$idx]['char'] = $arabicarr[$thischar['char']][1];
178:                 }
179:             }
180:         }
181:     }
182: 
183:     /**
184:      * Process AL character
185:      *
186:      * @param int       $idx      Current index
187:      * @param int       $pos      Current char position
188:      * @param int|false $prevchar Previous char
189:      * @param int       $thischar Current char
190:      * @param int|false $nextchar Next char
191:      */
192:     protected function processAlChar($idx, $pos, $prevchar, $thischar, $nextchar)
193:     {
194:         $laaletter = $this->isLaaLetter($prevchar, $thischar);
195:         if ($laaletter) {
196:             $arabicarr = UniArabic::$laa;
197:             $prevchar = (($pos > 1) ? $this->alchars[($pos - 2)] : false);
198:         } else {
199:             $arabicarr = UniArabic::$substitute;
200:         }
201: 
202:         if ($this->isMiddleChar($prevchar, $thischar, $nextchar)) {
203:             $this->setMiddleChar($idx, $prevchar, $thischar, $arabicarr);
204:         } elseif ($this->hasNextChar($thischar, $nextchar)) {
205:             $this->setInitialChar($idx, $thischar, $arabicarr);
206:         } elseif ($this->isFinalChar($prevchar, $thischar, $nextchar)) {
207:             // final
208:             $this->setFinalChar($idx, $prevchar, $thischar, $arabicarr);
209:         } elseif (isset($arabicarr[$thischar['char']][0])) {
210:             // isolated
211:             $this->newchardata[$idx]['char'] = $arabicarr[$thischar['char']][0];
212:         }
213: 
214:         
215:         // if laa letter
216:         if ($laaletter) {
217:             // mark characters to delete with false
218:             $this->newchardata[($this->alchars[($pos - 1)]['i'])]['char'] = false;
219:         }
220:     }
221: }
222: 
 

© 2004-2017 – Nicola Asuni - Tecnick.com - All rights reserved.
about - disclaimer - privacy