diff --git a/src/hb-font.hh b/src/hb-font.hh index 5ce3bd414..7c1c4c441 100644 --- a/src/hb-font.hh +++ b/src/hb-font.hh @@ -317,16 +317,34 @@ struct hb_font_t hb_position_t get_glyph_h_advance (hb_codepoint_t glyph) { - return klass->get.f.glyph_h_advance (this, user_data, - glyph, - !klass->user_data ? nullptr : klass->user_data->glyph_h_advance); + hb_position_t advance = klass->get.f.glyph_h_advance (this, user_data, + glyph, + !klass->user_data ? nullptr : klass->user_data->glyph_h_advance); + + if (x_strength && !embolden_in_place) + { + /* Emboldening. */ + hb_position_t x_strength = x_scale >= 0 ? x_strength : -x_strength; + advance += advance ? x_strength : 0; + } + + return advance; } hb_position_t get_glyph_v_advance (hb_codepoint_t glyph) { - return klass->get.f.glyph_v_advance (this, user_data, - glyph, - !klass->user_data ? nullptr : klass->user_data->glyph_v_advance); + hb_position_t advance = klass->get.f.glyph_v_advance (this, user_data, + glyph, + !klass->user_data ? nullptr : klass->user_data->glyph_v_advance); + + if (y_strength && !embolden_in_place) + { + /* Emboldening. */ + hb_position_t y_strength = y_scale >= 0 ? y_strength : -y_strength; + advance += advance ? y_strength : 0; + } + + return advance; } void get_glyph_h_advances (unsigned int count, @@ -340,6 +358,17 @@ struct hb_font_t first_glyph, glyph_stride, first_advance, advance_stride, !klass->user_data ? nullptr : klass->user_data->glyph_h_advances); + + if (x_strength && !embolden_in_place) + { + /* Emboldening. */ + hb_position_t x_strength = x_scale >= 0 ? x_strength : -x_strength; + for (unsigned int i = 0; i < count; i++) + { + *first_advance += *first_advance ? x_strength : 0; + first_advance = &StructAtOffsetUnaligned (first_advance, advance_stride); + } + } } void get_glyph_v_advances (unsigned int count, @@ -353,6 +382,17 @@ struct hb_font_t first_glyph, glyph_stride, first_advance, advance_stride, !klass->user_data ? nullptr : klass->user_data->glyph_v_advances); + + if (y_strength && !embolden_in_place) + { + /* Emboldening. */ + hb_position_t y_strength = y_scale >= 0 ? y_strength : -y_strength; + for (unsigned int i = 0; i < count; i++) + { + *first_advance += *first_advance ? y_strength : 0; + first_advance = &StructAtOffsetUnaligned (first_advance, advance_stride); + } + } } hb_bool_t get_glyph_h_origin (hb_codepoint_t glyph, diff --git a/src/hb-ft.cc b/src/hb-ft.cc index 47b0484e0..0f497d770 100644 --- a/src/hb-ft.cc +++ b/src/hb-ft.cc @@ -477,7 +477,6 @@ hb_ft_get_glyph_h_advances (hb_font_t* font, void* font_data, const hb_ft_font_t *ft_font = (const hb_ft_font_t *) font_data; _hb_ft_hb_font_check_changed (font, ft_font); - hb_position_t *orig_first_advance = first_advance; hb_lock_t lock (ft_font->lock); FT_Face ft_face = ft_font->ft_face; int load_flags = ft_font->load_flags; @@ -518,18 +517,6 @@ hb_ft_get_glyph_h_advances (hb_font_t* font, void* font_data, first_glyph = &StructAtOffsetUnaligned (first_glyph, glyph_stride); first_advance = &StructAtOffsetUnaligned (first_advance, advance_stride); } - - if (font->x_strength && !font->embolden_in_place) - { - /* Emboldening. */ - hb_position_t x_strength = font->x_scale >= 0 ? font->x_strength : -font->x_strength; - first_advance = orig_first_advance; - for (unsigned int i = 0; i < count; i++) - { - *first_advance += *first_advance ? x_strength : 0; - first_advance = &StructAtOffsetUnaligned (first_advance, advance_stride); - } - } } #ifndef HB_NO_VERTICAL @@ -562,15 +549,11 @@ hb_ft_get_glyph_v_advance (hb_font_t *font, if (unlikely (FT_Get_Advance (ft_font->ft_face, glyph, ft_font->load_flags | FT_LOAD_VERTICAL_LAYOUT, &v))) return 0; - v = (int) (y_mult * v); - /* Note: FreeType's vertical metrics grows downward while other FreeType coordinates * have a Y growing upward. Hence the extra negation. */ + v = ((-v + (1<<9)) >> 10); - hb_position_t y_strength = font->y_scale >= 0 ? font->y_strength : -font->y_strength; - v = ((-v + (1<<9)) >> 10) + (font->embolden_in_place ? 0 : y_strength); - - return v; + return (hb_position_t) (y_mult * v); } #endif diff --git a/src/hb-ot-font.cc b/src/hb-ot-font.cc index 78c8a6236..a94189b5f 100644 --- a/src/hb-ot-font.cc +++ b/src/hb-ot-font.cc @@ -205,8 +205,6 @@ hb_ot_get_glyph_h_advances (hb_font_t* font, void* font_data, const hb_ot_face_t *ot_face = ot_font->ot_face; const OT::hmtx_accelerator_t &hmtx = *ot_face->hmtx; - hb_position_t *orig_first_advance = first_advance; - #if !defined(HB_NO_VAR) && !defined(HB_NO_OT_FONT_ADVANCE_CACHE) const OT::HVAR &HVAR = *hmtx.var_table; const OT::ItemVariationStore &varStore = &HVAR + HVAR.varStore; @@ -280,18 +278,6 @@ hb_ot_get_glyph_h_advances (hb_font_t* font, void* font_data, #if !defined(HB_NO_VAR) && !defined(HB_NO_OT_FONT_ADVANCE_CACHE) OT::ItemVariationStore::destroy_cache (varStore_cache); #endif - - if (font->x_strength && !font->embolden_in_place) - { - /* Emboldening. */ - hb_position_t x_strength = font->x_scale >= 0 ? font->x_strength : -font->x_strength; - first_advance = orig_first_advance; - for (unsigned int i = 0; i < count; i++) - { - *first_advance += *first_advance ? x_strength : 0; - first_advance = &StructAtOffsetUnaligned (first_advance, advance_stride); - } - } } #ifndef HB_NO_VERTICAL @@ -308,8 +294,6 @@ hb_ot_get_glyph_v_advances (hb_font_t* font, void* font_data, const hb_ot_face_t *ot_face = ot_font->ot_face; const OT::vmtx_accelerator_t &vmtx = *ot_face->vmtx; - hb_position_t *orig_first_advance = first_advance; - if (vmtx.has_data ()) { #if !defined(HB_NO_VAR) && !defined(HB_NO_OT_FONT_ADVANCE_CACHE) @@ -344,18 +328,6 @@ hb_ot_get_glyph_v_advances (hb_font_t* font, void* font_data, first_advance = &StructAtOffsetUnaligned (first_advance, advance_stride); } } - - if (font->y_strength && !font->embolden_in_place) - { - /* Emboldening. */ - hb_position_t y_strength = font->y_scale >= 0 ? font->y_strength : -font->y_strength; - first_advance = orig_first_advance; - for (unsigned int i = 0; i < count; i++) - { - *first_advance += *first_advance ? y_strength : 0; - first_advance = &StructAtOffsetUnaligned (first_advance, advance_stride); - } - } } #endif