[pango/kill-ft-face: 3/15] fc: Implement create_hb_font



commit ceea8a00ce38fec1c0879d61a79911abc5788374
Author: Matthias Clasen <mclasen redhat com>
Date:   Sat Jul 13 00:00:10 2019 -0400

    fc: Implement create_hb_font

 pango/pangofc-font.c    | 39 +++++++++++++++++++++++++++++++++++++++
 pango/pangofc-fontmap.c | 25 +++++++++++++++++++++++++
 pango/pangofc-fontmap.h |  6 +++++-
 3 files changed, 69 insertions(+), 1 deletion(-)
---
diff --git a/pango/pangofc-font.c b/pango/pangofc-font.c
index 870fd935..437c7709 100644
--- a/pango/pangofc-font.c
+++ b/pango/pangofc-font.c
@@ -93,6 +93,7 @@ static void                  pango_fc_font_get_features (PangoFont        *font,
                                                          hb_feature_t     *features,
                                                          guint             len,
                                                          guint            *num_features);
+static hb_font_t *           pango_fc_font_create_hb_font (PangoFont        *font);
 
 #define PANGO_FC_FONT_LOCK_FACE(font)  (PANGO_FC_FONT_GET_CLASS (font)->lock_face (font))
 #define PANGO_FC_FONT_UNLOCK_FACE(font)        (PANGO_FC_FONT_GET_CLASS (font)->unlock_face (font))
@@ -120,6 +121,8 @@ pango_fc_font_class_init (PangoFcFontClass *class)
   font_class->get_metrics = pango_fc_font_get_metrics;
   font_class->get_font_map = pango_fc_font_get_font_map;
   font_class->get_features = pango_fc_font_get_features;
+  font_class->create_hb_font = pango_fc_font_create_hb_font;
+  font_class->get_features = pango_fc_font_get_features;
 
   g_object_class_install_property (object_class, PROP_PATTERN,
                                   g_param_spec_pointer ("pattern",
@@ -1039,6 +1042,42 @@ pango_fc_font_get_raw_extents (PangoFcFont    *fcfont,
   PANGO_FC_FONT_UNLOCK_FACE (fcfont);
 }
 
+static void
+pango_fc_font_get_features (PangoFont    *font,
+                            hb_feature_t *features,
+                            guint         len,
+                            guint        *num_features)
+{
+  /* Setup features from fontconfig pattern. */
+  PangoFcFont *fc_font = PANGO_FC_FONT (font);
+  if (fc_font->font_pattern)
+    {
+      char *s;
+      while (*num_features < len &&
+             FcResultMatch == FcPatternGetString (fc_font->font_pattern,
+                                                  PANGO_FC_FONT_FEATURES,
+                                                  *num_features,
+                                                  (FcChar8 **) &s))
+        {
+          gboolean ret = hb_feature_from_string (s, -1, &features[*num_features]);
+          features[*num_features].start = 0;
+          features[*num_features].end   = (unsigned int) -1;
+          if (ret)
+            (*num_features)++;
+        }
+    }
+
+static hb_font_t *
+pango_fc_font_create_hb_font (PangoFont *font)
+{
+  PangoFcFont *fcfont = PANGO_FC_FONT (font);
+  hb_face_t *hb_face;
+
+  hb_face = pango_fc_font_map_get_hb_face (PANGO_FC_FONT_MAP (fcfont->fontmap), fcfont);
+
+  return hb_font_create (hb_face);
+}
+
 static void
 pango_fc_font_get_features (PangoFont    *font,
                             hb_feature_t *features,
diff --git a/pango/pangofc-fontmap.c b/pango/pangofc-fontmap.c
index 27abb29e..9d968328 100644
--- a/pango/pangofc-fontmap.c
+++ b/pango/pangofc-fontmap.c
@@ -52,6 +52,7 @@
 #include "pango-impl-utils.h"
 #include "pango-enum-types.h"
 #include "pango-coverage-private.h"
+#include <hb-ft.h>
 
 
 /* Overview:
@@ -166,6 +167,8 @@ struct _PangoFcFontFaceData
   FcPattern *pattern;  /* Referenced pattern that owns filename */
   PangoCoverage *coverage;
   PangoFcCmapCache *cmap_cache;
+
+  hb_face_t *hb_face;
 };
 
 struct _PangoFcFace
@@ -297,6 +300,8 @@ pango_fc_font_face_data_free (PangoFcFontFaceData *data)
   if (data->cmap_cache)
     _pango_fc_cmap_cache_unref (data->cmap_cache);
 
+  hb_face_destroy (data->hb_face);
+
   g_slice_free (PangoFcFontFaceData, data);
 }
 
@@ -2728,3 +2733,23 @@ pango_fc_family_init (PangoFcFamily *fcfamily)
 {
   fcfamily->n_faces = -1;
 }
+
+hb_face_t *
+pango_fc_font_map_get_hb_face (PangoFcFontMap *fcfontmap,
+                               PangoFcFont    *fcfont)
+{
+  PangoFcFontFaceData *data;
+
+  data = pango_fc_font_map_get_font_face_data (fcfontmap, fcfont->font_pattern);
+  
+  if (!data->hb_face)
+    {
+      hb_blob_t *blob;
+
+      blob = hb_blob_create_from_file (data->filename);
+      data->hb_face = hb_face_create (blob, data->id);
+      hb_blob_destroy (blob);
+    }
+
+  return data->hb_face;
+}
diff --git a/pango/pangofc-fontmap.h b/pango/pangofc-fontmap.h
index 5195d761..495adc52 100644
--- a/pango/pangofc-fontmap.h
+++ b/pango/pangofc-fontmap.h
@@ -26,6 +26,7 @@
 #include <fontconfig/fontconfig.h>
 #include <pango/pangofc-decoder.h>
 #include <pango/pangofc-font.h>
+#include <hb.h>
 
 G_BEGIN_DECLS
 
@@ -42,7 +43,6 @@ typedef struct _PangoFcFontMap        PangoFcFontMap;
 typedef struct _PangoFcFontMapClass   PangoFcFontMapClass;
 typedef struct _PangoFcFontMapPrivate PangoFcFontMapPrivate;
 
-
 PANGO_AVAILABLE_IN_ALL
 GType pango_fc_font_map_get_type (void) G_GNUC_CONST;
 
@@ -87,6 +87,10 @@ PANGO_AVAILABLE_IN_1_4
 PangoFontDescription *pango_fc_font_description_from_pattern (FcPattern *pattern,
                                                              gboolean   include_size);
 
+PANGO_AVAILABLE_IN_1_44
+hb_face_t * pango_fc_font_map_get_hb_face (PangoFcFontMap *fcfontmap,
+                                           PangoFcFont    *fcfont);
+
 /**
  * PANGO_FC_GRAVITY:
  *


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