2 * Copyright © 2011 Google, Inc.
4 * This is part of HarfBuzz, a text shaping library.
6 * Permission is hereby granted, without written agreement and without
7 * license or royalty fees, to use, copy, modify, and distribute this
8 * software and its documentation for any purpose, provided that the
9 * above copyright notice and the following two paragraphs appear in
10 * all copies of this software.
12 * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR
13 * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
14 * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN
15 * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
18 * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING,
19 * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
20 * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
21 * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO
22 * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
24 * Google Author(s): Behdad Esfahbod
27 #include "hb-ot-shape-complex-private.hh"
32 /* buffer var allocations */
33 #define indic_category() var2.u8[0] /* indic_category_t */
34 #define indic_position() var2.u8[1] /* indic_matra_category_t */
36 #define INDIC_TABLE_ELEMENT_TYPE uint8_t
38 /* Cateories used in the OpenType spec:
39 * https://www.microsoft.com/typography/otfntdev/devanot/shaping.aspx
41 /* Note: This enum is duplicated in the -machine.rl source file.
42 * Not sure how to avoid duplication. */
43 enum indic_category_t {
46 OT_Ra, /* Not explicitly listed in the OT spec, but used in the grammar. */
59 /* Visual positions in a syllable from left to right. */
60 enum indic_position_t {
67 POS_INHERIT /* For Halant, Nukta, ZWJ, ZWNJ */
70 /* Categories used in IndicSyllabicCategory.txt from UCD */
71 /* The assignments are guesswork */
72 enum indic_syllabic_category_t {
73 INDIC_SYLLABIC_CATEGORY_OTHER = OT_X,
75 INDIC_SYLLABIC_CATEGORY_AVAGRAHA = OT_X,
76 INDIC_SYLLABIC_CATEGORY_BINDU = OT_SM,
77 INDIC_SYLLABIC_CATEGORY_CONSONANT = OT_C,
78 INDIC_SYLLABIC_CATEGORY_CONSONANT_DEAD = OT_C,
79 INDIC_SYLLABIC_CATEGORY_CONSONANT_FINAL = OT_C,
80 INDIC_SYLLABIC_CATEGORY_CONSONANT_HEAD_LETTER = OT_C,
81 INDIC_SYLLABIC_CATEGORY_CONSONANT_MEDIAL = OT_C,
82 INDIC_SYLLABIC_CATEGORY_CONSONANT_PLACEHOLDER = OT_NBSP,
83 INDIC_SYLLABIC_CATEGORY_CONSONANT_SUBJOINED = OT_C,
84 INDIC_SYLLABIC_CATEGORY_CONSONANT_REPHA = OT_C,
85 INDIC_SYLLABIC_CATEGORY_MODIFYING_LETTER = OT_X,
86 INDIC_SYLLABIC_CATEGORY_NUKTA = OT_N,
87 INDIC_SYLLABIC_CATEGORY_REGISTER_SHIFTER = OT_X,
88 INDIC_SYLLABIC_CATEGORY_TONE_LETTER = OT_X,
89 INDIC_SYLLABIC_CATEGORY_TONE_MARK = OT_X,
90 INDIC_SYLLABIC_CATEGORY_VIRAMA = OT_H,
91 INDIC_SYLLABIC_CATEGORY_VISARGA = OT_SM,
92 INDIC_SYLLABIC_CATEGORY_VOWEL = OT_V,
93 INDIC_SYLLABIC_CATEGORY_VOWEL_DEPENDENT = OT_M,
94 INDIC_SYLLABIC_CATEGORY_VOWEL_INDEPENDENT = OT_V
97 /* Categories used in IndicSMatraCategory.txt from UCD */
98 enum indic_matra_category_t {
99 INDIC_MATRA_CATEGORY_NOT_APPLICABLE = POS_BASE,
101 INDIC_MATRA_CATEGORY_LEFT = POS_PRE,
102 INDIC_MATRA_CATEGORY_TOP = POS_ABOVE,
103 INDIC_MATRA_CATEGORY_BOTTOM = POS_BELOW,
104 INDIC_MATRA_CATEGORY_RIGHT = POS_POST,
106 /* We don't really care much about these since we decompose them
107 * in the generic pre-shaping layer. They will only be used if
108 * the font does not cover the decomposition. In which case, we
109 * define these as aliases to the place we want the split-matra
110 * glyph to show up. Quite arbitrary. */
111 INDIC_MATRA_CATEGORY_BOTTOM_AND_RIGHT = INDIC_MATRA_CATEGORY_BOTTOM,
112 INDIC_MATRA_CATEGORY_LEFT_AND_RIGHT = INDIC_MATRA_CATEGORY_LEFT,
113 INDIC_MATRA_CATEGORY_TOP_AND_BOTTOM = INDIC_MATRA_CATEGORY_BOTTOM,
114 INDIC_MATRA_CATEGORY_TOP_AND_BOTTOM_AND_RIGHT = INDIC_MATRA_CATEGORY_BOTTOM,
115 INDIC_MATRA_CATEGORY_TOP_AND_LEFT = INDIC_MATRA_CATEGORY_LEFT,
116 INDIC_MATRA_CATEGORY_TOP_AND_LEFT_AND_RIGHT = INDIC_MATRA_CATEGORY_LEFT,
117 INDIC_MATRA_CATEGORY_TOP_AND_RIGHT = INDIC_MATRA_CATEGORY_RIGHT,
119 INDIC_MATRA_CATEGORY_INVISIBLE = INDIC_MATRA_CATEGORY_NOT_APPLICABLE,
120 INDIC_MATRA_CATEGORY_OVERSTRUCK = INDIC_MATRA_CATEGORY_NOT_APPLICABLE,
121 INDIC_MATRA_CATEGORY_VISUAL_ORDER_LEFT = INDIC_MATRA_CATEGORY_NOT_APPLICABLE
124 /* Note: We use ASSERT_STATIC_EXPR_ZERO() instead of ASSERT_STATIC_EXPR() and the comma operation
125 * because gcc fails to optimize the latter and fills the table in at runtime. */
126 #define INDIC_COMBINE_CATEGORIES(S,M) \
127 (ASSERT_STATIC_EXPR_ZERO (M == INDIC_MATRA_CATEGORY_NOT_APPLICABLE || (S == INDIC_SYLLABIC_CATEGORY_VIRAMA || S == INDIC_SYLLABIC_CATEGORY_VOWEL_DEPENDENT)) + \
128 ASSERT_STATIC_EXPR_ZERO (S < 16 && M < 16) + \
131 #include "hb-ot-shape-complex-indic-table.hh"
134 * This is a hack for now. We should:
135 * 1. Move this data into the main Indic table,
137 * 2. Probe font lookups to determine consonant positions.
139 static const struct {
141 indic_position_t position;
142 } consonant_positions[] = {
240 static const struct {
243 } indic_basic_features[] =
245 {HB_TAG('n','u','k','t'), true},
246 {HB_TAG('a','k','h','n'), false},
247 {HB_TAG('r','p','h','f'), false},
248 {HB_TAG('r','k','r','f'), false},
249 {HB_TAG('p','r','e','f'), false},
250 {HB_TAG('b','l','w','f'), false},
251 {HB_TAG('h','a','l','f'), false},
252 {HB_TAG('v','a','t','u'), true},
253 {HB_TAG('p','s','t','f'), false},
254 {HB_TAG('c','j','c','t'), true},
257 /* Same order as the indic_basic_features array */
271 static const hb_tag_t indic_other_features[] =
273 HB_TAG('p','r','e','s'),
274 HB_TAG('a','b','v','s'),
275 HB_TAG('b','l','w','s'),
276 HB_TAG('p','s','t','s'),
277 HB_TAG('h','a','l','n'),
279 HB_TAG('d','i','s','t'),
280 HB_TAG('a','b','v','m'),
281 HB_TAG('b','l','w','m'),
285 final_reordering (const hb_ot_map_t *map,
288 void *user_data HB_UNUSED)
293 _hb_ot_shape_complex_collect_features_indic (hb_ot_map_builder_t *map, const hb_segment_properties_t *props)
295 map->add_bool_feature (HB_TAG('l','o','c','l'));
296 /* The Indic specs do not require ccmp, but we apply it here since if
297 * there is a use of it, it's typically at the beginning. */
298 map->add_bool_feature (HB_TAG('c','c','m','p'));
300 map->add_gsub_pause (NULL, NULL);
302 for (unsigned int i = 0; i < ARRAY_LENGTH (indic_basic_features); i++)
303 map->add_bool_feature (indic_basic_features[i].tag, indic_basic_features[i].is_global);
305 map->add_gsub_pause (final_reordering, NULL);
307 for (unsigned int i = 0; i < ARRAY_LENGTH (indic_other_features); i++)
308 map->add_bool_feature (indic_other_features[i], true);
313 found_syllable (hb_ot_map_t *map, hb_buffer_t *buffer,
314 unsigned int start, unsigned int end)
316 //fprintf (stderr, "%d %d\n", start, end);
319 #include "hb-ot-shape-complex-indic-machine.hh"
323 _hb_ot_shape_complex_setup_masks_indic (hb_ot_map_t *map, hb_buffer_t *buffer)
325 unsigned int count = buffer->len;
327 for (unsigned int i = 0; i < count; i++)
329 unsigned int type = get_indic_categories (buffer->info[i].codepoint);
331 buffer->info[i].indic_category() = type & 0x0F;
332 buffer->info[i].indic_position() = type >> 4;
335 find_syllables (map, buffer);
337 hb_mask_t mask_array[ARRAY_LENGTH (indic_basic_features)] = {0};
338 unsigned int num_masks = ARRAY_LENGTH (indic_basic_features);
339 for (unsigned int i = 0; i < num_masks; i++)
340 mask_array[i] = map->get_1_mask (indic_basic_features[i].tag);