From 755b44cce6dc23376a3cf0212893609231fa4967 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Fri, 18 Oct 2013 11:17:42 +0200 Subject: [PATCH] [ft] Round metrics instead of truncate Lohit-Punjabi has a upem of 769! We were losing one unit in our code, and FreeType is losing another one... Test with U+0A06. Has an advance of 854 in the font. We were producing 852. Now we do 853, which is what FreeType is telling us. --- src/hb-ft.cc | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/hb-ft.cc b/src/hb-ft.cc index ff1e187b3..113b0eb85 100644 --- a/src/hb-ft.cc +++ b/src/hb-ft.cc @@ -94,7 +94,7 @@ hb_ft_get_glyph_h_advance (hb_font_t *font HB_UNUSED, if (unlikely (FT_Get_Advance (ft_face, glyph, load_flags, &v))) return 0; - return v >> 10; + return (v + (1<<9)) >> 10; } static hb_position_t @@ -112,7 +112,7 @@ hb_ft_get_glyph_v_advance (hb_font_t *font HB_UNUSED, /* Note: FreeType's vertical metrics grows downward while other FreeType coordinates * have a Y growing upward. Hence the extra negation. */ - return -v >> 10; + return (-v + (1<<9)) >> 10; } static hb_bool_t @@ -418,8 +418,8 @@ hb_ft_font_create (FT_Face ft_face, _hb_ft_get_font_funcs (), ft_face, (hb_destroy_func_t) _do_nothing); hb_font_set_scale (font, - ((uint64_t) ft_face->size->metrics.x_scale * (uint64_t) ft_face->units_per_EM) >> 16, - ((uint64_t) ft_face->size->metrics.y_scale * (uint64_t) ft_face->units_per_EM) >> 16); + ((uint64_t) ft_face->size->metrics.x_scale * (uint64_t) ft_face->units_per_EM + (1<<15)) >> 16, + ((uint64_t) ft_face->size->metrics.y_scale * (uint64_t) ft_face->units_per_EM + (1<<15)) >> 16); hb_font_set_ppem (font, ft_face->size->metrics.x_ppem, ft_face->size->metrics.y_ppem);