hb-ot-shape-complex-indic.cc revision 20503ccd578c9983162857954e3236413469ed35
1b9ddbd55930228422e82b34a141ad1b6093f5376Behdad Esfahbod/*
220503ccd578c9983162857954e3236413469ed35Behdad Esfahbod * Copyright © 2011  Google, Inc.
3b9ddbd55930228422e82b34a141ad1b6093f5376Behdad Esfahbod *
4b9ddbd55930228422e82b34a141ad1b6093f5376Behdad Esfahbod *  This is part of HarfBuzz, a text shaping library.
5b9ddbd55930228422e82b34a141ad1b6093f5376Behdad Esfahbod *
6b9ddbd55930228422e82b34a141ad1b6093f5376Behdad Esfahbod * Permission is hereby granted, without written agreement and without
7b9ddbd55930228422e82b34a141ad1b6093f5376Behdad Esfahbod * license or royalty fees, to use, copy, modify, and distribute this
8b9ddbd55930228422e82b34a141ad1b6093f5376Behdad Esfahbod * software and its documentation for any purpose, provided that the
9b9ddbd55930228422e82b34a141ad1b6093f5376Behdad Esfahbod * above copyright notice and the following two paragraphs appear in
10b9ddbd55930228422e82b34a141ad1b6093f5376Behdad Esfahbod * all copies of this software.
11b9ddbd55930228422e82b34a141ad1b6093f5376Behdad Esfahbod *
12b9ddbd55930228422e82b34a141ad1b6093f5376Behdad Esfahbod * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR
13b9ddbd55930228422e82b34a141ad1b6093f5376Behdad Esfahbod * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
14b9ddbd55930228422e82b34a141ad1b6093f5376Behdad Esfahbod * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN
15b9ddbd55930228422e82b34a141ad1b6093f5376Behdad Esfahbod * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
16b9ddbd55930228422e82b34a141ad1b6093f5376Behdad Esfahbod * DAMAGE.
17b9ddbd55930228422e82b34a141ad1b6093f5376Behdad Esfahbod *
18b9ddbd55930228422e82b34a141ad1b6093f5376Behdad Esfahbod * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING,
19b9ddbd55930228422e82b34a141ad1b6093f5376Behdad Esfahbod * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
20b9ddbd55930228422e82b34a141ad1b6093f5376Behdad Esfahbod * FITNESS FOR A PARTICULAR PURPOSE.  THE SOFTWARE PROVIDED HEREUNDER IS
21b9ddbd55930228422e82b34a141ad1b6093f5376Behdad Esfahbod * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO
22b9ddbd55930228422e82b34a141ad1b6093f5376Behdad Esfahbod * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
23b9ddbd55930228422e82b34a141ad1b6093f5376Behdad Esfahbod *
24b9ddbd55930228422e82b34a141ad1b6093f5376Behdad Esfahbod * Google Author(s): Behdad Esfahbod
25b9ddbd55930228422e82b34a141ad1b6093f5376Behdad Esfahbod */
26b9ddbd55930228422e82b34a141ad1b6093f5376Behdad Esfahbod
27b9ddbd55930228422e82b34a141ad1b6093f5376Behdad Esfahbod#include "hb-ot-shape-complex-private.hh"
28b9ddbd55930228422e82b34a141ad1b6093f5376Behdad Esfahbod
29b9ddbd55930228422e82b34a141ad1b6093f5376Behdad EsfahbodHB_BEGIN_DECLS
30b9ddbd55930228422e82b34a141ad1b6093f5376Behdad Esfahbod
31b9ddbd55930228422e82b34a141ad1b6093f5376Behdad Esfahbod
32b9ddbd55930228422e82b34a141ad1b6093f5376Behdad Esfahbod/* buffer var allocations */
33b9ddbd55930228422e82b34a141ad1b6093f5376Behdad Esfahbod#define indic_categories() var2.u32 /* indic shaping action */
34b9ddbd55930228422e82b34a141ad1b6093f5376Behdad Esfahbod
35b9ddbd55930228422e82b34a141ad1b6093f5376Behdad Esfahbod#define INDIC_TABLE_ELEMENT_TYPE uint8_t
36b9ddbd55930228422e82b34a141ad1b6093f5376Behdad Esfahbod
3720503ccd578c9983162857954e3236413469ed35Behdad Esfahbod/* Cateories used in the OpenType spec:
3820503ccd578c9983162857954e3236413469ed35Behdad Esfahbod * https://www.microsoft.com/typography/otfntdev/devanot/shaping.aspx
3920503ccd578c9983162857954e3236413469ed35Behdad Esfahbod */
4020503ccd578c9983162857954e3236413469ed35Behdad Esfahbodenum {
4120503ccd578c9983162857954e3236413469ed35Behdad Esfahbod  OT_X = 0,
4220503ccd578c9983162857954e3236413469ed35Behdad Esfahbod  OT_C,
4320503ccd578c9983162857954e3236413469ed35Behdad Esfahbod  OT_V,
4420503ccd578c9983162857954e3236413469ed35Behdad Esfahbod  OT_N,
4520503ccd578c9983162857954e3236413469ed35Behdad Esfahbod  OT_H,
4620503ccd578c9983162857954e3236413469ed35Behdad Esfahbod  OT_ZWNJ,
4720503ccd578c9983162857954e3236413469ed35Behdad Esfahbod  OT_ZWJ,
4820503ccd578c9983162857954e3236413469ed35Behdad Esfahbod  OT_M,
4920503ccd578c9983162857954e3236413469ed35Behdad Esfahbod  OT_SM,
5020503ccd578c9983162857954e3236413469ed35Behdad Esfahbod  OT_VD,
5120503ccd578c9983162857954e3236413469ed35Behdad Esfahbod  OT_A,
5220503ccd578c9983162857954e3236413469ed35Behdad Esfahbod  OT_NBSP,
5320503ccd578c9983162857954e3236413469ed35Behdad Esfahbod};
5420503ccd578c9983162857954e3236413469ed35Behdad Esfahbod
5520503ccd578c9983162857954e3236413469ed35Behdad Esfahbod/* Categories used in IndicSyllabicCategory.txt from UCD */
5620503ccd578c9983162857954e3236413469ed35Behdad Esfahbod/* The assignments are guesswork */
57b9ddbd55930228422e82b34a141ad1b6093f5376Behdad Esfahbodenum indic_syllabic_category_t {
5820503ccd578c9983162857954e3236413469ed35Behdad Esfahbod  INDIC_SYLLABIC_CATEGORY_OTHER			= OT_X,
5920503ccd578c9983162857954e3236413469ed35Behdad Esfahbod
6020503ccd578c9983162857954e3236413469ed35Behdad Esfahbod  INDIC_SYLLABIC_CATEGORY_AVAGRAHA		= OT_SM,
6120503ccd578c9983162857954e3236413469ed35Behdad Esfahbod  INDIC_SYLLABIC_CATEGORY_BINDU			= OT_SM,
6220503ccd578c9983162857954e3236413469ed35Behdad Esfahbod  INDIC_SYLLABIC_CATEGORY_CONSONANT		= OT_C,
6320503ccd578c9983162857954e3236413469ed35Behdad Esfahbod  INDIC_SYLLABIC_CATEGORY_CONSONANT_DEAD	= OT_C,
6420503ccd578c9983162857954e3236413469ed35Behdad Esfahbod  INDIC_SYLLABIC_CATEGORY_CONSONANT_FINAL	= OT_C,
6520503ccd578c9983162857954e3236413469ed35Behdad Esfahbod  INDIC_SYLLABIC_CATEGORY_CONSONANT_HEAD_LETTER	= OT_C,
6620503ccd578c9983162857954e3236413469ed35Behdad Esfahbod  INDIC_SYLLABIC_CATEGORY_CONSONANT_MEDIAL	= OT_C,
6720503ccd578c9983162857954e3236413469ed35Behdad Esfahbod  INDIC_SYLLABIC_CATEGORY_CONSONANT_PLACEHOLDER	= OT_NBSP,
6820503ccd578c9983162857954e3236413469ed35Behdad Esfahbod  INDIC_SYLLABIC_CATEGORY_CONSONANT_SUBJOINED	= OT_C,
6920503ccd578c9983162857954e3236413469ed35Behdad Esfahbod  INDIC_SYLLABIC_CATEGORY_CONSONANT_REPHA	= OT_C,
7020503ccd578c9983162857954e3236413469ed35Behdad Esfahbod  INDIC_SYLLABIC_CATEGORY_MODIFYING_LETTER	= OT_SM,
7120503ccd578c9983162857954e3236413469ed35Behdad Esfahbod  INDIC_SYLLABIC_CATEGORY_NUKTA			= OT_N,
7220503ccd578c9983162857954e3236413469ed35Behdad Esfahbod  INDIC_SYLLABIC_CATEGORY_REGISTER_SHIFTER	= OT_SM,
7320503ccd578c9983162857954e3236413469ed35Behdad Esfahbod  INDIC_SYLLABIC_CATEGORY_TONE_LETTER		= OT_V,
7420503ccd578c9983162857954e3236413469ed35Behdad Esfahbod  INDIC_SYLLABIC_CATEGORY_TONE_MARK		= OT_M,
7520503ccd578c9983162857954e3236413469ed35Behdad Esfahbod  INDIC_SYLLABIC_CATEGORY_VIRAMA		= OT_H,
7620503ccd578c9983162857954e3236413469ed35Behdad Esfahbod  INDIC_SYLLABIC_CATEGORY_VISARGA		= OT_SM,
7720503ccd578c9983162857954e3236413469ed35Behdad Esfahbod  INDIC_SYLLABIC_CATEGORY_VOWEL			= OT_V,
7820503ccd578c9983162857954e3236413469ed35Behdad Esfahbod  INDIC_SYLLABIC_CATEGORY_VOWEL_DEPENDENT	= OT_M,
7920503ccd578c9983162857954e3236413469ed35Behdad Esfahbod  INDIC_SYLLABIC_CATEGORY_VOWEL_INDEPENDENT	= OT_V,
80b9ddbd55930228422e82b34a141ad1b6093f5376Behdad Esfahbod};
81b9ddbd55930228422e82b34a141ad1b6093f5376Behdad Esfahbod
8220503ccd578c9983162857954e3236413469ed35Behdad Esfahbod/* Categories used in IndicSMatraCategory.txt from UCD */
83b9ddbd55930228422e82b34a141ad1b6093f5376Behdad Esfahbodenum indic_matra_category_t {
8420503ccd578c9983162857954e3236413469ed35Behdad Esfahbod  INDIC_MATRA_CATEGORY_NOT_APPLICABLE		= 0,
8520503ccd578c9983162857954e3236413469ed35Behdad Esfahbod
86b9ddbd55930228422e82b34a141ad1b6093f5376Behdad Esfahbod  INDIC_MATRA_CATEGORY_BOTTOM,
87b9ddbd55930228422e82b34a141ad1b6093f5376Behdad Esfahbod  INDIC_MATRA_CATEGORY_BOTTOM_AND_RIGHT,
88b9ddbd55930228422e82b34a141ad1b6093f5376Behdad Esfahbod  INDIC_MATRA_CATEGORY_INVISIBLE,
89b9ddbd55930228422e82b34a141ad1b6093f5376Behdad Esfahbod  INDIC_MATRA_CATEGORY_LEFT,
90b9ddbd55930228422e82b34a141ad1b6093f5376Behdad Esfahbod  INDIC_MATRA_CATEGORY_LEFT_AND_RIGHT,
91b9ddbd55930228422e82b34a141ad1b6093f5376Behdad Esfahbod  INDIC_MATRA_CATEGORY_OVERSTRUCK,
92b9ddbd55930228422e82b34a141ad1b6093f5376Behdad Esfahbod  INDIC_MATRA_CATEGORY_RIGHT,
93b9ddbd55930228422e82b34a141ad1b6093f5376Behdad Esfahbod  INDIC_MATRA_CATEGORY_TOP,
94b9ddbd55930228422e82b34a141ad1b6093f5376Behdad Esfahbod  INDIC_MATRA_CATEGORY_TOP_AND_BOTTOM,
95b9ddbd55930228422e82b34a141ad1b6093f5376Behdad Esfahbod  INDIC_MATRA_CATEGORY_TOP_AND_BOTTOM_AND_RIGHT,
96b9ddbd55930228422e82b34a141ad1b6093f5376Behdad Esfahbod  INDIC_MATRA_CATEGORY_TOP_AND_LEFT,
97b9ddbd55930228422e82b34a141ad1b6093f5376Behdad Esfahbod  INDIC_MATRA_CATEGORY_TOP_AND_LEFT_AND_RIGHT,
98b9ddbd55930228422e82b34a141ad1b6093f5376Behdad Esfahbod  INDIC_MATRA_CATEGORY_TOP_AND_RIGHT,
99b9ddbd55930228422e82b34a141ad1b6093f5376Behdad Esfahbod  INDIC_MATRA_CATEGORY_VISUAL_ORDER_LEFT,
100b9ddbd55930228422e82b34a141ad1b6093f5376Behdad Esfahbod};
101b9ddbd55930228422e82b34a141ad1b6093f5376Behdad Esfahbod
10220503ccd578c9983162857954e3236413469ed35Behdad Esfahbod#define INDIC_COMBINE_CATEGORIES(S,M) \
10320503ccd578c9983162857954e3236413469ed35Behdad Esfahbod  (ASSERT_STATIC_EXPR (M == INDIC_MATRA_CATEGORY_NOT_APPLICABLE || (S == INDIC_SYLLABIC_CATEGORY_VIRAMA || S == INDIC_SYLLABIC_CATEGORY_VOWEL_DEPENDENT)), \
10420503ccd578c9983162857954e3236413469ed35Behdad Esfahbod   ASSERT_STATIC_EXPR (S < 16 && M < 16), \
10520503ccd578c9983162857954e3236413469ed35Behdad Esfahbod   (M << 4) | S)
106b9ddbd55930228422e82b34a141ad1b6093f5376Behdad Esfahbod
107b9ddbd55930228422e82b34a141ad1b6093f5376Behdad Esfahbod#include "hb-ot-shape-complex-indic-table.hh"
108b9ddbd55930228422e82b34a141ad1b6093f5376Behdad Esfahbod
109b9ddbd55930228422e82b34a141ad1b6093f5376Behdad Esfahbodstatic const hb_tag_t indic_basic_features[] =
110b9ddbd55930228422e82b34a141ad1b6093f5376Behdad Esfahbod{
111b9ddbd55930228422e82b34a141ad1b6093f5376Behdad Esfahbod  HB_TAG('n','u','k','t'),
112b9ddbd55930228422e82b34a141ad1b6093f5376Behdad Esfahbod  HB_TAG('a','k','h','n'),
113b9ddbd55930228422e82b34a141ad1b6093f5376Behdad Esfahbod  HB_TAG('r','p','h','f'),
114b9ddbd55930228422e82b34a141ad1b6093f5376Behdad Esfahbod  HB_TAG('r','k','r','f'),
115b9ddbd55930228422e82b34a141ad1b6093f5376Behdad Esfahbod  HB_TAG('p','r','e','f'),
116b9ddbd55930228422e82b34a141ad1b6093f5376Behdad Esfahbod  HB_TAG('b','l','w','f'),
117b9ddbd55930228422e82b34a141ad1b6093f5376Behdad Esfahbod  HB_TAG('h','a','l','f'),
118b9ddbd55930228422e82b34a141ad1b6093f5376Behdad Esfahbod  HB_TAG('v','a','t','u'),
119b9ddbd55930228422e82b34a141ad1b6093f5376Behdad Esfahbod  HB_TAG('p','s','t','f'),
120b9ddbd55930228422e82b34a141ad1b6093f5376Behdad Esfahbod  HB_TAG('c','j','c','t'),
121b9ddbd55930228422e82b34a141ad1b6093f5376Behdad Esfahbod};
122b9ddbd55930228422e82b34a141ad1b6093f5376Behdad Esfahbod
123b9ddbd55930228422e82b34a141ad1b6093f5376Behdad Esfahbodstatic const hb_tag_t indic_other_features[] =
124b9ddbd55930228422e82b34a141ad1b6093f5376Behdad Esfahbod{
125b9ddbd55930228422e82b34a141ad1b6093f5376Behdad Esfahbod  HB_TAG('p','r','e','s'),
126b9ddbd55930228422e82b34a141ad1b6093f5376Behdad Esfahbod  HB_TAG('a','b','v','s'),
127b9ddbd55930228422e82b34a141ad1b6093f5376Behdad Esfahbod  HB_TAG('b','l','w','s'),
128b9ddbd55930228422e82b34a141ad1b6093f5376Behdad Esfahbod  HB_TAG('p','s','t','s'),
129b9ddbd55930228422e82b34a141ad1b6093f5376Behdad Esfahbod  HB_TAG('h','a','l','n'),
130b9ddbd55930228422e82b34a141ad1b6093f5376Behdad Esfahbod
131b9ddbd55930228422e82b34a141ad1b6093f5376Behdad Esfahbod  HB_TAG('d','i','s','t'),
132b9ddbd55930228422e82b34a141ad1b6093f5376Behdad Esfahbod  HB_TAG('a','b','v','m'),
133b9ddbd55930228422e82b34a141ad1b6093f5376Behdad Esfahbod  HB_TAG('b','l','w','m'),
134b9ddbd55930228422e82b34a141ad1b6093f5376Behdad Esfahbod};
135b9ddbd55930228422e82b34a141ad1b6093f5376Behdad Esfahbod
136b9ddbd55930228422e82b34a141ad1b6093f5376Behdad Esfahbod
137b9ddbd55930228422e82b34a141ad1b6093f5376Behdad Esfahbod
138b9ddbd55930228422e82b34a141ad1b6093f5376Behdad Esfahbodvoid
139b9ddbd55930228422e82b34a141ad1b6093f5376Behdad Esfahbod_hb_ot_shape_complex_collect_features_indic	(hb_ot_shape_planner_t *planner, const hb_segment_properties_t  *props)
140b9ddbd55930228422e82b34a141ad1b6093f5376Behdad Esfahbod{
141b9ddbd55930228422e82b34a141ad1b6093f5376Behdad Esfahbod  for (unsigned int i = 0; i < ARRAY_LENGTH (indic_basic_features); i++)
142b9ddbd55930228422e82b34a141ad1b6093f5376Behdad Esfahbod    planner->map.add_bool_feature (indic_basic_features[i], false);
143b9ddbd55930228422e82b34a141ad1b6093f5376Behdad Esfahbod
144b9ddbd55930228422e82b34a141ad1b6093f5376Behdad Esfahbod  for (unsigned int i = 0; i < ARRAY_LENGTH (indic_other_features); i++)
145b9ddbd55930228422e82b34a141ad1b6093f5376Behdad Esfahbod    planner->map.add_bool_feature (indic_other_features[i], true);
146b9ddbd55930228422e82b34a141ad1b6093f5376Behdad Esfahbod}
147b9ddbd55930228422e82b34a141ad1b6093f5376Behdad Esfahbod
148b9ddbd55930228422e82b34a141ad1b6093f5376Behdad Esfahbodvoid
149b9ddbd55930228422e82b34a141ad1b6093f5376Behdad Esfahbod_hb_ot_shape_complex_setup_masks_indic	(hb_ot_shape_context_t *c)
150b9ddbd55930228422e82b34a141ad1b6093f5376Behdad Esfahbod{
151b9ddbd55930228422e82b34a141ad1b6093f5376Behdad Esfahbod  unsigned int count = c->buffer->len;
152b9ddbd55930228422e82b34a141ad1b6093f5376Behdad Esfahbod
153b9ddbd55930228422e82b34a141ad1b6093f5376Behdad Esfahbod  for (unsigned int i = 0; i < count; i++)
154b9ddbd55930228422e82b34a141ad1b6093f5376Behdad Esfahbod  {
155b9ddbd55930228422e82b34a141ad1b6093f5376Behdad Esfahbod    unsigned int this_type = get_indic_categories (c->buffer->info[i].codepoint);
156b9ddbd55930228422e82b34a141ad1b6093f5376Behdad Esfahbod
157b9ddbd55930228422e82b34a141ad1b6093f5376Behdad Esfahbod    c->buffer->info[i].indic_categories() = this_type;
158b9ddbd55930228422e82b34a141ad1b6093f5376Behdad Esfahbod  }
159b9ddbd55930228422e82b34a141ad1b6093f5376Behdad Esfahbod
160b9ddbd55930228422e82b34a141ad1b6093f5376Behdad Esfahbod  hb_mask_t mask_array[ARRAY_LENGTH (indic_basic_features)] = {0};
161b9ddbd55930228422e82b34a141ad1b6093f5376Behdad Esfahbod  unsigned int num_masks = ARRAY_LENGTH (indic_basic_features);
162b9ddbd55930228422e82b34a141ad1b6093f5376Behdad Esfahbod  for (unsigned int i = 0; i < num_masks; i++)
163b9ddbd55930228422e82b34a141ad1b6093f5376Behdad Esfahbod    mask_array[i] = c->plan->map.get_1_mask (indic_basic_features[i]);
164b9ddbd55930228422e82b34a141ad1b6093f5376Behdad Esfahbod}
165b9ddbd55930228422e82b34a141ad1b6093f5376Behdad Esfahbod
166b9ddbd55930228422e82b34a141ad1b6093f5376Behdad Esfahbod
167b9ddbd55930228422e82b34a141ad1b6093f5376Behdad EsfahbodHB_END_DECLS
168