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