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 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 54 55 56 57
V    = 2;
N    = 3;
H    = 4;
ZWNJ = 5;
ZWJ  = 6;
M    = 7;
SM   = 8;
VD   = 9;
A    = 10;
NBSP = 11;
DOTTEDCIRCLE = 12;
RS   = 13;
Coeng = 14;
Repha = 15;
Ra    = 16;
58

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

cn = c.n?;
66
forced_rakar = ZWJ H ZWJ Ra;
67
matra_group = z{0,3}.M.N?.(H | forced_rakar)?;
68
syllable_tail =  (Coeng (cn|V))? (SM.ZWNJ?)? (VD VD?)?;
69
place_holder = NBSP | DOTTEDCIRCLE;
70 71
halant_group = (z?.h.ZWJ?);
final_halant_group = halant_group | h.ZWNJ;
72
halant_or_matra_group = (final_halant_group | matra_group{0,4});
73 74


75
consonant_syllable =	Repha? (cn.halant_group){0,4} cn A? halant_or_matra_group? syllable_tail;
76
vowel_syllable =	reph? V.n? (ZWJ | (halant_group.cn){0,4} halant_or_matra_group? syllable_tail);
77
standalone_cluster =	reph? place_holder.n? (halant_group.cn){0,4} halant_or_matra_group? syllable_tail;
78
broken_cluster =	n? (halant_group.cn){0,4} halant_or_matra_group syllable_tail;
79
other =			any;
80

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


}%%

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

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

  p = 0;
114
  pe = eof = buffer->len;
115

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

#endif /* HB_OT_SHAPE_COMPLEX_INDIC_MACHINE_HH */