1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/gfx/harfbuzz/src/hb-ot-shape-complex-indic-machine.rl Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,131 @@ 1.4 +/* 1.5 + * Copyright © 2011,2012 Google, Inc. 1.6 + * 1.7 + * This is part of HarfBuzz, a text shaping library. 1.8 + * 1.9 + * Permission is hereby granted, without written agreement and without 1.10 + * license or royalty fees, to use, copy, modify, and distribute this 1.11 + * software and its documentation for any purpose, provided that the 1.12 + * above copyright notice and the following two paragraphs appear in 1.13 + * all copies of this software. 1.14 + * 1.15 + * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR 1.16 + * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES 1.17 + * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN 1.18 + * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH 1.19 + * DAMAGE. 1.20 + * 1.21 + * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, 1.22 + * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 1.23 + * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS 1.24 + * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO 1.25 + * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. 1.26 + * 1.27 + * Google Author(s): Behdad Esfahbod 1.28 + */ 1.29 + 1.30 +#ifndef HB_OT_SHAPE_COMPLEX_INDIC_MACHINE_HH 1.31 +#define HB_OT_SHAPE_COMPLEX_INDIC_MACHINE_HH 1.32 + 1.33 +#include "hb-private.hh" 1.34 + 1.35 +%%{ 1.36 + machine indic_syllable_machine; 1.37 + alphtype unsigned char; 1.38 + write data; 1.39 +}%% 1.40 + 1.41 +%%{ 1.42 + 1.43 +# Same order as enum indic_category_t. Not sure how to avoid duplication. 1.44 +X = 0; 1.45 +C = 1; 1.46 +V = 2; 1.47 +N = 3; 1.48 +H = 4; 1.49 +ZWNJ = 5; 1.50 +ZWJ = 6; 1.51 +M = 7; 1.52 +SM = 8; 1.53 +VD = 9; 1.54 +A = 10; 1.55 +NBSP = 11; 1.56 +DOTTEDCIRCLE = 12; 1.57 +RS = 13; 1.58 +Coeng = 14; 1.59 +Repha = 15; 1.60 +Ra = 16; 1.61 +CM = 17; 1.62 +Avag = 18; 1.63 +CM2 = 31; 1.64 + 1.65 +c = (C | Ra); # is_consonant 1.66 +n = ((ZWNJ?.RS)? (N.N?)?); # is_consonant_modifier 1.67 +z = ZWJ|ZWNJ; # is_joiner 1.68 +h = H | Coeng; # is_halant_or_coeng 1.69 +reph = (Ra H | Repha); # possible reph 1.70 + 1.71 +cn = c.ZWJ?.n?; 1.72 +forced_rakar = ZWJ H ZWJ Ra; 1.73 +avagraha = Avag.N?; 1.74 +matra_group = z{0,3}.M.N?.(H | forced_rakar)?; 1.75 +syllable_tail2 = (SM.SM?.ZWNJ?)? (A.A?)? VD?; 1.76 +syllable_tail = (Coeng (cn|V))? avagraha? syllable_tail2; 1.77 +place_holder = NBSP | DOTTEDCIRCLE; 1.78 +halant_group = (z?.h.(ZWJ.N?)?); 1.79 +final_halant_group = halant_group | h.ZWNJ; 1.80 +medial_group = CM?.CM2?; 1.81 +halant_or_matra_group = (final_halant_group | (h.ZWJ)? matra_group{0,4}); 1.82 + 1.83 + 1.84 +consonant_syllable = Repha? (cn.halant_group){0,4} cn medial_group halant_or_matra_group syllable_tail; 1.85 +vowel_syllable = reph? V.n? (ZWJ | (halant_group.cn){0,4} medial_group halant_or_matra_group syllable_tail); 1.86 +standalone_cluster = reph? place_holder.n? (halant_group.cn){0,4} medial_group halant_or_matra_group syllable_tail; 1.87 +avagraha_cluster = avagraha syllable_tail2; 1.88 +broken_cluster = reph? n? (halant_group.cn){0,4} medial_group halant_or_matra_group syllable_tail; 1.89 +other = any; 1.90 + 1.91 +main := |* 1.92 + consonant_syllable => { found_syllable (consonant_syllable); }; 1.93 + vowel_syllable => { found_syllable (vowel_syllable); }; 1.94 + standalone_cluster => { found_syllable (standalone_cluster); }; 1.95 + avagraha_cluster => { found_syllable (avagraha_cluster); }; 1.96 + broken_cluster => { found_syllable (broken_cluster); }; 1.97 + other => { found_syllable (non_indic_cluster); }; 1.98 +*|; 1.99 + 1.100 + 1.101 +}%% 1.102 + 1.103 +#define found_syllable(syllable_type) \ 1.104 + HB_STMT_START { \ 1.105 + if (0) fprintf (stderr, "syllable %d..%d %s\n", last, p+1, #syllable_type); \ 1.106 + for (unsigned int i = last; i < p+1; i++) \ 1.107 + info[i].syllable() = (syllable_serial << 4) | syllable_type; \ 1.108 + last = p+1; \ 1.109 + syllable_serial++; \ 1.110 + if (unlikely (syllable_serial == 16)) syllable_serial = 1; \ 1.111 + } HB_STMT_END 1.112 + 1.113 +static void 1.114 +find_syllables (hb_buffer_t *buffer) 1.115 +{ 1.116 + unsigned int p, pe, eof, ts HB_UNUSED, te HB_UNUSED, act HB_UNUSED; 1.117 + int cs; 1.118 + hb_glyph_info_t *info = buffer->info; 1.119 + %%{ 1.120 + write init; 1.121 + getkey info[p].indic_category(); 1.122 + }%% 1.123 + 1.124 + p = 0; 1.125 + pe = eof = buffer->len; 1.126 + 1.127 + unsigned int last = 0; 1.128 + unsigned int syllable_serial = 1; 1.129 + %%{ 1.130 + write exec; 1.131 + }%% 1.132 +} 1.133 + 1.134 +#endif /* HB_OT_SHAPE_COMPLEX_INDIC_MACHINE_HH */