Re: Pango global font aliases
- From: Alex Larsson <alexl redhat com>
- To: <gtk-devel-list gnome org>
- Subject: Re: Pango global font aliases
- Date: Sat, 8 Sep 2001 22:33:52 -0400 (EDT)
On Sat, 8 Sep 2001, Alex Larsson wrote:
> Currently some pango backend has some own magic for doing aliases, and
> some doesn't support any, and some of it is handled in the generic code.
Here is a patch. This moves the font family name list to font resolution
to the backend, so it can do backend specific things. Global user aliased
are specified in /etc/pango/pango.aliases and/or ~/.pango.aliases, and can
be used in specific backend PangoFontMaps. It is used in the default one.
I'm not sure how this integrates with the work keith mentioned. Can we use
the XFree fontmatch stuff on win32, or do we just push it into the Xft and
FT2 backends.
/ Alex
Index: pango/pango-context.c
===================================================================
RCS file: /cvs/gnome/pango/pango/pango-context.c,v
retrieving revision 1.40
diff -u -p -r1.40 pango-context.c
--- pango/pango-context.c 2001/07/19 20:49:00 1.40
+++ pango/pango-context.c 2001/09/09 02:18:52
@@ -35,7 +35,7 @@ struct _PangoContext
PangoDirection base_dir;
PangoFontDescription *font_desc;
- GSList *font_maps;
+ PangoFontMap *font_map;
};
struct _PangoContextClass
@@ -94,7 +94,7 @@ pango_context_init (PangoContext *contex
context->base_dir = PANGO_DIRECTION_LTR;
context->language = NULL;
- context->font_maps = NULL;
+ context->font_map = NULL;
desc.family_name = "serif";
desc.style = PANGO_STYLE_NORMAL;
@@ -123,8 +123,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);
@@ -150,22 +150,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);
-
+
+ if (context->font_map)
+ g_object_unref (G_OBJECT (context->font_map));
+
g_object_ref (G_OBJECT (font_map));
- context->font_maps = g_slist_append (context->font_maps, font_map);
+ context->font_map = font_map;
}
/**
@@ -187,87 +189,21 @@ pango_context_list_fonts (PangoContext
PangoFontDescription ***descs,
int *n_descs)
{
- int n_maps;
-
g_return_if_fail (context != NULL);
g_return_if_fail (descs == NULL || n_descs != NULL);
if (n_descs == 0)
return;
- n_maps = g_slist_length (context->font_maps);
-
- if (n_maps == 0)
+ if (context->font_map == NULL)
{
*n_descs = 0;
if (descs)
*descs = NULL;
return;
}
- else if (n_maps == 1)
- pango_font_map_list_fonts (context->font_maps->data, family, descs, n_descs);
- else
- {
- /* FIXME: This does not properly suppress duplicate fonts! */
-
- PangoFontDescription ***tmp_descs;
- int *tmp_n_descs;
- int total_n_descs = 0;
- GSList *tmp_list;
- int i;
-
- tmp_descs = g_new (PangoFontDescription **, n_maps);
- tmp_n_descs = g_new (int, n_maps);
-
- *n_descs = 0;
-
- tmp_list = context->font_maps;
- for (i = 0; i<n_maps; i++)
- {
- pango_font_map_list_fonts (tmp_list->data, family, &tmp_descs[i], &tmp_n_descs[i]);
- *n_descs += tmp_n_descs[i];
-
- tmp_list = tmp_list->next;
- }
-
- if (descs)
- {
- *descs = g_new (PangoFontDescription *, *n_descs);
-
- total_n_descs = 0;
- for (i = 0; i<n_maps; i++)
- {
- memcpy (&(*descs)[total_n_descs], tmp_descs[i], tmp_n_descs[i] * sizeof (PangoFontDescription *));
- total_n_descs += tmp_n_descs[i];
- pango_font_descriptions_free (tmp_descs[i], tmp_n_descs[i]);
- }
- }
- else
- {
- for (i = 0; i<n_maps; i++)
- pango_font_descriptions_free (tmp_descs[i], tmp_n_descs[i]);
- }
-
- g_free (tmp_descs);
- g_free (tmp_n_descs);
- }
-}
-
-typedef struct
-{
- int n_found;
- char **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;
-
- g_free (value);
+ pango_font_map_list_fonts (context->font_map, family, descs, n_descs);
}
/**
@@ -284,74 +220,22 @@ pango_context_list_families (PangoContex
gchar ***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)
- {
- char **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++)
- {
- if (!g_hash_table_lookup (family_hash, tmp_families[i]))
- {
- char *family = g_strdup (tmp_families[i]);
-
- g_hash_table_insert (family_hash, family, family);
- (*n_families)++;
- }
- }
-
- pango_font_map_free_families (tmp_families, tmp_n_families);
-
- tmp_list = tmp_list->next;
- }
-
- info.n_found = 0;
-
- if (families)
- {
- *families = g_new (char *, *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);
}
/**
@@ -368,23 +252,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);
}
/**
@@ -697,16 +567,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, }
@@ -750,7 +617,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;
}
@@ -760,87 +632,17 @@ font_set_load (FontSet *fon
PangoLanguage *language,
PangoFontDescription *desc)
{
- PangoFontDescription tmp_desc = *desc;
- char **families;
int j;
font_set_free (font_set);
-
- families = g_strsplit (desc->family_name, ",", -1);
-
- font_set->n_families = 0;
- for (j=0; families[j] && font_set->n_families < MAX_FAMILIES; j++)
- {
- tmp_desc.family_name = 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);
- tmp_desc.family_name = desc->family_name;
- /* 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);
- tmp_desc.family_name = "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);
-
- tmp_desc.family_name = "Sans";
-
- 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);
- tmp_desc.style = PANGO_STYLE_NORMAL;
- tmp_desc.weight = PANGO_WEIGHT_NORMAL;
- tmp_desc.variant = PANGO_VARIANT_NORMAL;
- tmp_desc.stretch = 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);
- }
+ 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
@@ -1013,12 +815,11 @@ pango_context_get_metrics (PangoContext
PangoFontMetrics *metrics)
{
FontSet current_fonts = FONT_SET_INITIALIZER;
- PangoFontMetrics raw_metrics[MAX_FAMILIES];
- gboolean have_metrics[MAX_FAMILIES];
+ PangoFontMetrics *raw_metrics;
+ gboolean *have_metrics;
PangoFontDescription tmp_desc = *desc;
const char *sample_str;
const char *p;
- int i;
g_return_if_fail (PANGO_IS_CONTEXT (context));
g_return_if_fail (desc != NULL);
@@ -1028,15 +829,15 @@ pango_context_get_metrics (PangoContext
font_set_load (¤t_fonts, context, language, &tmp_desc);
- for (i=0; i < MAX_FAMILIES; i++)
- have_metrics[i] = FALSE;
-
if (current_fonts.n_families == 1)
pango_font_get_metrics (current_fonts.fonts[0], language, metrics);
else
{
int count = 0;
+ raw_metrics = g_new (PangoFontMetrics, current_fonts.n_families);
+ have_metrics = g_new0 (gboolean, current_fonts.n_families);
+
p = sample_str;
while (*p)
{
@@ -1064,6 +865,9 @@ pango_context_get_metrics (PangoContext
metrics->approximate_char_width /= count;
metrics->approximate_digit_width /= count;
+
+ g_free (raw_metrics);
+ g_free (have_metrics);
}
font_set_free (¤t_fonts);
Index: pango/pango-context.h
===================================================================
RCS file: /cvs/gnome/pango/pango/pango-context.h,v
retrieving revision 1.13
diff -u -p -r1.13 pango-context.h
--- pango/pango-context.h 2001/06/26 19:13:28 1.13
+++ pango/pango-context.h 2001/09/09 02:18:52
@@ -50,7 +50,7 @@ typedef struct _PangoContextClass PangoC
GType pango_context_get_type (void) G_GNUC_CONST;
PangoContext *pango_context_new (void);
-void pango_context_add_font_map (PangoContext *context,
+void pango_context_set_font_map (PangoContext *context,
PangoFontMap *font_map);
void pango_context_list_fonts (PangoContext *context,
const char *family,
Index: pango/pango-fontmap.c
===================================================================
RCS file: /cvs/gnome/pango/pango/pango-fontmap.c,v
retrieving revision 1.4
diff -u -p -r1.4 pango-fontmap.c
--- pango/pango-fontmap.c 2000/10/25 20:36:45 1.4
+++ pango/pango-fontmap.c 2001/09/09 02:18:52
@@ -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
@@ -130,4 +144,133 @@ pango_font_map_free_families (gchar
g_free (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++)
+ {
+ desc->family_name = aliases[j];
+ font = pango_font_map_load_font (fontmap, desc);
+ if (font)
+ g_ptr_array_add (fonts, font);
+ }
+ }
+ else
+ {
+ desc->family_name = 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 = *desc;
+ char **families;
+ int i, num;
+ GPtrArray *fonts;
+
+ families = g_strsplit (desc->family_name, ",", -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);
+ tmp_desc.family_name = desc->family_name;
+
+ /* The font description was completely unloadable, try with
+ * family == "Sans"
+ */
+ if (fonts->len == 0)
+ {
+ char *ctmp1, *ctmp2;
+
+ ctmp1 = pango_font_description_to_string (desc);
+ tmp_desc.family_name = "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;
+
+ tmp_desc.family_name = "Sans";
+ ctmp1 = pango_font_description_to_string (&tmp_desc);
+ tmp_desc.style = PANGO_STYLE_NORMAL;
+ tmp_desc.weight = PANGO_WEIGHT_NORMAL;
+ tmp_desc.variant = PANGO_VARIANT_NORMAL;
+ tmp_desc.stretch = 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.4
diff -u -p -r1.4 pango-fontmap.h
--- pango/pango-fontmap.h 2000/08/30 00:30:59 1.4
+++ pango/pango-fontmap.h 2001/09/09 02:18:52
@@ -57,11 +57,17 @@ struct _PangoFontMapClass
void (*list_families) (PangoFontMap *fontmap,
gchar ***families,
int *n_families);
+ int (*load_fonts) (PangoFontMap *fontmap,
+ const PangoFontDescription *desc,
+ PangoFont ***fonts);
};
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_fonts (PangoFontMap *fontmap,
const gchar *family,
PangoFontDescription ***descs,
Index: pango/pango-utils.c
===================================================================
RCS file: /cvs/gnome/pango/pango/pango-utils.c,v
retrieving revision 1.20
diff -u -p -r1.20 pango-utils.c
--- pango/pango-utils.c 2001/09/02 17:56:49 1.20
+++ pango/pango-utils.c 2001/09/09 02:18:52
@@ -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:
@@ -1161,3 +1170,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);
+
+ /* 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);
+ 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.12
diff -u -p -r1.12 pango-utils.h
--- pango/pango-utils.h 2001/06/26 19:13:28 1.12
+++ pango/pango-utils.h 2001/09/09 02:18:52
@@ -39,6 +39,10 @@ gboolean pango_scan_int (const cha
char * pango_config_key_get (const char *key);
+gint pango_lookup_aliases (const char *fontname,
+ char ***families);
+
+
/* Functions for parsing textual representations
* of PangoFontDescription fields. They return TRUE if the input string
* contains a valid value, which then has been assigned to the corresponding
Index: pango/pangoft2.c
===================================================================
RCS file: /cvs/gnome/pango/pango/pangoft2.c,v
retrieving revision 1.23
diff -u -p -r1.23 pangoft2.c
--- pango/pangoft2.c 2001/08/14 16:14:14 1.23
+++ pango/pangoft2.c 2001/09/09 02:18:52
@@ -168,7 +168,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.24
diff -u -p -r1.24 pangowin32.c
--- pango/pangowin32.c 2001/08/16 04:29:42 1.24
+++ pango/pangowin32.c 2001/09/09 02:18:53
@@ -131,7 +131,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.63
diff -u -p -r1.63 pangox.c
--- pango/pangox.c 2001/07/02 05:02:25 1.63
+++ pango/pangox.c 2001/09/09 02:18:53
@@ -276,7 +276,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.5
diff -u -p -r1.5 pangoxft-fontmap.c
--- pango/pangoxft-fontmap.c 2001/06/29 02:51:24 1.5
+++ pango/pangoxft-fontmap.c 2001/09/09 02:18:53
@@ -198,7 +198,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]