hb-ot-shape-complex-indic.cc revision 97158392a5899ddb739afaac925128f33f699bd7
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 */
33b65c06025d2b54a44f716e030d4b10072c65bea8Behdad Esfahbod#define indic_category() complex_var_persistent_u8_0() /* indic_category_t */
34b65c06025d2b54a44f716e030d4b10072c65bea8Behdad Esfahbod#define indic_position() complex_var_persistent_u8_1() /* indic_matra_category_t */
35b9ddbd55930228422e82b34a141ad1b6093f5376Behdad Esfahbod
36b9ddbd55930228422e82b34a141ad1b6093f5376Behdad Esfahbod#define INDIC_TABLE_ELEMENT_TYPE uint8_t
37b9ddbd55930228422e82b34a141ad1b6093f5376Behdad Esfahbod
3820503ccd578c9983162857954e3236413469ed35Behdad Esfahbod/* Cateories used in the OpenType spec:
3920503ccd578c9983162857954e3236413469ed35Behdad Esfahbod * https://www.microsoft.com/typography/otfntdev/devanot/shaping.aspx
4020503ccd578c9983162857954e3236413469ed35Behdad Esfahbod */
41c7fe56a1d5d3e969b6ec51cd9ecd471706a19568Behdad Esfahbod/* Note: This enum is duplicated in the -machine.rl source file.
42c7fe56a1d5d3e969b6ec51cd9ecd471706a19568Behdad Esfahbod * Not sure how to avoid duplication. */
43867361c3ad39629a8d5b7dc48d558a1c19e37d43Behdad Esfahbodenum indic_category_t {
4420503ccd578c9983162857954e3236413469ed35Behdad Esfahbod  OT_X = 0,
4520503ccd578c9983162857954e3236413469ed35Behdad Esfahbod  OT_C,
46c7fe56a1d5d3e969b6ec51cd9ecd471706a19568Behdad Esfahbod  OT_Ra, /* Not explicitly listed in the OT spec, but used in the grammar. */
4720503ccd578c9983162857954e3236413469ed35Behdad Esfahbod  OT_V,
4820503ccd578c9983162857954e3236413469ed35Behdad Esfahbod  OT_N,
4920503ccd578c9983162857954e3236413469ed35Behdad Esfahbod  OT_H,
5020503ccd578c9983162857954e3236413469ed35Behdad Esfahbod  OT_ZWNJ,
5120503ccd578c9983162857954e3236413469ed35Behdad Esfahbod  OT_ZWJ,
5220503ccd578c9983162857954e3236413469ed35Behdad Esfahbod  OT_M,
5320503ccd578c9983162857954e3236413469ed35Behdad Esfahbod  OT_SM,
5420503ccd578c9983162857954e3236413469ed35Behdad Esfahbod  OT_VD,
5520503ccd578c9983162857954e3236413469ed35Behdad Esfahbod  OT_A,
56b9452bfc1696457e156e79037c863903da5454fcBehdad Esfahbod  OT_NBSP
5720503ccd578c9983162857954e3236413469ed35Behdad Esfahbod};
5820503ccd578c9983162857954e3236413469ed35Behdad Esfahbod
598fdba506f0f1c66b50f8f4b114d624cb956d03b7Behdad Esfahbod/* Visual positions in a syllable from left to right. */
608fdba506f0f1c66b50f8f4b114d624cb956d03b7Behdad Esfahbodenum indic_position_t {
618fdba506f0f1c66b50f8f4b114d624cb956d03b7Behdad Esfahbod  POS_PRE,
628fdba506f0f1c66b50f8f4b114d624cb956d03b7Behdad Esfahbod  POS_BASE,
638fdba506f0f1c66b50f8f4b114d624cb956d03b7Behdad Esfahbod  POS_ABOVE,
648fdba506f0f1c66b50f8f4b114d624cb956d03b7Behdad Esfahbod  POS_BELOW,
658fdba506f0f1c66b50f8f4b114d624cb956d03b7Behdad Esfahbod  POS_POST,
668fdba506f0f1c66b50f8f4b114d624cb956d03b7Behdad Esfahbod};
678fdba506f0f1c66b50f8f4b114d624cb956d03b7Behdad Esfahbod
6820503ccd578c9983162857954e3236413469ed35Behdad Esfahbod/* Categories used in IndicSyllabicCategory.txt from UCD */
6920503ccd578c9983162857954e3236413469ed35Behdad Esfahbod/* The assignments are guesswork */
70b9ddbd55930228422e82b34a141ad1b6093f5376Behdad Esfahbodenum indic_syllabic_category_t {
7120503ccd578c9983162857954e3236413469ed35Behdad Esfahbod  INDIC_SYLLABIC_CATEGORY_OTHER			= OT_X,
7220503ccd578c9983162857954e3236413469ed35Behdad Esfahbod
73422e08dbb8e2c0c5664f1bdc7e159a673cfea8c5Behdad Esfahbod  INDIC_SYLLABIC_CATEGORY_AVAGRAHA		= OT_X,
7420503ccd578c9983162857954e3236413469ed35Behdad Esfahbod  INDIC_SYLLABIC_CATEGORY_BINDU			= OT_SM,
7520503ccd578c9983162857954e3236413469ed35Behdad Esfahbod  INDIC_SYLLABIC_CATEGORY_CONSONANT		= OT_C,
7620503ccd578c9983162857954e3236413469ed35Behdad Esfahbod  INDIC_SYLLABIC_CATEGORY_CONSONANT_DEAD	= OT_C,
7720503ccd578c9983162857954e3236413469ed35Behdad Esfahbod  INDIC_SYLLABIC_CATEGORY_CONSONANT_FINAL	= OT_C,
7820503ccd578c9983162857954e3236413469ed35Behdad Esfahbod  INDIC_SYLLABIC_CATEGORY_CONSONANT_HEAD_LETTER	= OT_C,
7920503ccd578c9983162857954e3236413469ed35Behdad Esfahbod  INDIC_SYLLABIC_CATEGORY_CONSONANT_MEDIAL	= OT_C,
8020503ccd578c9983162857954e3236413469ed35Behdad Esfahbod  INDIC_SYLLABIC_CATEGORY_CONSONANT_PLACEHOLDER	= OT_NBSP,
8120503ccd578c9983162857954e3236413469ed35Behdad Esfahbod  INDIC_SYLLABIC_CATEGORY_CONSONANT_SUBJOINED	= OT_C,
8220503ccd578c9983162857954e3236413469ed35Behdad Esfahbod  INDIC_SYLLABIC_CATEGORY_CONSONANT_REPHA	= OT_C,
83422e08dbb8e2c0c5664f1bdc7e159a673cfea8c5Behdad Esfahbod  INDIC_SYLLABIC_CATEGORY_MODIFYING_LETTER	= OT_X,
8420503ccd578c9983162857954e3236413469ed35Behdad Esfahbod  INDIC_SYLLABIC_CATEGORY_NUKTA			= OT_N,
85422e08dbb8e2c0c5664f1bdc7e159a673cfea8c5Behdad Esfahbod  INDIC_SYLLABIC_CATEGORY_REGISTER_SHIFTER	= OT_X,
86422e08dbb8e2c0c5664f1bdc7e159a673cfea8c5Behdad Esfahbod  INDIC_SYLLABIC_CATEGORY_TONE_LETTER		= OT_X,
87422e08dbb8e2c0c5664f1bdc7e159a673cfea8c5Behdad Esfahbod  INDIC_SYLLABIC_CATEGORY_TONE_MARK		= OT_X,
8820503ccd578c9983162857954e3236413469ed35Behdad Esfahbod  INDIC_SYLLABIC_CATEGORY_VIRAMA		= OT_H,
8920503ccd578c9983162857954e3236413469ed35Behdad Esfahbod  INDIC_SYLLABIC_CATEGORY_VISARGA		= OT_SM,
9020503ccd578c9983162857954e3236413469ed35Behdad Esfahbod  INDIC_SYLLABIC_CATEGORY_VOWEL			= OT_V,
9120503ccd578c9983162857954e3236413469ed35Behdad Esfahbod  INDIC_SYLLABIC_CATEGORY_VOWEL_DEPENDENT	= OT_M,
92b9452bfc1696457e156e79037c863903da5454fcBehdad Esfahbod  INDIC_SYLLABIC_CATEGORY_VOWEL_INDEPENDENT	= OT_V
93b9ddbd55930228422e82b34a141ad1b6093f5376Behdad Esfahbod};
94b9ddbd55930228422e82b34a141ad1b6093f5376Behdad Esfahbod
9520503ccd578c9983162857954e3236413469ed35Behdad Esfahbod/* Categories used in IndicSMatraCategory.txt from UCD */
96b9ddbd55930228422e82b34a141ad1b6093f5376Behdad Esfahbodenum indic_matra_category_t {
978fdba506f0f1c66b50f8f4b114d624cb956d03b7Behdad Esfahbod  INDIC_MATRA_CATEGORY_NOT_APPLICABLE		= POS_BASE,
9820503ccd578c9983162857954e3236413469ed35Behdad Esfahbod
998fdba506f0f1c66b50f8f4b114d624cb956d03b7Behdad Esfahbod  INDIC_MATRA_CATEGORY_LEFT			= POS_PRE,
1008fdba506f0f1c66b50f8f4b114d624cb956d03b7Behdad Esfahbod  INDIC_MATRA_CATEGORY_TOP			= POS_ABOVE,
1018fdba506f0f1c66b50f8f4b114d624cb956d03b7Behdad Esfahbod  INDIC_MATRA_CATEGORY_BOTTOM			= POS_BELOW,
1028fdba506f0f1c66b50f8f4b114d624cb956d03b7Behdad Esfahbod  INDIC_MATRA_CATEGORY_RIGHT			= POS_POST,
103422e08dbb8e2c0c5664f1bdc7e159a673cfea8c5Behdad Esfahbod
104422e08dbb8e2c0c5664f1bdc7e159a673cfea8c5Behdad Esfahbod  /* We don't really care much about these since we decompose them
1058fdba506f0f1c66b50f8f4b114d624cb956d03b7Behdad Esfahbod   * in the generic pre-shaping layer.  They will only be used if
1068fdba506f0f1c66b50f8f4b114d624cb956d03b7Behdad Esfahbod   * the font does not cover the decomposition.  In which case, we
1078fdba506f0f1c66b50f8f4b114d624cb956d03b7Behdad Esfahbod   * define these as aliases to the place we want the split-matra
1088fdba506f0f1c66b50f8f4b114d624cb956d03b7Behdad Esfahbod   * glyph to show up.  Quite arbitrary. */
1098fdba506f0f1c66b50f8f4b114d624cb956d03b7Behdad Esfahbod  INDIC_MATRA_CATEGORY_BOTTOM_AND_RIGHT		= INDIC_MATRA_CATEGORY_BOTTOM,
1108fdba506f0f1c66b50f8f4b114d624cb956d03b7Behdad Esfahbod  INDIC_MATRA_CATEGORY_LEFT_AND_RIGHT		= INDIC_MATRA_CATEGORY_LEFT,
1118fdba506f0f1c66b50f8f4b114d624cb956d03b7Behdad Esfahbod  INDIC_MATRA_CATEGORY_TOP_AND_BOTTOM		= INDIC_MATRA_CATEGORY_BOTTOM,
1128fdba506f0f1c66b50f8f4b114d624cb956d03b7Behdad Esfahbod  INDIC_MATRA_CATEGORY_TOP_AND_BOTTOM_AND_RIGHT	= INDIC_MATRA_CATEGORY_BOTTOM,
1138fdba506f0f1c66b50f8f4b114d624cb956d03b7Behdad Esfahbod  INDIC_MATRA_CATEGORY_TOP_AND_LEFT		= INDIC_MATRA_CATEGORY_LEFT,
1148fdba506f0f1c66b50f8f4b114d624cb956d03b7Behdad Esfahbod  INDIC_MATRA_CATEGORY_TOP_AND_LEFT_AND_RIGHT	= INDIC_MATRA_CATEGORY_LEFT,
1158fdba506f0f1c66b50f8f4b114d624cb956d03b7Behdad Esfahbod  INDIC_MATRA_CATEGORY_TOP_AND_RIGHT		= INDIC_MATRA_CATEGORY_RIGHT,
116422e08dbb8e2c0c5664f1bdc7e159a673cfea8c5Behdad Esfahbod
117422e08dbb8e2c0c5664f1bdc7e159a673cfea8c5Behdad Esfahbod  INDIC_MATRA_CATEGORY_INVISIBLE		= INDIC_MATRA_CATEGORY_NOT_APPLICABLE,
118422e08dbb8e2c0c5664f1bdc7e159a673cfea8c5Behdad Esfahbod  INDIC_MATRA_CATEGORY_OVERSTRUCK		= INDIC_MATRA_CATEGORY_NOT_APPLICABLE,
119422e08dbb8e2c0c5664f1bdc7e159a673cfea8c5Behdad Esfahbod  INDIC_MATRA_CATEGORY_VISUAL_ORDER_LEFT	= INDIC_MATRA_CATEGORY_NOT_APPLICABLE
120b9ddbd55930228422e82b34a141ad1b6093f5376Behdad Esfahbod};
121b9ddbd55930228422e82b34a141ad1b6093f5376Behdad Esfahbod
1224ec30aec3014be6effc09cbbc88dcd075f3826dfBehdad Esfahbod/* Note: We use ASSERT_STATIC_EXPR_ZERO() instead of ASSERT_STATIC_EXPR() and the comma operation
1234ec30aec3014be6effc09cbbc88dcd075f3826dfBehdad Esfahbod * because gcc fails to optimize the latter and fills the table in at runtime. */
12420503ccd578c9983162857954e3236413469ed35Behdad Esfahbod#define INDIC_COMBINE_CATEGORIES(S,M) \
1254ec30aec3014be6effc09cbbc88dcd075f3826dfBehdad Esfahbod  (ASSERT_STATIC_EXPR_ZERO (M == INDIC_MATRA_CATEGORY_NOT_APPLICABLE || (S == INDIC_SYLLABIC_CATEGORY_VIRAMA || S == INDIC_SYLLABIC_CATEGORY_VOWEL_DEPENDENT)) + \
1264ec30aec3014be6effc09cbbc88dcd075f3826dfBehdad Esfahbod   ASSERT_STATIC_EXPR_ZERO (S < 16 && M < 16) + \
1274ec30aec3014be6effc09cbbc88dcd075f3826dfBehdad Esfahbod   ((M << 4) | S))
128b9ddbd55930228422e82b34a141ad1b6093f5376Behdad Esfahbod
129b9ddbd55930228422e82b34a141ad1b6093f5376Behdad Esfahbod#include "hb-ot-shape-complex-indic-table.hh"
130b9ddbd55930228422e82b34a141ad1b6093f5376Behdad Esfahbod
13165988a145b4a52c37fd53c1473034f9e701f61d9Behdad Esfahbod/* XXX
13265988a145b4a52c37fd53c1473034f9e701f61d9Behdad Esfahbod * This is a hack for now.  We should:
13365988a145b4a52c37fd53c1473034f9e701f61d9Behdad Esfahbod * 1. Move this data into the main Indic table,
13465988a145b4a52c37fd53c1473034f9e701f61d9Behdad Esfahbod * and/or
13565988a145b4a52c37fd53c1473034f9e701f61d9Behdad Esfahbod * 2. Probe font lookups to determine consonant positions.
13665988a145b4a52c37fd53c1473034f9e701f61d9Behdad Esfahbod */
137743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbodstatic const struct consonant_position_t {
13865988a145b4a52c37fd53c1473034f9e701f61d9Behdad Esfahbod  hb_codepoint_t u;
1398fdba506f0f1c66b50f8f4b114d624cb956d03b7Behdad Esfahbod  indic_position_t position;
14065988a145b4a52c37fd53c1473034f9e701f61d9Behdad Esfahbod} consonant_positions[] = {
1418fdba506f0f1c66b50f8f4b114d624cb956d03b7Behdad Esfahbod  {0x0930, POS_BELOW},
1428fdba506f0f1c66b50f8f4b114d624cb956d03b7Behdad Esfahbod  {0x09AC, POS_BELOW},
1438fdba506f0f1c66b50f8f4b114d624cb956d03b7Behdad Esfahbod  {0x09AF, POS_POST},
1448fdba506f0f1c66b50f8f4b114d624cb956d03b7Behdad Esfahbod  {0x09B0, POS_BELOW},
1458fdba506f0f1c66b50f8f4b114d624cb956d03b7Behdad Esfahbod  {0x09F0, POS_BELOW},
1468fdba506f0f1c66b50f8f4b114d624cb956d03b7Behdad Esfahbod  {0x0A2F, POS_POST},
1478fdba506f0f1c66b50f8f4b114d624cb956d03b7Behdad Esfahbod  {0x0A30, POS_BELOW},
1488fdba506f0f1c66b50f8f4b114d624cb956d03b7Behdad Esfahbod  {0x0A35, POS_BELOW},
1498fdba506f0f1c66b50f8f4b114d624cb956d03b7Behdad Esfahbod  {0x0A39, POS_BELOW},
1508fdba506f0f1c66b50f8f4b114d624cb956d03b7Behdad Esfahbod  {0x0AB0, POS_BELOW},
1518fdba506f0f1c66b50f8f4b114d624cb956d03b7Behdad Esfahbod  {0x0B24, POS_BELOW},
1528fdba506f0f1c66b50f8f4b114d624cb956d03b7Behdad Esfahbod  {0x0B28, POS_BELOW},
1538fdba506f0f1c66b50f8f4b114d624cb956d03b7Behdad Esfahbod  {0x0B2C, POS_BELOW},
1548fdba506f0f1c66b50f8f4b114d624cb956d03b7Behdad Esfahbod  {0x0B2D, POS_BELOW},
1558fdba506f0f1c66b50f8f4b114d624cb956d03b7Behdad Esfahbod  {0x0B2E, POS_BELOW},
1568fdba506f0f1c66b50f8f4b114d624cb956d03b7Behdad Esfahbod  {0x0B2F, POS_POST},
1578fdba506f0f1c66b50f8f4b114d624cb956d03b7Behdad Esfahbod  {0x0B30, POS_BELOW},
1588fdba506f0f1c66b50f8f4b114d624cb956d03b7Behdad Esfahbod  {0x0B32, POS_BELOW},
1598fdba506f0f1c66b50f8f4b114d624cb956d03b7Behdad Esfahbod  {0x0B33, POS_BELOW},
1608fdba506f0f1c66b50f8f4b114d624cb956d03b7Behdad Esfahbod  {0x0B5F, POS_POST},
1618fdba506f0f1c66b50f8f4b114d624cb956d03b7Behdad Esfahbod  {0x0B71, POS_BELOW},
1628fdba506f0f1c66b50f8f4b114d624cb956d03b7Behdad Esfahbod  {0x0C15, POS_BELOW},
1638fdba506f0f1c66b50f8f4b114d624cb956d03b7Behdad Esfahbod  {0x0C16, POS_BELOW},
1648fdba506f0f1c66b50f8f4b114d624cb956d03b7Behdad Esfahbod  {0x0C17, POS_BELOW},
1658fdba506f0f1c66b50f8f4b114d624cb956d03b7Behdad Esfahbod  {0x0C18, POS_BELOW},
1668fdba506f0f1c66b50f8f4b114d624cb956d03b7Behdad Esfahbod  {0x0C19, POS_BELOW},
1678fdba506f0f1c66b50f8f4b114d624cb956d03b7Behdad Esfahbod  {0x0C1A, POS_BELOW},
1688fdba506f0f1c66b50f8f4b114d624cb956d03b7Behdad Esfahbod  {0x0C1B, POS_BELOW},
1698fdba506f0f1c66b50f8f4b114d624cb956d03b7Behdad Esfahbod  {0x0C1C, POS_BELOW},
1708fdba506f0f1c66b50f8f4b114d624cb956d03b7Behdad Esfahbod  {0x0C1D, POS_BELOW},
1718fdba506f0f1c66b50f8f4b114d624cb956d03b7Behdad Esfahbod  {0x0C1E, POS_BELOW},
1728fdba506f0f1c66b50f8f4b114d624cb956d03b7Behdad Esfahbod  {0x0C1F, POS_BELOW},
1738fdba506f0f1c66b50f8f4b114d624cb956d03b7Behdad Esfahbod  {0x0C20, POS_BELOW},
1748fdba506f0f1c66b50f8f4b114d624cb956d03b7Behdad Esfahbod  {0x0C21, POS_BELOW},
1758fdba506f0f1c66b50f8f4b114d624cb956d03b7Behdad Esfahbod  {0x0C22, POS_BELOW},
1768fdba506f0f1c66b50f8f4b114d624cb956d03b7Behdad Esfahbod  {0x0C23, POS_BELOW},
1778fdba506f0f1c66b50f8f4b114d624cb956d03b7Behdad Esfahbod  {0x0C24, POS_BELOW},
1788fdba506f0f1c66b50f8f4b114d624cb956d03b7Behdad Esfahbod  {0x0C25, POS_BELOW},
1798fdba506f0f1c66b50f8f4b114d624cb956d03b7Behdad Esfahbod  {0x0C26, POS_BELOW},
1808fdba506f0f1c66b50f8f4b114d624cb956d03b7Behdad Esfahbod  {0x0C27, POS_BELOW},
1818fdba506f0f1c66b50f8f4b114d624cb956d03b7Behdad Esfahbod  {0x0C28, POS_BELOW},
1828fdba506f0f1c66b50f8f4b114d624cb956d03b7Behdad Esfahbod  {0x0C2A, POS_BELOW},
1838fdba506f0f1c66b50f8f4b114d624cb956d03b7Behdad Esfahbod  {0x0C2B, POS_BELOW},
1848fdba506f0f1c66b50f8f4b114d624cb956d03b7Behdad Esfahbod  {0x0C2C, POS_BELOW},
1858fdba506f0f1c66b50f8f4b114d624cb956d03b7Behdad Esfahbod  {0x0C2D, POS_BELOW},
1868fdba506f0f1c66b50f8f4b114d624cb956d03b7Behdad Esfahbod  {0x0C2E, POS_BELOW},
1878fdba506f0f1c66b50f8f4b114d624cb956d03b7Behdad Esfahbod  {0x0C2F, POS_BELOW},
1888fdba506f0f1c66b50f8f4b114d624cb956d03b7Behdad Esfahbod  {0x0C30, POS_BELOW},
1898fdba506f0f1c66b50f8f4b114d624cb956d03b7Behdad Esfahbod  {0x0C32, POS_BELOW},
1908fdba506f0f1c66b50f8f4b114d624cb956d03b7Behdad Esfahbod  {0x0C33, POS_BELOW},
1918fdba506f0f1c66b50f8f4b114d624cb956d03b7Behdad Esfahbod  {0x0C35, POS_BELOW},
1928fdba506f0f1c66b50f8f4b114d624cb956d03b7Behdad Esfahbod  {0x0C36, POS_BELOW},
1938fdba506f0f1c66b50f8f4b114d624cb956d03b7Behdad Esfahbod  {0x0C37, POS_BELOW},
1948fdba506f0f1c66b50f8f4b114d624cb956d03b7Behdad Esfahbod  {0x0C38, POS_BELOW},
1958fdba506f0f1c66b50f8f4b114d624cb956d03b7Behdad Esfahbod  {0x0C39, POS_BELOW},
1968fdba506f0f1c66b50f8f4b114d624cb956d03b7Behdad Esfahbod  {0x0C95, POS_BELOW},
1978fdba506f0f1c66b50f8f4b114d624cb956d03b7Behdad Esfahbod  {0x0C96, POS_BELOW},
1988fdba506f0f1c66b50f8f4b114d624cb956d03b7Behdad Esfahbod  {0x0C97, POS_BELOW},
1998fdba506f0f1c66b50f8f4b114d624cb956d03b7Behdad Esfahbod  {0x0C98, POS_BELOW},
2008fdba506f0f1c66b50f8f4b114d624cb956d03b7Behdad Esfahbod  {0x0C99, POS_BELOW},
2018fdba506f0f1c66b50f8f4b114d624cb956d03b7Behdad Esfahbod  {0x0C9A, POS_BELOW},
2028fdba506f0f1c66b50f8f4b114d624cb956d03b7Behdad Esfahbod  {0x0C9B, POS_BELOW},
2038fdba506f0f1c66b50f8f4b114d624cb956d03b7Behdad Esfahbod  {0x0C9C, POS_BELOW},
2048fdba506f0f1c66b50f8f4b114d624cb956d03b7Behdad Esfahbod  {0x0C9D, POS_BELOW},
2058fdba506f0f1c66b50f8f4b114d624cb956d03b7Behdad Esfahbod  {0x0C9E, POS_BELOW},
2068fdba506f0f1c66b50f8f4b114d624cb956d03b7Behdad Esfahbod  {0x0C9F, POS_BELOW},
2078fdba506f0f1c66b50f8f4b114d624cb956d03b7Behdad Esfahbod  {0x0CA0, POS_BELOW},
2088fdba506f0f1c66b50f8f4b114d624cb956d03b7Behdad Esfahbod  {0x0CA1, POS_BELOW},
2098fdba506f0f1c66b50f8f4b114d624cb956d03b7Behdad Esfahbod  {0x0CA2, POS_BELOW},
2108fdba506f0f1c66b50f8f4b114d624cb956d03b7Behdad Esfahbod  {0x0CA3, POS_BELOW},
2118fdba506f0f1c66b50f8f4b114d624cb956d03b7Behdad Esfahbod  {0x0CA4, POS_BELOW},
2128fdba506f0f1c66b50f8f4b114d624cb956d03b7Behdad Esfahbod  {0x0CA5, POS_BELOW},
2138fdba506f0f1c66b50f8f4b114d624cb956d03b7Behdad Esfahbod  {0x0CA6, POS_BELOW},
2148fdba506f0f1c66b50f8f4b114d624cb956d03b7Behdad Esfahbod  {0x0CA7, POS_BELOW},
2158fdba506f0f1c66b50f8f4b114d624cb956d03b7Behdad Esfahbod  {0x0CA8, POS_BELOW},
2168fdba506f0f1c66b50f8f4b114d624cb956d03b7Behdad Esfahbod  {0x0CAA, POS_BELOW},
2178fdba506f0f1c66b50f8f4b114d624cb956d03b7Behdad Esfahbod  {0x0CAB, POS_BELOW},
2188fdba506f0f1c66b50f8f4b114d624cb956d03b7Behdad Esfahbod  {0x0CAC, POS_BELOW},
2198fdba506f0f1c66b50f8f4b114d624cb956d03b7Behdad Esfahbod  {0x0CAD, POS_BELOW},
2208fdba506f0f1c66b50f8f4b114d624cb956d03b7Behdad Esfahbod  {0x0CAE, POS_BELOW},
2218fdba506f0f1c66b50f8f4b114d624cb956d03b7Behdad Esfahbod  {0x0CAF, POS_BELOW},
2228fdba506f0f1c66b50f8f4b114d624cb956d03b7Behdad Esfahbod  {0x0CB0, POS_BELOW},
2238fdba506f0f1c66b50f8f4b114d624cb956d03b7Behdad Esfahbod  {0x0CB2, POS_BELOW},
2248fdba506f0f1c66b50f8f4b114d624cb956d03b7Behdad Esfahbod  {0x0CB3, POS_BELOW},
2258fdba506f0f1c66b50f8f4b114d624cb956d03b7Behdad Esfahbod  {0x0CB5, POS_BELOW},
2268fdba506f0f1c66b50f8f4b114d624cb956d03b7Behdad Esfahbod  {0x0CB6, POS_BELOW},
2278fdba506f0f1c66b50f8f4b114d624cb956d03b7Behdad Esfahbod  {0x0CB7, POS_BELOW},
2288fdba506f0f1c66b50f8f4b114d624cb956d03b7Behdad Esfahbod  {0x0CB8, POS_BELOW},
2298fdba506f0f1c66b50f8f4b114d624cb956d03b7Behdad Esfahbod  {0x0CB9, POS_BELOW},
2308fdba506f0f1c66b50f8f4b114d624cb956d03b7Behdad Esfahbod  {0x0CDE, POS_BELOW},
2318fdba506f0f1c66b50f8f4b114d624cb956d03b7Behdad Esfahbod  {0x0D2F, POS_POST},
2328fdba506f0f1c66b50f8f4b114d624cb956d03b7Behdad Esfahbod  {0x0D30, POS_POST},
2338fdba506f0f1c66b50f8f4b114d624cb956d03b7Behdad Esfahbod  {0x0D32, POS_BELOW},
2348fdba506f0f1c66b50f8f4b114d624cb956d03b7Behdad Esfahbod  {0x0D35, POS_POST},
23565988a145b4a52c37fd53c1473034f9e701f61d9Behdad Esfahbod};
23665988a145b4a52c37fd53c1473034f9e701f61d9Behdad Esfahbod
237352372ae5ea0998e40cf9fe43c22b6b610a5764eBehdad Esfahbod/* XXX
238352372ae5ea0998e40cf9fe43c22b6b610a5764eBehdad Esfahbod * This is a hack for now.  We should move this data into the main Indic table.
239352372ae5ea0998e40cf9fe43c22b6b610a5764eBehdad Esfahbod */
240352372ae5ea0998e40cf9fe43c22b6b610a5764eBehdad Esfahbodstatic const hb_codepoint_t ra_chars[] = {
241352372ae5ea0998e40cf9fe43c22b6b610a5764eBehdad Esfahbod  0x0930, /* Devanagari */
242352372ae5ea0998e40cf9fe43c22b6b610a5764eBehdad Esfahbod  0x09B0, /* Bengali */
243352372ae5ea0998e40cf9fe43c22b6b610a5764eBehdad Esfahbod  0x09F0, /* Bengali */
2448354e004e553856d7d743e0f0b4de4668484026aBehdad Esfahbod//0x09F1, /* Bengali */
245352372ae5ea0998e40cf9fe43c22b6b610a5764eBehdad Esfahbod//0x0A30, /* Gurmukhi */
246352372ae5ea0998e40cf9fe43c22b6b610a5764eBehdad Esfahbod  0x0AB0, /* Gujarati */
247352372ae5ea0998e40cf9fe43c22b6b610a5764eBehdad Esfahbod  0x0B30, /* Oriya */
248352372ae5ea0998e40cf9fe43c22b6b610a5764eBehdad Esfahbod//0x0BB0, /* Tamil */
249352372ae5ea0998e40cf9fe43c22b6b610a5764eBehdad Esfahbod//0x0C30, /* Telugu */
250352372ae5ea0998e40cf9fe43c22b6b610a5764eBehdad Esfahbod  0x0CB0, /* Kannada */
251352372ae5ea0998e40cf9fe43c22b6b610a5764eBehdad Esfahbod//0x0D30, /* Malayalam */
252352372ae5ea0998e40cf9fe43c22b6b610a5764eBehdad Esfahbod};
253352372ae5ea0998e40cf9fe43c22b6b610a5764eBehdad Esfahbod
254743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbodstatic int
255743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbodcompare_codepoint (const void *pa, const void *pb)
256743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod{
257743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod  hb_codepoint_t a = * (hb_codepoint_t *) pa;
258743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod  hb_codepoint_t b = * (hb_codepoint_t *) pb;
259743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod
260743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod  return a < b ? -1 : a == b ? 0 : +1;
261743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod}
262743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod
263743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbodstatic indic_position_t
264743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbodconsonant_position (hb_codepoint_t u)
265743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod{
266743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod  consonant_position_t *record;
267743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod
268743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod  record = (consonant_position_t *) bsearch (&u, consonant_positions,
269743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod					     ARRAY_LENGTH (consonant_positions),
270743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod					     sizeof (consonant_positions[0]),
271743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod					     compare_codepoint);
272743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod
273743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod  return record ? record->position : POS_BASE;
274743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod}
275743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod
276352372ae5ea0998e40cf9fe43c22b6b610a5764eBehdad Esfahbodstatic bool
277352372ae5ea0998e40cf9fe43c22b6b610a5764eBehdad Esfahbodis_ra (hb_codepoint_t u)
278352372ae5ea0998e40cf9fe43c22b6b610a5764eBehdad Esfahbod{
279352372ae5ea0998e40cf9fe43c22b6b610a5764eBehdad Esfahbod  return !!bsearch (&u, ra_chars,
280352372ae5ea0998e40cf9fe43c22b6b610a5764eBehdad Esfahbod		    ARRAY_LENGTH (ra_chars),
281352372ae5ea0998e40cf9fe43c22b6b610a5764eBehdad Esfahbod		    sizeof (ra_chars[0]),
282352372ae5ea0998e40cf9fe43c22b6b610a5764eBehdad Esfahbod		    compare_codepoint);
283352372ae5ea0998e40cf9fe43c22b6b610a5764eBehdad Esfahbod}
284352372ae5ea0998e40cf9fe43c22b6b610a5764eBehdad Esfahbod
2859ee27a928a989c71923cef82a9e9828f8e9ca051Behdad Esfahbodstatic bool
2869da0487cd452d780673e24329ce03e174a4ef83bBehdad Esfahbodis_joiner (const hb_glyph_info_t &info)
2879ee27a928a989c71923cef82a9e9828f8e9ca051Behdad Esfahbod{
2889da0487cd452d780673e24329ce03e174a4ef83bBehdad Esfahbod  return !!(FLAG (info.indic_category()) & (FLAG (OT_ZWJ) | FLAG (OT_ZWNJ)));
2899da0487cd452d780673e24329ce03e174a4ef83bBehdad Esfahbod}
2909da0487cd452d780673e24329ce03e174a4ef83bBehdad Esfahbod
2919da0487cd452d780673e24329ce03e174a4ef83bBehdad Esfahbodstatic bool
2929da0487cd452d780673e24329ce03e174a4ef83bBehdad Esfahbodis_consonant (const hb_glyph_info_t &info)
2939da0487cd452d780673e24329ce03e174a4ef83bBehdad Esfahbod{
2949da0487cd452d780673e24329ce03e174a4ef83bBehdad Esfahbod  return !!(FLAG (info.indic_category()) & (FLAG (OT_C) | FLAG (OT_Ra)));
2959ee27a928a989c71923cef82a9e9828f8e9ca051Behdad Esfahbod}
296c7fe56a1d5d3e969b6ec51cd9ecd471706a19568Behdad Esfahbod
297c7fe56a1d5d3e969b6ec51cd9ecd471706a19568Behdad Esfahbodstatic const struct {
298c7fe56a1d5d3e969b6ec51cd9ecd471706a19568Behdad Esfahbod  hb_tag_t tag;
299c7fe56a1d5d3e969b6ec51cd9ecd471706a19568Behdad Esfahbod  hb_bool_t is_global;
300c7fe56a1d5d3e969b6ec51cd9ecd471706a19568Behdad Esfahbod} indic_basic_features[] =
301b9ddbd55930228422e82b34a141ad1b6093f5376Behdad Esfahbod{
302c7fe56a1d5d3e969b6ec51cd9ecd471706a19568Behdad Esfahbod  {HB_TAG('n','u','k','t'), true},
303c7fe56a1d5d3e969b6ec51cd9ecd471706a19568Behdad Esfahbod  {HB_TAG('a','k','h','n'), false},
304c7fe56a1d5d3e969b6ec51cd9ecd471706a19568Behdad Esfahbod  {HB_TAG('r','p','h','f'), false},
305c7fe56a1d5d3e969b6ec51cd9ecd471706a19568Behdad Esfahbod  {HB_TAG('r','k','r','f'), false},
306c7fe56a1d5d3e969b6ec51cd9ecd471706a19568Behdad Esfahbod  {HB_TAG('p','r','e','f'), false},
307c7fe56a1d5d3e969b6ec51cd9ecd471706a19568Behdad Esfahbod  {HB_TAG('b','l','w','f'), false},
308c7fe56a1d5d3e969b6ec51cd9ecd471706a19568Behdad Esfahbod  {HB_TAG('h','a','l','f'), false},
309c7fe56a1d5d3e969b6ec51cd9ecd471706a19568Behdad Esfahbod  {HB_TAG('v','a','t','u'), true},
310c7fe56a1d5d3e969b6ec51cd9ecd471706a19568Behdad Esfahbod  {HB_TAG('p','s','t','f'), false},
3119da0487cd452d780673e24329ce03e174a4ef83bBehdad Esfahbod  {HB_TAG('c','j','c','t'), false},
312c7fe56a1d5d3e969b6ec51cd9ecd471706a19568Behdad Esfahbod};
313c7fe56a1d5d3e969b6ec51cd9ecd471706a19568Behdad Esfahbod
314c7fe56a1d5d3e969b6ec51cd9ecd471706a19568Behdad Esfahbod/* Same order as the indic_basic_features array */
315c7fe56a1d5d3e969b6ec51cd9ecd471706a19568Behdad Esfahbodenum {
316c7fe56a1d5d3e969b6ec51cd9ecd471706a19568Behdad Esfahbod  _NUKT,
317c7fe56a1d5d3e969b6ec51cd9ecd471706a19568Behdad Esfahbod  AKHN,
318c7fe56a1d5d3e969b6ec51cd9ecd471706a19568Behdad Esfahbod  RPHF,
319c7fe56a1d5d3e969b6ec51cd9ecd471706a19568Behdad Esfahbod  RKRF,
320c7fe56a1d5d3e969b6ec51cd9ecd471706a19568Behdad Esfahbod  PREF,
321c7fe56a1d5d3e969b6ec51cd9ecd471706a19568Behdad Esfahbod  BLWF,
322c7fe56a1d5d3e969b6ec51cd9ecd471706a19568Behdad Esfahbod  HALF,
323c7fe56a1d5d3e969b6ec51cd9ecd471706a19568Behdad Esfahbod  _VATU,
324c7fe56a1d5d3e969b6ec51cd9ecd471706a19568Behdad Esfahbod  PSTF,
3259da0487cd452d780673e24329ce03e174a4ef83bBehdad Esfahbod  CJCT,
326b9ddbd55930228422e82b34a141ad1b6093f5376Behdad Esfahbod};
327b9ddbd55930228422e82b34a141ad1b6093f5376Behdad Esfahbod
328b9ddbd55930228422e82b34a141ad1b6093f5376Behdad Esfahbodstatic const hb_tag_t indic_other_features[] =
329b9ddbd55930228422e82b34a141ad1b6093f5376Behdad Esfahbod{
330b9ddbd55930228422e82b34a141ad1b6093f5376Behdad Esfahbod  HB_TAG('p','r','e','s'),
331b9ddbd55930228422e82b34a141ad1b6093f5376Behdad Esfahbod  HB_TAG('a','b','v','s'),
332b9ddbd55930228422e82b34a141ad1b6093f5376Behdad Esfahbod  HB_TAG('b','l','w','s'),
333b9ddbd55930228422e82b34a141ad1b6093f5376Behdad Esfahbod  HB_TAG('p','s','t','s'),
334b9ddbd55930228422e82b34a141ad1b6093f5376Behdad Esfahbod  HB_TAG('h','a','l','n'),
335b9ddbd55930228422e82b34a141ad1b6093f5376Behdad Esfahbod
336b9ddbd55930228422e82b34a141ad1b6093f5376Behdad Esfahbod  HB_TAG('d','i','s','t'),
337b9ddbd55930228422e82b34a141ad1b6093f5376Behdad Esfahbod  HB_TAG('a','b','v','m'),
338b9ddbd55930228422e82b34a141ad1b6093f5376Behdad Esfahbod  HB_TAG('b','l','w','m'),
339b9ddbd55930228422e82b34a141ad1b6093f5376Behdad Esfahbod};
340b9ddbd55930228422e82b34a141ad1b6093f5376Behdad Esfahbod
341743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod
342743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbodstatic void
343743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbodinitial_reordering (const hb_ot_map_t *map,
344743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod		    hb_face_t *face,
345743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod		    hb_buffer_t *buffer,
346743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod		    void *user_data HB_UNUSED);
347f6fd3780e12b23ff7ed3743497c8996e71dcb064Behdad Esfahbodstatic void
348f6fd3780e12b23ff7ed3743497c8996e71dcb064Behdad Esfahbodfinal_reordering (const hb_ot_map_t *map,
349f6fd3780e12b23ff7ed3743497c8996e71dcb064Behdad Esfahbod		  hb_face_t *face,
350f6fd3780e12b23ff7ed3743497c8996e71dcb064Behdad Esfahbod		  hb_buffer_t *buffer,
351743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod		  void *user_data HB_UNUSED);
352b9ddbd55930228422e82b34a141ad1b6093f5376Behdad Esfahbod
353b9ddbd55930228422e82b34a141ad1b6093f5376Behdad Esfahbodvoid
35476f76812ac7cca8ac6935952a2360d5e151480faBehdad Esfahbod_hb_ot_shape_complex_collect_features_indic (hb_ot_map_builder_t *map, const hb_segment_properties_t  *props)
355b9ddbd55930228422e82b34a141ad1b6093f5376Behdad Esfahbod{
356f6fd3780e12b23ff7ed3743497c8996e71dcb064Behdad Esfahbod  map->add_bool_feature (HB_TAG('l','o','c','l'));
357a54a5505a35eef5315a8e2e7a79502901e3eff5fBehdad Esfahbod  /* The Indic specs do not require ccmp, but we apply it here since if
358a54a5505a35eef5315a8e2e7a79502901e3eff5fBehdad Esfahbod   * there is a use of it, it's typically at the beginning. */
359f6fd3780e12b23ff7ed3743497c8996e71dcb064Behdad Esfahbod  map->add_bool_feature (HB_TAG('c','c','m','p'));
360f6fd3780e12b23ff7ed3743497c8996e71dcb064Behdad Esfahbod
361743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod  map->add_gsub_pause (initial_reordering, NULL);
362f6fd3780e12b23ff7ed3743497c8996e71dcb064Behdad Esfahbod
363b9ddbd55930228422e82b34a141ad1b6093f5376Behdad Esfahbod  for (unsigned int i = 0; i < ARRAY_LENGTH (indic_basic_features); i++)
36476f76812ac7cca8ac6935952a2360d5e151480faBehdad Esfahbod    map->add_bool_feature (indic_basic_features[i].tag, indic_basic_features[i].is_global);
365b9ddbd55930228422e82b34a141ad1b6093f5376Behdad Esfahbod
366f6fd3780e12b23ff7ed3743497c8996e71dcb064Behdad Esfahbod  map->add_gsub_pause (final_reordering, NULL);
367f6fd3780e12b23ff7ed3743497c8996e71dcb064Behdad Esfahbod
368b9ddbd55930228422e82b34a141ad1b6093f5376Behdad Esfahbod  for (unsigned int i = 0; i < ARRAY_LENGTH (indic_other_features); i++)
36976f76812ac7cca8ac6935952a2360d5e151480faBehdad Esfahbod    map->add_bool_feature (indic_other_features[i], true);
370b9ddbd55930228422e82b34a141ad1b6093f5376Behdad Esfahbod}
371b9ddbd55930228422e82b34a141ad1b6093f5376Behdad Esfahbod
372867361c3ad39629a8d5b7dc48d558a1c19e37d43Behdad Esfahbod
37302cdf743c2ec345a44d4fcf865594b6ac13fccd0Behdad Esfahbodbool
37402cdf743c2ec345a44d4fcf865594b6ac13fccd0Behdad Esfahbod_hb_ot_shape_complex_prefer_decomposed_indic (void)
37502cdf743c2ec345a44d4fcf865594b6ac13fccd0Behdad Esfahbod{
37602cdf743c2ec345a44d4fcf865594b6ac13fccd0Behdad Esfahbod  /* We want split matras decomposed by the common shaping logic. */
37702cdf743c2ec345a44d4fcf865594b6ac13fccd0Behdad Esfahbod  return TRUE;
37802cdf743c2ec345a44d4fcf865594b6ac13fccd0Behdad Esfahbod}
37902cdf743c2ec345a44d4fcf865594b6ac13fccd0Behdad Esfahbod
380867361c3ad39629a8d5b7dc48d558a1c19e37d43Behdad Esfahbod
381b9ddbd55930228422e82b34a141ad1b6093f5376Behdad Esfahbodvoid
38276f76812ac7cca8ac6935952a2360d5e151480faBehdad Esfahbod_hb_ot_shape_complex_setup_masks_indic (hb_ot_map_t *map, hb_buffer_t *buffer)
383b9ddbd55930228422e82b34a141ad1b6093f5376Behdad Esfahbod{
3849f9bcceca6321d5a5812f878de1de39901349a78Behdad Esfahbod  HB_BUFFER_ALLOCATE_VAR (buffer, indic_category);
3859f9bcceca6321d5a5812f878de1de39901349a78Behdad Esfahbod  HB_BUFFER_ALLOCATE_VAR (buffer, indic_position);
3869f9bcceca6321d5a5812f878de1de39901349a78Behdad Esfahbod
387743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod  /* We cannot setup masks here.  We save information about characters
388743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod   * and setup masks later on in a pause-callback. */
389743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod
390743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod  unsigned int count = buffer->len;
391b9ddbd55930228422e82b34a141ad1b6093f5376Behdad Esfahbod  for (unsigned int i = 0; i < count; i++)
392b9ddbd55930228422e82b34a141ad1b6093f5376Behdad Esfahbod  {
39376f76812ac7cca8ac6935952a2360d5e151480faBehdad Esfahbod    unsigned int type = get_indic_categories (buffer->info[i].codepoint);
394b9ddbd55930228422e82b34a141ad1b6093f5376Behdad Esfahbod
39576f76812ac7cca8ac6935952a2360d5e151480faBehdad Esfahbod    buffer->info[i].indic_category() = type & 0x0F;
39676f76812ac7cca8ac6935952a2360d5e151480faBehdad Esfahbod    buffer->info[i].indic_position() = type >> 4;
397743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod
398352372ae5ea0998e40cf9fe43c22b6b610a5764eBehdad Esfahbod    if (buffer->info[i].indic_category() == OT_C) {
399743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod      buffer->info[i].indic_position() = consonant_position (buffer->info[i].codepoint);
400352372ae5ea0998e40cf9fe43c22b6b610a5764eBehdad Esfahbod      if (is_ra (buffer->info[i].codepoint))
401352372ae5ea0998e40cf9fe43c22b6b610a5764eBehdad Esfahbod	buffer->info[i].indic_category() = OT_Ra;
4029da0487cd452d780673e24329ce03e174a4ef83bBehdad Esfahbod    } else if (buffer->info[i].codepoint == 0x200C)
4039da0487cd452d780673e24329ce03e174a4ef83bBehdad Esfahbod      buffer->info[i].indic_category() = OT_ZWNJ;
4049da0487cd452d780673e24329ce03e174a4ef83bBehdad Esfahbod    else if (buffer->info[i].codepoint == 0x200D)
4059da0487cd452d780673e24329ce03e174a4ef83bBehdad Esfahbod      buffer->info[i].indic_category() = OT_ZWJ;
406b9ddbd55930228422e82b34a141ad1b6093f5376Behdad Esfahbod  }
407743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod}
408b9ddbd55930228422e82b34a141ad1b6093f5376Behdad Esfahbod
40945d6f29f15f1d2323bcaa2498aed23ff0c8a1567Behdad Esfahbodstatic int
41045d6f29f15f1d2323bcaa2498aed23ff0c8a1567Behdad Esfahbodcompare_indic_order (const hb_glyph_info_t *pa, const hb_glyph_info_t *pb)
41145d6f29f15f1d2323bcaa2498aed23ff0c8a1567Behdad Esfahbod{
41245d6f29f15f1d2323bcaa2498aed23ff0c8a1567Behdad Esfahbod  int a = pa->indic_position();
41345d6f29f15f1d2323bcaa2498aed23ff0c8a1567Behdad Esfahbod  int b = pb->indic_position();
41445d6f29f15f1d2323bcaa2498aed23ff0c8a1567Behdad Esfahbod
41545d6f29f15f1d2323bcaa2498aed23ff0c8a1567Behdad Esfahbod  return a < b ? -1 : a == b ? 0 : +1;
41645d6f29f15f1d2323bcaa2498aed23ff0c8a1567Behdad Esfahbod}
417867361c3ad39629a8d5b7dc48d558a1c19e37d43Behdad Esfahbod
418743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbodstatic void
419743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbodfound_consonant_syllable (const hb_ot_map_t *map, hb_buffer_t *buffer, hb_mask_t *mask_array,
420743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod			  unsigned int start, unsigned int end)
421743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod{
422743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod  unsigned int i;
423ee58f3bc75d2d071a71b94063bf12205a5871acbBehdad Esfahbod  hb_glyph_info_t *info = buffer->info;
424743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod
425743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod  /* Comments from:
426743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod   * https://www.microsoft.com/typography/otfntdev/devanot/shaping.aspx */
427743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod
428743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod  /* 1. Find base consonant:
429743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod   *
430743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod   * The shaping engine finds the base consonant of the syllable, using the
431743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod   * following algorithm: starting from the end of the syllable, move backwards
432743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod   * until a consonant is found that does not have a below-base or post-base
433743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod   * form (post-base forms have to follow below-base forms), or that is not a
434743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod   * pre-base reordering Ra, or arrive at the first consonant. The consonant
435743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod   * stopped at will be the base.
436743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod   *
437743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod   *   o If the syllable starts with Ra + Halant (in a script that has Reph)
438743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod   *     and has more than one consonant, Ra is excluded from candidates for
439743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod   *     base consonants.
440743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod   */
441743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod
442743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod  unsigned int base = 0;
443743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod
444743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod  /* -> starting from the end of the syllable, move backwards */
445743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod  i = end;
446743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod  do {
447743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod    i--;
448743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod    /* -> until a consonant is found */
44997158392a5899ddb739afaac925128f33f699bd7Behdad Esfahbod    if (is_consonant (info[i]))
450743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod    {
451743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod      /* -> that does not have a below-base or post-base form
452743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod       * (post-base forms have to follow below-base forms), */
453ee58f3bc75d2d071a71b94063bf12205a5871acbBehdad Esfahbod      if (info[i].indic_position() != POS_BELOW &&
454ee58f3bc75d2d071a71b94063bf12205a5871acbBehdad Esfahbod	  info[i].indic_position() != POS_POST)
455743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod      {
456743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod        base = i;
457743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod	break;
458743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod      }
459743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod
460743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod      /* TODO: or that is not a pre-base reordering Ra, */
461743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod
462743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod      /* -> or arrive at the first consonant. The consonant stopped at will be the base. */
463743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod      base = i;
464743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod    }
465743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod  } while (i > start);
466743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod  if (base < start)
467743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod    base = start; /* Just in case... */
468743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod
469743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod  /* TODO
470743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod   * If the syllable starts with Ra + Halant (in a script that has Reph)
471743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod   * and has more than one consonant, Ra is excluded from candidates for
472743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod   * base consonants. */
473743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod
474743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod
475743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod  /* 2. Decompose and reorder Matras:
476743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod   *
477743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod   * Each matra and any syllable modifier sign in the cluster are moved to the
478743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod   * appropriate position relative to the consonant(s) in the cluster. The
479743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod   * shaping engine decomposes two- or three-part matras into their constituent
480743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod   * parts before any repositioning. Matra characters are classified by which
481743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod   * consonant in a conjunct they have affinity for and are reordered to the
482743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod   * following positions:
483743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod   *
484743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod   *   o Before first half form in the syllable
485743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod   *   o After subjoined consonants
486743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod   *   o After post-form consonant
487743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod   *   o After main consonant (for above marks)
488743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod   *
489743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod   * IMPLEMENTATION NOTES:
490743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod   *
491743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod   * The normalize() routine has already decomposed matras for us, so we don't
492743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod   * need to worry about that.
493743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod   */
494743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod
495743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod
496743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod  /* 3.  Reorder marks to canonical order:
497743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod   *
498743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod   * Adjacent nukta and halant or nukta and vedic sign are always repositioned
499743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod   * if necessary, so that the nukta is first.
500743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod   *
501743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod   * IMPLEMENTATION NOTES:
502743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod   *
503743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod   * We don't need to do this: the normalize() routine already did this for us.
504743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod   */
505743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod
506743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod
50745d6f29f15f1d2323bcaa2498aed23ff0c8a1567Behdad Esfahbod  /* Reorder characters */
50845d6f29f15f1d2323bcaa2498aed23ff0c8a1567Behdad Esfahbod
50945d6f29f15f1d2323bcaa2498aed23ff0c8a1567Behdad Esfahbod  for (i = start; i < base; i++)
510ee58f3bc75d2d071a71b94063bf12205a5871acbBehdad Esfahbod    info[i].indic_position() = POS_PRE;
511ee58f3bc75d2d071a71b94063bf12205a5871acbBehdad Esfahbod  info[base].indic_position() = POS_BASE;
51245d6f29f15f1d2323bcaa2498aed23ff0c8a1567Behdad Esfahbod
513fd06bf56110e73826b3d5c73ac964e2609450d46Behdad Esfahbod
514fd06bf56110e73826b3d5c73ac964e2609450d46Behdad Esfahbod  /* Handle beginning Ra */
5150d8f8a177c4bfd4dc642a353bab8d03674e839acBehdad Esfahbod  if (start + 3 <= end &&
516fd06bf56110e73826b3d5c73ac964e2609450d46Behdad Esfahbod      info[start].indic_category() == OT_Ra &&
5179ee27a928a989c71923cef82a9e9828f8e9ca051Behdad Esfahbod      info[start + 1].indic_category() == OT_H &&
5180d8f8a177c4bfd4dc642a353bab8d03674e839acBehdad Esfahbod      !is_joiner (info[start + 2]))
519fd06bf56110e73826b3d5c73ac964e2609450d46Behdad Esfahbod   {
520fd06bf56110e73826b3d5c73ac964e2609450d46Behdad Esfahbod    info[start].indic_position() = POS_POST;
521fd06bf56110e73826b3d5c73ac964e2609450d46Behdad Esfahbod    info[start].mask = mask_array[RPHF];
522fd06bf56110e73826b3d5c73ac964e2609450d46Behdad Esfahbod   }
523fd06bf56110e73826b3d5c73ac964e2609450d46Behdad Esfahbod
524f5bc2725cb892264ba223e0a49f7fd2c622a0730Behdad Esfahbod  /* For old-style Indic script tags, move the first post-base Halant after
525f5bc2725cb892264ba223e0a49f7fd2c622a0730Behdad Esfahbod   * last consonant. */
526f5bc2725cb892264ba223e0a49f7fd2c622a0730Behdad Esfahbod  if ((map->get_chosen_script (0) & 0x000000FF) != '2') {
527f5bc2725cb892264ba223e0a49f7fd2c622a0730Behdad Esfahbod    /* We should only do this for Indic scripts which have a version two I guess. */
528f5bc2725cb892264ba223e0a49f7fd2c622a0730Behdad Esfahbod    for (i = base + 1; i < end; i++)
529f5bc2725cb892264ba223e0a49f7fd2c622a0730Behdad Esfahbod      if (info[i].indic_category() == OT_H) {
530f5bc2725cb892264ba223e0a49f7fd2c622a0730Behdad Esfahbod        unsigned int j;
531f5bc2725cb892264ba223e0a49f7fd2c622a0730Behdad Esfahbod        for (j = end - 1; j > i; j--)
532f5bc2725cb892264ba223e0a49f7fd2c622a0730Behdad Esfahbod	  if ((FLAG (info[j].indic_category()) & (FLAG (OT_C) | FLAG (OT_Ra))))
533f5bc2725cb892264ba223e0a49f7fd2c622a0730Behdad Esfahbod	    break;
534f5bc2725cb892264ba223e0a49f7fd2c622a0730Behdad Esfahbod	if (j > i) {
535f5bc2725cb892264ba223e0a49f7fd2c622a0730Behdad Esfahbod	  /* Move Halant to after last consonant. */
536f5bc2725cb892264ba223e0a49f7fd2c622a0730Behdad Esfahbod	  hb_glyph_info_t t = info[i];
537f5bc2725cb892264ba223e0a49f7fd2c622a0730Behdad Esfahbod	  memmove (&info[i], &info[i + 1], (j - i) * sizeof (info[0]));
538f5bc2725cb892264ba223e0a49f7fd2c622a0730Behdad Esfahbod	  info[j] = t;
539f5bc2725cb892264ba223e0a49f7fd2c622a0730Behdad Esfahbod	}
540f5bc2725cb892264ba223e0a49f7fd2c622a0730Behdad Esfahbod        break;
541f5bc2725cb892264ba223e0a49f7fd2c622a0730Behdad Esfahbod      }
542f5bc2725cb892264ba223e0a49f7fd2c622a0730Behdad Esfahbod  }
543f5bc2725cb892264ba223e0a49f7fd2c622a0730Behdad Esfahbod
54445d6f29f15f1d2323bcaa2498aed23ff0c8a1567Behdad Esfahbod  /* Attach ZWJ, ZWNJ, nukta, and halant to previous char to move with them. */
54545d6f29f15f1d2323bcaa2498aed23ff0c8a1567Behdad Esfahbod  for (i = start + 1; i < end; i++)
546ee58f3bc75d2d071a71b94063bf12205a5871acbBehdad Esfahbod    if ((FLAG (info[i].indic_category()) &
54745d6f29f15f1d2323bcaa2498aed23ff0c8a1567Behdad Esfahbod	 (FLAG (OT_ZWNJ) | FLAG (OT_ZWJ) | FLAG (OT_N) | FLAG (OT_H))))
548ee58f3bc75d2d071a71b94063bf12205a5871acbBehdad Esfahbod      info[i].indic_position() = info[i - 1].indic_position();
54945d6f29f15f1d2323bcaa2498aed23ff0c8a1567Behdad Esfahbod
55045d6f29f15f1d2323bcaa2498aed23ff0c8a1567Behdad Esfahbod  /* We do bubble-sort, skip malicious clusters attempts */
55145d6f29f15f1d2323bcaa2498aed23ff0c8a1567Behdad Esfahbod  if (end - start > 20)
55245d6f29f15f1d2323bcaa2498aed23ff0c8a1567Behdad Esfahbod    return;
55345d6f29f15f1d2323bcaa2498aed23ff0c8a1567Behdad Esfahbod
55445d6f29f15f1d2323bcaa2498aed23ff0c8a1567Behdad Esfahbod  /* Sit tight, rock 'n roll! */
555ee58f3bc75d2d071a71b94063bf12205a5871acbBehdad Esfahbod  hb_bubble_sort (info + start, end - start, compare_indic_order);
55645d6f29f15f1d2323bcaa2498aed23ff0c8a1567Behdad Esfahbod
557743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod  /* Setup masks now */
558743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod
559743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod  /* Pre-base */
560743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod  for (i = start; i < base; i++)
5619da0487cd452d780673e24329ce03e174a4ef83bBehdad Esfahbod    info[i].mask  |= mask_array[HALF] | mask_array[AKHN] | mask_array[CJCT];
562743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod  /* Base */
5639da0487cd452d780673e24329ce03e174a4ef83bBehdad Esfahbod  info[base].mask |= mask_array[AKHN] | mask_array[CJCT];
564743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod  /* Post-base */
565743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod  for (i = base + 1; i < end; i++)
5669da0487cd452d780673e24329ce03e174a4ef83bBehdad Esfahbod    info[i].mask  |= mask_array[BLWF] | mask_array[PSTF] | mask_array[CJCT];
5679da0487cd452d780673e24329ce03e174a4ef83bBehdad Esfahbod
5689da0487cd452d780673e24329ce03e174a4ef83bBehdad Esfahbod  /* Apply ZWJ/ZWNJ effects */
5699da0487cd452d780673e24329ce03e174a4ef83bBehdad Esfahbod  for (i = start + 1; i < end; i++)
5709da0487cd452d780673e24329ce03e174a4ef83bBehdad Esfahbod    if (is_joiner (info[i])) {
5719da0487cd452d780673e24329ce03e174a4ef83bBehdad Esfahbod      bool non_joiner = info[i].indic_category() == OT_ZWNJ;
5729da0487cd452d780673e24329ce03e174a4ef83bBehdad Esfahbod      unsigned int j = i - 1;
5739da0487cd452d780673e24329ce03e174a4ef83bBehdad Esfahbod
5749da0487cd452d780673e24329ce03e174a4ef83bBehdad Esfahbod      do {
5759da0487cd452d780673e24329ce03e174a4ef83bBehdad Esfahbod	info[j].mask &= !mask_array[HALF];
5769da0487cd452d780673e24329ce03e174a4ef83bBehdad Esfahbod	if (non_joiner)
5779da0487cd452d780673e24329ce03e174a4ef83bBehdad Esfahbod	  info[j].mask &= !mask_array[CJCT];
5789da0487cd452d780673e24329ce03e174a4ef83bBehdad Esfahbod	j--;
5799da0487cd452d780673e24329ce03e174a4ef83bBehdad Esfahbod      } while (j > start && !is_consonant (info[j]));
5809da0487cd452d780673e24329ce03e174a4ef83bBehdad Esfahbod    }
581743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod}
582743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod
583743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod
584743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbodstatic void
585743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbodfound_vowel_syllable (const hb_ot_map_t *map, hb_buffer_t *buffer, hb_mask_t *mask_array,
586743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod		      unsigned int start, unsigned int end)
587743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod{
588743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod  /* TODO
589743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod   * Not clear to me how this should work.  Do the matras move to before the
590743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod   * independent vowel?  No idea.
591743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod   */
592743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod}
593743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod
594743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbodstatic void
595743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbodfound_standalone_cluster (const hb_ot_map_t *map, hb_buffer_t *buffer, hb_mask_t *mask_array,
596743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod			  unsigned int start, unsigned int end)
597743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod{
598743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod  /* TODO
599743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod   * Easiest thing to do here is to convert the NBSP to consonant and
600743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod   * call found_consonant_syllable.
601743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod   */
602743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod}
603743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod
604743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbodstatic void
605743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbodfound_non_indic (const hb_ot_map_t *map, hb_buffer_t *buffer, hb_mask_t *mask_array,
606743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod		 unsigned int start, unsigned int end)
607743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod{
608743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod  /* Nothing to do right now.  If we ever switch to using the output
609743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod   * buffer in the reordering process, we'd need to next_glyph() here. */
610743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod}
611743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod
612743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod#include "hb-ot-shape-complex-indic-machine.hh"
613743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod
614743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbodstatic void
6159da0487cd452d780673e24329ce03e174a4ef83bBehdad Esfahbodremove_joiners (hb_buffer_t *buffer)
6169da0487cd452d780673e24329ce03e174a4ef83bBehdad Esfahbod{
6179da0487cd452d780673e24329ce03e174a4ef83bBehdad Esfahbod  buffer->clear_output ();
6189da0487cd452d780673e24329ce03e174a4ef83bBehdad Esfahbod  unsigned int count = buffer->len;
6199da0487cd452d780673e24329ce03e174a4ef83bBehdad Esfahbod  for (buffer->idx = 0; buffer->idx < count;)
6209da0487cd452d780673e24329ce03e174a4ef83bBehdad Esfahbod    if (unlikely (is_joiner (buffer->info[buffer->idx])))
6219da0487cd452d780673e24329ce03e174a4ef83bBehdad Esfahbod      buffer->skip_glyph ();
6229da0487cd452d780673e24329ce03e174a4ef83bBehdad Esfahbod    else
6239da0487cd452d780673e24329ce03e174a4ef83bBehdad Esfahbod      buffer->next_glyph ();
6249da0487cd452d780673e24329ce03e174a4ef83bBehdad Esfahbod
6259da0487cd452d780673e24329ce03e174a4ef83bBehdad Esfahbod  buffer->swap_buffers ();
6269da0487cd452d780673e24329ce03e174a4ef83bBehdad Esfahbod}
6279da0487cd452d780673e24329ce03e174a4ef83bBehdad Esfahbod
6289da0487cd452d780673e24329ce03e174a4ef83bBehdad Esfahbodstatic void
629743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbodinitial_reordering (const hb_ot_map_t *map,
630743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod		    hb_face_t *face,
631743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod		    hb_buffer_t *buffer,
632743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod		    void *user_data HB_UNUSED)
633743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod{
634b9ddbd55930228422e82b34a141ad1b6093f5376Behdad Esfahbod  hb_mask_t mask_array[ARRAY_LENGTH (indic_basic_features)] = {0};
635b9ddbd55930228422e82b34a141ad1b6093f5376Behdad Esfahbod  unsigned int num_masks = ARRAY_LENGTH (indic_basic_features);
636b9ddbd55930228422e82b34a141ad1b6093f5376Behdad Esfahbod  for (unsigned int i = 0; i < num_masks; i++)
63776f76812ac7cca8ac6935952a2360d5e151480faBehdad Esfahbod    mask_array[i] = map->get_1_mask (indic_basic_features[i].tag);
638743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod
639743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod  find_syllables (map, buffer, mask_array);
6409da0487cd452d780673e24329ce03e174a4ef83bBehdad Esfahbod
6419da0487cd452d780673e24329ce03e174a4ef83bBehdad Esfahbod  remove_joiners (buffer);
642b9ddbd55930228422e82b34a141ad1b6093f5376Behdad Esfahbod}
643b9ddbd55930228422e82b34a141ad1b6093f5376Behdad Esfahbod
644743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbodstatic void
645743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbodfinal_reordering (const hb_ot_map_t *map,
646743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod		  hb_face_t *face,
647743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod		  hb_buffer_t *buffer,
648743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod		  void *user_data HB_UNUSED)
649743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod{
650743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod  HB_BUFFER_DEALLOCATE_VAR (buffer, indic_category);
651743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod  HB_BUFFER_DEALLOCATE_VAR (buffer, indic_position);
652743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod}
653743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod
654743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod
655b9ddbd55930228422e82b34a141ad1b6093f5376Behdad Esfahbod
656b9ddbd55930228422e82b34a141ad1b6093f5376Behdad EsfahbodHB_END_DECLS
657