PluginProbe
PDF & Print by BestWebSoft – WordPress Posts and Pages PDF Generator Plugin / 1.9.0
PDF & Print by BestWebSoft – WordPress Posts and Pages PDF Generator Plugin v1.9.0
trunk 1.5 1.6 1.7 1.7.1 1.7.2 1.7.3 1.7.4 1.7.5 1.7.6 1.7.7 1.7.8 1.7.9 1.8.0 1.8.1 1.8.2 1.8.3 1.8.4 1.8.5 1.8.6 1.8.7 1.8.8 1.8.9 1.9.0 1.9.1 All 71 releases
pdf-print / mpdf / classes / myanmar.php

myanmar.php in PDF & Print by BestWebSoft – WordPress Posts and Pages PDF Generator Plugin 1.9.0, at mpdf/classes/myanmar.php

481 lines 13.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3
4 class MYANMAR {
5
6 /* FROM hb-ot-shape-complex-indic-private.hh */
7 // indic_category
8 const OT_X = 0;
9 const OT_C = 1;
10 const OT_V = 2;
11 const OT_N = 3;
12 const OT_H = 4;
13 const OT_ZWNJ = 5;
14 const OT_ZWJ = 6;
15 const OT_M = 7; /* Matra or Dependent Vowel */
16 const OT_SM = 8;
17 const OT_VD = 9;
18 const OT_A = 10;
19 const OT_NBSP = 11;
20 const OT_DOTTEDCIRCLE = 12; /* Not in the spec, but special in Uniscribe. /Very very/ special! */
21 const OT_RS = 13; /* Register Shifter, used in Khmer OT spec */
22 const OT_Coeng = 14;
23 const OT_Repha = 15;
24 const OT_Ra = 16; /* Not explicitly listed in the OT spec, but used in the grammar. */
25 const OT_CM = 17;
26
27 /* FROM hb-ot-shape-complex-myanmar.hh */
28 // myanmar_category
29 const OT_DB = 3; // same as INDIC::OT_N; /* Dot below */
30 const OT_GB = 12; // same as INDIC::OT_DOTTEDCIRCLE;
31
32 const OT_As = 18; /* Asat */
33 const OT_D = 19; /* Digits except zero */
34 const OT_D0 = 20; /* Digit zero */
35 const OT_MH = 21; /* Various consonant medial types */
36 const OT_MR = 22; /* Various consonant medial types */
37 const OT_MW = 23; /* Various consonant medial types */
38 const OT_MY = 24; /* Various consonant medial types */
39 const OT_PT = 25; /* Pwo and other tones */
40 const OT_VAbv = 26;
41 const OT_VBlw = 27;
42 const OT_VPre = 28;
43 const OT_VPst = 29;
44 const OT_VS = 30; /* Variation selectors */
45
46
47 // Based on myanmar_category used to make string to find syllables
48 // OT_ to string character (using e.g. OT_C from MYANMAR) hb-ot-shape-complex-myanmar-private.hh
49 public static $myanmar_category_char = array(
50 'x',
51 'C',
52 'V',
53 'N',
54 'H',
55 'Z',
56 'J',
57 'x',
58 'S',
59 'x',
60 'A',
61 'x',
62 'D',
63 'x',
64 'x',
65 'x',
66 'R',
67 'x',
68
69
70 'a', /* As Asat */
71 'd', /* Digits except zero */
72 'o', /* Digit zero */
73 'k', /* Medial types */
74 'l', /* Medial types */
75 'm', /* Medial types */
76 'n', /* Medial types */
77 'p', /* Pwo and other tones */
78 'v', /* Vowel aboVe */
79 'b', /* Vowel Below */
80 'e', /* Vowel prE */
81 't', /* Vowel posT */
82 's', /* variation Selector */
83
84 );
85
86
87 /* Visual positions in a syllable from left to right. */
88 /* FROM hb-ot-shape-complex-myanmar-private.hh */
89 // myanmar_position
90 const POS_START = 0;
91
92 const POS_RA_TO_BECOME_REPH = 1;
93 const POS_PRE_M = 2;
94 const POS_PRE_C = 3;
95
96 const POS_BASE_C = 4;
97 const POS_AFTER_MAIN = 5;
98
99 const POS_ABOVE_C = 6;
100
101 const POS_BEFORE_SUB = 7;
102 const POS_BELOW_C = 8;
103 const POS_AFTER_SUB = 9;
104
105 const POS_BEFORE_POST = 10;
106 const POS_POST_C = 11;
107 const POS_AFTER_POST = 12;
108
109 const POS_FINAL_C = 13;
110 const POS_SMVD = 14;
111
112 const POS_END = 15;
113
114
115
116 public static function set_myanmar_properties(&$info) {
117 $u = $info['uni'];
118 $type = self::myanmar_get_categories($u);
119 $cat = ($type & 0x7F);
120 $pos = ($type >> 8);
121 /*
122 * Re-assign category
123 * http://www.microsoft.com/typography/OpenTypeDev/myanmar/intro.htm#analyze
124 */
125 if (self::in_range($u, 0xFE00, 0xFE0F))
126 $cat = self::OT_VS;
127 else if ($u == 0x200C) $cat = self::OT_ZWNJ;
128 else if ($u == 0x200D) $cat = self::OT_ZWJ;
129
130 switch ($u) {
131 case 0x002D: case 0x00A0: case 0x00D7: case 0x2012:
132 case 0x2013: case 0x2014: case 0x2015: case 0x2022:
133 case 0x25CC: case 0x25FB: case 0x25FC: case 0x25FD:
134 case 0x25FE:
135 $cat = self::OT_GB;
136 break;
137
138 case 0x1004: case 0x101B: case 0x105A:
139 $cat = self::OT_Ra;
140 break;
141
142 case 0x1032: case 0x1036:
143 $cat = self::OT_A;
144 break;
145
146 case 0x103A:
147 $cat = self::OT_As;
148 break;
149
150 case 0x1041: case 0x1042: case 0x1043: case 0x1044:
151 case 0x1045: case 0x1046: case 0x1047: case 0x1048:
152 case 0x1049: case 0x1090: case 0x1091: case 0x1092:
153 case 0x1093: case 0x1094: case 0x1095: case 0x1096:
154 case 0x1097: case 0x1098: case 0x1099:
155 $cat = self::OT_D;
156 break;
157
158 case 0x1040:
159 $cat = self::OT_D; /* XXX The spec says D0, but Uniscribe doesn't seem to do. */
160 break;
161
162 case 0x103E: case 0x1060:
163 $cat = self::OT_MH;
164 break;
165
166 case 0x103C:
167 $cat = self::OT_MR;
168 break;
169
170 case 0x103D: case 0x1082:
171 $cat = self::OT_MW;
172 break;
173
174 case 0x103B: case 0x105E: case 0x105F:
175 $cat = self::OT_MY;
176 break;
177
178 case 0x1063: case 0x1064: case 0x1069: case 0x106A:
179 case 0x106B: case 0x106C: case 0x106D: case 0xAA7B:
180 $cat = self::OT_PT;
181 break;
182
183 case 0x1038: case 0x1087: case 0x1088: case 0x1089:
184 case 0x108A: case 0x108B: case 0x108C: case 0x108D:
185 case 0x108F: case 0x109A: case 0x109B: case 0x109C:
186 $cat = self::OT_SM;
187 break;
188 }
189
190 if ($cat == self::OT_M) {
191 switch ($pos) {
192 case self::POS_PRE_C:
193 $cat = self::OT_VPre;
194 $pos = self::POS_PRE_M;
195 break;
196 case self::POS_ABOVE_C: $cat = self::OT_VAbv; break;
197 case self::POS_BELOW_C: $cat = self::OT_VBlw; break;
198 case self::POS_POST_C: $cat = self::OT_VPst; break;
199 }
200 }
201 $info['myanmar_category'] = $cat;
202 $info['myanmar_position'] = $pos;
203 }
204
205 // syllable_type
206 const CONSONANT_SYLLABLE = 0;
207 const BROKEN_CLUSTER = 3;
208 const NON_MYANMAR_CLUSTER = 4;
209
210
211
212 public static function set_syllables(&$o, $s, &$broken_syllables) {
213 $ptr = 0;
214 $syllable_serial = 1;
215 $broken_syllables = false;
216
217 while($ptr < strlen($s)) {
218 $match = '';
219 $syllable_length = 1;
220 $syllable_type = self::NON_MYANMAR_CLUSTER ;
221 // CONSONANT_SYLLABLE Consonant syllable
222 // From OT spec:
223 if (preg_match('/^(RaH)?([C|R]|V|d|D)[s]?(H([C|R|V])[s]?)*(H|[a]*[n]?[l]?((m[k]?|k)[a]?)?[e]*[v]*[b]*[A]*(N[a]?)?(t[k]?[a]*[v]*[A]*(N[a]?)?)*(p[A]*(N[a]?)?)*S*[J|Z]?)/', substr($s,$ptr), $ma)) {
224 $syllable_length = strlen($ma[0]);
225 $syllable_type = self::CONSONANT_SYLLABLE ;
226 }
227
228 // BROKEN_CLUSTER syllable
229 else if (preg_match('/^(RaH)?s?(H|[a]*[n]?[l]?((m[k]?|k)[a]?)?[e]*[v]*[b]*[A]*(N[a]?)?(t[k]?[a]*[v]*[A]*(N[a]?)?)*(p[A]*(N[a]?)?)*S*[J|Z]?)/', substr($s,$ptr), $ma)) {
230 if (strlen($ma[0])) { // May match blank
231 $syllable_length = strlen($ma[0]);
232 $syllable_type = self::BROKEN_CLUSTER ;
233 $broken_syllables = true;
234 }
235 }
236 for ($i = $ptr; $i < $ptr+$syllable_length; $i++) { $o[$i]['syllable'] = ($syllable_serial << 4) | $syllable_type; }
237 $ptr += $syllable_length ;
238 $syllable_serial++;
239 if ($syllable_serial == 16) $syllable_serial = 1;
240 }
241 }
242
243
244
245 public static function reordering(&$info, $GSUBdata, $broken_syllables, $dottedcircle) {
246 if ($broken_syllables && $dottedcircle) { self::insert_dotted_circles ($info, $dottedcircle); }
247 $count = count($info);
248 if (!$count) return;
249 $last = 0;
250 $last_syllable = $info[0]['syllable'];
251 for ($i = 1; $i < $count; $i++) {
252 if ($last_syllable != $info[$i]['syllable']) {
253 self::reordering_syllable ($info, $GSUBdata, $last, $i);
254 $last = $i;
255 $last_syllable = $info[$last]['syllable'];
256 }
257 }
258 self::reordering_syllable($info, $GSUBdata, $last, $count);
259 }
260
261 public static function insert_dotted_circles(&$info, $dottedcircle) {
262 $idx = 0;
263 $last_syllable = 0;
264 while ($idx < count($info)) {
265 $syllable = $info[$idx]['syllable'];
266 $syllable_type = ($syllable & 0x0F);
267 if ($last_syllable != $syllable && $syllable_type == self::BROKEN_CLUSTER) {
268 $last_syllable = $syllable;
269 $dottedcircle[0]['syllable'] = $info[$idx]['syllable'];
270 array_splice($info, $idx, 0, $dottedcircle);
271 }
272 else
273 $idx++;
274 }
275 // In case of final bloken cluster...
276 $syllable = $info[$idx]['syllable'];
277 $syllable_type = ($syllable & 0x0F);
278 if ($last_syllable != $syllable && $syllable_type == self::BROKEN_CLUSTER) {
279 $dottedcircle[0]['syllable'] = $info[$idx]['syllable'];
280 array_splice($info, $idx, 0, $dottedcircle);
281 }
282 }
283
284
285
286 /* Rules from:
287 * https://www.microsoft.com/typography/otfntdev/devanot/shaping.aspx */
288
289 public static function reordering_syllable (&$info, $GSUBdata, $start, $end) {
290 /* vowel_syllable: We made the vowels look like consonants. So uses the consonant logic! */
291 /* broken_cluster: We already inserted dotted-circles, so just call the standalone_cluster. */
292
293 $syllable_type = ($info[$start]['syllable'] & 0x0F);
294 if ($syllable_type==self::NON_MYANMAR_CLUSTER ) { return; }
295 if ($syllable_type==self::BROKEN_CLUSTER) {
296 //if ($uniscribe_bug_compatible) {
297 /* For dotted-circle, this is what Uniscribe does:
298 * If dotted-circle is the last glyph, it just does nothing.
299 * i.e. It doesn't form Reph. */
300 if ($info[$end - 1]['myanmar_category'] == self::OT_DOTTEDCIRCLE) {
301 return;
302 }
303 }
304
305 $base = $end;
306 $has_reph = false;
307 $limit = $start;
308
309 if (($start + 3 <= $end) &&
310 $info[$start]['myanmar_category'] == self::OT_Ra &&
311 $info[$start+1]['myanmar_category'] == self::OT_As &&
312 $info[$start+2]['myanmar_category'] == self::OT_H ) {
313 $limit += 3;
314 $base = $start;
315 $has_reph = true;
316 }
317
318 if (!$has_reph)
319 $base = $limit;
320
321 for ($i = $limit; $i < $end; $i++) {
322 if (self::is_consonant($info[$i])) {
323 $base = $i;
324 break;
325 }
326 }
327
328
329 /* Reorder! */
330 $i = $start;
331 for (; $i < $start + ($has_reph ? 3 : 0); $i++)
332 $info[$i]['myanmar_position'] = self::POS_AFTER_MAIN;
333 for (; $i < $base; $i++)
334 $info[$i]['myanmar_position'] = self::POS_PRE_C;
335 if ($i < $end) {
336 $info[$i]['myanmar_position'] = self::POS_BASE_C;
337 $i++;
338 }
339 $pos = self::POS_AFTER_MAIN;
340 /* The following loop may be ugly, but it implements all of
341 * Myanmar reordering! */
342 for (; $i < $end; $i++) {
343 if ($info[$i]['myanmar_category'] == self::OT_MR) /* Pre-base reordering */
344 {
345 $info[$i]['myanmar_position'] = self::POS_PRE_C;
346 continue;
347 }
348 if ($info[$i]['myanmar_position'] < self::POS_BASE_C) /* Left matra */
349 {
350 continue;
351 }
352
353 if ($pos == self::POS_AFTER_MAIN && $info[$i]['myanmar_category'] == self::OT_VBlw)
354 {
355 $pos = self::POS_BELOW_C;
356 $info[$i]['myanmar_position'] = $pos;
357 continue;
358 }
359
360 if ($pos == self::POS_BELOW_C && $info[$i]['myanmar_category'] == self::OT_A)
361 {
362 $info[$i]['myanmar_position'] = self::POS_BEFORE_SUB;
363 continue;
364 }
365 if ($pos == self::POS_BELOW_C && $info[$i]['myanmar_category'] == self::OT_VBlw)
366 {
367 $info[$i]['myanmar_position'] = $pos;
368 continue;
369 }
370 if ($pos == self::POS_BELOW_C && $info[$i]['myanmar_category'] != self::OT_A)
371 {
372 $pos = self::POS_AFTER_SUB;
373 $info[$i]['myanmar_position'] = $pos;
374 continue;
375 }
376 $info[$i]['myanmar_position'] = $pos;
377 }
378
379
380 /* Sit tight, rock 'n roll! */
381 self::bubble_sort ($info, $start, $end - $start);
382
383 }
384
385
386 public static function is_one_of ($info, $flags) {
387 if (isset($info['is_ligature']) && $info['is_ligature']) return false; /* If it ligated, all bets are off. */
388 return !!(self::FLAG($info['myanmar_category']) & $flags);
389 }
390
391 /* Vowels and placeholders treated as if they were consonants. */
392 public static function is_consonant($info) {
393 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_GB)));
394 }
395
396
397
398 // From hb-private.hh
399 public static function in_range ($u, $lo, $hi) {
400 if ( (($lo^$hi) & $lo) == 0 && (($lo^$hi) & $hi) == ($lo^$hi) && (($lo^$hi) & (($lo^$hi) + 1)) == 0 )
401 return ($u & ~($lo^$hi)) == $lo;
402 else
403 return $lo <= $u && $u <= $hi;
404 }
405
406 // From hb-private.hh
407 public static function FLAG($x) { return (1<<($x)); }
408
409 public static function FLAG_RANGE($x,$y) { self::FLAG(y+1) - self::FLAG(x); }
410
411
412
413 // BELOW from hb-ot-shape-complex-indic.cc
414 // see INDIC for details
415
416 public static $myanmar_table = array(
417
418 /* Myanmar (1000..109F) */
419
420 /* 1000 */ 3841, 3841, 3841, 3841, 3841, 3841, 3841, 3841,
421 /* 1008 */ 3841, 3841, 3841, 3841, 3841, 3841, 3841, 3841,
422 /* 1010 */ 3841, 3841, 3841, 3841, 3841, 3841, 3841, 3841,
423 /* 1018 */ 3841, 3841, 3841, 3841, 3841, 3841, 3841, 3841,
424 /* 1020 */ 3841, 3842, 3842, 3842, 3842, 3842, 3842, 3842,
425 /* 1028 */ 3842, 3842, 3842, 2823, 2823, 1543, 1543, 2055,
426 /* 1030 */ 2055, 775, 1543, 1543, 1543, 1543, 3848, 3843,
427 /* 1038 */ 3848, 3844, 1540, 3857, 3857, 3857, 3857, 3841,
428 /* 1040 */ 3840, 3840, 3840, 3840, 3840, 3840, 3840, 3840,
429 /* 1048 */ 3840, 3840, 3840, 3840, 3840, 3840, 3840, 3840,
430 /* 1050 */ 3841, 3841, 3842, 3842, 3842, 3842, 2823, 2823,
431 /* 1058 */ 2055, 2055, 3841, 3841, 3841, 3841, 3857, 3857,
432 /* 1060 */ 3857, 3841, 2823, 3843, 3843, 3841, 3841, 2823,
433 /* 1068 */ 2823, 3843, 3843, 3843, 3843, 3843, 3841, 3841,
434 /* 1070 */ 3841, 1543, 1543, 1543, 1543, 3841, 3841, 3841,
435 /* 1078 */ 3841, 3841, 3841, 3841, 3841, 3841, 3841, 3841,
436 /* 1080 */ 3841, 3841, 3857, 2823, 775, 1543, 1543, 3843,
437 /* 1088 */ 3843, 3843, 3843, 3843, 3843, 3843, 3841, 3843,
438 /* 1090 */ 3840, 3840, 3840, 3840, 3840, 3840, 3840, 3840,
439 /* 1098 */ 3840, 3840, 3843, 3843, 2823, 1543, 3840, 3840,
440
441 /* Myanmar Extended-A (AA60..AA7F) */
442
443 /* AA60 */ 3841, 3841, 3841, 3841, 3841, 3841, 3841, 3841,
444 /* AA68 */ 3841, 3841, 3841, 3841, 3841, 3841, 3841, 3841,
445 /* AA70 */ 3840, 3841, 3841, 3841, 3840, 3840, 3840, 3840,
446 /* AA78 */ 3840, 3840, 3841, 3843, 3840, 3840, 3840, 3840,
447
448
449 );
450
451 // from "hb-ot-shape-complex-indic-table.cc"
452 public static function myanmar_get_categories ($u) {
453 if (0x1000 <= $u && $u <= 0x109F) return self::$myanmar_table[$u - 0x1000 + 0]; // offset 0 for Most "myanmar"
454 if (0xAA60 <= $u && $u <= 0xAA7F) return self::$myanmar_table[$u - 0xAA60 + 160]; // offset for extensions
455 if ($u == 0x00A0) return 3851; // (ISC_CP | (IMC_x << 8))
456 if ($u == 0x25CC) return 3851; // (ISC_CP | (IMC_x << 8))
457 return 3840; // (ISC_x | (IMC_x << 8))
458 }
459
460
461 public static function bubble_sort(&$arr, $start, $len) {
462 if ($len<2) { return;}
463 $k = $start+$len-2;
464 while ($k >= $start) {
465 for ($j=$start; $j<=$k; $j++) {
466 if ($arr[$j]['myanmar_position'] > $arr[$j + 1]['myanmar_position']) {
467 $t = $arr[$j];
468 $arr[$j] = $arr[$j + 1];
469 $arr[$j + 1] = $t;
470 }
471 }
472 $k--;
473 }
474 }
475
476
477
478
479 } // end Class
480
481 ?>