From bf03d7e962ec831d720efcfa33e5397bbbaa1ec4 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Mon, 21 Mar 2022 21:27:31 -0600 Subject: [PATCH] [ot-font] Use ascent+descent for fallback vertical advance This matches what FreeType does. Part of fixing https://github.com/harfbuzz/harfbuzz/issues/537 --- src/hb-ot-font.cc | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/src/hb-ot-font.cc b/src/hb-ot-font.cc index e00480442..974cc6aab 100644 --- a/src/hb-ot-font.cc +++ b/src/hb-ot-font.cc @@ -131,11 +131,25 @@ hb_ot_get_glyph_v_advances (hb_font_t* font, void* font_data, const hb_ot_face_t *ot_face = (const hb_ot_face_t *) font_data; const OT::vmtx_accelerator_t &vmtx = *ot_face->vmtx; - for (unsigned int i = 0; i < count; i++) + if (vmtx.has_data ()) + for (unsigned int i = 0; i < count; i++) + { + *first_advance = font->em_scale_y (-(int) vmtx.get_advance (*first_glyph, font)); + first_glyph = &StructAtOffsetUnaligned (first_glyph, glyph_stride); + first_advance = &StructAtOffsetUnaligned (first_advance, advance_stride); + } + else { - *first_advance = font->em_scale_y (-(int) vmtx.get_advance (*first_glyph, font)); - first_glyph = &StructAtOffsetUnaligned (first_glyph, glyph_stride); - first_advance = &StructAtOffsetUnaligned (first_advance, advance_stride); + hb_font_extents_t font_extents; + font->get_h_extents_with_fallback (&font_extents); + hb_position_t advance = -(font_extents.ascender - font_extents.descender); + + for (unsigned int i = 0; i < count; i++) + { + *first_advance = advance; + first_glyph = &StructAtOffsetUnaligned (first_glyph, glyph_stride); + first_advance = &StructAtOffsetUnaligned (first_advance, advance_stride); + } } } #endif