Behdad Esfahbod | b9ddbd5 | 2011-06-02 17:43:12 -0400 | [diff] [blame] | 1 | /* |
Behdad Esfahbod | 27aba59 | 2012-05-24 15:00:01 -0400 | [diff] [blame] | 2 | * Copyright © 2011,2012 Google, Inc. |
Behdad Esfahbod | b9ddbd5 | 2011-06-02 17:43:12 -0400 | [diff] [blame] | 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 | |
Behdad Esfahbod | 3ed4634 | 2012-04-19 22:34:06 -0400 | [diff] [blame] | 27 | #include "hb-ot-shape-complex-indic-private.hh" |
Behdad Esfahbod | 49c5ec5 | 2012-07-23 20:14:13 -0400 | [diff] [blame] | 28 | #include "hb-ot-layout-private.hh" |
Behdad Esfahbod | 352372a | 2011-07-30 19:04:02 -0400 | [diff] [blame] | 29 | |
Behdad Esfahbod | 3a83d33 | 2013-02-12 12:14:10 -0500 | [diff] [blame] | 30 | /* buffer var allocations */ |
| 31 | #define indic_category() complex_var_u8_0() /* indic_category_t */ |
| 32 | #define indic_position() complex_var_u8_1() /* indic_position_t */ |
| 33 | |
| 34 | |
| 35 | /* |
| 36 | * Indic shaper. |
| 37 | */ |
| 38 | |
| 39 | |
| 40 | #define IN_HALF_BLOCK(u, Base) (((u) & ~0x7F) == (Base)) |
| 41 | |
| 42 | #define IS_DEVA(u) (IN_HALF_BLOCK (u, 0x0900)) |
| 43 | #define IS_BENG(u) (IN_HALF_BLOCK (u, 0x0980)) |
| 44 | #define IS_GURU(u) (IN_HALF_BLOCK (u, 0x0A00)) |
| 45 | #define IS_GUJR(u) (IN_HALF_BLOCK (u, 0x0A80)) |
| 46 | #define IS_ORYA(u) (IN_HALF_BLOCK (u, 0x0B00)) |
| 47 | #define IS_TAML(u) (IN_HALF_BLOCK (u, 0x0B80)) |
| 48 | #define IS_TELU(u) (IN_HALF_BLOCK (u, 0x0C00)) |
| 49 | #define IS_KNDA(u) (IN_HALF_BLOCK (u, 0x0C80)) |
| 50 | #define IS_MLYM(u) (IN_HALF_BLOCK (u, 0x0D00)) |
| 51 | #define IS_SINH(u) (IN_HALF_BLOCK (u, 0x0D80)) |
| 52 | #define IS_KHMR(u) (IN_HALF_BLOCK (u, 0x1780)) |
| 53 | |
| 54 | |
| 55 | #define MATRA_POS_LEFT(u) POS_PRE_M |
| 56 | #define MATRA_POS_RIGHT(u) ( \ |
| 57 | IS_DEVA(u) ? POS_AFTER_SUB : \ |
| 58 | IS_BENG(u) ? POS_AFTER_POST : \ |
| 59 | IS_GURU(u) ? POS_AFTER_POST : \ |
| 60 | IS_GUJR(u) ? POS_AFTER_POST : \ |
| 61 | IS_ORYA(u) ? POS_AFTER_POST : \ |
| 62 | IS_TAML(u) ? POS_AFTER_POST : \ |
| 63 | IS_TELU(u) ? (u <= 0x0C42 ? POS_BEFORE_SUB : POS_AFTER_SUB) : \ |
| 64 | IS_KNDA(u) ? (u < 0x0CC3 || u > 0xCD6 ? POS_BEFORE_SUB : POS_AFTER_SUB) : \ |
| 65 | IS_MLYM(u) ? POS_AFTER_POST : \ |
| 66 | IS_SINH(u) ? POS_AFTER_SUB : \ |
| 67 | IS_KHMR(u) ? POS_AFTER_POST : \ |
| 68 | /*default*/ POS_AFTER_SUB \ |
| 69 | ) |
| 70 | #define MATRA_POS_TOP(u) ( /* BENG and MLYM don't have top matras. */ \ |
| 71 | IS_DEVA(u) ? POS_AFTER_SUB : \ |
| 72 | IS_GURU(u) ? POS_AFTER_POST : /* Deviate from spec */ \ |
| 73 | IS_GUJR(u) ? POS_AFTER_SUB : \ |
| 74 | IS_ORYA(u) ? POS_AFTER_MAIN : \ |
| 75 | IS_TAML(u) ? POS_AFTER_SUB : \ |
| 76 | IS_TELU(u) ? POS_BEFORE_SUB : \ |
| 77 | IS_KNDA(u) ? POS_BEFORE_SUB : \ |
| 78 | IS_SINH(u) ? POS_AFTER_SUB : \ |
| 79 | IS_KHMR(u) ? POS_AFTER_POST : \ |
| 80 | /*default*/ POS_AFTER_SUB \ |
| 81 | ) |
| 82 | #define MATRA_POS_BOTTOM(u) ( \ |
| 83 | IS_DEVA(u) ? POS_AFTER_SUB : \ |
| 84 | IS_BENG(u) ? POS_AFTER_SUB : \ |
| 85 | IS_GURU(u) ? POS_AFTER_POST : \ |
| 86 | IS_GUJR(u) ? POS_AFTER_POST : \ |
| 87 | IS_ORYA(u) ? POS_AFTER_SUB : \ |
| 88 | IS_TAML(u) ? POS_AFTER_POST : \ |
| 89 | IS_TELU(u) ? POS_BEFORE_SUB : \ |
| 90 | IS_KNDA(u) ? POS_BEFORE_SUB : \ |
| 91 | IS_MLYM(u) ? POS_AFTER_POST : \ |
| 92 | IS_SINH(u) ? POS_AFTER_SUB : \ |
| 93 | IS_KHMR(u) ? POS_AFTER_POST : \ |
| 94 | /*default*/ POS_AFTER_SUB \ |
| 95 | ) |
| 96 | |
| 97 | static inline indic_position_t |
| 98 | matra_position (hb_codepoint_t u, indic_position_t side) |
| 99 | { |
| 100 | switch ((int) side) |
| 101 | { |
| 102 | case POS_PRE_C: return MATRA_POS_LEFT (u); |
| 103 | case POS_POST_C: return MATRA_POS_RIGHT (u); |
| 104 | case POS_ABOVE_C: return MATRA_POS_TOP (u); |
| 105 | case POS_BELOW_C: return MATRA_POS_BOTTOM (u); |
| 106 | }; |
| 107 | return side; |
| 108 | } |
| 109 | |
| 110 | /* XXX |
| 111 | * This is a hack for now. We should move this data into the main Indic table. |
| 112 | * Or completely remove it and just check in the tables. |
| 113 | */ |
| 114 | static const hb_codepoint_t ra_chars[] = { |
| 115 | 0x0930, /* Devanagari */ |
| 116 | 0x09B0, /* Bengali */ |
| 117 | 0x09F0, /* Bengali */ |
| 118 | 0x0A30, /* Gurmukhi */ /* No Reph */ |
| 119 | 0x0AB0, /* Gujarati */ |
| 120 | 0x0B30, /* Oriya */ |
| 121 | 0x0BB0, /* Tamil */ /* No Reph */ |
| 122 | 0x0C30, /* Telugu */ /* Reph formed only with ZWJ */ |
| 123 | 0x0CB0, /* Kannada */ |
| 124 | 0x0D30, /* Malayalam */ /* No Reph, Logical Repha */ |
| 125 | |
| 126 | 0x0DBB, /* Sinhala */ /* Reph formed only with ZWJ */ |
| 127 | |
| 128 | 0x179A, /* Khmer */ /* No Reph, Visual Repha */ |
| 129 | }; |
| 130 | |
Behdad Esfahbod | 3a83d33 | 2013-02-12 12:14:10 -0500 | [diff] [blame] | 131 | static inline bool |
| 132 | is_ra (hb_codepoint_t u) |
| 133 | { |
| 134 | for (unsigned int i = 0; i < ARRAY_LENGTH (ra_chars); i++) |
| 135 | if (u == ra_chars[i]) |
| 136 | return true; |
| 137 | return false; |
| 138 | } |
| 139 | |
| 140 | static inline bool |
| 141 | is_one_of (const hb_glyph_info_t &info, unsigned int flags) |
| 142 | { |
| 143 | /* If it ligated, all bets are off. */ |
| 144 | if (is_a_ligature (info)) return false; |
| 145 | return !!(FLAG (info.indic_category()) & flags); |
| 146 | } |
| 147 | |
| 148 | #define JOINER_FLAGS (FLAG (OT_ZWJ) | FLAG (OT_ZWNJ)) |
| 149 | static inline bool |
| 150 | is_joiner (const hb_glyph_info_t &info) |
| 151 | { |
| 152 | return is_one_of (info, JOINER_FLAGS); |
| 153 | } |
| 154 | |
| 155 | /* Note: |
| 156 | * |
| 157 | * We treat Vowels and placeholders as if they were consonants. This is safe because Vowels |
| 158 | * cannot happen in a consonant syllable. The plus side however is, we can call the |
| 159 | * consonant syllable logic from the vowel syllable function and get it all right! */ |
| 160 | #define CONSONANT_FLAGS (FLAG (OT_C) | FLAG (OT_CM) | FLAG (OT_Ra) | FLAG (OT_V) | FLAG (OT_NBSP) | FLAG (OT_DOTTEDCIRCLE)) |
| 161 | static inline bool |
| 162 | is_consonant (const hb_glyph_info_t &info) |
| 163 | { |
| 164 | return is_one_of (info, CONSONANT_FLAGS); |
| 165 | } |
| 166 | |
| 167 | #define HALANT_OR_COENG_FLAGS (FLAG (OT_H) | FLAG (OT_Coeng)) |
| 168 | static inline bool |
| 169 | is_halant_or_coeng (const hb_glyph_info_t &info) |
| 170 | { |
| 171 | return is_one_of (info, HALANT_OR_COENG_FLAGS); |
| 172 | } |
| 173 | |
| 174 | static inline void |
| 175 | set_indic_properties (hb_glyph_info_t &info) |
| 176 | { |
| 177 | hb_codepoint_t u = info.codepoint; |
| 178 | unsigned int type = hb_indic_get_categories (u); |
| 179 | indic_category_t cat = (indic_category_t) (type & 0x7F); |
| 180 | indic_position_t pos = (indic_position_t) (type >> 8); |
| 181 | |
| 182 | |
| 183 | /* |
| 184 | * Re-assign category |
| 185 | */ |
| 186 | |
| 187 | |
| 188 | /* The spec says U+0952 is OT_A. However, testing shows that Uniscribe |
Behdad Esfahbod | 3756efa | 2013-10-16 19:06:29 +0200 | [diff] [blame] | 189 | * treats U+0951..U+0954 all behave similarly. |
Behdad Esfahbod | 3a83d33 | 2013-02-12 12:14:10 -0500 | [diff] [blame] | 190 | * TESTS: |
| 191 | * U+092E,U+0947,U+0952 |
| 192 | * U+092E,U+0952,U+0947 |
| 193 | * U+092E,U+0947,U+0951 |
| 194 | * U+092E,U+0951,U+0947 |
Behdad Esfahbod | 3756efa | 2013-10-16 19:06:29 +0200 | [diff] [blame] | 195 | */ |
Behdad Esfahbod | 3a83d33 | 2013-02-12 12:14:10 -0500 | [diff] [blame] | 196 | if (unlikely (hb_in_range<hb_codepoint_t> (u, 0x0951, 0x0954))) |
Behdad Esfahbod | 3756efa | 2013-10-16 19:06:29 +0200 | [diff] [blame] | 197 | cat = OT_A; |
Behdad Esfahbod | 3a83d33 | 2013-02-12 12:14:10 -0500 | [diff] [blame] | 198 | |
| 199 | if (unlikely (u == 0x17D1)) |
| 200 | cat = OT_X; |
| 201 | if (cat == OT_X && |
| 202 | unlikely (hb_in_range<hb_codepoint_t> (u, 0x17CB, 0x17D3))) /* Khmer Various signs */ |
| 203 | { |
| 204 | /* These are like Top Matras. */ |
| 205 | cat = OT_M; |
| 206 | pos = POS_ABOVE_C; |
| 207 | } |
| 208 | if (u == 0x17C6) /* Khmer Bindu doesn't like to be repositioned. */ |
| 209 | cat = OT_N; |
| 210 | |
| 211 | if (unlikely (u == 0x17D2)) cat = OT_Coeng; /* Khmer coeng */ |
| 212 | else if (unlikely (u == 0x200C)) cat = OT_ZWNJ; |
| 213 | else if (unlikely (u == 0x200D)) cat = OT_ZWJ; |
| 214 | else if (unlikely (u == 0x25CC)) cat = OT_DOTTEDCIRCLE; |
Behdad Esfahbod | 3756efa | 2013-10-16 19:06:29 +0200 | [diff] [blame] | 215 | else if (unlikely (u == 0x0A71)) cat = OT_SM; /* GURMUKHI ADDAK. Move it to the end. */ |
Behdad Esfahbod | 3a83d33 | 2013-02-12 12:14:10 -0500 | [diff] [blame] | 216 | |
| 217 | if (cat == OT_Repha) { |
| 218 | /* There are two kinds of characters marked as Repha: |
| 219 | * - The ones that are GenCat=Mn are already positioned visually, ie. after base. (eg. Khmer) |
| 220 | * - The ones that are GenCat=Lo is encoded logically, ie. beginning of syllable. (eg. Malayalam) |
| 221 | * |
| 222 | * We recategorize the first kind to look like a Nukta and attached to the base directly. |
| 223 | */ |
| 224 | if (_hb_glyph_info_get_general_category (&info) == HB_UNICODE_GENERAL_CATEGORY_NON_SPACING_MARK) |
| 225 | cat = OT_N; |
| 226 | } |
| 227 | |
| 228 | |
| 229 | |
| 230 | /* |
| 231 | * Re-assign position. |
| 232 | */ |
| 233 | |
| 234 | if ((FLAG (cat) & CONSONANT_FLAGS)) |
| 235 | { |
Behdad Esfahbod | c4e71ff | 2013-10-17 17:04:47 +0200 | [diff] [blame] | 236 | pos = POS_BASE_C; |
Behdad Esfahbod | 3a83d33 | 2013-02-12 12:14:10 -0500 | [diff] [blame] | 237 | if (is_ra (u)) |
| 238 | cat = OT_Ra; |
| 239 | } |
| 240 | else if (cat == OT_M) |
| 241 | { |
| 242 | pos = matra_position (u, pos); |
| 243 | } |
Behdad Esfahbod | 3756efa | 2013-10-16 19:06:29 +0200 | [diff] [blame] | 244 | else if ((FLAG (cat) & (FLAG (OT_SM) | FLAG (OT_VD) | FLAG (OT_A) | FLAG (OT_Avag)))) |
Behdad Esfahbod | 3a83d33 | 2013-02-12 12:14:10 -0500 | [diff] [blame] | 245 | { |
| 246 | pos = POS_SMVD; |
| 247 | } |
| 248 | |
| 249 | if (unlikely (u == 0x0B01)) pos = POS_BEFORE_SUB; /* Oriya Bindu is BeforeSub in the spec. */ |
| 250 | |
| 251 | |
| 252 | |
| 253 | info.indic_category() = cat; |
| 254 | info.indic_position() = pos; |
| 255 | } |
| 256 | |
| 257 | /* |
| 258 | * Things above this line should ideally be moved to the Indic table itself. |
| 259 | */ |
| 260 | |
Behdad Esfahbod | 1d00204 | 2012-08-02 05:01:11 -0400 | [diff] [blame] | 261 | |
Behdad Esfahbod | 11b0e20 | 2012-08-02 14:21:40 -0400 | [diff] [blame] | 262 | /* |
Behdad Esfahbod | 11b0e20 | 2012-08-02 14:21:40 -0400 | [diff] [blame] | 263 | * Indic configurations. Note that we do not want to keep every single script-specific |
| 264 | * behavior in these tables necessarily. This should mainly be used for per-script |
| 265 | * properties that are cheaper keeping here, than in the code. Ie. if, say, one and |
| 266 | * only one script has an exception, that one script can be if'ed directly in the code, |
| 267 | * instead of adding a new flag in these structs. |
| 268 | */ |
| 269 | |
| 270 | enum base_position_t { |
| 271 | BASE_POS_FIRST, |
Behdad Esfahbod | e10453e | 2013-10-17 16:49:06 +0200 | [diff] [blame] | 272 | BASE_POS_LAST_SINHALA, |
Behdad Esfahbod | 11b0e20 | 2012-08-02 14:21:40 -0400 | [diff] [blame] | 273 | BASE_POS_LAST |
| 274 | }; |
| 275 | enum reph_position_t { |
Behdad Esfahbod | 11b0e20 | 2012-08-02 14:21:40 -0400 | [diff] [blame] | 276 | REPH_POS_AFTER_MAIN = POS_AFTER_MAIN, |
| 277 | REPH_POS_BEFORE_SUB = POS_BEFORE_SUB, |
| 278 | REPH_POS_AFTER_SUB = POS_AFTER_SUB, |
| 279 | REPH_POS_BEFORE_POST = POS_BEFORE_POST, |
Behdad Esfahbod | 74f4bbf | 2013-10-17 19:07:53 +0200 | [diff] [blame] | 280 | REPH_POS_AFTER_POST = POS_AFTER_POST, |
| 281 | REPH_POS_DONT_CARE = POS_RA_TO_BECOME_REPH |
Behdad Esfahbod | 11b0e20 | 2012-08-02 14:21:40 -0400 | [diff] [blame] | 282 | }; |
| 283 | enum reph_mode_t { |
| 284 | REPH_MODE_IMPLICIT, /* Reph formed out of initial Ra,H sequence. */ |
| 285 | REPH_MODE_EXPLICIT, /* Reph formed out of initial Ra,H,ZWJ sequence. */ |
| 286 | REPH_MODE_VIS_REPHA, /* Encoded Repha character, no reordering needed. */ |
| 287 | REPH_MODE_LOG_REPHA /* Encoded Repha character, needs reordering. */ |
| 288 | }; |
Behdad Esfahbod | 8acbb6b | 2013-10-15 12:15:49 +0200 | [diff] [blame] | 289 | enum blwf_mode_t { |
| 290 | BLWF_MODE_PRE_AND_POST, /* Below-forms feature applied to pre-base and post-base. */ |
| 291 | BLWF_MODE_POST_ONLY /* Below-forms feature applied to post-base only. */ |
| 292 | }; |
Behdad Esfahbod | 74f4bbf | 2013-10-17 19:07:53 +0200 | [diff] [blame] | 293 | enum pref_len_t { |
| 294 | PREF_LEN_1 = 1, |
| 295 | PREF_LEN_2 = 2, |
| 296 | PREF_LEN_DONT_CARE = PREF_LEN_2 |
| 297 | }; |
Behdad Esfahbod | 11b0e20 | 2012-08-02 14:21:40 -0400 | [diff] [blame] | 298 | struct indic_config_t |
| 299 | { |
| 300 | hb_script_t script; |
| 301 | bool has_old_spec; |
| 302 | hb_codepoint_t virama; |
| 303 | base_position_t base_pos; |
| 304 | reph_position_t reph_pos; |
| 305 | reph_mode_t reph_mode; |
Behdad Esfahbod | 8acbb6b | 2013-10-15 12:15:49 +0200 | [diff] [blame] | 306 | blwf_mode_t blwf_mode; |
Behdad Esfahbod | 74f4bbf | 2013-10-17 19:07:53 +0200 | [diff] [blame] | 307 | pref_len_t pref_len; |
Behdad Esfahbod | 11b0e20 | 2012-08-02 14:21:40 -0400 | [diff] [blame] | 308 | }; |
| 309 | |
| 310 | static const indic_config_t indic_configs[] = |
| 311 | { |
| 312 | /* Default. Should be first. */ |
Behdad Esfahbod | 74f4bbf | 2013-10-17 19:07:53 +0200 | [diff] [blame] | 313 | {HB_SCRIPT_INVALID, false, 0,BASE_POS_LAST, REPH_POS_BEFORE_POST,REPH_MODE_IMPLICIT, BLWF_MODE_PRE_AND_POST, PREF_LEN_1}, |
| 314 | {HB_SCRIPT_DEVANAGARI,true, 0x094D,BASE_POS_LAST, REPH_POS_BEFORE_POST,REPH_MODE_IMPLICIT, BLWF_MODE_PRE_AND_POST, PREF_LEN_DONT_CARE}, |
| 315 | {HB_SCRIPT_BENGALI, true, 0x09CD,BASE_POS_LAST, REPH_POS_AFTER_SUB, REPH_MODE_IMPLICIT, BLWF_MODE_PRE_AND_POST, PREF_LEN_DONT_CARE}, |
| 316 | {HB_SCRIPT_GURMUKHI, true, 0x0A4D,BASE_POS_LAST, REPH_POS_BEFORE_SUB, REPH_MODE_IMPLICIT, BLWF_MODE_PRE_AND_POST, PREF_LEN_DONT_CARE}, |
| 317 | {HB_SCRIPT_GUJARATI, true, 0x0ACD,BASE_POS_LAST, REPH_POS_BEFORE_POST,REPH_MODE_IMPLICIT, BLWF_MODE_PRE_AND_POST, PREF_LEN_DONT_CARE}, |
| 318 | {HB_SCRIPT_ORIYA, true, 0x0B4D,BASE_POS_LAST, REPH_POS_AFTER_MAIN, REPH_MODE_IMPLICIT, BLWF_MODE_PRE_AND_POST, PREF_LEN_DONT_CARE}, |
| 319 | {HB_SCRIPT_TAMIL, true, 0x0BCD,BASE_POS_LAST, REPH_POS_AFTER_POST, REPH_MODE_IMPLICIT, BLWF_MODE_PRE_AND_POST, PREF_LEN_2}, |
| 320 | {HB_SCRIPT_TELUGU, true, 0x0C4D,BASE_POS_LAST, REPH_POS_AFTER_POST, REPH_MODE_EXPLICIT, BLWF_MODE_POST_ONLY, PREF_LEN_2}, |
| 321 | {HB_SCRIPT_KANNADA, true, 0x0CCD,BASE_POS_LAST, REPH_POS_AFTER_POST, REPH_MODE_IMPLICIT, BLWF_MODE_POST_ONLY, PREF_LEN_2}, |
| 322 | {HB_SCRIPT_MALAYALAM, true, 0x0D4D,BASE_POS_LAST, REPH_POS_AFTER_MAIN, REPH_MODE_LOG_REPHA,BLWF_MODE_PRE_AND_POST, PREF_LEN_2}, |
Behdad Esfahbod | e10453e | 2013-10-17 16:49:06 +0200 | [diff] [blame] | 323 | {HB_SCRIPT_SINHALA, false,0x0DCA,BASE_POS_LAST_SINHALA, |
Behdad Esfahbod | 74f4bbf | 2013-10-17 19:07:53 +0200 | [diff] [blame] | 324 | REPH_POS_AFTER_MAIN, REPH_MODE_EXPLICIT, BLWF_MODE_PRE_AND_POST, PREF_LEN_DONT_CARE}, |
| 325 | {HB_SCRIPT_KHMER, false,0x17D2,BASE_POS_FIRST,REPH_POS_DONT_CARE, REPH_MODE_VIS_REPHA,BLWF_MODE_PRE_AND_POST, PREF_LEN_2}, |
Behdad Esfahbod | 8f9ec92 | 2013-10-17 19:52:47 +0200 | [diff] [blame] | 326 | {HB_SCRIPT_JAVANESE, false,0xA9C0,BASE_POS_FIRST,REPH_POS_DONT_CARE, REPH_MODE_VIS_REPHA,BLWF_MODE_PRE_AND_POST, PREF_LEN_1}, |
Behdad Esfahbod | 11b0e20 | 2012-08-02 14:21:40 -0400 | [diff] [blame] | 327 | }; |
| 328 | |
| 329 | |
| 330 | |
| 331 | /* |
| 332 | * Indic shaper. |
| 333 | */ |
Behdad Esfahbod | 9ccc638 | 2012-07-19 12:32:16 -0400 | [diff] [blame] | 334 | |
Behdad Esfahbod | eed903b | 2012-05-11 20:50:53 +0200 | [diff] [blame] | 335 | struct feature_list_t { |
Behdad Esfahbod | c7fe56a | 2011-06-24 19:05:34 -0400 | [diff] [blame] | 336 | hb_tag_t tag; |
Behdad Esfahbod | ec54486 | 2013-02-14 11:25:10 -0500 | [diff] [blame] | 337 | hb_ot_map_feature_flags_t flags; |
Behdad Esfahbod | eed903b | 2012-05-11 20:50:53 +0200 | [diff] [blame] | 338 | }; |
| 339 | |
| 340 | static const feature_list_t |
Behdad Esfahbod | 85fc6c4 | 2012-08-02 12:21:44 -0400 | [diff] [blame] | 341 | indic_features[] = |
Behdad Esfahbod | b9ddbd5 | 2011-06-02 17:43:12 -0400 | [diff] [blame] | 342 | { |
Behdad Esfahbod | 85fc6c4 | 2012-08-02 12:21:44 -0400 | [diff] [blame] | 343 | /* |
| 344 | * Basic features. |
| 345 | * These features are applied in order, one at a time, after initial_reordering. |
| 346 | */ |
Behdad Esfahbod | a8cf7b4 | 2013-03-19 05:53:26 -0400 | [diff] [blame] | 347 | {HB_TAG('n','u','k','t'), F_GLOBAL}, |
| 348 | {HB_TAG('a','k','h','n'), F_GLOBAL}, |
| 349 | {HB_TAG('r','p','h','f'), F_NONE}, |
| 350 | {HB_TAG('r','k','r','f'), F_GLOBAL}, |
| 351 | {HB_TAG('p','r','e','f'), F_NONE}, |
| 352 | {HB_TAG('b','l','w','f'), F_NONE}, |
Behdad Esfahbod | a8cf7b4 | 2013-03-19 05:53:26 -0400 | [diff] [blame] | 353 | {HB_TAG('a','b','v','f'), F_NONE}, |
Behdad Esfahbod | a01cbf6 | 2013-10-15 16:37:53 +0200 | [diff] [blame] | 354 | {HB_TAG('h','a','l','f'), F_NONE}, |
Behdad Esfahbod | a8cf7b4 | 2013-03-19 05:53:26 -0400 | [diff] [blame] | 355 | {HB_TAG('p','s','t','f'), F_NONE}, |
Behdad Esfahbod | a8cf7b4 | 2013-03-19 05:53:26 -0400 | [diff] [blame] | 356 | {HB_TAG('v','a','t','u'), F_GLOBAL}, |
| 357 | {HB_TAG('c','j','c','t'), F_GLOBAL}, |
Behdad Esfahbod | a01cbf6 | 2013-10-15 16:37:53 +0200 | [diff] [blame] | 358 | {HB_TAG('c','f','a','r'), F_NONE}, |
Behdad Esfahbod | 85fc6c4 | 2012-08-02 12:21:44 -0400 | [diff] [blame] | 359 | /* |
| 360 | * Other features. |
| 361 | * These features are applied all at once, after final_reordering. |
Behdad Esfahbod | a01cbf6 | 2013-10-15 16:37:53 +0200 | [diff] [blame] | 362 | * Default Bengali font in Windows for example has intermixed |
| 363 | * lookups for init,pres,abvs,blws features. |
Behdad Esfahbod | 85fc6c4 | 2012-08-02 12:21:44 -0400 | [diff] [blame] | 364 | */ |
Behdad Esfahbod | ec54486 | 2013-02-14 11:25:10 -0500 | [diff] [blame] | 365 | {HB_TAG('i','n','i','t'), F_NONE}, |
| 366 | {HB_TAG('p','r','e','s'), F_GLOBAL}, |
| 367 | {HB_TAG('a','b','v','s'), F_GLOBAL}, |
| 368 | {HB_TAG('b','l','w','s'), F_GLOBAL}, |
| 369 | {HB_TAG('p','s','t','s'), F_GLOBAL}, |
| 370 | {HB_TAG('h','a','l','n'), F_GLOBAL}, |
Behdad Esfahbod | 85fc6c4 | 2012-08-02 12:21:44 -0400 | [diff] [blame] | 371 | /* Positioning features, though we don't care about the types. */ |
Behdad Esfahbod | ec54486 | 2013-02-14 11:25:10 -0500 | [diff] [blame] | 372 | {HB_TAG('d','i','s','t'), F_GLOBAL}, |
| 373 | {HB_TAG('a','b','v','m'), F_GLOBAL}, |
| 374 | {HB_TAG('b','l','w','m'), F_GLOBAL}, |
Behdad Esfahbod | c7fe56a | 2011-06-24 19:05:34 -0400 | [diff] [blame] | 375 | }; |
| 376 | |
Behdad Esfahbod | 85fc6c4 | 2012-08-02 12:21:44 -0400 | [diff] [blame] | 377 | /* |
| 378 | * Must be in the same order as the indic_features array. |
| 379 | */ |
Behdad Esfahbod | c7fe56a | 2011-06-24 19:05:34 -0400 | [diff] [blame] | 380 | enum { |
| 381 | _NUKT, |
Behdad Esfahbod | e047534 | 2012-07-19 20:24:14 -0400 | [diff] [blame] | 382 | _AKHN, |
Behdad Esfahbod | c7fe56a | 2011-06-24 19:05:34 -0400 | [diff] [blame] | 383 | RPHF, |
Behdad Esfahbod | df6d45c | 2012-05-09 11:38:31 +0200 | [diff] [blame] | 384 | _RKRF, |
Behdad Esfahbod | c7fe56a | 2011-06-24 19:05:34 -0400 | [diff] [blame] | 385 | PREF, |
Behdad Esfahbod | 167b625 | 2012-08-05 21:16:26 -0700 | [diff] [blame] | 386 | BLWF, |
Behdad Esfahbod | 29f106d | 2012-07-16 12:05:35 -0400 | [diff] [blame] | 387 | ABVF, |
Behdad Esfahbod | a01cbf6 | 2013-10-15 16:37:53 +0200 | [diff] [blame] | 388 | HALF, |
Behdad Esfahbod | c7fe56a | 2011-06-24 19:05:34 -0400 | [diff] [blame] | 389 | PSTF, |
Behdad Esfahbod | 85fc6c4 | 2012-08-02 12:21:44 -0400 | [diff] [blame] | 390 | _VATU, |
Behdad Esfahbod | 70d6565 | 2013-02-12 18:01:21 -0500 | [diff] [blame] | 391 | _CJCT, |
Behdad Esfahbod | a01cbf6 | 2013-10-15 16:37:53 +0200 | [diff] [blame] | 392 | CFAR, |
Behdad Esfahbod | 85fc6c4 | 2012-08-02 12:21:44 -0400 | [diff] [blame] | 393 | |
| 394 | INIT, |
| 395 | _PRES, |
| 396 | _ABVS, |
| 397 | _BLWS, |
| 398 | _PSTS, |
| 399 | _HALN, |
| 400 | _DIST, |
| 401 | _ABVM, |
| 402 | _BLWM, |
| 403 | |
| 404 | INDIC_NUM_FEATURES, |
| 405 | INDIC_BASIC_FEATURES = INIT /* Don't forget to update this! */ |
Behdad Esfahbod | b9ddbd5 | 2011-06-02 17:43:12 -0400 | [diff] [blame] | 406 | }; |
| 407 | |
Behdad Esfahbod | 743807a | 2011-07-29 16:37:02 -0400 | [diff] [blame] | 408 | static void |
Behdad Esfahbod | 166b5cf | 2012-09-07 14:55:07 -0400 | [diff] [blame] | 409 | setup_syllables (const hb_ot_shape_plan_t *plan, |
| 410 | hb_font_t *font, |
| 411 | hb_buffer_t *buffer); |
| 412 | static void |
Behdad Esfahbod | 8bb5deb | 2012-08-02 10:07:58 -0400 | [diff] [blame] | 413 | initial_reordering (const hb_ot_shape_plan_t *plan, |
Behdad Esfahbod | afbcc24 | 2012-08-02 08:36:40 -0400 | [diff] [blame] | 414 | hb_font_t *font, |
Behdad Esfahbod | 3e38c0f | 2012-08-02 09:44:18 -0400 | [diff] [blame] | 415 | hb_buffer_t *buffer); |
Behdad Esfahbod | f6fd378 | 2011-07-08 00:22:40 -0400 | [diff] [blame] | 416 | static void |
Behdad Esfahbod | 8bb5deb | 2012-08-02 10:07:58 -0400 | [diff] [blame] | 417 | final_reordering (const hb_ot_shape_plan_t *plan, |
Behdad Esfahbod | afbcc24 | 2012-08-02 08:36:40 -0400 | [diff] [blame] | 418 | hb_font_t *font, |
Behdad Esfahbod | 3e38c0f | 2012-08-02 09:44:18 -0400 | [diff] [blame] | 419 | hb_buffer_t *buffer); |
Behdad Esfahbod | 3014527 | 2013-10-15 13:47:27 +0200 | [diff] [blame] | 420 | static void |
| 421 | clear_syllables (const hb_ot_shape_plan_t *plan, |
| 422 | hb_font_t *font, |
| 423 | hb_buffer_t *buffer); |
Behdad Esfahbod | b9ddbd5 | 2011-06-02 17:43:12 -0400 | [diff] [blame] | 424 | |
Behdad Esfahbod | 693918e | 2012-07-30 21:08:51 -0400 | [diff] [blame] | 425 | static void |
Behdad Esfahbod | 16c6a27 | 2012-08-02 09:38:28 -0400 | [diff] [blame] | 426 | collect_features_indic (hb_ot_shape_planner_t *plan) |
Behdad Esfahbod | b9ddbd5 | 2011-06-02 17:43:12 -0400 | [diff] [blame] | 427 | { |
Behdad Esfahbod | 16c6a27 | 2012-08-02 09:38:28 -0400 | [diff] [blame] | 428 | hb_ot_map_builder_t *map = &plan->map; |
| 429 | |
Behdad Esfahbod | 166b5cf | 2012-09-07 14:55:07 -0400 | [diff] [blame] | 430 | /* Do this before any lookups have been applied. */ |
| 431 | map->add_gsub_pause (setup_syllables); |
| 432 | |
Behdad Esfahbod | e7ffcfa | 2013-02-14 11:05:56 -0500 | [diff] [blame] | 433 | map->add_global_bool_feature (HB_TAG('l','o','c','l')); |
Behdad Esfahbod | a54a550 | 2011-07-20 16:42:10 -0400 | [diff] [blame] | 434 | /* The Indic specs do not require ccmp, but we apply it here since if |
| 435 | * there is a use of it, it's typically at the beginning. */ |
Behdad Esfahbod | e7ffcfa | 2013-02-14 11:05:56 -0500 | [diff] [blame] | 436 | map->add_global_bool_feature (HB_TAG('c','c','m','p')); |
Behdad Esfahbod | f6fd378 | 2011-07-08 00:22:40 -0400 | [diff] [blame] | 437 | |
Behdad Esfahbod | f6fd378 | 2011-07-08 00:22:40 -0400 | [diff] [blame] | 438 | |
Behdad Esfahbod | 85fc6c4 | 2012-08-02 12:21:44 -0400 | [diff] [blame] | 439 | unsigned int i = 0; |
| 440 | map->add_gsub_pause (initial_reordering); |
| 441 | for (; i < INDIC_BASIC_FEATURES; i++) { |
Behdad Esfahbod | a8cf7b4 | 2013-03-19 05:53:26 -0400 | [diff] [blame] | 442 | map->add_feature (indic_features[i].tag, 1, indic_features[i].flags | F_MANUAL_ZWJ); |
Behdad Esfahbod | 3e38c0f | 2012-08-02 09:44:18 -0400 | [diff] [blame] | 443 | map->add_gsub_pause (NULL); |
Behdad Esfahbod | 412b918 | 2012-05-09 11:07:18 +0200 | [diff] [blame] | 444 | } |
Behdad Esfahbod | 3e38c0f | 2012-08-02 09:44:18 -0400 | [diff] [blame] | 445 | map->add_gsub_pause (final_reordering); |
Behdad Esfahbod | 85fc6c4 | 2012-08-02 12:21:44 -0400 | [diff] [blame] | 446 | for (; i < INDIC_NUM_FEATURES; i++) { |
Behdad Esfahbod | a8cf7b4 | 2013-03-19 05:53:26 -0400 | [diff] [blame] | 447 | map->add_feature (indic_features[i].tag, 1, indic_features[i].flags | F_MANUAL_ZWJ); |
Behdad Esfahbod | 85fc6c4 | 2012-08-02 12:21:44 -0400 | [diff] [blame] | 448 | } |
Behdad Esfahbod | 42d0f55 | 2013-10-17 13:05:05 +0200 | [diff] [blame] | 449 | |
| 450 | map->add_global_bool_feature (HB_TAG('c','a','l','t')); |
| 451 | map->add_global_bool_feature (HB_TAG('c','l','i','g')); |
| 452 | |
Behdad Esfahbod | 3014527 | 2013-10-15 13:47:27 +0200 | [diff] [blame] | 453 | map->add_gsub_pause (clear_syllables); |
Behdad Esfahbod | b9ddbd5 | 2011-06-02 17:43:12 -0400 | [diff] [blame] | 454 | } |
| 455 | |
Behdad Esfahbod | 693918e | 2012-07-30 21:08:51 -0400 | [diff] [blame] | 456 | static void |
Behdad Esfahbod | 16c6a27 | 2012-08-02 09:38:28 -0400 | [diff] [blame] | 457 | override_features_indic (hb_ot_shape_planner_t *plan) |
Behdad Esfahbod | d96838e | 2012-07-16 20:26:57 -0400 | [diff] [blame] | 458 | { |
Behdad Esfahbod | eb10233 | 2013-10-15 15:26:44 +0200 | [diff] [blame] | 459 | /* Uniscribe does not apply 'kern' in Khmer. */ |
Behdad Esfahbod | bab02d3 | 2013-02-12 15:26:45 -0500 | [diff] [blame] | 460 | if (hb_options ().uniscribe_bug_compatible) |
Behdad Esfahbod | eb10233 | 2013-10-15 15:26:44 +0200 | [diff] [blame] | 461 | { |
| 462 | switch ((hb_tag_t) plan->props.script) |
| 463 | { |
| 464 | case HB_SCRIPT_KHMER: |
Behdad Esfahbod | 9ac6b01 | 2013-10-17 16:27:38 +0200 | [diff] [blame] | 465 | plan->map.add_feature (HB_TAG('k','e','r','n'), 0, F_GLOBAL); |
Behdad Esfahbod | eb10233 | 2013-10-15 15:26:44 +0200 | [diff] [blame] | 466 | break; |
| 467 | } |
| 468 | } |
Behdad Esfahbod | 6b389dd | 2012-11-12 11:02:56 -0800 | [diff] [blame] | 469 | |
Behdad Esfahbod | ec54486 | 2013-02-14 11:25:10 -0500 | [diff] [blame] | 470 | plan->map.add_feature (HB_TAG('l','i','g','a'), 0, F_GLOBAL); |
Behdad Esfahbod | d96838e | 2012-07-16 20:26:57 -0400 | [diff] [blame] | 471 | } |
| 472 | |
Behdad Esfahbod | 867361c | 2011-06-17 18:35:46 -0400 | [diff] [blame] | 473 | |
Behdad Esfahbod | 85fc6c4 | 2012-08-02 12:21:44 -0400 | [diff] [blame] | 474 | struct would_substitute_feature_t |
Behdad Esfahbod | a8c6da9 | 2012-08-02 10:46:34 -0400 | [diff] [blame] | 475 | { |
Behdad Esfahbod | b5a0f69 | 2013-10-17 18:04:23 +0200 | [diff] [blame] | 476 | inline void init (const hb_ot_map_t *map, hb_tag_t feature_tag, bool zero_context_) |
Behdad Esfahbod | a8c6da9 | 2012-08-02 10:46:34 -0400 | [diff] [blame] | 477 | { |
Behdad Esfahbod | b5a0f69 | 2013-10-17 18:04:23 +0200 | [diff] [blame] | 478 | zero_context = zero_context_; |
Behdad Esfahbod | a8c6da9 | 2012-08-02 10:46:34 -0400 | [diff] [blame] | 479 | map->get_stage_lookups (0/*GSUB*/, |
| 480 | map->get_feature_stage (0/*GSUB*/, feature_tag), |
| 481 | &lookups, &count); |
| 482 | } |
| 483 | |
Behdad Esfahbod | 8144936 | 2013-03-05 20:08:59 -0500 | [diff] [blame] | 484 | inline bool would_substitute (const hb_codepoint_t *glyphs, |
| 485 | unsigned int glyphs_count, |
Behdad Esfahbod | 8144936 | 2013-03-05 20:08:59 -0500 | [diff] [blame] | 486 | hb_face_t *face) const |
Behdad Esfahbod | a8c6da9 | 2012-08-02 10:46:34 -0400 | [diff] [blame] | 487 | { |
| 488 | for (unsigned int i = 0; i < count; i++) |
Behdad Esfahbod | 362a990 | 2012-11-15 14:57:31 -0800 | [diff] [blame] | 489 | if (hb_ot_layout_lookup_would_substitute_fast (face, lookups[i].index, glyphs, glyphs_count, zero_context)) |
Behdad Esfahbod | a8c6da9 | 2012-08-02 10:46:34 -0400 | [diff] [blame] | 490 | return true; |
| 491 | return false; |
| 492 | } |
| 493 | |
| 494 | private: |
| 495 | const hb_ot_map_t::lookup_map_t *lookups; |
| 496 | unsigned int count; |
Behdad Esfahbod | b5a0f69 | 2013-10-17 18:04:23 +0200 | [diff] [blame] | 497 | bool zero_context; |
Behdad Esfahbod | a8c6da9 | 2012-08-02 10:46:34 -0400 | [diff] [blame] | 498 | }; |
| 499 | |
| 500 | struct indic_shape_plan_t |
| 501 | { |
Behdad Esfahbod | 85fc6c4 | 2012-08-02 12:21:44 -0400 | [diff] [blame] | 502 | ASSERT_POD (); |
Behdad Esfahbod | 914ffaa | 2012-08-02 11:03:39 -0400 | [diff] [blame] | 503 | |
| 504 | inline bool get_virama_glyph (hb_font_t *font, hb_codepoint_t *pglyph) const |
| 505 | { |
| 506 | hb_codepoint_t glyph = virama_glyph; |
| 507 | if (unlikely (virama_glyph == (hb_codepoint_t) -1)) |
| 508 | { |
Behdad Esfahbod | 11b0e20 | 2012-08-02 14:21:40 -0400 | [diff] [blame] | 509 | if (!config->virama || !font->get_glyph (config->virama, 0, &glyph)) |
Behdad Esfahbod | 914ffaa | 2012-08-02 11:03:39 -0400 | [diff] [blame] | 510 | glyph = 0; |
| 511 | /* Technically speaking, the spec says we should apply 'locl' to virama too. |
| 512 | * Maybe one day... */ |
| 513 | |
| 514 | /* Our get_glyph() function needs a font, so we can't get the virama glyph |
| 515 | * during shape planning... Instead, overwrite it here. It's safe. Don't worry! */ |
| 516 | (const_cast<indic_shape_plan_t *> (this))->virama_glyph = glyph; |
| 517 | } |
| 518 | |
| 519 | *pglyph = glyph; |
| 520 | return glyph != 0; |
| 521 | } |
Behdad Esfahbod | 85fc6c4 | 2012-08-02 12:21:44 -0400 | [diff] [blame] | 522 | |
Behdad Esfahbod | 11b0e20 | 2012-08-02 14:21:40 -0400 | [diff] [blame] | 523 | const indic_config_t *config; |
Behdad Esfahbod | 85fc6c4 | 2012-08-02 12:21:44 -0400 | [diff] [blame] | 524 | |
| 525 | bool is_old_spec; |
Behdad Esfahbod | 85fc6c4 | 2012-08-02 12:21:44 -0400 | [diff] [blame] | 526 | hb_codepoint_t virama_glyph; |
| 527 | |
Behdad Esfahbod | f2c0f59 | 2012-11-12 14:02:02 -0800 | [diff] [blame] | 528 | would_substitute_feature_t rphf; |
Behdad Esfahbod | 85fc6c4 | 2012-08-02 12:21:44 -0400 | [diff] [blame] | 529 | would_substitute_feature_t pref; |
| 530 | would_substitute_feature_t blwf; |
| 531 | would_substitute_feature_t pstf; |
| 532 | |
| 533 | hb_mask_t mask_array[INDIC_NUM_FEATURES]; |
Behdad Esfahbod | a8c6da9 | 2012-08-02 10:46:34 -0400 | [diff] [blame] | 534 | }; |
| 535 | |
| 536 | static void * |
| 537 | data_create_indic (const hb_ot_shape_plan_t *plan) |
| 538 | { |
Behdad Esfahbod | 85fc6c4 | 2012-08-02 12:21:44 -0400 | [diff] [blame] | 539 | indic_shape_plan_t *indic_plan = (indic_shape_plan_t *) calloc (1, sizeof (indic_shape_plan_t)); |
| 540 | if (unlikely (!indic_plan)) |
Behdad Esfahbod | a8c6da9 | 2012-08-02 10:46:34 -0400 | [diff] [blame] | 541 | return NULL; |
| 542 | |
Behdad Esfahbod | 11b0e20 | 2012-08-02 14:21:40 -0400 | [diff] [blame] | 543 | indic_plan->config = &indic_configs[0]; |
| 544 | for (unsigned int i = 1; i < ARRAY_LENGTH (indic_configs); i++) |
| 545 | if (plan->props.script == indic_configs[i].script) { |
| 546 | indic_plan->config = &indic_configs[i]; |
| 547 | break; |
Behdad Esfahbod | 85fc6c4 | 2012-08-02 12:21:44 -0400 | [diff] [blame] | 548 | } |
Behdad Esfahbod | 11b0e20 | 2012-08-02 14:21:40 -0400 | [diff] [blame] | 549 | |
Behdad Esfahbod | 851784f | 2012-11-14 16:24:05 -0800 | [diff] [blame] | 550 | indic_plan->is_old_spec = indic_plan->config->has_old_spec && ((plan->map.chosen_script[0] & 0x000000FF) != '2'); |
Behdad Esfahbod | 11b0e20 | 2012-08-02 14:21:40 -0400 | [diff] [blame] | 551 | indic_plan->virama_glyph = (hb_codepoint_t) -1; |
Behdad Esfahbod | a8c6da9 | 2012-08-02 10:46:34 -0400 | [diff] [blame] | 552 | |
Behdad Esfahbod | b5a0f69 | 2013-10-17 18:04:23 +0200 | [diff] [blame] | 553 | /* Use zero-context would_substitute() matching for new-spec of the main |
| 554 | * Indic scripts, but not for old-spec or scripts with one spec only. */ |
| 555 | bool zero_context = indic_plan->config->has_old_spec || !indic_plan->is_old_spec; |
| 556 | indic_plan->rphf.init (&plan->map, HB_TAG('r','p','h','f'), zero_context); |
| 557 | indic_plan->pref.init (&plan->map, HB_TAG('p','r','e','f'), zero_context); |
| 558 | indic_plan->blwf.init (&plan->map, HB_TAG('b','l','w','f'), zero_context); |
| 559 | indic_plan->pstf.init (&plan->map, HB_TAG('p','s','t','f'), zero_context); |
Behdad Esfahbod | 85fc6c4 | 2012-08-02 12:21:44 -0400 | [diff] [blame] | 560 | |
| 561 | for (unsigned int i = 0; i < ARRAY_LENGTH (indic_plan->mask_array); i++) |
Behdad Esfahbod | ec54486 | 2013-02-14 11:25:10 -0500 | [diff] [blame] | 562 | indic_plan->mask_array[i] = (indic_features[i].flags & F_GLOBAL) ? |
| 563 | 0 : plan->map.get_1_mask (indic_features[i].tag); |
Behdad Esfahbod | 85fc6c4 | 2012-08-02 12:21:44 -0400 | [diff] [blame] | 564 | |
| 565 | return indic_plan; |
Behdad Esfahbod | a8c6da9 | 2012-08-02 10:46:34 -0400 | [diff] [blame] | 566 | } |
| 567 | |
| 568 | static void |
| 569 | data_destroy_indic (void *data) |
| 570 | { |
| 571 | free (data); |
| 572 | } |
| 573 | |
| 574 | static indic_position_t |
| 575 | consonant_position_from_face (const indic_shape_plan_t *indic_plan, |
Behdad Esfahbod | 684fe59 | 2013-10-17 18:30:06 +0200 | [diff] [blame] | 576 | const hb_codepoint_t consonant, |
| 577 | const hb_codepoint_t virama, |
Behdad Esfahbod | 8144936 | 2013-03-05 20:08:59 -0500 | [diff] [blame] | 578 | hb_face_t *face) |
Behdad Esfahbod | a8c6da9 | 2012-08-02 10:46:34 -0400 | [diff] [blame] | 579 | { |
Behdad Esfahbod | 8144936 | 2013-03-05 20:08:59 -0500 | [diff] [blame] | 580 | /* For old-spec, the order of glyphs is Consonant,Virama, |
| 581 | * whereas for new-spec, it's Virama,Consonant. However, |
| 582 | * some broken fonts (like Free Sans) simply copied lookups |
| 583 | * from old-spec to new-spec without modification. |
| 584 | * And oddly enough, Uniscribe seems to respect those lookups. |
| 585 | * Eg. in the sequence U+0924,U+094D,U+0930, Uniscribe finds |
| 586 | * base at 0. The font however, only has lookups matching |
| 587 | * 930,94D in 'blwf', not the expected 94D,930 (with new-spec |
| 588 | * table). As such, we simply match both sequences. Seems |
| 589 | * to work. */ |
Behdad Esfahbod | 684fe59 | 2013-10-17 18:30:06 +0200 | [diff] [blame] | 590 | hb_codepoint_t glyphs[3] = {virama, consonant, virama}; |
Behdad Esfahbod | b5a0f69 | 2013-10-17 18:04:23 +0200 | [diff] [blame] | 591 | if (indic_plan->blwf.would_substitute (glyphs , 2, face) || |
Behdad Esfahbod | 684fe59 | 2013-10-17 18:30:06 +0200 | [diff] [blame] | 592 | indic_plan->blwf.would_substitute (glyphs+1, 2, face)) |
Behdad Esfahbod | 8144936 | 2013-03-05 20:08:59 -0500 | [diff] [blame] | 593 | return POS_BELOW_C; |
Behdad Esfahbod | b5a0f69 | 2013-10-17 18:04:23 +0200 | [diff] [blame] | 594 | if (indic_plan->pstf.would_substitute (glyphs , 2, face) || |
Behdad Esfahbod | 684fe59 | 2013-10-17 18:30:06 +0200 | [diff] [blame] | 595 | indic_plan->pstf.would_substitute (glyphs+1, 2, face)) |
Behdad Esfahbod | 8144936 | 2013-03-05 20:08:59 -0500 | [diff] [blame] | 596 | return POS_POST_C; |
Behdad Esfahbod | 74f4bbf | 2013-10-17 19:07:53 +0200 | [diff] [blame] | 597 | unsigned int pref_len = indic_plan->config->pref_len; |
| 598 | if ((pref_len == PREF_LEN_2 && |
| 599 | (indic_plan->pref.would_substitute (glyphs , 2, face) || |
| 600 | indic_plan->pref.would_substitute (glyphs+1, 2, face))) |
| 601 | || (pref_len == PREF_LEN_1 && |
| 602 | indic_plan->pref.would_substitute (glyphs+1, 1, face))) |
Behdad Esfahbod | ae9a583 | 2013-10-17 12:24:55 +0200 | [diff] [blame] | 603 | return POS_POST_C; |
Behdad Esfahbod | a8c6da9 | 2012-08-02 10:46:34 -0400 | [diff] [blame] | 604 | return POS_BASE_C; |
| 605 | } |
| 606 | |
| 607 | |
Behdad Esfahbod | 166b5cf | 2012-09-07 14:55:07 -0400 | [diff] [blame] | 608 | enum syllable_type_t { |
| 609 | consonant_syllable, |
| 610 | vowel_syllable, |
| 611 | standalone_cluster, |
Behdad Esfahbod | 3c7b364 | 2013-10-15 11:21:01 +0200 | [diff] [blame] | 612 | avagraha_cluster, |
Behdad Esfahbod | 166b5cf | 2012-09-07 14:55:07 -0400 | [diff] [blame] | 613 | broken_cluster, |
| 614 | non_indic_cluster, |
| 615 | }; |
| 616 | |
| 617 | #include "hb-ot-shape-complex-indic-machine.hh" |
| 618 | |
| 619 | |
Behdad Esfahbod | 693918e | 2012-07-30 21:08:51 -0400 | [diff] [blame] | 620 | static void |
Behdad Esfahbod | 16c6a27 | 2012-08-02 09:38:28 -0400 | [diff] [blame] | 621 | setup_masks_indic (const hb_ot_shape_plan_t *plan HB_UNUSED, |
| 622 | hb_buffer_t *buffer, |
| 623 | hb_font_t *font HB_UNUSED) |
Behdad Esfahbod | 24eacf1 | 2012-08-02 08:42:11 -0400 | [diff] [blame] | 624 | { |
| 625 | HB_BUFFER_ALLOCATE_VAR (buffer, indic_category); |
| 626 | HB_BUFFER_ALLOCATE_VAR (buffer, indic_position); |
| 627 | |
| 628 | /* We cannot setup masks here. We save information about characters |
| 629 | * and setup masks later on in a pause-callback. */ |
| 630 | |
| 631 | unsigned int count = buffer->len; |
| 632 | for (unsigned int i = 0; i < count; i++) |
| 633 | set_indic_properties (buffer->info[i]); |
| 634 | } |
| 635 | |
Behdad Esfahbod | 166b5cf | 2012-09-07 14:55:07 -0400 | [diff] [blame] | 636 | static void |
| 637 | setup_syllables (const hb_ot_shape_plan_t *plan HB_UNUSED, |
| 638 | hb_font_t *font HB_UNUSED, |
| 639 | hb_buffer_t *buffer) |
| 640 | { |
| 641 | find_syllables (buffer); |
| 642 | } |
| 643 | |
Behdad Esfahbod | 24eacf1 | 2012-08-02 08:42:11 -0400 | [diff] [blame] | 644 | static int |
| 645 | compare_indic_order (const hb_glyph_info_t *pa, const hb_glyph_info_t *pb) |
| 646 | { |
| 647 | int a = pa->indic_position(); |
| 648 | int b = pb->indic_position(); |
| 649 | |
| 650 | return a < b ? -1 : a == b ? 0 : +1; |
| 651 | } |
| 652 | |
| 653 | |
| 654 | |
| 655 | static void |
Behdad Esfahbod | 8bb5deb | 2012-08-02 10:07:58 -0400 | [diff] [blame] | 656 | update_consonant_positions (const hb_ot_shape_plan_t *plan, |
Behdad Esfahbod | 85fc6c4 | 2012-08-02 12:21:44 -0400 | [diff] [blame] | 657 | hb_font_t *font, |
| 658 | hb_buffer_t *buffer) |
Behdad Esfahbod | 8ef3d53 | 2012-08-02 07:53:18 -0400 | [diff] [blame] | 659 | { |
Behdad Esfahbod | a8c6da9 | 2012-08-02 10:46:34 -0400 | [diff] [blame] | 660 | const indic_shape_plan_t *indic_plan = (const indic_shape_plan_t *) plan->data; |
Behdad Esfahbod | 8ef3d53 | 2012-08-02 07:53:18 -0400 | [diff] [blame] | 661 | |
Behdad Esfahbod | c4e71ff | 2013-10-17 17:04:47 +0200 | [diff] [blame] | 662 | if (indic_plan->config->base_pos != BASE_POS_LAST) |
| 663 | return; |
| 664 | |
Behdad Esfahbod | 684fe59 | 2013-10-17 18:30:06 +0200 | [diff] [blame] | 665 | hb_codepoint_t virama; |
| 666 | if (indic_plan->get_virama_glyph (font, &virama)) |
Behdad Esfahbod | 8ef3d53 | 2012-08-02 07:53:18 -0400 | [diff] [blame] | 667 | { |
| 668 | hb_face_t *face = font->face; |
| 669 | unsigned int count = buffer->len; |
| 670 | for (unsigned int i = 0; i < count; i++) |
| 671 | if (buffer->info[i].indic_position() == POS_BASE_C) { |
Behdad Esfahbod | 684fe59 | 2013-10-17 18:30:06 +0200 | [diff] [blame] | 672 | hb_codepoint_t consonant = buffer->info[i].codepoint; |
| 673 | buffer->info[i].indic_position() = consonant_position_from_face (indic_plan, consonant, virama, face); |
Behdad Esfahbod | 8ef3d53 | 2012-08-02 07:53:18 -0400 | [diff] [blame] | 674 | } |
| 675 | } |
| 676 | } |
| 677 | |
Behdad Esfahbod | 867361c | 2011-06-17 18:35:46 -0400 | [diff] [blame] | 678 | |
Behdad Esfahbod | 7ea58db | 2012-05-11 18:58:57 +0200 | [diff] [blame] | 679 | /* Rules from: |
| 680 | * https://www.microsoft.com/typography/otfntdev/devanot/shaping.aspx */ |
| 681 | |
Behdad Esfahbod | 743807a | 2011-07-29 16:37:02 -0400 | [diff] [blame] | 682 | static void |
Behdad Esfahbod | f2c0f59 | 2012-11-12 14:02:02 -0800 | [diff] [blame] | 683 | initial_reordering_consonant_syllable (const hb_ot_shape_plan_t *plan, |
| 684 | hb_face_t *face, |
| 685 | hb_buffer_t *buffer, |
Behdad Esfahbod | ef24cc8 | 2012-05-09 17:56:03 +0200 | [diff] [blame] | 686 | unsigned int start, unsigned int end) |
Behdad Esfahbod | 743807a | 2011-07-29 16:37:02 -0400 | [diff] [blame] | 687 | { |
Behdad Esfahbod | 914ffaa | 2012-08-02 11:03:39 -0400 | [diff] [blame] | 688 | const indic_shape_plan_t *indic_plan = (const indic_shape_plan_t *) plan->data; |
Behdad Esfahbod | ee58f3b | 2011-07-30 19:15:53 -0400 | [diff] [blame] | 689 | hb_glyph_info_t *info = buffer->info; |
Behdad Esfahbod | 743807a | 2011-07-29 16:37:02 -0400 | [diff] [blame] | 690 | |
Behdad Esfahbod | 617f4ac | 2012-05-13 16:48:03 +0200 | [diff] [blame] | 691 | |
Behdad Esfahbod | 743807a | 2011-07-29 16:37:02 -0400 | [diff] [blame] | 692 | /* 1. Find base consonant: |
| 693 | * |
| 694 | * The shaping engine finds the base consonant of the syllable, using the |
| 695 | * following algorithm: starting from the end of the syllable, move backwards |
| 696 | * until a consonant is found that does not have a below-base or post-base |
| 697 | * form (post-base forms have to follow below-base forms), or that is not a |
| 698 | * pre-base reordering Ra, or arrive at the first consonant. The consonant |
| 699 | * stopped at will be the base. |
| 700 | * |
| 701 | * o If the syllable starts with Ra + Halant (in a script that has Reph) |
| 702 | * and has more than one consonant, Ra is excluded from candidates for |
| 703 | * base consonants. |
| 704 | */ |
| 705 | |
Behdad Esfahbod | 5e72071 | 2011-07-31 17:51:50 -0400 | [diff] [blame] | 706 | unsigned int base = end; |
Behdad Esfahbod | 76b3409 | 2012-05-09 11:43:43 +0200 | [diff] [blame] | 707 | bool has_reph = false; |
| 708 | |
Behdad Esfahbod | 76b3409 | 2012-05-09 11:43:43 +0200 | [diff] [blame] | 709 | { |
Behdad Esfahbod | 617f4ac | 2012-05-13 16:48:03 +0200 | [diff] [blame] | 710 | /* -> If the syllable starts with Ra + Halant (in a script that has Reph) |
| 711 | * and has more than one consonant, Ra is excluded from candidates for |
| 712 | * base consonants. */ |
| 713 | unsigned int limit = start; |
Behdad Esfahbod | efed40b | 2013-10-17 18:50:11 +0200 | [diff] [blame] | 714 | if (indic_plan->config->reph_pos != POS_RA_TO_BECOME_REPH && |
| 715 | indic_plan->mask_array[RPHF] && |
Behdad Esfahbod | 617f4ac | 2012-05-13 16:48:03 +0200 | [diff] [blame] | 716 | start + 3 <= end && |
Behdad Esfahbod | 8b217f5 | 2012-12-21 15:48:32 -0500 | [diff] [blame] | 717 | ( |
Behdad Esfahbod | 11b0e20 | 2012-08-02 14:21:40 -0400 | [diff] [blame] | 718 | (indic_plan->config->reph_mode == REPH_MODE_IMPLICIT && !is_joiner (info[start + 2])) || |
| 719 | (indic_plan->config->reph_mode == REPH_MODE_EXPLICIT && info[start + 2].indic_category() == OT_ZWJ) |
Behdad Esfahbod | 3285e10 | 2012-07-18 17:22:14 -0400 | [diff] [blame] | 720 | )) |
Behdad Esfahbod | 617f4ac | 2012-05-13 16:48:03 +0200 | [diff] [blame] | 721 | { |
Behdad Esfahbod | f2c0f59 | 2012-11-12 14:02:02 -0800 | [diff] [blame] | 722 | /* See if it matches the 'rphf' feature. */ |
| 723 | hb_codepoint_t glyphs[2] = {info[start].codepoint, info[start + 1].codepoint}; |
Behdad Esfahbod | b5a0f69 | 2013-10-17 18:04:23 +0200 | [diff] [blame] | 724 | if (indic_plan->rphf.would_substitute (glyphs, ARRAY_LENGTH (glyphs), face)) |
Behdad Esfahbod | f2c0f59 | 2012-11-12 14:02:02 -0800 | [diff] [blame] | 725 | { |
| 726 | limit += 2; |
| 727 | while (limit < end && is_joiner (info[limit])) |
| 728 | limit++; |
| 729 | base = start; |
| 730 | has_reph = true; |
| 731 | } |
Behdad Esfahbod | 8b217f5 | 2012-12-21 15:48:32 -0500 | [diff] [blame] | 732 | } else if (indic_plan->config->reph_mode == REPH_MODE_LOG_REPHA && info[start].indic_category() == OT_Repha) |
| 733 | { |
| 734 | limit += 1; |
| 735 | while (limit < end && is_joiner (info[limit])) |
| 736 | limit++; |
| 737 | base = start; |
| 738 | has_reph = true; |
| 739 | } |
Behdad Esfahbod | 743807a | 2011-07-29 16:37:02 -0400 | [diff] [blame] | 740 | |
Behdad Esfahbod | 23b0e9d | 2012-08-26 14:30:18 -0400 | [diff] [blame] | 741 | switch (indic_plan->config->base_pos) |
Behdad Esfahbod | 14dbdd9 | 2012-07-18 13:13:03 -0400 | [diff] [blame] | 742 | { |
Behdad Esfahbod | d469fad | 2012-11-14 15:07:36 -0800 | [diff] [blame] | 743 | default: |
| 744 | assert (false); |
| 745 | /* fallthrough */ |
| 746 | |
Behdad Esfahbod | 11b0e20 | 2012-08-02 14:21:40 -0400 | [diff] [blame] | 747 | case BASE_POS_LAST: |
| 748 | { |
| 749 | /* -> starting from the end of the syllable, move backwards */ |
| 750 | unsigned int i = end; |
| 751 | bool seen_below = false; |
| 752 | do { |
| 753 | i--; |
| 754 | /* -> until a consonant is found */ |
| 755 | if (is_consonant (info[i])) |
| 756 | { |
| 757 | /* -> that does not have a below-base or post-base form |
| 758 | * (post-base forms have to follow below-base forms), */ |
| 759 | if (info[i].indic_position() != POS_BELOW_C && |
| 760 | (info[i].indic_position() != POS_POST_C || seen_below)) |
| 761 | { |
| 762 | base = i; |
| 763 | break; |
| 764 | } |
| 765 | if (info[i].indic_position() == POS_BELOW_C) |
| 766 | seen_below = true; |
| 767 | |
| 768 | /* -> or that is not a pre-base reordering Ra, |
| 769 | * |
| 770 | * IMPLEMENTATION NOTES: |
| 771 | * |
Behdad Esfahbod | fb7c182 | 2013-03-06 00:53:24 -0500 | [diff] [blame] | 772 | * Our pre-base reordering Ra's are marked POS_POST_C, so will be skipped |
Behdad Esfahbod | 11b0e20 | 2012-08-02 14:21:40 -0400 | [diff] [blame] | 773 | * by the logic above already. |
| 774 | */ |
| 775 | |
| 776 | /* -> or arrive at the first consonant. The consonant stopped at will |
| 777 | * be the base. */ |
| 778 | base = i; |
| 779 | } |
| 780 | else |
| 781 | { |
| 782 | /* A ZWJ after a Halant stops the base search, and requests an explicit |
| 783 | * half form. |
| 784 | * A ZWJ before a Halant, requests a subjoined form instead, and hence |
| 785 | * search continues. This is particularly important for Bengali |
Behdad Esfahbod | c4be991 | 2012-11-12 14:27:33 -0800 | [diff] [blame] | 786 | * sequence Ra,H,Ya that should form Ya-Phalaa by subjoining Ya. */ |
Behdad Esfahbod | 11b0e20 | 2012-08-02 14:21:40 -0400 | [diff] [blame] | 787 | if (start < i && |
| 788 | info[i].indic_category() == OT_ZWJ && |
| 789 | info[i - 1].indic_category() == OT_H) |
| 790 | break; |
| 791 | } |
| 792 | } while (i > limit); |
| 793 | } |
| 794 | break; |
| 795 | |
Behdad Esfahbod | e10453e | 2013-10-17 16:49:06 +0200 | [diff] [blame] | 796 | case BASE_POS_LAST_SINHALA: |
Behdad Esfahbod | 11b0e20 | 2012-08-02 14:21:40 -0400 | [diff] [blame] | 797 | { |
Behdad Esfahbod | c4e71ff | 2013-10-17 17:04:47 +0200 | [diff] [blame] | 798 | /* Sinhala base positioning is slightly different from main Indic, in that: |
| 799 | * 1. It's ZWJ behavior is different, |
| 800 | * 2. We don't need to look into the font for consonant positions. |
| 801 | */ |
Behdad Esfahbod | 11b0e20 | 2012-08-02 14:21:40 -0400 | [diff] [blame] | 802 | |
| 803 | if (!has_reph) |
| 804 | base = limit; |
| 805 | |
| 806 | /* Find the last base consonant that is not blocked by ZWJ. If there is |
| 807 | * a ZWJ right before a base consonant, that would request a subjoined form. */ |
| 808 | for (unsigned int i = limit; i < end; i++) |
Behdad Esfahbod | c4e71ff | 2013-10-17 17:04:47 +0200 | [diff] [blame] | 809 | if (is_consonant (info[i])) |
Behdad Esfahbod | 11b0e20 | 2012-08-02 14:21:40 -0400 | [diff] [blame] | 810 | { |
| 811 | if (limit < i && info[i - 1].indic_category() == OT_ZWJ) |
| 812 | break; |
| 813 | else |
| 814 | base = i; |
| 815 | } |
| 816 | |
| 817 | /* Mark all subsequent consonants as below. */ |
| 818 | for (unsigned int i = base + 1; i < end; i++) |
Behdad Esfahbod | c4e71ff | 2013-10-17 17:04:47 +0200 | [diff] [blame] | 819 | if (is_consonant (info[i])) |
Behdad Esfahbod | 11b0e20 | 2012-08-02 14:21:40 -0400 | [diff] [blame] | 820 | info[i].indic_position() = POS_BELOW_C; |
| 821 | } |
| 822 | break; |
Behdad Esfahbod | e10453e | 2013-10-17 16:49:06 +0200 | [diff] [blame] | 823 | |
| 824 | case BASE_POS_FIRST: |
| 825 | { |
| 826 | /* The first consonant is always the base. */ |
| 827 | |
| 828 | assert (indic_plan->config->reph_mode == REPH_MODE_VIS_REPHA); |
Behdad Esfahbod | efed40b | 2013-10-17 18:50:11 +0200 | [diff] [blame] | 829 | assert (!has_reph); |
Behdad Esfahbod | e10453e | 2013-10-17 16:49:06 +0200 | [diff] [blame] | 830 | |
| 831 | base = start; |
| 832 | |
| 833 | /* Mark all subsequent consonants as below. */ |
| 834 | for (unsigned int i = base + 1; i < end; i++) |
Behdad Esfahbod | c4e71ff | 2013-10-17 17:04:47 +0200 | [diff] [blame] | 835 | if (is_consonant (info[i])) |
Behdad Esfahbod | e10453e | 2013-10-17 16:49:06 +0200 | [diff] [blame] | 836 | info[i].indic_position() = POS_BELOW_C; |
| 837 | } |
| 838 | break; |
Behdad Esfahbod | 5d32690 | 2012-07-17 14:23:28 -0400 | [diff] [blame] | 839 | } |
Behdad Esfahbod | 3c2ea94 | 2012-05-11 16:23:38 +0200 | [diff] [blame] | 840 | |
Behdad Esfahbod | 617f4ac | 2012-05-13 16:48:03 +0200 | [diff] [blame] | 841 | /* -> If the syllable starts with Ra + Halant (in a script that has Reph) |
| 842 | * and has more than one consonant, Ra is excluded from candidates for |
Behdad Esfahbod | 2278eef | 2012-07-24 00:26:43 -0400 | [diff] [blame] | 843 | * base consonants. |
| 844 | * |
| 845 | * Only do this for unforced Reph. (ie. not for Ra,H,ZWJ. */ |
Behdad Esfahbod | 9621e0b | 2013-02-11 06:58:27 -0500 | [diff] [blame] | 846 | if (has_reph && base == start && limit - base <= 2) { |
Behdad Esfahbod | 617f4ac | 2012-05-13 16:48:03 +0200 | [diff] [blame] | 847 | /* Have no other consonant, so Reph is not formed and Ra becomes base. */ |
| 848 | has_reph = false; |
| 849 | } |
Behdad Esfahbod | 5e4e21f | 2012-05-13 16:46:08 +0200 | [diff] [blame] | 850 | } |
Behdad Esfahbod | 2278eef | 2012-07-24 00:26:43 -0400 | [diff] [blame] | 851 | |
Behdad Esfahbod | 3d25079 | 2012-05-10 11:37:42 +0200 | [diff] [blame] | 852 | |
Behdad Esfahbod | 743807a | 2011-07-29 16:37:02 -0400 | [diff] [blame] | 853 | /* 2. Decompose and reorder Matras: |
| 854 | * |
| 855 | * Each matra and any syllable modifier sign in the cluster are moved to the |
| 856 | * appropriate position relative to the consonant(s) in the cluster. The |
| 857 | * shaping engine decomposes two- or three-part matras into their constituent |
| 858 | * parts before any repositioning. Matra characters are classified by which |
| 859 | * consonant in a conjunct they have affinity for and are reordered to the |
| 860 | * following positions: |
| 861 | * |
| 862 | * o Before first half form in the syllable |
| 863 | * o After subjoined consonants |
| 864 | * o After post-form consonant |
| 865 | * o After main consonant (for above marks) |
| 866 | * |
| 867 | * IMPLEMENTATION NOTES: |
| 868 | * |
| 869 | * The normalize() routine has already decomposed matras for us, so we don't |
| 870 | * need to worry about that. |
| 871 | */ |
| 872 | |
| 873 | |
| 874 | /* 3. Reorder marks to canonical order: |
| 875 | * |
| 876 | * Adjacent nukta and halant or nukta and vedic sign are always repositioned |
| 877 | * if necessary, so that the nukta is first. |
| 878 | * |
| 879 | * IMPLEMENTATION NOTES: |
| 880 | * |
| 881 | * We don't need to do this: the normalize() routine already did this for us. |
| 882 | */ |
| 883 | |
| 884 | |
Behdad Esfahbod | 45d6f29 | 2011-07-30 14:44:30 -0400 | [diff] [blame] | 885 | /* Reorder characters */ |
| 886 | |
Behdad Esfahbod | 3c2ea94 | 2012-05-11 16:23:38 +0200 | [diff] [blame] | 887 | for (unsigned int i = start; i < base; i++) |
Behdad Esfahbod | 900cf3d | 2012-07-20 10:18:23 -0400 | [diff] [blame] | 888 | info[i].indic_position() = MIN (POS_PRE_C, (indic_position_t) info[i].indic_position()); |
Behdad Esfahbod | 55f70eb | 2012-07-17 12:50:13 -0400 | [diff] [blame] | 889 | |
Behdad Esfahbod | 075d671 | 2012-07-18 15:41:53 -0400 | [diff] [blame] | 890 | if (base < end) |
| 891 | info[base].indic_position() = POS_BASE_C; |
Behdad Esfahbod | 45d6f29 | 2011-07-30 14:44:30 -0400 | [diff] [blame] | 892 | |
Behdad Esfahbod | 55f70eb | 2012-07-17 12:50:13 -0400 | [diff] [blame] | 893 | /* Mark final consonants. A final consonant is one appearing after a matra, |
| 894 | * like in Khmer. */ |
| 895 | for (unsigned int i = base + 1; i < end; i++) |
| 896 | if (info[i].indic_category() == OT_M) { |
| 897 | for (unsigned int j = i + 1; j < end; j++) |
| 898 | if (is_consonant (info[j])) { |
| 899 | info[j].indic_position() = POS_FINAL_C; |
| 900 | break; |
| 901 | } |
| 902 | break; |
| 903 | } |
| 904 | |
Behdad Esfahbod | fd06bf5 | 2011-07-30 20:14:44 -0400 | [diff] [blame] | 905 | /* Handle beginning Ra */ |
Behdad Esfahbod | 5e4e21f | 2012-05-13 16:46:08 +0200 | [diff] [blame] | 906 | if (has_reph) |
Behdad Esfahbod | dbb1058 | 2012-05-10 13:45:52 +0200 | [diff] [blame] | 907 | info[start].indic_position() = POS_RA_TO_BECOME_REPH; |
Behdad Esfahbod | fd06bf5 | 2011-07-30 20:14:44 -0400 | [diff] [blame] | 908 | |
Behdad Esfahbod | f5bc272 | 2011-07-30 21:08:10 -0400 | [diff] [blame] | 909 | /* For old-style Indic script tags, move the first post-base Halant after |
Behdad Esfahbod | ecd454b | 2013-01-08 18:09:46 -0600 | [diff] [blame] | 910 | * last consonant. Only do this if there is *not* a Halant after last |
| 911 | * consonant. Otherwise it becomes messy. */ |
Behdad Esfahbod | 914ffaa | 2012-08-02 11:03:39 -0400 | [diff] [blame] | 912 | if (indic_plan->is_old_spec) { |
Behdad Esfahbod | 3c2ea94 | 2012-05-11 16:23:38 +0200 | [diff] [blame] | 913 | for (unsigned int i = base + 1; i < end; i++) |
Behdad Esfahbod | f5bc272 | 2011-07-30 21:08:10 -0400 | [diff] [blame] | 914 | if (info[i].indic_category() == OT_H) { |
| 915 | unsigned int j; |
| 916 | for (j = end - 1; j > i; j--) |
Behdad Esfahbod | ecd454b | 2013-01-08 18:09:46 -0600 | [diff] [blame] | 917 | if (is_consonant (info[j]) || info[j].indic_category() == OT_H) |
Behdad Esfahbod | f5bc272 | 2011-07-30 21:08:10 -0400 | [diff] [blame] | 918 | break; |
Behdad Esfahbod | ecd454b | 2013-01-08 18:09:46 -0600 | [diff] [blame] | 919 | if (info[j].indic_category() != OT_H && j > i) { |
Behdad Esfahbod | f5bc272 | 2011-07-30 21:08:10 -0400 | [diff] [blame] | 920 | /* Move Halant to after last consonant. */ |
| 921 | hb_glyph_info_t t = info[i]; |
| 922 | memmove (&info[i], &info[i + 1], (j - i) * sizeof (info[0])); |
| 923 | info[j] = t; |
| 924 | } |
| 925 | break; |
| 926 | } |
| 927 | } |
| 928 | |
Behdad Esfahbod | 81202bd | 2012-07-20 15:10:02 -0400 | [diff] [blame] | 929 | /* Attach misc marks to previous char to move with them. */ |
Behdad Esfahbod | ebe2973 | 2012-05-11 16:43:12 +0200 | [diff] [blame] | 930 | { |
Behdad Esfahbod | 81202bd | 2012-07-20 15:10:02 -0400 | [diff] [blame] | 931 | indic_position_t last_pos = POS_START; |
| 932 | for (unsigned int i = start; i < end; i++) |
| 933 | { |
| 934 | if ((FLAG (info[i].indic_category()) & (JOINER_FLAGS | FLAG (OT_N) | FLAG (OT_RS) | HALANT_OR_COENG_FLAGS))) |
| 935 | { |
| 936 | info[i].indic_position() = last_pos; |
Behdad Esfahbod | dde5506 | 2012-11-14 11:37:04 -0800 | [diff] [blame] | 937 | if (unlikely (info[i].indic_category() == OT_H && |
Behdad Esfahbod | 81202bd | 2012-07-20 15:10:02 -0400 | [diff] [blame] | 938 | info[i].indic_position() == POS_PRE_M)) |
| 939 | { |
| 940 | /* |
| 941 | * Uniscribe doesn't move the Halant with Left Matra. |
| 942 | * TEST: U+092B,U+093F,U+094DE |
Behdad Esfahbod | dde5506 | 2012-11-14 11:37:04 -0800 | [diff] [blame] | 943 | * We follow. This is important for the Sinhala |
| 944 | * U+0DDA split matra since it decomposes to U+0DD9,U+0DCA |
| 945 | * where U+0DD9 is a left matra and U+0DCA is the virama. |
| 946 | * We don't want to move the virama with the left matra. |
| 947 | * TEST: U+0D9A,U+0DDA |
Behdad Esfahbod | 81202bd | 2012-07-20 15:10:02 -0400 | [diff] [blame] | 948 | */ |
Behdad Esfahbod | ebe2973 | 2012-05-11 16:43:12 +0200 | [diff] [blame] | 949 | for (unsigned int j = i; j > start; j--) |
Behdad Esfahbod | 6a091df | 2012-05-11 21:42:27 +0200 | [diff] [blame] | 950 | if (info[j - 1].indic_position() != POS_PRE_M) { |
Behdad Esfahbod | ebe2973 | 2012-05-11 16:43:12 +0200 | [diff] [blame] | 951 | info[i].indic_position() = info[j - 1].indic_position(); |
| 952 | break; |
| 953 | } |
Behdad Esfahbod | 81202bd | 2012-07-20 15:10:02 -0400 | [diff] [blame] | 954 | } |
| 955 | } else if (info[i].indic_position() != POS_SMVD) { |
| 956 | last_pos = (indic_position_t) info[i].indic_position(); |
Behdad Esfahbod | ebe2973 | 2012-05-11 16:43:12 +0200 | [diff] [blame] | 957 | } |
Behdad Esfahbod | 81202bd | 2012-07-20 15:10:02 -0400 | [diff] [blame] | 958 | } |
Behdad Esfahbod | ebe2973 | 2012-05-11 16:43:12 +0200 | [diff] [blame] | 959 | } |
Behdad Esfahbod | 74ccc6a | 2012-07-17 11:16:19 -0400 | [diff] [blame] | 960 | /* Re-attach ZWJ, ZWNJ, and halant to next char, for after-base consonants. */ |
| 961 | { |
| 962 | unsigned int last_halant = end; |
| 963 | for (unsigned int i = base + 1; i < end; i++) |
Behdad Esfahbod | deb521d | 2012-07-17 11:37:32 -0400 | [diff] [blame] | 964 | if (is_halant_or_coeng (info[i])) |
Behdad Esfahbod | 74ccc6a | 2012-07-17 11:16:19 -0400 | [diff] [blame] | 965 | last_halant = i; |
| 966 | else if (is_consonant (info[i])) { |
| 967 | for (unsigned int j = last_halant; j < i; j++) |
Behdad Esfahbod | 81202bd | 2012-07-20 15:10:02 -0400 | [diff] [blame] | 968 | if (info[j].indic_position() != POS_SMVD) |
| 969 | info[j].indic_position() = info[i].indic_position(); |
Behdad Esfahbod | 3756efa | 2013-10-16 19:06:29 +0200 | [diff] [blame] | 970 | last_halant = end; |
Behdad Esfahbod | 74ccc6a | 2012-07-17 11:16:19 -0400 | [diff] [blame] | 971 | } |
| 972 | } |
Behdad Esfahbod | 45d6f29 | 2011-07-30 14:44:30 -0400 | [diff] [blame] | 973 | |
Behdad Esfahbod | 28d5dae | 2013-10-16 12:32:12 +0200 | [diff] [blame] | 974 | |
Behdad Esfahbod | a391ff5 | 2012-05-10 11:31:20 +0200 | [diff] [blame] | 975 | { |
Behdad Esfahbod | 28d5dae | 2013-10-16 12:32:12 +0200 | [diff] [blame] | 976 | /* Use syllable() for sort accounting temporarily. */ |
| 977 | unsigned int syllable = info[start].syllable(); |
| 978 | for (unsigned int i = start; i < end; i++) |
| 979 | info[i].syllable() = i - start; |
| 980 | |
Behdad Esfahbod | a391ff5 | 2012-05-10 11:31:20 +0200 | [diff] [blame] | 981 | /* Sit tight, rock 'n roll! */ |
Behdad Esfahbod | d3637ed | 2012-05-10 10:51:38 +0200 | [diff] [blame] | 982 | hb_bubble_sort (info + start, end - start, compare_indic_order); |
Behdad Esfahbod | a391ff5 | 2012-05-10 11:31:20 +0200 | [diff] [blame] | 983 | /* Find base again */ |
| 984 | base = end; |
Behdad Esfahbod | 3c2ea94 | 2012-05-11 16:23:38 +0200 | [diff] [blame] | 985 | for (unsigned int i = start; i < end; i++) |
Behdad Esfahbod | 28d5dae | 2013-10-16 12:32:12 +0200 | [diff] [blame] | 986 | if (info[i].indic_position() == POS_BASE_C) |
| 987 | { |
| 988 | base = i; |
Behdad Esfahbod | a391ff5 | 2012-05-10 11:31:20 +0200 | [diff] [blame] | 989 | break; |
| 990 | } |
Behdad Esfahbod | 28d5dae | 2013-10-16 12:32:12 +0200 | [diff] [blame] | 991 | /* Things are out-of-control for post base positions, they may shuffle |
| 992 | * around like crazy. In old-spec mode, we move halants around, so in |
| 993 | * that case merge all clusters after base. Otherwise, check the sort |
| 994 | * order and merge as needed. |
| 995 | * For pre-base stuff, we handle cluster issues in final reordering. */ |
| 996 | if (indic_plan->is_old_spec || end - base > 127) |
| 997 | buffer->merge_clusters (base, end); |
| 998 | else |
| 999 | { |
| 1000 | /* Note! syllable() is a one-byte field. */ |
| 1001 | for (unsigned int i = base; i < end; i++) |
| 1002 | if (info[i].syllable() != 255) |
| 1003 | { |
| 1004 | unsigned int max = i; |
| 1005 | unsigned int j = start + info[i].syllable(); |
| 1006 | while (j != i) |
| 1007 | { |
| 1008 | max = MAX (max, j); |
| 1009 | unsigned int next = start + info[j].syllable(); |
| 1010 | info[j].syllable() = 255; /* So we don't process j later again. */ |
| 1011 | j = next; |
| 1012 | } |
| 1013 | if (i != max) |
| 1014 | buffer->merge_clusters (i, max + 1); |
| 1015 | } |
| 1016 | } |
| 1017 | |
| 1018 | /* Put syllable back in. */ |
| 1019 | for (unsigned int i = start; i < end; i++) |
| 1020 | info[i].syllable() = syllable; |
Behdad Esfahbod | a391ff5 | 2012-05-10 11:31:20 +0200 | [diff] [blame] | 1021 | } |
Behdad Esfahbod | 45d6f29 | 2011-07-30 14:44:30 -0400 | [diff] [blame] | 1022 | |
Behdad Esfahbod | 743807a | 2011-07-29 16:37:02 -0400 | [diff] [blame] | 1023 | /* Setup masks now */ |
| 1024 | |
Behdad Esfahbod | 2816839 | 2011-07-31 16:00:35 -0400 | [diff] [blame] | 1025 | { |
| 1026 | hb_mask_t mask; |
| 1027 | |
Behdad Esfahbod | dbb1058 | 2012-05-10 13:45:52 +0200 | [diff] [blame] | 1028 | /* Reph */ |
Behdad Esfahbod | 668c604 | 2012-05-11 15:34:13 +0200 | [diff] [blame] | 1029 | for (unsigned int i = start; i < end && info[i].indic_position() == POS_RA_TO_BECOME_REPH; i++) |
Behdad Esfahbod | 85fc6c4 | 2012-08-02 12:21:44 -0400 | [diff] [blame] | 1030 | info[i].mask |= indic_plan->mask_array[RPHF]; |
Behdad Esfahbod | dbb1058 | 2012-05-10 13:45:52 +0200 | [diff] [blame] | 1031 | |
Behdad Esfahbod | 2816839 | 2011-07-31 16:00:35 -0400 | [diff] [blame] | 1032 | /* Pre-base */ |
Behdad Esfahbod | 85fc6c4 | 2012-08-02 12:21:44 -0400 | [diff] [blame] | 1033 | mask = indic_plan->mask_array[HALF]; |
Behdad Esfahbod | c7dacac | 2013-10-17 12:20:24 +0200 | [diff] [blame] | 1034 | if (!indic_plan->is_old_spec && |
| 1035 | indic_plan->config->blwf_mode == BLWF_MODE_PRE_AND_POST) |
Behdad Esfahbod | 8acbb6b | 2013-10-15 12:15:49 +0200 | [diff] [blame] | 1036 | mask |= indic_plan->mask_array[BLWF]; |
Behdad Esfahbod | 3c2ea94 | 2012-05-11 16:23:38 +0200 | [diff] [blame] | 1037 | for (unsigned int i = start; i < base; i++) |
Behdad Esfahbod | 2816839 | 2011-07-31 16:00:35 -0400 | [diff] [blame] | 1038 | info[i].mask |= mask; |
| 1039 | /* Base */ |
Behdad Esfahbod | 20b68e6 | 2012-07-20 10:47:46 -0400 | [diff] [blame] | 1040 | mask = 0; |
Behdad Esfahbod | 075d671 | 2012-07-18 15:41:53 -0400 | [diff] [blame] | 1041 | if (base < end) |
| 1042 | info[base].mask |= mask; |
Behdad Esfahbod | 2816839 | 2011-07-31 16:00:35 -0400 | [diff] [blame] | 1043 | /* Post-base */ |
Behdad Esfahbod | 85fc6c4 | 2012-08-02 12:21:44 -0400 | [diff] [blame] | 1044 | mask = indic_plan->mask_array[BLWF] | indic_plan->mask_array[ABVF] | indic_plan->mask_array[PSTF]; |
Behdad Esfahbod | 3c2ea94 | 2012-05-11 16:23:38 +0200 | [diff] [blame] | 1045 | for (unsigned int i = base + 1; i < end; i++) |
Behdad Esfahbod | 2816839 | 2011-07-31 16:00:35 -0400 | [diff] [blame] | 1046 | info[i].mask |= mask; |
| 1047 | } |
Behdad Esfahbod | 9da0487 | 2011-07-31 13:46:44 -0400 | [diff] [blame] | 1048 | |
Behdad Esfahbod | 85c51ec | 2013-02-12 18:17:39 -0500 | [diff] [blame] | 1049 | if (indic_plan->is_old_spec && |
| 1050 | buffer->props.script == HB_SCRIPT_DEVANAGARI) |
| 1051 | { |
| 1052 | /* Old-spec eye-lash Ra needs special handling. From the |
| 1053 | * spec: |
| 1054 | * |
| 1055 | * "The feature 'below-base form' is applied to consonants |
| 1056 | * having below-base forms and following the base consonant. |
| 1057 | * The exception is vattu, which may appear below half forms |
| 1058 | * as well as below the base glyph. The feature 'below-base |
| 1059 | * form' will be applied to all such occurrences of Ra as well." |
| 1060 | * |
| 1061 | * Test case: U+0924,U+094D,U+0930,U+094d,U+0915 |
| 1062 | * with Sanskrit 2003 font. |
| 1063 | * |
| 1064 | * However, note that Ra,Halant,ZWJ is the correct way to |
| 1065 | * request eyelash form of Ra, so we wouldbn't inhibit it |
| 1066 | * in that sequence. |
| 1067 | * |
| 1068 | * Test case: U+0924,U+094D,U+0930,U+094d,U+200D,U+0915 |
| 1069 | */ |
| 1070 | for (unsigned int i = start; i + 1 < base; i++) |
| 1071 | if (info[i ].indic_category() == OT_Ra && |
| 1072 | info[i+1].indic_category() == OT_H && |
| 1073 | (i + 2 == base || |
| 1074 | info[i+2].indic_category() != OT_ZWJ)) |
| 1075 | { |
| 1076 | info[i ].mask |= indic_plan->mask_array[BLWF]; |
| 1077 | info[i+1].mask |= indic_plan->mask_array[BLWF]; |
| 1078 | } |
| 1079 | } |
| 1080 | |
Behdad Esfahbod | 74f4bbf | 2013-10-17 19:07:53 +0200 | [diff] [blame] | 1081 | unsigned int pref_len = indic_plan->config->pref_len; |
| 1082 | if (indic_plan->mask_array[PREF] && base + pref_len < end) |
Behdad Esfahbod | 17d7de9 | 2012-07-16 15:20:15 -0400 | [diff] [blame] | 1083 | { |
Behdad Esfahbod | 74f4bbf | 2013-10-17 19:07:53 +0200 | [diff] [blame] | 1084 | assert (1 <= pref_len && pref_len <= 2); |
Behdad Esfahbod | 771a8f5 | 2012-07-23 20:07:50 -0400 | [diff] [blame] | 1085 | /* Find a Halant,Ra sequence and mark it for pre-base reordering processing. */ |
Behdad Esfahbod | 74f4bbf | 2013-10-17 19:07:53 +0200 | [diff] [blame] | 1086 | for (unsigned int i = base + 1; i + pref_len - 1 < end; i++) { |
| 1087 | hb_codepoint_t glyphs[2]; |
| 1088 | for (unsigned int j = 0; j < pref_len; j++) |
| 1089 | glyphs[j] = info[i + j].codepoint; |
| 1090 | if (indic_plan->pref.would_substitute (glyphs, pref_len, face)) |
Behdad Esfahbod | 8e7b588 | 2012-07-16 17:04:46 -0400 | [diff] [blame] | 1091 | { |
Behdad Esfahbod | 74f4bbf | 2013-10-17 19:07:53 +0200 | [diff] [blame] | 1092 | for (unsigned int j = 0; j < pref_len; j++) |
| 1093 | info[i++].mask |= indic_plan->mask_array[PREF]; |
Behdad Esfahbod | 0201e0a | 2012-07-17 13:55:10 -0400 | [diff] [blame] | 1094 | |
| 1095 | /* Mark the subsequent stuff with 'cfar'. Used in Khmer. |
| 1096 | * Read the feature spec. |
| 1097 | * This allows distinguishing the following cases with MS Khmer fonts: |
| 1098 | * U+1784,U+17D2,U+179A,U+17D2,U+1782 |
| 1099 | * U+1784,U+17D2,U+1782,U+17D2,U+179A |
| 1100 | */ |
Behdad Esfahbod | 74f4bbf | 2013-10-17 19:07:53 +0200 | [diff] [blame] | 1101 | if (indic_plan->mask_array[CFAR]) |
| 1102 | for (; i < end; i++) |
| 1103 | info[i].mask |= indic_plan->mask_array[CFAR]; |
Behdad Esfahbod | 0201e0a | 2012-07-17 13:55:10 -0400 | [diff] [blame] | 1104 | |
Behdad Esfahbod | 8e7b588 | 2012-07-16 17:04:46 -0400 | [diff] [blame] | 1105 | break; |
| 1106 | } |
Behdad Esfahbod | 56be677 | 2012-11-12 14:09:40 -0800 | [diff] [blame] | 1107 | } |
Behdad Esfahbod | 17d7de9 | 2012-07-16 15:20:15 -0400 | [diff] [blame] | 1108 | } |
| 1109 | |
Behdad Esfahbod | 9da0487 | 2011-07-31 13:46:44 -0400 | [diff] [blame] | 1110 | /* Apply ZWJ/ZWNJ effects */ |
Behdad Esfahbod | 3c2ea94 | 2012-05-11 16:23:38 +0200 | [diff] [blame] | 1111 | for (unsigned int i = start + 1; i < end; i++) |
Behdad Esfahbod | 9da0487 | 2011-07-31 13:46:44 -0400 | [diff] [blame] | 1112 | if (is_joiner (info[i])) { |
| 1113 | bool non_joiner = info[i].indic_category() == OT_ZWNJ; |
Behdad Esfahbod | 6b37bc8 | 2011-07-31 15:57:00 -0400 | [diff] [blame] | 1114 | unsigned int j = i; |
Behdad Esfahbod | 9da0487 | 2011-07-31 13:46:44 -0400 | [diff] [blame] | 1115 | |
| 1116 | do { |
Behdad Esfahbod | 9da0487 | 2011-07-31 13:46:44 -0400 | [diff] [blame] | 1117 | j--; |
Behdad Esfahbod | 6b37bc8 | 2011-07-31 15:57:00 -0400 | [diff] [blame] | 1118 | |
Behdad Esfahbod | cfc507c | 2013-02-14 10:40:12 -0500 | [diff] [blame] | 1119 | /* ZWJ/ZWNJ should disable CJCT. They do that by simply |
| 1120 | * being there, since we don't skip them for the CJCT |
Behdad Esfahbod | a8cf7b4 | 2013-03-19 05:53:26 -0400 | [diff] [blame] | 1121 | * feature (ie. F_MANUAL_ZWJ) */ |
Behdad Esfahbod | 20b68e6 | 2012-07-20 10:47:46 -0400 | [diff] [blame] | 1122 | |
| 1123 | /* A ZWNJ disables HALF. */ |
Behdad Esfahbod | 6b37bc8 | 2011-07-31 15:57:00 -0400 | [diff] [blame] | 1124 | if (non_joiner) |
Behdad Esfahbod | 85fc6c4 | 2012-08-02 12:21:44 -0400 | [diff] [blame] | 1125 | info[j].mask &= ~indic_plan->mask_array[HALF]; |
Behdad Esfahbod | 6b37bc8 | 2011-07-31 15:57:00 -0400 | [diff] [blame] | 1126 | |
Behdad Esfahbod | 9da0487 | 2011-07-31 13:46:44 -0400 | [diff] [blame] | 1127 | } while (j > start && !is_consonant (info[j])); |
| 1128 | } |
Behdad Esfahbod | 743807a | 2011-07-29 16:37:02 -0400 | [diff] [blame] | 1129 | } |
| 1130 | |
| 1131 | |
| 1132 | static void |
Behdad Esfahbod | 8bb5deb | 2012-08-02 10:07:58 -0400 | [diff] [blame] | 1133 | initial_reordering_vowel_syllable (const hb_ot_shape_plan_t *plan, |
Behdad Esfahbod | f2c0f59 | 2012-11-12 14:02:02 -0800 | [diff] [blame] | 1134 | hb_face_t *face, |
Behdad Esfahbod | 9f377ed | 2012-05-13 16:13:44 +0200 | [diff] [blame] | 1135 | hb_buffer_t *buffer, |
Behdad Esfahbod | ef24cc8 | 2012-05-09 17:56:03 +0200 | [diff] [blame] | 1136 | unsigned int start, unsigned int end) |
Behdad Esfahbod | 743807a | 2011-07-29 16:37:02 -0400 | [diff] [blame] | 1137 | { |
Behdad Esfahbod | c5306b6 | 2012-05-10 12:07:33 +0200 | [diff] [blame] | 1138 | /* We made the vowels look like consonants. So let's call the consonant logic! */ |
Behdad Esfahbod | f2c0f59 | 2012-11-12 14:02:02 -0800 | [diff] [blame] | 1139 | initial_reordering_consonant_syllable (plan, face, buffer, start, end); |
Behdad Esfahbod | 743807a | 2011-07-29 16:37:02 -0400 | [diff] [blame] | 1140 | } |
| 1141 | |
| 1142 | static void |
Behdad Esfahbod | 8bb5deb | 2012-08-02 10:07:58 -0400 | [diff] [blame] | 1143 | initial_reordering_standalone_cluster (const hb_ot_shape_plan_t *plan, |
Behdad Esfahbod | f2c0f59 | 2012-11-12 14:02:02 -0800 | [diff] [blame] | 1144 | hb_face_t *face, |
Behdad Esfahbod | 9f377ed | 2012-05-13 16:13:44 +0200 | [diff] [blame] | 1145 | hb_buffer_t *buffer, |
Behdad Esfahbod | ef24cc8 | 2012-05-09 17:56:03 +0200 | [diff] [blame] | 1146 | unsigned int start, unsigned int end) |
Behdad Esfahbod | 743807a | 2011-07-29 16:37:02 -0400 | [diff] [blame] | 1147 | { |
Behdad Esfahbod | 18c06e1 | 2012-05-11 20:02:14 +0200 | [diff] [blame] | 1148 | /* We treat NBSP/dotted-circle as if they are consonants, so we should just chain. |
| 1149 | * Only if not in compatibility mode that is... */ |
| 1150 | |
Behdad Esfahbod | bab02d3 | 2013-02-12 15:26:45 -0500 | [diff] [blame] | 1151 | if (hb_options ().uniscribe_bug_compatible) |
Behdad Esfahbod | 18c06e1 | 2012-05-11 20:02:14 +0200 | [diff] [blame] | 1152 | { |
| 1153 | /* For dotted-circle, this is what Uniscribe does: |
| 1154 | * If dotted-circle is the last glyph, it just does nothing. |
| 1155 | * Ie. It doesn't form Reph. */ |
| 1156 | if (buffer->info[end - 1].indic_category() == OT_DOTTEDCIRCLE) |
| 1157 | return; |
| 1158 | } |
| 1159 | |
Behdad Esfahbod | f2c0f59 | 2012-11-12 14:02:02 -0800 | [diff] [blame] | 1160 | initial_reordering_consonant_syllable (plan, face, buffer, start, end); |
Behdad Esfahbod | 743807a | 2011-07-29 16:37:02 -0400 | [diff] [blame] | 1161 | } |
| 1162 | |
| 1163 | static void |
Behdad Esfahbod | b85800f | 2012-08-31 18:12:01 -0400 | [diff] [blame] | 1164 | initial_reordering_broken_cluster (const hb_ot_shape_plan_t *plan, |
Behdad Esfahbod | f2c0f59 | 2012-11-12 14:02:02 -0800 | [diff] [blame] | 1165 | hb_face_t *face, |
Behdad Esfahbod | b85800f | 2012-08-31 18:12:01 -0400 | [diff] [blame] | 1166 | hb_buffer_t *buffer, |
| 1167 | unsigned int start, unsigned int end) |
| 1168 | { |
| 1169 | /* We already inserted dotted-circles, so just call the standalone_cluster. */ |
Behdad Esfahbod | f2c0f59 | 2012-11-12 14:02:02 -0800 | [diff] [blame] | 1170 | initial_reordering_standalone_cluster (plan, face, buffer, start, end); |
Behdad Esfahbod | b85800f | 2012-08-31 18:12:01 -0400 | [diff] [blame] | 1171 | } |
| 1172 | |
| 1173 | static void |
Behdad Esfahbod | 3c7b364 | 2013-10-15 11:21:01 +0200 | [diff] [blame] | 1174 | initial_reordering_avagraha_cluster (const hb_ot_shape_plan_t *plan HB_UNUSED, |
| 1175 | hb_face_t *face HB_UNUSED, |
| 1176 | hb_buffer_t *buffer HB_UNUSED, |
| 1177 | unsigned int start HB_UNUSED, unsigned int end HB_UNUSED) |
| 1178 | { |
| 1179 | /* Nothing to do right now. If we ever switch to using the output |
| 1180 | * buffer in the reordering process, we'd need to next_glyph() here. */ |
| 1181 | } |
| 1182 | |
| 1183 | static void |
Behdad Esfahbod | 327d14e | 2012-08-31 16:49:34 -0400 | [diff] [blame] | 1184 | initial_reordering_non_indic_cluster (const hb_ot_shape_plan_t *plan HB_UNUSED, |
Behdad Esfahbod | f2c0f59 | 2012-11-12 14:02:02 -0800 | [diff] [blame] | 1185 | hb_face_t *face HB_UNUSED, |
Behdad Esfahbod | 327d14e | 2012-08-31 16:49:34 -0400 | [diff] [blame] | 1186 | hb_buffer_t *buffer HB_UNUSED, |
| 1187 | unsigned int start HB_UNUSED, unsigned int end HB_UNUSED) |
Behdad Esfahbod | 743807a | 2011-07-29 16:37:02 -0400 | [diff] [blame] | 1188 | { |
| 1189 | /* Nothing to do right now. If we ever switch to using the output |
| 1190 | * buffer in the reordering process, we'd need to next_glyph() here. */ |
| 1191 | } |
| 1192 | |
Behdad Esfahbod | 327d14e | 2012-08-31 16:49:34 -0400 | [diff] [blame] | 1193 | |
Behdad Esfahbod | 743807a | 2011-07-29 16:37:02 -0400 | [diff] [blame] | 1194 | static void |
Behdad Esfahbod | 327d14e | 2012-08-31 16:49:34 -0400 | [diff] [blame] | 1195 | initial_reordering_syllable (const hb_ot_shape_plan_t *plan, |
Behdad Esfahbod | f2c0f59 | 2012-11-12 14:02:02 -0800 | [diff] [blame] | 1196 | hb_face_t *face, |
Behdad Esfahbod | 327d14e | 2012-08-31 16:49:34 -0400 | [diff] [blame] | 1197 | hb_buffer_t *buffer, |
| 1198 | unsigned int start, unsigned int end) |
| 1199 | { |
| 1200 | syllable_type_t syllable_type = (syllable_type_t) (buffer->info[start].syllable() & 0x0F); |
| 1201 | switch (syllable_type) { |
Behdad Esfahbod | f2c0f59 | 2012-11-12 14:02:02 -0800 | [diff] [blame] | 1202 | case consonant_syllable: initial_reordering_consonant_syllable (plan, face, buffer, start, end); return; |
| 1203 | case vowel_syllable: initial_reordering_vowel_syllable (plan, face, buffer, start, end); return; |
| 1204 | case standalone_cluster: initial_reordering_standalone_cluster (plan, face, buffer, start, end); return; |
Behdad Esfahbod | 3c7b364 | 2013-10-15 11:21:01 +0200 | [diff] [blame] | 1205 | case avagraha_cluster: initial_reordering_avagraha_cluster (plan, face, buffer, start, end); return; |
Behdad Esfahbod | f2c0f59 | 2012-11-12 14:02:02 -0800 | [diff] [blame] | 1206 | case broken_cluster: initial_reordering_broken_cluster (plan, face, buffer, start, end); return; |
| 1207 | case non_indic_cluster: initial_reordering_non_indic_cluster (plan, face, buffer, start, end); return; |
Behdad Esfahbod | 327d14e | 2012-08-31 16:49:34 -0400 | [diff] [blame] | 1208 | } |
| 1209 | } |
| 1210 | |
Behdad Esfahbod | 166b5cf | 2012-09-07 14:55:07 -0400 | [diff] [blame] | 1211 | static inline void |
Behdad Esfahbod | 0beb66e | 2012-12-05 18:46:04 -0500 | [diff] [blame] | 1212 | insert_dotted_circles (const hb_ot_shape_plan_t *plan HB_UNUSED, |
Behdad Esfahbod | b85800f | 2012-08-31 18:12:01 -0400 | [diff] [blame] | 1213 | hb_font_t *font, |
| 1214 | hb_buffer_t *buffer) |
| 1215 | { |
Behdad Esfahbod | 166b5cf | 2012-09-07 14:55:07 -0400 | [diff] [blame] | 1216 | /* Note: This loop is extra overhead, but should not be measurable. */ |
| 1217 | bool has_broken_syllables = false; |
| 1218 | unsigned int count = buffer->len; |
| 1219 | for (unsigned int i = 0; i < count; i++) |
| 1220 | if ((buffer->info[i].syllable() & 0x0F) == broken_cluster) { |
| 1221 | has_broken_syllables = true; |
| 1222 | break; |
| 1223 | } |
| 1224 | if (likely (!has_broken_syllables)) |
| 1225 | return; |
| 1226 | |
| 1227 | |
Behdad Esfahbod | b85800f | 2012-08-31 18:12:01 -0400 | [diff] [blame] | 1228 | hb_codepoint_t dottedcircle_glyph; |
| 1229 | if (!font->get_glyph (0x25CC, 0, &dottedcircle_glyph)) |
| 1230 | return; |
| 1231 | |
Behdad Esfahbod | f41dc2d | 2012-11-15 10:36:43 -0800 | [diff] [blame] | 1232 | hb_glyph_info_t dottedcircle = {0}; |
Behdad Esfahbod | b85800f | 2012-08-31 18:12:01 -0400 | [diff] [blame] | 1233 | dottedcircle.codepoint = 0x25CC; |
| 1234 | set_indic_properties (dottedcircle); |
| 1235 | dottedcircle.codepoint = dottedcircle_glyph; |
| 1236 | |
| 1237 | buffer->clear_output (); |
| 1238 | |
| 1239 | buffer->idx = 0; |
| 1240 | unsigned int last_syllable = 0; |
| 1241 | while (buffer->idx < buffer->len) |
| 1242 | { |
| 1243 | unsigned int syllable = buffer->cur().syllable(); |
| 1244 | syllable_type_t syllable_type = (syllable_type_t) (syllable & 0x0F); |
| 1245 | if (unlikely (last_syllable != syllable && syllable_type == broken_cluster)) |
| 1246 | { |
Behdad Esfahbod | 596740d | 2012-12-21 19:41:04 -0500 | [diff] [blame] | 1247 | last_syllable = syllable; |
| 1248 | |
Behdad Esfahbod | b85800f | 2012-08-31 18:12:01 -0400 | [diff] [blame] | 1249 | hb_glyph_info_t info = dottedcircle; |
| 1250 | info.cluster = buffer->cur().cluster; |
| 1251 | info.mask = buffer->cur().mask; |
| 1252 | info.syllable() = buffer->cur().syllable(); |
Behdad Esfahbod | 596740d | 2012-12-21 19:41:04 -0500 | [diff] [blame] | 1253 | |
| 1254 | /* Insert dottedcircle after possible Repha. */ |
| 1255 | while (buffer->idx < buffer->len && |
| 1256 | last_syllable == buffer->cur().syllable() && |
| 1257 | buffer->cur().indic_category() == OT_Repha) |
| 1258 | buffer->next_glyph (); |
| 1259 | |
Behdad Esfahbod | b85800f | 2012-08-31 18:12:01 -0400 | [diff] [blame] | 1260 | buffer->output_info (info); |
Behdad Esfahbod | b85800f | 2012-08-31 18:12:01 -0400 | [diff] [blame] | 1261 | } |
Behdad Esfahbod | 596740d | 2012-12-21 19:41:04 -0500 | [diff] [blame] | 1262 | else |
| 1263 | buffer->next_glyph (); |
Behdad Esfahbod | b85800f | 2012-08-31 18:12:01 -0400 | [diff] [blame] | 1264 | } |
| 1265 | |
| 1266 | buffer->swap_buffers (); |
| 1267 | } |
| 1268 | |
| 1269 | static void |
Behdad Esfahbod | 8bb5deb | 2012-08-02 10:07:58 -0400 | [diff] [blame] | 1270 | initial_reordering (const hb_ot_shape_plan_t *plan, |
Behdad Esfahbod | 24eacf1 | 2012-08-02 08:42:11 -0400 | [diff] [blame] | 1271 | hb_font_t *font, |
Behdad Esfahbod | 3e38c0f | 2012-08-02 09:44:18 -0400 | [diff] [blame] | 1272 | hb_buffer_t *buffer) |
Behdad Esfahbod | 743807a | 2011-07-29 16:37:02 -0400 | [diff] [blame] | 1273 | { |
Behdad Esfahbod | 85fc6c4 | 2012-08-02 12:21:44 -0400 | [diff] [blame] | 1274 | update_consonant_positions (plan, font, buffer); |
Behdad Esfahbod | 166b5cf | 2012-09-07 14:55:07 -0400 | [diff] [blame] | 1275 | insert_dotted_circles (plan, font, buffer); |
Behdad Esfahbod | 327d14e | 2012-08-31 16:49:34 -0400 | [diff] [blame] | 1276 | |
| 1277 | hb_glyph_info_t *info = buffer->info; |
Behdad Esfahbod | b85800f | 2012-08-31 18:12:01 -0400 | [diff] [blame] | 1278 | unsigned int count = buffer->len; |
| 1279 | if (unlikely (!count)) return; |
Behdad Esfahbod | 327d14e | 2012-08-31 16:49:34 -0400 | [diff] [blame] | 1280 | unsigned int last = 0; |
| 1281 | unsigned int last_syllable = info[0].syllable(); |
| 1282 | for (unsigned int i = 1; i < count; i++) |
| 1283 | if (last_syllable != info[i].syllable()) { |
Behdad Esfahbod | f2c0f59 | 2012-11-12 14:02:02 -0800 | [diff] [blame] | 1284 | initial_reordering_syllable (plan, font->face, buffer, last, i); |
Behdad Esfahbod | 327d14e | 2012-08-31 16:49:34 -0400 | [diff] [blame] | 1285 | last = i; |
| 1286 | last_syllable = info[last].syllable(); |
| 1287 | } |
Behdad Esfahbod | f2c0f59 | 2012-11-12 14:02:02 -0800 | [diff] [blame] | 1288 | initial_reordering_syllable (plan, font->face, buffer, last, count); |
Behdad Esfahbod | b9ddbd5 | 2011-06-02 17:43:12 -0400 | [diff] [blame] | 1289 | } |
| 1290 | |
Behdad Esfahbod | 743807a | 2011-07-29 16:37:02 -0400 | [diff] [blame] | 1291 | static void |
Behdad Esfahbod | 85fc6c4 | 2012-08-02 12:21:44 -0400 | [diff] [blame] | 1292 | final_reordering_syllable (const hb_ot_shape_plan_t *plan, |
| 1293 | hb_buffer_t *buffer, |
Behdad Esfahbod | ef24cc8 | 2012-05-09 17:56:03 +0200 | [diff] [blame] | 1294 | unsigned int start, unsigned int end) |
Behdad Esfahbod | 743807a | 2011-07-29 16:37:02 -0400 | [diff] [blame] | 1295 | { |
Behdad Esfahbod | 85fc6c4 | 2012-08-02 12:21:44 -0400 | [diff] [blame] | 1296 | const indic_shape_plan_t *indic_plan = (const indic_shape_plan_t *) plan->data; |
Behdad Esfahbod | 4ac9e98 | 2012-05-10 12:53:53 +0200 | [diff] [blame] | 1297 | hb_glyph_info_t *info = buffer->info; |
| 1298 | |
Behdad Esfahbod | e7be057 | 2011-07-31 15:18:57 -0400 | [diff] [blame] | 1299 | /* 4. Final reordering: |
| 1300 | * |
| 1301 | * After the localized forms and basic shaping forms GSUB features have been |
| 1302 | * applied (see below), the shaping engine performs some final glyph |
| 1303 | * reordering before applying all the remaining font features to the entire |
| 1304 | * cluster. |
Behdad Esfahbod | 4ac9e98 | 2012-05-10 12:53:53 +0200 | [diff] [blame] | 1305 | */ |
| 1306 | |
| 1307 | /* Find base again */ |
Behdad Esfahbod | 5f0eaaa | 2012-07-20 15:47:24 -0400 | [diff] [blame] | 1308 | unsigned int base; |
| 1309 | for (base = start; base < end; base++) |
| 1310 | if (info[base].indic_position() >= POS_BASE_C) { |
| 1311 | if (start < base && info[base].indic_position() > POS_BASE_C) |
| 1312 | base--; |
| 1313 | break; |
| 1314 | } |
Behdad Esfahbod | a0cb9f3 | 2013-02-13 09:26:55 -0500 | [diff] [blame] | 1315 | if (base == end && start < base && |
| 1316 | info[base - 1].indic_category() != OT_ZWJ) |
| 1317 | base--; |
| 1318 | while (start < base && |
| 1319 | (info[base].indic_category() == OT_H || |
| 1320 | info[base].indic_category() == OT_N)) |
| 1321 | base--; |
Behdad Esfahbod | 4ac9e98 | 2012-05-10 12:53:53 +0200 | [diff] [blame] | 1322 | |
Behdad Esfahbod | 4705a70 | 2012-05-10 13:09:08 +0200 | [diff] [blame] | 1323 | |
Behdad Esfahbod | 4ac9e98 | 2012-05-10 12:53:53 +0200 | [diff] [blame] | 1324 | /* o Reorder matras: |
Behdad Esfahbod | e7be057 | 2011-07-31 15:18:57 -0400 | [diff] [blame] | 1325 | * |
| 1326 | * If a pre-base matra character had been reordered before applying basic |
| 1327 | * features, the glyph can be moved closer to the main consonant based on |
| 1328 | * whether half-forms had been formed. Actual position for the matra is |
| 1329 | * defined as “after last standalone halant glyph, after initial matra |
| 1330 | * position and before the main consonant”. If ZWJ or ZWNJ follow this |
| 1331 | * halant, position is moved after it. |
Behdad Esfahbod | 4ac9e98 | 2012-05-10 12:53:53 +0200 | [diff] [blame] | 1332 | */ |
| 1333 | |
Behdad Esfahbod | 65c43ac | 2012-07-24 03:36:47 -0400 | [diff] [blame] | 1334 | if (start + 1 < end && start < base) /* Otherwise there can't be any pre-base matra characters. */ |
Behdad Esfahbod | 9d0d319 | 2012-05-11 21:36:32 +0200 | [diff] [blame] | 1335 | { |
Behdad Esfahbod | 65c43ac | 2012-07-24 03:36:47 -0400 | [diff] [blame] | 1336 | /* If we lost track of base, alas, position before last thingy. */ |
| 1337 | unsigned int new_pos = base == end ? base - 2 : base - 1; |
Behdad Esfahbod | 4ac9e98 | 2012-05-10 12:53:53 +0200 | [diff] [blame] | 1338 | |
Behdad Esfahbod | 27bd55b | 2012-09-05 15:11:14 -0400 | [diff] [blame] | 1339 | /* Malayalam / Tamil do not have "half" forms or explicit virama forms. |
| 1340 | * The glyphs formed by 'half' are Chillus or ligated explicit viramas. |
| 1341 | * We want to position matra after them. |
Behdad Esfahbod | 65c43ac | 2012-07-24 03:36:47 -0400 | [diff] [blame] | 1342 | */ |
Behdad Esfahbod | 27bd55b | 2012-09-05 15:11:14 -0400 | [diff] [blame] | 1343 | if (buffer->props.script != HB_SCRIPT_MALAYALAM && buffer->props.script != HB_SCRIPT_TAMIL) |
Behdad Esfahbod | 65c43ac | 2012-07-24 03:36:47 -0400 | [diff] [blame] | 1344 | { |
| 1345 | while (new_pos > start && |
| 1346 | !(is_one_of (info[new_pos], (FLAG (OT_M) | FLAG (OT_H) | FLAG (OT_Coeng))))) |
| 1347 | new_pos--; |
| 1348 | |
| 1349 | /* If we found no Halant we are done. |
| 1350 | * Otherwise only proceed if the Halant does |
| 1351 | * not belong to the Matra itself! */ |
| 1352 | if (is_halant_or_coeng (info[new_pos]) && |
| 1353 | info[new_pos].indic_position() != POS_PRE_M) |
| 1354 | { |
| 1355 | /* -> If ZWJ or ZWNJ follow this halant, position is moved after it. */ |
| 1356 | if (new_pos + 1 < end && is_joiner (info[new_pos + 1])) |
| 1357 | new_pos++; |
| 1358 | } |
| 1359 | else |
| 1360 | new_pos = start; /* No move. */ |
| 1361 | } |
| 1362 | |
Behdad Esfahbod | 27bd55b | 2012-09-05 15:11:14 -0400 | [diff] [blame] | 1363 | if (start < new_pos && info[new_pos].indic_position () != POS_PRE_M) |
Behdad Esfahbod | 65c43ac | 2012-07-24 03:36:47 -0400 | [diff] [blame] | 1364 | { |
Behdad Esfahbod | 9d0d319 | 2012-05-11 21:36:32 +0200 | [diff] [blame] | 1365 | /* Now go see if there's actually any matras... */ |
Behdad Esfahbod | 921ce5b | 2012-07-16 15:26:56 -0400 | [diff] [blame] | 1366 | for (unsigned int i = new_pos; i > start; i--) |
Behdad Esfahbod | 6a091df | 2012-05-11 21:42:27 +0200 | [diff] [blame] | 1367 | if (info[i - 1].indic_position () == POS_PRE_M) |
Behdad Esfahbod | 9d0d319 | 2012-05-11 21:36:32 +0200 | [diff] [blame] | 1368 | { |
Behdad Esfahbod | 1a1dbe9 | 2012-07-16 15:40:33 -0400 | [diff] [blame] | 1369 | unsigned int old_pos = i - 1; |
| 1370 | hb_glyph_info_t tmp = info[old_pos]; |
| 1371 | memmove (&info[old_pos], &info[old_pos + 1], (new_pos - old_pos) * sizeof (info[0])); |
| 1372 | info[new_pos] = tmp; |
Behdad Esfahbod | f22b7e7 | 2013-02-13 07:32:46 -0500 | [diff] [blame] | 1373 | if (old_pos < base && base <= new_pos) /* Shouldn't actually happen. */ |
| 1374 | base--; |
Behdad Esfahbod | 9cb59d4 | 2013-10-16 11:34:07 +0200 | [diff] [blame] | 1375 | buffer->merge_clusters (new_pos, MIN (end, base + 1)); |
Behdad Esfahbod | 921ce5b | 2012-07-16 15:26:56 -0400 | [diff] [blame] | 1376 | new_pos--; |
Behdad Esfahbod | 9d0d319 | 2012-05-11 21:36:32 +0200 | [diff] [blame] | 1377 | } |
Behdad Esfahbod | abb3239 | 2012-07-22 23:55:19 -0400 | [diff] [blame] | 1378 | } else { |
Behdad Esfahbod | e6b01a8 | 2012-07-23 00:11:26 -0400 | [diff] [blame] | 1379 | for (unsigned int i = start; i < base; i++) |
Behdad Esfahbod | abb3239 | 2012-07-22 23:55:19 -0400 | [diff] [blame] | 1380 | if (info[i].indic_position () == POS_PRE_M) { |
Behdad Esfahbod | 2cc933a | 2012-07-23 08:22:55 -0400 | [diff] [blame] | 1381 | buffer->merge_clusters (i, MIN (end, base + 1)); |
Behdad Esfahbod | abb3239 | 2012-07-22 23:55:19 -0400 | [diff] [blame] | 1382 | break; |
| 1383 | } |
Behdad Esfahbod | 9d0d319 | 2012-05-11 21:36:32 +0200 | [diff] [blame] | 1384 | } |
Behdad Esfahbod | 4ac9e98 | 2012-05-10 12:53:53 +0200 | [diff] [blame] | 1385 | } |
| 1386 | |
| 1387 | |
| 1388 | /* o Reorder reph: |
Behdad Esfahbod | e7be057 | 2011-07-31 15:18:57 -0400 | [diff] [blame] | 1389 | * |
| 1390 | * Reph’s original position is always at the beginning of the syllable, |
| 1391 | * (i.e. it is not reordered at the character reordering stage). However, |
| 1392 | * it will be reordered according to the basic-forms shaping results. |
| 1393 | * Possible positions for reph, depending on the script, are; after main, |
| 1394 | * before post-base consonant forms, and after post-base consonant forms. |
Behdad Esfahbod | dbb1058 | 2012-05-10 13:45:52 +0200 | [diff] [blame] | 1395 | */ |
| 1396 | |
Behdad Esfahbod | 65a929b | 2013-10-15 18:08:05 +0200 | [diff] [blame] | 1397 | /* Two cases: |
| 1398 | * |
| 1399 | * - If repha is encoded as a sequence of characters (Ra,H or Ra,H,ZWJ), then |
| 1400 | * we should only move it if the sequence ligated to the repha form. |
| 1401 | * |
| 1402 | * - If repha is encoded separately and in the logical position, we should only |
| 1403 | * move it if it did NOT ligate. If it ligated, it's probably the font trying |
| 1404 | * to make it work without the reordering. |
| 1405 | */ |
Behdad Esfahbod | f5299ef | 2013-10-15 18:13:07 +0200 | [diff] [blame] | 1406 | if (start + 1 < end && |
| 1407 | info[start].indic_position() == POS_RA_TO_BECOME_REPH && |
| 1408 | ((info[start].indic_category() == OT_Repha) ^ is_a_ligature (info[start]))) |
Behdad Esfahbod | dbb1058 | 2012-05-10 13:45:52 +0200 | [diff] [blame] | 1409 | { |
Behdad Esfahbod | 11b0e20 | 2012-08-02 14:21:40 -0400 | [diff] [blame] | 1410 | unsigned int new_reph_pos; |
| 1411 | reph_position_t reph_pos = indic_plan->config->reph_pos; |
Behdad Esfahbod | 02b2922 | 2012-05-10 21:44:50 +0200 | [diff] [blame] | 1412 | |
Behdad Esfahbod | efed40b | 2013-10-17 18:50:11 +0200 | [diff] [blame] | 1413 | assert (reph_pos != POS_RA_TO_BECOME_REPH); |
Behdad Esfahbod | 02b2922 | 2012-05-10 21:44:50 +0200 | [diff] [blame] | 1414 | |
Behdad Esfahbod | dbb1058 | 2012-05-10 13:45:52 +0200 | [diff] [blame] | 1415 | /* 1. If reph should be positioned after post-base consonant forms, |
| 1416 | * proceed to step 5. |
Behdad Esfahbod | 02b2922 | 2012-05-10 21:44:50 +0200 | [diff] [blame] | 1417 | */ |
Behdad Esfahbod | 11b0e20 | 2012-08-02 14:21:40 -0400 | [diff] [blame] | 1418 | if (reph_pos == REPH_POS_AFTER_POST) |
Behdad Esfahbod | 02b2922 | 2012-05-10 21:44:50 +0200 | [diff] [blame] | 1419 | { |
Behdad Esfahbod | 9d0d319 | 2012-05-11 21:36:32 +0200 | [diff] [blame] | 1420 | goto reph_step_5; |
Behdad Esfahbod | 02b2922 | 2012-05-10 21:44:50 +0200 | [diff] [blame] | 1421 | } |
| 1422 | |
| 1423 | /* 2. If the reph repositioning class is not after post-base: target |
Behdad Esfahbod | dbb1058 | 2012-05-10 13:45:52 +0200 | [diff] [blame] | 1424 | * position is after the first explicit halant glyph between the |
| 1425 | * first post-reph consonant and last main consonant. If ZWJ or ZWNJ |
| 1426 | * are following this halant, position is moved after it. If such |
| 1427 | * position is found, this is the target position. Otherwise, |
| 1428 | * proceed to the next step. |
| 1429 | * |
| 1430 | * Note: in old-implementation fonts, where classifications were |
| 1431 | * fixed in shaping engine, there was no case where reph position |
| 1432 | * will be found on this step. |
Behdad Esfahbod | 02b2922 | 2012-05-10 21:44:50 +0200 | [diff] [blame] | 1433 | */ |
Behdad Esfahbod | 02b2922 | 2012-05-10 21:44:50 +0200 | [diff] [blame] | 1434 | { |
| 1435 | new_reph_pos = start + 1; |
Behdad Esfahbod | deb521d | 2012-07-17 11:37:32 -0400 | [diff] [blame] | 1436 | while (new_reph_pos < base && !is_halant_or_coeng (info[new_reph_pos])) |
Behdad Esfahbod | 02b2922 | 2012-05-10 21:44:50 +0200 | [diff] [blame] | 1437 | new_reph_pos++; |
| 1438 | |
Behdad Esfahbod | 1f91c39 | 2013-02-13 09:38:40 -0500 | [diff] [blame] | 1439 | if (new_reph_pos < base && is_halant_or_coeng (info[new_reph_pos])) |
| 1440 | { |
Behdad Esfahbod | 02b2922 | 2012-05-10 21:44:50 +0200 | [diff] [blame] | 1441 | /* ->If ZWJ or ZWNJ are following this halant, position is moved after it. */ |
| 1442 | if (new_reph_pos + 1 < base && is_joiner (info[new_reph_pos + 1])) |
| 1443 | new_reph_pos++; |
| 1444 | goto reph_move; |
| 1445 | } |
| 1446 | } |
| 1447 | |
| 1448 | /* 3. If reph should be repositioned after the main consonant: find the |
Behdad Esfahbod | dbb1058 | 2012-05-10 13:45:52 +0200 | [diff] [blame] | 1449 | * first consonant not ligated with main, or find the first |
| 1450 | * consonant that is not a potential pre-base reordering Ra. |
Behdad Esfahbod | 02b2922 | 2012-05-10 21:44:50 +0200 | [diff] [blame] | 1451 | */ |
Behdad Esfahbod | 11b0e20 | 2012-08-02 14:21:40 -0400 | [diff] [blame] | 1452 | if (reph_pos == REPH_POS_AFTER_MAIN) |
Behdad Esfahbod | 02b2922 | 2012-05-10 21:44:50 +0200 | [diff] [blame] | 1453 | { |
Behdad Esfahbod | b504e06 | 2012-07-16 15:21:12 -0400 | [diff] [blame] | 1454 | new_reph_pos = base; |
Behdad Esfahbod | 34ae336 | 2012-07-20 16:17:28 -0400 | [diff] [blame] | 1455 | while (new_reph_pos + 1 < end && info[new_reph_pos + 1].indic_position() <= POS_AFTER_MAIN) |
Behdad Esfahbod | b504e06 | 2012-07-16 15:21:12 -0400 | [diff] [blame] | 1456 | new_reph_pos++; |
| 1457 | if (new_reph_pos < end) |
| 1458 | goto reph_move; |
Behdad Esfahbod | 02b2922 | 2012-05-10 21:44:50 +0200 | [diff] [blame] | 1459 | } |
| 1460 | |
| 1461 | /* 4. If reph should be positioned before post-base consonant, find |
Behdad Esfahbod | dbb1058 | 2012-05-10 13:45:52 +0200 | [diff] [blame] | 1462 | * first post-base classified consonant not ligated with main. If no |
| 1463 | * consonant is found, the target position should be before the |
| 1464 | * first matra, syllable modifier sign or vedic sign. |
Behdad Esfahbod | 02b2922 | 2012-05-10 21:44:50 +0200 | [diff] [blame] | 1465 | */ |
Behdad Esfahbod | 9d0d319 | 2012-05-11 21:36:32 +0200 | [diff] [blame] | 1466 | /* This is our take on what step 4 is trying to say (and failing, BADLY). */ |
Behdad Esfahbod | 11b0e20 | 2012-08-02 14:21:40 -0400 | [diff] [blame] | 1467 | if (reph_pos == REPH_POS_AFTER_SUB) |
Behdad Esfahbod | 02b2922 | 2012-05-10 21:44:50 +0200 | [diff] [blame] | 1468 | { |
Behdad Esfahbod | 9d0d319 | 2012-05-11 21:36:32 +0200 | [diff] [blame] | 1469 | new_reph_pos = base; |
| 1470 | while (new_reph_pos < end && |
Behdad Esfahbod | be8b9f5 | 2012-07-19 12:11:12 -0400 | [diff] [blame] | 1471 | !( FLAG (info[new_reph_pos + 1].indic_position()) & (FLAG (POS_POST_C) | FLAG (POS_AFTER_POST) | FLAG (POS_SMVD)))) |
Behdad Esfahbod | 9d0d319 | 2012-05-11 21:36:32 +0200 | [diff] [blame] | 1472 | new_reph_pos++; |
| 1473 | if (new_reph_pos < end) |
| 1474 | goto reph_move; |
Behdad Esfahbod | 02b2922 | 2012-05-10 21:44:50 +0200 | [diff] [blame] | 1475 | } |
| 1476 | |
| 1477 | /* 5. If no consonant is found in steps 3 or 4, move reph to a position |
Behdad Esfahbod | dbb1058 | 2012-05-10 13:45:52 +0200 | [diff] [blame] | 1478 | * immediately before the first post-base matra, syllable modifier |
| 1479 | * sign or vedic sign that has a reordering class after the intended |
| 1480 | * reph position. For example, if the reordering position for reph |
| 1481 | * is post-main, it will skip above-base matras that also have a |
| 1482 | * post-main position. |
Behdad Esfahbod | dbb1058 | 2012-05-10 13:45:52 +0200 | [diff] [blame] | 1483 | */ |
Behdad Esfahbod | 02b2922 | 2012-05-10 21:44:50 +0200 | [diff] [blame] | 1484 | reph_step_5: |
| 1485 | { |
Behdad Esfahbod | d0e68db | 2012-07-20 11:25:41 -0400 | [diff] [blame] | 1486 | /* Copied from step 2. */ |
| 1487 | new_reph_pos = start + 1; |
| 1488 | while (new_reph_pos < base && !is_halant_or_coeng (info[new_reph_pos])) |
| 1489 | new_reph_pos++; |
| 1490 | |
Behdad Esfahbod | 1f91c39 | 2013-02-13 09:38:40 -0500 | [diff] [blame] | 1491 | if (new_reph_pos < base && is_halant_or_coeng (info[new_reph_pos])) |
| 1492 | { |
Behdad Esfahbod | d0e68db | 2012-07-20 11:25:41 -0400 | [diff] [blame] | 1493 | /* ->If ZWJ or ZWNJ are following this halant, position is moved after it. */ |
| 1494 | if (new_reph_pos + 1 < base && is_joiner (info[new_reph_pos + 1])) |
| 1495 | new_reph_pos++; |
| 1496 | goto reph_move; |
| 1497 | } |
Behdad Esfahbod | 8df5636 | 2012-05-10 15:41:04 +0200 | [diff] [blame] | 1498 | } |
| 1499 | |
Behdad Esfahbod | 02b2922 | 2012-05-10 21:44:50 +0200 | [diff] [blame] | 1500 | /* 6. Otherwise, reorder reph to the end of the syllable. |
| 1501 | */ |
Behdad Esfahbod | 02b2922 | 2012-05-10 21:44:50 +0200 | [diff] [blame] | 1502 | { |
| 1503 | new_reph_pos = end - 1; |
| 1504 | while (new_reph_pos > start && info[new_reph_pos].indic_position() == POS_SMVD) |
| 1505 | new_reph_pos--; |
| 1506 | |
Behdad Esfahbod | 892eb78 | 2012-05-11 16:54:40 +0200 | [diff] [blame] | 1507 | /* |
| 1508 | * If the Reph is to be ending up after a Matra,Halant sequence, |
| 1509 | * position it before that Halant so it can interact with the Matra. |
| 1510 | * However, if it's a plain Consonant,Halant we shouldn't do that. |
| 1511 | * Uniscribe doesn't do this. |
| 1512 | * TEST: U+0930,U+094D,U+0915,U+094B,U+094D |
| 1513 | */ |
Behdad Esfahbod | bab02d3 | 2013-02-12 15:26:45 -0500 | [diff] [blame] | 1514 | if (!hb_options ().uniscribe_bug_compatible && |
Behdad Esfahbod | deb521d | 2012-07-17 11:37:32 -0400 | [diff] [blame] | 1515 | unlikely (is_halant_or_coeng (info[new_reph_pos]))) { |
Behdad Esfahbod | 02b2922 | 2012-05-10 21:44:50 +0200 | [diff] [blame] | 1516 | for (unsigned int i = base + 1; i < new_reph_pos; i++) |
| 1517 | if (info[i].indic_category() == OT_M) { |
| 1518 | /* Ok, got it. */ |
| 1519 | new_reph_pos--; |
| 1520 | } |
| 1521 | } |
| 1522 | goto reph_move; |
| 1523 | } |
| 1524 | |
| 1525 | reph_move: |
| 1526 | { |
Behdad Esfahbod | 6b2abdc | 2013-10-17 13:15:43 +0200 | [diff] [blame] | 1527 | buffer->merge_clusters (start, new_reph_pos + 1); |
Behdad Esfahbod | e6b01a8 | 2012-07-23 00:11:26 -0400 | [diff] [blame] | 1528 | |
Behdad Esfahbod | 02b2922 | 2012-05-10 21:44:50 +0200 | [diff] [blame] | 1529 | /* Move */ |
| 1530 | hb_glyph_info_t reph = info[start]; |
| 1531 | memmove (&info[start], &info[start + 1], (new_reph_pos - start) * sizeof (info[0])); |
| 1532 | info[new_reph_pos] = reph; |
Behdad Esfahbod | f22b7e7 | 2013-02-13 07:32:46 -0500 | [diff] [blame] | 1533 | if (start < base && base <= new_reph_pos) |
| 1534 | base--; |
Behdad Esfahbod | 02b2922 | 2012-05-10 21:44:50 +0200 | [diff] [blame] | 1535 | } |
Behdad Esfahbod | dbb1058 | 2012-05-10 13:45:52 +0200 | [diff] [blame] | 1536 | } |
| 1537 | |
| 1538 | |
| 1539 | /* o Reorder pre-base reordering consonants: |
Behdad Esfahbod | e7be057 | 2011-07-31 15:18:57 -0400 | [diff] [blame] | 1540 | * |
| 1541 | * If a pre-base reordering consonant is found, reorder it according to |
| 1542 | * the following rules: |
Behdad Esfahbod | e7be057 | 2011-07-31 15:18:57 -0400 | [diff] [blame] | 1543 | */ |
| 1544 | |
Behdad Esfahbod | 85fc6c4 | 2012-08-02 12:21:44 -0400 | [diff] [blame] | 1545 | if (indic_plan->mask_array[PREF] && base + 1 < end) /* Otherwise there can't be any pre-base reordering Ra. */ |
Behdad Esfahbod | 46e645e | 2012-07-16 15:30:05 -0400 | [diff] [blame] | 1546 | { |
Behdad Esfahbod | 8e7b588 | 2012-07-16 17:04:46 -0400 | [diff] [blame] | 1547 | for (unsigned int i = base + 1; i < end; i++) |
Behdad Esfahbod | 85fc6c4 | 2012-08-02 12:21:44 -0400 | [diff] [blame] | 1548 | if ((info[i].mask & indic_plan->mask_array[PREF]) != 0) |
Behdad Esfahbod | 7881812 | 2012-07-16 15:49:08 -0400 | [diff] [blame] | 1549 | { |
Behdad Esfahbod | 8e7b588 | 2012-07-16 17:04:46 -0400 | [diff] [blame] | 1550 | /* 1. Only reorder a glyph produced by substitution during application |
| 1551 | * of the <pref> feature. (Note that a font may shape a Ra consonant with |
| 1552 | * the feature generally but block it in certain contexts.) |
| 1553 | */ |
Behdad Esfahbod | 85fc6c4 | 2012-08-02 12:21:44 -0400 | [diff] [blame] | 1554 | if (i + 1 == end || (info[i + 1].mask & indic_plan->mask_array[PREF]) == 0) |
Behdad Esfahbod | 8e7b588 | 2012-07-16 17:04:46 -0400 | [diff] [blame] | 1555 | { |
| 1556 | /* |
| 1557 | * 2. Try to find a target position the same way as for pre-base matra. |
| 1558 | * If it is found, reorder pre-base consonant glyph. |
| 1559 | * |
| 1560 | * 3. If position is not found, reorder immediately before main |
| 1561 | * consonant. |
| 1562 | */ |
| 1563 | |
| 1564 | unsigned int new_pos = base; |
Behdad Esfahbod | 88d3c98 | 2012-10-29 16:27:02 -0700 | [diff] [blame] | 1565 | /* Malayalam / Tamil do not have "half" forms or explicit virama forms. |
| 1566 | * The glyphs formed by 'half' are Chillus or ligated explicit viramas. |
| 1567 | * We want to position matra after them. |
| 1568 | */ |
| 1569 | if (buffer->props.script != HB_SCRIPT_MALAYALAM && buffer->props.script != HB_SCRIPT_TAMIL) |
Behdad Esfahbod | d90b8e8 | 2012-07-24 02:10:20 -0400 | [diff] [blame] | 1570 | { |
Behdad Esfahbod | 88d3c98 | 2012-10-29 16:27:02 -0700 | [diff] [blame] | 1571 | while (new_pos > start && |
| 1572 | !(is_one_of (info[new_pos - 1], FLAG(OT_M) | HALANT_OR_COENG_FLAGS))) |
| 1573 | new_pos--; |
| 1574 | |
| 1575 | /* In Khmer coeng model, a V,Ra can go *after* matras. If it goes after a |
| 1576 | * split matra, it should be reordered to *before* the left part of such matra. */ |
| 1577 | if (new_pos > start && info[new_pos - 1].indic_category() == OT_M) |
| 1578 | { |
| 1579 | unsigned int old_pos = i; |
| 1580 | for (unsigned int i = base + 1; i < old_pos; i++) |
| 1581 | if (info[i].indic_category() == OT_M) |
| 1582 | { |
| 1583 | new_pos--; |
| 1584 | break; |
| 1585 | } |
| 1586 | } |
Behdad Esfahbod | d90b8e8 | 2012-07-24 02:10:20 -0400 | [diff] [blame] | 1587 | } |
| 1588 | |
Behdad Esfahbod | deb521d | 2012-07-17 11:37:32 -0400 | [diff] [blame] | 1589 | if (new_pos > start && is_halant_or_coeng (info[new_pos - 1])) |
Behdad Esfahbod | 1f91c39 | 2013-02-13 09:38:40 -0500 | [diff] [blame] | 1590 | { |
Behdad Esfahbod | 8e7b588 | 2012-07-16 17:04:46 -0400 | [diff] [blame] | 1591 | /* -> If ZWJ or ZWNJ follow this halant, position is moved after it. */ |
| 1592 | if (new_pos < end && is_joiner (info[new_pos])) |
| 1593 | new_pos++; |
Behdad Esfahbod | 1f91c39 | 2013-02-13 09:38:40 -0500 | [diff] [blame] | 1594 | } |
Behdad Esfahbod | 8e7b588 | 2012-07-16 17:04:46 -0400 | [diff] [blame] | 1595 | |
| 1596 | { |
| 1597 | unsigned int old_pos = i; |
Behdad Esfahbod | e6b01a8 | 2012-07-23 00:11:26 -0400 | [diff] [blame] | 1598 | buffer->merge_clusters (new_pos, old_pos + 1); |
Behdad Esfahbod | 8e7b588 | 2012-07-16 17:04:46 -0400 | [diff] [blame] | 1599 | hb_glyph_info_t tmp = info[old_pos]; |
| 1600 | memmove (&info[new_pos + 1], &info[new_pos], (old_pos - new_pos) * sizeof (info[0])); |
| 1601 | info[new_pos] = tmp; |
Behdad Esfahbod | f22b7e7 | 2013-02-13 07:32:46 -0500 | [diff] [blame] | 1602 | if (new_pos <= base && base < old_pos) |
| 1603 | base++; |
Behdad Esfahbod | 8e7b588 | 2012-07-16 17:04:46 -0400 | [diff] [blame] | 1604 | } |
| 1605 | } |
| 1606 | |
| 1607 | break; |
Behdad Esfahbod | 7881812 | 2012-07-16 15:49:08 -0400 | [diff] [blame] | 1608 | } |
Behdad Esfahbod | 46e645e | 2012-07-16 15:30:05 -0400 | [diff] [blame] | 1609 | } |
Behdad Esfahbod | eed903b | 2012-05-11 20:50:53 +0200 | [diff] [blame] | 1610 | |
| 1611 | |
Behdad Esfahbod | a913b02 | 2012-05-11 20:59:26 +0200 | [diff] [blame] | 1612 | /* Apply 'init' to the Left Matra if it's a word start. */ |
Behdad Esfahbod | 6a091df | 2012-05-11 21:42:27 +0200 | [diff] [blame] | 1613 | if (info[start].indic_position () == POS_PRE_M && |
Behdad Esfahbod | a913b02 | 2012-05-11 20:59:26 +0200 | [diff] [blame] | 1614 | (!start || |
Behdad Esfahbod | eace47b | 2012-05-13 15:54:43 +0200 | [diff] [blame] | 1615 | !(FLAG (_hb_glyph_info_get_general_category (&info[start - 1])) & |
Behdad Esfahbod | 2c372b8 | 2012-07-20 13:37:48 -0400 | [diff] [blame] | 1616 | FLAG_RANGE (HB_UNICODE_GENERAL_CATEGORY_FORMAT, HB_UNICODE_GENERAL_CATEGORY_NON_SPACING_MARK)))) |
Behdad Esfahbod | 85fc6c4 | 2012-08-02 12:21:44 -0400 | [diff] [blame] | 1617 | info[start].mask |= indic_plan->mask_array[INIT]; |
Behdad Esfahbod | a913b02 | 2012-05-11 20:59:26 +0200 | [diff] [blame] | 1618 | |
Behdad Esfahbod | eed903b | 2012-05-11 20:50:53 +0200 | [diff] [blame] | 1619 | |
Behdad Esfahbod | 8ed248d | 2012-07-20 11:42:24 -0400 | [diff] [blame] | 1620 | /* |
| 1621 | * Finish off the clusters and go home! |
| 1622 | */ |
Behdad Esfahbod | 9ac6b01 | 2013-10-17 16:27:38 +0200 | [diff] [blame] | 1623 | if (hb_options ().uniscribe_bug_compatible) |
Behdad Esfahbod | ebe2973 | 2012-05-11 16:43:12 +0200 | [diff] [blame] | 1624 | { |
Behdad Esfahbod | 9ac6b01 | 2013-10-17 16:27:38 +0200 | [diff] [blame] | 1625 | switch ((hb_tag_t) plan->props.script) |
| 1626 | { |
| 1627 | case HB_SCRIPT_TAMIL: |
| 1628 | case HB_SCRIPT_SINHALA: |
| 1629 | break; |
| 1630 | |
| 1631 | default: |
| 1632 | /* Uniscribe merges the entire cluster... Except for Tamil & Sinhala. |
| 1633 | * This means, half forms are submerged into the main consonants cluster. |
| 1634 | * This is unnecessary, and makes cursor positioning harder, but that's what |
| 1635 | * Uniscribe does. */ |
| 1636 | buffer->merge_clusters (start, end); |
| 1637 | break; |
| 1638 | } |
Behdad Esfahbod | 21d2803 | 2012-05-10 18:34:34 +0200 | [diff] [blame] | 1639 | } |
Behdad Esfahbod | ef24cc8 | 2012-05-09 17:56:03 +0200 | [diff] [blame] | 1640 | } |
Behdad Esfahbod | e7be057 | 2011-07-31 15:18:57 -0400 | [diff] [blame] | 1641 | |
| 1642 | |
Behdad Esfahbod | ef24cc8 | 2012-05-09 17:56:03 +0200 | [diff] [blame] | 1643 | static void |
Behdad Esfahbod | 8bb5deb | 2012-08-02 10:07:58 -0400 | [diff] [blame] | 1644 | final_reordering (const hb_ot_shape_plan_t *plan, |
Behdad Esfahbod | 0beb66e | 2012-12-05 18:46:04 -0500 | [diff] [blame] | 1645 | hb_font_t *font HB_UNUSED, |
Behdad Esfahbod | 3e38c0f | 2012-08-02 09:44:18 -0400 | [diff] [blame] | 1646 | hb_buffer_t *buffer) |
Behdad Esfahbod | ef24cc8 | 2012-05-09 17:56:03 +0200 | [diff] [blame] | 1647 | { |
| 1648 | unsigned int count = buffer->len; |
Behdad Esfahbod | 327d14e | 2012-08-31 16:49:34 -0400 | [diff] [blame] | 1649 | if (unlikely (!count)) return; |
Behdad Esfahbod | e7be057 | 2011-07-31 15:18:57 -0400 | [diff] [blame] | 1650 | |
Behdad Esfahbod | ef24cc8 | 2012-05-09 17:56:03 +0200 | [diff] [blame] | 1651 | hb_glyph_info_t *info = buffer->info; |
| 1652 | unsigned int last = 0; |
Behdad Esfahbod | cee7187 | 2012-05-11 11:41:39 +0200 | [diff] [blame] | 1653 | unsigned int last_syllable = info[0].syllable(); |
Behdad Esfahbod | ef24cc8 | 2012-05-09 17:56:03 +0200 | [diff] [blame] | 1654 | for (unsigned int i = 1; i < count; i++) |
Behdad Esfahbod | cee7187 | 2012-05-11 11:41:39 +0200 | [diff] [blame] | 1655 | if (last_syllable != info[i].syllable()) { |
Behdad Esfahbod | 85fc6c4 | 2012-08-02 12:21:44 -0400 | [diff] [blame] | 1656 | final_reordering_syllable (plan, buffer, last, i); |
Behdad Esfahbod | ef24cc8 | 2012-05-09 17:56:03 +0200 | [diff] [blame] | 1657 | last = i; |
Behdad Esfahbod | cee7187 | 2012-05-11 11:41:39 +0200 | [diff] [blame] | 1658 | last_syllable = info[last].syllable(); |
Behdad Esfahbod | ef24cc8 | 2012-05-09 17:56:03 +0200 | [diff] [blame] | 1659 | } |
Behdad Esfahbod | 85fc6c4 | 2012-08-02 12:21:44 -0400 | [diff] [blame] | 1660 | final_reordering_syllable (plan, buffer, last, count); |
Behdad Esfahbod | ef24cc8 | 2012-05-09 17:56:03 +0200 | [diff] [blame] | 1661 | |
Behdad Esfahbod | 743807a | 2011-07-29 16:37:02 -0400 | [diff] [blame] | 1662 | HB_BUFFER_DEALLOCATE_VAR (buffer, indic_category); |
| 1663 | HB_BUFFER_DEALLOCATE_VAR (buffer, indic_position); |
| 1664 | } |
| 1665 | |
| 1666 | |
Behdad Esfahbod | 3014527 | 2013-10-15 13:47:27 +0200 | [diff] [blame] | 1667 | static void |
| 1668 | clear_syllables (const hb_ot_shape_plan_t *plan HB_UNUSED, |
| 1669 | hb_font_t *font HB_UNUSED, |
| 1670 | hb_buffer_t *buffer) |
| 1671 | { |
| 1672 | hb_glyph_info_t *info = buffer->info; |
| 1673 | unsigned int count = buffer->len; |
| 1674 | for (unsigned int i = 0; i < count; i++) |
| 1675 | info[i].syllable() = 0; |
| 1676 | } |
| 1677 | |
| 1678 | |
Behdad Esfahbod | b85800f | 2012-08-31 18:12:01 -0400 | [diff] [blame] | 1679 | static hb_ot_shape_normalization_mode_t |
Behdad Esfahbod | 0beb66e | 2012-12-05 18:46:04 -0500 | [diff] [blame] | 1680 | normalization_preference_indic (const hb_segment_properties_t *props HB_UNUSED) |
Behdad Esfahbod | b85800f | 2012-08-31 18:12:01 -0400 | [diff] [blame] | 1681 | { |
| 1682 | return HB_OT_SHAPE_NORMALIZATION_MODE_COMPOSED_DIACRITICS_NO_SHORT_CIRCUIT; |
| 1683 | } |
| 1684 | |
Behdad Esfahbod | eba312c | 2012-11-16 12:39:23 -0800 | [diff] [blame] | 1685 | static bool |
| 1686 | decompose_indic (const hb_ot_shape_normalize_context_t *c, |
Behdad Esfahbod | 0736915 | 2012-11-13 12:35:35 -0800 | [diff] [blame] | 1687 | hb_codepoint_t ab, |
| 1688 | hb_codepoint_t *a, |
| 1689 | hb_codepoint_t *b) |
| 1690 | { |
| 1691 | switch (ab) |
| 1692 | { |
| 1693 | /* Don't decompose these. */ |
| 1694 | case 0x0931 : return false; |
| 1695 | case 0x0B94 : return false; |
| 1696 | |
| 1697 | |
| 1698 | /* |
| 1699 | * Decompose split matras that don't have Unicode decompositions. |
| 1700 | */ |
| 1701 | |
| 1702 | case 0x0F77 : *a = 0x0FB2; *b= 0x0F81; return true; |
| 1703 | case 0x0F79 : *a = 0x0FB3; *b= 0x0F81; return true; |
| 1704 | case 0x17BE : *a = 0x17C1; *b= 0x17BE; return true; |
| 1705 | case 0x17BF : *a = 0x17C1; *b= 0x17BF; return true; |
| 1706 | case 0x17C0 : *a = 0x17C1; *b= 0x17C0; return true; |
| 1707 | case 0x17C4 : *a = 0x17C1; *b= 0x17C4; return true; |
| 1708 | case 0x17C5 : *a = 0x17C1; *b= 0x17C5; return true; |
| 1709 | case 0x1925 : *a = 0x1920; *b= 0x1923; return true; |
| 1710 | case 0x1926 : *a = 0x1920; *b= 0x1924; return true; |
| 1711 | case 0x1B3C : *a = 0x1B42; *b= 0x1B3C; return true; |
| 1712 | case 0x1112E : *a = 0x11127; *b= 0x11131; return true; |
| 1713 | case 0x1112F : *a = 0x11127; *b= 0x11132; return true; |
| 1714 | #if 0 |
| 1715 | /* This one has no decomposition in Unicode, but needs no decomposition either. */ |
| 1716 | /* case 0x0AC9 : return false; */ |
| 1717 | case 0x0B57 : *a = no decomp, -> RIGHT; return true; |
| 1718 | case 0x1C29 : *a = no decomp, -> LEFT; return true; |
| 1719 | case 0xA9C0 : *a = no decomp, -> RIGHT; return true; |
| 1720 | case 0x111BF : *a = no decomp, -> ABOVE; return true; |
| 1721 | #endif |
| 1722 | } |
| 1723 | |
Behdad Esfahbod | 43b6531 | 2012-11-16 13:12:35 -0800 | [diff] [blame] | 1724 | if ((ab == 0x0DDA || hb_in_range<hb_codepoint_t> (ab, 0x0DDC, 0x0DDE))) |
Behdad Esfahbod | 0736915 | 2012-11-13 12:35:35 -0800 | [diff] [blame] | 1725 | { |
Behdad Esfahbod | 43b6531 | 2012-11-16 13:12:35 -0800 | [diff] [blame] | 1726 | /* |
| 1727 | * Sinhala split matras... Let the fun begin. |
| 1728 | * |
| 1729 | * These four characters have Unicode decompositions. However, Uniscribe |
| 1730 | * decomposes them "Khmer-style", that is, it uses the character itself to |
| 1731 | * get the second half. The first half of all four decompositions is always |
| 1732 | * U+0DD9. |
| 1733 | * |
| 1734 | * Now, there are buggy fonts, namely, the widely used lklug.ttf, that are |
| 1735 | * broken with Uniscribe. But we need to support them. As such, we only |
| 1736 | * do the Uniscribe-style decomposition if the character is transformed into |
| 1737 | * its "sec.half" form by the 'pstf' feature. Otherwise, we fall back to |
| 1738 | * Unicode decomposition. |
| 1739 | * |
| 1740 | * Note that we can't unconditionally use Unicode decomposition. That would |
| 1741 | * break some other fonts, that are designed to work with Uniscribe, and |
| 1742 | * don't have positioning features for the Unicode-style decomposition. |
| 1743 | * |
| 1744 | * Argh... |
Behdad Esfahbod | b71b0bd | 2012-12-05 19:20:31 -0500 | [diff] [blame] | 1745 | * |
| 1746 | * The Uniscribe behavior is now documented in the newly published Sinhala |
| 1747 | * spec in 2012: |
| 1748 | * |
| 1749 | * http://www.microsoft.com/typography/OpenTypeDev/sinhala/intro.htm#shaping |
Behdad Esfahbod | 43b6531 | 2012-11-16 13:12:35 -0800 | [diff] [blame] | 1750 | */ |
| 1751 | |
| 1752 | const indic_shape_plan_t *indic_plan = (const indic_shape_plan_t *) c->plan->data; |
| 1753 | |
| 1754 | hb_codepoint_t glyph; |
| 1755 | |
Behdad Esfahbod | bab02d3 | 2013-02-12 15:26:45 -0500 | [diff] [blame] | 1756 | if (hb_options ().uniscribe_bug_compatible || |
Behdad Esfahbod | 43b6531 | 2012-11-16 13:12:35 -0800 | [diff] [blame] | 1757 | (c->font->get_glyph (ab, 0, &glyph) && |
Behdad Esfahbod | b5a0f69 | 2013-10-17 18:04:23 +0200 | [diff] [blame] | 1758 | indic_plan->pstf.would_substitute (&glyph, 1, c->font->face))) |
Behdad Esfahbod | 43b6531 | 2012-11-16 13:12:35 -0800 | [diff] [blame] | 1759 | { |
| 1760 | /* Ok, safe to use Uniscribe-style decomposition. */ |
| 1761 | *a = 0x0DD9; |
| 1762 | *b = ab; |
| 1763 | return true; |
| 1764 | } |
Behdad Esfahbod | 0736915 | 2012-11-13 12:35:35 -0800 | [diff] [blame] | 1765 | } |
| 1766 | |
Behdad Esfahbod | eba312c | 2012-11-16 12:39:23 -0800 | [diff] [blame] | 1767 | return c->unicode->decompose (ab, a, b); |
Behdad Esfahbod | 0736915 | 2012-11-13 12:35:35 -0800 | [diff] [blame] | 1768 | } |
| 1769 | |
Behdad Esfahbod | eba312c | 2012-11-16 12:39:23 -0800 | [diff] [blame] | 1770 | static bool |
| 1771 | compose_indic (const hb_ot_shape_normalize_context_t *c, |
Behdad Esfahbod | 0736915 | 2012-11-13 12:35:35 -0800 | [diff] [blame] | 1772 | hb_codepoint_t a, |
| 1773 | hb_codepoint_t b, |
| 1774 | hb_codepoint_t *ab) |
| 1775 | { |
| 1776 | /* Avoid recomposing split matras. */ |
Behdad Esfahbod | eba312c | 2012-11-16 12:39:23 -0800 | [diff] [blame] | 1777 | if (HB_UNICODE_GENERAL_CATEGORY_IS_MARK (c->unicode->general_category (a))) |
Behdad Esfahbod | 0736915 | 2012-11-13 12:35:35 -0800 | [diff] [blame] | 1778 | return false; |
| 1779 | |
| 1780 | /* Composition-exclusion exceptions that we want to recompose. */ |
| 1781 | if (a == 0x09AF && b == 0x09BC) { *ab = 0x09DF; return true; } |
| 1782 | |
Behdad Esfahbod | eba312c | 2012-11-16 12:39:23 -0800 | [diff] [blame] | 1783 | return c->unicode->compose (a, b, ab); |
Behdad Esfahbod | 0736915 | 2012-11-13 12:35:35 -0800 | [diff] [blame] | 1784 | } |
| 1785 | |
| 1786 | |
Behdad Esfahbod | 693918e | 2012-07-30 21:08:51 -0400 | [diff] [blame] | 1787 | const hb_ot_complex_shaper_t _hb_ot_complex_shaper_indic = |
| 1788 | { |
| 1789 | "indic", |
| 1790 | collect_features_indic, |
| 1791 | override_features_indic, |
Behdad Esfahbod | a8c6da9 | 2012-08-02 10:46:34 -0400 | [diff] [blame] | 1792 | data_create_indic, |
| 1793 | data_destroy_indic, |
Behdad Esfahbod | 9f9f04c | 2012-08-11 18:34:13 -0400 | [diff] [blame] | 1794 | NULL, /* preprocess_text */ |
Behdad Esfahbod | b85800f | 2012-08-31 18:12:01 -0400 | [diff] [blame] | 1795 | normalization_preference_indic, |
Behdad Esfahbod | 0736915 | 2012-11-13 12:35:35 -0800 | [diff] [blame] | 1796 | decompose_indic, |
| 1797 | compose_indic, |
Behdad Esfahbod | 693918e | 2012-07-30 21:08:51 -0400 | [diff] [blame] | 1798 | setup_masks_indic, |
Behdad Esfahbod | 5680002 | 2013-02-12 09:44:57 -0500 | [diff] [blame] | 1799 | HB_OT_SHAPE_ZERO_WIDTH_MARKS_NONE, |
Behdad Esfahbod | 865745b | 2012-11-14 13:48:26 -0800 | [diff] [blame] | 1800 | false, /* fallback_position */ |
Behdad Esfahbod | 693918e | 2012-07-30 21:08:51 -0400 | [diff] [blame] | 1801 | }; |