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
V    = 2;
N    = 3;
H    = 4;
ZWNJ = 5;
ZWJ  = 6;
M    = 7;
SM   = 8;
VD   = 9;
A    = 10;
52
PLACEHOLDER = 11;
B
Behdad Esfahbod 已提交
53
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)?;
B
Behdad Esfahbod 已提交
72
syllable_tail = (z?.SM.SM?.ZWNJ?)? A{0,3}? VD{0,2};
73
place_holder = PLACEHOLDER | DOTTEDCIRCLE;
B
Behdad Esfahbod 已提交
74
halant_group = (z?.h.(ZWJ.N?)?);
75
final_halant_group = halant_group | h.ZWNJ;
B
Behdad Esfahbod 已提交
76
medial_group = CM?.CM2?;
B
Behdad Esfahbod 已提交
77
halant_or_matra_group = (final_halant_group | (h.ZWJ)? matra_group{0,4}) (Coeng (cn|V))?;
78 79


B
Behdad Esfahbod 已提交
80 81
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);
82
standalone_cluster =	(Repha? PLACEHOLDER | reph? DOTTEDCIRCLE).n? (halant_group.cn){0,4} medial_group halant_or_matra_group syllable_tail;
B
Behdad Esfahbod 已提交
83
symbol_cluster = 	symbol syllable_tail;
B
Behdad Esfahbod 已提交
84
broken_cluster =	reph? n? (halant_group.cn){0,4} medial_group halant_or_matra_group syllable_tail;
85
other =			any;
86

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


}%%

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

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

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

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

#endif /* HB_OT_SHAPE_COMPLEX_INDIC_MACHINE_HH */