[pango] Bug 547671 - Add pango_fc_font_map_[gs]et_fc_config()
- From: Behdad Esfahbod <behdad src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [pango] Bug 547671 - Add pango_fc_font_map_[gs]et_fc_config()
- Date: Thu, 30 Apr 2015 22:00:28 +0000 (UTC)
commit 4ad91ff6754f99d8c4f3ca1e09e2cc3005edb857
Author: Behdad Esfahbod <behdad behdad org>
Date: Thu Apr 30 18:00:14 2015 -0400
Bug 547671 - Add pango_fc_font_map_[gs]et_fc_config()
docs/pango-sections.txt | 2 +
pango/pangofc-fontmap.c | 73 +++++++++++++++++++++++++++++++++++++++++++---
pango/pangofc-fontmap.h | 6 ++++
pango/pangoft2.c | 2 +-
pango/pangoft2.def | 2 +
5 files changed, 79 insertions(+), 6 deletions(-)
---
diff --git a/docs/pango-sections.txt b/docs/pango-sections.txt
index d8ac758..96cdd3c 100644
--- a/docs/pango-sections.txt
+++ b/docs/pango-sections.txt
@@ -916,6 +916,8 @@ pango_fc_font_map_add_decoder_find_func
pango_fc_font_map_find_decoder
pango_fc_font_map_cache_clear
pango_fc_font_map_shutdown
+pango_fc_font_map_set_fc_config
+pango_fc_font_map_get_fc_config
pango_fc_font_description_from_pattern
PANGO_FC_FONT_FEATURES
PANGO_FC_GRAVITY
diff --git a/pango/pangofc-fontmap.c b/pango/pangofc-fontmap.c
index 3fcc0c5..d4ff2dd 100644
--- a/pango/pangofc-fontmap.c
+++ b/pango/pangofc-fontmap.c
@@ -150,6 +150,8 @@ struct _PangoFcFontMapPrivate
GSList *findfuncs;
guint closed : 1;
+
+ FcConfig *fc_config;
};
struct _PangoFcFontFaceData
@@ -780,7 +782,7 @@ pango_fc_patterns_get_font_pattern (PangoFcPatterns *pats, int i, gboolean *prep
FcResult result;
if (!pats->match && !pats->fontset)
{
- pats->match = FcFontMatch (NULL, pats->pattern, &result);
+ pats->match = FcFontMatch (pats->fontmap->priv->fc_config, pats->pattern, &result);
#ifdef FC_PATTERN
/* The FC_PATTERN element, which points back to our the original
* pattern defeats our hash tables.
@@ -800,7 +802,7 @@ pango_fc_patterns_get_font_pattern (PangoFcPatterns *pats, int i, gboolean *prep
if (!pats->fontset)
{
FcResult result;
- pats->fontset = FcFontSort (NULL, pats->pattern, FcTrue, NULL, &result);
+ pats->fontset = FcFontSort (pats->fontmap->priv->fc_config, pats->pattern, FcTrue, NULL, &result);
if (pats->match)
{
FcPatternDestroy (pats->match);
@@ -1312,7 +1314,7 @@ pango_fc_font_map_list_families (PangoFontMap *fontmap,
* the same family have different spacing values */
GHashTable *temp_family_hash;
- fontset = FcFontList (NULL, pat, os);
+ fontset = FcFontList (priv->fc_config, pat, os);
FcPatternDestroy (pat);
FcObjectSetDestroy (os);
@@ -1809,6 +1811,63 @@ pango_fc_font_map_cache_clear (PangoFcFontMap *fcfontmap)
pango_font_map_changed (PANGO_FONT_MAP (fcfontmap));
}
+/**
+ * pango_fc_font_map_set_fc_config:
+ * @fcfontmap: a #PangoFcFontMap
+ * @fcconfig: (nullable) a #FcConfig, or %NULL
+ *
+ * Set the FcConfig for this font map to use. The default value
+ * is %NULL, which causes Fontconfig to use its global "current config".
+ * You can create a new FcConfig object and use this API to attach it
+ * to a font map.
+ *
+ * This is particularly useful for example, if you want to use application
+ * fonts with Pango. For that, you would create a fresh FcConfig, add your
+ * app fonts to it, and attach it to a new Pango font map.
+ *
+ * This function acquires a reference to the FcConfig object; the caller
+ * does NOT need to retain a reference.
+ *
+ * Since: 1.38
+ **/
+void
+pango_fc_font_map_set_fc_config (PangoFcFontMap *fcfontmap,
+ FcConfig *fcconfig)
+{
+ FcConfig *oldconfig;
+
+ g_return_if_fail (PANGO_IS_FC_FONT_MAP (fcfontmap));
+
+ oldconfig = fcfontmap->priv->fc_config;
+
+ if (fcconfig)
+ FcConfigReference (fcconfig);
+
+ fcfontmap->priv->fc_config = fcconfig;
+
+ if (oldconfig)
+ FcConfigDestroy (oldconfig);
+}
+
+/**
+ * pango_fc_font_map_get_fc_config:
+ * @fcfontmap: a #PangoFcFontMap
+ *
+ * Fetches FcConfig attached to a font map. See pango_fc_font_map_set_fc_config().
+ *
+ * Returns: (nullable): the #FcConfig object attached to @fcfontmap, which
+ * might be %NULL.
+ *
+ * Since: 1.38
+ **/
+FcConfig *
+pango_fc_font_map_get_fc_config (PangoFcFontMap *fcfontmap)
+{
+ g_return_val_if_fail (PANGO_IS_FC_FONT_MAP (fcfontmap), NULL);
+
+ return fcfontmap->priv->fc_config;
+}
+
static PangoFcFontFaceData *
pango_fc_font_map_get_font_face_data (PangoFcFontMap *fcfontmap,
FcPattern *font_pattern)
@@ -2238,6 +2297,7 @@ pango_fc_face_describe (PangoFontFace *face)
FcResult res;
FcPattern *match_pattern;
FcPattern *result_pattern;
+ FcConfig *fc_config = NULL;
if (G_UNLIKELY (!fcfamily))
return pango_font_description_new ();
@@ -2264,7 +2324,10 @@ pango_fc_face_describe (PangoFontFace *face)
FcConfigSubstitute (NULL, match_pattern, FcMatchPattern);
FcDefaultSubstitute (match_pattern);
- result_pattern = FcFontMatch (NULL, match_pattern, &res);
+ if (fcface->family && fcface->family->fontmap)
+ fc_config = fcface->family->fontmap->priv->fc_config;
+
+ result_pattern = FcFontMatch (fc_config, match_pattern, &res);
if (result_pattern)
{
desc = pango_fc_font_description_from_pattern (result_pattern, FALSE);
@@ -2484,7 +2547,7 @@ pango_fc_family_list_faces (PangoFontFamily *family,
PangoFcFace **faces;
gint num = 0;
- fontset = FcFontList (NULL, pat, os);
+ fontset = FcFontList (priv->fc_config, pat, os);
FcPatternDestroy (pat);
FcObjectSetDestroy (os);
diff --git a/pango/pangofc-fontmap.h b/pango/pangofc-fontmap.h
index fee5faa..3f81348 100644
--- a/pango/pangofc-fontmap.h
+++ b/pango/pangofc-fontmap.h
@@ -197,6 +197,12 @@ GType pango_fc_font_map_get_type (void) G_GNUC_CONST;
void pango_fc_font_map_cache_clear (PangoFcFontMap *fcfontmap);
+void
+pango_fc_font_map_set_fc_config (PangoFcFontMap *fcfontmap,
+ FcConfig *fcconfig);
+FcConfig *
+pango_fc_font_map_get_fc_config (PangoFcFontMap *fcfontmap);
+
/**
* PangoFcDecoderFindFunc:
* @pattern: a fully resolved #FcPattern specifying the font on the system
diff --git a/pango/pangoft2.c b/pango/pangoft2.c
index 186424d..ec47685 100644
--- a/pango/pangoft2.c
+++ b/pango/pangoft2.c
@@ -110,7 +110,7 @@ load_fallback_face (PangoFT2Font *ft2font,
_pango_ft2_font_map_default_substitute ((PangoFcFontMap *)fcfont->fontmap, sans);
- matched = FcFontMatch (NULL, sans, &result);
+ matched = FcFontMatch (pango_fc_font_map_get_fc_config (fcfont->fontmap), sans, &result);
if (FcPatternGetString (matched, FC_FILE, 0, &filename2) != FcResultMatch)
goto bail1;
diff --git a/pango/pangoft2.def b/pango/pangoft2.def
index f2082cc..1f5ec90 100644
--- a/pango/pangoft2.def
+++ b/pango/pangoft2.def
@@ -18,7 +18,9 @@ EXPORTS
pango_fc_font_map_cache_clear
pango_fc_font_map_create_context
pango_fc_font_map_find_decoder
+ pango_fc_font_map_get_fc_config
pango_fc_font_map_get_type
+ pango_fc_font_map_set_fc_config
pango_fc_font_map_shutdown
pango_fc_font_unlock_face
pango_fc_fontset_key_get_absolute_size
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]