hb-ot-shape-complex-indic-machine.rl 3.8 KB
Newer Older
1
/*
B
Minor  
Behdad Esfahbod 已提交
2
 * Copyright © 2011,2012  Google, Inc.
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
 *
 *  This is part of HarfBuzz, a text shaping library.
 *
 * Permission is hereby granted, without written agreement and without
 * license or royalty fees, to use, copy, modify, and distribute this
 * software and its documentation for any purpose, provided that the
 * above copyright notice and the following two paragraphs appear in
 * all copies of this software.
 *
 * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR
 * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
 * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN
 * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
 * DAMAGE.
 *
 * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING,
 * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
 * FITNESS FOR A PARTICULAR PURPOSE.  THE SOFTWARE PROVIDED HEREUNDER IS
 * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO
 * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
 *
 * Google Author(s): Behdad Esfahbod
 */

#ifndef HB_OT_SHAPE_COMPLEX_INDIC_MACHINE_HH
#define HB_OT_SHAPE_COMPLEX_INDIC_MACHINE_HH

#include "hb-private.hh"

%%{
  machine indic_syllable_machine;
  alphtype unsigned char;
  write data;
}%%

%%{

40
# Same order as enum indic_category_t.  Not sure how to avoid duplication.
41 42
X    = 0;
C    = 1;
B
Behdad Esfahbod 已提交
43 44 45 46 47 48 49 50 51 52 53
V    = 2;
N    = 3;
H    = 4;
ZWNJ = 5;
ZWJ  = 6;
M    = 7;
SM   = 8;
VD   = 9;
A    = 10;
NBSP = 11;
DOTTEDCIRCLE = 12;
B
Behdad Esfahbod 已提交
54
RS    = 13;
B
Behdad Esfahbod 已提交
55 56 57
Coeng = 14;
Repha = 15;
Ra    = 16;
58
CM    = 17;
59
Symbol= 18;
B
Behdad Esfahbod 已提交
60
CM2   = 31;
61

B
Behdad Esfahbod 已提交
62
c = (C | Ra);			# is_consonant
63
n = ((ZWNJ?.RS)? (N.N?)?);	# is_consonant_modifier
64 65
z = ZWJ|ZWNJ;			# is_joiner
h = H | Coeng;			# is_halant_or_coeng
B
Behdad Esfahbod 已提交
66
reph = (Ra H | Repha);		# possible reph
B
Behdad Esfahbod 已提交
67

B
Behdad Esfahbod 已提交
68
cn = c.ZWJ?.n?;
69
forced_rakar = ZWJ H ZWJ Ra;
70
symbol = Symbol.N?;
71
matra_group = z{0,3}.M.N?.(H | forced_rakar)?;
72
syllable_tail2 = (SM.SM?.ZWNJ?)? A{0,3}? VD{0,2};
73
syllable_tail =  (Coeng (cn|V))? symbol? syllable_tail2;
74
place_holder = NBSP | DOTTEDCIRCLE;
B
Behdad Esfahbod 已提交
75
halant_group = (z?.h.(ZWJ.N?)?);
76
final_halant_group = halant_group | h.ZWNJ;
B
Behdad Esfahbod 已提交
77 78
medial_group = CM?.CM2?;
halant_or_matra_group = (final_halant_group | (h.ZWJ)? matra_group{0,4});
79 80


B
Behdad Esfahbod 已提交
81 82 83
consonant_syllable =	Repha? (cn.halant_group){0,4} cn medial_group halant_or_matra_group syllable_tail;
vowel_syllable =	reph? V.n? (ZWJ | (halant_group.cn){0,4} medial_group halant_or_matra_group syllable_tail);
standalone_cluster =	reph? place_holder.n? (halant_group.cn){0,4} medial_group halant_or_matra_group syllable_tail;
84
symbol_cluster = 	symbol syllable_tail2;
B
Behdad Esfahbod 已提交
85
broken_cluster =	reph? n? (halant_group.cn){0,4} medial_group halant_or_matra_group syllable_tail;
86
other =			any;
87

88
main := |*
89 90 91
	consonant_syllable	=> { found_syllable (consonant_syllable); };
	vowel_syllable		=> { found_syllable (vowel_syllable); };
	standalone_cluster	=> { found_syllable (standalone_cluster); };
92
	symbol_cluster		=> { found_syllable (symbol_cluster); };
93
	broken_cluster		=> { found_syllable (broken_cluster); };
94
	other			=> { found_syllable (non_indic_cluster); };
95
*|;
96 97 98 99


}%%

100
#define found_syllable(syllable_type) \
101
  HB_STMT_START { \
102
    if (0) fprintf (stderr, "syllable %d..%d %s\n", last, p+1, #syllable_type); \
103
    for (unsigned int i = last; i < p+1; i++) \
104
      info[i].syllable() = (syllable_serial << 4) | syllable_type; \
105 106
    last = p+1; \
    syllable_serial++; \
107
    if (unlikely (syllable_serial == 16)) syllable_serial = 1; \
108
  } HB_STMT_END
109 110

static void
111
find_syllables (hb_buffer_t *buffer)
112
{
113
  unsigned int p, pe, eof, ts HB_UNUSED, te HB_UNUSED, act HB_UNUSED;
114
  int cs;
115
  hb_glyph_info_t *info = buffer->info;
116 117
  %%{
    write init;
118
    getkey info[p].indic_category();
119 120 121
  }%%

  p = 0;
122
  pe = eof = buffer->len;
123

124
  unsigned int last = 0;
125
  unsigned int syllable_serial = 1;
126 127 128 129 130 131
  %%{
    write exec;
  }%%
}

#endif /* HB_OT_SHAPE_COMPLEX_INDIC_MACHINE_HH */