|
- <?php
-
- require_once __DIR__ . '/../MpdfException.php';
-
- class INDIC
- {
-
-
-
- const OT_X = 0;
- const OT_C = 1;
- const OT_V = 2;
- const OT_N = 3;
- const OT_H = 4;
- const OT_ZWNJ = 5;
- const OT_ZWJ = 6;
- const OT_M = 7;
- const OT_SM = 8;
- const OT_VD = 9;
- const OT_A = 10;
- const OT_NBSP = 11;
- const OT_DOTTEDCIRCLE = 12;
- const OT_RS = 13;
- const OT_Coeng = 14;
- const OT_Repha = 15;
-
- const OT_Ra = 16;
- const OT_CM = 17;
-
-
-
- public static $indic_category_char = array(
- 'x',
- 'C',
- 'V',
- 'N',
- 'H',
- 'Z',
- 'J',
- 'M',
- 'S',
- 'v',
- 'A',
-
- 's',
- 'D',
- 'F',
- 'G',
- 'r',
- 'R',
- 'm',
- );
-
-
-
-
-
- const POS_START = 0;
-
- const POS_RA_TO_BECOME_REPH = 1;
- const POS_PRE_M = 2;
- const POS_PRE_C = 3;
-
- const POS_BASE_C = 4;
- const POS_AFTER_MAIN = 5;
-
- const POS_ABOVE_C = 6;
-
- const POS_BEFORE_SUB = 7;
- const POS_BELOW_C = 8;
- const POS_AFTER_SUB = 9;
-
- const POS_BEFORE_POST = 10;
- const POS_POST_C = 11;
- const POS_AFTER_POST = 12;
-
- const POS_FINAL_C = 13;
- const POS_SMVD = 14;
-
- const POS_END = 15;
-
-
-
-
-
-
- const _NUKT = 0;
- const _AKHN = 1;
- const RPHF = 2;
- const _RKRF = 3;
- const PREF = 4;
- const BLWF = 5;
- const HALF = 6;
- const ABVF = 7;
- const PSTF = 8;
- const CFAR = 9;
- const _VATU = 10;
- const _CJCT = 11;
- const INIT = 12;
-
- public static function set_indic_properties(&$info, $scriptblock)
- {
- $u = $info['uni'];
- $type = self::indic_get_categories($u);
- $cat = ($type & 0x7F);
- $pos = ($type >> 8);
-
-
-
-
- if ($u == 0x17D1)
- $cat = self::OT_X;
-
- if ($cat == self::OT_X && self::in_range($u, 0x17CB, 0x17D3)) {
-
- $cat = self::OT_M;
- $pos = self::POS_ABOVE_C;
- }
-
- if ($u == 0x17C6)
- $cat = self::OT_N;
-
- if ($u == 0x17D2)
- $cat = self::OT_Coeng;
-
-
-
-
- if (self::in_range($u, 0x0951, 0x0954))
- $cat = self::OT_VD;
-
- if ($u == 0x200C)
- $cat = self::OT_ZWNJ;
- else if ($u == 0x200D)
- $cat = self::OT_ZWJ;
- else if ($u == 0x25CC)
- $cat = self::OT_DOTTEDCIRCLE;
- else if ($u == 0x0A71)
- $cat = self::OT_SM;
-
- if ($cat == self::OT_Repha) {
-
-
- if ($info['general_category'] == UCDN::UNICODE_GENERAL_CATEGORY_NON_SPACING_MARK)
- $cat = self::OT_N;
- }
-
-
-
-
- if ((self::FLAG($cat) & (self::FLAG(self::OT_C) | self::FLAG(self::OT_CM) | self::FLAG(self::OT_Ra) | self::FLAG(self::OT_V) | self::FLAG(self::OT_NBSP) | self::FLAG(self::OT_DOTTEDCIRCLE)))) {
- if ($scriptblock == UCDN::SCRIPT_KHMER)
- $pos = self::POS_BELOW_C;
- else
- $pos = self::POS_BASE_C;
-
- if (self::is_ra($u))
- $cat = self::OT_Ra;
- }
- else if ($cat == self::OT_M) {
- $pos = self::matra_position($u, $pos);
- } else if ($cat == self::OT_SM || $cat == self::OT_VD) {
- $pos = self::POS_SMVD;
- }
-
- if ($u == 0x0B01)
- $pos = self::POS_BEFORE_SUB;
-
- $info['indic_category'] = $cat;
- $info['indic_position'] = $pos;
- }
-
-
- const CONSONANT_SYLLABLE = 0;
- const VOWEL_SYLLABLE = 1;
- const STANDALONE_CLUSTER = 2;
- const BROKEN_CLUSTER = 3;
- const NON_INDIC_CLUSTER = 4;
-
- public static function set_syllables(&$o, $s, &$broken_syllables)
- {
- $ptr = 0;
- $syllable_serial = 1;
- $broken_syllables = false;
-
- while ($ptr < strlen($s)) {
- $match = '';
- $syllable_length = 1;
- $syllable_type = self::NON_INDIC_CLUSTER;
-
-
- if (preg_match('/^([CR]m*[N]?(H[ZJ]?|[ZJ]H))*[CR]m*[N]?[A]?(H[ZJ]?|[M]*[N]?[H]?)?[S]?[v]{0,2}/', substr($s, $ptr), $ma)) {
-
-
- $syllable_length = strlen($ma[0]);
- $syllable_type = self::CONSONANT_SYLLABLE;
- }
-
-
- else if (preg_match('/^(RH|r)?V[N]?([ZJ]?H[CR]m*|J[CR]m*)?([M]*[N]?[H]?)?[S]?[v]{0,2}/', substr($s, $ptr), $ma)) {
-
-
- $syllable_length = strlen($ma[0]);
- $syllable_type = self::VOWEL_SYLLABLE;
- }
-
-
-
-
- else if (($ptr == 0 ||
- $o[$ptr - 1]['general_category'] < UCDN::UNICODE_GENERAL_CATEGORY_LOWERCASE_LETTER ||
- $o[$ptr - 1]['general_category'] > UCDN::UNICODE_GENERAL_CATEGORY_NON_SPACING_MARK
- ) && (preg_match('/^(RH|r)?[sD][N]?([ZJ]?H[CR]m*)?([M]*[N]?[H]?)?[S]?[v]{0,2}/', substr($s, $ptr), $ma))) {
-
-
- $syllable_length = strlen($ma[0]);
- $syllable_type = self::STANDALONE_CLUSTER;
- }
-
-
- else if (preg_match('/^(RH|r)?[N]?([ZJ]?H[CR])?([M]*[N]?[H]?)?[S]?[v]{0,2}/', substr($s, $ptr), $ma)) {
-
-
- if (strlen($ma[0])) {
- $syllable_length = strlen($ma[0]);
- $syllable_type = self::BROKEN_CLUSTER;
- $broken_syllables = true;
- }
- }
-
- for ($i = $ptr; $i < $ptr + $syllable_length; $i++) {
- $o[$i]['syllable'] = ($syllable_serial << 4) | $syllable_type;
- }
- $ptr += $syllable_length;
- $syllable_serial++;
- if ($syllable_serial == 16)
- $syllable_serial = 1;
- }
- }
-
- public static function set_syllables_sinhala(&$o, $s, &$broken_syllables)
- {
- $ptr = 0;
- $syllable_serial = 1;
- $broken_syllables = false;
-
- while ($ptr < strlen($s)) {
- $match = '';
- $syllable_length = 1;
- $syllable_type = self::NON_INDIC_CLUSTER;
-
-
- if (preg_match('/^([CR]HJ|[CR]JH){0,8}[CR][HM]{0,3}[S]{0,1}/', substr($s, $ptr), $ma)) {
- $syllable_length = strlen($ma[0]);
- $syllable_type = self::CONSONANT_SYLLABLE;
- }
-
-
- else if (preg_match('/^V[S]{0,1}/', substr($s, $ptr), $ma)) {
- $syllable_length = strlen($ma[0]);
- $syllable_type = self::VOWEL_SYLLABLE;
- }
-
- for ($i = $ptr; $i < $ptr + $syllable_length; $i++) {
- $o[$i]['syllable'] = ($syllable_serial << 4) | $syllable_type;
- }
- $ptr += $syllable_length;
- $syllable_serial++;
- if ($syllable_serial == 16)
- $syllable_serial = 1;
- }
- }
-
- public static function set_syllables_khmer(&$o, $s, &$broken_syllables)
- {
- $ptr = 0;
- $syllable_serial = 1;
- $broken_syllables = false;
-
- while ($ptr < strlen($s)) {
- $match = '';
- $syllable_length = 1;
- $syllable_type = self::NON_INDIC_CLUSTER;
-
- if (preg_match('/^r?([CR]J?((Z?F)?[N]{0,2})?[ZJ]?G(JN?)?){0,4}[CR]J?((Z?F)?[N]{0,2})?A?((([ZJ]?G(JN?)?)|GZ)|(GJ)?([ZJ]{0,3}MN?(H|JHJR)?){0,4})?(G([CR]J?((Z?F)?[N]{0,2})?|V))?(SZ?)?[v]{0,2}/', substr($s, $ptr), $ma)) {
- $syllable_length = strlen($ma[0]);
- $syllable_type = self::CONSONANT_SYLLABLE;
- }
-
- else if (preg_match('/^(RH|r)?V((Z?F)?[N]{0,2})?(J|([ZJ]?G(JN?)?[CR]J?((Z?F)?[N]{0,2})?){0,4}((([ZJ]?G(JN?)?)|GZ)|(GJ)?([ZJ]{0,3}MN?(H|JHJR)?){0,4})?(G([CR]J?((Z?F)?[N]{0,2})?|V))?(SZ?)?[v]{0,2})/', substr($s, $ptr), $ma)) {
- $syllable_length = strlen($ma[0]);
- $syllable_type = self::VOWEL_SYLLABLE;
- }
-
-
-
- else if (preg_match('/^(RH|r)?((Z?F)?[N]{0,2})?(([ZJ]?G(JN?)?)[CR]J?((Z?F)?[N]{0,2})?){0,4}((([ZJ]?G(JN?)?)|GZ)|(GJ)?([ZJ]{0,3}MN?(H|JHJR)?){0,4})(G([CR]J?((Z?F)?[N]{0,2})?|V))?(SZ?)?[v]{0,2}/', substr($s, $ptr), $ma)) {
- if (strlen($ma[0])) {
- $syllable_length = strlen($ma[0]);
- $syllable_type = self::BROKEN_CLUSTER;
- $broken_syllables = true;
- }
- }
-
- for ($i = $ptr; $i < $ptr + $syllable_length; $i++) {
- $o[$i]['syllable'] = ($syllable_serial << 4) | $syllable_type;
- }
- $ptr += $syllable_length;
- $syllable_serial++;
- if ($syllable_serial == 16)
- $syllable_serial = 1;
- }
- }
-
- public static function initial_reordering(&$info, $GSUBdata, $broken_syllables, $indic_config, $scriptblock, $is_old_spec, $dottedcircle)
- {
-
- self::update_consonant_positions($info, $GSUBdata);
-
- if ($broken_syllables && $dottedcircle) {
- self::insert_dotted_circles($info, $dottedcircle);
- }
-
- $count = count($info);
- if (!$count)
- return;
- $last = 0;
- $last_syllable = $info[0]['syllable'];
- for ($i = 1; $i < $count; $i++) {
- if ($last_syllable != $info[$i]['syllable']) {
- self::initial_reordering_syllable($info, $GSUBdata, $indic_config, $scriptblock, $is_old_spec, $last, $i);
- $last = $i;
- $last_syllable = $info[$last]['syllable'];
- }
- }
- self::initial_reordering_syllable($info, $GSUBdata, $indic_config, $scriptblock, $is_old_spec, $last, $count);
- }
-
- public static function update_consonant_positions(&$info, $GSUBdata)
- {
- $count = count($info);
- for ($i = 0; $i < $count; $i++) {
- if ($info[$i]['indic_position'] == self::POS_BASE_C) {
- $c = $info[$i]['uni'];
-
- if (isset($GSUBdata['pref'][$c])) {
- $info[$i]['indic_position'] = self::POS_POST_C;
- } else if (isset($GSUBdata['blwf'][$c])) {
- $info[$i]['indic_position'] = self::POS_BELOW_C;
- } else if (isset($GSUBdata['pstf'][$c])) {
- $info[$i]['indic_position'] = self::POS_POST_C;
- }
- }
- }
- }
-
- public static function insert_dotted_circles(&$info, $dottedcircle)
- {
- $idx = 0;
- $last_syllable = 0;
- while ($idx < count($info)) {
- $syllable = $info[$idx]['syllable'];
- $syllable_type = ($syllable & 0x0F);
- if ($last_syllable != $syllable && $syllable_type == self::BROKEN_CLUSTER) {
- $last_syllable = $syllable;
-
- $dottedcircle[0]['syllable'] = $info[$idx]['syllable'];
-
-
- while ($idx < count($info) && $last_syllable == $info[$idx]['syllable'] && $info[$idx]['indic_category'] == self::OT_Repha)
- $idx++;
- array_splice($info, $idx, 0, $dottedcircle);
- } else {
- $idx++;
- }
- }
-
-
-
- if (isset($info[$idx])) {
- throw new MpdfException('Unexpected error occured in Indic processing');
- }
-
-
-
-
-
-
-
- }
-
-
-
-
- public static function initial_reordering_syllable(&$info, $GSUBdata, $indic_config, $scriptblock, $is_old_spec, $start, $end)
- {
-
-
-
-
- $syllable_type = ($info[$start]['syllable'] & 0x0F);
- if ($syllable_type == self::NON_INDIC_CLUSTER) {
- return;
- }
- if ($syllable_type == self::BROKEN_CLUSTER || $syllable_type == self::STANDALONE_CLUSTER) {
-
-
-
- if ($info[$end - 1]['indic_category'] == self::OT_DOTTEDCIRCLE) {
- return;
- }
- }
-
-
-
-
- $base = $end;
- $has_reph = false;
- $limit = $start;
-
- if ($scriptblock != UCDN::SCRIPT_KHMER) {
-
-
- if (count($GSUBdata['rphf']) && $start + 3 <= $end &&
- (
- ($indic_config[4] == self::REPH_MODE_IMPLICIT && !self::is_joiner($info[$start + 2])) ||
- ($indic_config[4] == self::REPH_MODE_EXPLICIT && $info[$start + 2]['indic_category'] == self::OT_ZWJ)
- )) {
-
-
-
- if (isset($GSUBdata['rphf'][$info[$start]['uni']]) && self::is_halant_or_coeng($info[$start + 1])) {
- $limit += 2;
- while ($limit < $end && self::is_joiner($info[$limit]))
- $limit++;
- $base = $start;
- $has_reph = true;
- }
- } else if ($indic_config[4] == self::REPH_MODE_LOG_REPHA && $info[$start]['indic_category'] == self::OT_Repha) {
- $limit += 1;
- while ($limit < $end && self::is_joiner($info[$limit]))
- $limit++;
- $base = $start;
- $has_reph = true;
- }
- }
-
- switch ($indic_config[2]) {
- case self::BASE_POS_LAST:
-
- $i = $end;
- $seen_below = false;
- do {
- $i--;
-
- if (self::is_consonant($info[$i])) {
-
-
- if ($info[$i]['indic_position'] != self::POS_BELOW_C && ($info[$i]['indic_position'] != self::POS_POST_C || $seen_below)) {
- $base = $i;
- break;
- }
- if ($info[$i]['indic_position'] == self::POS_BELOW_C)
- $seen_below = true;
-
-
-
-
-
-
- $base = $i;
- }
- else {
-
-
- if ($start < $i && $info[$i]['indic_category'] == self::OT_ZWJ && $info[$i - 1]['indic_category'] == self::OT_H) {
- if (!defined("OMIT_INDIC_FIX_1") || OMIT_INDIC_FIX_1 != 1) {
- $base = $i;
- }
- break;
- }
-
- if ($start < $i && $info[$i]['indic_category'] == self::OT_ZWNJ) {
- break;
- }
- }
- } while ($i > $limit);
- break;
-
- case self::BASE_POS_FIRST:
-
-
- if (!$has_reph)
- $base = $limit;
-
-
-
- for ($i = $limit; $i < $end; $i++) {
- if (self::is_consonant($info[$i]) && $info[$i]['indic_position'] == self::POS_BASE_C) {
- if ($limit < $i && $info[$i - 1]['indic_category'] == self::OT_ZWJ)
- break;
- else
- $base = $i;
- }
- }
-
-
- for ($i = $base + 1; $i < $end; $i++) {
- if (self::is_consonant($info[$i]) && $info[$i]['indic_position'] == self::POS_BASE_C)
- $info[$i]['indic_position'] = self::POS_BELOW_C;
- }
- break;
-
-
-
- }
-
-
-
- if ($scriptblock != UCDN::SCRIPT_KHMER) {
- if ($has_reph && $base == $start && $limit - $base <= 2) {
-
- $has_reph = false;
- }
- }
-
-
-
-
-
-
-
-
-
-
- for ($i = $start; $i < $base; $i++)
- $info[$i]['indic_position'] = min(self::POS_PRE_C, $info[$i]['indic_position']);
-
- if ($base < $end)
- $info[$base]['indic_position'] = self::POS_BASE_C;
-
-
-
- for ($i = $base + 1; $i < $end; $i++)
- if ($info[$i]['indic_category'] == self::OT_M) {
- for ($j = $i + 1; $j < $end; $j++)
- if (self::is_consonant($info[$j])) {
- $info[$j]['indic_position'] = self::POS_FINAL_C;
- break;
- }
- break;
- }
-
-
- if ($scriptblock != UCDN::SCRIPT_KHMER) {
- if ($has_reph)
- $info[$start]['indic_position'] = self::POS_RA_TO_BECOME_REPH;
- }
-
-
-
-
- if ($is_old_spec) {
- for ($i = $base + 1; $i < $end; $i++) {
- if ($info[$i]['indic_category'] == self::OT_H) {
- for ($j = $end - 1; $j > $i; $j--) {
- if (self::is_consonant($info[$j]) || $info[$j]['indic_category'] == self::OT_H) {
- break;
- }
- }
- if ($info[$j]['indic_category'] != self::OT_H && $j > $i) {
-
- self::_move_info_pos($info, $i, $j + 1);
- }
- break;
- }
- }
- }
-
-
- $last_pos = self::POS_START;
- for ($i = $start; $i < $end; $i++) {
- if ((self::FLAG($info[$i]['indic_category']) & (self::FLAG(self::OT_ZWJ) | self::FLAG(self::OT_ZWNJ) | self::FLAG(self::OT_N) | self::FLAG(self::OT_RS) | self::FLAG(self::OT_H) | self::FLAG(self::OT_Coeng) ))) {
- $info[$i]['indic_position'] = $last_pos;
- if ($info[$i]['indic_category'] == self::OT_H && $info[$i]['indic_position'] == self::POS_PRE_M) {
-
-
- for ($j = $i; $j > $start; $j--)
- if ($info[$j - 1]['indic_position'] != self::POS_PRE_M) {
- $info[$i]['indic_position'] = $info[$j - 1]['indic_position'];
- break;
- }
- }
- } else if ($info[$i]['indic_position'] != self::POS_SMVD) {
- $last_pos = $info[$i]['indic_position'];
- }
- }
-
-
- $last_halant = $end;
- for ($i = $base + 1; $i < $end; $i++) {
- if (self::is_halant_or_coeng($info[$i]))
- $last_halant = $i;
- else if (self::is_consonant($info[$i])) {
- for ($j = $last_halant; $j < $i; $j++)
- if ($info[$j]['indic_position'] != self::POS_SMVD)
- $info[$j]['indic_position'] = $info[$i]['indic_position'];
- }
- }
-
-
- if ($scriptblock == UCDN::SCRIPT_KHMER) {
-
-
- for ($i = $base + 1; $i < $end; $i++) {
- if (self::is_halant_or_coeng($info[$i]) && self::is_ra($info[$i + 1]['uni'])) {
- $info[$i]['indic_position'] = self::POS_PRE_C;
- $info[$i + 1]['indic_position'] = self::POS_PRE_C;
- break;
- }
- }
- }
-
-
-
-
-
-
- for ($i = $start; $i < $end; $i++) {
- $info[$i]['mask'] = 0;
- }
-
-
- if ($scriptblock == UCDN::SCRIPT_KHMER) {
-
- $mask = self::FLAG(self::PREF);
- for ($i = $base; $i < $end - 1; $i++) {
- if (self::is_halant_or_coeng($info[$i]) && self::is_ra($info[$i + 1]['uni'])) {
-
- $info[$i]['mask'] |= self::FLAG(self::PREF);
- $info[$i + 1]['mask'] |= self::FLAG(self::PREF);
-
-
-
- for ($j = ($i + 2); $j < $end; $j++)
- $info[$j]['mask'] |= self::FLAG(self::CFAR);
-
- break;
- }
- }
- }
-
-
-
-
- self::bubble_sort($info, $start, $end - $start);
-
-
- $base = $end;
- for ($i = $start; $i < $end; $i++) {
- if ($info[$i]['indic_position'] == self::POS_BASE_C) {
- $base = $i;
- break;
- }
- }
-
- if ($scriptblock != UCDN::SCRIPT_KHMER) {
-
- for ($i = $start; $i < $end; $i++) {
- if ($info[$i]['indic_position'] == self::POS_RA_TO_BECOME_REPH) {
- $info[$i]['mask'] |= self::FLAG(self::RPHF);
- }
- }
-
-
- $mask = self::FLAG(self::HALF);
- for ($i = $start; $i < $base; $i++) {
- $info[$i]['mask'] |= $mask;
- }
- }
-
-
- $mask = (self::FLAG(self::BLWF) | self::FLAG(self::ABVF) | self::FLAG(self::PSTF));
- for ($i = $base + 1; $i < $end; $i++) {
- $info[$i]['mask'] |= $mask;
- }
-
-
- if ($scriptblock != UCDN::SCRIPT_KHMER) {
- if (!defined("OMIT_INDIC_FIX_3") || OMIT_INDIC_FIX_3 != 1) {
-
-
-
- if (($base - $start) >= 3) {
- for ($i = $start; $i < ($base - 2); $i++) {
- if (self::is_consonant($info[$i])) {
- if (self::is_halant_or_coeng($info[$i + 1]) && self::is_ra($info[$i + 2]['uni'])) {
-
- if (isset($GSUBdata['blwf'][$info[$i + 2]['uni']])) {
- $info[$i + 1]['mask'] |= self::FLAG(self::BLWF);
- $info[$i + 2]['mask'] |= self::FLAG(self::BLWF);
- }
- else if (self::is_halant_or_coeng($info[$i + 3])) {
- $info[$i + 2]['mask'] |= self::FLAG(self::RPHF);
- $info[$i + 3]['mask'] |= self::FLAG(self::RPHF);
- }
- break;
- }
- }
- }
- }
- }
- }
-
-
-
- if ($is_old_spec && $scriptblock == UCDN::SCRIPT_DEVANAGARI) {
-
-
- for ($i = $start; ($i + 1) < $base; $i++) {
- if ($info[$i]['indic_category'] == self::OT_Ra && $info[$i + 1]['indic_category'] == self::OT_H &&
- ($i + 2 == $base || $info[$i + 2]['indic_category'] != self::OT_ZWJ)) {
- $info[$i]['mask'] |= self::FLAG(self::BLWF);
- $info[$i + 1]['mask'] |= self::FLAG(self::BLWF);
- }
- }
- }
-
- if ($scriptblock != UCDN::SCRIPT_KHMER) {
- if (count($GSUBdata['pref']) && $base + 2 < $end) {
-
- for ($i = $base + 1; $i + 1 < $end; $i++) {
-
- if ((isset($GSUBdata['pref'][$info[$i + 1]['uni']]) && self::is_halant_or_coeng($info[$i]) && self::is_ra($info[$i + 1]['uni']) ) ||
- ($is_old_spec && isset($GSUBdata['pref'][$info[$i]['uni']]) && self::is_halant_or_coeng($info[$i + 1]) && self::is_ra($info[$i]['uni']) )
- ) {
- $info[$i++]['mask'] |= self::FLAG(self::PREF);
- $info[$i++]['mask'] |= self::FLAG(self::PREF);
- break;
- }
- }
- }
- }
-
-
-
- for ($i = $start + 1; $i < $end; $i++) {
- if (self::is_joiner($info[$i])) {
- $non_joiner = ($info[$i]['indic_category'] == self::OT_ZWNJ);
- $j = $i;
- while ($j > $start) {
- if (defined("OMIT_INDIC_FIX_4") && OMIT_INDIC_FIX_4 == 1) {
-
-
- if (!self::is_consonant($info[$j])) {
- break;
- }
- }
- $j--;
-
-
-
-
-
- if ($non_joiner) {
- $info[$j]['mask'] &= ~(self::FLAG(self::HALF) | self::FLAG(self::BLWF));
- }
- }
- }
- }
- }
-
- public static function final_reordering(&$info, $GSUBdata, $indic_config, $scriptblock, $is_old_spec)
- {
- $count = count($info);
- if (!$count)
- return;
- $last = 0;
- $last_syllable = $info[0]['syllable'];
- for ($i = 1; $i < $count; $i++) {
- if ($last_syllable != $info[$i]['syllable']) {
- self::final_reordering_syllable($info, $GSUBdata, $indic_config, $scriptblock, $is_old_spec, $last, $i);
- $last = $i;
- $last_syllable = $info[$last]['syllable'];
- }
- }
- self::final_reordering_syllable($info, $GSUBdata, $indic_config, $scriptblock, $is_old_spec, $last, $count);
- }
-
- public static function final_reordering_syllable(&$info, $GSUBdata, $indic_config, $scriptblock, $is_old_spec, $start, $end)
- {
-
-
-
-
-
- for ($base = $start; $base < $end; $base++)
- if ($info[$base]['indic_position'] >= self::POS_BASE_C) {
- if ($start < $base && $info[$base]['indic_position'] > self::POS_BASE_C)
- $base--;
- break;
- }
- if ($base == $end && $start < $base && $info[$base - 1]['indic_category'] != self::OT_ZWJ)
- $base--;
- while ($start < $base && isset($info[$base]) && ($info[$base]['indic_category'] == self::OT_H || $info[$base]['indic_category'] == self::OT_N))
- $base--;
-
-
-
-
-
-
- if ($start + 1 < $end && $start < $base) {
-
- $new_pos = ($base == $end) ? $base - 2 : $base - 1;
-
-
-
- if ($scriptblock != UCDN::SCRIPT_MALAYALAM && $scriptblock != UCDN::SCRIPT_TAMIL) {
- while ($new_pos > $start && !(self::is_one_of($info[$new_pos], (self::FLAG(self::OT_M) | self::FLAG(self::OT_H) | self::FLAG(self::OT_Coeng)))))
- $new_pos--;
-
-
-
- if (self::is_halant_or_coeng($info[$new_pos]) && $info[$new_pos]['indic_position'] != self::POS_PRE_M) {
-
- if ($new_pos + 1 < $end && self::is_joiner($info[$new_pos + 1]))
- $new_pos++;
- } else
- $new_pos = $start;
- }
-
- if ($start < $new_pos && $info[$new_pos]['indic_position'] != self::POS_PRE_M) {
-
- for ($i = $new_pos; $i > $start; $i--)
- if ($info[$i - 1]['indic_position'] == self::POS_PRE_M) {
- $old_pos = $i - 1;
-
- self::_move_info_pos($info, $old_pos, $new_pos + 1);
-
- if ($old_pos < $base && $base <= $new_pos)
- $base--;
- $new_pos--;
- }
- }
- }
-
-
-
-
-
-
-
- if ($start + 1 < $end &&
- $info[$start]['indic_position'] == self::POS_RA_TO_BECOME_REPH && $info[$start + 1]['indic_position'] != self::POS_RA_TO_BECOME_REPH) {
- $reph_pos = $indic_config[3];
- $skip_to_reph_step_5 = false;
- $skip_to_reph_move = false;
-
-
-
- if ($reph_pos == self::REPH_POS_AFTER_POST) {
- $skip_to_reph_step_5 = true;
- }
-
-
-
-
- if (!$skip_to_reph_step_5) {
-
- $new_reph_pos = $start + 1;
-
- while ($new_reph_pos < $base && !self::is_halant_or_coeng($info[$new_reph_pos]))
- $new_reph_pos++;
-
- if ($new_reph_pos < $base && self::is_halant_or_coeng($info[$new_reph_pos])) {
-
- if ($new_reph_pos + 1 < $base && self::is_joiner($info[$new_reph_pos + 1]))
- $new_reph_pos++;
- $skip_to_reph_move = true;
- }
- }
-
-
-
- if ($reph_pos == self::REPH_POS_AFTER_MAIN && !$skip_to_reph_move && !$skip_to_reph_step_5) {
- $new_reph_pos = $base;
-
- while ($new_reph_pos + 1 < $end && $info[$new_reph_pos + 1]['indic_position'] <= self::POS_AFTER_MAIN)
- $new_reph_pos++;
- if ($new_reph_pos < $end)
- $skip_to_reph_move = true;
- }
-
-
-
-
- if ($reph_pos == self::REPH_POS_AFTER_SUB && !$skip_to_reph_move && !$skip_to_reph_step_5) {
- $new_reph_pos = $base;
- while ($new_reph_pos < $end && isset($info[$new_reph_pos + 1]['indic_position']) &&
- !( self::FLAG($info[$new_reph_pos + 1]['indic_position']) & (self::FLAG(self::POS_POST_C) | self::FLAG(self::POS_AFTER_POST) | self::FLAG(self::POS_SMVD)))) {
- $new_reph_pos++;
- }
- if ($new_reph_pos < $end) {
- $skip_to_reph_move = true;
- }
- }
-
-
-
- if (!$skip_to_reph_move) {
-
- $new_reph_pos = $start + 1;
- while ($new_reph_pos < $base && !self::is_halant_or_coeng($info[$new_reph_pos]))
- $new_reph_pos++;
-
- if ($new_reph_pos < $base && self::is_halant_or_coeng($info[$new_reph_pos])) {
-
- if ($new_reph_pos + 1 < $base && self::is_joiner($info[$new_reph_pos + 1]))
- $new_reph_pos++;
- $skip_to_reph_move = true;
- }
- }
-
-
-
-
- if (!$skip_to_reph_move) {
- $new_reph_pos = $end - 1;
- while ($new_reph_pos > $start && $info[$new_reph_pos]['indic_position'] == self::POS_SMVD)
- $new_reph_pos--;
-
-
-
-
- if (self::is_halant_or_coeng($info[$new_reph_pos])) {
- for ($i = $base + 1; $i < $new_reph_pos; $i++)
- if ($info[$i]['indic_category'] == self::OT_M) {
-
- $new_reph_pos--;
- }
- }
- }
-
-
-
- self::_move_info_pos($info, $start, $new_reph_pos + 1);
-
- if ($start < $base && $base <= $new_reph_pos) {
- $base--;
- }
- }
-
-
-
-
-
-
- if (count($GSUBdata['pref']) && $base + 1 < $end) {
- for ($i = $base + 1; $i < $end; $i++) {
- if ($info[$i]['mask'] & self::FLAG(self::PREF)) {
-
-
-
- if ($i + 1 == $end || ($info[$i + 1]['mask'] & self::FLAG(self::PREF)) == 0) {
-
-
- $new_pos = $base;
-
-
- if ($scriptblock != UCDN::SCRIPT_MALAYALAM && $scriptblock != UCDN::SCRIPT_TAMIL) {
- while ($new_pos > $start &&
- !(self::is_one_of($info[$new_pos - 1], self::FLAG(self::OT_M) | self::FLAG(self::OT_H) | self::FLAG(self::OT_Coeng))))
- $new_pos--;
-
-
-
- if ($new_pos > $start && $info[$new_pos - 1]['indic_category'] == self::OT_M) {
- $old_pos = i;
- for ($i = $base + 1; $i < $old_pos; $i++)
- if ($info[$i]['indic_category'] == self::OT_M) {
- $new_pos--;
- break;
- }
- }
- }
-
- if ($new_pos > $start && self::is_halant_or_coeng($info[$new_pos - 1])) {
-
- if ($new_pos < $end && self::is_joiner($info[$new_pos]))
- $new_pos++;
- }
-
- $old_pos = $i;
- self::_move_info_pos($info, $old_pos, $new_pos);
-
- if ($new_pos <= $base && $base < $old_pos)
- $base++;
- }
-
- break;
- }
- }
- }
-
-
-
- if ($info[$start]['indic_position'] == self::POS_PRE_M &&
- ($start == 0 ||
- ($info[$start - 1]['general_category'] < UCDN::UNICODE_GENERAL_CATEGORY_FORMAT || $info[$start - 1]['general_category'] > UCDN::UNICODE_GENERAL_CATEGORY_NON_SPACING_MARK)
- )) {
- $info[$start]['mask'] |= self::FLAG(self::INIT);
- }
-
-
-
-
- }
-
- public static function _move_info_pos(&$info, $from, $to)
- {
- $t = array();
- $t[0] = $info[$from];
- if ($from > $to) {
- array_splice($info, $from, 1);
- array_splice($info, $to, 0, $t);
- } else {
- array_splice($info, $to, 0, $t);
- array_splice($info, $from, 1);
- }
- }
-
- public static $ra_chars = array(
- 0x0930 => 1,
- 0x09B0 => 1,
- 0x09F0 => 1,
- 0x0A30 => 1,
- 0x0AB0 => 1,
- 0x0B30 => 1,
- 0x0BB0 => 1,
- 0x0C30 => 1,
- 0x0CB0 => 1,
- 0x0D30 => 1,
- 0x0DBB => 1,
- 0x179A => 1,
- );
-
- public static function is_ra($u)
- {
- if (isset(self::$ra_chars[$u]))
- return true;
- return false;
- }
-
- public static function is_one_of($info, $flags)
- {
- if (isset($info['is_ligature']) && $info['is_ligature'])
- return false;
- return !!(self::FLAG($info['indic_category']) & $flags);
- }
-
- public static function is_joiner($info)
- {
- return self::is_one_of($info, (self::FLAG(self::OT_ZWJ) | self::FLAG(self::OT_ZWNJ)));
- }
-
-
-
- public static function is_consonant($info)
- {
- return self::is_one_of($info, (self::FLAG(self::OT_C) | self::FLAG(self::OT_CM) | self::FLAG(self::OT_Ra) | self::FLAG(self::OT_V) | self::FLAG(self::OT_NBSP) | self::FLAG(self::OT_DOTTEDCIRCLE)));
- }
-
- public static function is_halant_or_coeng($info)
- {
- return self::is_one_of($info, (self::FLAG(self::OT_H) | self::FLAG(self::OT_Coeng)));
- }
-
-
- public static function in_range($u, $lo, $hi)
- {
- if ((($lo ^ $hi) & $lo) == 0 && (($lo ^ $hi) & $hi) == ($lo ^ $hi) && (($lo ^ $hi) & (($lo ^ $hi) + 1)) == 0)
- return ($u & ~($lo ^ $hi)) == $lo;
- else
- return $lo <= $u && $u <= $hi;
- }
-
-
- public static function FLAG($x)
- {
- return (1 << ($x));
- }
-
-
-
-
-
-
-
- const BASE_POS_FIRST = 0;
- const BASE_POS_LAST = 1;
-
-
- const REPH_POS_DEFAULT = 10;
-
- const REPH_POS_AFTER_MAIN = 5;
-
- const REPH_POS_BEFORE_SUB = 7;
- const REPH_POS_AFTER_SUB = 9;
- const REPH_POS_BEFORE_POST = 10;
- const REPH_POS_AFTER_POST = 12;
-
-
- const REPH_MODE_IMPLICIT = 0;
- const REPH_MODE_EXPLICIT = 1;
- const REPH_MODE_VIS_REPHA = 2;
- const REPH_MODE_LOG_REPHA = 3;
-
-
-
-
- public static $indic_configs = array(
- 9 => array(true, 0x094D, 1, 10, 0),
- 10 => array(true, 0x09CD, 1, 9, 0),
- 11 => array(true, 0x0A4D, 1, 7, 0),
- 12 => array(true, 0x0ACD, 1, 10, 0),
- 13 => array(true, 0x0B4D, 1, 5, 0),
- 14 => array(true, 0x0BCD, 1, 12, 0),
- 15 => array(true, 0x0C4D, 1, 12, 1),
- 16 => array(true, 0x0CCD, 1, 12, 0),
- 17 => array(true, 0x0D4D, 1, 5, 3),
- 18 => array(false, 0x0DCA, 0, 5, 1),
- 30 => array(false, 0x17D2, 0, 10, 2),
- 84 => array(false, 0xA9C0, 1, 10, 0),
- );
-
-
-
-
-
-
- public static $indic_table = array(
-
-
- 3848, 3848, 3848, 3848, 3842, 3842, 3842, 3842,
- 3842, 3842, 3842, 3842, 3842, 3842, 3842, 3842,
- 3842, 3842, 3842, 3842, 3842, 3841, 3841, 3841,
- 3841, 3841, 3841, 3841, 3841, 3841, 3841, 3841,
- 3841, 3841, 3841, 3841, 3841, 3841, 3841, 3841,
- 3841, 3841, 3841, 3841, 3841, 3841, 3841, 3841,
- 3841, 3841, 3841, 3841, 3841, 3841, 3841, 3841,
- 3841, 3841, 1543, 2823, 3843, 3840, 2823, 775,
- 2823, 2055, 2055, 2055, 2055, 1543, 1543, 1543,
- 1543, 2823, 2823, 2823, 2823, 2052, 775, 2823,
- 3840, 3840, 3840, 3840, 3840, 1543, 2055, 2055,
- 3841, 3841, 3841, 3841, 3841, 3841, 3841, 3841,
- 3842, 3842, 2055, 2055, 3840, 3840, 3840, 3840,
- 3840, 3840, 3840, 3840, 3840, 3840, 3840, 3840,
- 3840, 3840, 3842, 3842, 3842, 3842, 3842, 3842,
- 3840, 3841, 3841, 3841, 3841, 3841, 3841, 3841,
-
-
- 3840, 3848, 3848, 3848, 3840, 3842, 3842, 3842,
- 3842, 3842, 3842, 3842, 3842, 3840, 3840, 3842,
- 3842, 3840, 3840, 3842, 3842, 3841, 3841, 3841,
- 3841, 3841, 3841, 3841, 3841, 3841, 3841, 3841,
- 3841, 3841, 3841, 3841, 3841, 3841, 3841, 3841,
- 3841, 3840, 3841, 3841, 3841, 3841, 3841, 3841,
- 3841, 3840, 3841, 3840, 3840, 3840, 3841, 3841,
- 3841, 3841, 3840, 3840, 3843, 3840, 2823, 775,
- 2823, 2055, 2055, 2055, 2055, 3840, 3840, 775,
- 775, 3840, 3840, 2823, 2823, 2052, 3841, 3840,
- 3840, 3840, 3840, 3840, 3840, 3840, 3840, 2823,
- 3840, 3840, 3840, 3840, 3841, 3841, 3840, 3841,
- 3842, 3842, 2055, 2055, 3840, 3840, 3840, 3840,
- 3840, 3840, 3840, 3840, 3840, 3840, 3840, 3840,
- 3841, 3841, 3840, 3840, 3840, 3840, 3840, 3840,
- 3840, 3840, 3840, 3840, 3840, 3840, 3840, 3840,
-
-
- 3840, 3848, 3848, 3848, 3840, 3842, 3842, 3842,
- 3842, 3842, 3842, 3840, 3840, 3840, 3840, 3842,
- 3842, 3840, 3840, 3842, 3842, 3841, 3841, 3841,
- 3841, 3841, 3841, 3841, 3841, 3841, 3841, 3841,
- 3841, 3841, 3841, 3841, 3841, 3841, 3841, 3841,
- 3841, 3840, 3841, 3841, 3841, 3841, 3841, 3841,
- 3841, 3840, 3841, 3841, 3840, 3841, 3841, 3840,
- 3841, 3841, 3840, 3840, 3843, 3840, 2823, 775,
- 2823, 2055, 2055, 3840, 3840, 3840, 3840, 1543,
- 1543, 3840, 3840, 1543, 1543, 2052, 3840, 3840,
- 3840, 3840, 3840, 3840, 3840, 3840, 3840, 3840,
- 3840, 3841, 3841, 3841, 3841, 3840, 3841, 3840,
- 3840, 3840, 3840, 3840, 3840, 3840, 3840, 3840,
- 3840, 3840, 3840, 3840, 3840, 3840, 3840, 3840,
- 3848, 3840, 13841, 13841, 3840, 3857, 3840, 3840,
- 3840, 3840, 3840, 3840, 3840, 3840, 3840, 3840,
-
-
- 3840, 3848, 3848, 3848, 3840, 3842, 3842, 3842,
- 3842, 3842, 3842, 3842, 3842, 3842, 3840, 3842,
- 3842, 3842, 3840, 3842, 3842, 3841, 3841, 3841,
- 3841, 3841, 3841, 3841, 3841, 3841, 3841, 3841,
- 3841, 3841, 3841, 3841, 3841, 3841, 3841, 3841,
- 3841, 3840, 3841, 3841, 3841, 3841, 3841, 3841,
- 3841, 3840, 3841, 3841, 3840, 3841, 3841, 3841,
- 3841, 3841, 3840, 3840, 3843, 3840, 2823, 775,
- 2823, 2055, 2055, 2055, 2055, 1543, 3840, 1543,
- 1543, 2823, 3840, 2823, 2823, 2052, 3840, 3840,
- 3840, 3840, 3840, 3840, 3840, 3840, 3840, 3840,
- 3840, 3840, 3840, 3840, 3840, 3840, 3840, 3840,
- 3842, 3842, 2055, 2055, 3840, 3840, 3840, 3840,
- 3840, 3840, 3840, 3840, 3840, 3840, 3840, 3840,
- 3840, 3840, 3840, 3840, 3840, 3840, 3840, 3840,
- 3840, 3840, 3840, 3840, 3840, 3840, 3840, 3840,
-
-
- 3840, 3848, 3848, 3848, 3840, 3842, 3842, 3842,
- 3842, 3842, 3842, 3842, 3842, 3840, 3840, 3842,
- 3842, 3840, 3840, 3842, 3842, 3841, 3841, 3841,
- 3841, 3841, 3841, 3841, 3841, 3841, 3841, 3841,
- 3841, 3841, 3841, 3841, 3841, 3841, 3841, 3841,
- 3841, 3840, 3841, 3841, 3841, 3841, 3841, 3841,
- 3841, 3840, 3841, 3841, 3840, 3841, 3841, 3841,
- 3841, 3841, 3840, 3840, 3843, 3840, 2823, 1543,
- 2823, 2055, 2055, 2055, 2055, 3840, 3840, 775,
- 1543, 3840, 3840, 2823, 2823, 2052, 3840, 3840,
- 3840, 3840, 3840, 3840, 3840, 3840, 1543, 2823,
- 3840, 3840, 3840, 3840, 3841, 3841, 3840, 3841,
- 3842, 3842, 2055, 2055, 3840, 3840, 3840, 3840,
- 3840, 3840, 3840, 3840, 3840, 3840, 3840, 3840,
- 3840, 3841, 3840, 3840, 3840, 3840, 3840, 3840,
- 3840, 3840, 3840, 3840, 3840, 3840, 3840, 3840,
-
-
- 3840, 3840, 3848, 3840, 3840, 3842, 3842, 3842,
- 3842, 3842, 3842, 3840, 3840, 3840, 3842, 3842,
- 3842, 3840, 3842, 3842, 3842, 3841, 3840, 3840,
- 3840, 3841, 3841, 3840, 3841, 3840, 3841, 3841,
- 3840, 3840, 3840, 3841, 3841, 3840, 3840, 3840,
- 3841, 3841, 3841, 3840, 3840, 3840, 3841, 3841,
- 3841, 3841, 3841, 3841, 3841, 3841, 3841, 3841,
- 3841, 3841, 3840, 3840, 3840, 3840, 2823, 2823,
- 1543, 2055, 2055, 3840, 3840, 3840, 775, 775,
- 775, 3840, 2823, 2823, 2823, 1540, 3840, 3840,
- 3840, 3840, 3840, 3840, 3840, 3840, 3840, 2823,
- 3840, 3840, 3840, 3840, 3840, 3840, 3840, 3840,
- 3840, 3840, 3840, 3840, 3840, 3840, 3840, 3840,
- 3840, 3840, 3840, 3840, 3840, 3840, 3840, 3840,
- 3840, 3840, 3840, 3840, 3840, 3840, 3840, 3840,
- 3840, 3840, 3840, 3840, 3840, 3840, 3840, 3840,
-
-
- 3840, 3848, 3848, 3848, 3840, 3842, 3842, 3842,
- 3842, 3842, 3842, 3842, 3842, 3840, 3842, 3842,
- 3842, 3840, 3842, 3842, 3842, 3841, 3841, 3841,
- 3841, 3841, 3841, 3841, 3841, 3841, 3841, 3841,
- 3841, 3841, 3841, 3841, 3841, 3841, 3841, 3841,
- 3841, 3840, 3841, 3841, 3841, 3841, 3841, 3841,
- 3841, 3841, 3841, 3841, 3840, 3841, 3841, 3841,
- 3841, 3841, 3840, 3840, 3840, 3840, 1543, 1543,
- 1543, 2823, 2823, 2823, 2823, 3840, 1543, 1543,
- 2055, 3840, 1543, 1543, 1543, 1540, 3840, 3840,
- 3840, 3840, 3840, 3840, 3840, 1543, 2055, 3840,
- 3841, 3841, 3840, 3840, 3840, 3840, 3840, 3840,
- 3842, 3842, 2055, 2055, 3840, 3840, 3840, 3840,
- 3840, 3840, 3840, 3840, 3840, 3840, 3840, 3840,
- 3840, 3840, 3840, 3840, 3840, 3840, 3840, 3840,
- 3840, 3840, 3840, 3840, 3840, 3840, 3840, 3840,
-
-
- 3840, 3840, 3848, 3848, 3840, 3842, 3842, 3842,
- 3842, 3842, 3842, 3842, 3842, 3840, 3842, 3842,
- 3842, 3840, 3842, 3842, 3842, 3841, 3841, 3841,
- 3841, 3841, 3841, 3841, 3841, 3841, 3841, 3841,
- 3841, 3841, 3841, 3841, 3841, 3841, 3841, 3841,
- 3841, 3840, 3841, 3841, 3841, 3841, 3841, 3841,
- 3841, 3841, 3841, 3841, 3840, 3841, 3841, 3841,
- 3841, 3841, 3840, 3840, 3843, 3840, 2823, 1543,
- 2823, 2823, 2823, 2823, 2823, 3840, 1543, 2823,
- 2823, 3840, 2823, 2823, 1543, 1540, 3840, 3840,
- 3840, 3840, 3840, 3840, 3840, 2823, 2823, 3840,
- 3840, 3840, 3840, 3840, 3840, 3840, 3841, 3840,
- 3842, 3842, 2055, 2055, 3840, 3840, 3840, 3840,
- 3840, 3840, 3840, 3840, 3840, 3840, 3840, 3840,
- 3840, 3840, 3840, 3840, 3840, 3840, 3840, 3840,
- 3840, 3840, 3840, 3840, 3840, 3840, 3840, 3840,
-
-
- 3840, 3840, 3848, 3848, 3840, 3842, 3842, 3842,
- 3842, 3842, 3842, 3842, 3842, 3840, 3842, 3842,
- 3842, 3840, 3842, 3842, 3842, 3841, 3841, 3841,
- 3841, 3841, 3841, 3841, 3841, 3841, 3841, 3841,
- 3841, 3841, 3841, 3841, 3841, 3841, 3841, 3841,
- 3841, 3841, 3841, 3841, 3841, 3841, 3841, 3841,
- 3841, 3841, 3841, 3841, 3841, 3841, 3841, 3841,
- 3841, 3841, 3841, 3840, 3840, 3840, 2823, 2823,
- 2823, 2823, 2823, 2055, 2055, 3840, 775, 775,
- 775, 3840, 2823, 2823, 2823, 1540, 3855, 3840,
- 3840, 3840, 3840, 3840, 3840, 3840, 3840, 2823,
- 3840, 3840, 3840, 3840, 3840, 3840, 3840, 3840,
- 3842, 3842, 2055, 2055, 3840, 3840, 3840, 3840,
- 3840, 3840, 3840, 3840, 3840, 3840, 3840, 3840,
- 3840, 3840, 3840, 3840, 3840, 3840, 3840, 3840,
- 3840, 3840, 3841, 3841, 3841, 3841, 3841, 3841,
-
-
- 3840, 3840, 3848, 3848, 3840, 3842, 3842, 3842,
- 3842, 3842, 3842, 3842, 3842, 3842, 3842, 3842,
- 3842, 3842, 3842, 3842, 3842, 3842, 3842, 3840,
- 3840, 3840, 3841, 3841, 3841, 3841, 3841, 3841,
- 3841, 3841, 3841, 3841, 3841, 3841, 3841, 3841,
- 3841, 3841, 3841, 3841, 3841, 3841, 3841, 3841,
- 3841, 3841, 3840, 3841, 3841, 3841, 3841, 3841,
- 3841, 3841, 3841, 3841, 3840, 3841, 3840, 3840,
- 3841, 3841, 3841, 3841, 3841, 3841, 3841, 3840,
- 3840, 3840, 1540, 3840, 3840, 3840, 3840, 2823,
- 2823, 2823, 1543, 1543, 2055, 3840, 2055, 3840,
- 2823, 775, 1543, 775, 2823, 2823, 2823, 2823,
- 3840, 3840, 3840, 3840, 3840, 3840, 3840, 3840,
- 3840, 3840, 3840, 3840, 3840, 3840, 3840, 3840,
- 3840, 3840, 2823, 2823, 3840, 3840, 3840, 3840,
- 3840, 3840, 3840, 3840, 3840, 3840, 3840, 3840,
-
-
- 3840, 3840, 3840, 3840, 3840, 3840, 3840, 3840,
- 3840, 3840, 3840, 3840, 3840, 3840, 3840, 3840,
- 3840, 3840, 3840, 3840, 3840, 3840, 3840, 3840,
- 3840, 3840, 3840, 3840, 3840, 3840, 3840, 3840,
- 3840, 3840, 3848, 3848, 3840, 3840, 3840, 3840,
- 3840, 3840, 3840, 3840, 3840, 3840, 3840, 3840,
- );
-
- public static $khmer_table = array(
-
-
- 3841, 3841, 3841, 3841, 3841, 3841, 3841, 3841,
- 3841, 3841, 3841, 3841, 3841, 3841, 3841, 3841,
- 3841, 3841, 3841, 3841, 3841, 3841, 3841, 3841,
- 3841, 3841, 3841, 3841, 3841, 3841, 3841, 3841,
- 3841, 3841, 3841, 3842, 3842, 3842, 3842, 3842,
- 3842, 3842, 3842, 3842, 3842, 3842, 3842, 3842,
- 3842, 3842, 3842, 3842, 3840, 3840, 2823, 1543,
- 1543, 1543, 1543, 2055, 2055, 2055, 1543, 2823,
- 2823, 775, 775, 775, 2823, 2823, 3848, 3848,
- 2823, 3853, 3853, 3840, 3855, 3840, 3840, 3840,
- 3840, 1540, 3844, 3840, 3840, 3840, 3840, 3840,
- 3840, 3840, 3840, 3840, 3840, 3840, 3840, 3840,
- 3840, 3840, 3840, 3840, 3840, 3840, 3840, 3840,
- 3840, 3840, 3840, 3840, 3840, 3840, 3840, 3840,
- 3840, 3840, 3840, 3840, 3840, 3840, 3840, 3840,
- 3840, 3840, 3840, 3840, 3840, 3840, 3840, 3840,
- );
-
-
- public static function indic_get_categories($u)
- {
- if (0x0900 <= $u && $u <= 0x0DFF)
- return self::$indic_table[$u - 0x0900 + 0];
- if (0x1CD0 <= $u && $u <= 0x1D00)
- return self::$indic_table[$u - 0x1CD0 + 1152];
- if (0x1780 <= $u && $u <= 0x17FF)
- return self::$khmer_table[$u - 0x1780];
- if ($u == 0x00A0)
- return 3851;
- if ($u == 0x25CC)
- return 3851;
- return 3840;
- }
-
-
-
-
-
- public static function IN_HALF_BLOCK($u, $Base)
- {
- return (($u & ~0x7F) == $Base);
- }
-
- public static function IS_DEVA($u)
- {
- return self::IN_HALF_BLOCK($u, 0x0900);
- }
-
- public static function IS_BENG($u)
- {
- return self::IN_HALF_BLOCK($u, 0x0980);
- }
-
- public static function IS_GURU($u)
- {
- return self::IN_HALF_BLOCK($u, 0x0A00);
- }
-
- public static function IS_GUJR($u)
- {
- return self::IN_HALF_BLOCK($u, 0x0A80);
- }
-
- public static function IS_ORYA($u)
- {
- return self::IN_HALF_BLOCK($u, 0x0B00);
- }
-
- public static function IS_TAML($u)
- {
- return self::IN_HALF_BLOCK($u, 0x0B80);
- }
-
- public static function IS_TELU($u)
- {
- return self::IN_HALF_BLOCK($u, 0x0C00);
- }
-
- public static function IS_KNDA($u)
- {
- return self::IN_HALF_BLOCK($u, 0x0C80);
- }
-
- public static function IS_MLYM($u)
- {
- return self::IN_HALF_BLOCK($u, 0x0D00);
- }
-
- public static function IS_SINH($u)
- {
- return self::IN_HALF_BLOCK($u, 0x0D80);
- }
-
- public static function IS_KHMR($u)
- {
- return self::IN_HALF_BLOCK($u, 0x1780);
- }
-
- public static function MATRA_POS_LEFT($u)
- {
- return self::POS_PRE_M;
- }
-
- public static function MATRA_POS_RIGHT($u)
- {
- return
- (self::IS_DEVA($u) ? self::POS_AFTER_SUB :
- (self::IS_BENG($u) ? self::POS_AFTER_POST :
- (self::IS_GURU($u) ? self::POS_AFTER_POST :
- (self::IS_GUJR($u) ? self::POS_AFTER_POST :
- (self::IS_ORYA($u) ? self::POS_AFTER_POST :
- (self::IS_TAML($u) ? self::POS_AFTER_POST :
- (self::IS_TELU($u) ? ($u <= 0x0C42 ? self::POS_BEFORE_SUB : self::POS_AFTER_SUB) :
- (self::IS_KNDA($u) ? ($u < 0x0CC3 || $u > 0xCD6 ? self::POS_BEFORE_SUB : self::POS_AFTER_SUB) :
- (self::IS_MLYM($u) ? self::POS_AFTER_POST :
- (self::IS_SINH($u) ? self::POS_AFTER_SUB :
- (self::IS_KHMR($u) ? self::POS_AFTER_POST :
- self::POS_AFTER_SUB)))))))))));
- }
-
- public static function MATRA_POS_TOP($u)
- {
- return
- (self::IS_DEVA($u) ? self::POS_AFTER_SUB :
- (self::IS_GURU($u) ? self::POS_AFTER_POST :
- (self::IS_GUJR($u) ? self::POS_AFTER_SUB :
- (self::IS_ORYA($u) ? self::POS_AFTER_MAIN :
- (self::IS_TAML($u) ? self::POS_AFTER_SUB :
- (self::IS_TELU($u) ? self::POS_BEFORE_SUB :
- (self::IS_KNDA($u) ? self::POS_BEFORE_SUB :
- (self::IS_SINH($u) ? self::POS_AFTER_SUB :
- (self::IS_KHMR($u) ? self::POS_AFTER_POST :
- self::POS_AFTER_SUB)))))))));
- }
-
- public static function MATRA_POS_BOTTOM($u)
- {
- return
- (self::IS_DEVA($u) ? self::POS_AFTER_SUB :
- (self::IS_BENG($u) ? self::POS_AFTER_SUB :
- (self::IS_GURU($u) ? self::POS_AFTER_POST :
- (self::IS_GUJR($u) ? self::POS_AFTER_POST :
- (self::IS_ORYA($u) ? self::POS_AFTER_SUB :
- (self::IS_TAML($u) ? self::POS_AFTER_POST :
- (self::IS_TELU($u) ? self::POS_BEFORE_SUB :
- (self::IS_KNDA($u) ? self::POS_BEFORE_SUB :
- (self::IS_MLYM($u) ? self::POS_AFTER_POST :
- (self::IS_SINH($u) ? self::POS_AFTER_SUB :
- (self::IS_KHMR($u) ? self::POS_AFTER_POST :
- self::POS_AFTER_SUB)))))))))));
- }
-
- public static function matra_position($u, $side)
- {
- switch ($side) {
- case self::POS_PRE_C: return self::MATRA_POS_LEFT($u);
- case self::POS_POST_C: return self::MATRA_POS_RIGHT($u);
- case self::POS_ABOVE_C: return self::MATRA_POS_TOP($u);
- case self::POS_BELOW_C: return self::MATRA_POS_BOTTOM($u);
- }
- return $side;
- }
-
-
-
-
-
- public static function decompose_indic($ab)
- {
- $sub = array();
- switch ($ab) {
-
-
-
- case 0x9cb : $sub[0] = 0x9c7;
- $sub[1] = 0x9be;
- return $sub;
- case 0x9cc : $sub[0] = 0x9c7;
- $sub[1] = 0x9d7;
- return $sub;
-
- case 0xb48 : $sub[0] = 0xb47;
- $sub[1] = 0xb56;
- return $sub;
- case 0xb4b : $sub[0] = 0xb47;
- $sub[1] = 0xb3e;
- return $sub;
- case 0xb4c : $sub[0] = 0xb47;
- $sub[1] = 0xb57;
- return $sub;
-
- case 0xbca : $sub[0] = 0xbc6;
- $sub[1] = 0xbbe;
- return $sub;
- case 0xbcb : $sub[0] = 0xbc7;
- $sub[1] = 0xbbe;
- return $sub;
- case 0xbcc : $sub[0] = 0xbc6;
- $sub[1] = 0xbd7;
- return $sub;
-
- case 0xc48 : $sub[0] = 0xc46;
- $sub[1] = 0xc56;
- return $sub;
-
- case 0xcc0 : $sub[0] = 0xcbf;
- $sub[1] = 0xcd5;
- return $sub;
- case 0xcc7 : $sub[0] = 0xcc6;
- $sub[1] = 0xcd5;
- return $sub;
- case 0xcc8 : $sub[0] = 0xcc6;
- $sub[1] = 0xcd6;
- return $sub;
- case 0xcca : $sub[0] = 0xcc6;
- $sub[1] = 0xcc2;
- return $sub;
- case 0xccb : $sub[0] = 0xcc6;
- $sub[1] = 0xcc2;
- $sub[2] = 0xcd5;
- return $sub;
-
- case 0xd4a : $sub[0] = 0xd46;
- $sub[1] = 0xd3e;
- return $sub;
- case 0xd4b : $sub[0] = 0xd47;
- $sub[1] = 0xd3e;
- return $sub;
- case 0xd4c : $sub[0] = 0xd46;
- $sub[1] = 0xd57;
- return $sub;
-
-
-
-
- case 0xdda : $sub[0] = 0xdd9;
- $sub[1] = 0xdca;
- return $sub;
- case 0xddc : $sub[0] = 0xdd9;
- $sub[1] = 0xdcf;
- return $sub;
- case 0xddd : $sub[0] = 0xdd9;
- $sub[1] = 0xdcf;
- $sub[2] = 0xdca;
- return $sub;
- case 0xdde : $sub[0] = 0xdd9;
- $sub[1] = 0xddf;
- return $sub;
-
- case 0x17be : $sub[0] = 0x17c1;
- $sub[1] = 0x17be;
- return $sub;
- case 0x17bf : $sub[0] = 0x17c1;
- $sub[1] = 0x17bf;
- return $sub;
- case 0x17c0 : $sub[0] = 0x17c1;
- $sub[1] = 0x17c0;
- return $sub;
-
- case 0x17c4 : $sub[0] = 0x17c1;
- $sub[1] = 0x17c4;
- return $sub;
- case 0x17c5 : $sub[0] = 0x17c1;
- $sub[1] = 0x17c5;
- return $sub;
-
- case 0xf73 : $sub[0] = 0xf71;
- $sub[1] = 0xf72;
- return $sub;
- case 0xf75 : $sub[0] = 0xf71;
- $sub[1] = 0xf74;
- return $sub;
- case 0xf76 : $sub[0] = 0xfb2;
- $sub[1] = 0xf80;
- return $sub;
- case 0xf77 : $sub[0] = 0xfb2;
- $sub[1] = 0xf81;
- return $sub;
- case 0xf78 : $sub[0] = 0xfb3;
- $sub[1] = 0xf80;
- return $sub;
- case 0xf79 : $sub[0] = 0xfb3;
- $sub[1] = 0xf71;
- $sub[2] = 0xf80;
- return $sub;
- case 0xf81 : $sub[0] = 0xf71;
- $sub[1] = 0xf80;
- return $sub;
- }
- return false;
- }
-
- public static function bubble_sort(&$arr, $start, $len)
- {
- if ($len < 2) {
- return;
- }
- $k = $start + $len - 2;
- while ($k >= $start) {
- for ($j = $start; $j <= $k; $j++) {
- if ($arr[$j]['indic_position'] > $arr[$j + 1]['indic_position']) {
- $t = $arr[$j];
- $arr[$j] = $arr[$j + 1];
- $arr[$j + 1] = $t;
- }
- }
- $k--;
- }
- }
-
- }
|