[pango/preferred-languages: 8/8] pangofc: Add pango_fc_font_get_languages
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [pango/preferred-languages: 8/8] pangofc: Add pango_fc_font_get_languages
- Date: Tue, 8 Sep 2020 21:02:49 +0000 (UTC)
commit e11a226a94df7515447fffa73ecc04b07ec5a01c
Author: Matthias Clasen <mclasen redhat com>
Date: Tue Sep 8 14:25:42 2020 -0400
pangofc: Add pango_fc_font_get_languages
This really belongs into PangoFont, but we're out of
room in the PangoFontClass struct for vfuncs, so this
will have to remain backend-specific functionality
for now.
docs/pango-sections.txt | 1 +
pango/pangofc-font.c | 32 ++++++++++++++++++++++++++++
pango/pangofc-font.h | 4 ++++
pango/pangofc-fontmap.c | 56 ++++++++++++++++++++++++++++++++++++++++++++++++-
pango/pangofc-private.h | 3 +++
5 files changed, 95 insertions(+), 1 deletion(-)
---
diff --git a/docs/pango-sections.txt b/docs/pango-sections.txt
index 56ca9ecf..062b1bb4 100644
--- a/docs/pango-sections.txt
+++ b/docs/pango-sections.txt
@@ -1011,6 +1011,7 @@ pango_fc_font_has_char
pango_fc_font_get_glyph
pango_fc_font_get_unknown_glyph
pango_fc_font_kern_glyphs
+pango_fc_font_get_languages
<SUBSECTION Standard>
PANGO_FC_FONT
PANGO_IS_FC_FONT
diff --git a/pango/pangofc-font.c b/pango/pangofc-font.c
index 7456cd9e..6c5492ad 100644
--- a/pango/pangofc-font.c
+++ b/pango/pangofc-font.c
@@ -1035,3 +1035,35 @@ pango_fc_font_create_hb_font (PangoFont *font)
done:
return hb_font;
}
+
+/**
+ * pango_fc_font_get_languages:
+ * @font: a #PangoFcFont
+ *
+ * Returns the languages that are supported by @font.
+ *
+ * This corresponds to the FC_LANG member of the FcPattern.
+ *
+ * The returned array is only valid as long as the font
+ * and its fontmap are valid.
+ *
+ * Returns: (transfer none) (nullable): a %NULL-terminated
+ * array of PangoLanguage*
+ *
+ * Since: 1.48
+ */
+PangoLanguage **
+pango_fc_font_get_languages (PangoFcFont *font)
+{
+ PangoFcFontMap *fontmap;
+ PangoLanguage **languages;
+
+ fontmap = g_weak_ref_get ((GWeakRef *) &font->fontmap);
+ if (!fontmap)
+ return NULL;
+
+ languages = _pango_fc_font_map_get_languages (fontmap, font);
+ g_object_unref (fontmap);
+
+ return languages;
+}
diff --git a/pango/pangofc-font.h b/pango/pangofc-font.h
index 25a0277c..aa4fd3b0 100644
--- a/pango/pangofc-font.h
+++ b/pango/pangofc-font.h
@@ -94,6 +94,10 @@ gboolean pango_fc_font_has_char (PangoFcFont *font,
PANGO_AVAILABLE_IN_1_4
guint pango_fc_font_get_glyph (PangoFcFont *font,
gunichar wc);
+PANGO_AVAILABLE_IN_1_48
+PangoLanguage **
+ pango_fc_font_get_languages (PangoFcFont *font);
+
PANGO_DEPRECATED_FOR(PANGO_GET_UNKNOWN_GLYPH)
PangoGlyph pango_fc_font_get_unknown_glyph (PangoFcFont *font,
gunichar wc);
diff --git a/pango/pangofc-fontmap.c b/pango/pangofc-fontmap.c
index eed0960a..bd15bf2a 100644
--- a/pango/pangofc-fontmap.c
+++ b/pango/pangofc-fontmap.c
@@ -166,8 +166,9 @@ struct _PangoFcFontFaceData
int id; /* needed to handle TTC files with multiple faces */
/* Data */
- FcPattern *pattern; /* Referenced pattern that owns filename */
+ FcPattern *pattern; /* Referenced pattern that owns filename */
PangoCoverage *coverage;
+ PangoLanguage **languages;
hb_face_t *hb_face;
};
@@ -307,6 +308,8 @@ pango_fc_font_face_data_free (PangoFcFontFaceData *data)
if (data->coverage)
pango_coverage_unref (data->coverage);
+ g_free (data->languages);
+
hb_face_destroy (data->hb_face);
g_slice_free (PangoFcFontFaceData, data);
@@ -2245,6 +2248,57 @@ _pango_fc_font_map_fc_to_coverage (FcCharSet *charset)
return (PangoCoverage *)coverage;
}
+static PangoLanguage **
+_pango_fc_font_map_fc_to_languages (FcLangSet *langset)
+{
+ FcStrSet *strset;
+ FcStrList *list;
+ FcChar8 *s;
+ GArray *langs;
+
+ langs = g_array_new (TRUE, FALSE, sizeof (PangoLanguage *));
+
+ strset = FcLangSetGetLangs (langset);
+ list = FcStrListCreate (strset);
+
+ FcStrListFirst (list);
+ while ((s = FcStrListNext (list)))
+ {
+ PangoLanguage *l = pango_language_from_string ((const char *)s);
+ g_array_append_val (langs, l);
+ }
+
+ FcStrListDone (list);
+ FcStrSetDestroy (strset);
+
+ return (PangoLanguage **) g_array_free (langs, FALSE);
+}
+
+PangoLanguage **
+_pango_fc_font_map_get_languages (PangoFcFontMap *fcfontmap,
+ PangoFcFont *fcfont)
+{
+ PangoFcFontFaceData *data;
+ FcLangSet *langset;
+
+ data = pango_fc_font_map_get_font_face_data (fcfontmap, fcfont->font_pattern);
+ if (G_UNLIKELY (!data))
+ return NULL;
+
+ if (G_UNLIKELY (data->languages == NULL))
+ {
+ /*
+ * Pull the languages out of the pattern, this
+ * doesn't require loading the font
+ */
+ if (FcPatternGetLangSet (fcfont->font_pattern, FC_LANG, 0, &langset) != FcResultMatch)
+ return NULL;
+
+ data->languages = _pango_fc_font_map_fc_to_languages (langset);
+ }
+
+ return data->languages;
+}
/**
* pango_fc_font_map_create_context:
* @fcfontmap: a #PangoFcFontMap
diff --git a/pango/pangofc-private.h b/pango/pangofc-private.h
index 27b96df4..7e216ed9 100644
--- a/pango/pangofc-private.h
+++ b/pango/pangofc-private.h
@@ -78,6 +78,9 @@ _PANGO_EXTERN
PangoFontMetrics *pango_fc_font_create_base_metrics_for_context (PangoFcFont *font,
PangoContext *context);
+PangoLanguage **_pango_fc_font_map_get_languages (PangoFcFontMap *fcfontmap,
+ PangoFcFont *fcfont);
+
G_END_DECLS
#endif /* __PANGOFC_PRIVATE_H__ */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]