From 4b8de1ea804b225e8357422d0686aad76b05ccf3 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Mon, 6 Jun 2016 23:08:54 -0700 Subject: [PATCH] Round, not truncate, when scaling values Fixes https://github.com/behdad/harfbuzz/issues/255 --- src/hb-font-private.hh | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/hb-font-private.hh b/src/hb-font-private.hh index 8da40a992..0b7557794 100644 --- a/src/hb-font-private.hh +++ b/src/hb-font-private.hh @@ -505,7 +505,13 @@ struct hb_font_t { } private: - inline hb_position_t em_scale (int16_t v, int scale) { return (hb_position_t) (v * (int64_t) scale / face->get_upem ()); } + inline hb_position_t em_scale (int16_t v, int scale) + { + int upem = face->get_upem (); + int64_t scaled = v * (int64_t) scale; + scaled += scaled >= 0 ? upem/2 : -upem/2; /* Round. */ + return (hb_position_t) (scaled / upem); + } }; #define HB_SHAPER_DATA_CREATE_FUNC_EXTRA_ARGS