summaryrefslogtreecommitdiff
path: root/pango
diff options
context:
space:
mode:
authorOwen Taylor <otaylor@redhat.com>2000-02-11 06:14:28 +0000
committerOwen Taylor <otaylor@src.gnome.org>2000-02-11 06:14:28 +0000
commitb1c021842d26d5674a51f802f29e2a8496767c55 (patch)
tree58e8cf4cbaa464eaf728fc38e7aa1bbfb1cb24c3 /pango
parent11884d20295c2aea6dfeb8a915dd02b48ec60d9c (diff)
downloadpango-b1c021842d26d5674a51f802f29e2a8496767c55.tar.gz
Add style selector, rewrite family selector to use list_families().
Thu Feb 10 19:57:27 2000 Owen Taylor <otaylor@redhat.com> * examples/viewer.c: Add style selector, rewrite family selector to use list_families(). * libpango/pango-context.[ch] libpango/pango-font.h libpango/pangox.c libpango/fonts.c: Add calls to list families, modify list_fonts() call to take an optional "family" parameter for the purpose of listing the fonts within a family.
Diffstat (limited to 'pango')
-rw-r--r--pango/fonts.c46
-rw-r--r--pango/pango-context.c115
-rw-r--r--pango/pango-context.h4
-rw-r--r--pango/pango-font.h44
-rw-r--r--pango/pangox.c106
5 files changed, 275 insertions, 40 deletions
diff --git a/pango/fonts.c b/pango/fonts.c
index a519daee..b52742aa 100644
--- a/pango/fonts.c
+++ b/pango/fonts.c
@@ -290,20 +290,62 @@ pango_font_map_load_font (PangoFontMap *fontmap,
/**
* pango_font_map_list_fonts:
* @fontmap: a #PangoFontMap
+ * @family: the family for which to list the fonts, or %NULL
+ * to list fonts in all families.
* @descs: location to store a pointer to an array of pointers to
* #PangoFontDescription. This array should be freed
* with pango_font_descriptions_free().
* @n_descs: location to store the number of elements in @descs
*
- * List all fonts in a fontmap.
+ * List all fonts in a fontmap, or the fonts in a particular family.
**/
void
pango_font_map_list_fonts (PangoFontMap *fontmap,
+ const char *family,
PangoFontDescription ***descs,
int *n_descs)
{
g_return_if_fail (fontmap != NULL);
- fontmap->klass->list_fonts (fontmap, descs, n_descs);
+ fontmap->klass->list_fonts (fontmap, family, descs, n_descs);
}
+/**
+ * pango_font_map_list_families:
+ * @fontmap: a #PangoFontMap
+ * @families: location to store a pointer to an array of strings.
+ * This array should be freed with pango_font_map_free_families().
+ * @n_families: location to store the number of elements in @descs
+ *
+ * List all families for a fontmap.
+ **/
+void
+pango_font_map_list_families (PangoFontMap *fontmap,
+ gchar ***families,
+ int *n_families)
+{
+ g_return_if_fail (fontmap != NULL);
+
+ fontmap->klass->list_families (fontmap, families, n_families);
+}
+
+/**
+ * pango_font_map_free_families:
+ * @families: a list of families
+ * @n_families: number of elements in @families
+ *
+ * Free a list of families returned from pango_font_map_list_families()
+ **/
+void
+pango_font_map_free_families (gchar **families,
+ int n_families)
+{
+ int i;
+
+ g_return_if_fail (n_families == 0 || families != NULL);
+
+ for (i=0; i<n_families; i++)
+ g_free (families[i]);
+
+ g_free (families);
+}
diff --git a/pango/pango-context.c b/pango/pango-context.c
index 7a369a86..d9e15c3f 100644
--- a/pango/pango-context.c
+++ b/pango/pango-context.c
@@ -125,6 +125,7 @@ pango_context_add_font_map (PangoContext *context,
**/
void
pango_context_list_fonts (PangoContext *context,
+ const char *family,
PangoFontDescription ***descs,
int *n_descs)
{
@@ -133,21 +134,24 @@ pango_context_list_fonts (PangoContext *context,
g_return_if_fail (context != NULL);
g_return_if_fail (descs == NULL || n_descs != NULL);
- if (n_descs == NULL)
+ if (n_descs == 0)
return;
n_maps = g_slist_length (context->font_maps);
if (n_maps == 0)
{
- if (n_descs)
- *n_descs = 0;
+ *n_descs = 0;
+ if (descs)
+ *descs = NULL;
return;
}
else if (n_maps == 1)
- pango_font_map_list_fonts (context->font_maps->data, descs, n_descs);
+ 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;
@@ -162,7 +166,7 @@ pango_context_list_fonts (PangoContext *context,
tmp_list = context->font_maps;
for (i = 0; i<n_maps; i++)
{
- pango_font_map_list_fonts (tmp_list->data, &tmp_descs[i], &tmp_n_descs[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;
@@ -191,6 +195,107 @@ pango_context_list_fonts (PangoContext *context,
}
}
+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_context_list_families:
+ * @fontmap: a #PangoContext
+ * @families: location to store a pointer to an array of strings.
+ * This array should be freed with pango_font_map_free_families().
+ * @n_families: location to store the number of elements in @descs
+ *
+ * List all families for a context.
+ **/
+void
+pango_context_list_families (PangoContext *context,
+ 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)
+ {
+ *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);
+ }
+}
+
/**
* pango_context_load_font:
* @context: a #PangoContext
diff --git a/pango/pango-context.h b/pango/pango-context.h
index 642f3d49..64fe06ac 100644
--- a/pango/pango-context.h
+++ b/pango/pango-context.h
@@ -41,8 +41,12 @@ void pango_context_add_font_map (PangoContext *context,
PangoFontMap *font_map);
void pango_context_list_fonts (PangoContext *context,
+ const char *family,
PangoFontDescription ***descs,
int *n_descs);
+void pango_context_list_families (PangoContext *context,
+ gchar ***families,
+ int *n_families);
PangoFont * pango_context_load_font (PangoContext *context,
PangoFontDescription *desc,
gdouble size);
diff --git a/pango/pango-font.h b/pango/pango-font.h
index a2d618ab..161236e6 100644
--- a/pango/pango-font.h
+++ b/pango/pango-font.h
@@ -130,24 +130,36 @@ struct _PangoFontMap
struct _PangoFontMapClass
{
- void (*destroy) (PangoFontMap *fontmap);
- PangoFont *(*load_font) (PangoFontMap *fontmap,
- PangoFontDescription *desc,
- double size);
- void (*list_fonts) (PangoFontMap *fontmap,
- PangoFontDescription ***descs,
- int *n_descs);
+ void (*destroy) (PangoFontMap *fontmap);
+ PangoFont *(*load_font) (PangoFontMap *fontmap,
+ PangoFontDescription *desc,
+ double size);
+ void (*list_fonts) (PangoFontMap *fontmap,
+ const gchar *family,
+ PangoFontDescription ***descs,
+ int *n_descs);
+ void (*list_families) (PangoFontMap *fontmap,
+ gchar ***families,
+ int *n_families);
};
-void pango_font_map_init (PangoFontMap *fontmap);
-void pango_font_map_ref (PangoFontMap *fontmap);
-void pango_font_map_unref (PangoFontMap *fontmap);
-PangoFont *pango_font_map_load_font (PangoFontMap *fontmap,
- PangoFontDescription *desc,
- double size);
-void pango_font_map_list_fonts (PangoFontMap *fontmap,
- PangoFontDescription ***descs,
- int *n_descs);
+void pango_font_map_init (PangoFontMap *fontmap);
+void pango_font_map_ref (PangoFontMap *fontmap);
+void pango_font_map_unref (PangoFontMap *fontmap);
+PangoFont *pango_font_map_load_font (PangoFontMap *fontmap,
+ PangoFontDescription *desc,
+ double size);
+
+void pango_font_map_list_fonts (PangoFontMap *fontmap,
+ const gchar *family,
+ PangoFontDescription ***descs,
+ int *n_descs);
+void pango_font_map_list_families (PangoFontMap *fontmap,
+ gchar ***families,
+ int *n_families);
+void pango_font_map_free_families (gchar **families,
+ int n_families);
+
#ifdef __cplusplus
}
#endif /* __cplusplus */
diff --git a/pango/pangox.c b/pango/pangox.c
index c0347080..bcc175d1 100644
--- a/pango/pangox.c
+++ b/pango/pangox.c
@@ -155,15 +155,18 @@ const struct {
{ "condensed", PANGO_STRETCH_CONDENSED },
};
-static void pango_x_font_map_destroy (PangoFontMap *fontmap);
-static PangoFont *pango_x_font_map_load_font (PangoFontMap *fontmap,
- PangoFontDescription *desc,
- double size);
-static void pango_x_font_map_list_fonts (PangoFontMap *fontmap,
- PangoFontDescription ***descs,
- int *n_descs);
-static void pango_x_font_map_read_aliases (PangoXFontMap *xfontmap);
-
+static void pango_x_font_map_destroy (PangoFontMap *fontmap);
+static PangoFont *pango_x_font_map_load_font (PangoFontMap *fontmap,
+ PangoFontDescription *desc,
+ double size);
+static void pango_x_font_map_list_fonts (PangoFontMap *fontmap,
+ const gchar *family,
+ PangoFontDescription ***descs,
+ int *n_descs);
+static void pango_x_font_map_list_families (PangoFontMap *fontmap,
+ gchar ***families,
+ int *n_families);
+static void pango_x_font_map_read_aliases (PangoXFontMap *xfontmap);
static void pango_x_font_destroy (PangoFont *font);
static PangoFontDescription *pango_x_font_describe (PangoFont *font);
@@ -210,7 +213,8 @@ PangoFontClass pango_x_font_class = {
PangoFontMapClass pango_x_font_map_class = {
pango_x_font_map_destroy,
pango_x_font_map_load_font,
- pango_x_font_map_list_fonts
+ pango_x_font_map_list_fonts,
+ pango_x_font_map_list_families
};
static PangoFontMap *
@@ -350,7 +354,6 @@ typedef struct
PangoFontDescription **descs;
} ListFontsInfo;
-
static void
list_fonts_foreach (gpointer key, gpointer value, gpointer user_data)
{
@@ -370,6 +373,7 @@ list_fonts_foreach (gpointer key, gpointer value, gpointer user_data)
static void
pango_x_font_map_list_fonts (PangoFontMap *fontmap,
+ const gchar *family,
PangoFontDescription ***descs,
int *n_descs)
{
@@ -379,16 +383,84 @@ pango_x_font_map_list_fonts (PangoFontMap *fontmap,
if (!n_descs)
return;
- *n_descs = xfontmap->n_fonts;
- if (!descs)
+ if (family)
+ {
+ PangoXFamilyEntry *entry = g_hash_table_lookup (xfontmap->families, family);
+ if (entry)
+ {
+ *n_descs = g_slist_length (entry->font_entries);
+ if (descs)
+ {
+ *descs = g_new (PangoFontDescription *, *n_descs);
+
+ info.descs = *descs;
+ info.n_found = 0;
+
+ list_fonts_foreach ((gpointer)family, (gpointer)entry, &info);
+ }
+ }
+ else
+ {
+ *n_descs = 0;
+ if (descs)
+ *descs = NULL;
+ }
+ }
+ else
+ {
+ *n_descs = xfontmap->n_fonts;
+ if (descs)
+ {
+ *descs = g_new (PangoFontDescription *, xfontmap->n_fonts);
+
+ info.descs = *descs;
+ info.n_found = 0;
+
+ g_hash_table_foreach (xfontmap->families, list_fonts_foreach, &info);
+ }
+ }
+}
+
+static void
+list_families_foreach (gpointer key, gpointer value, gpointer user_data)
+{
+ GSList **list = user_data;
+
+ *list = g_slist_prepend (*list, key);
+}
+
+static void
+pango_x_font_map_list_families (PangoFontMap *fontmap,
+ gchar ***families,
+ int *n_families)
+{
+ GSList *family_list = NULL;
+ GSList *tmp_list;
+ PangoXFontMap *xfontmap = (PangoXFontMap *)fontmap;
+
+ if (!n_families)
return;
- *descs = g_new (PangoFontDescription *, xfontmap->n_fonts);
+ g_hash_table_foreach (xfontmap->families, list_families_foreach, &family_list);
+
+ *n_families = g_slist_length (family_list);
- info.descs = *descs;
- info.n_found = 0;
+ if (families)
+ {
+ int i = 0;
+
+ *families = g_new (gchar *, *n_families);
+
+ tmp_list = family_list;
+ while (tmp_list)
+ {
+ (*families)[i] = g_strdup (tmp_list->data);
+ i++;
+ tmp_list = tmp_list->next;
+ }
+ }
- g_hash_table_foreach (xfontmap->families, list_fonts_foreach, &info);
+ g_slist_free (family_list);
}
/* Similar to GNU libc's getline, but buffer is g_malloc'd */