Behdad Esfahbod | 3ed4634 | 2012-04-19 22:34:06 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright © 2012 Google, Inc. |
| 3 | * |
| 4 | * This is part of HarfBuzz, a text shaping library. |
| 5 | * |
| 6 | * Permission is hereby granted, without written agreement and without |
| 7 | * license or royalty fees, to use, copy, modify, and distribute this |
| 8 | * software and its documentation for any purpose, provided that the |
| 9 | * above copyright notice and the following two paragraphs appear in |
| 10 | * all copies of this software. |
| 11 | * |
| 12 | * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR |
| 13 | * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES |
| 14 | * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN |
| 15 | * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH |
| 16 | * DAMAGE. |
| 17 | * |
| 18 | * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, |
| 19 | * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND |
| 20 | * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS |
| 21 | * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO |
| 22 | * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. |
| 23 | * |
| 24 | * Google Author(s): Behdad Esfahbod |
| 25 | */ |
| 26 | |
| 27 | #ifndef HB_OT_SHAPE_COMPLEX_INDIC_PRIVATE_HH |
| 28 | #define HB_OT_SHAPE_COMPLEX_INDIC_PRIVATE_HH |
| 29 | |
| 30 | #include "hb-private.hh" |
| 31 | |
| 32 | |
| 33 | #include "hb-ot-shape-complex-private.hh" |
Behdad Esfahbod | 3eb6f81 | 2012-08-02 07:37:46 -0400 | [diff] [blame] | 34 | #include "hb-ot-shape-private.hh" /* XXX Remove */ |
Behdad Esfahbod | 3ed4634 | 2012-04-19 22:34:06 -0400 | [diff] [blame] | 35 | |
| 36 | |
Behdad Esfahbod | effddd0 | 2018-02-13 21:38:15 -0800 | [diff] [blame] | 37 | /* buffer var allocations */ |
| 38 | #define indic_category() complex_var_u8_0() /* indic_category_t */ |
| 39 | #define indic_position() complex_var_u8_1() /* indic_position_t */ |
| 40 | |
| 41 | |
Behdad Esfahbod | dba1867 | 2012-11-12 14:48:33 -0800 | [diff] [blame] | 42 | #define INDIC_TABLE_ELEMENT_TYPE uint16_t |
Behdad Esfahbod | 3ed4634 | 2012-04-19 22:34:06 -0400 | [diff] [blame] | 43 | |
| 44 | /* Cateories used in the OpenType spec: |
Ebrahim Byagowi | f24b0b9 | 2018-04-12 13:40:45 +0430 | [diff] [blame] | 45 | * https://docs.microsoft.com/en-us/typography/script-development/devanagari |
Behdad Esfahbod | 3ed4634 | 2012-04-19 22:34:06 -0400 | [diff] [blame] | 46 | */ |
| 47 | /* Note: This enum is duplicated in the -machine.rl source file. |
| 48 | * Not sure how to avoid duplication. */ |
| 49 | enum indic_category_t { |
| 50 | OT_X = 0, |
Behdad Esfahbod | c16012e | 2013-10-18 02:27:00 +0200 | [diff] [blame] | 51 | OT_C = 1, |
| 52 | OT_V = 2, |
| 53 | OT_N = 3, |
| 54 | OT_H = 4, |
| 55 | OT_ZWNJ = 5, |
| 56 | OT_ZWJ = 6, |
| 57 | OT_M = 7, |
| 58 | OT_SM = 8, |
Behdad Esfahbod | f6df251 | 2018-01-05 17:27:48 +0000 | [diff] [blame] | 59 | /* OT_VD = 9, UNUSED; we use OT_A instead. */ |
Behdad Esfahbod | c16012e | 2013-10-18 02:27:00 +0200 | [diff] [blame] | 60 | OT_A = 10, |
Behdad Esfahbod | cf78dd4 | 2014-05-27 17:53:37 -0400 | [diff] [blame] | 61 | OT_PLACEHOLDER = 11, |
Behdad Esfahbod | c16012e | 2013-10-18 02:27:00 +0200 | [diff] [blame] | 62 | OT_DOTTEDCIRCLE = 12, |
| 63 | OT_RS = 13, /* Register Shifter, used in Khmer OT spec. */ |
| 64 | OT_Coeng = 14, /* Khmer-style Virama. */ |
| 65 | OT_Repha = 15, /* Atomically-encoded logical or visual repha. */ |
| 66 | OT_Ra = 16, |
| 67 | OT_CM = 17, /* Consonant-Medial. */ |
Behdad Esfahbod | f559c63 | 2017-10-03 15:20:07 +0200 | [diff] [blame] | 68 | OT_Symbol = 18, /* Avagraha, etc that take marks (SM,A,VD). */ |
| 69 | OT_CS = 19 |
Behdad Esfahbod | 3ed4634 | 2012-04-19 22:34:06 -0400 | [diff] [blame] | 70 | }; |
| 71 | |
Behdad Esfahbod | 8b5d6e7 | 2016-05-06 15:59:27 +0100 | [diff] [blame] | 72 | #define MEDIAL_FLAGS (FLAG (OT_CM)) |
Behdad Esfahbod | cf71d28 | 2014-05-27 17:47:43 -0400 | [diff] [blame] | 73 | |
| 74 | /* Note: |
| 75 | * |
| 76 | * We treat Vowels and placeholders as if they were consonants. This is safe because Vowels |
| 77 | * cannot happen in a consonant syllable. The plus side however is, we can call the |
| 78 | * consonant syllable logic from the vowel syllable function and get it all right! */ |
Behdad Esfahbod | f559c63 | 2017-10-03 15:20:07 +0200 | [diff] [blame] | 79 | #define CONSONANT_FLAGS (FLAG (OT_C) | FLAG (OT_CS) | FLAG (OT_Ra) | MEDIAL_FLAGS | FLAG (OT_V) | FLAG (OT_PLACEHOLDER) | FLAG (OT_DOTTEDCIRCLE)) |
Behdad Esfahbod | cf71d28 | 2014-05-27 17:47:43 -0400 | [diff] [blame] | 80 | #define JOINER_FLAGS (FLAG (OT_ZWJ) | FLAG (OT_ZWNJ)) |
Behdad Esfahbod | cf71d28 | 2014-05-27 17:47:43 -0400 | [diff] [blame] | 81 | |
| 82 | |
Behdad Esfahbod | 3ed4634 | 2012-04-19 22:34:06 -0400 | [diff] [blame] | 83 | /* Visual positions in a syllable from left to right. */ |
| 84 | enum indic_position_t { |
Behdad Esfahbod | 9b878bd | 2018-02-13 21:22:47 -0800 | [diff] [blame] | 85 | POS_START = 0, |
Behdad Esfahbod | 81202bd | 2012-07-20 15:10:02 -0400 | [diff] [blame] | 86 | |
Behdad Esfahbod | 9b878bd | 2018-02-13 21:22:47 -0800 | [diff] [blame] | 87 | POS_RA_TO_BECOME_REPH = 1, |
| 88 | POS_PRE_M = 2, |
| 89 | POS_PRE_C = 3, |
Behdad Esfahbod | be8b9f5 | 2012-07-19 12:11:12 -0400 | [diff] [blame] | 90 | |
Behdad Esfahbod | 9b878bd | 2018-02-13 21:22:47 -0800 | [diff] [blame] | 91 | POS_BASE_C = 4, |
| 92 | POS_AFTER_MAIN = 5, |
Behdad Esfahbod | be8b9f5 | 2012-07-19 12:11:12 -0400 | [diff] [blame] | 93 | |
Behdad Esfahbod | 9b878bd | 2018-02-13 21:22:47 -0800 | [diff] [blame] | 94 | POS_ABOVE_C = 6, |
Behdad Esfahbod | be8b9f5 | 2012-07-19 12:11:12 -0400 | [diff] [blame] | 95 | |
Behdad Esfahbod | 9b878bd | 2018-02-13 21:22:47 -0800 | [diff] [blame] | 96 | POS_BEFORE_SUB = 7, |
| 97 | POS_BELOW_C = 8, |
| 98 | POS_AFTER_SUB = 9, |
Behdad Esfahbod | be8b9f5 | 2012-07-19 12:11:12 -0400 | [diff] [blame] | 99 | |
Behdad Esfahbod | 9b878bd | 2018-02-13 21:22:47 -0800 | [diff] [blame] | 100 | POS_BEFORE_POST = 10, |
| 101 | POS_POST_C = 11, |
| 102 | POS_AFTER_POST = 12, |
Behdad Esfahbod | be8b9f5 | 2012-07-19 12:11:12 -0400 | [diff] [blame] | 103 | |
Behdad Esfahbod | 9b878bd | 2018-02-13 21:22:47 -0800 | [diff] [blame] | 104 | POS_FINAL_C = 13, |
| 105 | POS_SMVD = 14, |
Behdad Esfahbod | 81202bd | 2012-07-20 15:10:02 -0400 | [diff] [blame] | 106 | |
Behdad Esfahbod | 9b878bd | 2018-02-13 21:22:47 -0800 | [diff] [blame] | 107 | POS_END = 15 |
Behdad Esfahbod | 3ed4634 | 2012-04-19 22:34:06 -0400 | [diff] [blame] | 108 | }; |
| 109 | |
Behdad Esfahbod | c5306b6 | 2012-05-10 12:07:33 +0200 | [diff] [blame] | 110 | /* Categories used in IndicSyllabicCategory.txt from UCD. */ |
Behdad Esfahbod | 3ed4634 | 2012-04-19 22:34:06 -0400 | [diff] [blame] | 111 | enum indic_syllabic_category_t { |
Behdad Esfahbod | 5c4e3e9 | 2014-06-30 14:25:18 -0400 | [diff] [blame] | 112 | INDIC_SYLLABIC_CATEGORY_OTHER = OT_X, |
Behdad Esfahbod | 3ed4634 | 2012-04-19 22:34:06 -0400 | [diff] [blame] | 113 | |
Behdad Esfahbod | 5c4e3e9 | 2014-06-30 14:25:18 -0400 | [diff] [blame] | 114 | INDIC_SYLLABIC_CATEGORY_AVAGRAHA = OT_Symbol, |
| 115 | INDIC_SYLLABIC_CATEGORY_BINDU = OT_SM, |
Behdad Esfahbod | 2813e30 | 2015-12-18 11:05:11 +0000 | [diff] [blame] | 116 | INDIC_SYLLABIC_CATEGORY_BRAHMI_JOINING_NUMBER = OT_PLACEHOLDER, /* Don't care. */ |
Behdad Esfahbod | d743ce7 | 2014-06-30 15:24:02 -0400 | [diff] [blame] | 117 | INDIC_SYLLABIC_CATEGORY_CANTILLATION_MARK = OT_A, |
Behdad Esfahbod | 5c4e3e9 | 2014-06-30 14:25:18 -0400 | [diff] [blame] | 118 | INDIC_SYLLABIC_CATEGORY_CONSONANT = OT_C, |
| 119 | INDIC_SYLLABIC_CATEGORY_CONSONANT_DEAD = OT_C, |
| 120 | INDIC_SYLLABIC_CATEGORY_CONSONANT_FINAL = OT_CM, |
| 121 | INDIC_SYLLABIC_CATEGORY_CONSONANT_HEAD_LETTER = OT_C, |
Behdad Esfahbod | 2813e30 | 2015-12-18 11:05:11 +0000 | [diff] [blame] | 122 | INDIC_SYLLABIC_CATEGORY_CONSONANT_KILLER = OT_M, /* U+17CD only. */ |
Behdad Esfahbod | 5c4e3e9 | 2014-06-30 14:25:18 -0400 | [diff] [blame] | 123 | INDIC_SYLLABIC_CATEGORY_CONSONANT_MEDIAL = OT_CM, |
| 124 | INDIC_SYLLABIC_CATEGORY_CONSONANT_PLACEHOLDER = OT_PLACEHOLDER, |
Behdad Esfahbod | d743ce7 | 2014-06-30 15:24:02 -0400 | [diff] [blame] | 125 | INDIC_SYLLABIC_CATEGORY_CONSONANT_PRECEDING_REPHA = OT_Repha, |
Behdad Esfahbod | 2813e30 | 2015-12-18 11:05:11 +0000 | [diff] [blame] | 126 | INDIC_SYLLABIC_CATEGORY_CONSONANT_PREFIXED = OT_X, /* Don't care. */ |
Behdad Esfahbod | 5c4e3e9 | 2014-06-30 14:25:18 -0400 | [diff] [blame] | 127 | INDIC_SYLLABIC_CATEGORY_CONSONANT_SUBJOINED = OT_CM, |
Behdad Esfahbod | d743ce7 | 2014-06-30 15:24:02 -0400 | [diff] [blame] | 128 | INDIC_SYLLABIC_CATEGORY_CONSONANT_SUCCEEDING_REPHA = OT_N, |
Behdad Esfahbod | f559c63 | 2017-10-03 15:20:07 +0200 | [diff] [blame] | 129 | INDIC_SYLLABIC_CATEGORY_CONSONANT_WITH_STACKER = OT_CS, |
ebraminio | 7c6937e | 2017-11-20 14:49:22 -0500 | [diff] [blame] | 130 | INDIC_SYLLABIC_CATEGORY_GEMINATION_MARK = OT_SM, /* https://github.com/harfbuzz/harfbuzz/issues/552 */ |
Behdad Esfahbod | 2813e30 | 2015-12-18 11:05:11 +0000 | [diff] [blame] | 131 | INDIC_SYLLABIC_CATEGORY_INVISIBLE_STACKER = OT_Coeng, |
Behdad Esfahbod | d743ce7 | 2014-06-30 15:24:02 -0400 | [diff] [blame] | 132 | INDIC_SYLLABIC_CATEGORY_JOINER = OT_ZWJ, |
Behdad Esfahbod | 5c4e3e9 | 2014-06-30 14:25:18 -0400 | [diff] [blame] | 133 | INDIC_SYLLABIC_CATEGORY_MODIFYING_LETTER = OT_X, |
Behdad Esfahbod | d743ce7 | 2014-06-30 15:24:02 -0400 | [diff] [blame] | 134 | INDIC_SYLLABIC_CATEGORY_NON_JOINER = OT_ZWNJ, |
Behdad Esfahbod | 5c4e3e9 | 2014-06-30 14:25:18 -0400 | [diff] [blame] | 135 | INDIC_SYLLABIC_CATEGORY_NUKTA = OT_N, |
Behdad Esfahbod | d743ce7 | 2014-06-30 15:24:02 -0400 | [diff] [blame] | 136 | INDIC_SYLLABIC_CATEGORY_NUMBER = OT_PLACEHOLDER, |
Behdad Esfahbod | 2813e30 | 2015-12-18 11:05:11 +0000 | [diff] [blame] | 137 | INDIC_SYLLABIC_CATEGORY_NUMBER_JOINER = OT_PLACEHOLDER, /* Don't care. */ |
| 138 | INDIC_SYLLABIC_CATEGORY_PURE_KILLER = OT_M, /* Is like a vowel matra. */ |
Behdad Esfahbod | 5c4e3e9 | 2014-06-30 14:25:18 -0400 | [diff] [blame] | 139 | INDIC_SYLLABIC_CATEGORY_REGISTER_SHIFTER = OT_RS, |
Behdad Esfahbod | 3cc84f4 | 2017-07-14 15:50:22 +0100 | [diff] [blame] | 140 | INDIC_SYLLABIC_CATEGORY_SYLLABLE_MODIFIER = OT_SM, |
Behdad Esfahbod | 5c4e3e9 | 2014-06-30 14:25:18 -0400 | [diff] [blame] | 141 | INDIC_SYLLABIC_CATEGORY_TONE_LETTER = OT_X, |
| 142 | INDIC_SYLLABIC_CATEGORY_TONE_MARK = OT_N, |
| 143 | INDIC_SYLLABIC_CATEGORY_VIRAMA = OT_H, |
| 144 | INDIC_SYLLABIC_CATEGORY_VISARGA = OT_SM, |
| 145 | INDIC_SYLLABIC_CATEGORY_VOWEL = OT_V, |
| 146 | INDIC_SYLLABIC_CATEGORY_VOWEL_DEPENDENT = OT_M, |
| 147 | INDIC_SYLLABIC_CATEGORY_VOWEL_INDEPENDENT = OT_V |
Behdad Esfahbod | 3ed4634 | 2012-04-19 22:34:06 -0400 | [diff] [blame] | 148 | }; |
| 149 | |
| 150 | /* Categories used in IndicSMatraCategory.txt from UCD */ |
| 151 | enum indic_matra_category_t { |
Behdad Esfahbod | 5c4e3e9 | 2014-06-30 14:25:18 -0400 | [diff] [blame] | 152 | INDIC_MATRA_CATEGORY_NOT_APPLICABLE = POS_END, |
Behdad Esfahbod | 3ed4634 | 2012-04-19 22:34:06 -0400 | [diff] [blame] | 153 | |
Behdad Esfahbod | 5c4e3e9 | 2014-06-30 14:25:18 -0400 | [diff] [blame] | 154 | INDIC_MATRA_CATEGORY_LEFT = POS_PRE_C, |
| 155 | INDIC_MATRA_CATEGORY_TOP = POS_ABOVE_C, |
| 156 | INDIC_MATRA_CATEGORY_BOTTOM = POS_BELOW_C, |
| 157 | INDIC_MATRA_CATEGORY_RIGHT = POS_POST_C, |
Behdad Esfahbod | 3ed4634 | 2012-04-19 22:34:06 -0400 | [diff] [blame] | 158 | |
Behdad Esfahbod | f83aaa3 | 2012-07-19 12:23:23 -0400 | [diff] [blame] | 159 | /* These should resolve to the position of the last part of the split sequence. */ |
Behdad Esfahbod | 5c4e3e9 | 2014-06-30 14:25:18 -0400 | [diff] [blame] | 160 | INDIC_MATRA_CATEGORY_BOTTOM_AND_RIGHT = INDIC_MATRA_CATEGORY_RIGHT, |
| 161 | INDIC_MATRA_CATEGORY_LEFT_AND_RIGHT = INDIC_MATRA_CATEGORY_RIGHT, |
| 162 | INDIC_MATRA_CATEGORY_TOP_AND_BOTTOM = INDIC_MATRA_CATEGORY_BOTTOM, |
| 163 | INDIC_MATRA_CATEGORY_TOP_AND_BOTTOM_AND_RIGHT = INDIC_MATRA_CATEGORY_RIGHT, |
| 164 | INDIC_MATRA_CATEGORY_TOP_AND_LEFT = INDIC_MATRA_CATEGORY_TOP, |
| 165 | INDIC_MATRA_CATEGORY_TOP_AND_LEFT_AND_RIGHT = INDIC_MATRA_CATEGORY_RIGHT, |
| 166 | INDIC_MATRA_CATEGORY_TOP_AND_RIGHT = INDIC_MATRA_CATEGORY_RIGHT, |
Behdad Esfahbod | 3ed4634 | 2012-04-19 22:34:06 -0400 | [diff] [blame] | 167 | |
Behdad Esfahbod | 5c4e3e9 | 2014-06-30 14:25:18 -0400 | [diff] [blame] | 168 | INDIC_MATRA_CATEGORY_OVERSTRUCK = POS_AFTER_MAIN, |
| 169 | INDIC_MATRA_CATEGORY_VISUAL_ORDER_LEFT = POS_PRE_M |
Behdad Esfahbod | 3ed4634 | 2012-04-19 22:34:06 -0400 | [diff] [blame] | 170 | }; |
| 171 | |
Behdad Esfahbod | 3ed4634 | 2012-04-19 22:34:06 -0400 | [diff] [blame] | 172 | #define INDIC_COMBINE_CATEGORIES(S,M) \ |
Behdad Esfahbod | 2813e30 | 2015-12-18 11:05:11 +0000 | [diff] [blame] | 173 | ( \ |
| 174 | ASSERT_STATIC_EXPR_ZERO (S < 255 && M < 255) + \ |
| 175 | ( S | \ |
| 176 | ( \ |
| 177 | ( \ |
| 178 | S == INDIC_SYLLABIC_CATEGORY_CONSONANT_MEDIAL || \ |
| 179 | S == INDIC_SYLLABIC_CATEGORY_GEMINATION_MARK || \ |
| 180 | S == INDIC_SYLLABIC_CATEGORY_REGISTER_SHIFTER || \ |
| 181 | S == INDIC_SYLLABIC_CATEGORY_CONSONANT_SUCCEEDING_REPHA || \ |
| 182 | S == INDIC_SYLLABIC_CATEGORY_VIRAMA || \ |
| 183 | S == INDIC_SYLLABIC_CATEGORY_VOWEL_DEPENDENT || \ |
| 184 | false \ |
| 185 | ? M : INDIC_MATRA_CATEGORY_NOT_APPLICABLE \ |
| 186 | ) << 8 \ |
| 187 | ) \ |
| 188 | ) \ |
| 189 | ) |
Behdad Esfahbod | 3ed4634 | 2012-04-19 22:34:06 -0400 | [diff] [blame] | 190 | |
Behdad Esfahbod | 3a83d33 | 2013-02-12 12:14:10 -0500 | [diff] [blame] | 191 | HB_INTERNAL INDIC_TABLE_ELEMENT_TYPE |
| 192 | hb_indic_get_categories (hb_codepoint_t u); |
Behdad Esfahbod | 3ed4634 | 2012-04-19 22:34:06 -0400 | [diff] [blame] | 193 | |
Behdad Esfahbod | 397ed53 | 2018-02-13 18:54:26 -0800 | [diff] [blame] | 194 | |
Behdad Esfahbod | d830d3d | 2018-02-13 19:01:03 -0800 | [diff] [blame] | 195 | static inline bool |
| 196 | is_one_of (const hb_glyph_info_t &info, unsigned int flags) |
| 197 | { |
| 198 | /* If it ligated, all bets are off. */ |
| 199 | if (_hb_glyph_info_ligated (&info)) return false; |
| 200 | return !!(FLAG_UNSAFE (info.indic_category()) & flags); |
| 201 | } |
| 202 | |
| 203 | static inline bool |
| 204 | is_joiner (const hb_glyph_info_t &info) |
| 205 | { |
| 206 | return is_one_of (info, JOINER_FLAGS); |
| 207 | } |
| 208 | |
| 209 | static inline bool |
| 210 | is_consonant (const hb_glyph_info_t &info) |
| 211 | { |
| 212 | return is_one_of (info, CONSONANT_FLAGS); |
| 213 | } |
| 214 | |
| 215 | static inline bool |
| 216 | is_halant (const hb_glyph_info_t &info) |
| 217 | { |
| 218 | return is_one_of (info, FLAG (OT_H)); |
| 219 | } |
Behdad Esfahbod | 397ed53 | 2018-02-13 18:54:26 -0800 | [diff] [blame] | 220 | |
| 221 | #define IN_HALF_BLOCK(u, Base) (((u) & ~0x7Fu) == (Base)) |
| 222 | |
| 223 | #define IS_DEVA(u) (IN_HALF_BLOCK (u, 0x0900u)) |
| 224 | #define IS_BENG(u) (IN_HALF_BLOCK (u, 0x0980u)) |
| 225 | #define IS_GURU(u) (IN_HALF_BLOCK (u, 0x0A00u)) |
| 226 | #define IS_GUJR(u) (IN_HALF_BLOCK (u, 0x0A80u)) |
| 227 | #define IS_ORYA(u) (IN_HALF_BLOCK (u, 0x0B00u)) |
| 228 | #define IS_TAML(u) (IN_HALF_BLOCK (u, 0x0B80u)) |
| 229 | #define IS_TELU(u) (IN_HALF_BLOCK (u, 0x0C00u)) |
| 230 | #define IS_KNDA(u) (IN_HALF_BLOCK (u, 0x0C80u)) |
| 231 | #define IS_MLYM(u) (IN_HALF_BLOCK (u, 0x0D00u)) |
| 232 | #define IS_SINH(u) (IN_HALF_BLOCK (u, 0x0D80u)) |
| 233 | |
| 234 | |
| 235 | #define MATRA_POS_LEFT(u) POS_PRE_M |
| 236 | #define MATRA_POS_RIGHT(u) ( \ |
| 237 | IS_DEVA(u) ? POS_AFTER_SUB : \ |
| 238 | IS_BENG(u) ? POS_AFTER_POST : \ |
| 239 | IS_GURU(u) ? POS_AFTER_POST : \ |
| 240 | IS_GUJR(u) ? POS_AFTER_POST : \ |
| 241 | IS_ORYA(u) ? POS_AFTER_POST : \ |
| 242 | IS_TAML(u) ? POS_AFTER_POST : \ |
| 243 | IS_TELU(u) ? (u <= 0x0C42u ? POS_BEFORE_SUB : POS_AFTER_SUB) : \ |
| 244 | IS_KNDA(u) ? (u < 0x0CC3u || u > 0xCD6u ? POS_BEFORE_SUB : POS_AFTER_SUB) : \ |
| 245 | IS_MLYM(u) ? POS_AFTER_POST : \ |
| 246 | IS_SINH(u) ? POS_AFTER_SUB : \ |
| 247 | /*default*/ POS_AFTER_SUB \ |
| 248 | ) |
| 249 | #define MATRA_POS_TOP(u) ( /* BENG and MLYM don't have top matras. */ \ |
| 250 | IS_DEVA(u) ? POS_AFTER_SUB : \ |
| 251 | IS_GURU(u) ? POS_AFTER_POST : /* Deviate from spec */ \ |
| 252 | IS_GUJR(u) ? POS_AFTER_SUB : \ |
| 253 | IS_ORYA(u) ? POS_AFTER_MAIN : \ |
| 254 | IS_TAML(u) ? POS_AFTER_SUB : \ |
| 255 | IS_TELU(u) ? POS_BEFORE_SUB : \ |
| 256 | IS_KNDA(u) ? POS_BEFORE_SUB : \ |
| 257 | IS_SINH(u) ? POS_AFTER_SUB : \ |
| 258 | /*default*/ POS_AFTER_SUB \ |
| 259 | ) |
| 260 | #define MATRA_POS_BOTTOM(u) ( \ |
| 261 | IS_DEVA(u) ? POS_AFTER_SUB : \ |
| 262 | IS_BENG(u) ? POS_AFTER_SUB : \ |
| 263 | IS_GURU(u) ? POS_AFTER_POST : \ |
| 264 | IS_GUJR(u) ? POS_AFTER_POST : \ |
| 265 | IS_ORYA(u) ? POS_AFTER_SUB : \ |
| 266 | IS_TAML(u) ? POS_AFTER_POST : \ |
| 267 | IS_TELU(u) ? POS_BEFORE_SUB : \ |
| 268 | IS_KNDA(u) ? POS_BEFORE_SUB : \ |
| 269 | IS_MLYM(u) ? POS_AFTER_POST : \ |
| 270 | IS_SINH(u) ? POS_AFTER_SUB : \ |
| 271 | /*default*/ POS_AFTER_SUB \ |
| 272 | ) |
| 273 | |
| 274 | static inline indic_position_t |
Behdad Esfahbod | d830d3d | 2018-02-13 19:01:03 -0800 | [diff] [blame] | 275 | matra_position_indic (hb_codepoint_t u, indic_position_t side) |
Behdad Esfahbod | 397ed53 | 2018-02-13 18:54:26 -0800 | [diff] [blame] | 276 | { |
| 277 | switch ((int) side) |
| 278 | { |
| 279 | case POS_PRE_C: return MATRA_POS_LEFT (u); |
| 280 | case POS_POST_C: return MATRA_POS_RIGHT (u); |
| 281 | case POS_ABOVE_C: return MATRA_POS_TOP (u); |
| 282 | case POS_BELOW_C: return MATRA_POS_BOTTOM (u); |
| 283 | }; |
| 284 | return side; |
| 285 | } |
| 286 | |
| 287 | /* XXX |
| 288 | * This is a hack for now. We should move this data into the main Indic table. |
| 289 | * Or completely remove it and just check in the tables. |
| 290 | */ |
| 291 | static const hb_codepoint_t ra_chars[] = { |
| 292 | 0x0930u, /* Devanagari */ |
| 293 | 0x09B0u, /* Bengali */ |
| 294 | 0x09F0u, /* Bengali */ |
| 295 | 0x0A30u, /* Gurmukhi */ /* No Reph */ |
| 296 | 0x0AB0u, /* Gujarati */ |
| 297 | 0x0B30u, /* Oriya */ |
| 298 | 0x0BB0u, /* Tamil */ /* No Reph */ |
| 299 | 0x0C30u, /* Telugu */ /* Reph formed only with ZWJ */ |
| 300 | 0x0CB0u, /* Kannada */ |
| 301 | 0x0D30u, /* Malayalam */ /* No Reph, Logical Repha */ |
| 302 | |
Behdad Esfahbod | 1a96cc8 | 2018-07-31 11:45:32 -0700 | [diff] [blame] | 303 | 0x0DBBu, /* Sinhala */ /* Reph formed only with ZWJ */ |
| 304 | |
| 305 | 0x179Au, /* Khmer */ |
Behdad Esfahbod | 397ed53 | 2018-02-13 18:54:26 -0800 | [diff] [blame] | 306 | }; |
| 307 | |
| 308 | static inline bool |
| 309 | is_ra (hb_codepoint_t u) |
| 310 | { |
| 311 | for (unsigned int i = 0; i < ARRAY_LENGTH (ra_chars); i++) |
| 312 | if (u == ra_chars[i]) |
| 313 | return true; |
| 314 | return false; |
| 315 | } |
| 316 | |
| 317 | static inline void |
| 318 | set_indic_properties (hb_glyph_info_t &info) |
| 319 | { |
| 320 | hb_codepoint_t u = info.codepoint; |
| 321 | unsigned int type = hb_indic_get_categories (u); |
| 322 | indic_category_t cat = (indic_category_t) (type & 0x7Fu); |
| 323 | indic_position_t pos = (indic_position_t) (type >> 8); |
| 324 | |
| 325 | |
| 326 | /* |
| 327 | * Re-assign category |
| 328 | */ |
| 329 | |
| 330 | /* The following act more like the Bindus. */ |
| 331 | if (unlikely (hb_in_range<hb_codepoint_t> (u, 0x0953u, 0x0954u))) |
| 332 | cat = OT_SM; |
| 333 | /* The following act like consonants. */ |
| 334 | else if (unlikely (hb_in_ranges<hb_codepoint_t> (u, 0x0A72u, 0x0A73u, |
| 335 | 0x1CF5u, 0x1CF6u))) |
| 336 | cat = OT_C; |
| 337 | /* TODO: The following should only be allowed after a Visarga. |
| 338 | * For now, just treat them like regular tone marks. */ |
| 339 | else if (unlikely (hb_in_range<hb_codepoint_t> (u, 0x1CE2u, 0x1CE8u))) |
| 340 | cat = OT_A; |
| 341 | /* TODO: The following should only be allowed after some of |
| 342 | * the nasalization marks, maybe only for U+1CE9..U+1CF1. |
| 343 | * For now, just treat them like tone marks. */ |
| 344 | else if (unlikely (u == 0x1CEDu)) |
| 345 | cat = OT_A; |
| 346 | /* The following take marks in standalone clusters, similar to Avagraha. */ |
| 347 | else if (unlikely (hb_in_ranges<hb_codepoint_t> (u, 0xA8F2u, 0xA8F7u, |
| 348 | 0x1CE9u, 0x1CECu, |
| 349 | 0x1CEEu, 0x1CF1u))) |
| 350 | { |
| 351 | cat = OT_Symbol; |
| 352 | static_assert (((int) INDIC_SYLLABIC_CATEGORY_AVAGRAHA == OT_Symbol), ""); |
| 353 | } |
| 354 | else if (unlikely (u == 0x0A51u)) |
| 355 | { |
| 356 | /* https://github.com/harfbuzz/harfbuzz/issues/524 */ |
| 357 | cat = OT_M; |
| 358 | pos = POS_BELOW_C; |
| 359 | } |
| 360 | |
| 361 | /* According to ScriptExtensions.txt, these Grantha marks may also be used in Tamil, |
| 362 | * so the Indic shaper needs to know their categories. */ |
| 363 | else if (unlikely (u == 0x11301u || u == 0x11303u)) cat = OT_SM; |
| 364 | else if (unlikely (u == 0x1133cu)) cat = OT_N; |
| 365 | |
| 366 | else if (unlikely (u == 0x0AFBu)) cat = OT_N; /* https://github.com/harfbuzz/harfbuzz/issues/552 */ |
| 367 | |
| 368 | else if (unlikely (u == 0x0980u)) cat = OT_PLACEHOLDER; /* https://github.com/harfbuzz/harfbuzz/issues/538 */ |
| 369 | else if (unlikely (u == 0x0C80u)) cat = OT_PLACEHOLDER; /* https://github.com/harfbuzz/harfbuzz/pull/623 */ |
| 370 | else if (unlikely (hb_in_range<hb_codepoint_t> (u, 0x2010u, 0x2011u))) |
| 371 | cat = OT_PLACEHOLDER; |
| 372 | else if (unlikely (u == 0x25CCu)) cat = OT_DOTTEDCIRCLE; |
| 373 | |
| 374 | |
| 375 | /* |
| 376 | * Re-assign position. |
| 377 | */ |
| 378 | |
| 379 | if ((FLAG_UNSAFE (cat) & CONSONANT_FLAGS)) |
| 380 | { |
| 381 | pos = POS_BASE_C; |
| 382 | if (is_ra (u)) |
| 383 | cat = OT_Ra; |
| 384 | } |
| 385 | else if (cat == OT_M) |
| 386 | { |
Behdad Esfahbod | d830d3d | 2018-02-13 19:01:03 -0800 | [diff] [blame] | 387 | pos = matra_position_indic (u, pos); |
Behdad Esfahbod | 397ed53 | 2018-02-13 18:54:26 -0800 | [diff] [blame] | 388 | } |
| 389 | else if ((FLAG_UNSAFE (cat) & (FLAG (OT_SM) /* | FLAG (OT_VD) */ | FLAG (OT_A) | FLAG (OT_Symbol)))) |
| 390 | { |
| 391 | pos = POS_SMVD; |
| 392 | } |
| 393 | |
| 394 | if (unlikely (u == 0x0B01u)) pos = POS_BEFORE_SUB; /* Oriya Bindu is BeforeSub in the spec. */ |
| 395 | |
| 396 | |
| 397 | |
| 398 | info.indic_category() = cat; |
| 399 | info.indic_position() = pos; |
| 400 | } |
| 401 | |
| 402 | |
Behdad Esfahbod | 3ed4634 | 2012-04-19 22:34:06 -0400 | [diff] [blame] | 403 | #endif /* HB_OT_SHAPE_COMPLEX_INDIC_PRIVATE_HH */ |