Imported Upstream version 1.2.7
[platform/upstream/harfbuzz.git] / src / hb-ot-shape-complex-use-machine.rl
1 /*
2  * Copyright © 2015  Mozilla Foundation.
3  * Copyright © 2015  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  * Mozilla Author(s): Jonathan Kew
26  * Google Author(s): Behdad Esfahbod
27  */
28
29 #ifndef HB_OT_SHAPE_COMPLEX_USE_MACHINE_HH
30 #define HB_OT_SHAPE_COMPLEX_USE_MACHINE_HH
31
32 #include "hb-private.hh"
33
34 %%{
35   machine use_syllable_machine;
36   alphtype unsigned char;
37   write data;
38 }%%
39
40 %%{
41
42 # Same order as enum use_category_t.  Not sure how to avoid duplication.
43
44 O       = 0; # OTHER
45
46 B       = 1; # BASE
47 IV      = 2; # BASE_VOWEL
48 IND     = 3; # BASE_IND
49 N       = 4; # BASE_NUM
50 GB      = 5; # BASE_OTHER
51 CGJ     = 6; # CGJ
52 #F      = 7; # CONS_FINAL
53 FM      = 8; # CONS_FINAL_MOD
54 #M      = 9; # CONS_MED
55 #CM     = 10; # CONS_MOD
56 SUB     = 11; # CONS_SUB
57 H       = 12; # HALANT
58
59 HN      = 13; # HALANT_NUM
60 ZWNJ    = 14; # Zero width non-joiner
61 ZWJ     = 15; # Zero width joiner
62 WJ      = 16; # Word joiner
63 Rsv     = 17; # Reserved characters
64 R       = 18; # REPHA
65 S       = 19; # SYM
66 #SM     = 20; # SYM_MOD
67 VS      = 21; # VARIATION_SELECTOR
68 #V      = 36; # VOWEL
69 #VM     = 40; # VOWEL_MOD
70
71 FAbv    = 24; # CONS_FINAL_ABOVE
72 FBlw    = 25; # CONS_FINAL_BELOW
73 FPst    = 26; # CONS_FINAL_POST
74 MAbv    = 27; # CONS_MED_ABOVE
75 MBlw    = 28; # CONS_MED_BELOW
76 MPst    = 29; # CONS_MED_POST
77 MPre    = 30; # CONS_MED_PRE
78 CMAbv   = 31; # CONS_MOD_ABOVE
79 CMBlw   = 32; # CONS_MOD_BELOW
80 VAbv    = 33; # VOWEL_ABOVE / VOWEL_ABOVE_BELOW / VOWEL_ABOVE_BELOW_POST / VOWEL_ABOVE_POST
81 VBlw    = 34; # VOWEL_BELOW / VOWEL_BELOW_POST
82 VPst    = 35; # VOWEL_POST      UIPC = Right
83 VPre    = 22; # VOWEL_PRE / VOWEL_PRE_ABOVE / VOWEL_PRE_ABOVE_POST / VOWEL_PRE_POST
84 VMAbv   = 37; # VOWEL_MOD_ABOVE
85 VMBlw   = 38; # VOWEL_MOD_BELOW
86 VMPst   = 39; # VOWEL_MOD_POST
87 VMPre   = 23; # VOWEL_MOD_PRE
88 SMAbv   = 41; # SYM_MOD_ABOVE
89 SMBlw   = 42; # SYM_MOD_BELOW
90
91
92 consonant_modifiers = CMAbv* CMBlw* ((H B | SUB) VS? CMAbv? CMBlw*)*;
93 medial_consonants = MPre? MAbv? MBlw? MPst?;
94 dependent_vowels = VPre* VAbv* VBlw* VPst*;
95 vowel_modifiers = VMPre* VMAbv* VMBlw* VMPst*;
96 final_consonants = FAbv* FBlw* FPst* FM?;
97
98 virama_terminated_cluster =
99         R? (B | GB | IV) VS?
100         consonant_modifiers
101         H
102 ;
103 consonant_cluster =
104         R? (B | GB) VS?
105         consonant_modifiers
106         medial_consonants
107         dependent_vowels
108         vowel_modifiers
109         final_consonants
110 ;
111 vowel_cluster =
112         R? (IV) VS?
113         consonant_modifiers
114         medial_consonants
115         vowel_modifiers
116         final_consonants
117 ;
118
119 broken_cluster =
120         R?
121         consonant_modifiers
122         medial_consonants
123         dependent_vowels
124         vowel_modifiers
125         final_consonants
126 ;
127
128 number_joiner_terminated_cluster = N VS? (HN N VS?)* H;
129 numeral_cluster = N VS? (HN N VS?)*;
130 symbol_cluster = S VS? SMAbv* SMBlw*;
131 independent_cluster = (IND | O | Rsv | WJ) VS?;
132
133 main := |*
134         independent_cluster                     => { found_syllable (independent_cluster); };
135         virama_terminated_cluster               => { found_syllable (virama_terminated_cluster); };
136         consonant_cluster                       => { found_syllable (consonant_cluster); };
137         vowel_cluster                           => { found_syllable (vowel_cluster); };
138         number_joiner_terminated_cluster        => { found_syllable (number_joiner_terminated_cluster); };
139         numeral_cluster                         => { found_syllable (numeral_cluster); };
140         symbol_cluster                          => { found_syllable (symbol_cluster); };
141         broken_cluster                          => { found_syllable (broken_cluster); };
142 *|;
143
144
145 }%%
146
147 #define found_syllable(syllable_type) \
148   HB_STMT_START { \
149     if (0) fprintf (stderr, "syllable %d..%d %s\n", last, p+1, #syllable_type); \
150     for (unsigned int i = last; i < p+1; i++) \
151       info[i].syllable() = (syllable_serial << 4) | syllable_type; \
152     last = p+1; \
153     syllable_serial++; \
154     if (unlikely (syllable_serial == 16)) syllable_serial = 1; \
155   } HB_STMT_END
156
157 static void
158 find_syllables (hb_buffer_t *buffer)
159 {
160   unsigned int p, pe, eof, ts HB_UNUSED, te HB_UNUSED, act HB_UNUSED;
161   int cs;
162   hb_glyph_info_t *info = buffer->info;
163   %%{
164     write init;
165     getkey info[p].use_category();
166   }%%
167
168   p = 0;
169   pe = eof = buffer->len;
170
171   unsigned int last = 0;
172   unsigned int syllable_serial = 1;
173   %%{
174     write exec;
175   }%%
176 }
177
178 #undef found_syllable
179
180 #endif /* HB_OT_SHAPE_COMPLEX_USE_MACHINE_HH */