hb-ot-shape-complex-indic-private.hh revision 55f70ebfb95083f515d9b0044a2a65ab11484bb5
1/*
2 * Copyright © 2012  Google, Inc.
3 *
4 *  This is part of HarfBuzz, a text shaping library.
5 *
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.
11 *
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
16 * DAMAGE.
17 *
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.
23 *
24 * Google Author(s): Behdad Esfahbod
25 */
26
27#ifndef HB_OT_SHAPE_COMPLEX_INDIC_PRIVATE_HH
28#define HB_OT_SHAPE_COMPLEX_INDIC_PRIVATE_HH
29
30#include "hb-private.hh"
31
32
33#include "hb-ot-shape-complex-private.hh"
34
35
36/* buffer var allocations */
37#define indic_category() complex_var_persistent_u8_0() /* indic_category_t */
38#define indic_position() complex_var_persistent_u8_1() /* indic_matra_category_t */
39
40#define INDIC_TABLE_ELEMENT_TYPE uint8_t
41
42/* Cateories used in the OpenType spec:
43 * https://www.microsoft.com/typography/otfntdev/devanot/shaping.aspx
44 */
45/* Note: This enum is duplicated in the -machine.rl source file.
46 * Not sure how to avoid duplication. */
47enum indic_category_t {
48  OT_X = 0,
49  OT_C,
50  OT_Ra, /* Not explicitly listed in the OT spec, but used in the grammar. */
51  OT_V,
52  OT_N,
53  OT_H,
54  OT_ZWNJ,
55  OT_ZWJ,
56  OT_M,
57  OT_SM,
58  OT_VD,
59  OT_A,
60  OT_NBSP,
61  OT_DOTTEDCIRCLE, /* Not in the spec, but special in Uniscribe. /Very very/ special! */
62  OT_RS, /* Register Shifter (and other marks), used in Khmer OT spec */
63  OT_Coeng
64};
65
66/* Visual positions in a syllable from left to right. */
67enum indic_position_t {
68  POS_RA_TO_BECOME_REPH,
69  POS_PRE_M,
70  POS_PRE_C,
71  POS_BASE_C,
72  POS_ABOVE_C,
73  POS_BELOW_C,
74  POS_ABOVE_M,
75  POS_BELOW_M,
76  POS_POST_C,
77  POS_POST_M,
78  POS_FINAL_C,
79  POS_SMVD
80};
81
82/* Categories used in IndicSyllabicCategory.txt from UCD. */
83enum indic_syllabic_category_t {
84  INDIC_SYLLABIC_CATEGORY_OTHER			= OT_X,
85
86  INDIC_SYLLABIC_CATEGORY_AVAGRAHA		= OT_X,
87  INDIC_SYLLABIC_CATEGORY_BINDU			= OT_SM,
88  INDIC_SYLLABIC_CATEGORY_CONSONANT		= OT_C,
89  INDIC_SYLLABIC_CATEGORY_CONSONANT_DEAD	= OT_C,
90  INDIC_SYLLABIC_CATEGORY_CONSONANT_FINAL	= OT_C,
91  INDIC_SYLLABIC_CATEGORY_CONSONANT_HEAD_LETTER	= OT_C,
92  INDIC_SYLLABIC_CATEGORY_CONSONANT_MEDIAL	= OT_C,
93  INDIC_SYLLABIC_CATEGORY_CONSONANT_PLACEHOLDER	= OT_NBSP,
94  INDIC_SYLLABIC_CATEGORY_CONSONANT_SUBJOINED	= OT_C,
95  INDIC_SYLLABIC_CATEGORY_CONSONANT_REPHA	= OT_C,
96  INDIC_SYLLABIC_CATEGORY_MODIFYING_LETTER	= OT_X,
97  INDIC_SYLLABIC_CATEGORY_NUKTA			= OT_N,
98  INDIC_SYLLABIC_CATEGORY_REGISTER_SHIFTER	= OT_RS,
99  INDIC_SYLLABIC_CATEGORY_TONE_LETTER		= OT_X,
100  INDIC_SYLLABIC_CATEGORY_TONE_MARK		= OT_X,
101  INDIC_SYLLABIC_CATEGORY_VIRAMA		= OT_H,
102  INDIC_SYLLABIC_CATEGORY_VISARGA		= OT_SM,
103  INDIC_SYLLABIC_CATEGORY_VOWEL			= OT_V,
104  INDIC_SYLLABIC_CATEGORY_VOWEL_DEPENDENT	= OT_M,
105  INDIC_SYLLABIC_CATEGORY_VOWEL_INDEPENDENT	= OT_V
106};
107
108/* Categories used in IndicSMatraCategory.txt from UCD */
109enum indic_matra_category_t {
110  INDIC_MATRA_CATEGORY_NOT_APPLICABLE		= POS_BASE_C,
111
112  INDIC_MATRA_CATEGORY_LEFT			= POS_PRE_M,
113  INDIC_MATRA_CATEGORY_TOP			= POS_ABOVE_M,
114  INDIC_MATRA_CATEGORY_BOTTOM			= POS_BELOW_M,
115  INDIC_MATRA_CATEGORY_RIGHT			= POS_POST_M,
116
117  /* We don't really care much about these since we decompose them
118   * in the generic pre-shaping layer.  They will only be used if
119   * the font does not cover the decomposition.  In which case, we
120   * define these as aliases to the place we want the split-matra
121   * glyph to show up.  Quite arbitrary.
122   *
123   * TODO: There are some split matras without Unicode decompositions.
124   * We have to figure out what to do with them.
125   */
126  INDIC_MATRA_CATEGORY_BOTTOM_AND_RIGHT		= POS_POST_M,
127  INDIC_MATRA_CATEGORY_LEFT_AND_RIGHT		= POS_POST_M,
128  INDIC_MATRA_CATEGORY_TOP_AND_BOTTOM		= POS_BELOW_M,
129  INDIC_MATRA_CATEGORY_TOP_AND_BOTTOM_AND_RIGHT	= POS_POST_M,
130  INDIC_MATRA_CATEGORY_TOP_AND_LEFT		= POS_ABOVE_M,
131  INDIC_MATRA_CATEGORY_TOP_AND_LEFT_AND_RIGHT	= POS_POST_M,
132  INDIC_MATRA_CATEGORY_TOP_AND_RIGHT		= POS_POST_M,
133
134  INDIC_MATRA_CATEGORY_INVISIBLE		= INDIC_MATRA_CATEGORY_NOT_APPLICABLE,
135  INDIC_MATRA_CATEGORY_OVERSTRUCK		= INDIC_MATRA_CATEGORY_NOT_APPLICABLE,
136  INDIC_MATRA_CATEGORY_VISUAL_ORDER_LEFT	= INDIC_MATRA_CATEGORY_NOT_APPLICABLE
137};
138
139/* Note: We use ASSERT_STATIC_EXPR_ZERO() instead of ASSERT_STATIC_EXPR() and the comma operation
140 * because gcc fails to optimize the latter and fills the table in at runtime. */
141#define INDIC_COMBINE_CATEGORIES(S,M) \
142  (ASSERT_STATIC_EXPR_ZERO (M == INDIC_MATRA_CATEGORY_NOT_APPLICABLE || (S == INDIC_SYLLABIC_CATEGORY_VIRAMA || S == INDIC_SYLLABIC_CATEGORY_VOWEL_DEPENDENT)) + \
143   ASSERT_STATIC_EXPR_ZERO (S < 16 && M < 16) + \
144   ((M << 4) | S))
145
146
147#include "hb-ot-shape-complex-indic-table.hh"
148
149/* XXX
150 * This is a hack for now.  We should:
151 * 1. Move this data into the main Indic table,
152 * and/or
153 * 2. Probe font lookups to determine consonant positions.
154 */
155static const struct consonant_position_t {
156  hb_codepoint_t u;
157  indic_position_t position;
158} consonant_positions[] = {
159  {0x0930, POS_BELOW_C},
160  {0x09AC, POS_BELOW_C},
161  {0x09AF, POS_POST_C},
162  {0x09B0, POS_BELOW_C},
163  {0x09F0, POS_BELOW_C},
164  {0x0A2F, POS_POST_C},
165  {0x0A30, POS_BELOW_C},
166  {0x0A35, POS_BELOW_C},
167  {0x0A39, POS_BELOW_C},
168  {0x0AB0, POS_BELOW_C},
169  {0x0B24, POS_BELOW_C},
170  {0x0B28, POS_BELOW_C},
171  {0x0B2C, POS_BELOW_C},
172  {0x0B2D, POS_BELOW_C},
173  {0x0B2E, POS_BELOW_C},
174  {0x0B2F, POS_POST_C},
175  {0x0B30, POS_BELOW_C},
176  {0x0B32, POS_BELOW_C},
177  {0x0B33, POS_BELOW_C},
178  {0x0B5F, POS_POST_C},
179  {0x0B71, POS_BELOW_C},
180  {0x0C15, POS_BELOW_C},
181  {0x0C16, POS_BELOW_C},
182  {0x0C17, POS_BELOW_C},
183  {0x0C18, POS_BELOW_C},
184  {0x0C19, POS_BELOW_C},
185  {0x0C1A, POS_BELOW_C},
186  {0x0C1B, POS_BELOW_C},
187  {0x0C1C, POS_BELOW_C},
188  {0x0C1D, POS_BELOW_C},
189  {0x0C1E, POS_BELOW_C},
190  {0x0C1F, POS_BELOW_C},
191  {0x0C20, POS_BELOW_C},
192  {0x0C21, POS_BELOW_C},
193  {0x0C22, POS_BELOW_C},
194  {0x0C23, POS_BELOW_C},
195  {0x0C24, POS_BELOW_C},
196  {0x0C25, POS_BELOW_C},
197  {0x0C26, POS_BELOW_C},
198  {0x0C27, POS_BELOW_C},
199  {0x0C28, POS_BELOW_C},
200  {0x0C2A, POS_BELOW_C},
201  {0x0C2B, POS_BELOW_C},
202  {0x0C2C, POS_BELOW_C},
203  {0x0C2D, POS_BELOW_C},
204  {0x0C2E, POS_BELOW_C},
205  {0x0C2F, POS_BELOW_C},
206  {0x0C30, POS_BELOW_C},
207  {0x0C32, POS_BELOW_C},
208  {0x0C33, POS_BELOW_C},
209  {0x0C35, POS_BELOW_C},
210  {0x0C36, POS_BELOW_C},
211  {0x0C37, POS_BELOW_C},
212  {0x0C38, POS_BELOW_C},
213  {0x0C39, POS_BELOW_C},
214  {0x0C95, POS_BELOW_C},
215  {0x0C96, POS_BELOW_C},
216  {0x0C97, POS_BELOW_C},
217  {0x0C98, POS_BELOW_C},
218  {0x0C99, POS_BELOW_C},
219  {0x0C9A, POS_BELOW_C},
220  {0x0C9B, POS_BELOW_C},
221  {0x0C9C, POS_BELOW_C},
222  {0x0C9D, POS_BELOW_C},
223  {0x0C9E, POS_BELOW_C},
224  {0x0C9F, POS_BELOW_C},
225  {0x0CA0, POS_BELOW_C},
226  {0x0CA1, POS_BELOW_C},
227  {0x0CA2, POS_BELOW_C},
228  {0x0CA3, POS_BELOW_C},
229  {0x0CA4, POS_BELOW_C},
230  {0x0CA5, POS_BELOW_C},
231  {0x0CA6, POS_BELOW_C},
232  {0x0CA7, POS_BELOW_C},
233  {0x0CA8, POS_BELOW_C},
234  {0x0CAA, POS_BELOW_C},
235  {0x0CAB, POS_BELOW_C},
236  {0x0CAC, POS_BELOW_C},
237  {0x0CAD, POS_BELOW_C},
238  {0x0CAE, POS_BELOW_C},
239  {0x0CAF, POS_BELOW_C},
240  {0x0CB0, POS_BELOW_C},
241  {0x0CB2, POS_BELOW_C},
242  {0x0CB3, POS_BELOW_C},
243  {0x0CB5, POS_BELOW_C},
244  {0x0CB6, POS_BELOW_C},
245  {0x0CB7, POS_BELOW_C},
246  {0x0CB8, POS_BELOW_C},
247  {0x0CB9, POS_BELOW_C},
248  {0x0CDE, POS_BELOW_C},
249  {0x0D2F, POS_POST_C},
250  {0x0D30, POS_POST_C},
251  {0x0D32, POS_BELOW_C},
252  {0x0D35, POS_POST_C},
253};
254
255/* XXX
256 * This is a hack for now.  We should move this data into the main Indic table.
257 * Or completely remove it and just check in the tables.
258 */
259static const hb_codepoint_t ra_chars[] = {
260  0x0930, /* Devanagari */
261  0x09B0, /* Bengali */
262  0x09F0, /* Bengali */
263  0x0A30, /* Gurmukhi */	/* No Reph */
264  0x0AB0, /* Gujarati */
265  0x0B30, /* Oriya */
266  0x0BB0, /* Tamil */		/* No Reph */
267  0x0C30, /* Telugu */		/* No Reph */
268  0x0CB0, /* Kannada */
269  0x0D30, /* Malayalam */	/* No Reph */
270
271  0x179A, /* Khmer */		/* No Reph */
272};
273
274
275#endif /* HB_OT_SHAPE_COMPLEX_INDIC_PRIVATE_HH */
276