[ot-font] Vertically center glyph in vertical writing fallback

Fixes https://github.com/harfbuzz/harfbuzz/issues/537
This commit is contained in:
Behdad Esfahbod 2022-03-21 21:40:07 -06:00
parent bf03d7e962
commit 1449498e1d
1 changed files with 14 additions and 5 deletions

View File

@ -175,8 +175,9 @@ hb_ot_get_glyph_v_origin (hb_font_t *font,
} }
hb_glyph_extents_t extents = {0}; hb_glyph_extents_t extents = {0};
if (ot_face->vmtx->has_data () && if (ot_face->glyf->get_extents (font, glyph, &extents))
ot_face->glyf->get_extents (font, glyph, &extents)) {
if (ot_face->vmtx->has_data ())
{ {
const OT::vmtx_accelerator_t &vmtx = *ot_face->vmtx; const OT::vmtx_accelerator_t &vmtx = *ot_face->vmtx;
hb_position_t tsb = vmtx.get_side_bearing (font, glyph); hb_position_t tsb = vmtx.get_side_bearing (font, glyph);
@ -184,6 +185,14 @@ hb_ot_get_glyph_v_origin (hb_font_t *font,
return true; return true;
} }
hb_font_extents_t font_extents;
font->get_h_extents_with_fallback (&font_extents);
hb_position_t advance = font_extents.ascender - font_extents.descender;
int diff = advance - -extents.height;
*y = extents.y_bearing + (diff >> 1);
return true;
}
hb_font_extents_t font_extents; hb_font_extents_t font_extents;
font->get_h_extents_with_fallback (&font_extents); font->get_h_extents_with_fallback (&font_extents);
*y = font_extents.ascender; *y = font_extents.ascender;