From b5e9f2cb2b9896bf84bb03f8993aa6c728d05770 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Thu, 10 Oct 2024 14:15:50 -0600 Subject: [PATCH] [coretext-font] Implement get_glyph_extents --- src/hb-coretext-font.cc | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/src/hb-coretext-font.cc b/src/hb-coretext-font.cc index 5cb095162..c75f1eb72 100644 --- a/src/hb-coretext-font.cc +++ b/src/hb-coretext-font.cc @@ -149,8 +149,22 @@ hb_coretext_get_glyph_extents (hb_font_t *font, hb_glyph_extents_t *extents, void *user_data HB_UNUSED) { - // TODO - return false; + CTFontRef ct_font = (CTFontRef) font_data; + + CGFloat ct_font_size = CTFontGetSize (ct_font); + CGFloat x_mult = (CGFloat) font->x_scale / ct_font_size; + CGFloat y_mult = (CGFloat) font->y_scale / ct_font_size; + + CGGlyph glyphs[1] = { glyph }; + CGRect bounds = ::CTFontGetBoundingRectsForGlyphs(ct_font, + kCTFontDefaultOrientation, glyphs, NULL, 1); + + extents->x_bearing = round (bounds.origin.x * x_mult); + extents->y_bearing = round (bounds.origin.y * y_mult); + extents->width = round (bounds.size.width * x_mult); + extents->height = round (bounds.size.height * y_mult); + + return true; } static hb_bool_t