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