[pango/kill-ft-face: 9/12] fc: Use harfbuzz for glyph extents



commit 97f04d7de822a17952136be0f2b358df7b20bd73
Author: Matthias Clasen <mclasen redhat com>
Date:   Fri May 24 17:15:19 2019 +0000

    fc: Use harfbuzz for glyph extents
    
    Harfbuzz has the api, no need to use freetype.

 pango/pangofc-font.c | 91 ++++++++++++++++------------------------------------
 1 file changed, 28 insertions(+), 63 deletions(-)
---
diff --git a/pango/pangofc-font.c b/pango/pangofc-font.c
index 081cfd7e..c7fd066a 100644
--- a/pango/pangofc-font.c
+++ b/pango/pangofc-font.c
@@ -799,23 +799,6 @@ _pango_fc_font_set_font_key (PangoFcFont    *fcfont,
   priv->key = key;
 }
 
-static FT_Glyph_Metrics *
-get_per_char (FT_Face      face,
-             FT_Int32     load_flags,
-             PangoGlyph   glyph)
-{
-  FT_Error error;
-  FT_Glyph_Metrics *result;
-
-  error = FT_Load_Glyph (face, glyph, load_flags);
-  if (error == FT_Err_Ok)
-    result = &face->glyph->metrics;
-  else
-    result = NULL;
-
-  return result;
-}
-
 /**
  * pango_fc_font_get_raw_extents:
  * @fcfont: a #PangoFcFont
@@ -845,76 +828,58 @@ pango_fc_font_get_raw_extents (PangoFcFont    *fcfont,
                               PangoRectangle *ink_rect,
                               PangoRectangle *logical_rect)
 {
-  FT_Glyph_Metrics *gm;
-  FT_Face face;
-
   g_return_if_fail (PANGO_IS_FC_FONT (fcfont));
 
-  face = PANGO_FC_FONT_LOCK_FACE (fcfont);
-  if (G_UNLIKELY (!face))
-    {
-      /* Get generic unknown-glyph extents. */
-      pango_font_get_glyph_extents (NULL, glyph, ink_rect, logical_rect);
-      return;
-    }
-
   if (glyph == PANGO_GLYPH_EMPTY)
-    gm = NULL;
-  else
-    gm = get_per_char (face, load_flags, glyph);
-
-  if (gm)
     {
       if (ink_rect)
        {
-         ink_rect->x = PANGO_UNITS_26_6 (gm->horiBearingX);
-         ink_rect->width = PANGO_UNITS_26_6 (gm->width);
-         ink_rect->y = -PANGO_UNITS_26_6 (gm->horiBearingY);
-         ink_rect->height = PANGO_UNITS_26_6 (gm->height);
+         ink_rect->x = 0;
+         ink_rect->width = 0;
+         ink_rect->y = 0;
+         ink_rect->height = 0;
        }
 
       if (logical_rect)
        {
          logical_rect->x = 0;
-         logical_rect->width = PANGO_UNITS_26_6 (gm->horiAdvance);
-         if (fcfont->is_hinted ||
-             (face->face_flags & FT_FACE_FLAG_SCALABLE) == 0)
-           {
-             logical_rect->y = - PANGO_UNITS_26_6 (face->size->metrics.ascender);
-             logical_rect->height = PANGO_UNITS_26_6 (face->size->metrics.ascender - 
face->size->metrics.descender);
-           }
-         else
-           {
-             FT_Fixed ascender, descender;
-
-             ascender = FT_MulFix (face->ascender, face->size->metrics.y_scale);
-             descender = FT_MulFix (face->descender, face->size->metrics.y_scale);
-
-             logical_rect->y = - PANGO_UNITS_26_6 (ascender);
-             logical_rect->height = PANGO_UNITS_26_6 (ascender - descender);
-           }
+         logical_rect->width = 0;
+         logical_rect->y = 0;
+         logical_rect->height = 0;
        }
     }
   else
     {
+      hb_font_t *hb_font = pango_font_get_hb_font (PANGO_FONT (fcfont));
+      hb_glyph_extents_t extents;
+      hb_font_extents_t font_extents;
+
+      hb_font_get_glyph_extents (hb_font, glyph, &extents);
+      hb_font_get_extents_for_direction (hb_font, HB_DIRECTION_LTR, &font_extents);
+
       if (ink_rect)
        {
-         ink_rect->x = 0;
-         ink_rect->width = 0;
-         ink_rect->y = 0;
-         ink_rect->height = 0;
+         ink_rect->x = extents.x_bearing;
+         ink_rect->width = extents.width;
+         ink_rect->y = -extents.y_bearing;
+         ink_rect->height = extents.height;
        }
 
       if (logical_rect)
        {
+          hb_position_t x, y;
+
+          hb_font_get_glyph_advance_for_direction (hb_font,
+                                                   glyph,
+                                                   HB_DIRECTION_LTR,
+                                                   &x, &y);
+
          logical_rect->x = 0;
-         logical_rect->width = 0;
-         logical_rect->y = 0;
-         logical_rect->height = 0;
+         logical_rect->width = x;
+         logical_rect->y = - font_extents.ascender;
+         logical_rect->height = font_extents.ascender - font_extents.descender;
        }
     }
-
-  PANGO_FC_FONT_UNLOCK_FACE (fcfont);
 }
 
 static void


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]