hb-ot-shape-complex-use-machine.rl revision 40c4a991c7ea18017273ff8993eecc3953869e69
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 EsfahbodIV	= 2; # BASE_VOWEL
48e0eabd7f67462ac34fbfc749d897be478fbd1224Behdad EsfahbodIND	= 3; # BASE_IND
49e0eabd7f67462ac34fbfc749d897be478fbd1224Behdad EsfahbodN	= 4; # BASE_NUM
50e0eabd7f67462ac34fbfc749d897be478fbd1224Behdad EsfahbodGB	= 5; # BASE_OTHER
51e0eabd7f67462ac34fbfc749d897be478fbd1224Behdad EsfahbodCGJ	= 6; # CGJ
52e0eabd7f67462ac34fbfc749d897be478fbd1224Behdad Esfahbod#F	= 7; # CONS_FINAL
53e0eabd7f67462ac34fbfc749d897be478fbd1224Behdad EsfahbodFM	= 8; # CONS_FINAL_MOD
54e0eabd7f67462ac34fbfc749d897be478fbd1224Behdad Esfahbod#M	= 9; # CONS_MED
55e0eabd7f67462ac34fbfc749d897be478fbd1224Behdad Esfahbod#CM	= 10; # CONS_MOD
56e0eabd7f67462ac34fbfc749d897be478fbd1224Behdad EsfahbodSUB	= 11; # CONS_SUB
57e0eabd7f67462ac34fbfc749d897be478fbd1224Behdad EsfahbodH	= 12; # HALANT
587ce03ebe7c525919ce22d9094480847ff1b3c2b2Behdad Esfahbod
59e0eabd7f67462ac34fbfc749d897be478fbd1224Behdad EsfahbodHN	= 13; # HALANT_NUM
60e0eabd7f67462ac34fbfc749d897be478fbd1224Behdad EsfahbodZWNJ	= 14; # Zero width non-joiner
61e0eabd7f67462ac34fbfc749d897be478fbd1224Behdad EsfahbodZWJ	= 15; # Zero width joiner
62e0eabd7f67462ac34fbfc749d897be478fbd1224Behdad EsfahbodWJ	= 16; # Word joiner
63e0eabd7f67462ac34fbfc749d897be478fbd1224Behdad EsfahbodRsv	= 17; # Reserved characters
64e0eabd7f67462ac34fbfc749d897be478fbd1224Behdad EsfahbodR	= 18; # REPHA
65e0eabd7f67462ac34fbfc749d897be478fbd1224Behdad EsfahbodS	= 19; # SYM
66e0eabd7f67462ac34fbfc749d897be478fbd1224Behdad Esfahbod#SM	= 20; # SYM_MOD
67e0eabd7f67462ac34fbfc749d897be478fbd1224Behdad EsfahbodVS	= 21; # VARIATION_SELECTOR
687ce03ebe7c525919ce22d9094480847ff1b3c2b2Behdad Esfahbod#V	= 36; # VOWEL
697ce03ebe7c525919ce22d9094480847ff1b3c2b2Behdad Esfahbod#VM	= 40; # VOWEL_MOD
70e0eabd7f67462ac34fbfc749d897be478fbd1224Behdad Esfahbod
71e0eabd7f67462ac34fbfc749d897be478fbd1224Behdad EsfahbodFAbv	= 24; # CONS_FINAL_ABOVE
72e0eabd7f67462ac34fbfc749d897be478fbd1224Behdad EsfahbodFBlw	= 25; # CONS_FINAL_BELOW
73e0eabd7f67462ac34fbfc749d897be478fbd1224Behdad EsfahbodFPst	= 26; # CONS_FINAL_POST
74e0eabd7f67462ac34fbfc749d897be478fbd1224Behdad EsfahbodMAbv	= 27; # CONS_MED_ABOVE
75e0eabd7f67462ac34fbfc749d897be478fbd1224Behdad EsfahbodMBlw	= 28; # CONS_MED_BELOW
76e0eabd7f67462ac34fbfc749d897be478fbd1224Behdad EsfahbodMPst	= 29; # CONS_MED_POST
77e0eabd7f67462ac34fbfc749d897be478fbd1224Behdad EsfahbodMPre	= 30; # CONS_MED_PRE
78e0eabd7f67462ac34fbfc749d897be478fbd1224Behdad EsfahbodCMAbv	= 31; # CONS_MOD_ABOVE
79e0eabd7f67462ac34fbfc749d897be478fbd1224Behdad EsfahbodCMBlw	= 32; # CONS_MOD_BELOW
80e0eabd7f67462ac34fbfc749d897be478fbd1224Behdad EsfahbodVAbv	= 33; # VOWEL_ABOVE / VOWEL_ABOVE_BELOW / VOWEL_ABOVE_BELOW_POST / VOWEL_ABOVE_POST
81e0eabd7f67462ac34fbfc749d897be478fbd1224Behdad EsfahbodVBlw	= 34; # VOWEL_BELOW / VOWEL_BELOW_POST
82e0eabd7f67462ac34fbfc749d897be478fbd1224Behdad EsfahbodVPst	= 35; # VOWEL_POST	UIPC = Right
837ce03ebe7c525919ce22d9094480847ff1b3c2b2Behdad EsfahbodVPre	= 22; # VOWEL_PRE / VOWEL_PRE_ABOVE / VOWEL_PRE_ABOVE_POST / VOWEL_PRE_POST
84e0eabd7f67462ac34fbfc749d897be478fbd1224Behdad EsfahbodVMAbv	= 37; # VOWEL_MOD_ABOVE
85e0eabd7f67462ac34fbfc749d897be478fbd1224Behdad EsfahbodVMBlw	= 38; # VOWEL_MOD_BELOW
86e0eabd7f67462ac34fbfc749d897be478fbd1224Behdad EsfahbodVMPst	= 39; # VOWEL_MOD_POST
877ce03ebe7c525919ce22d9094480847ff1b3c2b2Behdad EsfahbodVMPre	= 23; # VOWEL_MOD_PRE
88e0eabd7f67462ac34fbfc749d897be478fbd1224Behdad EsfahbodSMAbv	= 41; # SYM_MOD_ABOVE
89e0eabd7f67462ac34fbfc749d897be478fbd1224Behdad EsfahbodSMBlw	= 42; # SYM_MOD_BELOW
90e0eabd7f67462ac34fbfc749d897be478fbd1224Behdad Esfahbod
91e0eabd7f67462ac34fbfc749d897be478fbd1224Behdad Esfahbod
92e0eabd7f67462ac34fbfc749d897be478fbd1224Behdad Esfahbodconsonant_modifiers = CMAbv* CMBlw* ((H B | SUB) VS? CMAbv? CMBlw*)*;
93e0eabd7f67462ac34fbfc749d897be478fbd1224Behdad Esfahbodmedial_consonants = MPre? MAbv? MBlw? MPst?;
94e0eabd7f67462ac34fbfc749d897be478fbd1224Behdad Esfahboddependent_vowels = VPre* VAbv* VBlw* VPst*;
95e0eabd7f67462ac34fbfc749d897be478fbd1224Behdad Esfahbodvowel_modifiers = VMPre* VMAbv* VMBlw* VMPst*;
96e0eabd7f67462ac34fbfc749d897be478fbd1224Behdad Esfahbodfinal_consonants = FAbv* FBlw* FPst* FM?;
97e0eabd7f67462ac34fbfc749d897be478fbd1224Behdad Esfahbod
98e0eabd7f67462ac34fbfc749d897be478fbd1224Behdad Esfahbodvirama_terminated_cluster =
99e0eabd7f67462ac34fbfc749d897be478fbd1224Behdad Esfahbod	R? (B | GB | IV) VS?
100e0eabd7f67462ac34fbfc749d897be478fbd1224Behdad Esfahbod	consonant_modifiers
101e0eabd7f67462ac34fbfc749d897be478fbd1224Behdad Esfahbod	H
102e0eabd7f67462ac34fbfc749d897be478fbd1224Behdad Esfahbod;
103e0eabd7f67462ac34fbfc749d897be478fbd1224Behdad Esfahbodconsonant_cluster =
104e0eabd7f67462ac34fbfc749d897be478fbd1224Behdad Esfahbod	R? (B | GB) VS?
105e0eabd7f67462ac34fbfc749d897be478fbd1224Behdad Esfahbod	consonant_modifiers
106e0eabd7f67462ac34fbfc749d897be478fbd1224Behdad Esfahbod	medial_consonants
107e0eabd7f67462ac34fbfc749d897be478fbd1224Behdad Esfahbod	dependent_vowels
108e0eabd7f67462ac34fbfc749d897be478fbd1224Behdad Esfahbod	vowel_modifiers
109e0eabd7f67462ac34fbfc749d897be478fbd1224Behdad Esfahbod	final_consonants
110e0eabd7f67462ac34fbfc749d897be478fbd1224Behdad Esfahbod;
111e0eabd7f67462ac34fbfc749d897be478fbd1224Behdad Esfahbodvowel_cluster =
112e0eabd7f67462ac34fbfc749d897be478fbd1224Behdad Esfahbod	R? (IV) VS?
113e0eabd7f67462ac34fbfc749d897be478fbd1224Behdad Esfahbod	consonant_modifiers
114e0eabd7f67462ac34fbfc749d897be478fbd1224Behdad Esfahbod	medial_consonants
115e0eabd7f67462ac34fbfc749d897be478fbd1224Behdad Esfahbod	vowel_modifiers
116e0eabd7f67462ac34fbfc749d897be478fbd1224Behdad Esfahbod	final_consonants
117e0eabd7f67462ac34fbfc749d897be478fbd1224Behdad Esfahbod;
118e0eabd7f67462ac34fbfc749d897be478fbd1224Behdad Esfahbod
11940c4a991c7ea18017273ff8993eecc3953869e69Behdad Esfahbodbroken_cluster =
12040c4a991c7ea18017273ff8993eecc3953869e69Behdad Esfahbod	R?
12140c4a991c7ea18017273ff8993eecc3953869e69Behdad Esfahbod	consonant_modifiers
12240c4a991c7ea18017273ff8993eecc3953869e69Behdad Esfahbod	medial_consonants
12340c4a991c7ea18017273ff8993eecc3953869e69Behdad Esfahbod	dependent_vowels
12440c4a991c7ea18017273ff8993eecc3953869e69Behdad Esfahbod	vowel_modifiers
12540c4a991c7ea18017273ff8993eecc3953869e69Behdad Esfahbod	final_consonants
12640c4a991c7ea18017273ff8993eecc3953869e69Behdad Esfahbod;
12740c4a991c7ea18017273ff8993eecc3953869e69Behdad Esfahbod
128eb74535cc2c0d0de41e54e75bdc71825ec969523Behdad Esfahbodnumber_joiner_terminated_cluster = N VS? (HN N VS?)* H;
129eb74535cc2c0d0de41e54e75bdc71825ec969523Behdad Esfahbodnumeral_cluster = N VS? (HN N VS?)*;
130e0eabd7f67462ac34fbfc749d897be478fbd1224Behdad Esfahbodsymbol_cluster = S VS? SMAbv* SMBlw*;
131e0eabd7f67462ac34fbfc749d897be478fbd1224Behdad Esfahbodindependent_cluster = (IND | O | Rsv | WJ) VS?;
132e0eabd7f67462ac34fbfc749d897be478fbd1224Behdad Esfahbod
133e0eabd7f67462ac34fbfc749d897be478fbd1224Behdad Esfahbodmain := |*
134e0eabd7f67462ac34fbfc749d897be478fbd1224Behdad Esfahbod	independent_cluster			=> { found_syllable (independent_cluster); };
135e0eabd7f67462ac34fbfc749d897be478fbd1224Behdad Esfahbod	virama_terminated_cluster		=> { found_syllable (virama_terminated_cluster); };
136e0eabd7f67462ac34fbfc749d897be478fbd1224Behdad Esfahbod	consonant_cluster			=> { found_syllable (consonant_cluster); };
137e0eabd7f67462ac34fbfc749d897be478fbd1224Behdad Esfahbod	vowel_cluster				=> { found_syllable (vowel_cluster); };
138e0eabd7f67462ac34fbfc749d897be478fbd1224Behdad Esfahbod	number_joiner_terminated_cluster	=> { found_syllable (number_joiner_terminated_cluster); };
139e0eabd7f67462ac34fbfc749d897be478fbd1224Behdad Esfahbod	numeral_cluster				=> { found_syllable (numeral_cluster); };
140e0eabd7f67462ac34fbfc749d897be478fbd1224Behdad Esfahbod	symbol_cluster				=> { found_syllable (symbol_cluster); };
14140c4a991c7ea18017273ff8993eecc3953869e69Behdad Esfahbod	broken_cluster				=> { found_syllable (broken_cluster); };
142e0eabd7f67462ac34fbfc749d897be478fbd1224Behdad Esfahbod*|;
143e0eabd7f67462ac34fbfc749d897be478fbd1224Behdad Esfahbod
144e0eabd7f67462ac34fbfc749d897be478fbd1224Behdad Esfahbod
145e0eabd7f67462ac34fbfc749d897be478fbd1224Behdad Esfahbod}%%
146e0eabd7f67462ac34fbfc749d897be478fbd1224Behdad Esfahbod
147e0eabd7f67462ac34fbfc749d897be478fbd1224Behdad Esfahbod#define found_syllable(syllable_type) \
148e0eabd7f67462ac34fbfc749d897be478fbd1224Behdad Esfahbod  HB_STMT_START { \
149e0eabd7f67462ac34fbfc749d897be478fbd1224Behdad Esfahbod    if (0) fprintf (stderr, "syllable %d..%d %s\n", last, p+1, #syllable_type); \
150e0eabd7f67462ac34fbfc749d897be478fbd1224Behdad Esfahbod    for (unsigned int i = last; i < p+1; i++) \
151e0eabd7f67462ac34fbfc749d897be478fbd1224Behdad Esfahbod      info[i].syllable() = (syllable_serial << 4) | syllable_type; \
152e0eabd7f67462ac34fbfc749d897be478fbd1224Behdad Esfahbod    last = p+1; \
153e0eabd7f67462ac34fbfc749d897be478fbd1224Behdad Esfahbod    syllable_serial++; \
154e0eabd7f67462ac34fbfc749d897be478fbd1224Behdad Esfahbod    if (unlikely (syllable_serial == 16)) syllable_serial = 1; \
155e0eabd7f67462ac34fbfc749d897be478fbd1224Behdad Esfahbod  } HB_STMT_END
156e0eabd7f67462ac34fbfc749d897be478fbd1224Behdad Esfahbod
157e0eabd7f67462ac34fbfc749d897be478fbd1224Behdad Esfahbodstatic void
158e0eabd7f67462ac34fbfc749d897be478fbd1224Behdad Esfahbodfind_syllables (hb_buffer_t *buffer)
159e0eabd7f67462ac34fbfc749d897be478fbd1224Behdad Esfahbod{
160e0eabd7f67462ac34fbfc749d897be478fbd1224Behdad Esfahbod  unsigned int p, pe, eof, ts HB_UNUSED, te HB_UNUSED, act HB_UNUSED;
161e0eabd7f67462ac34fbfc749d897be478fbd1224Behdad Esfahbod  int cs;
162e0eabd7f67462ac34fbfc749d897be478fbd1224Behdad Esfahbod  hb_glyph_info_t *info = buffer->info;
163e0eabd7f67462ac34fbfc749d897be478fbd1224Behdad Esfahbod  %%{
164e0eabd7f67462ac34fbfc749d897be478fbd1224Behdad Esfahbod    write init;
165e0eabd7f67462ac34fbfc749d897be478fbd1224Behdad Esfahbod    getkey info[p].use_category();
166e0eabd7f67462ac34fbfc749d897be478fbd1224Behdad Esfahbod  }%%
167e0eabd7f67462ac34fbfc749d897be478fbd1224Behdad Esfahbod
168e0eabd7f67462ac34fbfc749d897be478fbd1224Behdad Esfahbod  p = 0;
169e0eabd7f67462ac34fbfc749d897be478fbd1224Behdad Esfahbod  pe = eof = buffer->len;
170e0eabd7f67462ac34fbfc749d897be478fbd1224Behdad Esfahbod
171e0eabd7f67462ac34fbfc749d897be478fbd1224Behdad Esfahbod  unsigned int last = 0;
172e0eabd7f67462ac34fbfc749d897be478fbd1224Behdad Esfahbod  unsigned int syllable_serial = 1;
173e0eabd7f67462ac34fbfc749d897be478fbd1224Behdad Esfahbod  %%{
174e0eabd7f67462ac34fbfc749d897be478fbd1224Behdad Esfahbod    write exec;
175e0eabd7f67462ac34fbfc749d897be478fbd1224Behdad Esfahbod  }%%
176e0eabd7f67462ac34fbfc749d897be478fbd1224Behdad Esfahbod}
177e0eabd7f67462ac34fbfc749d897be478fbd1224Behdad Esfahbod
178e0eabd7f67462ac34fbfc749d897be478fbd1224Behdad Esfahbod#undef found_syllable
179e0eabd7f67462ac34fbfc749d897be478fbd1224Behdad Esfahbod
180e0eabd7f67462ac34fbfc749d897be478fbd1224Behdad Esfahbod#endif /* HB_OT_SHAPE_COMPLEX_USE_MACHINE_HH */
181