From 798e4185bc71b1a63528e6b0af236d4c964ec607 Mon Sep 17 00:00:00 2001 From: Jonathan Kew Date: Tue, 10 Jun 2014 13:10:30 +0100 Subject: [PATCH] When zeroing mark widths for LTR, also adjust offset... ...so that they overstrike preceding glyph. https://github.com/behdad/harfbuzz/pull/43 --- src/hb-ot-shape.cc | 50 ++++++++++++++++++++++++++++++++++++---------- 1 file changed, 39 insertions(+), 11 deletions(-) diff --git a/src/hb-ot-shape.cc b/src/hb-ot-shape.cc index 3080a1d03..42f68ab29 100644 --- a/src/hb-ot-shape.cc +++ b/src/hb-ot-shape.cc @@ -452,26 +452,42 @@ hb_ot_substitute (hb_ot_shape_context_t *c) /* Position */ static inline void -zero_mark_widths_by_unicode (hb_buffer_t *buffer) +adjust_mark_offsets (hb_glyph_position_t *pos) +{ + pos->x_offset -= pos->x_advance; + pos->y_offset -= pos->y_advance; +} + +static inline void +zero_mark_width (hb_glyph_position_t *pos) +{ + pos->x_advance = 0; + pos->y_advance = 0; +} + +static inline void +zero_mark_widths_by_unicode (hb_buffer_t *buffer, bool adjust_offsets) { unsigned int count = buffer->len; for (unsigned int i = 0; i < count; i++) if (_hb_glyph_info_get_general_category (&buffer->info[i]) == HB_UNICODE_GENERAL_CATEGORY_NON_SPACING_MARK) { - buffer->pos[i].x_advance = 0; - buffer->pos[i].y_advance = 0; + if (adjust_offsets) + adjust_mark_offsets (&buffer->pos[i]); + zero_mark_width (&buffer->pos[i]); } } static inline void -zero_mark_widths_by_gdef (hb_buffer_t *buffer) +zero_mark_widths_by_gdef (hb_buffer_t *buffer, bool adjust_offsets) { unsigned int count = buffer->len; for (unsigned int i = 0; i < count; i++) if (_hb_glyph_info_is_mark (&buffer->info[i])) { - buffer->pos[i].x_advance = 0; - buffer->pos[i].y_advance = 0; + if (adjust_offsets) + adjust_mark_offsets (&buffer->pos[i]); + zero_mark_width (&buffer->pos[i]); } } @@ -501,16 +517,28 @@ hb_ot_position_complex (hb_ot_shape_context_t *c) { bool ret = false; unsigned int count = c->buffer->len; + bool has_positioning = hb_ot_layout_has_positioning (c->face); + /* If the font has no GPOS, AND, no fallback positioning will + * happen, AND, direction is forward, then when zeroing mark + * widths, we shift the mark with it, such that the mark + * is positioned hanging over the previous glyph. When + * direction is backward we don't shift and it will end up + * hanging over the next glyph after the final reordering. + * If fallback positinoing happens or GPOS is present, we don't + * care. + */ + bool adjust_offsets_when_zeroing = !(has_positioning || c->plan->shaper->fallback_position || + HB_DIRECTION_IS_BACKWARD (c->buffer->props.direction)); switch (c->plan->shaper->zero_width_marks) { case HB_OT_SHAPE_ZERO_WIDTH_MARKS_BY_GDEF_EARLY: - zero_mark_widths_by_gdef (c->buffer); + zero_mark_widths_by_gdef (c->buffer, adjust_offsets_when_zeroing); break; /* Not currently used for any shaper: case HB_OT_SHAPE_ZERO_WIDTH_MARKS_BY_UNICODE_EARLY: - zero_mark_widths_by_unicode (c->buffer); + zero_mark_widths_by_unicode (c->buffer, adjust_offsets_when_zeroing); break; */ @@ -521,7 +549,7 @@ hb_ot_position_complex (hb_ot_shape_context_t *c) break; } - if (hb_ot_layout_has_positioning (c->face)) + if (has_positioning) { hb_glyph_info_t *info = c->buffer->info; hb_glyph_position_t *pos = c->buffer->pos; @@ -550,11 +578,11 @@ hb_ot_position_complex (hb_ot_shape_context_t *c) switch (c->plan->shaper->zero_width_marks) { case HB_OT_SHAPE_ZERO_WIDTH_MARKS_BY_UNICODE_LATE: - zero_mark_widths_by_unicode (c->buffer); + zero_mark_widths_by_unicode (c->buffer, adjust_offsets_when_zeroing); break; case HB_OT_SHAPE_ZERO_WIDTH_MARKS_BY_GDEF_LATE: - zero_mark_widths_by_gdef (c->buffer); + zero_mark_widths_by_gdef (c->buffer, adjust_offsets_when_zeroing); break; default: