1e0eabd7f67462ac34fbfc749d897be478fbd1224Behdad Esfahbod/*
2e0eabd7f67462ac34fbfc749d897be478fbd1224Behdad Esfahbod * Copyright © 2015  Mozilla Foundation.
3e0eabd7f67462ac34fbfc749d897be478fbd1224Behdad Esfahbod * Copyright © 2015  Google, Inc.
4e0eabd7f67462ac34fbfc749d897be478fbd1224Behdad Esfahbod *
5e0eabd7f67462ac34fbfc749d897be478fbd1224Behdad Esfahbod *  This is part of HarfBuzz, a text shaping library.
6e0eabd7f67462ac34fbfc749d897be478fbd1224Behdad Esfahbod *
7e0eabd7f67462ac34fbfc749d897be478fbd1224Behdad Esfahbod * Permission is hereby granted, without written agreement and without
8e0eabd7f67462ac34fbfc749d897be478fbd1224Behdad Esfahbod * license or royalty fees, to use, copy, modify, and distribute this
9e0eabd7f67462ac34fbfc749d897be478fbd1224Behdad Esfahbod * software and its documentation for any purpose, provided that the
10e0eabd7f67462ac34fbfc749d897be478fbd1224Behdad Esfahbod * above copyright notice and the following two paragraphs appear in
11e0eabd7f67462ac34fbfc749d897be478fbd1224Behdad Esfahbod * all copies of this software.
12e0eabd7f67462ac34fbfc749d897be478fbd1224Behdad Esfahbod *
13e0eabd7f67462ac34fbfc749d897be478fbd1224Behdad Esfahbod * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR
14e0eabd7f67462ac34fbfc749d897be478fbd1224Behdad Esfahbod * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
15e0eabd7f67462ac34fbfc749d897be478fbd1224Behdad Esfahbod * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN
16e0eabd7f67462ac34fbfc749d897be478fbd1224Behdad Esfahbod * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
17e0eabd7f67462ac34fbfc749d897be478fbd1224Behdad Esfahbod * DAMAGE.
18e0eabd7f67462ac34fbfc749d897be478fbd1224Behdad Esfahbod *
19e0eabd7f67462ac34fbfc749d897be478fbd1224Behdad Esfahbod * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING,
20e0eabd7f67462ac34fbfc749d897be478fbd1224Behdad Esfahbod * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
21e0eabd7f67462ac34fbfc749d897be478fbd1224Behdad Esfahbod * FITNESS FOR A PARTICULAR PURPOSE.  THE SOFTWARE PROVIDED HEREUNDER IS
22e0eabd7f67462ac34fbfc749d897be478fbd1224Behdad Esfahbod * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO
23e0eabd7f67462ac34fbfc749d897be478fbd1224Behdad Esfahbod * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
24e0eabd7f67462ac34fbfc749d897be478fbd1224Behdad Esfahbod *
25e0eabd7f67462ac34fbfc749d897be478fbd1224Behdad Esfahbod * Mozilla Author(s): Jonathan Kew
26e0eabd7f67462ac34fbfc749d897be478fbd1224Behdad Esfahbod * Google Author(s): Behdad Esfahbod
27e0eabd7f67462ac34fbfc749d897be478fbd1224Behdad Esfahbod */
28e0eabd7f67462ac34fbfc749d897be478fbd1224Behdad Esfahbod
29e0eabd7f67462ac34fbfc749d897be478fbd1224Behdad Esfahbod#ifndef HB_OT_SHAPE_COMPLEX_USE_MACHINE_HH
30e0eabd7f67462ac34fbfc749d897be478fbd1224Behdad Esfahbod#define HB_OT_SHAPE_COMPLEX_USE_MACHINE_HH
31e0eabd7f67462ac34fbfc749d897be478fbd1224Behdad Esfahbod
32e0eabd7f67462ac34fbfc749d897be478fbd1224Behdad Esfahbod#include "hb-private.hh"
33e0eabd7f67462ac34fbfc749d897be478fbd1224Behdad Esfahbod
34e0eabd7f67462ac34fbfc749d897be478fbd1224Behdad Esfahbod%%{
35e0eabd7f67462ac34fbfc749d897be478fbd1224Behdad Esfahbod  machine use_syllable_machine;
36e0eabd7f67462ac34fbfc749d897be478fbd1224Behdad Esfahbod  alphtype unsigned char;
37e0eabd7f67462ac34fbfc749d897be478fbd1224Behdad Esfahbod  write data;
38e0eabd7f67462ac34fbfc749d897be478fbd1224Behdad Esfahbod}%%
39e0eabd7f67462ac34fbfc749d897be478fbd1224Behdad Esfahbod
40e0eabd7f67462ac34fbfc749d897be478fbd1224Behdad Esfahbod%%{
41e0eabd7f67462ac34fbfc749d897be478fbd1224Behdad Esfahbod
42e0eabd7f67462ac34fbfc749d897be478fbd1224Behdad Esfahbod# Same order as enum use_category_t.  Not sure how to avoid duplication.
43e0eabd7f67462ac34fbfc749d897be478fbd1224Behdad Esfahbod
44e0eabd7f67462ac34fbfc749d897be478fbd1224Behdad EsfahbodO	= 0; # OTHER
45e0eabd7f67462ac34fbfc749d897be478fbd1224Behdad Esfahbod
46e0eabd7f67462ac34fbfc749d897be478fbd1224Behdad EsfahbodB	= 1; # BASE
47e0eabd7f67462ac34fbfc749d897be478fbd1224Behdad EsfahbodIND	= 3; # BASE_IND
48e0eabd7f67462ac34fbfc749d897be478fbd1224Behdad EsfahbodN	= 4; # BASE_NUM
49e0eabd7f67462ac34fbfc749d897be478fbd1224Behdad EsfahbodGB	= 5; # BASE_OTHER
50e0eabd7f67462ac34fbfc749d897be478fbd1224Behdad EsfahbodCGJ	= 6; # CGJ
51e0eabd7f67462ac34fbfc749d897be478fbd1224Behdad Esfahbod#F	= 7; # CONS_FINAL
52e0eabd7f67462ac34fbfc749d897be478fbd1224Behdad EsfahbodFM	= 8; # CONS_FINAL_MOD
53e0eabd7f67462ac34fbfc749d897be478fbd1224Behdad Esfahbod#M	= 9; # CONS_MED
54e0eabd7f67462ac34fbfc749d897be478fbd1224Behdad Esfahbod#CM	= 10; # CONS_MOD
55e0eabd7f67462ac34fbfc749d897be478fbd1224Behdad EsfahbodSUB	= 11; # CONS_SUB
56e0eabd7f67462ac34fbfc749d897be478fbd1224Behdad EsfahbodH	= 12; # HALANT
577ce03ebe7c525919ce22d9094480847ff1b3c2b2Behdad Esfahbod
58e0eabd7f67462ac34fbfc749d897be478fbd1224Behdad EsfahbodHN	= 13; # HALANT_NUM
59e0eabd7f67462ac34fbfc749d897be478fbd1224Behdad EsfahbodZWNJ	= 14; # Zero width non-joiner
60e0eabd7f67462ac34fbfc749d897be478fbd1224Behdad EsfahbodZWJ	= 15; # Zero width joiner
61e0eabd7f67462ac34fbfc749d897be478fbd1224Behdad EsfahbodWJ	= 16; # Word joiner
62e0eabd7f67462ac34fbfc749d897be478fbd1224Behdad EsfahbodRsv	= 17; # Reserved characters
63e0eabd7f67462ac34fbfc749d897be478fbd1224Behdad EsfahbodR	= 18; # REPHA
64e0eabd7f67462ac34fbfc749d897be478fbd1224Behdad EsfahbodS	= 19; # SYM
65e0eabd7f67462ac34fbfc749d897be478fbd1224Behdad Esfahbod#SM	= 20; # SYM_MOD
66e0eabd7f67462ac34fbfc749d897be478fbd1224Behdad EsfahbodVS	= 21; # VARIATION_SELECTOR
677ce03ebe7c525919ce22d9094480847ff1b3c2b2Behdad Esfahbod#V	= 36; # VOWEL
687ce03ebe7c525919ce22d9094480847ff1b3c2b2Behdad Esfahbod#VM	= 40; # VOWEL_MOD
69e0eabd7f67462ac34fbfc749d897be478fbd1224Behdad Esfahbod
70e0eabd7f67462ac34fbfc749d897be478fbd1224Behdad EsfahbodFAbv	= 24; # CONS_FINAL_ABOVE
71e0eabd7f67462ac34fbfc749d897be478fbd1224Behdad EsfahbodFBlw	= 25; # CONS_FINAL_BELOW
72e0eabd7f67462ac34fbfc749d897be478fbd1224Behdad EsfahbodFPst	= 26; # CONS_FINAL_POST
73e0eabd7f67462ac34fbfc749d897be478fbd1224Behdad EsfahbodMAbv	= 27; # CONS_MED_ABOVE
74e0eabd7f67462ac34fbfc749d897be478fbd1224Behdad EsfahbodMBlw	= 28; # CONS_MED_BELOW
75e0eabd7f67462ac34fbfc749d897be478fbd1224Behdad EsfahbodMPst	= 29; # CONS_MED_POST
76e0eabd7f67462ac34fbfc749d897be478fbd1224Behdad EsfahbodMPre	= 30; # CONS_MED_PRE
77e0eabd7f67462ac34fbfc749d897be478fbd1224Behdad EsfahbodCMAbv	= 31; # CONS_MOD_ABOVE
78e0eabd7f67462ac34fbfc749d897be478fbd1224Behdad EsfahbodCMBlw	= 32; # CONS_MOD_BELOW
79e0eabd7f67462ac34fbfc749d897be478fbd1224Behdad EsfahbodVAbv	= 33; # VOWEL_ABOVE / VOWEL_ABOVE_BELOW / VOWEL_ABOVE_BELOW_POST / VOWEL_ABOVE_POST
80e0eabd7f67462ac34fbfc749d897be478fbd1224Behdad EsfahbodVBlw	= 34; # VOWEL_BELOW / VOWEL_BELOW_POST
81e0eabd7f67462ac34fbfc749d897be478fbd1224Behdad EsfahbodVPst	= 35; # VOWEL_POST	UIPC = Right
827ce03ebe7c525919ce22d9094480847ff1b3c2b2Behdad EsfahbodVPre	= 22; # VOWEL_PRE / VOWEL_PRE_ABOVE / VOWEL_PRE_ABOVE_POST / VOWEL_PRE_POST
83e0eabd7f67462ac34fbfc749d897be478fbd1224Behdad EsfahbodVMAbv	= 37; # VOWEL_MOD_ABOVE
84e0eabd7f67462ac34fbfc749d897be478fbd1224Behdad EsfahbodVMBlw	= 38; # VOWEL_MOD_BELOW
85e0eabd7f67462ac34fbfc749d897be478fbd1224Behdad EsfahbodVMPst	= 39; # VOWEL_MOD_POST
867ce03ebe7c525919ce22d9094480847ff1b3c2b2Behdad EsfahbodVMPre	= 23; # VOWEL_MOD_PRE
87e0eabd7f67462ac34fbfc749d897be478fbd1224Behdad EsfahbodSMAbv	= 41; # SYM_MOD_ABOVE
88e0eabd7f67462ac34fbfc749d897be478fbd1224Behdad EsfahbodSMBlw	= 42; # SYM_MOD_BELOW
89e0eabd7f67462ac34fbfc749d897be478fbd1224Behdad Esfahbod
90e0eabd7f67462ac34fbfc749d897be478fbd1224Behdad Esfahbod
91e0eabd7f67462ac34fbfc749d897be478fbd1224Behdad Esfahbodconsonant_modifiers = CMAbv* CMBlw* ((H B | SUB) VS? CMAbv? CMBlw*)*;
92e0eabd7f67462ac34fbfc749d897be478fbd1224Behdad Esfahbodmedial_consonants = MPre? MAbv? MBlw? MPst?;
93e0eabd7f67462ac34fbfc749d897be478fbd1224Behdad Esfahboddependent_vowels = VPre* VAbv* VBlw* VPst*;
94e0eabd7f67462ac34fbfc749d897be478fbd1224Behdad Esfahbodvowel_modifiers = VMPre* VMAbv* VMBlw* VMPst*;
95e0eabd7f67462ac34fbfc749d897be478fbd1224Behdad Esfahbodfinal_consonants = FAbv* FBlw* FPst* FM?;
96e0eabd7f67462ac34fbfc749d897be478fbd1224Behdad Esfahbod
97e0eabd7f67462ac34fbfc749d897be478fbd1224Behdad Esfahbodvirama_terminated_cluster =
989b6312f9451db790db00dc2c2e27a5a1db852e72Behdad Esfahbod	R? (B | GB) VS?
99e0eabd7f67462ac34fbfc749d897be478fbd1224Behdad Esfahbod	consonant_modifiers
100e0eabd7f67462ac34fbfc749d897be478fbd1224Behdad Esfahbod	H
101e0eabd7f67462ac34fbfc749d897be478fbd1224Behdad Esfahbod;
1029b6312f9451db790db00dc2c2e27a5a1db852e72Behdad Esfahbodstandard_cluster =
103e0eabd7f67462ac34fbfc749d897be478fbd1224Behdad Esfahbod	R? (B | GB) VS?
104e0eabd7f67462ac34fbfc749d897be478fbd1224Behdad Esfahbod	consonant_modifiers
105e0eabd7f67462ac34fbfc749d897be478fbd1224Behdad Esfahbod	medial_consonants
106e0eabd7f67462ac34fbfc749d897be478fbd1224Behdad Esfahbod	dependent_vowels
107e0eabd7f67462ac34fbfc749d897be478fbd1224Behdad Esfahbod	vowel_modifiers
108e0eabd7f67462ac34fbfc749d897be478fbd1224Behdad Esfahbod	final_consonants
109e0eabd7f67462ac34fbfc749d897be478fbd1224Behdad Esfahbod;
110e0eabd7f67462ac34fbfc749d897be478fbd1224Behdad Esfahbod
11140c4a991c7ea18017273ff8993eecc3953869e69Behdad Esfahbodbroken_cluster =
11240c4a991c7ea18017273ff8993eecc3953869e69Behdad Esfahbod	R?
11340c4a991c7ea18017273ff8993eecc3953869e69Behdad Esfahbod	consonant_modifiers
11440c4a991c7ea18017273ff8993eecc3953869e69Behdad Esfahbod	medial_consonants
11540c4a991c7ea18017273ff8993eecc3953869e69Behdad Esfahbod	dependent_vowels
11640c4a991c7ea18017273ff8993eecc3953869e69Behdad Esfahbod	vowel_modifiers
11740c4a991c7ea18017273ff8993eecc3953869e69Behdad Esfahbod	final_consonants
11840c4a991c7ea18017273ff8993eecc3953869e69Behdad Esfahbod;
11940c4a991c7ea18017273ff8993eecc3953869e69Behdad Esfahbod
120d04e461fe3310ccaf8633efcb79b8eb6ca2201c3Behdad Esfahbodnumber_joiner_terminated_cluster = N VS? (HN N VS?)* HN;
121eb74535cc2c0d0de41e54e75bdc71825ec969523Behdad Esfahbodnumeral_cluster = N VS? (HN N VS?)*;
122e0eabd7f67462ac34fbfc749d897be478fbd1224Behdad Esfahbodsymbol_cluster = S VS? SMAbv* SMBlw*;
123e0eabd7f67462ac34fbfc749d897be478fbd1224Behdad Esfahbodindependent_cluster = (IND | O | Rsv | WJ) VS?;
1243e4e7616a8ca80a50a438601b84428b4ba4c8694Behdad Esfahbodother = any;
125e0eabd7f67462ac34fbfc749d897be478fbd1224Behdad Esfahbod
126e0eabd7f67462ac34fbfc749d897be478fbd1224Behdad Esfahbodmain := |*
127e0eabd7f67462ac34fbfc749d897be478fbd1224Behdad Esfahbod	independent_cluster			=> { found_syllable (independent_cluster); };
128e0eabd7f67462ac34fbfc749d897be478fbd1224Behdad Esfahbod	virama_terminated_cluster		=> { found_syllable (virama_terminated_cluster); };
1299b6312f9451db790db00dc2c2e27a5a1db852e72Behdad Esfahbod	standard_cluster			=> { found_syllable (standard_cluster); };
130e0eabd7f67462ac34fbfc749d897be478fbd1224Behdad Esfahbod	number_joiner_terminated_cluster	=> { found_syllable (number_joiner_terminated_cluster); };
131e0eabd7f67462ac34fbfc749d897be478fbd1224Behdad Esfahbod	numeral_cluster				=> { found_syllable (numeral_cluster); };
132e0eabd7f67462ac34fbfc749d897be478fbd1224Behdad Esfahbod	symbol_cluster				=> { found_syllable (symbol_cluster); };
13340c4a991c7ea18017273ff8993eecc3953869e69Behdad Esfahbod	broken_cluster				=> { found_syllable (broken_cluster); };
1343e4e7616a8ca80a50a438601b84428b4ba4c8694Behdad Esfahbod	other					=> { found_syllable (non_cluster); };
135e0eabd7f67462ac34fbfc749d897be478fbd1224Behdad Esfahbod*|;
136e0eabd7f67462ac34fbfc749d897be478fbd1224Behdad Esfahbod
137e0eabd7f67462ac34fbfc749d897be478fbd1224Behdad Esfahbod
138e0eabd7f67462ac34fbfc749d897be478fbd1224Behdad Esfahbod}%%
139e0eabd7f67462ac34fbfc749d897be478fbd1224Behdad Esfahbod
140e0eabd7f67462ac34fbfc749d897be478fbd1224Behdad Esfahbod#define found_syllable(syllable_type) \
141e0eabd7f67462ac34fbfc749d897be478fbd1224Behdad Esfahbod  HB_STMT_START { \
142e0eabd7f67462ac34fbfc749d897be478fbd1224Behdad Esfahbod    if (0) fprintf (stderr, "syllable %d..%d %s\n", last, p+1, #syllable_type); \
143e0eabd7f67462ac34fbfc749d897be478fbd1224Behdad Esfahbod    for (unsigned int i = last; i < p+1; i++) \
144e0eabd7f67462ac34fbfc749d897be478fbd1224Behdad Esfahbod      info[i].syllable() = (syllable_serial << 4) | syllable_type; \
145e0eabd7f67462ac34fbfc749d897be478fbd1224Behdad Esfahbod    last = p+1; \
146e0eabd7f67462ac34fbfc749d897be478fbd1224Behdad Esfahbod    syllable_serial++; \
147e0eabd7f67462ac34fbfc749d897be478fbd1224Behdad Esfahbod    if (unlikely (syllable_serial == 16)) syllable_serial = 1; \
148e0eabd7f67462ac34fbfc749d897be478fbd1224Behdad Esfahbod  } HB_STMT_END
149e0eabd7f67462ac34fbfc749d897be478fbd1224Behdad Esfahbod
150e0eabd7f67462ac34fbfc749d897be478fbd1224Behdad Esfahbodstatic void
151e0eabd7f67462ac34fbfc749d897be478fbd1224Behdad Esfahbodfind_syllables (hb_buffer_t *buffer)
152e0eabd7f67462ac34fbfc749d897be478fbd1224Behdad Esfahbod{
153e0eabd7f67462ac34fbfc749d897be478fbd1224Behdad Esfahbod  unsigned int p, pe, eof, ts HB_UNUSED, te HB_UNUSED, act HB_UNUSED;
154e0eabd7f67462ac34fbfc749d897be478fbd1224Behdad Esfahbod  int cs;
155e0eabd7f67462ac34fbfc749d897be478fbd1224Behdad Esfahbod  hb_glyph_info_t *info = buffer->info;
156e0eabd7f67462ac34fbfc749d897be478fbd1224Behdad Esfahbod  %%{
157e0eabd7f67462ac34fbfc749d897be478fbd1224Behdad Esfahbod    write init;
158e0eabd7f67462ac34fbfc749d897be478fbd1224Behdad Esfahbod    getkey info[p].use_category();
159e0eabd7f67462ac34fbfc749d897be478fbd1224Behdad Esfahbod  }%%
160e0eabd7f67462ac34fbfc749d897be478fbd1224Behdad Esfahbod
161e0eabd7f67462ac34fbfc749d897be478fbd1224Behdad Esfahbod  p = 0;
162e0eabd7f67462ac34fbfc749d897be478fbd1224Behdad Esfahbod  pe = eof = buffer->len;
163e0eabd7f67462ac34fbfc749d897be478fbd1224Behdad Esfahbod
164e0eabd7f67462ac34fbfc749d897be478fbd1224Behdad Esfahbod  unsigned int last = 0;
165e0eabd7f67462ac34fbfc749d897be478fbd1224Behdad Esfahbod  unsigned int syllable_serial = 1;
166e0eabd7f67462ac34fbfc749d897be478fbd1224Behdad Esfahbod  %%{
167e0eabd7f67462ac34fbfc749d897be478fbd1224Behdad Esfahbod    write exec;
168e0eabd7f67462ac34fbfc749d897be478fbd1224Behdad Esfahbod  }%%
169e0eabd7f67462ac34fbfc749d897be478fbd1224Behdad Esfahbod}
170e0eabd7f67462ac34fbfc749d897be478fbd1224Behdad Esfahbod
171e0eabd7f67462ac34fbfc749d897be478fbd1224Behdad Esfahbod#undef found_syllable
172e0eabd7f67462ac34fbfc749d897be478fbd1224Behdad Esfahbod
173e0eabd7f67462ac34fbfc749d897be478fbd1224Behdad Esfahbod#endif /* HB_OT_SHAPE_COMPLEX_USE_MACHINE_HH */
174