summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias Clasen <mclasen@redhat.com>2019-07-13 00:00:10 -0400
committerMatthias Clasen <mclasen@redhat.com>2019-07-18 12:47:53 -0700
commitceea8a00ce38fec1c0879d61a79911abc5788374 (patch)
tree0770f81e0db86f6cdcf52da0082c07e70a9e8917
parentb3c6ed417f7f6bf98f7114dd075818d20489622c (diff)
downloadpango-ceea8a00ce38fec1c0879d61a79911abc5788374.tar.gz
fc: Implement create_hb_font
-rw-r--r--pango/pangofc-font.c39
-rw-r--r--pango/pangofc-fontmap.c25
-rw-r--r--pango/pangofc-fontmap.h6
3 files changed, 69 insertions, 1 deletions
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",
@@ -1063,4 +1066,40 @@ pango_fc_font_get_features (PangoFont *font,
(*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,
+ 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)++;
+ }
+ }
}
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:
*