• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.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
47IND	= 3; # BASE_IND
48N	= 4; # BASE_NUM
49GB	= 5; # BASE_OTHER
50CGJ	= 6; # CGJ
51#F	= 7; # CONS_FINAL
52#FM	= 8; # CONS_FINAL_MOD
53#M	= 9; # CONS_MED
54#CM	= 10; # CONS_MOD
55SUB	= 11; # CONS_SUB
56H	= 12; # HALANT
57
58HN	= 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
67#V	= 36; # VOWEL
68#VM	= 40; # VOWEL_MOD
69CS	= 43; # CONS_WITH_STACKER
70HVM	= 44; # HALANT_OR_VOWEL_MODIFIER
71Sk	= 48; # SAKOT
72
73FAbv	= 24; # CONS_FINAL_ABOVE
74FBlw	= 25; # CONS_FINAL_BELOW
75FPst	= 26; # CONS_FINAL_POST
76MAbv	= 27; # CONS_MED_ABOVE
77MBlw	= 28; # CONS_MED_BELOW
78MPst	= 29; # CONS_MED_POST
79MPre	= 30; # CONS_MED_PRE
80CMAbv	= 31; # CONS_MOD_ABOVE
81CMBlw	= 32; # CONS_MOD_BELOW
82VAbv	= 33; # VOWEL_ABOVE / VOWEL_ABOVE_BELOW / VOWEL_ABOVE_BELOW_POST / VOWEL_ABOVE_POST
83VBlw	= 34; # VOWEL_BELOW / VOWEL_BELOW_POST
84VPst	= 35; # VOWEL_POST	UIPC = Right
85VPre	= 22; # VOWEL_PRE / VOWEL_PRE_ABOVE / VOWEL_PRE_ABOVE_POST / VOWEL_PRE_POST
86VMAbv	= 37; # VOWEL_MOD_ABOVE
87VMBlw	= 38; # VOWEL_MOD_BELOW
88VMPst	= 39; # VOWEL_MOD_POST
89VMPre	= 23; # VOWEL_MOD_PRE
90SMAbv	= 41; # SYM_MOD_ABOVE
91SMBlw	= 42; # SYM_MOD_BELOW
92FMAbv	= 45; # CONS_FINAL_MOD	UIPC = Top
93FMBlw	= 46; # CONS_FINAL_MOD	UIPC = Bottom
94FMPst	= 47; # CONS_FINAL_MOD	UIPC = Not_Applicable
95
96h = H | HVM | Sk;
97
98# Override: Adhoc ZWJ placement. https://github.com/harfbuzz/harfbuzz/issues/542#issuecomment-353169729
99consonant_modifiers = CMAbv* CMBlw* ((ZWJ?.h.ZWJ? B | SUB) VS? CMAbv? CMBlw*)*;
100# Override: Allow two MBlw. https://github.com/harfbuzz/harfbuzz/issues/376
101medial_consonants = MPre? MAbv? MBlw?.MBlw? MPst?;
102dependent_vowels = VPre* VAbv* VBlw* VPst*;
103vowel_modifiers = HVM? VMPre* VMAbv* VMBlw* VMPst*;
104final_consonants = FAbv* FBlw* FPst*;
105final_modifiers = FMAbv* FMBlw* | FMPst?;
106
107complex_syllable_start = (R | CS)? (B | GB) VS?;
108complex_syllable_middle =
109	consonant_modifiers
110	medial_consonants
111	dependent_vowels
112	vowel_modifiers
113	(Sk B)*
114;
115complex_syllable_tail =
116	complex_syllable_middle
117	final_consonants
118	final_modifiers
119;
120number_joiner_terminated_cluster_tail = (HN N VS?)* HN;
121numeral_cluster_tail = (HN N VS?)+;
122symbol_cluster_tail = SMAbv+ SMBlw* | SMBlw+;
123
124virama_terminated_cluster =
125	complex_syllable_start
126	consonant_modifiers
127	ZWJ?.h.ZWJ?
128;
129sakot_terminated_cluster =
130	complex_syllable_start
131	complex_syllable_middle
132	Sk
133;
134standard_cluster =
135	complex_syllable_start
136	complex_syllable_tail
137;
138broken_cluster =
139	R?
140	(complex_syllable_tail | number_joiner_terminated_cluster_tail | numeral_cluster_tail | symbol_cluster_tail)
141;
142
143number_joiner_terminated_cluster = N VS? number_joiner_terminated_cluster_tail;
144numeral_cluster = N VS? numeral_cluster_tail?;
145symbol_cluster = (S | GB) VS? symbol_cluster_tail?;
146independent_cluster = (IND | O | Rsv | WJ) VS?;
147other = any;
148
149main := |*
150	independent_cluster			=> { found_syllable (independent_cluster); };
151	virama_terminated_cluster		=> { found_syllable (virama_terminated_cluster); };
152	sakot_terminated_cluster		=> { found_syllable (sakot_terminated_cluster); };
153	standard_cluster			=> { found_syllable (standard_cluster); };
154	number_joiner_terminated_cluster	=> { found_syllable (number_joiner_terminated_cluster); };
155	numeral_cluster				=> { found_syllable (numeral_cluster); };
156	symbol_cluster				=> { found_syllable (symbol_cluster); };
157	broken_cluster				=> { found_syllable (broken_cluster); };
158	other					=> { found_syllable (non_cluster); };
159*|;
160
161
162}%%
163
164#define found_syllable(syllable_type) \
165  HB_STMT_START { \
166    if (0) fprintf (stderr, "syllable %d..%d %s\n", ts, te, #syllable_type); \
167    for (unsigned int i = ts; i < te; i++) \
168      info[i].syllable() = (syllable_serial << 4) | use_##syllable_type; \
169    syllable_serial++; \
170    if (unlikely (syllable_serial == 16)) syllable_serial = 1; \
171  } HB_STMT_END
172
173static void
174find_syllables_use (hb_buffer_t *buffer)
175{
176  unsigned int p, pe, eof, ts, te, act;
177  int cs;
178  hb_glyph_info_t *info = buffer->info;
179  %%{
180    write init;
181    getkey info[p].use_category();
182  }%%
183
184  p = 0;
185  pe = eof = buffer->len;
186
187  unsigned int syllable_serial = 1;
188  %%{
189    write exec;
190  }%%
191}
192
193#undef found_syllable
194
195#endif /* HB_OT_SHAPE_COMPLEX_USE_MACHINE_HH */
196