hb-ot-shape-complex-indic-machine.rl 2.8 KB
Newer Older
1 2 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 40 41
/*
 * Copyright © 2011  Google, Inc.
 *
 *  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"

HB_BEGIN_DECLS

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

%%{

42
# Same order as enum indic_category_t.  Not sure how to avoid duplication.
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
X    = 0;
C    = 1;
Ra   = 2;
V    = 3;
N    = 4;
H    = 5;
ZWNJ = 6;
ZWJ  = 7;
M    = 8;
SM   = 9;
VD   = 10;
A    = 11;
NBSP = 12;

c = C | Ra;
z = ZWJ|ZWNJ;
matra_group = M N? H?;
syllable_tail = SM? (VD VD?)?;

B
Behdad Esfahbod 已提交
62 63 64 65 66
action found_consonant_syllable { found_consonant_syllable (map, buffer, mask_array, last, p); }
action found_vowel_syllable { found_vowel_syllable (map, buffer, mask_array, last, p); }
action found_standalone_cluster { found_standalone_cluster (map, buffer, mask_array, last, p); }
action found_non_indic { found_non_indic (map, buffer, mask_array, last, p); }

67
action next_syllable { buffer->merge_clusters (last, p); last = p; }
68

69
consonant_syllable =	(c.N? (H.z?|z.H))* c.N? A? (H.z? | matra_group*)? syllable_tail %(found_consonant_syllable);
70
vowel_syllable =	(Ra H)? V N? (z?.H.c | ZWJ.c)? matra_group* syllable_tail %(found_vowel_syllable);
B
Behdad Esfahbod 已提交
71 72
standalone_cluster =	(Ra H)? NBSP N? (z? H c)? matra_group* syllable_tail %(found_standalone_cluster);
non_indic = X %(found_non_indic);
73 74 75 76 77 78 79 80

syllable =
	  consonant_syllable
	| vowel_syllable
	| standalone_cluster
	| non_indic
	;

B
Behdad Esfahbod 已提交
81
main := (syllable %(next_syllable))**;
82 83 84 85 86

}%%


static void
B
Behdad Esfahbod 已提交
87
find_syllables (const hb_ot_map_t *map, hb_buffer_t *buffer, hb_mask_t *mask_array)
88 89 90 91 92
{
  unsigned int p, pe, eof;
  int cs;
  %%{
    write init;
93
    getkey buffer->info[p].indic_category();
94 95 96
  }%%

  p = 0;
97
  pe = eof = buffer->len;
98

99
  unsigned int last = 0;
100 101 102 103 104 105 106 107
  %%{
    write exec;
  }%%
}

HB_END_DECLS

#endif /* HB_OT_SHAPE_COMPLEX_INDIC_MACHINE_HH */