indic.php 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433
  1. <?php
  2. class indic {
  3. function indic() {
  4. }
  5. function substituteIndic($earr, $lang, $font) {
  6. global $voltdata;
  7. if (!isset($voltdata[$font])) {
  8. include_once(_MPDF_PATH.'includes/'.$font.'.volt.php');
  9. $voltdata[$font] = $volt;
  10. }
  11. foreach($earr as $eid=>$char) {
  12. $earr[$eid] = sprintf("%04s", strtoupper(dechex($char)));
  13. }
  14. $vstr = "0020 ".implode(" ",$earr)." 0020";
  15. //============================
  16. // Common Indic Punctuation marks
  17. // If NOT devanagari
  18. if ($lang!='hi') {
  19. $vstr = str_replace('0964','007C', $vstr); // U+0964 replace with "|"
  20. $vstr = str_replace('0965','007C 007C', $vstr); // U+0964 replace with "|"
  21. }
  22. //============================
  23. // Tamil numeral for Zero missing Added mPDF 4.2
  24. if ($lang=='ta') {
  25. $vstr = str_replace('0BE6','0030', $vstr); // U+0BEB replace with "0"
  26. }
  27. //============================
  28. // Re-order vowels
  29. // DEVANAGARI vowel sign matraI[093F] before consonant
  30. if ($lang=='hi') {
  31. $prebasedvowels = "(093F)";
  32. $nukta = "093C";
  33. $halant = "094D";
  34. $vstr = preg_replace('/([A-F0-9]{4}) '.$prebasedvowels.'/','\\2 \\1', $vstr); // vowel sign pre-based shift left
  35. $vstr = preg_replace('/([A-F0-9]{4}) '.$prebasedvowels.' '.$nukta.'/','\\2 \\1 '.$nukta, $vstr); // before NUKTA
  36. $vstr = preg_replace('/([A-F0-9]{4}) '.$halant.' '.$prebasedvowels.'/','\\2 \\1 '.$halant, $vstr); // before CHAR HALANT == VIRAMA
  37. }
  38. // BENGALI vowels [09BF 09C7 09C8]
  39. else if ($lang=='bn') {
  40. // Khanda Ta 09CE not in font -> replace with 09A4|09CD
  41. $vstr = preg_replace('/09CE/','09A4 09CD 200D', $vstr); // mPDF 5.3.09
  42. // BENGALI double-part vowels [09CB 09C7 09BE][09CC 09C7 09D7]
  43. $vstr = str_replace('09CB','09C7 09BE', $vstr); // convert to 2 parts
  44. $vstr = str_replace('09CC','09C7 09D7', $vstr); // 09C7 pre-based is then shifted below
  45. $prebasedvowels = "(09BF|09C7|09C8)";
  46. $nukta = "09BC";
  47. $halant = "09CD";
  48. // mPDF 5.0.044
  49. $bnfullcons = "0995|0996|0997|0998|0999|099A|099B|099C|099D|099F|09A0|09A1|09A2|09A3|09A4|09A5|09A6|09A7|09A8|09AA|09AB|09AC|09AD|09AE|09AF|09B0|09B2|09B6|09B7|09B8|09B9|09DC|09DD|09DF";
  50. $vstr = preg_replace('/([A-F0-9]{4}) '.$prebasedvowels.'/','\\2 \\1', $vstr); // vowel sign pre-based shift left
  51. $vstr = preg_replace('/([A-F0-9]{4}) '.$prebasedvowels.' '.$nukta.'/','\\2 \\1 '.$nukta, $vstr); // before NUKTA
  52. $vstr = preg_replace('/([A-F0-9]{4}) '.$halant.' '.$prebasedvowels.'/','\\2 \\1 '.$halant, $vstr); // before CHAR HALANT
  53. // mPDF 5.0.044
  54. // .. and shifting left-based vowel further to the left in case 3 consonants together.
  55. $vstr = preg_replace('/('.$bnfullcons.') '.$halant.' '.$prebasedvowels.'/','\\2 \\1 '.$halant, $vstr);
  56. // mPDF 5.0.044
  57. // If left-based vowel has now been shifted to left of RA/Halant (09B0/09CD)
  58. // Convert here to above-line form (E068) as it would get missed later
  59. // e.g. 09B0 09CD 09AD 09C7 would be changed above =>
  60. // e.g. 09C7 09B0 09CD 09AD. The 09B0 09CD should => E068
  61. // ??? need to add 09BF as well (09BF|09C7|09C8)
  62. $vstr = preg_replace('/(09C7|09C8) 09B0 09CD/', '\\1 E068', $vstr);
  63. }
  64. // GUJARATI pre-based vowel [0ABF]
  65. else if ($lang=='gu') {
  66. $prebasedvowels = "(0ABF)";
  67. $nukta = "0ABC";
  68. $halant = "0ACD";
  69. $vstr = preg_replace('/([A-F0-9]{4}) '.$prebasedvowels.'/','\\2 \\1', $vstr); // vowel sign pre-based shift left
  70. $vstr = preg_replace('/([A-F0-9]{4}) '.$prebasedvowels.' '.$nukta.'/','\\2 \\1 '.$nukta, $vstr); // before NUKTA
  71. $vstr = preg_replace('/([A-F0-9]{4}) '.$halant.' '.$prebasedvowels.'/','\\2 \\1 '.$halant, $vstr); // before CHAR HALANT
  72. }
  73. // GURMUKHI/PUNJABI pre-based vowel [0ABF]
  74. else if ($lang=='pa') {
  75. $prebasedvowels = "(0A3F)";
  76. $nukta = "0A3C";
  77. $halant = "0A4D";
  78. $vstr = preg_replace('/([A-F0-9]{4}) '.$prebasedvowels.'/','\\2 \\1', $vstr); // vowel sign pre-based shift left
  79. $vstr = preg_replace('/([A-F0-9]{4}) '.$prebasedvowels.' '.$nukta.'/','\\2 \\1 '.$nukta, $vstr); // before NUKTA
  80. $vstr = preg_replace('/([A-F0-9]{4}) '.$halant.' '.$prebasedvowels.'/','\\2 \\1 '.$halant, $vstr); // before CHAR HALANT
  81. }
  82. // TAMIL pre-based vowel [0ABF]
  83. else if ($lang=='ta') {
  84. // Shrii (Shree)
  85. $vstr = preg_replace('/0BB6 0BCD 0BB0 0BC0/','E04B', $vstr);
  86. // TAMIL double-part vowels [0BCA 0BC6 0BBE][0BCB 0BC7 0BBE][0BCC 0BC6 0BD7]
  87. $vstr = preg_replace('/0BCA/','0BC6 0BBE', $vstr); // convert to 2 parts
  88. $vstr = preg_replace('/0BCB/','0BC7 0BBE', $vstr); // pre-based is then shifted below
  89. $vstr = preg_replace('/0BCC/','0BC6 0BD7', $vstr);
  90. $prebasedvowels = "(0BC6|0BC7|0BC8)";
  91. // No nukta
  92. $halant = "0BCD"; // Doesn't seem to move most in front of halanted consonants
  93. $vstr = preg_replace('/([A-F0-9]{4}) '.$prebasedvowels.'/','\\2 \\1', $vstr); // vowel sign pre-based shift left
  94. // ? Only for special case KSS (already moved to left of 0BB7)
  95. $vstr = preg_replace('/0B95 '.$halant.' '.$prebasedvowels.' 0BB7/','\\1 0B95 '.$halant.' 0BB7', $vstr);
  96. }
  97. // ORIYA
  98. else if ($lang=='or') {
  99. // ORIYA double-part vowels []
  100. $vstr = str_replace('0B48','0B47 0B56', $vstr); // 2-part Vowel
  101. $vstr = str_replace('0B4B','0B47 0B3E', $vstr); // 2-part Vowel
  102. $vstr = str_replace('0B4C','0B47 0B57', $vstr); // 2-part Vowel
  103. $orprebasedvowels = "(0B47)";
  104. // No nukta
  105. $halant = "0B4D";
  106. $vstr = preg_replace('/([A-F0-9]{4}) '.$orprebasedvowels.'/','\\2 \\1', $vstr); // vowel sign pre-based shift left
  107. $vstr = preg_replace('/([A-F0-9]{4}) '.$halant.' '.$orprebasedvowels.'/','\\2 \\1 '.$halant, $vstr); // before CHAR HALANT
  108. $vstr = preg_replace('/([A-F0-9]{4}) '.$halant.' '.$orprebasedvowels.'/','\\2 \\1 '.$halant, $vstr); // before CHAR HALANT
  109. }
  110. // MALAYALAM
  111. else if ($lang=='ml') {
  112. // Chillus - old forms - remove ZWNJ after
  113. // This font Volt rules recognises e.g. "Na Halant(Virama)" as ChilluN
  114. $vstr = preg_replace('/(0D23 0D4D|0D28 0D4D|0D30 0D4D|0D32 0D4D|0D33 0D4D) 200D/','\\1', $vstr);
  115. // See Chillus in Unicode [http://en.wikipedia.org/wiki/Malayalam_script]
  116. $vstr = str_replace('0D7A','0D23 0D4D', $vstr); // [mlymChilluNn]
  117. $vstr = str_replace('0D7B','0D28 0D4D', $vstr); // [mlymChilluN]
  118. $vstr = str_replace('0D7C','0D30 0D4D', $vstr); // [mlymChilluR]
  119. $vstr = str_replace('0D7D','0D32 0D4D', $vstr); // [mlymChilluL]
  120. $vstr = str_replace('0D7E','0D33 0D4D', $vstr); // [mlymChilluLl]
  121. /*
  122. // Chillus - 0D7A-0D7E not in font directly, but as E005-E009
  123. $vstr = preg_replace('/0D23 0D4D 200D/','0D7A', $vstr);
  124. $vstr = preg_replace('/0D28 0D4D 200D/','0D7B', $vstr);
  125. $vstr = preg_replace('/0D30 0D4D 200D/','0D7C', $vstr);
  126. $vstr = preg_replace('/0D32 0D4D 200D/','0D7D', $vstr);
  127. $vstr = preg_replace('/0D33 0D4D 200D/','0D7E', $vstr);
  128. $vstr = preg_replace('/0D7F/','E004', $vstr); // [mlymChilluK]
  129. $vstr = preg_replace('/0D7A/','E005', $vstr); // [mlymChilluNn]
  130. $vstr = preg_replace('/0D7B/','E006', $vstr); // [mlymChilluN]
  131. $vstr = preg_replace('/0D7C/','E007', $vstr); // [mlymChilluR]
  132. $vstr = preg_replace('/0D7D/','E008', $vstr); // [mlymChilluL]
  133. $vstr = preg_replace('/0D7E/','E009', $vstr); // [mlymChilluLl]
  134. */
  135. // MALAYALAM double-part vowels []
  136. $vstr = str_replace('0D4A','0D46 0D3E', $vstr); // 2-part Vowel
  137. $vstr = str_replace('0D4B','0D47 0D3E', $vstr); // 2-part Vowel
  138. $vstr = str_replace('0D4C','0D46 0D57', $vstr); // 2-part Vowel
  139. $mlprebasedvowels = "(0D46|0D47|0D48)";
  140. // No nukta
  141. $halant = "0D4D";
  142. $vstr = preg_replace('/([A-F0-9]{4}) '.$mlprebasedvowels.'/','\\2 \\1', $vstr); // vowel sign pre-based shift left
  143. $vstr = preg_replace('/([A-F0-9]{4}) '.$halant.' '.$mlprebasedvowels.'/','\\2 \\1 '.$halant, $vstr); // before CHAR HALANT
  144. }
  145. // TELUGU
  146. else if ($lang=='te') {
  147. // TELUGU double-part vowels [0C48 -> 0C46 0C56]
  148. $vstr = str_replace('0C48','0C46 0C56', $vstr); // 2-part Vowel
  149. $prebasedvowels = "(0C46)";
  150. $abvvowels = "(0C3E|0C3F|0C40|0C46|0C47|0C4A|0C4B|0C4C|0C55)";
  151. // No nukta
  152. $halant = "0C4D";
  153. $tefullforms = "0C15|0C17|0C18|0C1A|0C1B|0C1C|0C1D|0C20|0C21|0C22|0C24|0C25|0C26|0C27|0C28|0C2A|0C2B|0C2D|0C2E|0C2F|0C30|0C33|0C35|0C36|0C37|0C38|0C39|E028|E029|E02A|E02B|E078|E07A|E07B";
  154. $vstr = preg_replace('/('.$tefullforms .') '.$halant.' ('.$tefullforms .') '.$abvvowels .'/','\\1 \\3 '.$halant.' \\2', $vstr); // before HALANT
  155. }
  156. // KANNADA
  157. else if ($lang=='kn') {
  158. // KANNADA double-part vowels [0CC8 -> 0CC6 0CD6]
  159. $vstr = str_replace('0CC0','0CBF 0CD5', $vstr); // 2-part Vowel
  160. $vstr = str_replace('0CC7','0CC6 0CD5', $vstr); // 2-part Vowel
  161. $vstr = str_replace('0CC8','0CC6 0CD6', $vstr); // 2-part Vowel AI - no glyph for single
  162. $vstr = str_replace('0CCA','0CC6 0CC2', $vstr); // 2-part Vowel
  163. $vstr = str_replace('0CCB','0CC6 0CC2 0CD5', $vstr); // 2-part Vowel
  164. $prebasedvowels = "(0CBF|0CC6)";
  165. $halant = "0CCD";
  166. }
  167. //============================
  168. // SPECIALS
  169. // DEVANAGARI Ra Halant Ra
  170. if ($lang=='hi') {
  171. $vstr = str_replace('0930 094D 0930','E05D 0930', $vstr); // Ra Halant Ra => halfRa FullRa
  172. }
  173. // GUJARATI
  174. if ($lang=='gu') {
  175. $vstr = str_replace('0AB0 0AC2','E02E', $vstr); // Ra VowelUu => SpecialForm RaUu
  176. }
  177. // TELUGU Ra Halant <Consonant> Halant => halfRa Halant<Consonant> Halant
  178. if ($lang=='te') {
  179. $vstr = preg_replace('/0C30 0C4D ([A-F0-9]{4}) 0C4D/','E021 0C4D \\1 0C4D', $vstr);
  180. }
  181. // KANNADA
  182. // Reph at end of word becomes E0CC instead of E00B
  183. if ($lang=='kn') {
  184. $vstr = str_replace('0CB0 0CCD 0020','E0CC 0020', $vstr); // mPDF 5.3.87
  185. }
  186. //============================
  187. // MAIN BIT FROM VOLT RULES
  188. foreach($voltdata[$font] AS $rid=>$reps) {
  189. //echo $rid . ': ' . $vstr.'<br />';
  190. $vstr = preg_replace('/'.$reps['match'].'/',$reps['replace'], $vstr);
  191. }
  192. //echo $vstr.'<br />'; exit;
  193. //============================
  194. // SPECIALS
  195. // KANNADA
  196. // <Base> <BelowBase1> [<BelowBase2> ] MatraI -> <Base/MatraI ligature> <Belowbase1> etc
  197. if ($lang=='kn') {
  198. $matraI = "0CBF";
  199. $knbase = preg_split('/\|/', "0C95|0C96|0C97|0C98|0C9A|0C9B|0C9C|0C9D|0CA0|0CA1|0CA2|0CA3|0CA4|0CA5|0CA6|0CA7|0CA8|0CAA|0CAB|0CAC|0CAD|0CAE|0CAF|0CB0|0CB2|0CB3|0CB5|0CB6|0CB7|0CB8|0CB9|E0A3|E07D|E07E");
  200. $knmatraIligature = preg_split('/\|/', "E082|E083|E084|E085|E086|E087|E088|E089|E08A|E08B|E08C|E08D|E08E|E08F|E090|E091|E092|E093|E094|E095|E096|E097|E098|E099|E09A|E09B|E09C|E09D|E09E|E09F|E0A0|E0A4|E0A1|E0A2");
  201. $belowbase1 = "E02E|E02F|E030|E031|E032|E033|E034|E035|E036|E037|E038|E039|E03A|E03B|E03C|E03D|E03E|E03F|E040|E041|E042|E043|E044|E045|E046|E047|E048|E049|E04A|E04B|E04C|E04D|E04E|E04F|E050|E081";
  202. $belowbase2 = "E052|E053|E054|E055|E056|E057|E058|E059|E05A|E05B|E05C|E05D|E05E|E05F|E060|E061|E062|E063|E064|E065|E066|E067|E068|E069|E06A|E06B|E06C|E06D|E06E|E06F|E070|E071|E072|E073|E074|E081";
  203. for ($i=0; $i<count($knbase);$i++) {
  204. $vstr = preg_replace('/'.$knbase[$i].' ('.$belowbase1.') ('.$belowbase2.') '.$matraI.'/', $knmatraIligature[$i].' \\1 \\2', $vstr);
  205. $vstr = preg_replace('/'.$knbase[$i].' ('.$belowbase1.') '.$matraI.'/', $knmatraIligature[$i].' \\1', $vstr);
  206. }
  207. }
  208. // KANNADA
  209. // [KanTtaFull] [matraI] => [KanTtaPartial] [matraI]
  210. if ($lang=='kn') {
  211. $vstr = preg_replace('/0C9F '.$matraI.'/', 'E015 '.$matraI, $vstr);
  212. }
  213. // ORIYA
  214. if ($lang=='or') {
  215. // SpecialCase Ra[0B30] Halant still left before [oryaFullNnNna] => E00F
  216. $vstr = preg_replace('/0B30 '.$halant.' E00F/','E00F E069', $vstr); // convert to Reph
  217. }
  218. //============================
  219. // SHIFT REPH
  220. // DEVANAGARI Shift Reph [E015]
  221. if ($lang=='hi') {
  222. // FIRSTLY - halfRa = E05D - Change this to Reph [E015]
  223. $himatchhalfforms = "E043|E044|E045|E046|E047|E048|E049|E04A|E04B|E04C|E04D|E04E|E04F|E050|E051|E052|E053|E054|E055|E056|E057|E058|E059|E05A|E05B|E05C|E05D|E05E|E05F|E060|E061|E062|E063|E064|E065|E066|E067|E068|E069|E06A|E06B|E06C|E06D|E06E|E06F|E070|E071|E072|E073|E074|E075|E076|E077|E078|E079|E07A|E07B|E07C|E07D|E07E|E07F|E080|E081|E082|E083|E084|E085|E086|E087|E088|E089|E08A|E0D3|E0D4|E0D5|E0D6|E0D7|E0D8|E0D9|E0DA|E0DB|E0DC|E0DD|E0DE|E0DF|E0E0|E0E1|E0E2|E0E3|E0E4|E0E5|E0E6|E0E7|E0E8|E0E9|E0EA|E0EB|E0EC|E0ED|E0EE|E0EF|E0F0|E0F1|E0F2|E0F3|E0F4|E0F5|E0F6|E0F7|E0F8|E0F9|E0FA|E0FB|E0FC|E0FD|E0FE|E0FF|E100|E101|E102|E103|E104|E105|E106|E107|E108|E109|E10A|E10B|E10C|E10D|E10E|E10F|E110|E111|E112|E113|E114|E115|E116|E117|E118|E119|E11A|E13D|E13E|E13F|E140|E141|E142|E143|E144|E145";
  224. $himatchfullforms = "0915|0916|0917|0918|0919|091A|091B|091C|091D|091E|091F|0920|0921|0922|0923|0924|0925|0926|0927|0928|092A|092B|092C|092D|092E|092F|0930|0932|0933|0935|0936|0937|0938|0939|E028|E029|0958|0959|095A|E02A|E02B|E02C|E02D|095B|E02E|E02F|E030|E031|095C|095D|E032|E033|E034|E035|E036|0929|E037|095E|E038|E039|E03A|095F|0931|E03B|0934|E03C|E03D|E03E|E03F|E040|E041|E042|E08B|E08C|E08D|E08E|E08F|E090|E091|E092|E093|E094|E095|E096|E097|E098|E099|E09A|E09B|E09C|E09D|E09E|E09F|E0A0|E0A1|E0A2|E0A3|E0A4|E0A5|E0A6|E0A7|E0A8|E0A9|E0AA|E0AB|E0AC|E0AD|E0AE|E0AF|E0B0|E0B1|E0B2|E0B3|E0B4|E0B5|E0B6|E0B7|E0B8|E0B9|E0BA|E0BB|E0BC|E0BD|E0BE|E0BF|E0C0|E0C1|E0C2|E0C3|E0C4|E0C5|E0C6|E0C7|E0C8|E0C9|E0CA|E0CB|E0CC|E0CD|E0CE|E0CF|E0D0|E0D1|E0D2|E11E|E11F|E120|E121|E122|E123|E124|E125|E126|E127|E128|E129|E12A|E12B|E12C|E12D|E12E|E12F|E130|E131|E132|E133";
  225. $vstr = preg_replace('/E05D ('.$himatchhalfforms.'|'.$himatchfullforms.')/', 'E015 \\1', $vstr);
  226. // Reph = E015 - Shift Right to just after end of syllable
  227. // FullAllForms + HalfAllForms + 093E matraA
  228. while(preg_match('/E015 ('.$himatchhalfforms.')/', $vstr)) {
  229. $vstr = preg_replace('/E015 ('.$himatchhalfforms.')/', '\\1 E015', $vstr);
  230. }
  231. $vstr = preg_replace('/E015 ('.$himatchfullforms.')/', '\\1 E015', $vstr);
  232. // Now shift it beyond post-based vowels // ??? Need to add others e.g. 0949,094A,094B,094C + presentation forms like E198
  233. $vstr = str_replace('E015 093E', '093E E015', $vstr);
  234. $vstr = preg_replace('/E015 (0940|E194|E195|E196|E197|E198)/', '\\1 E014', $vstr); // (Small) reph [E014] to Right of matraI
  235. $vstr = str_replace('E015 0947', '0947 E014', $vstr); // (Small) reph [E014] to Right of matraI
  236. }
  237. // BENGALI Shift Reph [E068]
  238. else if ($lang=='bn') {
  239. $bnfullconjuncts = "E002|E003|E004|E041|E042|E043|E044|E045|E046|E047|E048|E049|E04A|E04B|E04C|E04D|E04E|E04F|E050|E051|E052|E053|E054|E055|E056|E057|E058|E059|E05A|E05B|E05C|E05D|E05E|E05F|E060|E061|E062|E063|E064|E065|E06A|E06B|E06C|E06D|E06E|E06F|E070|E071|E072|E073|E074|E075|E076|E077|E078|E079|E07A|E07B|E07C|E07D|E07E|E07F|E080|E081|E082|E083|E084|E085|E086|E087|E088|E089|E08A|E08B|E08C|E08D|E08E|E08F|E090|E091|E092|E093|E094|E095|E096|E097|E098|E099|E09A|E09B|E09C|E09D|E09E|E09F|E0A0|E0A1|E0A2|E0A3|E0A4|E0A5|E0A6|E0A7|E0A8|E0A9|E0AA|E0AB|E0AC|E0AD|E0AE|E0AF|E0B0|E0B1|E0B2|E0B3|E0B4|E0B5|E0B6|E0B7|E0B8|E0B9|E0BA|E0BB|E0BC|E0BD|E0BE|E0BF|E0C0|E0C1|E0C2|E0C3|E0C4|E0C5|E0C6|E0C7|E0C8|E0C9|E0CA|E0CB|E0CC|E0CD|E0CE|E0CF|E0D0|E0D1|E0D2|E0D3|E0D4|E0D5|E0D6|E0D7|E0D8|E0D9|E0DA|E0DB|E0DC|E0DD|E0DE|E0DF|E0E0|E0E1|E0E2|E0E3|E0E4|E0E5|E0E6|E0E7|E0E8|E0E9|E0EA|E0EB|E0EC|E0ED|E0EE|E0EF|E0F0|E0F1|E0F2|E0F3|E0F4|E0F5|E0F6|E0F7|E0F8|E0F9|E0FA|E0FB|E0FC|E0FD|E0FE|E0FF|E100|E101|E102|E103|E104|E105|E106|E107|E108|E109|E10A|E10B|E10C|E10D|E10E|E10F|E110|E111|E112|E113|E114|E115|E116|E117|E118|E119|E11A|E11B|E11C|E11D|E11E|E11F|E120|E121|E122|E123|E124|E125|E126|E127|E128|E129|E12A|E12B|E12C|E12D|E12E|E12F|E130|E131|E132|E133|E134|E135|E136|E137|E138|E139|E13A|E13B|E13C|E13D|E13E|E13F|E140|E141|E142|E143|E144|E145|E146|E147|E148|E149|E14A|E14B|E14C|E14D|E14E|E14F|E150|E151|E152|E153|E154|E155|E156|E157|E158|E159|E15A|E15B|E15C|E15D|E15E|E15F|E160|E161|E162|E163|E164|E165|E166|E167|E168|E169|E16A|E16B|E16C|E16D|E16E|E16F|E170|E171|E172|E173|E174|E175|E176|E177|E178|E179|E17A|E17B|E17C|E17D|E17E|E17F|E180|E181|E182|E183|E184|E185|E186|E187|E188|E189|E18A|E18B|E18C|E18D|E18E|E18F|E190|E191|E192|E193|E194|E195|E196|E197|E198|E199|E19A";
  240. // $bnfullcons - set above;
  241. $vstr = preg_replace('/E068 ('.$bnfullconjuncts.'|'.$bnfullcons.')/', '\\1 E068', $vstr);
  242. // ? Need to shift it beyond post-base vowels 09BE, 09C0, 09D7 haven't found so can't test??
  243. $vstr = preg_replace('/E068 (09BE|09C0|09D7)/', '\\1 E068', $vstr);
  244. }
  245. // GUJARATI Shift Reph [E032]
  246. else if ($lang=='gu') {
  247. $gufullforms = "0A95|0A96|0A97|0A98|0A99|0A9A|0A9B|0A9C|0A9D|0A9E|0A9F|0AA0|0AA1|0AA2|0AA3|0AA4|0AA5|0AA6|0AA7|0AA8|0AAA|0AAB|0AAC|0AAD|0AAE|0AAF|0AB0|0AB2|0AB3|0AB5|0AB6|0AB7|0AB8|0AB9|E002|E003|E004|E005|E006|E007|E008|E009|E00A|E00B|E00C|E00D|E00E|E00F|E010|E011|E012|E013|E014|E015|E016|E017|E018|E019|E01A|E01B|E01C|E01D|E01E|E01F|E020|E021|E022|E023|E024|E025|E026|E027|E05E|E05F|E060|E061|E062|E063|E064|E065|E066|E067|E068|E069|E06A|E06B|E06C|E06D|E06E|E06F|E070|E071|E072|E073|E074|E075|E076|E077|E078|E079|E07A|E07B|E07C|E07D|E07E|E07F|E080|E081|E082|E083|E084|E085|E086|E087|E088|E089|E08A|E08B|E08C|E08D|E08E|E08F|E090|E091|E092|E093|E094|E095|E096|E097|E098|E099|E09A|E09B|E09C|E09D|E09E|E09F|E0A0|E0A1|E0A2|E0A3|E0A4|E0A5";
  248. $vstr = preg_replace('/E032 ('.$gufullforms.')/', '\\1 E032', $vstr);
  249. // Now shift it beyond post-based vowels // ??? Need to add others e.g. 0949,094A,094B,094C + presentation forms like E198
  250. // ? Need to shift it beyond post-base vowels 0ABE, 0AC0 haven't found so can't test??
  251. $vstr = preg_replace('/E032 (0ABE|0AC0)/', '\\1 E032', $vstr);
  252. }
  253. // TELUGU Shift Reph to LEFT [E046|E069|E077] [TelRaSmallOne] => E046 [TelRaSmallTwo] => E069 [TelRaSmallThree] => E077
  254. else if ($lang=='te') {
  255. // tefullforms defined earlier
  256. $tepartialforms = "E00D|E00E|E00F|E010|E011|E012|E013|E014|E015|E016|E017|E018|E019|E01A|E01B|E01C|E01D|E01E|E01F|E020|E021|E022|E023|E024|E025|E026|E027|E07C|E07D|E07E";
  257. $matraligs = "E07F|E080|E081|E082|E083|E084|E085|E086|E087|E088|E089|E08A|E08B|E08C|E08D|E08E|E08F|E090|E091|E092|E093|E094|E095|E096|E097|E098|E099|E09A|E09B|E09C|E09D|E09E|E09F|E0A0|E0A1|E0A2|E0A3|E0A4|E0A5|E0A6|E0A7|E0A8|E0A9|E0AA|E0AB|E0AC|E0AD|E0AE|E0AF";
  258. $tevowels = "0C3E|0C3F|0C40|0C46|0C47|0C56|0C4A|0C4B|0C4C"
  259. ."|0C41|0C42|0C43|0C44"; // post matras
  260. $vstr = preg_replace('/('.$tevowels.') (E046|E069|E077)/', '\\2 \\1', $vstr);
  261. while(preg_match('/('.$tepartialforms.') (E046|E069|E077)/', $vstr)) {
  262. $vstr = preg_replace('/('.$tepartialforms.') (E046|E069|E077)/', '\\2 \\1', $vstr);
  263. }
  264. $vstr = preg_replace('/('.$tefullforms .'|'.$matraligs.') (E046|E069|E077)/', '\\2 \\1', $vstr);
  265. }
  266. // KANNADA Shift Reph to RIGHT [E00B]
  267. else if ($lang=='kn') {
  268. $knfullforms = "0C95|0C96|0C97|0C98|0C99|0C9A|0C9B|0C9C|0C9D|0C9E|0C9F|0CA0|0CA1|0CA2|0CA3|0CA4|0CA5|0CA6|0CA7|0CA8|0CAA|0CAB|0CAC|0CAD|0CAE|0CAF|0CB0|0CB1|0CB2|0CB3|0CB5|0CB6|0CB7|0CB8|0CB9|E07D|E07E|E0A3";
  269. $knpartialforms = "E00C|E00D|E00E|E00F|E010|E011|E012|E013|E014|0C9E|E015|E016|E017|E018|E019|E01A|E01B|E01C|E01D|E01E|E01F|E020|E021|E022|E023|E024|E025|E026|E027|E028|E029|E02A|E02B|E02C|E02D|E07F";
  270. while(preg_match('/E00B ('.$knpartialforms.')/', $vstr)) {
  271. $vstr = preg_replace('/E00B ('.$knpartialforms.')/', '\\1 E00B', $vstr);
  272. }
  273. // mPDF 5.3.47 Also move Reph to right of matraIligatures
  274. $knfullforms .= "|E082|E083|E084|E085|E086|E087|E088|E089|E08A|E08B|E08C|E08D|E08E|E08F|E090|E091|E092|E093|E094|E095|E096|E097|E098|E099|E09A|E09B|E09C|E09D|E09E|E09F|E0A0|E0A4|E0A1|E0A2";
  275. $vstr = preg_replace('/E00B ('.$knfullforms.')/', '\\1 E00B', $vstr);
  276. // ? Need to shift it beyond base or below-base forms - haven't found so can't test??
  277. // mPDF 5.3.87
  278. // E004 added to list (which is a transformed version of 0CBE)
  279. $knvowels = "0CBE|0CC0|0CC1|0CC2|0CC3|0CC4|0CC7|0CC8|0CCA|0CCB|0CD5|0CD6|E004";
  280. $vstr = preg_replace('/E00B ('.$knvowels.')/', '\\1 E00B', $vstr);
  281. }
  282. // ORIYA Shift Reph to RIGHT [E069|E06A|E06B|E06C]
  283. else if ($lang=='or') {
  284. $orrephs = "E069|E06A|E06B|E06C";
  285. $orfullforms = "0B15|0B16|0B17|0B18|0B19|0B1A|0B1B|0B1C|0B1D|0B1E|0B1F|0B20|0B21|0B22|0B23|0B24|0B25|0B26|0B27|0B28|0B29|0B2A|0B2B|0B2C|0B2D|0B2E|0B2F|0B30|0B31|0B32|0B33|0B34|0B35|0B36|0B37|0B38|E003|E004|E005|E006|E007|E008|E009|E00A|E00B|E00C|E00D|E00E|E00F|E010|E011|E012|E013|E014|E015|E016|E017|E018|E019|E01A|E01B|E01C|E01D|E01E|E01F|E020|E021|E022|E023|E024|E025|E026|E027|E028|E029|E02A|E02B|E02C|E02D|E02E|E02F|E030|E031|E032|E033|E034|E035|E036|E037";
  286. // E123 - E147 FullHalant forms ? add to FullForms
  287. $orpartialforms = "E090|E091|E092|E093|E094|E095|E096|E097|E098|E099|E09A|E09B|E09C|E09D|E09E|E09F|E0A0|E0A1|E0A2|E0A3|E0A4|E0A5|E0A6|E0A7|E0A8|E0A9|E0AA|E0AB|E0AC|E0AD|E0AE|E0AF|E0B0|E0B1|E0B2|E0B3|E0B4|E0B5|E0B6|E0B7|E0B8|E0B9|E0BA|E0BB|E0BC|E0BD|E0BE|E0BF|E0C0|E0C1|E0C2|E0C3|E0C4|E0C5|E0C6|E0C7|E0C8|E0C9|E0CA|E0CB|E0CC|E0CD|E0CE|E0CF|E0D0|E0D1|E0D2|E0D3|E0D4|E0D5|E0D6|E0D7|E0D8|E0D9|E0DA|E0DB|E0DC|E0DD|E0DE|E0DF|E0E0|E0E1|E0E2|E0E3|E0E4|E0E5|E0E6|E0E7|E0E8|E0E9|E0EA|E0EB|E0EC|E0ED|E0EE|E0EF|E0F0|E0F1|E0F2|E0F3|E0F4|E0F5";
  288. // Combined MatraIReph[E06D] split [0B3F & E069] to allow reph to be shifted forwards
  289. $vstr = preg_replace('/('.$orfullforms.') E06D ('.$orfullforms.') 0B3E/', '\\1 0B3F E069 \\2 0B3E', $vstr);
  290. while(preg_match('/('.$orrephs.') ('.$orpartialforms.')/', $vstr)) {
  291. $vstr = preg_replace('/('.$orrephs.') ('.$orpartialforms.')/', '\\2 \\1', $vstr);
  292. }
  293. $vstr = preg_replace('/('.$orrephs.') ('.$orfullforms.')/', '\\2 \\1', $vstr);
  294. // Combine Reph and MatraI
  295. $vstr = str_replace('E069 0B3F', 'E06D', $vstr); // Reph and MatraI -> MatraIReph
  296. $vstr = str_replace('E06A 0B3F', 'E06E', $vstr); // Reph and MatraI -> MatraIReph
  297. $vstr = str_replace('E06B 0B3F', 'E06F', $vstr); // Reph and MatraI -> MatraIReph
  298. }
  299. // MALAYALAM Shift Reph to LEFT [E00E] (mlylmRaVattu)
  300. else if ($lang=='ml') {
  301. $halant = "0D4D";
  302. $vstr = preg_replace('/([A-F0-9]{4}) '.$halant.' 0D30/','E00E \\1', $vstr); // 0D30 = Ra
  303. $vstr = preg_replace('/([A-F0-9]{4}) '.$halant.' '.$mlprebasedvowels .' 0D30/','\\2 E00E \\1', $vstr); // 0D30 = Ra
  304. $mlfullforms = "0D15|0D16|0D17|0D18|0D19|0D1A|0D1B|0D1C|0D1D|0D1E|0D1F|0D20|0D21|0D22|0D23|0D24|0D25|0D26|0D27|0D28|0D2A|0D2B|0D2C|0D2D|0D2E|0D2F|0D30|0D31|0D32|0D33|0D34|0D35|0D36|0D37|0D38|0D39"
  305. ."|E010|E011|E012|E013|E014|E015|E016|E017|E018|E019|E01A|E01B|E01C|E01D|E01E|E01F|E020|E021|E022|E023|E024|E025|E026|E027|E028|E029|E02A|E02B|E02C|E02D|E02E|E02F|E030|E031|E032|E033|E034|E035|E036|E037|E038|E039|E03A|E03B|E03C|E03D|E03E|E03F|E040|E041|E042|E043|E044|E045|E046|E047|E048|E049|E04A|E04B|E04C|E04D|E04E|E04F|E050|E051|E052|E053|E054|E055|E056|E057|E058|E059|E05A|E05B|E05C|E05D|E05E|E05F|E060|E061|E062|E063|E064|E065|E066|E067|E068|E069|E06A|E06B|E06C|E06D|E06E|E06F|E070|E071|E072|E073|E074|E075|E076|E077|E078|E079|E07A|E07B|E07C|E07D";
  306. // = FullConsonants + FullConjuncts
  307. // = Add Chillu characters // mPDF 5.0.024
  308. $mlfullforms .= "|E004|E005|E006|E007|E008|E009";
  309. while(preg_match('/('.$mlfullforms.') E00E/', $vstr))
  310. $vstr = preg_replace('/('.$mlfullforms.') E00E/', 'E00E \\1', $vstr);
  311. }
  312. //============================
  313. // SHIFT post-based vowels to Left of SmallForms (NOT to left of full forms)
  314. // TELUGU Shift
  315. if ($lang=='te') {
  316. // NB $tevowels defined above
  317. // NB $tefullforms defined above
  318. $tebelowbase1 = "E02C|E02D|E02E|E02F|E030|E031|E032|E033|E034|E035|E036|E037|E038|E039|E03A|E03B|E03C|E03D|E03E|E03F|E040|E041|E042|E043|E044|E045|E046|E047|E048|E049|E04A|E04B|E04C|E04D|E04E"; //'Small1KaToHa'
  319. $tebelowbase2 = "E04F|E050|E051|E052|E053|E054|E055|E056|E057|E058|E059|E05A|E05B|E05C|E05D|E05E|E05F|E060|E061|E062|E063|E064|E065|E066|E067|E068|E069|E06A|E06B|E06C|E06D|E06E|E06F|E070|E071"; // 'Small2KaToHa'
  320. $vstr = preg_replace('/('.$tebelowbase2.') ('.$tevowels.')/', '\\2 \\1', $vstr);
  321. $vstr = preg_replace('/('.$tebelowbase1.') ('.$tevowels.')/', '\\2 \\1', $vstr);
  322. }
  323. // KANNADA Shift
  324. else if ($lang=='kn') {
  325. $knvowels = "0CBE|0CC0|0CC1|0CC2|0CC3|0CC4|0CC7|0CC8|0CCA|0CCB|0CD5|0CD6"
  326. // mPDF 5.3.87 Shouldn't swop E082 and E047 (belowbase1) below
  327. // E082 is a matraIligature
  328. // ."|E082|E083|E084|E085|E086|E087|E088|E089|E08A|E08B|E08C|E08D|E08E|E08F|E090|E091|E092|E093|E094|E095|E096|E097|E098|E099|E09A|E09B|E09C|E09D|E09E|E09F|E0A0|E0A1|E0A2|E0A3|E0A4|E0A5|E0A6|E0A7|E0A8|E0A9|E0AA|E0AB"
  329. ."|E004|E007|E008|E009|E00A";
  330. // NB $knvowels defined above
  331. // NB $fullforms defined above
  332. // $belowbase1/2 defined above
  333. $vstr = preg_replace('/('.$belowbase2.') ('.$knvowels.')/', '\\2 \\1', $vstr);
  334. // mPDF 5.3.87
  335. $vstr = preg_replace('/('.$belowbase1.') ('.$knvowels.')/', '\\2 \\1', $vstr);
  336. //$vstr = preg_replace('/('.$fullforms.') ('.$knvowels.')/', '\\2 \\1', $vstr);
  337. }
  338. //============================
  339. // Clear unwanted ZWJ, ZWNJ
  340. // MALAYALAM
  341. if ($lang=='ml') {
  342. $vstr = preg_replace('/(200C|200D) /','', $vstr);
  343. }
  344. //============================
  345. // END & PUT IT BACK TOGETHER
  346. $vstr = preg_replace('/^0020 (.*) 0020$/', '\\1', $vstr);
  347. $varr = explode(" ",$vstr);
  348. $e = '';
  349. foreach($varr AS $v) {
  350. $e.=code2utf(hexdec($v));
  351. }
  352. //============================
  353. return $e;
  354. }
  355. }
  356. ?>