hb-ot-shape-complex-indic-machine.rl 3.6 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
 *
 *  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

30
#include "hb.hh"
31 32 33 34 35 36 37 38 39

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

%%{

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

B
Behdad Esfahbod 已提交
59
c = (C | Ra);			# is_consonant
60
n = ((ZWNJ?.RS)? (N.N?)?);	# is_consonant_modifier
61
z = ZWJ|ZWNJ;			# is_joiner
B
Behdad Esfahbod 已提交
62
reph = (Ra H | Repha);		# possible reph
B
Behdad Esfahbod 已提交
63

B
Behdad Esfahbod 已提交
64
cn = c.ZWJ?.n?;
65
forced_rakar = ZWJ H ZWJ Ra;
66
symbol = Symbol.N?;
67
matra_group = z{0,3}.M.N?.(H | forced_rakar)?;
68
syllable_tail = (z?.SM.SM?.ZWNJ?)? A{0,3}?;
69 70
halant_group = (z?.H.(ZWJ.N?)?);
final_halant_group = halant_group | H.ZWNJ;
71
medial_group = CM?;
72
halant_or_matra_group = (final_halant_group | matra_group{0,4});
73 74


75
consonant_syllable =	(Repha|CS)? (cn.halant_group){0,4} cn medial_group halant_or_matra_group syllable_tail;
B
Behdad Esfahbod 已提交
76
vowel_syllable =	reph? V.n? (ZWJ | (halant_group.cn){0,4} medial_group halant_or_matra_group syllable_tail);
77
standalone_cluster =	((Repha|CS)? PLACEHOLDER | reph? DOTTEDCIRCLE).n? (halant_group.cn){0,4} medial_group halant_or_matra_group syllable_tail;
B
Behdad Esfahbod 已提交
78
symbol_cluster = 	symbol syllable_tail;
B
Behdad Esfahbod 已提交
79
broken_cluster =	reph? n? (halant_group.cn){0,4} medial_group halant_or_matra_group syllable_tail;
80
other =			any;
81

82
main := |*
83 84 85
	consonant_syllable	=> { found_syllable (consonant_syllable); };
	vowel_syllable		=> { found_syllable (vowel_syllable); };
	standalone_cluster	=> { found_syllable (standalone_cluster); };
86
	symbol_cluster		=> { found_syllable (symbol_cluster); };
87
	broken_cluster		=> { found_syllable (broken_cluster); };
88
	other			=> { found_syllable (non_indic_cluster); };
89
*|;
90 91 92 93


}%%

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

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

  p = 0;
116
  pe = eof = buffer->len;
117

118
  unsigned int last = 0;
119
  unsigned int syllable_serial = 1;
120 121 122 123 124 125
  %%{
    write exec;
  }%%
}

#endif /* HB_OT_SHAPE_COMPLEX_INDIC_MACHINE_HH */