From ff697debd8e55d8858a2f199ae06f7a9f33a5991 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Sun, 19 Dec 2021 07:25:37 -0700 Subject: [PATCH] [GPOS] Apply font synthetic slant Part of fixing https://github.com/harfbuzz/harfbuzz/issues/3196 --- src/hb-font.cc | 1 + src/hb-font.hh | 2 ++ src/hb-ot-layout-gpos-table.hh | 11 +++++++++-- 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/hb-font.cc b/src/hb-font.cc index dd1a31508..1c6a41011 100644 --- a/src/hb-font.cc +++ b/src/hb-font.cc @@ -1478,6 +1478,7 @@ DEFINE_NULL_INSTANCE (hb_font_t) = 1000, /* x_scale */ 1000, /* y_scale */ 0., /* slant */ + 0., /* slant_xy; */ 1<<16, /* x_mult */ 1<<16, /* y_mult */ diff --git a/src/hb-font.hh b/src/hb-font.hh index 248d85deb..0d73589e8 100644 --- a/src/hb-font.hh +++ b/src/hb-font.hh @@ -110,6 +110,7 @@ struct hb_font_t int32_t x_scale; int32_t y_scale; float slant; + float slant_xy; int64_t x_mult; int64_t y_mult; @@ -618,6 +619,7 @@ struct hb_font_t signed upem = face->get_upem (); x_mult = ((int64_t) x_scale << 16) / upem; y_mult = ((int64_t) y_scale << 16) / upem; + slant_xy = y_scale ? slant * x_scale / y_scale : 0.f; } hb_position_t em_mult (int16_t v, int64_t mult) diff --git a/src/hb-ot-layout-gpos-table.hh b/src/hb-ot-layout-gpos-table.hh index 6db3e0894..bda6f02b8 100644 --- a/src/hb-ot-layout-gpos-table.hh +++ b/src/hb-ot-layout-gpos-table.hh @@ -2951,7 +2951,7 @@ GPOS::position_finish_advances (hb_font_t *font HB_UNUSED, hb_buffer_t *buffer H } void -GPOS::position_finish_offsets (hb_font_t *font HB_UNUSED, hb_buffer_t *buffer) +GPOS::position_finish_offsets (hb_font_t *font, hb_buffer_t *buffer) { _hb_buffer_assert_gsubgpos_vars (buffer); @@ -2961,8 +2961,15 @@ GPOS::position_finish_offsets (hb_font_t *font HB_UNUSED, hb_buffer_t *buffer) /* Handle attachments */ if (buffer->scratch_flags & HB_BUFFER_SCRATCH_FLAG_HAS_GPOS_ATTACHMENT) - for (unsigned int i = 0; i < len; i++) + for (unsigned i = 0; i < len; i++) propagate_attachment_offsets (pos, len, i, direction); + + if (unlikely (font->slant)) + { + for (unsigned i = 0; i < len; i++) + if (unlikely (pos[i].y_offset)) + pos[i].x_offset += _hb_roundf (font->slant_xy * pos[i].y_offset); + } }