[pango/pango2: 71/195] Reduce use of redundant apis




commit f799434071c52fbbda5e0b9b48fb9d3ed39506cc
Author: Matthias Clasen <mclasen redhat com>
Date:   Sat Feb 12 13:53:54 2022 -0500

    Reduce use of redundant apis

 tests/test-font.c    | 39 ++++++++++++++++++++-------------------
 tests/test-itemize.c | 12 ++++++------
 tests/testcontext.c  | 25 -------------------------
 utils/pango-list.c   | 49 +++++++++++++++++++++++--------------------------
 4 files changed, 49 insertions(+), 76 deletions(-)
---
diff --git a/tests/test-font.c b/tests/test-font.c
index b4a38c22..3a1e2d98 100644
--- a/tests/test-font.c
+++ b/tests/test-font.c
@@ -221,13 +221,9 @@ test_enumerate (void)
 {
   PangoFontMap *fontmap;
   PangoContext *context;
-  PangoFontFamily **families;
   PangoFontFamily *family;
-  int n_families;
   int i;
-  PangoFontFace **faces;
   PangoFontFace *face;
-  int n_faces;
   PangoFontDescription *desc;
   PangoFont *font;
   gboolean found_face;
@@ -235,33 +231,40 @@ test_enumerate (void)
   fontmap = pango_cairo_font_map_get_default ();
   context = pango_font_map_create_context (fontmap);
 
-  pango_font_map_list_families (fontmap, &families, &n_families);
-  g_assert_cmpint (n_families, >, 0);
+  g_assert_cmpint (g_list_model_get_n_items (G_LIST_MODEL (fontmap)), >, 0);
 
-  for (i = 0; i < n_families; i++)
+  for (i = 0; i < g_list_model_get_n_items (G_LIST_MODEL (fontmap)); i++)
     {
-      family = pango_font_map_get_family (fontmap, pango_font_family_get_name (families[i]));
-      g_assert_true (family == families[i]);
+      PangoFontFamily *fam = g_list_model_get_item (G_LIST_MODEL (fontmap), i);
+      family = pango_font_map_get_family (fontmap, pango_font_family_get_name (fam));
+      g_assert_true (family == fam);
+      g_object_unref (fam);
     }
 
-  pango_font_family_list_faces (families[0], &faces, &n_faces);
-  g_assert_cmpint (n_faces, >, 0);
-  for (i = 0; i < n_faces; i++)
+  family = g_list_model_get_item (G_LIST_MODEL (fontmap), 0);
+  g_object_unref (family);
+
+  g_assert_cmpint (g_list_model_get_n_items (G_LIST_MODEL (family)), >, 0);
+  for (i = 0; i < g_list_model_get_n_items (G_LIST_MODEL (family)); i++)
     {
-      face = pango_font_family_get_face (families[0], pango_font_face_get_face_name (faces[i]));
-      g_assert_cmpstr (pango_font_face_get_face_name (face), ==, pango_font_face_get_face_name (faces[i]));
+      PangoFontFace *f = g_list_model_get_item (G_LIST_MODEL (family), i);
+      face = pango_font_family_get_face (family, pango_font_face_get_face_name (f));
+      g_assert_cmpstr (pango_font_face_get_face_name (face), ==, pango_font_face_get_face_name (f));
+      g_object_unref (f);
     }
 
   desc = pango_font_description_new ();
-  pango_font_description_set_family (desc, pango_font_family_get_name (families[0]));
+  pango_font_description_set_family (desc, pango_font_family_get_name (family));
   pango_font_description_set_size (desc, 10*PANGO_SCALE);
 
   font = pango_font_map_load_font (fontmap, context, desc);
   face = pango_font_get_face (font);
   found_face = FALSE;
-  for (i = 0; i < n_faces; i++)
+  for (i = 0; i < g_list_model_get_n_items (G_LIST_MODEL (family)); i++)
     {
-      if (face == faces[i])
+      PangoFontFace *f = g_list_model_get_item (G_LIST_MODEL (family), i);
+      g_object_unref (f);
+      if (face == f)
         {
           found_face = TRUE;
           break;
@@ -271,8 +274,6 @@ test_enumerate (void)
 
   g_object_unref (font);
   pango_font_description_free (desc);
-  g_free (faces);
-  g_free (families);
   g_object_unref (context);
 }
 
diff --git a/tests/test-itemize.c b/tests/test-itemize.c
index a12bddd7..29b43dde 100644
--- a/tests/test-itemize.c
+++ b/tests/test-itemize.c
@@ -252,9 +252,8 @@ test_itemize (gconstpointer d)
   GError *error = NULL;
   GString *dump;
   gchar *diff;
-  PangoFontFamily **families;
-  int n_families;
   gboolean found_cantarell;
+  PangoFontMap *map;
 
   char *old_locale = g_strdup (setlocale (LC_ALL, NULL));
   setlocale (LC_ALL, "en_US.UTF-8");
@@ -268,16 +267,17 @@ test_itemize (gconstpointer d)
     }
 
   found_cantarell = FALSE;
-  pango_context_list_families (context, &families, &n_families);
-  for (int i = 0; i < n_families; i++)
+  map = pango_context_get_font_map (context);
+  for (int i = 0; i < g_list_model_get_n_items (G_LIST_MODEL (map)); i++)
     {
-      if (strcmp (pango_font_family_get_name (families[i]), "Cantarell") == 0)
+      PangoFontFamily *family = g_list_model_get_item (G_LIST_MODEL (map), i);
+      g_object_unref (family);
+      if (strcmp (pango_font_family_get_name (family), "Cantarell") == 0)
         {
           found_cantarell = TRUE;
           break;
         }
     }
-  g_free (families);
 
   if (!found_cantarell)
     {
diff --git a/tests/testcontext.c b/tests/testcontext.c
index 9cd8d833..dcf5a2cc 100644
--- a/tests/testcontext.c
+++ b/tests/testcontext.c
@@ -23,30 +23,6 @@
 #include <pango/pango.h>
 #include <pango/pangocairo.h>
 
-static void
-test_list_families (void)
-{
-  PangoContext *context;
-  PangoFontFamily **families = NULL;
-  int n_families = 0;
-
-  context = pango_context_new ();
-
-  pango_context_list_families (context, &families, &n_families);
-  g_assert_null (families);
-  g_assert_cmpint (n_families, ==, 0);
-
-  pango_context_set_font_map (context, pango_cairo_font_map_get_default ());
-
-  pango_context_list_families (context, &families, &n_families);
-  g_assert_nonnull (families);
-  g_assert_cmpint (n_families, >, 0);
-
-  g_free (families);
-
-  g_object_unref (context);
-}
-
 static void
 test_set_language (void)
 {
@@ -134,7 +110,6 @@ main (int argc, char *argv[])
 {
   g_test_init (&argc, &argv, NULL);
 
-  g_test_add_func ("/context/list-families", test_list_families);
   g_test_add_func ("/context/set-language", test_set_language);
   g_test_add_func ("/context/set-base-dir", test_set_base_dir);
   g_test_add_func ("/context/set-base-gravity", test_set_base_gravity);
diff --git a/utils/pango-list.c b/utils/pango-list.c
index 82a5647c..0966578a 100644
--- a/utils/pango-list.c
+++ b/utils/pango-list.c
@@ -57,8 +57,6 @@ main (int    argc,
   GOptionContext *context;
   PangoContext *ctx;
   PangoFontMap *fontmap;
-  PangoFontFamily **families;
-  int n_families;
   int i, j;
   int width;
   GError *error = NULL;
@@ -92,24 +90,24 @@ main (int    argc,
   if (opt_verbose)
     g_print ("Using %s\n\n", G_OBJECT_TYPE_NAME (fontmap));
 
-  pango_font_map_list_families (fontmap, &families, &n_families);
-  for (i = 0; i < n_families; i++)
+  for (i = 0; i < g_list_model_get_n_items (G_LIST_MODEL (fontmap)); i++)
     {
-      PangoFontFace **faces;
-      int n_faces;
+      PangoFontFamily *family = g_list_model_get_item (G_LIST_MODEL (fontmap), i);
       const char *kind;
+      const char *family_name = pango_font_family_get_name (family);
 
-      const char *family_name = pango_font_family_get_name (families[i]);
-      if (pango_font_family_is_monospace (families[i]))
+      g_object_unref (family);
+
+      if (pango_font_family_is_monospace (family))
         {
-          if (pango_font_family_is_variable (families[i]))
+          if (pango_font_family_is_variable (family))
             kind = "(monospace, variable)";
           else
             kind = "(monospace)";
         }
       else
         {
-          if (pango_font_family_is_variable (families[i]))
+          if (pango_font_family_is_variable (family))
             kind = "(variable)";
           else
             kind = "";
@@ -117,23 +115,24 @@ main (int    argc,
 
       g_print ("%s %s\n", family_name, kind);
 
-      pango_font_family_list_faces (families[i], &faces, &n_faces);
-
       width = 0;
-      for (j = 0; j < n_faces; j++)
+      for (j = 0; j < g_list_model_get_n_items (G_LIST_MODEL (family)); j++)
        {
-         const char *face_name = pango_font_face_get_face_name (faces[j]);
-         gboolean is_synth = pango_font_face_is_synthesized (faces[j]);
+          PangoFontFace *face = g_list_model_get_item (G_LIST_MODEL (family), j);
+         const char *face_name = pango_font_face_get_face_name (face);
+         gboolean is_synth = pango_font_face_is_synthesized (face);
          const char *synth_str = is_synth ? "*" : "";
           width = MAX (width, strlen (synth_str) + strlen (face_name));
+          g_object_unref (face);
         }
 
-      for (j = 0; j < n_faces; j++)
+      for (j = 0; j < g_list_model_get_n_items (G_LIST_MODEL (family)); j++)
        {
-         const char *face_name = pango_font_face_get_face_name (faces[j]);
-         gboolean is_synth = pango_font_face_is_synthesized (faces[j]);
+          PangoFontFace *face = g_list_model_get_item (G_LIST_MODEL (family), j);
+         const char *face_name = pango_font_face_get_face_name (face);
+         gboolean is_synth = pango_font_face_is_synthesized (face);
          const char *synth_str = is_synth ? "*" : "";
-         PangoFontDescription *desc = pango_font_face_describe (faces[j]);
+         PangoFontDescription *desc = pango_font_face_describe (face);
          char *desc_str = pango_font_description_to_string (desc);
 
          g_print ("  %s%s: %*s%s\n", synth_str, face_name,
@@ -159,7 +158,7 @@ main (int    argc,
             }
 
           if (opt_variations &&
-              pango_font_family_is_variable (families[i]))
+              pango_font_family_is_variable (family))
             {
               PangoFont *font;
               hb_font_t *hb_font;
@@ -201,13 +200,11 @@ main (int    argc,
                 }
             }
 
-         g_free (desc_str);
-         pango_font_description_free (desc);
-       }
-
-      g_free (faces);
+          g_free (desc_str);
+          pango_font_description_free (desc);
+          g_object_unref (face);
+        }
     }
-  g_free (families);
   g_object_unref (ctx);
   g_object_unref (fontmap);
 


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