Optimize fallback kerning
Patch from Jonathan Kew. "These changes seem to yield a small but just-about-measurable improvement with old fonts that lack GPOS kerning."
This commit is contained in:
parent
133eeba6a3
commit
6b03e3c724
|
@ -430,41 +430,52 @@ _hb_ot_shape_fallback_kern (const hb_ot_shape_plan_t *plan,
|
||||||
hb_font_t *font,
|
hb_font_t *font,
|
||||||
hb_buffer_t *buffer)
|
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_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'));
|
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);
|
OT::hb_apply_context_t c (1, font, buffer);
|
||||||
c.set_lookup_mask (kern_mask);
|
c.set_lookup_mask (kern_mask);
|
||||||
c.set_lookup_props (OT::LookupFlag::IgnoreMarks);
|
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 ())
|
if (!skippy_iter.next ())
|
||||||
{
|
{
|
||||||
buffer->idx++;
|
idx++;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
hb_position_t x_kern, y_kern, kern1, kern2;
|
hb_position_t x_kern, y_kern;
|
||||||
font->get_glyph_kerning_for_direction (buffer->info[buffer->idx].codepoint,
|
font->get_glyph_kerning_for_direction (info[idx].codepoint,
|
||||||
buffer->info[skippy_iter.idx].codepoint,
|
info[skippy_iter.idx].codepoint,
|
||||||
buffer->props.direction,
|
buffer->props.direction,
|
||||||
&x_kern, &y_kern);
|
&x_kern, &y_kern);
|
||||||
|
|
||||||
kern1 = x_kern >> 1;
|
if (x_kern)
|
||||||
kern2 = x_kern - kern1;
|
{
|
||||||
buffer->pos[buffer->idx].x_advance += kern1;
|
hb_position_t kern1 = x_kern >> 1;
|
||||||
buffer->pos[skippy_iter.idx].x_advance += kern2;
|
hb_position_t kern2 = x_kern - kern1;
|
||||||
buffer->pos[skippy_iter.idx].x_offset += kern2;
|
pos[idx].x_advance += kern1;
|
||||||
|
pos[skippy_iter.idx].x_advance += kern2;
|
||||||
|
pos[skippy_iter.idx].x_offset += kern2;
|
||||||
|
}
|
||||||
|
|
||||||
kern1 = y_kern >> 1;
|
if (y_kern)
|
||||||
kern2 = y_kern - kern1;
|
{
|
||||||
buffer->pos[buffer->idx].y_advance += kern1;
|
hb_position_t kern1 = y_kern >> 1;
|
||||||
buffer->pos[skippy_iter.idx].y_advance += kern2;
|
hb_position_t kern2 = y_kern - kern1;
|
||||||
buffer->pos[skippy_iter.idx].y_offset += kern2;
|
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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue