[pango/kill-ft-face: 7/14] fc: Use harfbuzz for font metrics



commit e1d8e597a9530e88305b7d3fe7f78726c82b15e0
Author: Matthias Clasen <mclasen redhat com>
Date:   Fri May 24 16:53:28 2019 +0000

    fc: Use harfbuzz for font metrics
    
    Note that some of the harfbuzz api we use here
    has not landed yet.
    See https://github.com/harfbuzz/harfbuzz/pull/1432

 pango/pangofc-font.c | 146 ++++++++++-----------------------------------------
 1 file changed, 29 insertions(+), 117 deletions(-)
---
diff --git a/pango/pangofc-font.c b/pango/pangofc-font.c
index 6f424640..03c7dfa9 100644
--- a/pango/pangofc-font.c
+++ b/pango/pangofc-font.c
@@ -47,9 +47,6 @@
 #include "pango-impl-utils.h"
 
 #include <harfbuzz/hb-ot.h>
-#include <fontconfig/fcfreetype.h>
-
-#include FT_TRUETYPE_TABLES_H
 
 enum {
   PROP_0,
@@ -63,7 +60,6 @@ struct _PangoFcFontPrivate
 {
   PangoFcDecoder *decoder;
   PangoFcFontKey *key;
-  PangoFcCmapCache *cmap_cache;
 };
 
 static gboolean pango_fc_font_real_has_char  (PangoFcFont *font,
@@ -176,9 +172,6 @@ pango_fc_font_finalize (GObject *object)
   if (priv->decoder)
     _pango_fc_font_set_decoder (fcfont, NULL);
 
-  if (priv->cmap_cache)
-    _pango_fc_cmap_cache_unref (priv->cmap_cache);
-
   G_OBJECT_CLASS (pango_fc_font_parent_class)->finalize (object);
 }
 
@@ -387,135 +380,55 @@ static void
 get_face_metrics (PangoFcFont      *fcfont,
                  PangoFontMetrics *metrics)
 {
-  FT_Face face = PANGO_FC_FONT_LOCK_FACE (fcfont);
+  hb_font_t *hb_font = pango_font_get_hb_font (PANGO_FONT (font));
+  hb_font_extents_t extents;
+
   FcMatrix *fc_matrix;
-  FT_Matrix ft_matrix;
-  TT_OS2 *os2;
   gboolean have_transform = FALSE;
 
-  if (G_UNLIKELY (!face))
-    {
-      metrics->descent = 0;
-      metrics->ascent = PANGO_SCALE * PANGO_UNKNOWN_GLYPH_HEIGHT;
-      metrics->height = metrics->ascent;
-      metrics->underline_thickness = PANGO_SCALE;
-      metrics->underline_position = - PANGO_SCALE;
-      metrics->strikethrough_thickness = PANGO_SCALE;
-      metrics->strikethrough_position = PANGO_SCALE * (PANGO_UNKNOWN_GLYPH_HEIGHT/2);
-      return;
-    }
+  hb_font_get_extents_for_direction (hb_font, HB_DIRECTION_LTR, &extents);
 
   if  (FcPatternGetMatrix (fcfont->font_pattern,
                           FC_MATRIX, 0, &fc_matrix) == FcResultMatch)
     {
-      ft_matrix.xx = 0x10000L * fc_matrix->xx;
-      ft_matrix.yy = 0x10000L * fc_matrix->yy;
-      ft_matrix.xy = 0x10000L * fc_matrix->xy;
-      ft_matrix.yx = 0x10000L * fc_matrix->yx;
-
-      have_transform = (ft_matrix.xx != 0x10000 || ft_matrix.xy != 0 ||
-                       ft_matrix.yx != 0 || ft_matrix.yy != 0x10000);
+      have_transform = (fc_matrix->xx != 1 || fc_matrix->xy != 0 ||
+                       fc_matrix->yx != 0 || fc_matrix->yy != 1);
     }
 
   if (have_transform)
     {
-      FT_Vector        vector;
-
-      vector.x = 0;
-      vector.y = face->size->metrics.descender;
-      FT_Vector_Transform (&vector, &ft_matrix);
-      metrics->descent = - PANGO_UNITS_26_6 (vector.y);
-
-      vector.x = 0;
-      vector.y = face->size->metrics.ascender;
-      FT_Vector_Transform (&vector, &ft_matrix);
-      metrics->ascent = PANGO_UNITS_26_6 (vector.y);
-
-      vector.x = 0;
-      vector.y = face->size->metrics.height;
-      FT_Vector_Transform (&vector, &ft_matrix);
-      metrics->height = PANGO_UNITS_26_6 (vector.y);
-    }
-  else if (fcfont->is_hinted ||
-          (face->face_flags & FT_FACE_FLAG_SCALABLE) == 0)
-    {
-      metrics->descent = - PANGO_UNITS_26_6 (face->size->metrics.descender);
-      metrics->ascent = PANGO_UNITS_26_6 (face->size->metrics.ascender);
-      metrics->height = PANGO_UNITS_26_6 (face->size->metrics.height);
+      metrics->descent = extents.descender * fc_matrix->yy;
+      metrics->ascent = extents.ascender * fc_matrix->yy;
+      metrics->height = (extents.ascender + extents.descender + extents.line_gap) * fc_matrix->yy;
     }
   else
     {
-      FT_Fixed ascender, descender, height;
-
-      descender = FT_MulFix (face->descender, face->size->metrics.y_scale);
-      metrics->descent = - PANGO_UNITS_26_6 (descender);
-
-      ascender = FT_MulFix (face->ascender, face->size->metrics.y_scale);
-      metrics->ascent = PANGO_UNITS_26_6 (ascender);
-
-      height = FT_MulFix (face->height, face->size->metrics.y_scale);
-      metrics->height = PANGO_UNITS_26_6 (height);
+      metrics->descent = - extents.decender;
+      metrics->ascent = extents.ascender;
+      metrics->height = extents.ascender + extents.descender + extents.line_gap;
     }
 
-  metrics->underline_thickness = 0;
-  metrics->underline_position = 0;
+  metrics->underline_thickness = PANGO_SCALE;
+  metrics->underline_position = - PANGO_SCALE;
+  metrics->strikethrough_thickness = PANGO_SCALE;
+  metrics->strikethrough_position = metrics->ascent / 2;
 
-  {
-    FT_Fixed ft_thickness, ft_position;
+  /* FIXME: use the right hb version */
+#if HB_VERSION_ATLEAST (2,5,2)
+  hb_position_t position;
 
-    ft_thickness = FT_MulFix (face->underline_thickness, face->size->metrics.y_scale);
-    metrics->underline_thickness = PANGO_UNITS_26_6 (ft_thickness);
+  if (hb_ot_metrics_get_position (hb_font, HB_OT_METRICS_UNDERLINE_SIZE, &position))
+    metrics->underline_thickness = position;
 
-    ft_position = FT_MulFix (face->underline_position, face->size->metrics.y_scale);
-    metrics->underline_position = PANGO_UNITS_26_6 (ft_position);
-  }
+  if (hb_ot_metrics_get_position (hb_font, HB_OT_METRICS_UNDERLINE_OFFSET, &position))
+    metrics->underline_position = position;
 
-  if (metrics->underline_thickness == 0 || metrics->underline_position == 0)
-    {
-      metrics->underline_thickness = (PANGO_SCALE * face->size->metrics.y_ppem) / 14;
-      metrics->underline_position = - metrics->underline_thickness;
-    }
-
-
-  metrics->strikethrough_thickness = 0;
-  metrics->strikethrough_position = 0;
-
-  os2 = FT_Get_Sfnt_Table (face, ft_sfnt_os2);
-  if (os2 && os2->version != 0xFFFF)
-    {
-      FT_Fixed ft_thickness, ft_position;
+  if (hb_ot_metrics_get_position (hb_font, HB_OT_METRICS_STRIKEOUT_SIZE, &position))
+    metrics->strikethrough_thickness = position;
 
-      ft_thickness = FT_MulFix (os2->yStrikeoutSize, face->size->metrics.y_scale);
-      metrics->strikethrough_thickness = PANGO_UNITS_26_6 (ft_thickness);
-
-      ft_position = FT_MulFix (os2->yStrikeoutPosition, face->size->metrics.y_scale);
-      metrics->strikethrough_position = PANGO_UNITS_26_6 (ft_position);
-    }
-
-  if (metrics->strikethrough_thickness == 0 || metrics->strikethrough_position == 0)
-    {
-      metrics->strikethrough_thickness = metrics->underline_thickness;
-      metrics->strikethrough_position = (PANGO_SCALE * face->size->metrics.y_ppem) / 4;
-    }
-
-
-  /* If hinting is on for this font, quantize the underline and strikethrough position
-   * to integer values.
-   */
-  if (fcfont->is_hinted)
-    {
-      pango_quantize_line_geometry (&metrics->underline_thickness,
-                                   &metrics->underline_position);
-      pango_quantize_line_geometry (&metrics->strikethrough_thickness,
-                                   &metrics->strikethrough_position);
-
-      /* Quantizing may have pushed underline_position to 0.  Not good */
-      if (metrics->underline_position == 0)
-       metrics->underline_position = - metrics->underline_thickness;
-    }
-
-
-  PANGO_FC_FONT_UNLOCK_FACE (fcfont);
+  if (hb_ot_metrics_get_position (hb_font, HB_OT_METRICS_STRIKEOUT_OFFSET, &position))
+    metrics->strikethrough_position = position;
+#endif
 }
 
 PangoFontMetrics *
@@ -663,7 +576,7 @@ static guint
 pango_fc_font_real_get_glyph (PangoFcFont *font,
                              gunichar     wc)
 {
-  hb_font_t *hb_font = pango_font_get_hb_font (font);
+  hb_font_t *hb_font = pango_font_get_hb_font (PANGO_FONT (font));
   hb_codepoint_t glyph = PANGO_GET_UNKNOWN_GLYPH (wc);
 
   hb_font_get_nominal_glyph (hb_font, wc, &glyph);
@@ -818,7 +731,6 @@ void
 pango_fc_font_kern_glyphs (PangoFcFont      *font,
                           PangoGlyphString *glyphs)
 {
-  FT_Face face;
   FT_Error error;
   FT_Vector kerning;
   int i;


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