[pango/kill-ft-face: 1/15] Add api to get a hb_font_t



commit 4918d431d160a630da7454339bf83aeeeaa876aa
Author: Matthias Clasen <mclasen redhat com>
Date:   Mon Oct 15 16:34:01 2018 -0400

    Add api to get a hb_font_t
    
    Add pango_font_get_hb_font, which will make it easier
    access harfbuzz features.

 docs/pango-sections.txt    |  1 +
 pango/fonts.c              | 50 +++++++++++++++++++++++++++++++++++++++++++++-
 pango/pango-font-private.h |  3 ++-
 pango/pango-font.h         |  4 ++++
 pango/pangofc-font.c       | 13 +++++++++++-
 pango/pangofc-fontmap.c    | 25 +++++++++++++++++++++++
 pango/pangofc-fontmap.h    |  6 +++++-
 7 files changed, 98 insertions(+), 4 deletions(-)
---
diff --git a/docs/pango-sections.txt b/docs/pango-sections.txt
index 61823711..cf0a1fd7 100644
--- a/docs/pango-sections.txt
+++ b/docs/pango-sections.txt
@@ -235,6 +235,7 @@ pango_font_get_coverage
 pango_font_get_glyph_extents
 pango_font_get_metrics
 pango_font_get_font_map
+pango_font_get_hb_font
 <SUBSECTION>
 PangoFontFamily
 PANGO_TYPE_FONT_FAMILY
diff --git a/pango/fonts.c b/pango/fonts.c
index f273cd26..7d61b992 100644
--- a/pango/fonts.c
+++ b/pango/fonts.c
@@ -1617,11 +1617,29 @@ pango_parse_stretch (const char   *str,
  * PangoFont
  */
 
-G_DEFINE_ABSTRACT_TYPE (PangoFont, pango_font, G_TYPE_OBJECT)
+typedef struct {
+  hb_font_t *hb_font;
+} PangoFontPrivate;
+
+G_DEFINE_ABSTRACT_TYPE_WITH_PRIVATE (PangoFont, pango_font, G_TYPE_OBJECT)
+
+static void
+pango_font_finalize (GObject *object)
+{
+  PangoFont *font = PANGO_FONT (object);
+  PangoFontPrivate *priv = pango_font_get_instance_private (font);
+
+  hb_font_destroy (priv->hb_font);
+
+  G_OBJECT_CLASS (pango_font_parent_class)->finalize (object);
+}
 
 static void
 pango_font_class_init (PangoFontClass *class G_GNUC_UNUSED)
 {
+  GObjectClass *object_class = G_OBJECT_CLASS (class);
+
+  object_class->finalize = pango_font_finalize;
 }
 
 static void
@@ -1838,6 +1856,36 @@ pango_font_get_font_map (PangoFont *font)
     return NULL;
 }
 
+/**
+ * pango_font_get_hb_font:
+ * @font: a #PangoFont
+ *
+ * Get a hb_font_t object backing this font.
+ *
+ * Returns: (transfer none) (nullable): the hb_font_t object backing the
+ *          font, or %NULL if the font does not have one
+ *
+ * Since: 1.44
+ */
+hb_font_t *
+pango_font_get_hb_font (PangoFont *font)
+{
+  PangoFontPrivate *priv = pango_font_get_instance_private (font);
+
+  if (G_UNLIKELY (!font))
+    return NULL;
+
+  if (priv->hb_font)
+    return priv->hb_font;
+  else if (PANGO_FONT_GET_CLASS (font)->create_hb_font)
+    {
+      priv->hb_font = PANGO_FONT_GET_CLASS (font)->create_hb_font (font);
+      return priv->hb_font;
+    }
+
+  return hb_font_get_empty ();
+}
+
 G_DEFINE_BOXED_TYPE (PangoFontMetrics, pango_font_metrics,
                      pango_font_metrics_ref,
                      pango_font_metrics_unref);
diff --git a/pango/pango-font-private.h b/pango/pango-font-private.h
index 44d19dee..48ad8771 100644
--- a/pango/pango-font-private.h
+++ b/pango/pango-font-private.h
@@ -176,11 +176,12 @@ struct _PangoFontClass
                                               PangoLanguage  *language);
   PangoFontMap *        (*get_font_map)       (PangoFont      *font);
   PangoFontDescription *(*describe_absolute)  (PangoFont      *font);
+  hb_font_t *           (*create_hb_font)     (PangoFont      *font);
+
   /*< private >*/
 
   /* Padding for future expansion */
   void (*_pango_reserved1) (void);
-  void (*_pango_reserved2) (void);
 };
 
 /* used for very rare and miserable situtations that we cannot even
diff --git a/pango/pango-font.h b/pango/pango-font.h
index ceaf9643..c2db5e9e 100644
--- a/pango/pango-font.h
+++ b/pango/pango-font.h
@@ -26,6 +26,7 @@
 #include <pango/pango-types.h>
 
 #include <glib-object.h>
+#include <hb.h>
 
 G_BEGIN_DECLS
 
@@ -484,6 +485,9 @@ void                  pango_font_get_glyph_extents (PangoFont        *font,
 PANGO_AVAILABLE_IN_1_10
 PangoFontMap         *pango_font_get_font_map      (PangoFont        *font);
 
+PANGO_AVAILABLE_IN_1_44
+hb_font_t *           pango_font_get_hb_font       (PangoFont        *font);
+
 
 /**
  * PANGO_GLYPH_EMPTY:
diff --git a/pango/pangofc-font.c b/pango/pangofc-font.c
index 79fb07c1..40e36dca 100644
--- a/pango/pangofc-font.c
+++ b/pango/pangofc-font.c
@@ -89,7 +89,7 @@ static PangoFontMetrics *    pango_fc_font_get_metrics  (PangoFont        *font,
 static PangoFontMap *        pango_fc_font_get_font_map (PangoFont        *font);
 static PangoFontDescription *pango_fc_font_describe     (PangoFont        *font);
 static PangoFontDescription *pango_fc_font_describe_absolute (PangoFont        *font);
-
+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))
@@ -116,6 +116,7 @@ pango_fc_font_class_init (PangoFcFontClass *class)
   font_class->get_coverage = pango_fc_font_get_coverage;
   font_class->get_metrics = pango_fc_font_get_metrics;
   font_class->get_font_map = pango_fc_font_get_font_map;
+  font_class->create_hb_font = pango_fc_font_create_hb_font;
 
   g_object_class_install_property (object_class, PROP_PATTERN,
                                   g_param_spec_pointer ("pattern",
@@ -1086,3 +1087,13 @@ pango_fc_font_get_raw_extents (PangoFcFont    *fcfont,
   PANGO_FC_FONT_UNLOCK_FACE (fcfont);
 }
 
+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);
+}
diff --git a/pango/pangofc-fontmap.c b/pango/pangofc-fontmap.c
index e88ac431..12d7a9a1 100644
--- a/pango/pangofc-fontmap.c
+++ b/pango/pangofc-fontmap.c
@@ -51,6 +51,7 @@
 #include "pangofc-private.h"
 #include "pango-impl-utils.h"
 #include "pango-enum-types.h"
+#include <hb-ft.h>
 
 
 /* Overview:
@@ -165,6 +166,8 @@ struct _PangoFcFontFaceData
   FcPattern *pattern;  /* Referenced pattern that owns filename */
   PangoCoverage *coverage;
   PangoFcCmapCache *cmap_cache;
+
+  hb_face_t *hb_face;
 };
 
 struct _PangoFcFace
@@ -296,6 +299,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);
 }
 
@@ -2690,3 +2695,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]