Behdad Esfahbod | affaf8a | 2012-08-07 22:41:38 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright © 2011,2012 Google, Inc. |
| 3 | * |
| 4 | * This is part of HarfBuzz, a text shaping library. |
| 5 | * |
| 6 | * Permission is hereby granted, without written agreement and without |
| 7 | * license or royalty fees, to use, copy, modify, and distribute this |
| 8 | * software and its documentation for any purpose, provided that the |
| 9 | * above copyright notice and the following two paragraphs appear in |
| 10 | * all copies of this software. |
| 11 | * |
| 12 | * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR |
| 13 | * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES |
| 14 | * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN |
| 15 | * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH |
| 16 | * DAMAGE. |
| 17 | * |
| 18 | * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, |
| 19 | * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND |
| 20 | * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS |
| 21 | * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO |
| 22 | * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. |
| 23 | * |
| 24 | * Google Author(s): Behdad Esfahbod |
| 25 | */ |
| 26 | |
Behdad Esfahbod | 9c929ab | 2012-08-08 14:33:37 -0400 | [diff] [blame] | 27 | #include "hb-ot-shape-fallback-private.hh" |
Behdad Esfahbod | affaf8a | 2012-08-07 22:41:38 -0400 | [diff] [blame] | 28 | |
Behdad Esfahbod | 2175693 | 2012-08-08 01:20:45 -0400 | [diff] [blame] | 29 | static unsigned int |
Behdad Esfahbod | 3992b5e | 2012-09-01 19:20:41 -0400 | [diff] [blame] | 30 | recategorize_combining_class (hb_codepoint_t u, |
Behdad Esfahbod | 1d581ec | 2012-09-01 20:06:26 -0400 | [diff] [blame] | 31 | unsigned int klass) |
Behdad Esfahbod | 2175693 | 2012-08-08 01:20:45 -0400 | [diff] [blame] | 32 | { |
Behdad Esfahbod | 1d581ec | 2012-09-01 20:06:26 -0400 | [diff] [blame] | 33 | if (klass >= 200) |
| 34 | return klass; |
Behdad Esfahbod | 2175693 | 2012-08-08 01:20:45 -0400 | [diff] [blame] | 35 | |
Behdad Esfahbod | 1d581ec | 2012-09-01 20:06:26 -0400 | [diff] [blame] | 36 | /* Thai / Lao need some per-character work. */ |
| 37 | if ((u & ~0xFF) == 0x0E00) |
| 38 | { |
| 39 | if (unlikely (klass == 0)) |
| 40 | { |
| 41 | switch (u) |
| 42 | { |
| 43 | case 0x0E31: |
| 44 | case 0x0E34: |
| 45 | case 0x0E35: |
| 46 | case 0x0E36: |
| 47 | case 0x0E37: |
| 48 | case 0x0E47: |
| 49 | case 0x0E4C: |
| 50 | case 0x0E4D: |
| 51 | case 0x0E4E: |
| 52 | klass = HB_UNICODE_COMBINING_CLASS_ABOVE_RIGHT; |
| 53 | break; |
| 54 | |
| 55 | case 0x0EB1: |
| 56 | case 0x0EB4: |
| 57 | case 0x0EB5: |
| 58 | case 0x0EB6: |
| 59 | case 0x0EB7: |
| 60 | case 0x0EBB: |
| 61 | case 0x0ECC: |
| 62 | case 0x0ECD: |
| 63 | klass = HB_UNICODE_COMBINING_CLASS_ABOVE; |
| 64 | break; |
| 65 | |
| 66 | case 0x0EBC: |
| 67 | klass = HB_UNICODE_COMBINING_CLASS_BELOW; |
| 68 | break; |
| 69 | } |
| 70 | } else { |
| 71 | /* Thai virama is below-right */ |
| 72 | if (u == 0x0E3A) |
| 73 | klass = HB_UNICODE_COMBINING_CLASS_BELOW_RIGHT; |
| 74 | } |
| 75 | } |
| 76 | |
| 77 | switch (klass) |
Behdad Esfahbod | 2175693 | 2012-08-08 01:20:45 -0400 | [diff] [blame] | 78 | { |
Behdad Esfahbod | 56c9e7c | 2012-08-09 21:12:30 -0400 | [diff] [blame] | 79 | |
Behdad Esfahbod | 2175693 | 2012-08-08 01:20:45 -0400 | [diff] [blame] | 80 | /* Hebrew */ |
Behdad Esfahbod | 56c9e7c | 2012-08-09 21:12:30 -0400 | [diff] [blame] | 81 | |
Behdad Esfahbod | 2175693 | 2012-08-08 01:20:45 -0400 | [diff] [blame] | 82 | case HB_MODIFIED_COMBINING_CLASS_CCC10: /* sheva */ |
| 83 | case HB_MODIFIED_COMBINING_CLASS_CCC11: /* hataf segol */ |
| 84 | case HB_MODIFIED_COMBINING_CLASS_CCC12: /* hataf patah */ |
| 85 | case HB_MODIFIED_COMBINING_CLASS_CCC13: /* hataf qamats */ |
| 86 | case HB_MODIFIED_COMBINING_CLASS_CCC14: /* hiriq */ |
| 87 | case HB_MODIFIED_COMBINING_CLASS_CCC15: /* tsere */ |
| 88 | case HB_MODIFIED_COMBINING_CLASS_CCC16: /* segol */ |
| 89 | case HB_MODIFIED_COMBINING_CLASS_CCC17: /* patah */ |
| 90 | case HB_MODIFIED_COMBINING_CLASS_CCC18: /* qamats */ |
| 91 | case HB_MODIFIED_COMBINING_CLASS_CCC20: /* qubuts */ |
| 92 | case HB_MODIFIED_COMBINING_CLASS_CCC22: /* meteg */ |
| 93 | return HB_UNICODE_COMBINING_CLASS_BELOW; |
| 94 | |
| 95 | case HB_MODIFIED_COMBINING_CLASS_CCC23: /* rafe */ |
| 96 | return HB_UNICODE_COMBINING_CLASS_ATTACHED_ABOVE; |
| 97 | |
| 98 | case HB_MODIFIED_COMBINING_CLASS_CCC24: /* shin dot */ |
| 99 | return HB_UNICODE_COMBINING_CLASS_ABOVE_RIGHT; |
| 100 | |
| 101 | case HB_MODIFIED_COMBINING_CLASS_CCC25: /* sin dot */ |
| 102 | case HB_MODIFIED_COMBINING_CLASS_CCC19: /* holam */ |
| 103 | return HB_UNICODE_COMBINING_CLASS_ABOVE_LEFT; |
| 104 | |
| 105 | case HB_MODIFIED_COMBINING_CLASS_CCC26: /* point varika */ |
| 106 | return HB_UNICODE_COMBINING_CLASS_ABOVE; |
| 107 | |
| 108 | case HB_MODIFIED_COMBINING_CLASS_CCC21: /* dagesh */ |
| 109 | break; |
| 110 | |
Behdad Esfahbod | 56c9e7c | 2012-08-09 21:12:30 -0400 | [diff] [blame] | 111 | |
Behdad Esfahbod | 2175693 | 2012-08-08 01:20:45 -0400 | [diff] [blame] | 112 | /* Arabic and Syriac */ |
Behdad Esfahbod | 56c9e7c | 2012-08-09 21:12:30 -0400 | [diff] [blame] | 113 | |
Behdad Esfahbod | 2175693 | 2012-08-08 01:20:45 -0400 | [diff] [blame] | 114 | case HB_MODIFIED_COMBINING_CLASS_CCC27: /* fathatan */ |
| 115 | case HB_MODIFIED_COMBINING_CLASS_CCC28: /* dammatan */ |
| 116 | case HB_MODIFIED_COMBINING_CLASS_CCC30: /* fatha */ |
| 117 | case HB_MODIFIED_COMBINING_CLASS_CCC31: /* damma */ |
| 118 | case HB_MODIFIED_COMBINING_CLASS_CCC33: /* shadda */ |
| 119 | case HB_MODIFIED_COMBINING_CLASS_CCC34: /* sukun */ |
| 120 | case HB_MODIFIED_COMBINING_CLASS_CCC35: /* superscript alef */ |
| 121 | case HB_MODIFIED_COMBINING_CLASS_CCC36: /* superscript alaph */ |
| 122 | return HB_UNICODE_COMBINING_CLASS_ABOVE; |
| 123 | |
| 124 | case HB_MODIFIED_COMBINING_CLASS_CCC29: /* kasratan */ |
| 125 | case HB_MODIFIED_COMBINING_CLASS_CCC32: /* kasra */ |
| 126 | return HB_UNICODE_COMBINING_CLASS_BELOW; |
| 127 | |
Behdad Esfahbod | 56c9e7c | 2012-08-09 21:12:30 -0400 | [diff] [blame] | 128 | |
| 129 | /* Thai */ |
| 130 | |
Behdad Esfahbod | 56c9e7c | 2012-08-09 21:12:30 -0400 | [diff] [blame] | 131 | case HB_MODIFIED_COMBINING_CLASS_CCC103: /* sara u / sara uu */ |
Behdad Esfahbod | 5a7f187 | 2012-08-30 22:53:29 -0400 | [diff] [blame] | 132 | return HB_UNICODE_COMBINING_CLASS_BELOW_RIGHT; |
Behdad Esfahbod | 56c9e7c | 2012-08-09 21:12:30 -0400 | [diff] [blame] | 133 | |
| 134 | case HB_MODIFIED_COMBINING_CLASS_CCC107: /* mai */ |
Behdad Esfahbod | 5a7f187 | 2012-08-30 22:53:29 -0400 | [diff] [blame] | 135 | return HB_UNICODE_COMBINING_CLASS_ABOVE_RIGHT; |
Behdad Esfahbod | 56c9e7c | 2012-08-09 21:12:30 -0400 | [diff] [blame] | 136 | |
| 137 | |
| 138 | /* Lao */ |
| 139 | |
| 140 | case HB_MODIFIED_COMBINING_CLASS_CCC118: /* sign u / sign uu */ |
Behdad Esfahbod | 5a7f187 | 2012-08-30 22:53:29 -0400 | [diff] [blame] | 141 | return HB_UNICODE_COMBINING_CLASS_BELOW_RIGHT; |
Behdad Esfahbod | 56c9e7c | 2012-08-09 21:12:30 -0400 | [diff] [blame] | 142 | |
| 143 | case HB_MODIFIED_COMBINING_CLASS_CCC122: /* mai */ |
Behdad Esfahbod | 5a7f187 | 2012-08-30 22:53:29 -0400 | [diff] [blame] | 144 | return HB_UNICODE_COMBINING_CLASS_ABOVE_RIGHT; |
Behdad Esfahbod | 56c9e7c | 2012-08-09 21:12:30 -0400 | [diff] [blame] | 145 | |
| 146 | |
| 147 | /* Tibetan */ |
| 148 | |
| 149 | case HB_MODIFIED_COMBINING_CLASS_CCC129: /* sign aa */ |
| 150 | return HB_UNICODE_COMBINING_CLASS_BELOW; |
| 151 | |
| 152 | case HB_MODIFIED_COMBINING_CLASS_CCC130: /* sign i*/ |
| 153 | return HB_UNICODE_COMBINING_CLASS_ABOVE; |
| 154 | |
| 155 | case HB_MODIFIED_COMBINING_CLASS_CCC132: /* sign u */ |
| 156 | return HB_UNICODE_COMBINING_CLASS_BELOW; |
| 157 | |
Behdad Esfahbod | 2175693 | 2012-08-08 01:20:45 -0400 | [diff] [blame] | 158 | } |
| 159 | |
Behdad Esfahbod | 1d581ec | 2012-09-01 20:06:26 -0400 | [diff] [blame] | 160 | return klass; |
Behdad Esfahbod | 2175693 | 2012-08-08 01:20:45 -0400 | [diff] [blame] | 161 | } |
| 162 | |
Behdad Esfahbod | 3992b5e | 2012-09-01 19:20:41 -0400 | [diff] [blame] | 163 | void |
| 164 | _hb_ot_shape_fallback_position_recategorize_marks (const hb_ot_shape_plan_t *plan, |
| 165 | hb_font_t *font, |
| 166 | hb_buffer_t *buffer) |
| 167 | { |
| 168 | unsigned int count = buffer->len; |
| 169 | for (unsigned int i = 0; i < count; i++) |
| 170 | if (_hb_glyph_info_get_general_category (&buffer->info[i]) == HB_UNICODE_GENERAL_CATEGORY_NON_SPACING_MARK) { |
| 171 | unsigned int combining_class = _hb_glyph_info_get_modified_combining_class (&buffer->info[i]); |
| 172 | combining_class = recategorize_combining_class (buffer->info[i].codepoint, combining_class); |
| 173 | _hb_glyph_info_set_modified_combining_class (&buffer->info[i], combining_class); |
| 174 | } |
| 175 | } |
| 176 | |
| 177 | |
| 178 | static void |
| 179 | zero_mark_advances (hb_buffer_t *buffer, |
| 180 | unsigned int start, |
| 181 | unsigned int end) |
| 182 | { |
| 183 | for (unsigned int i = start; i < end; i++) |
| 184 | if (_hb_glyph_info_get_general_category (&buffer->info[i]) == HB_UNICODE_GENERAL_CATEGORY_NON_SPACING_MARK) |
| 185 | { |
| 186 | buffer->pos[i].x_advance = 0; |
| 187 | buffer->pos[i].y_advance = 0; |
| 188 | } |
| 189 | } |
| 190 | |
Behdad Esfahbod | 2175693 | 2012-08-08 01:20:45 -0400 | [diff] [blame] | 191 | static inline void |
| 192 | position_mark (const hb_ot_shape_plan_t *plan, |
| 193 | hb_font_t *font, |
| 194 | hb_buffer_t *buffer, |
| 195 | hb_glyph_extents_t &base_extents, |
| 196 | unsigned int i, |
| 197 | unsigned int combining_class) |
| 198 | { |
| 199 | hb_glyph_extents_t mark_extents; |
Behdad Esfahbod | 4c8ac4f | 2012-08-08 17:44:19 -0400 | [diff] [blame] | 200 | if (!font->get_glyph_extents (buffer->info[i].codepoint, |
| 201 | &mark_extents)) |
Behdad Esfahbod | 2175693 | 2012-08-08 01:20:45 -0400 | [diff] [blame] | 202 | return; |
| 203 | |
| 204 | hb_position_t y_gap = font->y_scale / 16; |
| 205 | |
| 206 | hb_glyph_position_t &pos = buffer->pos[i]; |
| 207 | pos.x_offset = pos.y_offset = 0; |
| 208 | |
| 209 | |
| 210 | /* We dont position LEFT and RIGHT marks. */ |
| 211 | |
| 212 | /* X positioning */ |
| 213 | switch (combining_class) |
| 214 | { |
| 215 | case HB_UNICODE_COMBINING_CLASS_DOUBLE_BELOW: |
| 216 | case HB_UNICODE_COMBINING_CLASS_DOUBLE_ABOVE: |
Behdad Esfahbod | daf13af | 2012-08-10 16:38:44 -0400 | [diff] [blame] | 217 | if (buffer->props.direction == HB_DIRECTION_LTR) { |
| 218 | pos.x_offset += base_extents.x_bearing - mark_extents.width / 2 - mark_extents.x_bearing; |
| 219 | break; |
| 220 | } else if (buffer->props.direction == HB_DIRECTION_RTL) { |
| 221 | pos.x_offset += base_extents.x_bearing + base_extents.width - mark_extents.width / 2 - mark_extents.x_bearing; |
| 222 | break; |
| 223 | } |
| 224 | /* Fall through */ |
Behdad Esfahbod | 2175693 | 2012-08-08 01:20:45 -0400 | [diff] [blame] | 225 | |
Behdad Esfahbod | e1ba628 | 2012-08-27 16:28:05 -0400 | [diff] [blame] | 226 | default: |
Behdad Esfahbod | 2175693 | 2012-08-08 01:20:45 -0400 | [diff] [blame] | 227 | case HB_UNICODE_COMBINING_CLASS_ATTACHED_BELOW: |
| 228 | case HB_UNICODE_COMBINING_CLASS_ATTACHED_ABOVE: |
| 229 | case HB_UNICODE_COMBINING_CLASS_BELOW: |
| 230 | case HB_UNICODE_COMBINING_CLASS_ABOVE: |
| 231 | /* Center align. */ |
| 232 | pos.x_offset += base_extents.x_bearing + (base_extents.width - mark_extents.width) / 2 - mark_extents.x_bearing; |
| 233 | break; |
| 234 | |
| 235 | case HB_UNICODE_COMBINING_CLASS_ATTACHED_BELOW_LEFT: |
| 236 | case HB_UNICODE_COMBINING_CLASS_BELOW_LEFT: |
| 237 | case HB_UNICODE_COMBINING_CLASS_ABOVE_LEFT: |
| 238 | /* Left align. */ |
| 239 | pos.x_offset += base_extents.x_bearing - mark_extents.x_bearing; |
| 240 | break; |
| 241 | |
| 242 | case HB_UNICODE_COMBINING_CLASS_ATTACHED_ABOVE_RIGHT: |
| 243 | case HB_UNICODE_COMBINING_CLASS_BELOW_RIGHT: |
| 244 | case HB_UNICODE_COMBINING_CLASS_ABOVE_RIGHT: |
| 245 | /* Right align. */ |
| 246 | pos.x_offset += base_extents.x_bearing + base_extents.width - mark_extents.width - mark_extents.x_bearing; |
| 247 | break; |
| 248 | } |
| 249 | |
| 250 | /* Y positioning */ |
| 251 | switch (combining_class) |
| 252 | { |
| 253 | case HB_UNICODE_COMBINING_CLASS_DOUBLE_BELOW: |
| 254 | case HB_UNICODE_COMBINING_CLASS_BELOW_LEFT: |
| 255 | case HB_UNICODE_COMBINING_CLASS_BELOW: |
| 256 | case HB_UNICODE_COMBINING_CLASS_BELOW_RIGHT: |
| 257 | /* Add gap, fall-through. */ |
| 258 | base_extents.height -= y_gap; |
| 259 | |
| 260 | case HB_UNICODE_COMBINING_CLASS_ATTACHED_BELOW_LEFT: |
| 261 | case HB_UNICODE_COMBINING_CLASS_ATTACHED_BELOW: |
| 262 | pos.y_offset += base_extents.y_bearing + base_extents.height - mark_extents.y_bearing; |
| 263 | base_extents.height += mark_extents.height; |
| 264 | break; |
| 265 | |
| 266 | case HB_UNICODE_COMBINING_CLASS_DOUBLE_ABOVE: |
| 267 | case HB_UNICODE_COMBINING_CLASS_ABOVE_LEFT: |
| 268 | case HB_UNICODE_COMBINING_CLASS_ABOVE: |
| 269 | case HB_UNICODE_COMBINING_CLASS_ABOVE_RIGHT: |
| 270 | /* Add gap, fall-through. */ |
| 271 | base_extents.y_bearing += y_gap; |
| 272 | base_extents.height -= y_gap; |
| 273 | |
| 274 | case HB_UNICODE_COMBINING_CLASS_ATTACHED_ABOVE: |
| 275 | case HB_UNICODE_COMBINING_CLASS_ATTACHED_ABOVE_RIGHT: |
| 276 | pos.y_offset += base_extents.y_bearing - (mark_extents.y_bearing + mark_extents.height); |
| 277 | base_extents.y_bearing -= mark_extents.height; |
| 278 | base_extents.height += mark_extents.height; |
| 279 | break; |
| 280 | } |
| 281 | } |
| 282 | |
| 283 | static inline void |
| 284 | position_around_base (const hb_ot_shape_plan_t *plan, |
| 285 | hb_font_t *font, |
| 286 | hb_buffer_t *buffer, |
| 287 | unsigned int base, |
| 288 | unsigned int end) |
| 289 | { |
| 290 | hb_glyph_extents_t base_extents; |
Behdad Esfahbod | 4c8ac4f | 2012-08-08 17:44:19 -0400 | [diff] [blame] | 291 | if (!font->get_glyph_extents (buffer->info[base].codepoint, |
| 292 | &base_extents)) |
Behdad Esfahbod | 2175693 | 2012-08-08 01:20:45 -0400 | [diff] [blame] | 293 | { |
| 294 | /* If extents don't work, zero marks and go home. */ |
| 295 | zero_mark_advances (buffer, base + 1, end); |
| 296 | return; |
| 297 | } |
| 298 | base_extents.x_bearing += buffer->pos[base].x_offset; |
| 299 | base_extents.y_bearing += buffer->pos[base].y_offset; |
| 300 | |
| 301 | /* XXX Handle ligature component positioning... */ |
| 302 | HB_UNUSED bool is_ligature = is_a_ligature (buffer->info[base]); |
| 303 | |
| 304 | hb_position_t x_offset = 0, y_offset = 0; |
Behdad Esfahbod | d345313 | 2012-08-10 16:34:04 -0400 | [diff] [blame] | 305 | if (HB_DIRECTION_IS_FORWARD (buffer->props.direction)) { |
| 306 | x_offset -= buffer->pos[base].x_advance; |
| 307 | y_offset -= buffer->pos[base].y_advance; |
| 308 | } |
Behdad Esfahbod | 2175693 | 2012-08-08 01:20:45 -0400 | [diff] [blame] | 309 | unsigned int last_combining_class = 255; |
| 310 | hb_glyph_extents_t cluster_extents; |
| 311 | for (unsigned int i = base + 1; i < end; i++) |
Behdad Esfahbod | 30dd622 | 2012-08-27 16:54:34 -0400 | [diff] [blame] | 312 | if (_hb_glyph_info_get_modified_combining_class (&buffer->info[i])) |
Behdad Esfahbod | 2175693 | 2012-08-08 01:20:45 -0400 | [diff] [blame] | 313 | { |
Behdad Esfahbod | 3992b5e | 2012-09-01 19:20:41 -0400 | [diff] [blame] | 314 | unsigned int this_combining_class = _hb_glyph_info_get_modified_combining_class (&buffer->info[i]); |
Behdad Esfahbod | 2175693 | 2012-08-08 01:20:45 -0400 | [diff] [blame] | 315 | if (this_combining_class != last_combining_class) |
| 316 | cluster_extents = base_extents; |
| 317 | |
Behdad Esfahbod | 667218a | 2012-08-27 17:00:44 -0400 | [diff] [blame] | 318 | position_mark (plan, font, buffer, cluster_extents, i, this_combining_class); |
Behdad Esfahbod | 2175693 | 2012-08-08 01:20:45 -0400 | [diff] [blame] | 319 | |
| 320 | buffer->pos[i].x_advance = 0; |
| 321 | buffer->pos[i].y_advance = 0; |
| 322 | buffer->pos[i].x_offset += x_offset; |
| 323 | buffer->pos[i].y_offset += y_offset; |
| 324 | |
Behdad Esfahbod | 2175693 | 2012-08-08 01:20:45 -0400 | [diff] [blame] | 325 | last_combining_class = this_combining_class; |
| 326 | } else { |
Behdad Esfahbod | d345313 | 2012-08-10 16:34:04 -0400 | [diff] [blame] | 327 | if (HB_DIRECTION_IS_FORWARD (buffer->props.direction)) { |
| 328 | x_offset -= buffer->pos[i].x_advance; |
| 329 | y_offset -= buffer->pos[i].y_advance; |
| 330 | } else { |
| 331 | x_offset += buffer->pos[i].x_advance; |
| 332 | y_offset += buffer->pos[i].y_advance; |
| 333 | } |
Behdad Esfahbod | 2175693 | 2012-08-08 01:20:45 -0400 | [diff] [blame] | 334 | } |
| 335 | |
| 336 | |
| 337 | } |
| 338 | |
| 339 | static inline void |
| 340 | position_cluster (const hb_ot_shape_plan_t *plan, |
| 341 | hb_font_t *font, |
| 342 | hb_buffer_t *buffer, |
| 343 | unsigned int start, |
| 344 | unsigned int end) |
| 345 | { |
| 346 | if (end - start < 2) |
| 347 | return; |
| 348 | |
| 349 | /* Find the base glyph */ |
| 350 | for (unsigned int i = start; i < end; i++) |
Behdad Esfahbod | 9433c21 | 2012-09-06 14:27:15 -0400 | [diff] [blame] | 351 | if (!HB_UNICODE_GENERAL_CATEGORY_IS_MARK (_hb_glyph_info_get_general_category (&buffer->info[i]))) |
Behdad Esfahbod | 2175693 | 2012-08-08 01:20:45 -0400 | [diff] [blame] | 352 | { |
Behdad Esfahbod | 525c685 | 2012-09-06 16:02:07 -0400 | [diff] [blame^] | 353 | /* Find mark glyphs */ |
| 354 | unsigned int j; |
| 355 | for (j = i + 1; j < end; j++) |
| 356 | if (!HB_UNICODE_GENERAL_CATEGORY_IS_MARK (_hb_glyph_info_get_general_category (&buffer->info[j]))) |
| 357 | break; |
| 358 | |
| 359 | position_around_base (plan, font, buffer, i, j); |
| 360 | |
| 361 | i = j - 1; |
Behdad Esfahbod | 2175693 | 2012-08-08 01:20:45 -0400 | [diff] [blame] | 362 | } |
| 363 | } |
| 364 | |
Behdad Esfahbod | affaf8a | 2012-08-07 22:41:38 -0400 | [diff] [blame] | 365 | void |
Behdad Esfahbod | 9c929ab | 2012-08-08 14:33:37 -0400 | [diff] [blame] | 366 | _hb_ot_shape_fallback_position (const hb_ot_shape_plan_t *plan, |
Behdad Esfahbod | affaf8a | 2012-08-07 22:41:38 -0400 | [diff] [blame] | 367 | hb_font_t *font, |
| 368 | hb_buffer_t *buffer) |
| 369 | { |
Behdad Esfahbod | 2175693 | 2012-08-08 01:20:45 -0400 | [diff] [blame] | 370 | unsigned int start = 0; |
| 371 | unsigned int last_cluster = buffer->info[0].cluster; |
| 372 | unsigned int count = buffer->len; |
| 373 | for (unsigned int i = 1; i < count; i++) |
| 374 | if (buffer->info[i].cluster != last_cluster) { |
| 375 | position_cluster (plan, font, buffer, start, i); |
| 376 | start = i; |
| 377 | last_cluster = buffer->info[i].cluster; |
| 378 | } |
| 379 | position_cluster (plan, font, buffer, start, count); |
Behdad Esfahbod | affaf8a | 2012-08-07 22:41:38 -0400 | [diff] [blame] | 380 | } |