hb-ot-shape-complex-indic.cc revision 5e72071062c015237b79fbd0521341a63166a204
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 4425e72071062c015237b79fbd0521341a63166a204Behdad Esfahbod unsigned int base = end; 443743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod 444743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod /* -> starting from the end of the syllable, move backwards */ 445743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod i = end; 4465e72071062c015237b79fbd0521341a63166a204Behdad Esfahbod unsigned int limit = start; 4475e72071062c015237b79fbd0521341a63166a204Behdad Esfahbod if (info[start].indic_category() == OT_Ra && start + 2 <= end) { 4485e72071062c015237b79fbd0521341a63166a204Behdad Esfahbod limit += 2; 4495e72071062c015237b79fbd0521341a63166a204Behdad Esfahbod base = start; 4505e72071062c015237b79fbd0521341a63166a204Behdad Esfahbod }; 451743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod do { 452743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod i--; 453743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod /* -> until a consonant is found */ 45497158392a5899ddb739afaac925128f33f699bd7Behdad Esfahbod if (is_consonant (info[i])) 455743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod { 456743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod /* -> that does not have a below-base or post-base form 457743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod * (post-base forms have to follow below-base forms), */ 458ee58f3bc75d2d071a71b94063bf12205a5871acbBehdad Esfahbod if (info[i].indic_position() != POS_BELOW && 459ee58f3bc75d2d071a71b94063bf12205a5871acbBehdad Esfahbod info[i].indic_position() != POS_POST) 460743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod { 461743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod base = i; 462743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod break; 463743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod } 464743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod 465cfd4382ec1af91640129551697de36fd42c0849aBehdad Esfahbod /* -> or that is not a pre-base reordering Ra, 466cfd4382ec1af91640129551697de36fd42c0849aBehdad Esfahbod * 467e7be05702447ae270d797398132c1930cd3a9b86Behdad Esfahbod * TODO 468e7be05702447ae270d797398132c1930cd3a9b86Behdad Esfahbod */ 469e7be05702447ae270d797398132c1930cd3a9b86Behdad Esfahbod 470e7be05702447ae270d797398132c1930cd3a9b86Behdad Esfahbod /* -> o If the syllable starts with Ra + Halant (in a script that has Reph) 471e7be05702447ae270d797398132c1930cd3a9b86Behdad Esfahbod * and has more than one consonant, Ra is excluded from candidates for 472e7be05702447ae270d797398132c1930cd3a9b86Behdad Esfahbod * base consonants. 473cfd4382ec1af91640129551697de36fd42c0849aBehdad Esfahbod * 474cfd4382ec1af91640129551697de36fd42c0849aBehdad Esfahbod * IMPLEMENTATION NOTES: 475cfd4382ec1af91640129551697de36fd42c0849aBehdad Esfahbod * 476cfd4382ec1af91640129551697de36fd42c0849aBehdad Esfahbod * We do this by adjusting limit accordingly before entering the loop. 477cfd4382ec1af91640129551697de36fd42c0849aBehdad Esfahbod */ 478cfd4382ec1af91640129551697de36fd42c0849aBehdad Esfahbod 479cfd4382ec1af91640129551697de36fd42c0849aBehdad Esfahbod /* -> or arrive at the first consonant. The consonant stopped at will 480cfd4382ec1af91640129551697de36fd42c0849aBehdad Esfahbod * be the base. */ 481743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod base = i; 482743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod } 4835e72071062c015237b79fbd0521341a63166a204Behdad Esfahbod else 4845e72071062c015237b79fbd0521341a63166a204Behdad Esfahbod if (is_joiner (info[i])) 4855e72071062c015237b79fbd0521341a63166a204Behdad Esfahbod break; 486cfd4382ec1af91640129551697de36fd42c0849aBehdad Esfahbod } while (i > limit); 487743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod if (base < start) 488743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod base = start; /* Just in case... */ 489743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod 490743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod 491743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod /* 2. Decompose and reorder Matras: 492743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod * 493743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod * Each matra and any syllable modifier sign in the cluster are moved to the 494743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod * appropriate position relative to the consonant(s) in the cluster. The 495743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod * shaping engine decomposes two- or three-part matras into their constituent 496743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod * parts before any repositioning. Matra characters are classified by which 497743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod * consonant in a conjunct they have affinity for and are reordered to the 498743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod * following positions: 499743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod * 500743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod * o Before first half form in the syllable 501743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod * o After subjoined consonants 502743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod * o After post-form consonant 503743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod * o After main consonant (for above marks) 504743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod * 505743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod * IMPLEMENTATION NOTES: 506743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod * 507743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod * The normalize() routine has already decomposed matras for us, so we don't 508743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod * need to worry about that. 509743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod */ 510743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod 511743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod 512743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod /* 3. Reorder marks to canonical order: 513743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod * 514743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod * Adjacent nukta and halant or nukta and vedic sign are always repositioned 515743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod * if necessary, so that the nukta is first. 516743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod * 517743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod * IMPLEMENTATION NOTES: 518743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod * 519743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod * We don't need to do this: the normalize() routine already did this for us. 520743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod */ 521743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod 522743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod 52345d6f29f15f1d2323bcaa2498aed23ff0c8a1567Behdad Esfahbod /* Reorder characters */ 52445d6f29f15f1d2323bcaa2498aed23ff0c8a1567Behdad Esfahbod 52545d6f29f15f1d2323bcaa2498aed23ff0c8a1567Behdad Esfahbod for (i = start; i < base; i++) 526ee58f3bc75d2d071a71b94063bf12205a5871acbBehdad Esfahbod info[i].indic_position() = POS_PRE; 527ee58f3bc75d2d071a71b94063bf12205a5871acbBehdad Esfahbod info[base].indic_position() = POS_BASE; 52845d6f29f15f1d2323bcaa2498aed23ff0c8a1567Behdad Esfahbod 529fd06bf56110e73826b3d5c73ac964e2609450d46Behdad Esfahbod 530fd06bf56110e73826b3d5c73ac964e2609450d46Behdad Esfahbod /* Handle beginning Ra */ 5310d8f8a177c4bfd4dc642a353bab8d03674e839acBehdad Esfahbod if (start + 3 <= end && 532fd06bf56110e73826b3d5c73ac964e2609450d46Behdad Esfahbod info[start].indic_category() == OT_Ra && 5339ee27a928a989c71923cef82a9e9828f8e9ca051Behdad Esfahbod info[start + 1].indic_category() == OT_H && 5340d8f8a177c4bfd4dc642a353bab8d03674e839acBehdad Esfahbod !is_joiner (info[start + 2])) 535fd06bf56110e73826b3d5c73ac964e2609450d46Behdad Esfahbod { 536fd06bf56110e73826b3d5c73ac964e2609450d46Behdad Esfahbod info[start].indic_position() = POS_POST; 537fd06bf56110e73826b3d5c73ac964e2609450d46Behdad Esfahbod info[start].mask = mask_array[RPHF]; 538fd06bf56110e73826b3d5c73ac964e2609450d46Behdad Esfahbod } 539fd06bf56110e73826b3d5c73ac964e2609450d46Behdad Esfahbod 540f5bc2725cb892264ba223e0a49f7fd2c622a0730Behdad Esfahbod /* For old-style Indic script tags, move the first post-base Halant after 541f5bc2725cb892264ba223e0a49f7fd2c622a0730Behdad Esfahbod * last consonant. */ 542f5bc2725cb892264ba223e0a49f7fd2c622a0730Behdad Esfahbod if ((map->get_chosen_script (0) & 0x000000FF) != '2') { 543f5bc2725cb892264ba223e0a49f7fd2c622a0730Behdad Esfahbod /* We should only do this for Indic scripts which have a version two I guess. */ 544f5bc2725cb892264ba223e0a49f7fd2c622a0730Behdad Esfahbod for (i = base + 1; i < end; i++) 545f5bc2725cb892264ba223e0a49f7fd2c622a0730Behdad Esfahbod if (info[i].indic_category() == OT_H) { 546f5bc2725cb892264ba223e0a49f7fd2c622a0730Behdad Esfahbod unsigned int j; 547f5bc2725cb892264ba223e0a49f7fd2c622a0730Behdad Esfahbod for (j = end - 1; j > i; j--) 548f5bc2725cb892264ba223e0a49f7fd2c622a0730Behdad Esfahbod if ((FLAG (info[j].indic_category()) & (FLAG (OT_C) | FLAG (OT_Ra)))) 549f5bc2725cb892264ba223e0a49f7fd2c622a0730Behdad Esfahbod break; 550f5bc2725cb892264ba223e0a49f7fd2c622a0730Behdad Esfahbod if (j > i) { 551f5bc2725cb892264ba223e0a49f7fd2c622a0730Behdad Esfahbod /* Move Halant to after last consonant. */ 552f5bc2725cb892264ba223e0a49f7fd2c622a0730Behdad Esfahbod hb_glyph_info_t t = info[i]; 553f5bc2725cb892264ba223e0a49f7fd2c622a0730Behdad Esfahbod memmove (&info[i], &info[i + 1], (j - i) * sizeof (info[0])); 554f5bc2725cb892264ba223e0a49f7fd2c622a0730Behdad Esfahbod info[j] = t; 555f5bc2725cb892264ba223e0a49f7fd2c622a0730Behdad Esfahbod } 556f5bc2725cb892264ba223e0a49f7fd2c622a0730Behdad Esfahbod break; 557f5bc2725cb892264ba223e0a49f7fd2c622a0730Behdad Esfahbod } 558f5bc2725cb892264ba223e0a49f7fd2c622a0730Behdad Esfahbod } 559f5bc2725cb892264ba223e0a49f7fd2c622a0730Behdad Esfahbod 56045d6f29f15f1d2323bcaa2498aed23ff0c8a1567Behdad Esfahbod /* Attach ZWJ, ZWNJ, nukta, and halant to previous char to move with them. */ 56145d6f29f15f1d2323bcaa2498aed23ff0c8a1567Behdad Esfahbod for (i = start + 1; i < end; i++) 562ee58f3bc75d2d071a71b94063bf12205a5871acbBehdad Esfahbod if ((FLAG (info[i].indic_category()) & 56345d6f29f15f1d2323bcaa2498aed23ff0c8a1567Behdad Esfahbod (FLAG (OT_ZWNJ) | FLAG (OT_ZWJ) | FLAG (OT_N) | FLAG (OT_H)))) 564ee58f3bc75d2d071a71b94063bf12205a5871acbBehdad Esfahbod info[i].indic_position() = info[i - 1].indic_position(); 56545d6f29f15f1d2323bcaa2498aed23ff0c8a1567Behdad Esfahbod 56645d6f29f15f1d2323bcaa2498aed23ff0c8a1567Behdad Esfahbod /* We do bubble-sort, skip malicious clusters attempts */ 56745d6f29f15f1d2323bcaa2498aed23ff0c8a1567Behdad Esfahbod if (end - start > 20) 56845d6f29f15f1d2323bcaa2498aed23ff0c8a1567Behdad Esfahbod return; 56945d6f29f15f1d2323bcaa2498aed23ff0c8a1567Behdad Esfahbod 57045d6f29f15f1d2323bcaa2498aed23ff0c8a1567Behdad Esfahbod /* Sit tight, rock 'n roll! */ 571ee58f3bc75d2d071a71b94063bf12205a5871acbBehdad Esfahbod hb_bubble_sort (info + start, end - start, compare_indic_order); 57245d6f29f15f1d2323bcaa2498aed23ff0c8a1567Behdad Esfahbod 573743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod /* Setup masks now */ 574743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod 575281683995a46ed37aeeb84061249758c59822457Behdad Esfahbod { 576281683995a46ed37aeeb84061249758c59822457Behdad Esfahbod hb_mask_t mask; 577281683995a46ed37aeeb84061249758c59822457Behdad Esfahbod 578281683995a46ed37aeeb84061249758c59822457Behdad Esfahbod /* Pre-base */ 579281683995a46ed37aeeb84061249758c59822457Behdad Esfahbod mask = mask_array[HALF] | mask_array[AKHN] | mask_array[CJCT]; 580281683995a46ed37aeeb84061249758c59822457Behdad Esfahbod for (i = start; i < base; i++) 581281683995a46ed37aeeb84061249758c59822457Behdad Esfahbod info[i].mask |= mask; 582281683995a46ed37aeeb84061249758c59822457Behdad Esfahbod /* Base */ 583281683995a46ed37aeeb84061249758c59822457Behdad Esfahbod mask = mask_array[AKHN] | mask_array[CJCT]; 584281683995a46ed37aeeb84061249758c59822457Behdad Esfahbod info[base].mask |= mask; 585281683995a46ed37aeeb84061249758c59822457Behdad Esfahbod /* Post-base */ 586281683995a46ed37aeeb84061249758c59822457Behdad Esfahbod mask = mask_array[BLWF] | mask_array[PSTF] | mask_array[CJCT]; 587281683995a46ed37aeeb84061249758c59822457Behdad Esfahbod for (i = base + 1; i < end; i++) 588281683995a46ed37aeeb84061249758c59822457Behdad Esfahbod info[i].mask |= mask; 589281683995a46ed37aeeb84061249758c59822457Behdad Esfahbod } 5909da0487cd452d780673e24329ce03e174a4ef83bBehdad Esfahbod 5919da0487cd452d780673e24329ce03e174a4ef83bBehdad Esfahbod /* Apply ZWJ/ZWNJ effects */ 5929da0487cd452d780673e24329ce03e174a4ef83bBehdad Esfahbod for (i = start + 1; i < end; i++) 5939da0487cd452d780673e24329ce03e174a4ef83bBehdad Esfahbod if (is_joiner (info[i])) { 5949da0487cd452d780673e24329ce03e174a4ef83bBehdad Esfahbod bool non_joiner = info[i].indic_category() == OT_ZWNJ; 5956b37bc80843e38ca7b62500f95fd70c08af68d62Behdad Esfahbod unsigned int j = i; 5969da0487cd452d780673e24329ce03e174a4ef83bBehdad Esfahbod 5979da0487cd452d780673e24329ce03e174a4ef83bBehdad Esfahbod do { 5989da0487cd452d780673e24329ce03e174a4ef83bBehdad Esfahbod j--; 5996b37bc80843e38ca7b62500f95fd70c08af68d62Behdad Esfahbod 6006b37bc80843e38ca7b62500f95fd70c08af68d62Behdad Esfahbod info[j].mask &= !mask_array[CJCT]; 6016b37bc80843e38ca7b62500f95fd70c08af68d62Behdad Esfahbod if (non_joiner) 6026b37bc80843e38ca7b62500f95fd70c08af68d62Behdad Esfahbod info[j].mask &= !mask_array[HALF]; 6036b37bc80843e38ca7b62500f95fd70c08af68d62Behdad Esfahbod 6049da0487cd452d780673e24329ce03e174a4ef83bBehdad Esfahbod } while (j > start && !is_consonant (info[j])); 6059da0487cd452d780673e24329ce03e174a4ef83bBehdad Esfahbod } 606743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod} 607743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod 608743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod 609743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbodstatic void 610743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbodfound_vowel_syllable (const hb_ot_map_t *map, hb_buffer_t *buffer, hb_mask_t *mask_array, 611743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod unsigned int start, unsigned int end) 612743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod{ 613743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod /* TODO 614743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod * Not clear to me how this should work. Do the matras move to before the 615743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod * independent vowel? No idea. 616743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod */ 617743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod} 618743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod 619743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbodstatic void 620743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbodfound_standalone_cluster (const hb_ot_map_t *map, hb_buffer_t *buffer, hb_mask_t *mask_array, 621743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod unsigned int start, unsigned int end) 622743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod{ 623743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod /* TODO 624743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod * Easiest thing to do here is to convert the NBSP to consonant and 625743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod * call found_consonant_syllable. 626743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod */ 627743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod} 628743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod 629743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbodstatic void 630743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbodfound_non_indic (const hb_ot_map_t *map, hb_buffer_t *buffer, hb_mask_t *mask_array, 631743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod unsigned int start, unsigned int end) 632743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod{ 633743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod /* Nothing to do right now. If we ever switch to using the output 634743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod * buffer in the reordering process, we'd need to next_glyph() here. */ 635743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod} 636743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod 637743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod#include "hb-ot-shape-complex-indic-machine.hh" 638743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod 639743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbodstatic void 6409da0487cd452d780673e24329ce03e174a4ef83bBehdad Esfahbodremove_joiners (hb_buffer_t *buffer) 6419da0487cd452d780673e24329ce03e174a4ef83bBehdad Esfahbod{ 6429da0487cd452d780673e24329ce03e174a4ef83bBehdad Esfahbod buffer->clear_output (); 6439da0487cd452d780673e24329ce03e174a4ef83bBehdad Esfahbod unsigned int count = buffer->len; 6449da0487cd452d780673e24329ce03e174a4ef83bBehdad Esfahbod for (buffer->idx = 0; buffer->idx < count;) 6459da0487cd452d780673e24329ce03e174a4ef83bBehdad Esfahbod if (unlikely (is_joiner (buffer->info[buffer->idx]))) 6469da0487cd452d780673e24329ce03e174a4ef83bBehdad Esfahbod buffer->skip_glyph (); 6479da0487cd452d780673e24329ce03e174a4ef83bBehdad Esfahbod else 6489da0487cd452d780673e24329ce03e174a4ef83bBehdad Esfahbod buffer->next_glyph (); 6499da0487cd452d780673e24329ce03e174a4ef83bBehdad Esfahbod 6509da0487cd452d780673e24329ce03e174a4ef83bBehdad Esfahbod buffer->swap_buffers (); 6519da0487cd452d780673e24329ce03e174a4ef83bBehdad Esfahbod} 6529da0487cd452d780673e24329ce03e174a4ef83bBehdad Esfahbod 6539da0487cd452d780673e24329ce03e174a4ef83bBehdad Esfahbodstatic void 654743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbodinitial_reordering (const hb_ot_map_t *map, 655743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod hb_face_t *face, 656743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod hb_buffer_t *buffer, 657743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod void *user_data HB_UNUSED) 658743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod{ 659b9ddbd55930228422e82b34a141ad1b6093f5376Behdad Esfahbod hb_mask_t mask_array[ARRAY_LENGTH (indic_basic_features)] = {0}; 660b9ddbd55930228422e82b34a141ad1b6093f5376Behdad Esfahbod unsigned int num_masks = ARRAY_LENGTH (indic_basic_features); 661b9ddbd55930228422e82b34a141ad1b6093f5376Behdad Esfahbod for (unsigned int i = 0; i < num_masks; i++) 66276f76812ac7cca8ac6935952a2360d5e151480faBehdad Esfahbod mask_array[i] = map->get_1_mask (indic_basic_features[i].tag); 663743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod 664743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod find_syllables (map, buffer, mask_array); 6659da0487cd452d780673e24329ce03e174a4ef83bBehdad Esfahbod 6669da0487cd452d780673e24329ce03e174a4ef83bBehdad Esfahbod remove_joiners (buffer); 667b9ddbd55930228422e82b34a141ad1b6093f5376Behdad Esfahbod} 668b9ddbd55930228422e82b34a141ad1b6093f5376Behdad Esfahbod 669743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbodstatic void 670743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbodfinal_reordering (const hb_ot_map_t *map, 671743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod hb_face_t *face, 672743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod hb_buffer_t *buffer, 673743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod void *user_data HB_UNUSED) 674743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod{ 675e7be05702447ae270d797398132c1930cd3a9b86Behdad Esfahbod /* 4. Final reordering: 676e7be05702447ae270d797398132c1930cd3a9b86Behdad Esfahbod * 677e7be05702447ae270d797398132c1930cd3a9b86Behdad Esfahbod * After the localized forms and basic shaping forms GSUB features have been 678e7be05702447ae270d797398132c1930cd3a9b86Behdad Esfahbod * applied (see below), the shaping engine performs some final glyph 679e7be05702447ae270d797398132c1930cd3a9b86Behdad Esfahbod * reordering before applying all the remaining font features to the entire 680e7be05702447ae270d797398132c1930cd3a9b86Behdad Esfahbod * cluster. 681e7be05702447ae270d797398132c1930cd3a9b86Behdad Esfahbod * 682e7be05702447ae270d797398132c1930cd3a9b86Behdad Esfahbod * o Reorder matras: 683e7be05702447ae270d797398132c1930cd3a9b86Behdad Esfahbod * 684e7be05702447ae270d797398132c1930cd3a9b86Behdad Esfahbod * If a pre-base matra character had been reordered before applying basic 685e7be05702447ae270d797398132c1930cd3a9b86Behdad Esfahbod * features, the glyph can be moved closer to the main consonant based on 686e7be05702447ae270d797398132c1930cd3a9b86Behdad Esfahbod * whether half-forms had been formed. Actual position for the matra is 687e7be05702447ae270d797398132c1930cd3a9b86Behdad Esfahbod * defined as “after last standalone halant glyph, after initial matra 688e7be05702447ae270d797398132c1930cd3a9b86Behdad Esfahbod * position and before the main consonant”. If ZWJ or ZWNJ follow this 689e7be05702447ae270d797398132c1930cd3a9b86Behdad Esfahbod * halant, position is moved after it. 690e7be05702447ae270d797398132c1930cd3a9b86Behdad Esfahbod * 691e7be05702447ae270d797398132c1930cd3a9b86Behdad Esfahbod * o Reorder reph: 692e7be05702447ae270d797398132c1930cd3a9b86Behdad Esfahbod * 693e7be05702447ae270d797398132c1930cd3a9b86Behdad Esfahbod * Reph’s original position is always at the beginning of the syllable, 694e7be05702447ae270d797398132c1930cd3a9b86Behdad Esfahbod * (i.e. it is not reordered at the character reordering stage). However, 695e7be05702447ae270d797398132c1930cd3a9b86Behdad Esfahbod * it will be reordered according to the basic-forms shaping results. 696e7be05702447ae270d797398132c1930cd3a9b86Behdad Esfahbod * Possible positions for reph, depending on the script, are; after main, 697e7be05702447ae270d797398132c1930cd3a9b86Behdad Esfahbod * before post-base consonant forms, and after post-base consonant forms. 698e7be05702447ae270d797398132c1930cd3a9b86Behdad Esfahbod * 699e7be05702447ae270d797398132c1930cd3a9b86Behdad Esfahbod * 1. If reph should be positioned after post-base consonant forms, 700e7be05702447ae270d797398132c1930cd3a9b86Behdad Esfahbod * proceed to step 5. 701e7be05702447ae270d797398132c1930cd3a9b86Behdad Esfahbod * 702e7be05702447ae270d797398132c1930cd3a9b86Behdad Esfahbod * 2. If the reph repositioning class is not after post-base: target 703e7be05702447ae270d797398132c1930cd3a9b86Behdad Esfahbod * position is after the first explicit halant glyph between the 704e7be05702447ae270d797398132c1930cd3a9b86Behdad Esfahbod * first post-reph consonant and last main consonant. If ZWJ or ZWNJ 705e7be05702447ae270d797398132c1930cd3a9b86Behdad Esfahbod * are following this halant, position is moved after it. If such 706e7be05702447ae270d797398132c1930cd3a9b86Behdad Esfahbod * position is found, this is the target position. Otherwise, 707e7be05702447ae270d797398132c1930cd3a9b86Behdad Esfahbod * proceed to the next step. 708e7be05702447ae270d797398132c1930cd3a9b86Behdad Esfahbod * 709e7be05702447ae270d797398132c1930cd3a9b86Behdad Esfahbod * Note: in old-implementation fonts, where classifications were 710e7be05702447ae270d797398132c1930cd3a9b86Behdad Esfahbod * fixed in shaping engine, there was no case where reph position 711e7be05702447ae270d797398132c1930cd3a9b86Behdad Esfahbod * will be found on this step. 712e7be05702447ae270d797398132c1930cd3a9b86Behdad Esfahbod * 713e7be05702447ae270d797398132c1930cd3a9b86Behdad Esfahbod * 3. If reph should be repositioned after the main consonant: from the 714e7be05702447ae270d797398132c1930cd3a9b86Behdad Esfahbod * first consonant not ligated with main, or find the first 715e7be05702447ae270d797398132c1930cd3a9b86Behdad Esfahbod * consonant that is not a potential pre-base reordering Ra. 716e7be05702447ae270d797398132c1930cd3a9b86Behdad Esfahbod * 717e7be05702447ae270d797398132c1930cd3a9b86Behdad Esfahbod * 718e7be05702447ae270d797398132c1930cd3a9b86Behdad Esfahbod * 4. If reph should be positioned before post-base consonant, find 719e7be05702447ae270d797398132c1930cd3a9b86Behdad Esfahbod * first post-base classified consonant not ligated with main. If no 720e7be05702447ae270d797398132c1930cd3a9b86Behdad Esfahbod * consonant is found, the target position should be before the 721e7be05702447ae270d797398132c1930cd3a9b86Behdad Esfahbod * first matra, syllable modifier sign or vedic sign. 722e7be05702447ae270d797398132c1930cd3a9b86Behdad Esfahbod * 723e7be05702447ae270d797398132c1930cd3a9b86Behdad Esfahbod * 5. If no consonant is found in steps 3 or 4, move reph to a position 724e7be05702447ae270d797398132c1930cd3a9b86Behdad Esfahbod * immediately before the first post-base matra, syllable modifier 725e7be05702447ae270d797398132c1930cd3a9b86Behdad Esfahbod * sign or vedic sign that has a reordering class after the intended 726e7be05702447ae270d797398132c1930cd3a9b86Behdad Esfahbod * reph position. For example, if the reordering position for reph 727e7be05702447ae270d797398132c1930cd3a9b86Behdad Esfahbod * is post-main, it will skip above-base matras that also have a 728e7be05702447ae270d797398132c1930cd3a9b86Behdad Esfahbod * post-main position. 729e7be05702447ae270d797398132c1930cd3a9b86Behdad Esfahbod * 730e7be05702447ae270d797398132c1930cd3a9b86Behdad Esfahbod * 6. Otherwise, reorder reph to the end of the syllable. 731e7be05702447ae270d797398132c1930cd3a9b86Behdad Esfahbod * 732e7be05702447ae270d797398132c1930cd3a9b86Behdad Esfahbod * o Reorder pre-base reordering consonants: 733e7be05702447ae270d797398132c1930cd3a9b86Behdad Esfahbod * 734e7be05702447ae270d797398132c1930cd3a9b86Behdad Esfahbod * If a pre-base reordering consonant is found, reorder it according to 735e7be05702447ae270d797398132c1930cd3a9b86Behdad Esfahbod * the following rules: 736e7be05702447ae270d797398132c1930cd3a9b86Behdad Esfahbod * 737e7be05702447ae270d797398132c1930cd3a9b86Behdad Esfahbod * 1. Only reorder a glyph produced by substitution during application 738e7be05702447ae270d797398132c1930cd3a9b86Behdad Esfahbod * of the feature. (Note that a font may shape a Ra consonant with 739e7be05702447ae270d797398132c1930cd3a9b86Behdad Esfahbod * the feature generally but block it in certain contexts.) 740e7be05702447ae270d797398132c1930cd3a9b86Behdad Esfahbod * 741e7be05702447ae270d797398132c1930cd3a9b86Behdad Esfahbod * 2. Try to find a target position the same way as for pre-base matra. 742e7be05702447ae270d797398132c1930cd3a9b86Behdad Esfahbod * If it is found, reorder pre-base consonant glyph. 743e7be05702447ae270d797398132c1930cd3a9b86Behdad Esfahbod * 744e7be05702447ae270d797398132c1930cd3a9b86Behdad Esfahbod * 3. If position is not found, reorder immediately before main 745e7be05702447ae270d797398132c1930cd3a9b86Behdad Esfahbod * consonant. 746e7be05702447ae270d797398132c1930cd3a9b86Behdad Esfahbod */ 747e7be05702447ae270d797398132c1930cd3a9b86Behdad Esfahbod 748e7be05702447ae270d797398132c1930cd3a9b86Behdad Esfahbod /* TODO */ 749e7be05702447ae270d797398132c1930cd3a9b86Behdad Esfahbod 750e7be05702447ae270d797398132c1930cd3a9b86Behdad Esfahbod 751e7be05702447ae270d797398132c1930cd3a9b86Behdad Esfahbod 752743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod HB_BUFFER_DEALLOCATE_VAR (buffer, indic_category); 753743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod HB_BUFFER_DEALLOCATE_VAR (buffer, indic_position); 754743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod} 755743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod 756743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod 757b9ddbd55930228422e82b34a141ad1b6093f5376Behdad Esfahbod 758b9ddbd55930228422e82b34a141ad1b6093f5376Behdad EsfahbodHB_END_DECLS 759