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

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:  * Shaping.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;
 17: 
 18: use \Com\Tecnick\Unicode\Data\Constant as UniConstant;
 19: use \Com\Tecnick\Unicode\Data\Arabic as UniArabic;
 20: 
 21: /**
 22:  * Com\Tecnick\Unicode\Bidi\Shaping
 23:  *
 24:  * @since       2015-07-13
 25:  * @category    Library
 26:  * @package     Unicode
 27:  * @author      Nicola Asuni <info@tecnick.com>
 28:  * @copyright   2011-2015 Nicola Asuni - Tecnick.com LTD
 29:  * @license     http://www.gnu.org/copyleft/lesser.html GNU-LGPL v3 (see LICENSE.TXT)
 30:  * @link        https://github.com/tecnickcom/tc-lib-unicode
 31:  */
 32: class Shaping extends \Com\Tecnick\Unicode\Bidi\Shaping\Arabic
 33: {
 34:     /**
 35:      * Sequence to process and return
 36:      *
 37:      * @var array
 38:      */
 39:     protected $seq = array();
 40: 
 41:     /**
 42:      * Array of processed chars
 43:      *
 44:      * @var array
 45:      */
 46:     protected $newchardata = array();
 47: 
 48:     /**
 49:      * Array of AL characters
 50:      *
 51:      * @var array
 52:      */
 53:     protected $alchars = array();
 54: 
 55:     /**
 56:      * Number of AL characters
 57:      *
 58:      * @var int
 59:      */
 60:     protected $numalchars = 0;
 61: 
 62:     /**
 63:      * Shaping
 64:      * Cursively connected scripts, such as Arabic or Syriac,
 65:      * require the selection of positional character shapes that depend on adjacent characters.
 66:      * Shaping is logically applied after the Bidirectional Algorithm is used and is limited to
 67:      * characters within the same directional run.
 68:      *
 69:      * @param array $seq isolated Sequence array
 70:      */
 71:     public function __construct($seq)
 72:     {
 73:         $this->seq = $seq;
 74:         $this->newchardata = $seq['item'];
 75:         $this->process();
 76:     }
 77: 
 78:     /**
 79:      * Returns the processed sequence
 80:      *
 81:      * @return array
 82:      */
 83:     public function getSequence()
 84:     {
 85:         return $this->seq;
 86:     }
 87: 
 88:     /**
 89:      * Process
 90:      */
 91:     protected function process()
 92:     {
 93:         $this->setAlChars();
 94:         for ($idx = 0; $idx < $this->seq['length']; ++$idx) {
 95:             if ($this->seq['item'][$idx]['otype'] == 'AL') {
 96:                 $thischar = $this->seq['item'][$idx];
 97:                 $pos = $thischar['x'];
 98:                 $prevchar = (($pos > 0) ? $this->alchars[($pos - 1)] : false);
 99:                 $nextchar = ((($pos + 1) < $this->numalchars) ? $this->alchars[($pos + 1)] : false);
100:                 $this->processAlChar($idx, $pos, $prevchar, $thischar, $nextchar);
101:             }
102:         }
103:         $this->combineShadda();
104:         $this->removeDeletedChars();
105:         $this->seq['item'] = array_values($this->newchardata);
106:         unset($this->newchardata);
107:     }
108: 
109:     /**
110:      * Set AL chars array
111:      */
112:     protected function setAlChars()
113:     {
114:         $this->numalchars = 0;
115:         for ($idx = 0; $idx < $this->seq['length']; ++$idx) {
116:             if (($this->seq['item'][$idx]['otype'] == 'AL')
117:                 || ($this->seq['item'][$idx]['char'] == UniConstant::SPACE)
118:                 || ($this->seq['item'][$idx]['char'] == UniConstant::ZERO_WIDTH_NON_JOINER)
119:             ) {
120:                 $this->alchars[$this->numalchars] = $this->seq['item'][$idx];
121:                 $this->alchars[$this->numalchars]['i'] = $idx;
122:                 $this->seq['item'][$idx]['x'] = $this->numalchars;
123:                 ++$this->numalchars;
124:             }
125:         }
126:     }
127: 
128:     /**
129:      * Combine characters that can occur with Arabic Shadda (0651 HEX, 1617 DEC).
130:      * Putting the combining mark and shadda in the same glyph allows
131:      * to avoid the two marks overlapping each other in an illegible manner.
132:      */
133:     protected function combineShadda()
134:     {
135:         $last = ($this->seq['length'] - 1);
136:         for ($idx = 0; $idx < $last; ++$idx) {
137:             if (($this->newchardata[$idx]['char'] == UniArabic::SHADDA)
138:                 && (isset(UniArabic::$diacritic[($this->newchardata[($idx + 1)]['char'])]))
139:             ) {
140:                 $this->newchardata[$idx]['char'] = false;
141:                 $this->newchardata[($idx + 1)]['char'] = UniArabic::$diacritic[
142:                     ($this->newchardata[($idx + 1)]['char'])
143:                 ];
144:             }
145:         }
146:     }
147: 
148:     /**
149:      * Remove marked characters
150:      */
151:     protected function removeDeletedChars()
152:     {
153:         foreach ($this->newchardata as $key => $value) {
154:             if ($value['char'] === false) {
155:                 unset($this->newchardata[$key]);
156:             }
157:         }
158:     }
159: }
160: 
 

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