123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383 |
- <?php
- class SEA
- {
-
-
- const OT_X = 0;
- const OT_C = 1;
- const OT_IV = 2;
- const OT_T = 3;
- const OT_H = 4;
- const OT_A = 10;
- const OT_GB = 12;
- const OT_CM = 17;
- const OT_MR = 22;
- const OT_VAbv = 26;
- const OT_VBlw = 27;
- const OT_VPre = 28;
- const OT_VPst = 29;
-
- const OT_ZWNJ = 5;
- const OT_ZWJ = 6;
- const OT_M = 7;
- const OT_SM = 8;
- const OT_VD = 9;
- const OT_NBSP = 11;
- const OT_RS = 13;
- const OT_Coeng = 14;
- const OT_Repha = 15;
- const OT_Ra = 16;
-
-
- public static $sea_category_char = array(
- 'x',
- 'C',
- 'V',
- 'T',
- 'H',
- 'x',
- 'x',
- 'x',
- 'x',
- 'x',
- 'A',
- 'x',
- 'G',
- 'x',
- 'x',
- 'x',
- 'x',
- 'M',
- 'x',
- 'x',
- 'x',
- 'x',
- 'R',
- 'x',
- 'x',
- 'x',
- 'a',
- 'b',
- 'p',
- 't',
- );
-
-
- 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;
- public static function set_sea_properties(&$info, $scriptblock)
- {
- $u = $info['uni'];
- $type = self::sea_get_categories($u);
- $cat = ($type & 0x7F);
- $pos = ($type >> 8);
-
-
- if ($u == 0x1A55 || $u == 0xAA34) {
- $cat = self::OT_MR;
- }
-
- if ($cat == self::OT_M) {
- switch ($pos) {
- case self::POS_PRE_C: $cat = self::OT_VPre;
- break;
- case self::POS_ABOVE_C: $cat = self::OT_VAbv;
- break;
- case self::POS_BELOW_C: $cat = self::OT_VBlw;
- break;
- case self::POS_POST_C: $cat = self::OT_VPst;
- break;
- }
- }
- $info['sea_category'] = $cat;
- $info['sea_position'] = $pos;
- }
-
- const CONSONANT_SYLLABLE = 0;
- const BROKEN_CLUSTER = 1;
- const NON_SEA_CLUSTER = 2;
- 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_SEA_CLUSTER;
-
- if (preg_match('/^(C|V|G)(p|a|b|t|HC|M|R|T|A)*/', substr($s, $ptr), $ma)) {
- $syllable_length = strlen($ma[0]);
- $syllable_type = self::CONSONANT_SYLLABLE;
- }
-
- else if (preg_match('/^(p|a|b|t|HC|M|R|T|A)+/', substr($s, $ptr), $ma)) {
- $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, $scriptblock, $dottedcircle)
- {
- 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, $scriptblock, $last, $i);
- $last = $i;
- $last_syllable = $info[$last]['syllable'];
- }
- }
- self::initial_reordering_syllable($info, $GSUBdata, $scriptblock, $last, $count);
- }
- 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'];
- array_splice($info, $idx, 0, $dottedcircle);
- } else
- $idx++;
- }
- }
- public static function initial_reordering_syllable(&$info, $GSUBdata, $scriptblock, $start, $end)
- {
-
- $syllable_type = ($info[$start]['syllable'] & 0x0F);
- if ($syllable_type == self::NON_SEA_CLUSTER) {
- return;
- }
- if ($syllable_type == self::BROKEN_CLUSTER) {
-
- if ($info[$end - 1]['sea_category'] == self::OT_GB) {
- return;
- }
- }
- $base = $start;
- $i = $start;
- for (; $i < $base; $i++)
- $info[$i]['sea_position'] = self::POS_PRE_C;
- if ($i < $end) {
- $info[$i]['sea_position'] = self::POS_BASE_C;
- $i++;
- }
- for (; $i < $end; $i++) {
- if (isset($info[$i]['sea_category']) && $info[$i]['sea_category'] == self::OT_MR) {
- $info[$i]['sea_position'] = self::POS_PRE_C;
- continue;
- }
- if (isset($info[$i]['sea_category']) && $info[$i]['sea_category'] == self::OT_VPre) {
- $info[$i]['sea_position'] = self::POS_PRE_M;
- continue;
- }
- $info[$i]['sea_position'] = self::POS_AFTER_MAIN;
- }
-
- self::bubble_sort($info, $start, $end - $start);
- }
- public static function final_reordering(&$info, $GSUBdata, $scriptblock)
- {
- $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, $scriptblock, $last, $i);
- $last = $i;
- $last_syllable = $info[$last]['syllable'];
- }
- }
- self::final_reordering_syllable($info, $GSUBdata, $scriptblock, $last, $count);
- }
- public static function final_reordering_syllable(&$info, $GSUBdata, $scriptblock, $start, $end)
- {
-
- }
- public static $sea_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, 3841, 3841, 3841, 3841, 3841,
- 3841, 3841, 3841, 3841, 3840, 3840, 3840, 3840,
- 2823, 2823, 2823, 2823, 2823, 775, 775, 775,
- 2823, 2823, 775, 2823, 2823, 2823, 2823, 2823,
- 2823, 3857, 3857, 3857, 3857, 3857, 3857, 3857,
- 3843, 3843, 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, 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, 3841, 3842, 3842, 3842,
- 3842, 3842, 3842, 3841, 3841, 3857, 3857, 3857,
- 3857, 3857, 3857, 3857, 3857, 3857, 3857, 3840,
- 3844, 2823, 1543, 2823, 2823, 1543, 1543, 1543,
- 1543, 2055, 2055, 1543, 2055, 2823, 775, 775,
- 775, 775, 775, 1543, 1543, 3843, 3843, 3843,
- 3843, 3843, 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,
- 3840, 3840, 3840, 3840, 3840, 3840, 3840, 3840,
-
- 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, 1543, 1543, 1543, 1543, 2055, 1543, 775,
- 775, 1543, 2055, 3857, 3857, 3857, 3857, 3840,
- 3840, 3840, 3840, 3840, 3840, 3840, 3840, 3840,
- 3857, 3857, 3857, 3857, 3857, 3857, 3857, 3857,
- 3857, 3857, 3857, 3857, 3857, 3857, 3840, 3840,
- 3840, 3840, 3840, 3840, 3840, 3840, 3840, 3840,
- 3840, 3840, 3840, 3840, 3840, 3840, 3840, 3840,
- );
- public static function sea_get_categories($u)
- {
- if (0x1980 <= $u && $u <= 0x19DF)
- return self::$sea_table[$u - 0x1980];
- if (0x1A20 <= $u && $u <= 0x1AAF)
- return self::$sea_table[$u - 0x1A20 + 96];
- if (0xAA00 <= $u && $u <= 0xAA5F)
- return self::$sea_table[$u - 0xAA00 + 96 + 144];
- if ($u == 0x00A0)
- return 3851;
- if ($u == 0x25CC)
- return 3851;
- return 3840;
- }
- 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]['sea_position'] > $arr[$j + 1]['sea_position']) {
- $t = $arr[$j];
- $arr[$j] = $arr[$j + 1];
- $arr[$j + 1] = $t;
- }
- }
- $k--;
- }
- }
- }
|