blob: 11fb47020acff8c760447524110c855fd9426d31 [file] [log] [blame]
Behdad Esfahbode0eabd72015-07-20 13:30:51 +01001/*
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
44O = 0; # OTHER
45
46B = 1; # BASE
Behdad Esfahbode0eabd72015-07-20 13:30:51 +010047IND = 3; # BASE_IND
48N = 4; # BASE_NUM
49GB = 5; # BASE_OTHER
50CGJ = 6; # CGJ
51#F = 7; # CONS_FINAL
52FM = 8; # CONS_FINAL_MOD
53#M = 9; # CONS_MED
54#CM = 10; # CONS_MOD
55SUB = 11; # CONS_SUB
56H = 12; # HALANT
Behdad Esfahbod7ce03eb2015-07-21 16:55:26 +010057
Behdad Esfahbode0eabd72015-07-20 13:30:51 +010058HN = 13; # HALANT_NUM
59ZWNJ = 14; # Zero width non-joiner
60ZWJ = 15; # Zero width joiner
61WJ = 16; # Word joiner
62Rsv = 17; # Reserved characters
63R = 18; # REPHA
64S = 19; # SYM
65#SM = 20; # SYM_MOD
66VS = 21; # VARIATION_SELECTOR
Behdad Esfahbod7ce03eb2015-07-21 16:55:26 +010067#V = 36; # VOWEL
68#VM = 40; # VOWEL_MOD
Behdad Esfahbode0eabd72015-07-20 13:30:51 +010069
70FAbv = 24; # CONS_FINAL_ABOVE
71FBlw = 25; # CONS_FINAL_BELOW
72FPst = 26; # CONS_FINAL_POST
73MAbv = 27; # CONS_MED_ABOVE
74MBlw = 28; # CONS_MED_BELOW
75MPst = 29; # CONS_MED_POST
76MPre = 30; # CONS_MED_PRE
77CMAbv = 31; # CONS_MOD_ABOVE
78CMBlw = 32; # CONS_MOD_BELOW
79VAbv = 33; # VOWEL_ABOVE / VOWEL_ABOVE_BELOW / VOWEL_ABOVE_BELOW_POST / VOWEL_ABOVE_POST
80VBlw = 34; # VOWEL_BELOW / VOWEL_BELOW_POST
81VPst = 35; # VOWEL_POST UIPC = Right
Behdad Esfahbod7ce03eb2015-07-21 16:55:26 +010082VPre = 22; # VOWEL_PRE / VOWEL_PRE_ABOVE / VOWEL_PRE_ABOVE_POST / VOWEL_PRE_POST
Behdad Esfahbode0eabd72015-07-20 13:30:51 +010083VMAbv = 37; # VOWEL_MOD_ABOVE
84VMBlw = 38; # VOWEL_MOD_BELOW
85VMPst = 39; # VOWEL_MOD_POST
Behdad Esfahbod7ce03eb2015-07-21 16:55:26 +010086VMPre = 23; # VOWEL_MOD_PRE
Behdad Esfahbode0eabd72015-07-20 13:30:51 +010087SMAbv = 41; # SYM_MOD_ABOVE
88SMBlw = 42; # SYM_MOD_BELOW
Behdad Esfahbode07669f2017-10-03 14:57:14 +020089CS = 43; # CONS_WITH_STACKER
Behdad Esfahbode0eabd72015-07-20 13:30:51 +010090
91
Behdad Esfahbod72ecaae2017-12-24 16:05:07 -050092# Override: Adjoc ZWJ placement. https://github.com/harfbuzz/harfbuzz/issues/542#issuecomment-353169729
93consonant_modifiers = CMAbv* CMBlw* ((ZWJ?.H.ZWJ? B | SUB) VS? CMAbv? CMBlw*)*;
ebraminio7c6937e2017-11-20 14:49:22 -050094# Override: Allow two MBlw. https://github.com/harfbuzz/harfbuzz/issues/376
Behdad Esfahbod9dd29c62017-07-14 17:01:27 +010095medial_consonants = MPre? MAbv? MBlw?.MBlw? MPst?;
Behdad Esfahbode0eabd72015-07-20 13:30:51 +010096dependent_vowels = VPre* VAbv* VBlw* VPst*;
97vowel_modifiers = VMPre* VMAbv* VMBlw* VMPst*;
98final_consonants = FAbv* FBlw* FPst* FM?;
99
100virama_terminated_cluster =
Behdad Esfahbode07669f2017-10-03 14:57:14 +0200101 (R|CS)? (B | GB) VS?
Behdad Esfahbode0eabd72015-07-20 13:30:51 +0100102 consonant_modifiers
punchcutterc6dbf6e2018-01-31 14:09:04 -0800103 ZWJ?.H.ZWJ?
Behdad Esfahbode0eabd72015-07-20 13:30:51 +0100104;
Behdad Esfahbod9b6312f2016-05-06 17:41:49 +0100105standard_cluster =
Behdad Esfahbode07669f2017-10-03 14:57:14 +0200106 (R|CS)? (B | GB) VS?
Behdad Esfahbode0eabd72015-07-20 13:30:51 +0100107 consonant_modifiers
108 medial_consonants
109 dependent_vowels
110 vowel_modifiers
111 final_consonants
112;
Behdad Esfahbode0eabd72015-07-20 13:30:51 +0100113
Behdad Esfahbod40c4a992015-07-21 17:14:54 +0100114broken_cluster =
115 R?
116 consonant_modifiers
117 medial_consonants
118 dependent_vowels
119 vowel_modifiers
120 final_consonants
121;
122
Behdad Esfahbodd04e4612016-05-06 17:17:00 +0100123number_joiner_terminated_cluster = N VS? (HN N VS?)* HN;
Behdad Esfahbodeb745352015-07-20 15:33:25 +0100124numeral_cluster = N VS? (HN N VS?)*;
Behdad Esfahbode0eabd72015-07-20 13:30:51 +0100125symbol_cluster = S VS? SMAbv* SMBlw*;
126independent_cluster = (IND | O | Rsv | WJ) VS?;
Behdad Esfahbod3e4e7612016-05-06 17:28:25 +0100127other = any;
Behdad Esfahbode0eabd72015-07-20 13:30:51 +0100128
129main := |*
130 independent_cluster => { found_syllable (independent_cluster); };
131 virama_terminated_cluster => { found_syllable (virama_terminated_cluster); };
Behdad Esfahbod9b6312f2016-05-06 17:41:49 +0100132 standard_cluster => { found_syllable (standard_cluster); };
Behdad Esfahbode0eabd72015-07-20 13:30:51 +0100133 number_joiner_terminated_cluster => { found_syllable (number_joiner_terminated_cluster); };
134 numeral_cluster => { found_syllable (numeral_cluster); };
135 symbol_cluster => { found_syllable (symbol_cluster); };
Behdad Esfahbod40c4a992015-07-21 17:14:54 +0100136 broken_cluster => { found_syllable (broken_cluster); };
Behdad Esfahbod3e4e7612016-05-06 17:28:25 +0100137 other => { found_syllable (non_cluster); };
Behdad Esfahbode0eabd72015-07-20 13:30:51 +0100138*|;
139
140
141}%%
142
143#define found_syllable(syllable_type) \
144 HB_STMT_START { \
145 if (0) fprintf (stderr, "syllable %d..%d %s\n", last, p+1, #syllable_type); \
146 for (unsigned int i = last; i < p+1; i++) \
147 info[i].syllable() = (syllable_serial << 4) | syllable_type; \
148 last = p+1; \
149 syllable_serial++; \
150 if (unlikely (syllable_serial == 16)) syllable_serial = 1; \
151 } HB_STMT_END
152
153static void
154find_syllables (hb_buffer_t *buffer)
155{
156 unsigned int p, pe, eof, ts HB_UNUSED, te HB_UNUSED, act HB_UNUSED;
157 int cs;
158 hb_glyph_info_t *info = buffer->info;
159 %%{
160 write init;
161 getkey info[p].use_category();
162 }%%
163
164 p = 0;
165 pe = eof = buffer->len;
166
167 unsigned int last = 0;
168 unsigned int syllable_serial = 1;
169 %%{
170 write exec;
171 }%%
172}
173
174#undef found_syllable
175
176#endif /* HB_OT_SHAPE_COMPLEX_USE_MACHINE_HH */