[pango/hb-getters: 42/46] Add api to get a hb_font_t
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [pango/hb-getters: 42/46] Add api to get a hb_font_t
- Date: Thu, 31 Jan 2019 09:13:24 +0000 (UTC)
commit 9ee4f023beacf0a00b0d0775e76aa90a9963d8b6
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.
pango/fonts.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++++-
pango/pango-font.h | 6 +++++-
pango/pangofc-font.c | 13 ++++++++++++-
pango/pangofc-fontmap.c | 25 +++++++++++++++++++++++++
pango/pangofc-fontmap.h | 7 +++++++
5 files changed, 98 insertions(+), 3 deletions(-)
---
diff --git a/pango/fonts.c b/pango/fonts.c
index 63e7c7b9..e29de11d 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
@@ -1837,6 +1855,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.h b/pango/pango-font.h
index 1b85c386..461ece87 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
@@ -585,6 +586,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);
+
#ifdef PANGO_ENABLE_BACKEND
#define PANGO_FONT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), PANGO_TYPE_FONT, PangoFontClass))
@@ -634,11 +638,11 @@ 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/pangofc-font.c b/pango/pangofc-font.c
index 5a48e782..fffc6e2d 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",
@@ -1067,3 +1068,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 7d75f6f9..575f5d03 100644
--- a/pango/pangofc-fontmap.c
+++ b/pango/pangofc-fontmap.c
@@ -50,6 +50,7 @@
#include "pangofc-private.h"
#include "pango-impl-utils.h"
#include "pango-enum-types.h"
+#include <hb-ft.h>
/* Overview:
@@ -164,6 +165,8 @@ struct _PangoFcFontFaceData
FcPattern *pattern; /* Referenced pattern that owns filename */
PangoCoverage *coverage;
PangoFcCmapCache *cmap_cache;
+
+ hb_face_t *hb_face;
};
struct _PangoFcFace
@@ -295,6 +298,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);
}
@@ -2689,3 +2694,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 bff288b6..afa402df 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
@@ -187,6 +188,7 @@ struct _PangoFcFontMapClass
FcPattern *pattern);
PangoFcFont *(*create_font) (PangoFcFontMap *fontmap,
PangoFcFontKey *fontkey);
+
/*< private >*/
/* Padding for future expansion */
@@ -249,6 +251,11 @@ 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]