198628cac9f733f2674d6409954cddb7d0634c233Behdad Esfahbod/*
298628cac9f733f2674d6409954cddb7d0634c233Behdad Esfahbod * Copyright © 2011,2012  Google, Inc.
398628cac9f733f2674d6409954cddb7d0634c233Behdad Esfahbod *
498628cac9f733f2674d6409954cddb7d0634c233Behdad Esfahbod *  This is part of HarfBuzz, a text shaping library.
598628cac9f733f2674d6409954cddb7d0634c233Behdad Esfahbod *
698628cac9f733f2674d6409954cddb7d0634c233Behdad Esfahbod * Permission is hereby granted, without written agreement and without
798628cac9f733f2674d6409954cddb7d0634c233Behdad Esfahbod * license or royalty fees, to use, copy, modify, and distribute this
898628cac9f733f2674d6409954cddb7d0634c233Behdad Esfahbod * software and its documentation for any purpose, provided that the
998628cac9f733f2674d6409954cddb7d0634c233Behdad Esfahbod * above copyright notice and the following two paragraphs appear in
1098628cac9f733f2674d6409954cddb7d0634c233Behdad Esfahbod * all copies of this software.
1198628cac9f733f2674d6409954cddb7d0634c233Behdad Esfahbod *
1298628cac9f733f2674d6409954cddb7d0634c233Behdad Esfahbod * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR
1398628cac9f733f2674d6409954cddb7d0634c233Behdad Esfahbod * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
1498628cac9f733f2674d6409954cddb7d0634c233Behdad Esfahbod * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN
1598628cac9f733f2674d6409954cddb7d0634c233Behdad Esfahbod * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
1698628cac9f733f2674d6409954cddb7d0634c233Behdad Esfahbod * DAMAGE.
1798628cac9f733f2674d6409954cddb7d0634c233Behdad Esfahbod *
1898628cac9f733f2674d6409954cddb7d0634c233Behdad Esfahbod * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING,
1998628cac9f733f2674d6409954cddb7d0634c233Behdad Esfahbod * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
2098628cac9f733f2674d6409954cddb7d0634c233Behdad Esfahbod * FITNESS FOR A PARTICULAR PURPOSE.  THE SOFTWARE PROVIDED HEREUNDER IS
2198628cac9f733f2674d6409954cddb7d0634c233Behdad Esfahbod * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO
2298628cac9f733f2674d6409954cddb7d0634c233Behdad Esfahbod * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
2398628cac9f733f2674d6409954cddb7d0634c233Behdad Esfahbod *
2498628cac9f733f2674d6409954cddb7d0634c233Behdad Esfahbod * Google Author(s): Behdad Esfahbod
2598628cac9f733f2674d6409954cddb7d0634c233Behdad Esfahbod */
2698628cac9f733f2674d6409954cddb7d0634c233Behdad Esfahbod
2798628cac9f733f2674d6409954cddb7d0634c233Behdad Esfahbod#ifndef HB_OT_SHAPE_COMPLEX_MYANMAR_MACHINE_HH
2898628cac9f733f2674d6409954cddb7d0634c233Behdad Esfahbod#define HB_OT_SHAPE_COMPLEX_MYANMAR_MACHINE_HH
2998628cac9f733f2674d6409954cddb7d0634c233Behdad Esfahbod
3098628cac9f733f2674d6409954cddb7d0634c233Behdad Esfahbod#include "hb-private.hh"
3198628cac9f733f2674d6409954cddb7d0634c233Behdad Esfahbod
3298628cac9f733f2674d6409954cddb7d0634c233Behdad Esfahbod%%{
3398628cac9f733f2674d6409954cddb7d0634c233Behdad Esfahbod  machine myanmar_syllable_machine;
3498628cac9f733f2674d6409954cddb7d0634c233Behdad Esfahbod  alphtype unsigned char;
3598628cac9f733f2674d6409954cddb7d0634c233Behdad Esfahbod  write data;
3698628cac9f733f2674d6409954cddb7d0634c233Behdad Esfahbod}%%
3798628cac9f733f2674d6409954cddb7d0634c233Behdad Esfahbod
3898628cac9f733f2674d6409954cddb7d0634c233Behdad Esfahbod%%{
3998628cac9f733f2674d6409954cddb7d0634c233Behdad Esfahbod
4098628cac9f733f2674d6409954cddb7d0634c233Behdad Esfahbod# Same order as enum myanmar_category_t.  Not sure how to avoid duplication.
4198628cac9f733f2674d6409954cddb7d0634c233Behdad EsfahbodA    = 10;
4298628cac9f733f2674d6409954cddb7d0634c233Behdad EsfahbodAs   = 18;
4398628cac9f733f2674d6409954cddb7d0634c233Behdad EsfahbodC    = 1;
4498628cac9f733f2674d6409954cddb7d0634c233Behdad EsfahbodD    = 19;
4598628cac9f733f2674d6409954cddb7d0634c233Behdad EsfahbodD0   = 20;
4698628cac9f733f2674d6409954cddb7d0634c233Behdad EsfahbodDB   = 3;
47186ece94c8838e95db240d3e7c3ce415da6be81eBehdad EsfahbodGB   = 11;
4898628cac9f733f2674d6409954cddb7d0634c233Behdad EsfahbodH    = 4;
4998628cac9f733f2674d6409954cddb7d0634c233Behdad EsfahbodIV   = 2;
5098628cac9f733f2674d6409954cddb7d0634c233Behdad EsfahbodMH   = 21;
5198628cac9f733f2674d6409954cddb7d0634c233Behdad EsfahbodMR   = 22;
5298628cac9f733f2674d6409954cddb7d0634c233Behdad EsfahbodMW   = 23;
5398628cac9f733f2674d6409954cddb7d0634c233Behdad EsfahbodMY   = 24;
5498628cac9f733f2674d6409954cddb7d0634c233Behdad EsfahbodPT   = 25;
5598628cac9f733f2674d6409954cddb7d0634c233Behdad EsfahbodV    = 8;
5698628cac9f733f2674d6409954cddb7d0634c233Behdad EsfahbodVAbv = 26;
5798628cac9f733f2674d6409954cddb7d0634c233Behdad EsfahbodVBlw = 27;
5898628cac9f733f2674d6409954cddb7d0634c233Behdad EsfahbodVPre = 28;
5998628cac9f733f2674d6409954cddb7d0634c233Behdad EsfahbodVPst = 29;
6098628cac9f733f2674d6409954cddb7d0634c233Behdad EsfahbodVS   = 30;
6198628cac9f733f2674d6409954cddb7d0634c233Behdad EsfahbodZWJ  = 6;
6298628cac9f733f2674d6409954cddb7d0634c233Behdad EsfahbodZWNJ = 5;
6398628cac9f733f2674d6409954cddb7d0634c233Behdad EsfahbodRa   = 16;
649174a9db5c4e01284143ed8bd318ce9454535987Behdad EsfahbodP    = 31;
6598628cac9f733f2674d6409954cddb7d0634c233Behdad Esfahbod
6698628cac9f733f2674d6409954cddb7d0634c233Behdad Esfahbodj = ZWJ|ZWNJ;			# Joiners
6798628cac9f733f2674d6409954cddb7d0634c233Behdad Esfahbodk = (Ra As H);			# Kinzi
6898628cac9f733f2674d6409954cddb7d0634c233Behdad Esfahbod
6998628cac9f733f2674d6409954cddb7d0634c233Behdad Esfahbodc = C|Ra;			# is_consonant
7098628cac9f733f2674d6409954cddb7d0634c233Behdad Esfahbod
71439b05867c0856a81fa8f9bea3a7465b4b4bdd91Behdad Esfahbodmedial_group = MY? MR? MW? MH? As?;
7298628cac9f733f2674d6409954cddb7d0634c233Behdad Esfahbodmain_vowel_group = VPre* VAbv* VBlw* A* (DB As?)?;
7398628cac9f733f2674d6409954cddb7d0634c233Behdad Esfahbodpost_vowel_group = VPst MH? As* VAbv* A* (DB As?)?;
74d2da5e0b4b4ffc1722403ffb90b8777cfa1cd174Behdad Esfahbodpwo_tone_group = PT A* DB? As?;
7598628cac9f733f2674d6409954cddb7d0634c233Behdad Esfahbod
7698628cac9f733f2674d6409954cddb7d0634c233Behdad Esfahbodcomplex_syllable_tail = As* medial_group main_vowel_group post_vowel_group* pwo_tone_group* V* j?;
7798628cac9f733f2674d6409954cddb7d0634c233Behdad Esfahbodsyllable_tail = (H | complex_syllable_tail);
7898628cac9f733f2674d6409954cddb7d0634c233Behdad Esfahbod
790572c1410a9cb0ac5dd5dc84a8034698cc5c4892Behdad Esfahbodconsonant_syllable =	k? (c|IV|D|GB).VS? (H (c|IV).VS?)* syllable_tail;
809174a9db5c4e01284143ed8bd318ce9454535987Behdad Esfahbodpunctuation_cluster = 	P V;
8198628cac9f733f2674d6409954cddb7d0634c233Behdad Esfahbodbroken_cluster =	k? VS? syllable_tail;
8298628cac9f733f2674d6409954cddb7d0634c233Behdad Esfahbodother =			any;
8398628cac9f733f2674d6409954cddb7d0634c233Behdad Esfahbod
8498628cac9f733f2674d6409954cddb7d0634c233Behdad Esfahbodmain := |*
8598628cac9f733f2674d6409954cddb7d0634c233Behdad Esfahbod	consonant_syllable	=> { found_syllable (consonant_syllable); };
8698628cac9f733f2674d6409954cddb7d0634c233Behdad Esfahbod	j			=> { found_syllable (non_myanmar_cluster); };
879174a9db5c4e01284143ed8bd318ce9454535987Behdad Esfahbod	punctuation_cluster	=> { found_syllable (punctuation_cluster); };
8898628cac9f733f2674d6409954cddb7d0634c233Behdad Esfahbod	broken_cluster		=> { found_syllable (broken_cluster); };
8998628cac9f733f2674d6409954cddb7d0634c233Behdad Esfahbod	other			=> { found_syllable (non_myanmar_cluster); };
9098628cac9f733f2674d6409954cddb7d0634c233Behdad Esfahbod*|;
9198628cac9f733f2674d6409954cddb7d0634c233Behdad Esfahbod
9298628cac9f733f2674d6409954cddb7d0634c233Behdad Esfahbod
9398628cac9f733f2674d6409954cddb7d0634c233Behdad Esfahbod}%%
9498628cac9f733f2674d6409954cddb7d0634c233Behdad Esfahbod
9598628cac9f733f2674d6409954cddb7d0634c233Behdad Esfahbod#define found_syllable(syllable_type) \
9698628cac9f733f2674d6409954cddb7d0634c233Behdad Esfahbod  HB_STMT_START { \
9798628cac9f733f2674d6409954cddb7d0634c233Behdad Esfahbod    if (0) fprintf (stderr, "syllable %d..%d %s\n", last, p+1, #syllable_type); \
9898628cac9f733f2674d6409954cddb7d0634c233Behdad Esfahbod    for (unsigned int i = last; i < p+1; i++) \
9998628cac9f733f2674d6409954cddb7d0634c233Behdad Esfahbod      info[i].syllable() = (syllable_serial << 4) | syllable_type; \
10098628cac9f733f2674d6409954cddb7d0634c233Behdad Esfahbod    last = p+1; \
10198628cac9f733f2674d6409954cddb7d0634c233Behdad Esfahbod    syllable_serial++; \
10298628cac9f733f2674d6409954cddb7d0634c233Behdad Esfahbod    if (unlikely (syllable_serial == 16)) syllable_serial = 1; \
10398628cac9f733f2674d6409954cddb7d0634c233Behdad Esfahbod  } HB_STMT_END
10498628cac9f733f2674d6409954cddb7d0634c233Behdad Esfahbod
10598628cac9f733f2674d6409954cddb7d0634c233Behdad Esfahbodstatic void
10698628cac9f733f2674d6409954cddb7d0634c233Behdad Esfahbodfind_syllables (hb_buffer_t *buffer)
10798628cac9f733f2674d6409954cddb7d0634c233Behdad Esfahbod{
108e7562f53fe6a506d2c6d59d6688e4fa468bba462Behdad Esfahbod  unsigned int p, pe, eof, ts HB_UNUSED, te HB_UNUSED, act HB_UNUSED;
10998628cac9f733f2674d6409954cddb7d0634c233Behdad Esfahbod  int cs;
11098628cac9f733f2674d6409954cddb7d0634c233Behdad Esfahbod  hb_glyph_info_t *info = buffer->info;
11198628cac9f733f2674d6409954cddb7d0634c233Behdad Esfahbod  %%{
11298628cac9f733f2674d6409954cddb7d0634c233Behdad Esfahbod    write init;
11398628cac9f733f2674d6409954cddb7d0634c233Behdad Esfahbod    getkey info[p].myanmar_category();
11498628cac9f733f2674d6409954cddb7d0634c233Behdad Esfahbod  }%%
11598628cac9f733f2674d6409954cddb7d0634c233Behdad Esfahbod
11698628cac9f733f2674d6409954cddb7d0634c233Behdad Esfahbod  p = 0;
11798628cac9f733f2674d6409954cddb7d0634c233Behdad Esfahbod  pe = eof = buffer->len;
11898628cac9f733f2674d6409954cddb7d0634c233Behdad Esfahbod
11998628cac9f733f2674d6409954cddb7d0634c233Behdad Esfahbod  unsigned int last = 0;
12098628cac9f733f2674d6409954cddb7d0634c233Behdad Esfahbod  unsigned int syllable_serial = 1;
12198628cac9f733f2674d6409954cddb7d0634c233Behdad Esfahbod  %%{
12298628cac9f733f2674d6409954cddb7d0634c233Behdad Esfahbod    write exec;
12398628cac9f733f2674d6409954cddb7d0634c233Behdad Esfahbod  }%%
12498628cac9f733f2674d6409954cddb7d0634c233Behdad Esfahbod}
12598628cac9f733f2674d6409954cddb7d0634c233Behdad Esfahbod
12698628cac9f733f2674d6409954cddb7d0634c233Behdad Esfahbod#undef found_syllable
12798628cac9f733f2674d6409954cddb7d0634c233Behdad Esfahbod
12898628cac9f733f2674d6409954cddb7d0634c233Behdad Esfahbod#endif /* HB_OT_SHAPE_COMPLEX_MYANMAR_MACHINE_HH */
129