diff --git a/src/hb-ot-shape-fallback.cc b/src/hb-ot-shape-fallback.cc index 593c3335e..449b64e5c 100644 --- a/src/hb-ot-shape-fallback.cc +++ b/src/hb-ot-shape-fallback.cc @@ -430,41 +430,52 @@ _hb_ot_shape_fallback_kern (const hb_ot_shape_plan_t *plan, hb_font_t *font, hb_buffer_t *buffer) { - unsigned int count = buffer->len; hb_mask_t kern_mask = plan->map.get_1_mask (HB_DIRECTION_IS_HORIZONTAL (buffer->props.direction) ? HB_TAG ('k','e','r','n') : HB_TAG ('v','k','r','n')); + if (!kern_mask) return; + + unsigned int count = buffer->len; OT::hb_apply_context_t c (1, font, buffer); c.set_lookup_mask (kern_mask); c.set_lookup_props (OT::LookupFlag::IgnoreMarks); - for (buffer->idx = 0; buffer->idx < count;) + hb_glyph_info_t *info = buffer->info; + hb_glyph_position_t *pos = buffer->pos; + + for (unsigned int idx = 0; idx < count;) { - OT::hb_apply_context_t::skipping_forward_iterator_t skippy_iter (&c, buffer->idx, 1); + OT::hb_apply_context_t::skipping_forward_iterator_t skippy_iter (&c, idx, 1); if (!skippy_iter.next ()) { - buffer->idx++; + idx++; continue; } - hb_position_t x_kern, y_kern, kern1, kern2; - font->get_glyph_kerning_for_direction (buffer->info[buffer->idx].codepoint, - buffer->info[skippy_iter.idx].codepoint, + hb_position_t x_kern, y_kern; + font->get_glyph_kerning_for_direction (info[idx].codepoint, + info[skippy_iter.idx].codepoint, buffer->props.direction, &x_kern, &y_kern); - kern1 = x_kern >> 1; - kern2 = x_kern - kern1; - buffer->pos[buffer->idx].x_advance += kern1; - buffer->pos[skippy_iter.idx].x_advance += kern2; - buffer->pos[skippy_iter.idx].x_offset += kern2; + if (x_kern) + { + hb_position_t kern1 = x_kern >> 1; + hb_position_t kern2 = x_kern - kern1; + pos[idx].x_advance += kern1; + pos[skippy_iter.idx].x_advance += kern2; + pos[skippy_iter.idx].x_offset += kern2; + } - kern1 = y_kern >> 1; - kern2 = y_kern - kern1; - buffer->pos[buffer->idx].y_advance += kern1; - buffer->pos[skippy_iter.idx].y_advance += kern2; - buffer->pos[skippy_iter.idx].y_offset += kern2; + if (y_kern) + { + hb_position_t kern1 = y_kern >> 1; + hb_position_t kern2 = y_kern - kern1; + pos[idx].y_advance += kern1; + pos[skippy_iter.idx].y_advance += kern2; + pos[skippy_iter.idx].y_offset += kern2; + } - buffer->idx = skippy_iter.idx; + idx = skippy_iter.idx; } }