michael@0: /* michael@0: * Copyright © 2011,2012 Google, Inc. michael@0: * michael@0: * This is part of HarfBuzz, a text shaping library. michael@0: * michael@0: * Permission is hereby granted, without written agreement and without michael@0: * license or royalty fees, to use, copy, modify, and distribute this michael@0: * software and its documentation for any purpose, provided that the michael@0: * above copyright notice and the following two paragraphs appear in michael@0: * all copies of this software. michael@0: * michael@0: * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR michael@0: * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES michael@0: * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN michael@0: * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH michael@0: * DAMAGE. michael@0: * michael@0: * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, michael@0: * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND michael@0: * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS michael@0: * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO michael@0: * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. michael@0: * michael@0: * Google Author(s): Behdad Esfahbod michael@0: */ michael@0: michael@0: #ifndef HB_OT_SHAPE_COMPLEX_MYANMAR_MACHINE_HH michael@0: #define HB_OT_SHAPE_COMPLEX_MYANMAR_MACHINE_HH michael@0: michael@0: #include "hb-private.hh" michael@0: michael@0: %%{ michael@0: machine myanmar_syllable_machine; michael@0: alphtype unsigned char; michael@0: write data; michael@0: }%% michael@0: michael@0: %%{ michael@0: michael@0: # Same order as enum myanmar_category_t. Not sure how to avoid duplication. michael@0: A = 10; michael@0: As = 18; michael@0: C = 1; michael@0: D = 19; michael@0: D0 = 20; michael@0: DB = 3; michael@0: GB = 12; michael@0: H = 4; michael@0: IV = 2; michael@0: MH = 21; michael@0: MR = 22; michael@0: MW = 23; michael@0: MY = 24; michael@0: PT = 25; michael@0: V = 8; michael@0: VAbv = 26; michael@0: VBlw = 27; michael@0: VPre = 28; michael@0: VPst = 29; michael@0: VS = 30; michael@0: ZWJ = 6; michael@0: ZWNJ = 5; michael@0: Ra = 16; michael@0: P = 31; michael@0: michael@0: j = ZWJ|ZWNJ; # Joiners michael@0: k = (Ra As H); # Kinzi michael@0: michael@0: c = C|Ra; # is_consonant michael@0: michael@0: medial_group = MY? MR? ((MW MH? | MH) As?)?; michael@0: main_vowel_group = VPre* VAbv* VBlw* A* (DB As?)?; michael@0: post_vowel_group = VPst MH? As* VAbv* A* (DB As?)?; michael@0: pwo_tone_group = PT A* DB? As?; michael@0: michael@0: complex_syllable_tail = As* medial_group main_vowel_group post_vowel_group* pwo_tone_group* V* j?; michael@0: syllable_tail = (H | complex_syllable_tail); michael@0: michael@0: consonant_syllable = k? (c|IV|D|GB).VS? (H (c|IV).VS?)* syllable_tail; michael@0: punctuation_cluster = P V; michael@0: broken_cluster = k? VS? syllable_tail; michael@0: other = any; michael@0: michael@0: main := |* michael@0: consonant_syllable => { found_syllable (consonant_syllable); }; michael@0: j => { found_syllable (non_myanmar_cluster); }; michael@0: punctuation_cluster => { found_syllable (punctuation_cluster); }; michael@0: broken_cluster => { found_syllable (broken_cluster); }; michael@0: other => { found_syllable (non_myanmar_cluster); }; michael@0: *|; michael@0: michael@0: michael@0: }%% michael@0: michael@0: #define found_syllable(syllable_type) \ michael@0: HB_STMT_START { \ michael@0: if (0) fprintf (stderr, "syllable %d..%d %s\n", last, p+1, #syllable_type); \ michael@0: for (unsigned int i = last; i < p+1; i++) \ michael@0: info[i].syllable() = (syllable_serial << 4) | syllable_type; \ michael@0: last = p+1; \ michael@0: syllable_serial++; \ michael@0: if (unlikely (syllable_serial == 16)) syllable_serial = 1; \ michael@0: } HB_STMT_END michael@0: michael@0: static void michael@0: find_syllables (hb_buffer_t *buffer) michael@0: { michael@0: unsigned int p, pe, eof, ts HB_UNUSED, te HB_UNUSED, act HB_UNUSED; michael@0: int cs; michael@0: hb_glyph_info_t *info = buffer->info; michael@0: %%{ michael@0: write init; michael@0: getkey info[p].myanmar_category(); michael@0: }%% michael@0: michael@0: p = 0; michael@0: pe = eof = buffer->len; michael@0: michael@0: unsigned int last = 0; michael@0: unsigned int syllable_serial = 1; michael@0: %%{ michael@0: write exec; michael@0: }%% michael@0: } michael@0: michael@0: #undef found_syllable michael@0: michael@0: #endif /* HB_OT_SHAPE_COMPLEX_MYANMAR_MACHINE_HH */