1 #line 1 "hb-ot-shape-complex-khmer-machine.rl"
2 /*
3 * Copyright © 2011,2012  Google, Inc.
4 *
5 *  This is part of HarfBuzz, a text shaping library.
6 *
7 * Permission is hereby granted, without written agreement and without
8 * license or royalty fees, to use, copy, modify, and distribute this
9 * software and its documentation for any purpose, provided that the
10 * above copyright notice and the following two paragraphs appear in
11 * all copies of this software.
12 *
13 * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR
14 * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
15 * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN
16 * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
17 * DAMAGE.
18 *
19 * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING,
20 * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
21 * FITNESS FOR A PARTICULAR PURPOSE.  THE SOFTWARE PROVIDED HEREUNDER IS
22 * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO
23 * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
24 *
25 * Google Author(s): Behdad Esfahbod
26 */
27 
28 #ifndef HB_OT_SHAPE_COMPLEX_KHMER_MACHINE_HH
29 #define HB_OT_SHAPE_COMPLEX_KHMER_MACHINE_HH
30 
31 #include "hb.hh"
32 
33 enum khmer_syllable_type_t {
34 	khmer_consonant_syllable,
35 	khmer_broken_cluster,
36 	khmer_non_khmer_cluster,
37 };
38 
39 
40 #line 41 "hb-ot-shape-complex-khmer-machine.hh"
41 #define khmer_syllable_machine_ex_C 1u
42 #define khmer_syllable_machine_ex_Coeng 14u
43 #define khmer_syllable_machine_ex_DOTTEDCIRCLE 12u
44 #define khmer_syllable_machine_ex_PLACEHOLDER 11u
45 #define khmer_syllable_machine_ex_Ra 16u
46 #define khmer_syllable_machine_ex_Robatic 20u
47 #define khmer_syllable_machine_ex_V 2u
48 #define khmer_syllable_machine_ex_VAbv 26u
49 #define khmer_syllable_machine_ex_VBlw 27u
50 #define khmer_syllable_machine_ex_VPre 28u
51 #define khmer_syllable_machine_ex_VPst 29u
52 #define khmer_syllable_machine_ex_Xgroup 21u
53 #define khmer_syllable_machine_ex_Ygroup 22u
54 #define khmer_syllable_machine_ex_ZWJ 6u
55 #define khmer_syllable_machine_ex_ZWNJ 5u
56 
57 
58 #line 59 "hb-ot-shape-complex-khmer-machine.hh"
59 static const unsigned char _khmer_syllable_machine_trans_keys[] = {
60 	2u, 8u, 2u, 6u, 2u, 8u, 2u, 6u,
61 	0u, 0u, 2u, 6u, 2u, 8u, 2u, 6u,
62 	2u, 8u, 2u, 6u, 2u, 6u, 2u, 8u,
63 	2u, 6u, 0u, 0u, 2u, 6u, 2u, 8u,
64 	2u, 6u, 2u, 8u, 2u, 6u, 2u, 8u,
65 	0u, 11u, 2u, 11u, 2u, 11u, 2u, 11u,
66 	7u, 7u, 2u, 7u, 2u, 11u, 2u, 11u,
67 	2u, 11u, 0u, 0u, 2u, 8u, 2u, 11u,
68 	2u, 11u, 7u, 7u, 2u, 7u, 2u, 11u,
69 	2u, 11u, 0u, 0u, 2u, 11u, 2u, 11u,
70 	0u
71 };
72 
73 static const signed char _khmer_syllable_machine_char_class[] = {
74 	0, 0, 1, 1, 2, 2, 1, 1,
75 	1, 1, 3, 3, 1, 4, 1, 0,
76 	1, 1, 1, 5, 6, 7, 1, 1,
77 	1, 8, 9, 10, 11, 0
78 };
79 
80 static const short _khmer_syllable_machine_index_offsets[] = {
81 	0, 7, 12, 19, 24, 25, 30, 37,
82 	42, 49, 54, 59, 66, 71, 72, 77,
83 	84, 89, 96, 101, 108, 120, 130, 140,
84 	150, 151, 157, 167, 177, 187, 188, 195,
85 	205, 215, 216, 222, 232, 242, 243, 253,
86 	0
87 };
88 
89 static const signed char _khmer_syllable_machine_indicies[] = {
90 	1, 0, 0, 2, 3, 0, 4, 1,
91 	0, 0, 0, 3, 1, 0, 0, 0,
92 	3, 0, 4, 5, 0, 0, 0, 4,
93 	6, 7, 0, 0, 0, 8, 9, 0,
94 	0, 0, 10, 0, 4, 9, 0, 0,
95 	0, 10, 11, 0, 0, 0, 12, 0,
96 	4, 11, 0, 0, 0, 12, 14, 13,
97 	13, 13, 15, 14, 16, 16, 16, 15,
98 	16, 17, 18, 16, 16, 16, 17, 19,
99 	20, 16, 16, 16, 21, 22, 16, 16,
100 	16, 23, 16, 17, 22, 16, 16, 16,
101 	23, 24, 16, 16, 16, 25, 16, 17,
102 	24, 16, 16, 16, 25, 14, 16, 16,
103 	26, 15, 16, 17, 29, 28, 30, 2,
104 	31, 28, 15, 19, 17, 23, 25, 21,
105 	33, 32, 34, 2, 3, 6, 4, 10,
106 	12, 8, 35, 32, 36, 32, 3, 6,
107 	4, 10, 12, 8, 5, 32, 36, 32,
108 	4, 6, 32, 32, 32, 8, 6, 7,
109 	32, 36, 32, 8, 6, 37, 32, 36,
110 	32, 10, 6, 4, 32, 32, 8, 38,
111 	32, 36, 32, 12, 6, 4, 10, 32,
112 	8, 35, 32, 34, 32, 3, 6, 4,
113 	10, 12, 8, 29, 14, 39, 39, 39,
114 	15, 39, 17, 41, 40, 42, 40, 15,
115 	19, 17, 23, 25, 21, 18, 40, 42,
116 	40, 17, 19, 40, 40, 40, 21, 19,
117 	20, 40, 42, 40, 21, 19, 43, 40,
118 	42, 40, 23, 19, 17, 40, 40, 21,
119 	44, 40, 42, 40, 25, 19, 17, 23,
120 	40, 21, 45, 46, 40, 31, 26, 15,
121 	19, 17, 23, 25, 21, 41, 40, 31,
122 	40, 15, 19, 17, 23, 25, 21, 0
123 };
124 
125 static const signed char _khmer_syllable_machine_index_defaults[] = {
126 	0, 0, 0, 0, 0, 0, 0, 0,
127 	0, 0, 13, 16, 16, 16, 16, 16,
128 	16, 16, 16, 16, 28, 32, 32, 32,
129 	32, 32, 32, 32, 32, 32, 39, 40,
130 	40, 40, 40, 40, 40, 40, 40, 40,
131 	0
132 };
133 
134 static const signed char _khmer_syllable_machine_cond_targs[] = {
135 	20, 1, 28, 22, 23, 3, 24, 5,
136 	25, 7, 26, 9, 27, 20, 10, 31,
137 	20, 32, 12, 33, 14, 34, 16, 35,
138 	18, 36, 39, 20, 20, 21, 30, 37,
139 	20, 0, 29, 2, 4, 6, 8, 20,
140 	20, 11, 13, 15, 17, 38, 19, 0
141 };
142 
143 static const signed char _khmer_syllable_machine_cond_actions[] = {
144 	1, 0, 2, 2, 2, 0, 0, 0,
145 	2, 0, 2, 0, 2, 3, 0, 4,
146 	5, 2, 0, 0, 0, 2, 0, 2,
147 	0, 2, 4, 0, 8, 2, 9, 0,
148 	10, 0, 0, 0, 0, 0, 0, 11,
149 	12, 0, 0, 0, 0, 4, 0, 0
150 };
151 
152 static const signed char _khmer_syllable_machine_to_state_actions[] = {
153 	0, 0, 0, 0, 0, 0, 0, 0,
154 	0, 0, 0, 0, 0, 0, 0, 0,
155 	0, 0, 0, 0, 6, 0, 0, 0,
156 	0, 0, 0, 0, 0, 0, 0, 0,
157 	0, 0, 0, 0, 0, 0, 0, 0,
158 	0
159 };
160 
161 static const signed char _khmer_syllable_machine_from_state_actions[] = {
162 	0, 0, 0, 0, 0, 0, 0, 0,
163 	0, 0, 0, 0, 0, 0, 0, 0,
164 	0, 0, 0, 0, 7, 0, 0, 0,
165 	0, 0, 0, 0, 0, 0, 0, 0,
166 	0, 0, 0, 0, 0, 0, 0, 0,
167 	0
168 };
169 
170 static const signed char _khmer_syllable_machine_eof_trans[] = {
171 	1, 1, 1, 1, 1, 1, 1, 1,
172 	1, 1, 14, 17, 17, 17, 17, 17,
173 	17, 17, 17, 17, 28, 33, 33, 33,
174 	33, 33, 33, 33, 33, 33, 40, 41,
175 	41, 41, 41, 41, 41, 41, 41, 41,
176 	0
177 };
178 
179 static const int khmer_syllable_machine_start = 20;
180 static const int khmer_syllable_machine_first_final = 20;
181 static const int khmer_syllable_machine_error = -1;
182 
183 static const int khmer_syllable_machine_en_main = 20;
184 
185 
186 #line 43 "hb-ot-shape-complex-khmer-machine.rl"
187 
188 
189 
190 #line 86 "hb-ot-shape-complex-khmer-machine.rl"
191 
192 
193 #define found_syllable(syllable_type) \
194 HB_STMT_START { \
195 	if (0) fprintf (stderr, "syllable %d..%d %s\n", ts, te, #syllable_type); \
196 		for (unsigned int i = ts; i < te; i++) \
197 	info[i].syllable() = (syllable_serial << 4) | syllable_type; \
198 	syllable_serial++; \
199 	if (unlikely (syllable_serial == 16)) syllable_serial = 1; \
200 	} HB_STMT_END
201 
202 static void
find_syllables_khmer(hb_buffer_t * buffer)203 find_syllables_khmer (hb_buffer_t *buffer)
204 {
205 	unsigned int p, pe, eof, ts, te, act HB_UNUSED;
206 	int cs;
207 	hb_glyph_info_t *info = buffer->info;
208 
209 #line 210 "hb-ot-shape-complex-khmer-machine.hh"
210 	{
211 		cs = (int)khmer_syllable_machine_start;
212 		ts = 0;
213 		te = 0;
214 		act = 0;
215 	}
216 
217 #line 106 "hb-ot-shape-complex-khmer-machine.rl"
218 
219 
220 	p = 0;
221 	pe = eof = buffer->len;
222 
223 	unsigned int syllable_serial = 1;
224 
225 #line 226 "hb-ot-shape-complex-khmer-machine.hh"
226 	{
227 		unsigned int _trans = 0;
228 		const unsigned char * _keys;
229 		const signed char * _inds;
230 		int _ic;
231 		_resume: {}
232 		if ( p == pe && p != eof )
233 			goto _out;
234 		switch ( _khmer_syllable_machine_from_state_actions[cs] ) {
235 			case 7:  {
236 				{
237 #line 1 "NONE"
238 					{ts = p;}}
239 
240 #line 241 "hb-ot-shape-complex-khmer-machine.hh"
241 
242 
243 				break;
244 			}
245 		}
246 
247 		if ( p == eof ) {
248 			if ( _khmer_syllable_machine_eof_trans[cs] > 0 ) {
249 				_trans = (unsigned int)_khmer_syllable_machine_eof_trans[cs] - 1;
250 			}
251 		}
252 		else {
253 			_keys = ( _khmer_syllable_machine_trans_keys + ((cs<<1)));
254 			_inds = ( _khmer_syllable_machine_indicies + (_khmer_syllable_machine_index_offsets[cs]));
255 
256 			if ( (info[p].khmer_category()) <= 29 && (info[p].khmer_category()) >= 1 ) {
257 				_ic = (int)_khmer_syllable_machine_char_class[(int)(info[p].khmer_category()) - 1];
258 				if ( _ic <= (int)(*( _keys+1)) && _ic >= (int)(*( _keys)) )
259 					_trans = (unsigned int)(*( _inds + (int)( _ic - (int)(*( _keys)) ) ));
260 				else
261 					_trans = (unsigned int)_khmer_syllable_machine_index_defaults[cs];
262 			}
263 			else {
264 				_trans = (unsigned int)_khmer_syllable_machine_index_defaults[cs];
265 			}
266 
267 		}
268 		cs = (int)_khmer_syllable_machine_cond_targs[_trans];
269 
270 		if ( _khmer_syllable_machine_cond_actions[_trans] != 0 ) {
271 
272 			switch ( _khmer_syllable_machine_cond_actions[_trans] ) {
273 				case 2:  {
274 					{
275 #line 1 "NONE"
276 						{te = p+1;}}
277 
278 #line 279 "hb-ot-shape-complex-khmer-machine.hh"
279 
280 
281 					break;
282 				}
283 				case 8:  {
284 					{
285 #line 82 "hb-ot-shape-complex-khmer-machine.rl"
286 						{te = p+1;{
287 #line 82 "hb-ot-shape-complex-khmer-machine.rl"
288 								found_syllable (khmer_non_khmer_cluster); }
289 						}}
290 
291 #line 292 "hb-ot-shape-complex-khmer-machine.hh"
292 
293 
294 					break;
295 				}
296 				case 10:  {
297 					{
298 #line 80 "hb-ot-shape-complex-khmer-machine.rl"
299 						{te = p;p = p - 1;{
300 #line 80 "hb-ot-shape-complex-khmer-machine.rl"
301 								found_syllable (khmer_consonant_syllable); }
302 						}}
303 
304 #line 305 "hb-ot-shape-complex-khmer-machine.hh"
305 
306 
307 					break;
308 				}
309 				case 12:  {
310 					{
311 #line 81 "hb-ot-shape-complex-khmer-machine.rl"
312 						{te = p;p = p - 1;{
313 #line 81 "hb-ot-shape-complex-khmer-machine.rl"
314 								found_syllable (khmer_broken_cluster); }
315 						}}
316 
317 #line 318 "hb-ot-shape-complex-khmer-machine.hh"
318 
319 
320 					break;
321 				}
322 				case 11:  {
323 					{
324 #line 82 "hb-ot-shape-complex-khmer-machine.rl"
325 						{te = p;p = p - 1;{
326 #line 82 "hb-ot-shape-complex-khmer-machine.rl"
327 								found_syllable (khmer_non_khmer_cluster); }
328 						}}
329 
330 #line 331 "hb-ot-shape-complex-khmer-machine.hh"
331 
332 
333 					break;
334 				}
335 				case 1:  {
336 					{
337 #line 80 "hb-ot-shape-complex-khmer-machine.rl"
338 						{p = ((te))-1;
339 							{
340 #line 80 "hb-ot-shape-complex-khmer-machine.rl"
341 								found_syllable (khmer_consonant_syllable); }
342 						}}
343 
344 #line 345 "hb-ot-shape-complex-khmer-machine.hh"
345 
346 
347 					break;
348 				}
349 				case 5:  {
350 					{
351 #line 81 "hb-ot-shape-complex-khmer-machine.rl"
352 						{p = ((te))-1;
353 							{
354 #line 81 "hb-ot-shape-complex-khmer-machine.rl"
355 								found_syllable (khmer_broken_cluster); }
356 						}}
357 
358 #line 359 "hb-ot-shape-complex-khmer-machine.hh"
359 
360 
361 					break;
362 				}
363 				case 3:  {
364 					{
365 #line 1 "NONE"
366 						{switch( act ) {
367 								case 2:  {
368 									p = ((te))-1;
369 									{
370 #line 81 "hb-ot-shape-complex-khmer-machine.rl"
371 										found_syllable (khmer_broken_cluster); }
372 									break;
373 								}
374 								case 3:  {
375 									p = ((te))-1;
376 									{
377 #line 82 "hb-ot-shape-complex-khmer-machine.rl"
378 										found_syllable (khmer_non_khmer_cluster); }
379 									break;
380 								}
381 							}}
382 					}
383 
384 #line 385 "hb-ot-shape-complex-khmer-machine.hh"
385 
386 
387 					break;
388 				}
389 				case 4:  {
390 					{
391 #line 1 "NONE"
392 						{te = p+1;}}
393 
394 #line 395 "hb-ot-shape-complex-khmer-machine.hh"
395 
396 					{
397 #line 81 "hb-ot-shape-complex-khmer-machine.rl"
398 						{act = 2;}}
399 
400 #line 401 "hb-ot-shape-complex-khmer-machine.hh"
401 
402 
403 					break;
404 				}
405 				case 9:  {
406 					{
407 #line 1 "NONE"
408 						{te = p+1;}}
409 
410 #line 411 "hb-ot-shape-complex-khmer-machine.hh"
411 
412 					{
413 #line 82 "hb-ot-shape-complex-khmer-machine.rl"
414 						{act = 3;}}
415 
416 #line 417 "hb-ot-shape-complex-khmer-machine.hh"
417 
418 
419 					break;
420 				}
421 			}
422 
423 		}
424 
425 		if ( p == eof ) {
426 			if ( cs >= 20 )
427 				goto _out;
428 		}
429 		else {
430 			switch ( _khmer_syllable_machine_to_state_actions[cs] ) {
431 				case 6:  {
432 					{
433 #line 1 "NONE"
434 						{ts = 0;}}
435 
436 #line 437 "hb-ot-shape-complex-khmer-machine.hh"
437 
438 
439 					break;
440 				}
441 			}
442 
443 			p += 1;
444 			goto _resume;
445 		}
446 		_out: {}
447 	}
448 
449 #line 114 "hb-ot-shape-complex-khmer-machine.rl"
450 
451 }
452 
453 #undef found_syllable
454 
455 #endif /* HB_OT_SHAPE_COMPLEX_KHMER_MACHINE_HH */
456