[pango/pango2: 117/201] Add some useful face api




commit 789e5e4512ef4a07bca5f4face467da19ef1b6d5
Author: Matthias Clasen <mclasen redhat com>
Date:   Thu Feb 17 17:08:34 2022 -0600

    Add some useful face api
    
    Add pango_font_face_supports_language and pango_font_face_get_languages.
    There is no particular reason to tie language information to fonts
    instead of faces. This will be useful for the font chooser.
    
    Update the fontconfig implementation for these changes.

 pango/pango-font-face-private.h | 15 ++++++----
 pango/pango-font-face.c         | 62 +++++++++++++++++++++++++++++++++++++++++
 pango/pango-font-face.h         | 11 ++++++--
 pango/pango-font.c              |  2 +-
 4 files changed, 81 insertions(+), 9 deletions(-)
---
diff --git a/pango/pango-font-face-private.h b/pango/pango-font-face-private.h
index 8fabce44..71c9033e 100644
--- a/pango/pango-font-face-private.h
+++ b/pango/pango-font-face-private.h
@@ -33,12 +33,15 @@ struct _PangoFontFaceClass
 {
   GObjectClass parent_class;
 
-  const char *           (* get_face_name)  (PangoFontFace *face);
-  PangoFontDescription * (* describe)       (PangoFontFace *face);
-  gboolean               (* is_synthesized) (PangoFontFace *face);
-  gboolean               (*is_monospace)    (PangoFontFace *face);
-  gboolean               (*is_variable)     (PangoFontFace *face);
-  PangoFontFamily *      (* get_family)     (PangoFontFace *face);
+  const char *           (* get_face_name)     (PangoFontFace *face);
+  PangoFontDescription * (* describe)          (PangoFontFace *face);
+  gboolean               (* is_synthesized)    (PangoFontFace *face);
+  gboolean               (*is_monospace)       (PangoFontFace *face);
+  gboolean               (*is_variable)        (PangoFontFace *face);
+  PangoFontFamily *      (* get_family)        (PangoFontFace *face);
+  gboolean               (* supports_language) (PangoFontFace *face,
+                                                PangoLanguage *language);
+  PangoLanguage **       (* get_languages)     (PangoFontFace *face);
 };
 
 #define PANGO_FONT_FACE_CLASS(klass)      (G_TYPE_CHECK_CLASS_CAST ((klass), PANGO_TYPE_FONT_FACE, 
PangoFontFaceClass))
diff --git a/pango/pango-font-face.c b/pango/pango-font-face.c
index 9eb46bac..8f57e0f3 100644
--- a/pango/pango-font-face.c
+++ b/pango/pango-font-face.c
@@ -38,11 +38,26 @@ pango_font_face_default_is_variable (PangoFontFace *face)
   return pango_font_family_is_variable (pango_font_face_get_family (face));
 }
 
+static gboolean
+pango_font_face_default_supports_language (PangoFontFace *face,
+                                           PangoLanguage *language)
+{
+  return TRUE;
+}
+
+static PangoLanguage **
+pango_font_face_default_get_languages (PangoFontFace *face)
+{
+  return NULL;
+}
+
 static void
 pango_font_face_class_init (PangoFontFaceClass *class G_GNUC_UNUSED)
 {
   class->is_monospace = pango_font_face_default_is_monospace;
   class->is_variable = pango_font_face_default_is_variable;
+  class->get_languages = pango_font_face_default_get_languages;
+  class->supports_language = pango_font_face_default_supports_language;
 }
 
 static void
@@ -177,3 +192,50 @@ pango_font_face_is_variable (PangoFontFace *face)
 
   return PANGO_FONT_FACE_GET_CLASS (face)->is_variable (face);
 }
+
+/**
+ * pango_font_face_supports_language:
+ * @face: a `PangoFontFace`
+ * @language: a `PangoLanguage`
+ *
+ * Returns whether @face has all the glyphs necessary to write @language.
+ *
+ * Returns: `TRUE` if @face supports @language
+ *
+ * Since: 1.52
+ */
+gboolean
+pango_font_face_supports_language (PangoFontFace *face,
+                                   PangoLanguage *language)
+{
+  g_return_val_if_fail (PANGO_IS_FONT_FACE (face), FALSE);
+
+  return PANGO_FONT_FACE_GET_CLASS (face)->supports_language (face, language);
+}
+
+/**
+ * pango_font_face_get_languages:
+ * @face: a `PangoFontFace`
+ *
+ * Returns the languages that are supported by @face.
+ *
+ * If the font backend does not provide this information,
+ * %NULL is returned. For the fontconfig backend, this
+ * corresponds to the FC_LANG member of the FcPattern.
+ *
+ * The returned array is only valid as long as the face
+ * and its fontmap are valid.
+ *
+ * Returns: (transfer none) (nullable) (array zero-terminated=1) (element-type PangoLanguage):
+ *   an array of `PangoLanguage`
+ *
+ * Since: 1.52
+ */
+PangoLanguage **
+pango_font_face_get_languages (PangoFontFace *face)
+{
+  g_return_val_if_fail (PANGO_IS_FONT_FACE (face), FALSE);
+
+  return PANGO_FONT_FACE_GET_CLASS (face)->get_languages (face);
+}
+
diff --git a/pango/pango-font-face.h b/pango/pango-font-face.h
index caca6ac7..ac666c9b 100644
--- a/pango/pango-font-face.h
+++ b/pango/pango-font-face.h
@@ -37,13 +37,20 @@ PANGO_AVAILABLE_IN_ALL
 const char *            pango_font_face_get_face_name  (PangoFontFace  *face) G_GNUC_PURE;
 PANGO_AVAILABLE_IN_1_18
 gboolean                pango_font_face_is_synthesized (PangoFontFace  *face) G_GNUC_PURE;
-PANGO_AVAILABLE_IN_1_52
+PANGO_AVAILABLE_IN_ALL
 gboolean                pango_font_face_is_monospace   (PangoFontFace  *face);
-PANGO_AVAILABLE_IN_1_52
+PANGO_AVAILABLE_IN_ALL
 gboolean                pango_font_face_is_variable    (PangoFontFace  *face);
 
 PANGO_AVAILABLE_IN_1_46
 PangoFontFamily *       pango_font_face_get_family     (PangoFontFace  *face);
 
+PANGO_AVAILABLE_IN_ALL
+gboolean              pango_font_face_supports_language (PangoFontFace *face,
+                                                         PangoLanguage *language);
+
+PANGO_AVAILABLE_IN_ALL
+PangoLanguage **      pango_font_face_get_languages     (PangoFontFace *face);
+
 
 G_END_DECLS
diff --git a/pango/pango-font.c b/pango/pango-font.c
index 344a91ac..a6c651e4 100644
--- a/pango/pango-font.c
+++ b/pango/pango-font.c
@@ -48,7 +48,7 @@ pango_font_finalize (GObject *object)
 static PangoLanguage **
 pango_font_default_get_languages (PangoFont *font)
 {
-  return NULL;
+  return pango_font_face_get_languages (pango_font_get_face (font));
 }
 
 static gboolean


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]