[pango/hb-getters: 3/3] Implement hb font getter for fontconfig
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [pango/hb-getters: 3/3] Implement hb font getter for fontconfig
- Date: Mon, 15 Oct 2018 21:48:24 +0000 (UTC)
commit 539d8f6ad0c2d7987d9e1132ce6e5a1528172de4
Author: Matthias Clasen <mclasen redhat com>
Date: Mon Oct 15 17:46:54 2018 -0400
Implement hb font getter for fontconfig
We cache a hb_face_t object along with the font data
we already cache, and create a hb_font_t object from
it as needed.
pango/pangofc-font.c | 16 +++++++++++++++-
pango/pangofc-fontmap.c | 26 ++++++++++++++++++++++++++
pango/pangofc-fontmap.h | 7 +++++++
3 files changed, 48 insertions(+), 1 deletion(-)
---
diff --git a/pango/pangofc-font.c b/pango/pangofc-font.c
index 5a48e782..d26a11e3 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_get_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->get_hb_font = pango_fc_font_get_hb_font;
g_object_class_install_property (object_class, PROP_PATTERN,
g_param_spec_pointer ("pattern",
@@ -1067,3 +1068,16 @@ pango_fc_font_get_raw_extents (PangoFcFont *fcfont,
PANGO_FC_FONT_UNLOCK_FACE (fcfont);
}
+static hb_font_t *
+pango_fc_font_get_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);
+
+ if (hb_face)
+ return hb_font_create (hb_face);
+
+ return NULL;
+}
diff --git a/pango/pangofc-fontmap.c b/pango/pangofc-fontmap.c
index 8b41018b..5a9389a8 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
@@ -294,6 +297,9 @@ pango_fc_font_face_data_free (PangoFcFontFaceData *data)
if (data->cmap_cache)
_pango_fc_cmap_cache_unref (data->cmap_cache);
+ if (data->hb_face)
+ hb_face_destroy (data->hb_face);
+
g_slice_free (PangoFcFontFaceData, data);
}
@@ -2656,3 +2662,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]