gfx/harfbuzz/src/hb-ot-shape-fallback.cc

Fri, 16 Jan 2015 18:13:44 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Fri, 16 Jan 2015 18:13:44 +0100
branch
TOR_BUG_9701
changeset 14
925c144e1f1f
permissions
-rw-r--r--

Integrate suggestion from review to improve consistency with existing code.

michael@0 1 /*
michael@0 2 * Copyright © 2011,2012 Google, Inc.
michael@0 3 *
michael@0 4 * This is part of HarfBuzz, a text shaping library.
michael@0 5 *
michael@0 6 * Permission is hereby granted, without written agreement and without
michael@0 7 * license or royalty fees, to use, copy, modify, and distribute this
michael@0 8 * software and its documentation for any purpose, provided that the
michael@0 9 * above copyright notice and the following two paragraphs appear in
michael@0 10 * all copies of this software.
michael@0 11 *
michael@0 12 * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR
michael@0 13 * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
michael@0 14 * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN
michael@0 15 * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
michael@0 16 * DAMAGE.
michael@0 17 *
michael@0 18 * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING,
michael@0 19 * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
michael@0 20 * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
michael@0 21 * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO
michael@0 22 * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
michael@0 23 *
michael@0 24 * Google Author(s): Behdad Esfahbod
michael@0 25 */
michael@0 26
michael@0 27 #include "hb-ot-shape-fallback-private.hh"
michael@0 28 #include "hb-ot-layout-gsubgpos-private.hh"
michael@0 29
michael@0 30 static unsigned int
michael@0 31 recategorize_combining_class (hb_codepoint_t u,
michael@0 32 unsigned int klass)
michael@0 33 {
michael@0 34 if (klass >= 200)
michael@0 35 return klass;
michael@0 36
michael@0 37 /* Thai / Lao need some per-character work. */
michael@0 38 if ((u & ~0xFF) == 0x0E00)
michael@0 39 {
michael@0 40 if (unlikely (klass == 0))
michael@0 41 {
michael@0 42 switch (u)
michael@0 43 {
michael@0 44 case 0x0E31:
michael@0 45 case 0x0E34:
michael@0 46 case 0x0E35:
michael@0 47 case 0x0E36:
michael@0 48 case 0x0E37:
michael@0 49 case 0x0E47:
michael@0 50 case 0x0E4C:
michael@0 51 case 0x0E4D:
michael@0 52 case 0x0E4E:
michael@0 53 klass = HB_UNICODE_COMBINING_CLASS_ABOVE_RIGHT;
michael@0 54 break;
michael@0 55
michael@0 56 case 0x0EB1:
michael@0 57 case 0x0EB4:
michael@0 58 case 0x0EB5:
michael@0 59 case 0x0EB6:
michael@0 60 case 0x0EB7:
michael@0 61 case 0x0EBB:
michael@0 62 case 0x0ECC:
michael@0 63 case 0x0ECD:
michael@0 64 klass = HB_UNICODE_COMBINING_CLASS_ABOVE;
michael@0 65 break;
michael@0 66
michael@0 67 case 0x0EBC:
michael@0 68 klass = HB_UNICODE_COMBINING_CLASS_BELOW;
michael@0 69 break;
michael@0 70 }
michael@0 71 } else {
michael@0 72 /* Thai virama is below-right */
michael@0 73 if (u == 0x0E3A)
michael@0 74 klass = HB_UNICODE_COMBINING_CLASS_BELOW_RIGHT;
michael@0 75 }
michael@0 76 }
michael@0 77
michael@0 78 switch (klass)
michael@0 79 {
michael@0 80
michael@0 81 /* Hebrew */
michael@0 82
michael@0 83 case HB_MODIFIED_COMBINING_CLASS_CCC10: /* sheva */
michael@0 84 case HB_MODIFIED_COMBINING_CLASS_CCC11: /* hataf segol */
michael@0 85 case HB_MODIFIED_COMBINING_CLASS_CCC12: /* hataf patah */
michael@0 86 case HB_MODIFIED_COMBINING_CLASS_CCC13: /* hataf qamats */
michael@0 87 case HB_MODIFIED_COMBINING_CLASS_CCC14: /* hiriq */
michael@0 88 case HB_MODIFIED_COMBINING_CLASS_CCC15: /* tsere */
michael@0 89 case HB_MODIFIED_COMBINING_CLASS_CCC16: /* segol */
michael@0 90 case HB_MODIFIED_COMBINING_CLASS_CCC17: /* patah */
michael@0 91 case HB_MODIFIED_COMBINING_CLASS_CCC18: /* qamats */
michael@0 92 case HB_MODIFIED_COMBINING_CLASS_CCC20: /* qubuts */
michael@0 93 case HB_MODIFIED_COMBINING_CLASS_CCC22: /* meteg */
michael@0 94 return HB_UNICODE_COMBINING_CLASS_BELOW;
michael@0 95
michael@0 96 case HB_MODIFIED_COMBINING_CLASS_CCC23: /* rafe */
michael@0 97 return HB_UNICODE_COMBINING_CLASS_ATTACHED_ABOVE;
michael@0 98
michael@0 99 case HB_MODIFIED_COMBINING_CLASS_CCC24: /* shin dot */
michael@0 100 return HB_UNICODE_COMBINING_CLASS_ABOVE_RIGHT;
michael@0 101
michael@0 102 case HB_MODIFIED_COMBINING_CLASS_CCC25: /* sin dot */
michael@0 103 case HB_MODIFIED_COMBINING_CLASS_CCC19: /* holam */
michael@0 104 return HB_UNICODE_COMBINING_CLASS_ABOVE_LEFT;
michael@0 105
michael@0 106 case HB_MODIFIED_COMBINING_CLASS_CCC26: /* point varika */
michael@0 107 return HB_UNICODE_COMBINING_CLASS_ABOVE;
michael@0 108
michael@0 109 case HB_MODIFIED_COMBINING_CLASS_CCC21: /* dagesh */
michael@0 110 break;
michael@0 111
michael@0 112
michael@0 113 /* Arabic and Syriac */
michael@0 114
michael@0 115 case HB_MODIFIED_COMBINING_CLASS_CCC27: /* fathatan */
michael@0 116 case HB_MODIFIED_COMBINING_CLASS_CCC28: /* dammatan */
michael@0 117 case HB_MODIFIED_COMBINING_CLASS_CCC30: /* fatha */
michael@0 118 case HB_MODIFIED_COMBINING_CLASS_CCC31: /* damma */
michael@0 119 case HB_MODIFIED_COMBINING_CLASS_CCC33: /* shadda */
michael@0 120 case HB_MODIFIED_COMBINING_CLASS_CCC34: /* sukun */
michael@0 121 case HB_MODIFIED_COMBINING_CLASS_CCC35: /* superscript alef */
michael@0 122 case HB_MODIFIED_COMBINING_CLASS_CCC36: /* superscript alaph */
michael@0 123 return HB_UNICODE_COMBINING_CLASS_ABOVE;
michael@0 124
michael@0 125 case HB_MODIFIED_COMBINING_CLASS_CCC29: /* kasratan */
michael@0 126 case HB_MODIFIED_COMBINING_CLASS_CCC32: /* kasra */
michael@0 127 return HB_UNICODE_COMBINING_CLASS_BELOW;
michael@0 128
michael@0 129
michael@0 130 /* Thai */
michael@0 131
michael@0 132 case HB_MODIFIED_COMBINING_CLASS_CCC103: /* sara u / sara uu */
michael@0 133 return HB_UNICODE_COMBINING_CLASS_BELOW_RIGHT;
michael@0 134
michael@0 135 case HB_MODIFIED_COMBINING_CLASS_CCC107: /* mai */
michael@0 136 return HB_UNICODE_COMBINING_CLASS_ABOVE_RIGHT;
michael@0 137
michael@0 138
michael@0 139 /* Lao */
michael@0 140
michael@0 141 case HB_MODIFIED_COMBINING_CLASS_CCC118: /* sign u / sign uu */
michael@0 142 return HB_UNICODE_COMBINING_CLASS_BELOW;
michael@0 143
michael@0 144 case HB_MODIFIED_COMBINING_CLASS_CCC122: /* mai */
michael@0 145 return HB_UNICODE_COMBINING_CLASS_ABOVE;
michael@0 146
michael@0 147
michael@0 148 /* Tibetan */
michael@0 149
michael@0 150 case HB_MODIFIED_COMBINING_CLASS_CCC129: /* sign aa */
michael@0 151 return HB_UNICODE_COMBINING_CLASS_BELOW;
michael@0 152
michael@0 153 case HB_MODIFIED_COMBINING_CLASS_CCC130: /* sign i*/
michael@0 154 return HB_UNICODE_COMBINING_CLASS_ABOVE;
michael@0 155
michael@0 156 case HB_MODIFIED_COMBINING_CLASS_CCC132: /* sign u */
michael@0 157 return HB_UNICODE_COMBINING_CLASS_BELOW;
michael@0 158
michael@0 159 }
michael@0 160
michael@0 161 return klass;
michael@0 162 }
michael@0 163
michael@0 164 void
michael@0 165 _hb_ot_shape_fallback_position_recategorize_marks (const hb_ot_shape_plan_t *plan HB_UNUSED,
michael@0 166 hb_font_t *font HB_UNUSED,
michael@0 167 hb_buffer_t *buffer)
michael@0 168 {
michael@0 169 unsigned int count = buffer->len;
michael@0 170 for (unsigned int i = 0; i < count; i++)
michael@0 171 if (_hb_glyph_info_get_general_category (&buffer->info[i]) == HB_UNICODE_GENERAL_CATEGORY_NON_SPACING_MARK) {
michael@0 172 unsigned int combining_class = _hb_glyph_info_get_modified_combining_class (&buffer->info[i]);
michael@0 173 combining_class = recategorize_combining_class (buffer->info[i].codepoint, combining_class);
michael@0 174 _hb_glyph_info_set_modified_combining_class (&buffer->info[i], combining_class);
michael@0 175 }
michael@0 176 }
michael@0 177
michael@0 178
michael@0 179 static void
michael@0 180 zero_mark_advances (hb_buffer_t *buffer,
michael@0 181 unsigned int start,
michael@0 182 unsigned int end)
michael@0 183 {
michael@0 184 for (unsigned int i = start; i < end; i++)
michael@0 185 if (_hb_glyph_info_get_general_category (&buffer->info[i]) == HB_UNICODE_GENERAL_CATEGORY_NON_SPACING_MARK)
michael@0 186 {
michael@0 187 buffer->pos[i].x_advance = 0;
michael@0 188 buffer->pos[i].y_advance = 0;
michael@0 189 }
michael@0 190 }
michael@0 191
michael@0 192 static inline void
michael@0 193 position_mark (const hb_ot_shape_plan_t *plan,
michael@0 194 hb_font_t *font,
michael@0 195 hb_buffer_t *buffer,
michael@0 196 hb_glyph_extents_t &base_extents,
michael@0 197 unsigned int i,
michael@0 198 unsigned int combining_class)
michael@0 199 {
michael@0 200 hb_glyph_extents_t mark_extents;
michael@0 201 if (!font->get_glyph_extents (buffer->info[i].codepoint,
michael@0 202 &mark_extents))
michael@0 203 return;
michael@0 204
michael@0 205 hb_position_t y_gap = font->y_scale / 16;
michael@0 206
michael@0 207 hb_glyph_position_t &pos = buffer->pos[i];
michael@0 208 pos.x_offset = pos.y_offset = 0;
michael@0 209
michael@0 210
michael@0 211 /* We dont position LEFT and RIGHT marks. */
michael@0 212
michael@0 213 /* X positioning */
michael@0 214 switch (combining_class)
michael@0 215 {
michael@0 216 case HB_UNICODE_COMBINING_CLASS_DOUBLE_BELOW:
michael@0 217 case HB_UNICODE_COMBINING_CLASS_DOUBLE_ABOVE:
michael@0 218 if (buffer->props.direction == HB_DIRECTION_LTR) {
michael@0 219 pos.x_offset += base_extents.x_bearing - mark_extents.width / 2 - mark_extents.x_bearing;
michael@0 220 break;
michael@0 221 } else if (buffer->props.direction == HB_DIRECTION_RTL) {
michael@0 222 pos.x_offset += base_extents.x_bearing + base_extents.width - mark_extents.width / 2 - mark_extents.x_bearing;
michael@0 223 break;
michael@0 224 }
michael@0 225 /* Fall through */
michael@0 226
michael@0 227 default:
michael@0 228 case HB_UNICODE_COMBINING_CLASS_ATTACHED_BELOW:
michael@0 229 case HB_UNICODE_COMBINING_CLASS_ATTACHED_ABOVE:
michael@0 230 case HB_UNICODE_COMBINING_CLASS_BELOW:
michael@0 231 case HB_UNICODE_COMBINING_CLASS_ABOVE:
michael@0 232 /* Center align. */
michael@0 233 pos.x_offset += base_extents.x_bearing + (base_extents.width - mark_extents.width) / 2 - mark_extents.x_bearing;
michael@0 234 break;
michael@0 235
michael@0 236 case HB_UNICODE_COMBINING_CLASS_ATTACHED_BELOW_LEFT:
michael@0 237 case HB_UNICODE_COMBINING_CLASS_BELOW_LEFT:
michael@0 238 case HB_UNICODE_COMBINING_CLASS_ABOVE_LEFT:
michael@0 239 /* Left align. */
michael@0 240 pos.x_offset += base_extents.x_bearing - mark_extents.x_bearing;
michael@0 241 break;
michael@0 242
michael@0 243 case HB_UNICODE_COMBINING_CLASS_ATTACHED_ABOVE_RIGHT:
michael@0 244 case HB_UNICODE_COMBINING_CLASS_BELOW_RIGHT:
michael@0 245 case HB_UNICODE_COMBINING_CLASS_ABOVE_RIGHT:
michael@0 246 /* Right align. */
michael@0 247 pos.x_offset += base_extents.x_bearing + base_extents.width - mark_extents.width - mark_extents.x_bearing;
michael@0 248 break;
michael@0 249 }
michael@0 250
michael@0 251 /* Y positioning */
michael@0 252 switch (combining_class)
michael@0 253 {
michael@0 254 case HB_UNICODE_COMBINING_CLASS_DOUBLE_BELOW:
michael@0 255 case HB_UNICODE_COMBINING_CLASS_BELOW_LEFT:
michael@0 256 case HB_UNICODE_COMBINING_CLASS_BELOW:
michael@0 257 case HB_UNICODE_COMBINING_CLASS_BELOW_RIGHT:
michael@0 258 /* Add gap, fall-through. */
michael@0 259 base_extents.height -= y_gap;
michael@0 260
michael@0 261 case HB_UNICODE_COMBINING_CLASS_ATTACHED_BELOW_LEFT:
michael@0 262 case HB_UNICODE_COMBINING_CLASS_ATTACHED_BELOW:
michael@0 263 pos.y_offset = base_extents.y_bearing + base_extents.height - mark_extents.y_bearing;
michael@0 264 /* Never shift up "below" marks. */
michael@0 265 if ((y_gap > 0) == (pos.y_offset > 0))
michael@0 266 {
michael@0 267 base_extents.height -= pos.y_offset;
michael@0 268 pos.y_offset = 0;
michael@0 269 }
michael@0 270 base_extents.height += mark_extents.height;
michael@0 271 break;
michael@0 272
michael@0 273 case HB_UNICODE_COMBINING_CLASS_DOUBLE_ABOVE:
michael@0 274 case HB_UNICODE_COMBINING_CLASS_ABOVE_LEFT:
michael@0 275 case HB_UNICODE_COMBINING_CLASS_ABOVE:
michael@0 276 case HB_UNICODE_COMBINING_CLASS_ABOVE_RIGHT:
michael@0 277 /* Add gap, fall-through. */
michael@0 278 base_extents.y_bearing += y_gap;
michael@0 279 base_extents.height -= y_gap;
michael@0 280
michael@0 281 case HB_UNICODE_COMBINING_CLASS_ATTACHED_ABOVE:
michael@0 282 case HB_UNICODE_COMBINING_CLASS_ATTACHED_ABOVE_RIGHT:
michael@0 283 pos.y_offset = base_extents.y_bearing - (mark_extents.y_bearing + mark_extents.height);
michael@0 284 /* Don't shift down "above" marks too much. */
michael@0 285 if ((y_gap > 0) != (pos.y_offset > 0))
michael@0 286 {
michael@0 287 unsigned int correction = -pos.y_offset / 2;
michael@0 288 base_extents.y_bearing += correction;
michael@0 289 base_extents.height -= correction;
michael@0 290 pos.y_offset += correction;
michael@0 291 }
michael@0 292 base_extents.y_bearing -= mark_extents.height;
michael@0 293 base_extents.height += mark_extents.height;
michael@0 294 break;
michael@0 295 }
michael@0 296 }
michael@0 297
michael@0 298 static inline void
michael@0 299 position_around_base (const hb_ot_shape_plan_t *plan,
michael@0 300 hb_font_t *font,
michael@0 301 hb_buffer_t *buffer,
michael@0 302 unsigned int base,
michael@0 303 unsigned int end)
michael@0 304 {
michael@0 305 hb_direction_t horiz_dir = HB_DIRECTION_INVALID;
michael@0 306 hb_glyph_extents_t base_extents;
michael@0 307 if (!font->get_glyph_extents (buffer->info[base].codepoint,
michael@0 308 &base_extents))
michael@0 309 {
michael@0 310 /* If extents don't work, zero marks and go home. */
michael@0 311 zero_mark_advances (buffer, base + 1, end);
michael@0 312 return;
michael@0 313 }
michael@0 314 base_extents.x_bearing += buffer->pos[base].x_offset;
michael@0 315 base_extents.y_bearing += buffer->pos[base].y_offset;
michael@0 316
michael@0 317 unsigned int lig_id = _hb_glyph_info_get_lig_id (&buffer->info[base]);
michael@0 318 unsigned int num_lig_components = _hb_glyph_info_get_lig_num_comps (&buffer->info[base]);
michael@0 319
michael@0 320 hb_position_t x_offset = 0, y_offset = 0;
michael@0 321 if (HB_DIRECTION_IS_FORWARD (buffer->props.direction)) {
michael@0 322 x_offset -= buffer->pos[base].x_advance;
michael@0 323 y_offset -= buffer->pos[base].y_advance;
michael@0 324 }
michael@0 325
michael@0 326 hb_glyph_extents_t component_extents = base_extents;
michael@0 327 unsigned int last_lig_component = (unsigned int) -1;
michael@0 328 unsigned int last_combining_class = 255;
michael@0 329 hb_glyph_extents_t cluster_extents = base_extents; /* Initialization is just to shut gcc up. */
michael@0 330 for (unsigned int i = base + 1; i < end; i++)
michael@0 331 if (_hb_glyph_info_get_modified_combining_class (&buffer->info[i]))
michael@0 332 {
michael@0 333 if (num_lig_components > 1) {
michael@0 334 unsigned int this_lig_id = _hb_glyph_info_get_lig_id (&buffer->info[i]);
michael@0 335 unsigned int this_lig_component = _hb_glyph_info_get_lig_comp (&buffer->info[i]) - 1;
michael@0 336 /* Conditions for attaching to the last component. */
michael@0 337 if (!lig_id || lig_id != this_lig_id || this_lig_component >= num_lig_components)
michael@0 338 this_lig_component = num_lig_components - 1;
michael@0 339 if (last_lig_component != this_lig_component)
michael@0 340 {
michael@0 341 last_lig_component = this_lig_component;
michael@0 342 last_combining_class = 255;
michael@0 343 component_extents = base_extents;
michael@0 344 if (unlikely (horiz_dir == HB_DIRECTION_INVALID)) {
michael@0 345 if (HB_DIRECTION_IS_HORIZONTAL (plan->props.direction))
michael@0 346 horiz_dir = plan->props.direction;
michael@0 347 else
michael@0 348 horiz_dir = hb_script_get_horizontal_direction (plan->props.script);
michael@0 349 }
michael@0 350 if (horiz_dir == HB_DIRECTION_LTR)
michael@0 351 component_extents.x_bearing += (this_lig_component * component_extents.width) / num_lig_components;
michael@0 352 else
michael@0 353 component_extents.x_bearing += ((num_lig_components - 1 - this_lig_component) * component_extents.width) / num_lig_components;
michael@0 354 component_extents.width /= num_lig_components;
michael@0 355 }
michael@0 356 }
michael@0 357
michael@0 358 unsigned int this_combining_class = _hb_glyph_info_get_modified_combining_class (&buffer->info[i]);
michael@0 359 if (last_combining_class != this_combining_class)
michael@0 360 {
michael@0 361 last_combining_class = this_combining_class;
michael@0 362 cluster_extents = component_extents;
michael@0 363 }
michael@0 364
michael@0 365 position_mark (plan, font, buffer, cluster_extents, i, this_combining_class);
michael@0 366
michael@0 367 buffer->pos[i].x_advance = 0;
michael@0 368 buffer->pos[i].y_advance = 0;
michael@0 369 buffer->pos[i].x_offset += x_offset;
michael@0 370 buffer->pos[i].y_offset += y_offset;
michael@0 371
michael@0 372 } else {
michael@0 373 if (HB_DIRECTION_IS_FORWARD (buffer->props.direction)) {
michael@0 374 x_offset -= buffer->pos[i].x_advance;
michael@0 375 y_offset -= buffer->pos[i].y_advance;
michael@0 376 } else {
michael@0 377 x_offset += buffer->pos[i].x_advance;
michael@0 378 y_offset += buffer->pos[i].y_advance;
michael@0 379 }
michael@0 380 }
michael@0 381 }
michael@0 382
michael@0 383 static inline void
michael@0 384 position_cluster (const hb_ot_shape_plan_t *plan,
michael@0 385 hb_font_t *font,
michael@0 386 hb_buffer_t *buffer,
michael@0 387 unsigned int start,
michael@0 388 unsigned int end)
michael@0 389 {
michael@0 390 if (end - start < 2)
michael@0 391 return;
michael@0 392
michael@0 393 /* Find the base glyph */
michael@0 394 for (unsigned int i = start; i < end; i++)
michael@0 395 if (!HB_UNICODE_GENERAL_CATEGORY_IS_MARK (_hb_glyph_info_get_general_category (&buffer->info[i])))
michael@0 396 {
michael@0 397 /* Find mark glyphs */
michael@0 398 unsigned int j;
michael@0 399 for (j = i + 1; j < end; j++)
michael@0 400 if (!HB_UNICODE_GENERAL_CATEGORY_IS_MARK (_hb_glyph_info_get_general_category (&buffer->info[j])))
michael@0 401 break;
michael@0 402
michael@0 403 position_around_base (plan, font, buffer, i, j);
michael@0 404
michael@0 405 i = j - 1;
michael@0 406 }
michael@0 407 }
michael@0 408
michael@0 409 void
michael@0 410 _hb_ot_shape_fallback_position (const hb_ot_shape_plan_t *plan,
michael@0 411 hb_font_t *font,
michael@0 412 hb_buffer_t *buffer)
michael@0 413 {
michael@0 414 unsigned int start = 0;
michael@0 415 unsigned int last_cluster = buffer->info[0].cluster;
michael@0 416 unsigned int count = buffer->len;
michael@0 417 for (unsigned int i = 1; i < count; i++)
michael@0 418 if (buffer->info[i].cluster != last_cluster) {
michael@0 419 position_cluster (plan, font, buffer, start, i);
michael@0 420 start = i;
michael@0 421 last_cluster = buffer->info[i].cluster;
michael@0 422 }
michael@0 423 position_cluster (plan, font, buffer, start, count);
michael@0 424 }
michael@0 425
michael@0 426
michael@0 427 /* Performs old-style TrueType kerning. */
michael@0 428 void
michael@0 429 _hb_ot_shape_fallback_kern (const hb_ot_shape_plan_t *plan,
michael@0 430 hb_font_t *font,
michael@0 431 hb_buffer_t *buffer)
michael@0 432 {
michael@0 433 if (!plan->has_kern) return;
michael@0 434
michael@0 435 unsigned int count = buffer->len;
michael@0 436
michael@0 437 OT::hb_apply_context_t c (1, font, buffer);
michael@0 438 c.set_lookup_mask (plan->kern_mask);
michael@0 439 c.set_lookup_props (OT::LookupFlag::IgnoreMarks);
michael@0 440
michael@0 441 hb_glyph_info_t *info = buffer->info;
michael@0 442 hb_glyph_position_t *pos = buffer->pos;
michael@0 443
michael@0 444 for (unsigned int idx = 0; idx < count;)
michael@0 445 {
michael@0 446 OT::hb_apply_context_t::skipping_forward_iterator_t skippy_iter (&c, idx, 1);
michael@0 447 if (!skippy_iter.next ())
michael@0 448 {
michael@0 449 idx++;
michael@0 450 continue;
michael@0 451 }
michael@0 452
michael@0 453 hb_position_t x_kern, y_kern;
michael@0 454 font->get_glyph_kerning_for_direction (info[idx].codepoint,
michael@0 455 info[skippy_iter.idx].codepoint,
michael@0 456 buffer->props.direction,
michael@0 457 &x_kern, &y_kern);
michael@0 458
michael@0 459 if (x_kern)
michael@0 460 {
michael@0 461 hb_position_t kern1 = x_kern >> 1;
michael@0 462 hb_position_t kern2 = x_kern - kern1;
michael@0 463 pos[idx].x_advance += kern1;
michael@0 464 pos[skippy_iter.idx].x_advance += kern2;
michael@0 465 pos[skippy_iter.idx].x_offset += kern2;
michael@0 466 }
michael@0 467
michael@0 468 if (y_kern)
michael@0 469 {
michael@0 470 hb_position_t kern1 = y_kern >> 1;
michael@0 471 hb_position_t kern2 = y_kern - kern1;
michael@0 472 pos[idx].y_advance += kern1;
michael@0 473 pos[skippy_iter.idx].y_advance += kern2;
michael@0 474 pos[skippy_iter.idx].y_offset += kern2;
michael@0 475 }
michael@0 476
michael@0 477 idx = skippy_iter.idx;
michael@0 478 }
michael@0 479 }

mercurial