[pango/family-face-api: 53/56] Add pango_font_map_get_family



commit f5e2d4e34e7c3090b0bfb3d17b7d7a31678df831
Author: Matthias Clasen <mclasen redhat com>
Date:   Tue Aug 13 22:18:32 2019 -0400

    Add pango_font_map_get_family
    
    This lets us get a PangoFontFamily by name.

 docs/pango-sections.txt       |  1 +
 pango/pango-fontmap-private.h |  1 -
 pango/pango-fontmap.c         | 52 ++++++++++++++++++++++++++++++++++++
 pango/pango-fontmap.h         |  7 ++++-
 pango/pangofc-fontmap.c       | 62 +++++++++++++++++++++++++++++++++----------
 5 files changed, 107 insertions(+), 16 deletions(-)
---
diff --git a/docs/pango-sections.txt b/docs/pango-sections.txt
index c875b91f..3abcf7c3 100644
--- a/docs/pango-sections.txt
+++ b/docs/pango-sections.txt
@@ -277,6 +277,7 @@ pango_font_map_create_context
 pango_font_map_load_font
 pango_font_map_load_fontset
 pango_font_map_list_families
+pango_font_map_get_family
 pango_font_map_get_serial
 pango_font_map_changed
 <SUBSECTION>
diff --git a/pango/pango-fontmap-private.h b/pango/pango-fontmap-private.h
index be06bd8f..3452fbca 100644
--- a/pango/pango-fontmap-private.h
+++ b/pango/pango-fontmap-private.h
@@ -28,7 +28,6 @@
 
 G_BEGIN_DECLS
 
-
 PANGO_DEPRECATED_IN_1_38
 const char   *pango_font_map_get_shape_engine_type (PangoFontMap *fontmap);
 
diff --git a/pango/pango-fontmap.c b/pango/pango-fontmap.c
index 46054ec1..47096e8b 100644
--- a/pango/pango-fontmap.c
+++ b/pango/pango-fontmap.c
@@ -31,12 +31,16 @@ static PangoFontset *pango_font_map_real_load_fontset (PangoFontMap
                                                       PangoLanguage              *language);
 
 
+static PangoFontFamily *pango_font_map_real_get_family (PangoFontMap *fontmap,
+                                                        const char   *name);
+
 G_DEFINE_ABSTRACT_TYPE (PangoFontMap, pango_font_map, G_TYPE_OBJECT)
 
 static void
 pango_font_map_class_init (PangoFontMapClass *class)
 {
   class->load_fontset = pango_font_map_real_load_fontset;
+  class->get_family = pango_font_map_real_get_family;
 }
 
 static void
@@ -339,3 +343,51 @@ pango_font_map_changed (PangoFontMap *fontmap)
   if (PANGO_FONT_MAP_GET_CLASS (fontmap)->changed)
     PANGO_FONT_MAP_GET_CLASS (fontmap)->changed (fontmap);
 }
+
+static PangoFontFamily *
+pango_font_map_real_get_family (PangoFontMap *fontmap,
+                                const char   *name)
+{
+  PangoFontFamily **families;
+  int n_families;
+  PangoFontFamily *family;
+  int i;
+
+  pango_font_map_list_families (fontmap, &families, &n_families);
+
+  family = NULL;
+
+  for (i = 0; i < n_families; i++)
+    {
+      if (strcmp (name, pango_font_family_get_name (families[i])) == 0)
+        {
+          family = families[i];
+          break;
+        }
+    }
+
+  g_free (families);
+
+  return family;
+}
+
+/**
+ * pango_font_map_get_family:
+ * @fontmap: a #PangoFontMap
+ * @name: a family name
+ *
+ * Gets a font family by name.
+ *
+ * Returns: (transfer none): the #PangoFontFamily
+ *
+ * Since: 1.44
+ */
+PangoFontFamily *
+pango_font_map_get_family (PangoFontMap *fontmap,
+                           const char   *name)
+{
+  g_return_val_if_fail (PANGO_IS_FONT_MAP (fontmap), NULL);
+
+  return PANGO_FONT_MAP_GET_CLASS (fontmap)->get_family (fontmap, name);
+}
+
diff --git a/pango/pango-fontmap.h b/pango/pango-fontmap.h
index b6206f1d..6552dff4 100644
--- a/pango/pango-fontmap.h
+++ b/pango/pango-fontmap.h
@@ -114,11 +114,13 @@ struct _PangoFontMapClass
   guint         (*get_serial)    (PangoFontMap               *fontmap);
   void          (*changed)       (PangoFontMap               *fontmap);
 
+  PangoFontFamily * (*get_family) (PangoFontMap               *fontmap,
+                                   const char                 *name);
+
   /*< private >*/
 
   /* Padding for future expansion */
   void (*_pango_reserved1) (void);
-  void (*_pango_reserved2) (void);
 };
 
 PANGO_AVAILABLE_IN_ALL
@@ -143,6 +145,9 @@ guint         pango_font_map_get_serial    (PangoFontMap                 *fontma
 PANGO_AVAILABLE_IN_1_34
 void          pango_font_map_changed       (PangoFontMap                 *fontmap);
 
+PANGO_AVAILABLE_IN_1_44
+PangoFontFamily *pango_font_map_get_family (PangoFontMap                 *fontmap,
+                                            const char                   *name);
 
 G_END_DECLS
 
diff --git a/pango/pangofc-fontmap.c b/pango/pangofc-fontmap.c
index 535a6f0e..8b49bdce 100644
--- a/pango/pangofc-fontmap.c
+++ b/pango/pangofc-fontmap.c
@@ -219,6 +219,8 @@ static PangoFontset *pango_fc_font_map_load_fontset  (PangoFontMap
 static void          pango_fc_font_map_list_families (PangoFontMap                 *fontmap,
                                                       PangoFontFamily            ***families,
                                                       int                          *n_families);
+static PangoFontFamily *pango_fc_font_map_get_family (PangoFontMap *fontmap,
+                                                      const char   *name);
 
 static double pango_fc_font_map_get_resolution (PangoFcFontMap *fcfontmap,
                                                PangoContext   *context);
@@ -1190,6 +1192,7 @@ pango_fc_font_map_class_init (PangoFcFontMapClass *class)
   fontmap_class->load_font = pango_fc_font_map_load_font;
   fontmap_class->load_fontset = pango_fc_font_map_load_fontset;
   fontmap_class->list_families = pango_fc_font_map_list_families;
+  fontmap_class->get_family = pango_fc_font_map_get_family;
   fontmap_class->shape_engine_type = PANGO_RENDER_TYPE_FC;
 }
 
@@ -1356,26 +1359,13 @@ is_alias_family (const char *family_name)
 }
 
 static void
-pango_fc_font_map_list_families (PangoFontMap      *fontmap,
-                                PangoFontFamily ***families,
-                                int               *n_families)
+ensure_families (PangoFcFontMap *fcfontmap)
 {
-  PangoFcFontMap *fcfontmap = PANGO_FC_FONT_MAP (fontmap);
   PangoFcFontMapPrivate *priv = fcfontmap->priv;
   FcFontSet *fontset;
   int i;
   int count;
 
-  if (priv->closed)
-    {
-      if (families)
-       *families = NULL;
-      if (n_families)
-       *n_families = 0;
-
-      return;
-    }
-
   if (priv->n_families < 0)
     {
       FcObjectSet *os = FcObjectSetBuild (FC_FAMILY, FC_SPACING, FC_STYLE, FC_WEIGHT, FC_WIDTH, FC_SLANT,
@@ -1448,6 +1438,27 @@ pango_fc_font_map_list_families (PangoFontMap      *fontmap,
 
       priv->n_families = count;
     }
+}
+
+static void
+pango_fc_font_map_list_families (PangoFontMap      *fontmap,
+                                PangoFontFamily ***families,
+                                int               *n_families)
+{
+  PangoFcFontMap *fcfontmap = PANGO_FC_FONT_MAP (fontmap);
+  PangoFcFontMapPrivate *priv = fcfontmap->priv;
+
+  if (priv->closed)
+    {
+      if (families)
+       *families = NULL;
+      if (n_families)
+       *n_families = 0;
+
+      return;
+    }
+
+  ensure_families (fcfontmap);
 
   if (n_families)
     *n_families = priv->n_families;
@@ -1456,6 +1467,29 @@ pango_fc_font_map_list_families (PangoFontMap      *fontmap,
     *families = g_memdup (priv->families, priv->n_families * sizeof (PangoFontFamily *));
 }
 
+static PangoFontFamily *
+pango_fc_font_map_get_family (PangoFontMap *fontmap,
+                              const char   *name)
+{
+  PangoFcFontMap *fcfontmap = PANGO_FC_FONT_MAP (fontmap);
+  PangoFcFontMapPrivate *priv = fcfontmap->priv;
+  int i;
+
+  if (priv->closed)
+    return NULL;
+
+  ensure_families (fcfontmap);
+
+  for (i = 0; i < priv->n_families; i++)
+    {
+      PangoFontFamily *family = PANGO_FONT_FAMILY (priv->families[i]);
+      if (strcmp (name, pango_font_family_get_name (family)) == 0)
+        return family;
+    }
+
+  return NULL;
+}
+
 static double
 pango_fc_convert_weight_to_fc (PangoWeight pango_weight)
 {


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