Pango aliases patch.



Here is a new version of the pango common aliases patch.

Comments?

/ Alex

Index: pango/pango-context.c
===================================================================
RCS file: /cvs/gnome/pango/pango/pango-context.c,v
retrieving revision 1.42
diff -u -p -r1.42 pango-context.c
--- pango/pango-context.c	2001/09/19 23:44:50	1.42
+++ pango/pango-context.c	2001/10/02 02:37:28
@@ -35,7 +35,7 @@ struct _PangoContext
   PangoDirection base_dir;
   PangoFontDescription *font_desc;
 
-  GSList *font_maps;
+  PangoFontMap *font_map;
 };
 
 struct _PangoContextClass
@@ -92,7 +92,7 @@ pango_context_init (PangoContext *contex
 {
   context->base_dir = PANGO_DIRECTION_LTR;
   context->language = NULL;
-  context->font_maps = NULL;
+  context->font_map = NULL;
 
   context->font_desc = pango_font_description_new ();
   pango_font_description_set_family (context->font_desc, "serif");
@@ -120,8 +120,8 @@ pango_context_finalize (GObject *object)
 
   context = PANGO_CONTEXT (object);
 
-  g_slist_foreach (context->font_maps, (GFunc)g_object_unref, NULL);
-  g_slist_free (context->font_maps);
+  if (context->font_map)
+    g_object_unref (G_OBJECT(context->font_map));
 
   pango_font_description_free (context->font_desc);
   
@@ -147,39 +147,24 @@ pango_context_new (void)
 }
 
 /**
- * pango_context_add_font_map:
+ * pango_context_set_font_map:
  * @context: a #PangoContext
- * @font_map: the #PangoFontMap to add.
+ * @font_map: the #PangoFontMap to set.
  * 
- * Add a font map to the list of font maps that are searched for fonts
- * when fonts are looked-up in this context.
+ * Sets the font map to be searched when fonts are looked-up in this context.
  **/
 void
-pango_context_add_font_map (PangoContext *context,
+pango_context_set_font_map (PangoContext *context,
 			    PangoFontMap *font_map)
 {
   g_return_if_fail (context != NULL);
   g_return_if_fail (font_map != NULL);
-  
-  g_object_ref (G_OBJECT (font_map));
-  context->font_maps =  g_slist_append (context->font_maps, font_map);
-}
-
-typedef struct
-{
-  int n_found;
-  PangoFontFamily **families;
-} ListFamiliesInfo;
 
-static void
-list_families_foreach (gpointer key, gpointer value, gpointer user_data)
-{
-  ListFamiliesInfo *info = user_data;
-
-  if (info->families)
-    info->families[info->n_found++] = value;
+  if (context->font_map)
+    g_object_unref (G_OBJECT (context->font_map));
 
-  g_free (value);
+  g_object_ref (G_OBJECT (font_map));
+  context->font_map = font_map;
 }
 
 /**
@@ -196,75 +181,22 @@ pango_context_list_families (PangoContex
 			     PangoFontFamily     ***families,
 			     int                   *n_families)
 {
-  int n_maps;
-  
   g_return_if_fail (context != NULL);
   g_return_if_fail (families == NULL || n_families != NULL);
 
   if (n_families == NULL)
     return;
   
-  n_maps = g_slist_length (context->font_maps);
-  
-  if (n_maps == 0)
+  if (context->font_map == NULL)
     {
       *n_families = 0;
       if (families)
 	*families = NULL;
       
       return;
-    }
-  else if (n_maps == 1)
-
-    pango_font_map_list_families (context->font_maps->data, families, n_families);
-  else
-    {
-      GHashTable *family_hash;
-      GSList *tmp_list;
-      ListFamiliesInfo info;
-
-      *n_families = 0;
-
-      family_hash = g_hash_table_new (g_str_hash, g_str_equal);
-
-      tmp_list = context->font_maps;
-      while (tmp_list)
-	{
-	  PangoFontFamily **tmp_families;
-	  int tmp_n_families;
-	  int i;
-	  
-	  pango_font_map_list_families (tmp_list->data, &tmp_families, &tmp_n_families);
-
-	  for (i=0; i<*n_families; i++)
-	    {
-	      const char *family = pango_font_family_get_name (tmp_families[i]);
-		  
-	      if (!g_hash_table_lookup (family_hash, tmp_families[i]))
-		{
-		  g_hash_table_insert (family_hash, (char *)family, tmp_families[i]);
-		  (*n_families)++;
-		}
-	    }
-	  
-	  g_free (tmp_families);
-
-	  tmp_list = tmp_list->next;
-	}
-
-      info.n_found = 0;
-
-      if (families)
-	{
-	  *families = g_new (PangoFontFamily *, *n_families);
-	  info.families = *families;
-	}
-      else
-	info.families = NULL;
-	  
-      g_hash_table_foreach (family_hash, list_families_foreach, &info);
-      g_hash_table_destroy (family_hash);
     }
+  else 
+    pango_font_map_list_families (context->font_map, families, n_families);
 }
 
 /**
@@ -281,23 +213,9 @@ PangoFont *
 pango_context_load_font (PangoContext               *context,
 			 const PangoFontDescription *desc)
 {
-  GSList *tmp_list;
-
   g_return_val_if_fail (context != NULL, NULL);
-
-  tmp_list = context->font_maps;
-  while (tmp_list)
-    {
-      PangoFont *font;
-      
-      font = pango_font_map_load_font (tmp_list->data, desc);
-      if (font)
-	return font;
-      
-      tmp_list = tmp_list->next;
-    }
 
-  return NULL;
+  return  pango_font_map_load_font (context->font_map, desc);
 }
 
 /**
@@ -610,16 +528,13 @@ static PangoEngineShape fallback_shaper 
   fallback_engine_get_coverage
 };
 
-/* FIXME: Remove this artificial limit */
-#define MAX_FAMILIES 16
-
 typedef struct _FontSet FontSet;
 
 struct _FontSet
 {
   int n_families;
-  PangoFont *fonts[MAX_FAMILIES];
-  PangoCoverage *coverages[MAX_FAMILIES];  
+  PangoFont **fonts;
+  PangoCoverage **coverages;  
 };
 
 #define FONT_SET_INITIALIZER { 0, }
@@ -663,7 +578,12 @@ font_set_free (FontSet *font_set)
 	  pango_coverage_unref (font_set->coverages[j]);
 	}
     }
+  g_free (font_set->fonts);
+  font_set->fonts = NULL;
 
+  g_free (font_set->coverages);
+  font_set->coverages = NULL;
+
   font_set->n_families = 0;
 }
 
@@ -673,87 +593,16 @@ font_set_load (FontSet                  
 	       PangoLanguage              *language,
 	       const PangoFontDescription *desc)
 {
-  PangoFontDescription *tmp_desc = pango_font_description_copy_static (desc);
-  char **families;
   int j;
 
   font_set_free (font_set);
-
-  families = g_strsplit (pango_font_description_get_family (desc), ",", -1);
-
-  font_set->n_families = 0;
-  for (j=0; families[j] && font_set->n_families < MAX_FAMILIES; j++)
-    {
-      pango_font_description_set_family_static (tmp_desc, families[j]);
-      font_set->fonts[font_set->n_families] = pango_context_load_font (context, tmp_desc);
-      
-      if (font_set->fonts[font_set->n_families])
-	{
-	  font_set->coverages[font_set->n_families] = pango_font_get_coverage (font_set->fonts[font_set->n_families], language);
-	  (font_set->n_families)++;
-	}
-    }
-  
-  g_strfreev (families);
-  pango_font_description_set_family_static (tmp_desc, pango_font_description_get_family (desc));
-
-  /* The font description was completely unloadable, try with
-   * family == "Sans"
-   */
-  if (font_set->n_families == 0)
-    {
-      char *ctmp1, *ctmp2;
-      
-      ctmp1 = pango_font_description_to_string (desc);
-      pango_font_description_set_family_static (tmp_desc, "Sans");
-      ctmp2 = pango_font_description_to_string (tmp_desc);
-      
-      g_warning ("Couldn't load font \"%s\" falling back to \"%s\"", ctmp1, ctmp2);
-      g_free (ctmp1);
-      g_free (ctmp2);
-      
-      font_set->fonts[0] = pango_context_load_font (context, tmp_desc);
-      if (font_set->fonts[0])
-	{
-	  font_set->coverages[0] = pango_font_get_coverage (font_set->fonts[0], language);
-	  font_set->n_families = 1;
-	}
-    }
-  
-  /* We couldn't try with Sans and the specified style. Try Sans Normal
-   */
-  if (font_set->n_families == 0)
-    {
-      char *ctmp1, *ctmp2;
-      
-      ctmp1 = pango_font_description_to_string (tmp_desc);
-      pango_font_description_set_style (tmp_desc, PANGO_STYLE_NORMAL);
-      pango_font_description_set_weight (tmp_desc, PANGO_WEIGHT_NORMAL);
-      pango_font_description_set_variant (tmp_desc, PANGO_VARIANT_NORMAL);
-      pango_font_description_set_stretch (tmp_desc, PANGO_STRETCH_NORMAL);
-      ctmp2 = pango_font_description_to_string (tmp_desc);
-      
-      g_warning ("Couldn't load font \"%s\" falling back to \"%s\"", ctmp1, ctmp2);
-      g_free (ctmp1);
-      g_free (ctmp2);
-      
-      font_set->fonts[0] = pango_context_load_font (context, tmp_desc);
-      if (font_set->fonts[0])
-	{
-	  font_set->coverages[0] = pango_font_get_coverage (font_set->fonts[0], language);
-	  font_set->n_families = 1;
-	}
-    }
-
-  /* Everything failed, we are screwed, there is no way to continue
-   */
-  if (font_set->n_families == 0)
-    {
-      g_warning ("All font failbacks failed!!!!");
-      exit (1);
-    }
-
-  pango_font_description_free (tmp_desc);
+  font_set->n_families = pango_font_map_load_fonts (context->font_map,
+						    desc,
+						    &font_set->fonts);
+
+  font_set->coverages = g_new (PangoCoverage *, font_set->n_families);
+  for (j = 0; j < font_set->n_families; j++)
+    font_set->coverages[j] = pango_font_get_coverage (font_set->fonts[j], language);
 }
 
 static gboolean
@@ -930,7 +779,7 @@ pango_context_get_metrics (PangoContext 
 			   PangoLanguage                *language)
 {
   FontSet current_fonts = FONT_SET_INITIALIZER;
-  PangoFontMetrics *raw_metrics[MAX_FAMILIES];
+  PangoFontMetrics **raw_metrics;
   PangoFontMetrics *metrics;
   const char *sample_str;
   const char *p;
@@ -950,10 +799,8 @@ pango_context_get_metrics (PangoContext 
       int count = 0;
 
       metrics = pango_font_metrics_new ();
+      raw_metrics = g_new0 (PangoFontMetrics *, current_fonts.n_families);
 
-      for (i=0; i < MAX_FAMILIES; i++)
-	raw_metrics[i] = NULL;
-  
       p = sample_str;
       while (*p)
 	{
@@ -976,12 +823,14 @@ pango_context_get_metrics (PangoContext 
 	  count++;
 	}
 
-      for (i=0; i < MAX_FAMILIES; i++)
+      for (i = 0; i < current_fonts.n_families; i++)
 	if (raw_metrics[i])
 	  pango_font_metrics_unref (raw_metrics[i]);
 
       metrics->approximate_char_width /= count;
       metrics->approximate_digit_width /= count;
+
+      g_free (raw_metrics);
     }
       
   font_set_free (&current_fonts);
Index: pango/pango-context.h
===================================================================
RCS file: /cvs/gnome/pango/pango/pango-context.h,v
retrieving revision 1.14
diff -u -p -r1.14 pango-context.h
--- pango/pango-context.h	2001/09/18 20:05:17	1.14
+++ pango/pango-context.h	2001/10/02 02:37:28
@@ -50,7 +50,7 @@ GType         pango_context_get_type    
 
 #ifdef PANGO_ENABLE_BACKEND
 PangoContext *pango_context_new           (void);
-void          pango_context_add_font_map  (PangoContext                 *context,
+void          pango_context_set_font_map  (PangoContext                 *context,
 					   PangoFontMap                 *font_map);
 #endif /* PANGO_ENABLE_BACKEND */
 
Index: pango/pango-fontmap.c
===================================================================
RCS file: /cvs/gnome/pango/pango/pango-fontmap.c,v
retrieving revision 1.6
diff -u -p -r1.6 pango-fontmap.c
--- pango/pango-fontmap.c	2001/09/19 23:44:50	1.6
+++ pango/pango-fontmap.c	2001/10/02 02:37:28
@@ -20,7 +20,14 @@
  */
 
 #include "pango-fontmap.h"
+#include "pango-utils.h"
+#include <stdlib.h>
 
+static void  pango_font_map_class_init      (PangoFontMapClass            *class);
+static int   pango_font_map_real_load_fonts (PangoFontMap                 *fontmap,
+					     const PangoFontDescription   *desc,
+					     PangoFont                  ***fonts);
+
 GType
 pango_font_map_get_type (void)
 {
@@ -33,7 +40,7 @@ pango_font_map_get_type (void)
         sizeof (PangoFontMapClass),
         (GBaseInitFunc) NULL,
         (GBaseFinalizeFunc) NULL,
-        NULL,           /* class_init */
+        (GClassInitFunc) pango_font_map_class_init,
         NULL,           /* class_finalize */
         NULL,           /* class_data */
         sizeof (PangoFontMap),
@@ -49,6 +56,13 @@ pango_font_map_get_type (void)
   return object_type;
 }
 
+
+static void
+pango_font_map_class_init (PangoFontMapClass *class)
+{
+  class->load_fonts = pango_font_map_real_load_fonts;
+}
+
 /**
  * pango_font_map_load_font:
  * @fontmap: a #PangoFontMap
@@ -84,4 +98,134 @@ pango_font_map_list_families (PangoFontM
   g_return_if_fail (fontmap != NULL);
 
   PANGO_FONT_MAP_GET_CLASS (fontmap)->list_families (fontmap, families, n_families);
+}
+
+int
+pango_font_map_load_fonts (PangoFontMap                 *fontmap,
+			   const PangoFontDescription   *desc,
+			   PangoFont                  ***fonts)
+{
+  g_return_val_if_fail (fontmap != NULL, 0);
+
+  return PANGO_FONT_MAP_GET_CLASS (fontmap)->load_fonts (fontmap, desc, fonts);
+}
+
+void
+pango_font_map_fontset_add_fonts (PangoFontMap          *fontmap,
+				  GPtrArray             *fonts,
+				  PangoFontDescription  *desc,
+				  char                  *family)
+{
+  char **aliases;
+  int n_aliases;
+  int j;
+  PangoFont *font;
+
+  n_aliases = pango_lookup_aliases (family,
+				    &aliases);
+      
+  if (n_aliases)
+    {
+      for (j = 0; j < n_aliases; j++)
+	{
+	  pango_font_description_set_family_static (desc, aliases[j]);
+	  font = pango_font_map_load_font (fontmap, desc);
+	  if (font)
+	    g_ptr_array_add (fonts, font);
+	}
+    }
+  else
+    {
+      pango_font_description_set_family_static (desc, family);
+      font = pango_font_map_load_font (fontmap, desc);
+      if (font)
+	g_ptr_array_add (fonts, font);
+    }
+}
+
+static int
+pango_font_map_real_load_fonts (PangoFontMap                 *fontmap,
+				const PangoFontDescription   *desc,
+				PangoFont                  ***fonts_out)
+{
+  PangoFontDescription *tmp_desc = pango_font_description_copy_static (desc);
+  char **families;
+  int i, num;
+  GPtrArray *fonts;
+
+  families = g_strsplit (pango_font_description_get_family (desc), ",", -1);
+
+  num = 0;
+  while (families[num])
+    num++;
+
+  fonts = g_ptr_array_sized_new (num);
+  
+  for (i = 0; families[i]; i++)
+    pango_font_map_fontset_add_fonts (fontmap,
+				      fonts,
+				      tmp_desc,
+				      families[i]);
+  
+  g_strfreev (families);
+  pango_font_description_set_family_static (tmp_desc,
+					    pango_font_description_get_family (desc));
+
+  /* The font description was completely unloadable, try with
+   * family == "Sans"
+   */
+  if (fonts->len == 0)
+    {
+      char *ctmp1, *ctmp2;
+      
+      ctmp1 = pango_font_description_to_string (desc);
+      pango_font_description_set_family_static (tmp_desc, "Sans");
+      ctmp2 = pango_font_description_to_string (tmp_desc);
+      
+      g_warning ("Couldn't load font \"%s\" falling back to \"%s\"", ctmp1, ctmp2);
+      g_free (ctmp1);
+      g_free (ctmp2);
+      
+      pango_font_map_fontset_add_fonts (fontmap,
+					fonts,
+					tmp_desc,
+					"Sans");
+    }
+  
+  /* We couldn't try with Sans and the specified style. Try Sans Normal
+   */
+  if (fonts->len == 0)
+    {
+      char *ctmp1, *ctmp2;
+      
+      pango_font_description_set_family_static (tmp_desc, "Sans");
+      ctmp1 = pango_font_description_to_string (tmp_desc);
+      pango_font_description_set_style (tmp_desc, PANGO_STYLE_NORMAL);
+      pango_font_description_set_weight (tmp_desc, PANGO_WEIGHT_NORMAL);
+      pango_font_description_set_variant (tmp_desc, PANGO_VARIANT_NORMAL);
+      pango_font_description_set_stretch (tmp_desc, PANGO_STRETCH_NORMAL);
+      ctmp2 = pango_font_description_to_string (tmp_desc);
+      
+      g_warning ("Couldn't load font \"%s\" falling back to \"%s\"", ctmp1, ctmp2);
+      g_free (ctmp1);
+      g_free (ctmp2);
+      
+      pango_font_map_fontset_add_fonts (fontmap,
+					fonts,
+					tmp_desc,
+					"Sans");
+    }
+
+  /* Everything failed, we are screwed, there is no way to continue
+   */
+  if (fonts->len == 0)
+    {
+      g_warning ("All font failbacks failed!!!!");
+      exit (1);
+    }
+
+  num = fonts->len;
+  *fonts_out = (PangoFont **)g_ptr_array_free (fonts, FALSE);
+ 
+  return num;
 }
Index: pango/pango-fontmap.h
===================================================================
RCS file: /cvs/gnome/pango/pango/pango-fontmap.h,v
retrieving revision 1.5
diff -u -p -r1.5 pango-fontmap.h
--- pango/pango-fontmap.h	2001/09/18 20:05:17	1.5
+++ pango/pango-fontmap.h	2001/10/02 02:37:28
@@ -35,6 +35,9 @@ typedef struct _PangoFontMap PangoFontMa
 GType      pango_font_map_get_type       (void) G_GNUC_CONST;
 PangoFont *pango_font_map_load_font     (PangoFontMap                 *fontmap,
 					 const PangoFontDescription   *desc);
+int        pango_font_map_load_fonts    (PangoFontMap                 *fontmap,
+					 const PangoFontDescription   *desc,
+					 PangoFont                  ***fonts);
 void       pango_font_map_list_families (PangoFontMap                 *fontmap,
 					 PangoFontFamily            ***families,
 					 int                          *n_families);
@@ -61,6 +64,9 @@ struct _PangoFontMapClass
   void       (*list_families) (PangoFontMap               *fontmap,
 			       PangoFontFamily          ***families,
 			       int                        *n_families);
+  int        (*load_fonts)    (PangoFontMap               *fontmap,
+			       const PangoFontDescription *desc,
+			       PangoFont                ***fonts);
 };
 
 #endif /* PANGO_ENABLE_BACKEND */
Index: pango/pango-utils.c
===================================================================
RCS file: /cvs/gnome/pango/pango/pango-utils.c,v
retrieving revision 1.24
diff -u -p -r1.24 pango-utils.c
--- pango/pango-utils.c	2001/09/27 16:10:37	1.24
+++ pango/pango-utils.c	2001/10/02 02:37:28
@@ -48,6 +48,15 @@
 
 #endif
 
+struct PangoAlias {
+  gchar *alias;
+  int n_families;
+  gchar **families;
+  gboolean visible; /* Do we want/need this? */
+};
+
+GHashTable *pango_aliases_ht = NULL;
+
 /**
  * pango_trim_string:
  * @str: a string
@@ -546,7 +555,7 @@ read_config_file (const char *filename, 
     }
       
   if (ferror (file))
-    errstring = g_strdup ("g_strerror(errno)");
+    errstring = g_strdup (g_strerror(errno));
   
  error:
 
@@ -1162,3 +1171,238 @@ pango_get_mirror_char (gunichar        c
 }
 
 #endif /* HAVE_FRIBIDI */
+
+
+guint
+alias_hash (struct PangoAlias *alias)
+{
+  return g_str_hash (alias->alias);
+}
+
+gboolean
+alias_equal (struct PangoAlias *alias1,
+	     struct PangoAlias *alias2)
+{
+  return g_str_equal (alias1->alias,
+		      alias2->alias);
+}
+
+
+void
+alias_free (struct PangoAlias *alias)
+{
+  int i;
+  g_free (alias->alias);
+
+  for (i = 0; i < alias->n_families; i++)
+    g_free (alias->families[i]);
+
+  g_free (alias->families);
+  
+  g_free (alias);
+}
+
+static void
+read_alias_file (const gchar *filename)
+{
+  FILE *file;
+    
+  GString *line_buffer;
+  GString *tmp_buffer1;
+  GString *tmp_buffer2;
+  char *errstring = NULL;
+  const char *pos;
+  int line = 0;
+  struct PangoAlias alias_key;
+  struct PangoAlias *alias;
+  char **new_families;
+  int n_new;
+  int i;
+
+  file = fopen (filename, "r");
+  if (!file)
+    return;
+
+  line_buffer = g_string_new (NULL);
+  tmp_buffer1 = g_string_new (NULL);
+  tmp_buffer2 = g_string_new (NULL);
+
+  while (pango_read_line (file, line_buffer))
+    {
+      gboolean empty = FALSE;
+      gboolean append = FALSE;
+      line++;
+
+      pos = line_buffer->str;
+      if (!pango_skip_space (&pos))
+	continue;
+      
+      if (!pango_scan_word (&pos, tmp_buffer1) ||
+	  !pango_skip_space (&pos))
+	{
+	  errstring = g_strdup ("Line is not of the form KEY=VALUE or KEY+=VALUE");
+	  goto error;
+	}
+      
+      if (*pos == '+')
+	{
+	  append = TRUE;
+	  pos++;
+	}
+
+      if (*(pos++) != '=')
+	{
+	  errstring = g_strdup ("Line is not of the form KEY=VALUE or KEY+=VALUE");
+	  goto error;
+	}
+      
+      if (!pango_skip_space (&pos))
+	{
+	  empty = TRUE;
+	}
+      else
+	{
+	  if (!pango_scan_string (&pos, tmp_buffer2))
+	    {
+	      errstring = g_strdup ("Error parsing value string");
+	      goto error;
+	    }
+	  if (pango_skip_space (&pos))
+	    {
+	      errstring = g_strdup ("Junk after value string");
+	      goto error;
+	    }
+	}
+
+      alias_key.alias = g_ascii_strdown (tmp_buffer1->str, -1);
+      
+      /* Remove any existing values */
+      alias = g_hash_table_lookup (pango_aliases_ht, &alias_key);
+      
+      if (!alias)
+	{
+	  alias = g_new0 (struct PangoAlias, 1);
+	  alias->alias = alias_key.alias;
+	  
+	  g_hash_table_insert (pango_aliases_ht,
+			       alias, alias);
+	}
+      else
+	g_free (alias_key.alias);
+	  
+      new_families = g_strsplit (tmp_buffer2->str, ",", -1);
+      
+      n_new = 0;
+      while (new_families[n_new])
+	n_new++;
+      
+      if (alias->families && append)
+	{
+	  alias->families = g_realloc (alias->families,
+				       sizeof (char *) *(n_new + alias->n_families));
+	  for (i = 0; i < n_new; i++)
+	    alias->families[alias->n_families + i] = new_families[i];
+	  g_free (new_families);
+	  alias->n_families += n_new;
+	}
+      else
+	{
+	  for (i = 0; i < alias->n_families; i++)
+	    g_free (alias->families[i]);
+	  g_free (alias->families);
+	  
+	  alias->families = new_families;
+	  alias->n_families = n_new;
+	}
+    }
+
+  if (ferror (file))
+    errstring = g_strdup (g_strerror(errno));
+  
+ error:
+
+  if (errstring)
+    {
+      fprintf (stderr, "Pango:%s:%d: %s\n", filename, line, errstring);
+      g_free (errstring);
+    }
+      
+  g_string_free (line_buffer, TRUE);
+  g_string_free (tmp_buffer1, TRUE);
+  g_string_free (tmp_buffer2, TRUE);
+
+  fclose (file);
+}
+
+void
+pango_load_aliases (void)
+{
+  char *filename;
+  const char *home;
+
+  pango_aliases_ht = g_hash_table_new_full ((GHashFunc)alias_hash,
+					    (GEqualFunc)alias_equal,
+					    (GDestroyNotify)alias_free,
+					    NULL);
+
+
+  filename = g_strconcat (pango_get_sysconf_subdirectory (),
+			  G_DIR_SEPARATOR_S "pango.aliases",
+			  NULL);
+  read_alias_file (filename);
+  g_free (filename);
+  
+  home = g_get_home_dir ();
+  if (home && *home)
+    {
+      filename = g_strconcat (home,
+			      G_DIR_SEPARATOR_S ".pango.aliases",
+			      NULL);
+      read_alias_file (filename);
+      g_free (filename);
+    }
+}
+
+
+/**
+ * pango_lookup_aliases:
+ * @fontname: an ascii string
+ * @families: will be set to an array of font family names.
+ *    this array is owned by pango and should not be freed.
+ *
+ * Look up all user defined aliases for the alias #fontname.
+ * The resulting font family names will be stored in #families,
+ * and the number of families will be returned.
+ * 
+ * Return value: the number of font famillies stored in the #families argument.
+ *   This value is owned by Pango and must not be freed.
+ **/
+gint
+pango_lookup_aliases (const gchar   *fontname,
+		      gchar       ***families)
+{
+  struct PangoAlias alias_key;
+  struct PangoAlias *alias;
+  
+  if (pango_aliases_ht == NULL)
+    pango_load_aliases ();
+
+
+  alias_key.alias = g_ascii_strdown (fontname, -1);
+  alias = g_hash_table_lookup (pango_aliases_ht, &alias_key);
+  g_free (alias_key.alias);
+
+  if (alias)
+    {
+      *families = alias->families;
+      return alias->n_families;
+    }
+
+  *families = NULL;
+  return 0;
+}
+
+
+
+
+
Index: pango/pango-utils.h
===================================================================
RCS file: /cvs/gnome/pango/pango/pango-utils.h,v
retrieving revision 1.13
diff -u -p -r1.13 pango-utils.h
--- pango/pango-utils.h	2001/09/18 20:05:17	1.13
+++ pango/pango-utils.h	2001/10/02 02:37:28
@@ -40,6 +40,10 @@ gboolean pango_scan_int       (const cha
 
 char *   pango_config_key_get (const char  *key);
 
+gint     pango_lookup_aliases (const char   *fontname,
+			       char       ***families);
+
+
 #endif /* PANGO_ENABLE_BACKEND */
 
 /* Functions for parsing textual representations
Index: pango/pangoft2.c
===================================================================
RCS file: /cvs/gnome/pango/pango/pangoft2.c,v
retrieving revision 1.24
diff -u -p -r1.24 pangoft2.c
--- pango/pangoft2.c	2001/09/18 20:05:17	1.24
+++ pango/pangoft2.c	2001/10/02 02:37:28
@@ -167,7 +167,7 @@ pango_ft2_get_context (void)
     }
   
   result = pango_context_new ();
-  pango_context_add_font_map (result, pango_ft2_font_map_for_display ());
+  pango_context_set_font_map (result, pango_ft2_font_map_for_display ());
 
   return result;
 }
Index: pango/pangowin32.c
===================================================================
RCS file: /cvs/gnome/pango/pango/pangowin32.c,v
retrieving revision 1.26
diff -u -p -r1.26 pangowin32.c
--- pango/pangowin32.c	2001/09/21 19:51:32	1.26
+++ pango/pangowin32.c	2001/10/02 02:37:29
@@ -130,7 +130,7 @@ pango_win32_get_context (void)
     }
 
   result = pango_context_new ();
-  pango_context_add_font_map (result, pango_win32_font_map_for_display ());
+  pango_context_set_font_map (result, pango_win32_font_map_for_display ());
 
   return result;
 }
Index: pango/pangox.c
===================================================================
RCS file: /cvs/gnome/pango/pango/pangox.c,v
retrieving revision 1.64
diff -u -p -r1.64 pangox.c
--- pango/pangox.c	2001/09/18 20:05:18	1.64
+++ pango/pangox.c	2001/10/02 02:37:29
@@ -275,7 +275,7 @@ pango_x_get_context (Display *display)
                            g_quark_from_static_string ("pango-x-info"),
                            info, (GDestroyNotify)g_free);
   
-  pango_context_add_font_map (result, pango_x_font_map_for_display (display));
+  pango_context_set_font_map (result, pango_x_font_map_for_display (display));
 
   return result;
 }
Index: pango/pangoxft-fontmap.c
===================================================================
RCS file: /cvs/gnome/pango/pango/pangoxft-fontmap.c,v
retrieving revision 1.6
diff -u -p -r1.6 pangoxft-fontmap.c
--- pango/pangoxft-fontmap.c	2001/09/18 20:05:18	1.6
+++ pango/pangoxft-fontmap.c	2001/10/02 02:37:29
@@ -201,7 +201,7 @@ pango_xft_get_context (Display *display,
     }
   
   result = pango_context_new ();
-  pango_context_add_font_map (result, pango_xft_get_font_map (display, screen));
+  pango_context_set_font_map (result, pango_xft_get_font_map (display, screen));
 
   return result;
 }





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