hb-ot-shape-complex-indic-machine.rl revision 8c0aa486f31e9b6cbb31ce295573b53b0a214124
1/*
2 * Copyright © 2011  Google, Inc.
3 *
4 *  This is part of HarfBuzz, a text shaping library.
5 *
6 * Permission is hereby granted, without written agreement and without
7 * license or royalty fees, to use, copy, modify, and distribute this
8 * software and its documentation for any purpose, provided that the
9 * above copyright notice and the following two paragraphs appear in
10 * all copies of this software.
11 *
12 * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR
13 * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
14 * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN
15 * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
16 * DAMAGE.
17 *
18 * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING,
19 * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
20 * FITNESS FOR A PARTICULAR PURPOSE.  THE SOFTWARE PROVIDED HEREUNDER IS
21 * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO
22 * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
23 *
24 * Google Author(s): Behdad Esfahbod
25 */
26
27#ifndef HB_OT_SHAPE_COMPLEX_INDIC_MACHINE_HH
28#define HB_OT_SHAPE_COMPLEX_INDIC_MACHINE_HH
29
30#include "hb-private.hh"
31
32HB_BEGIN_DECLS
33
34%%{
35  machine indic_syllable_machine;
36  alphtype unsigned char;
37  write data;
38}%%
39
40%%{
41
42# Same order as enum indic_category_t.  Not sure how to avoid duplication.
43X    = 0;
44C    = 1;
45Ra   = 2;
46V    = 3;
47N    = 4;
48H    = 5;
49ZWNJ = 6;
50ZWJ  = 7;
51M    = 8;
52SM   = 9;
53VD   = 10;
54A    = 11;
55NBSP = 12;
56
57c = C | Ra;
58n = N N?;
59z = ZWJ|ZWNJ;
60matra_group = M N? H?;
61syllable_tail = SM? (VD VD?)?;
62
63
64consonant_syllable =	(c.n? (H.z?|z.H))* c.n? A? (H.z? | matra_group*)? syllable_tail;
65vowel_syllable =	(Ra H)? V n? (z?.H.c | ZWJ.c)? matra_group* syllable_tail;
66standalone_cluster =	(Ra H)? NBSP n? (z? H c)? matra_group* syllable_tail;
67other =			any;
68
69main := |*
70	consonant_syllable	=> { process_syllable (consonant_syllable); };
71	vowel_syllable		=> { process_syllable (vowel_syllable); };
72	standalone_cluster	=> { process_syllable (standalone_cluster); };
73	other			=> { process_syllable (non_indic); };
74*|;
75
76
77}%%
78
79#define process_syllable(func) \
80  HB_STMT_START { \
81    /* printf ("syllable %d..%d %s\n", last, p+1, #func); */ \
82    for (unsigned int i = last; i < p+1; i++) \
83      info[i].syllable() = syllable_serial; \
84    PASTE (initial_reordering_, func) (map, buffer, mask_array, last, p+1); \
85    last = p+1; \
86    syllable_serial++; \
87    if (unlikely (!syllable_serial)) syllable_serial++; \
88  } HB_STMT_END
89
90static void
91find_syllables (const hb_ot_map_t *map, hb_buffer_t *buffer, hb_mask_t *mask_array)
92{
93  unsigned int p, pe, eof, ts, te, act;
94  int cs;
95  hb_glyph_info_t *info = buffer->info;
96  %%{
97    write init;
98    getkey info[p].indic_category();
99  }%%
100
101  p = 0;
102  pe = eof = buffer->len;
103
104  unsigned int last = 0;
105  uint8_t syllable_serial = 1;
106  %%{
107    write exec;
108  }%%
109}
110
111HB_END_DECLS
112
113#endif /* HB_OT_SHAPE_COMPLEX_INDIC_MACHINE_HH */
114