summaryrefslogtreecommitdiff
path: root/pango/pango-attributes.c
diff options
context:
space:
mode:
authorBehdad Esfahbod <behdad@gnome.org>2008-04-21 19:26:10 +0000
committerBehdad Esfahbod <behdad@src.gnome.org>2008-04-21 19:26:10 +0000
commit3e56f5f1a5412a2ca4f34f4b1fd973644b64c82b (patch)
tree966f722e9b6c3664225a89ef86501dc612f5993e /pango/pango-attributes.c
parentfcf1afb9f48ba15e04ea8ae269e62bb075b8d656 (diff)
downloadpango-3e56f5f1a5412a2ca4f34f4b1fd973644b64c82b.tar.gz
Bug 511183 – Add pango_attr_type_get_name()
2008-04-21 Behdad Esfahbod <behdad@gnome.org> Bug 511183 – Add pango_attr_type_get_name() * docs/pango-sections.txt: * docs/tmpl/text-attributes.sgml: * pango/pango-attributes.c (pango_attr_type_register), (pango_attr_type_get_name): * pango/pango-attributes.h: * pango/pango.def: New public API: pango_attr_type_get_name() svn path=/trunk/; revision=2598
Diffstat (limited to 'pango/pango-attributes.c')
-rw-r--r--pango/pango-attributes.c44
1 files changed, 41 insertions, 3 deletions
diff --git a/pango/pango-attributes.c b/pango/pango-attributes.c
index 0d398d52..3ec294dc 100644
--- a/pango/pango-attributes.c
+++ b/pango/pango-attributes.c
@@ -54,11 +54,14 @@ static PangoAttribute *pango_attr_size_new_internal (int size,
gboolean absolute);
+static GHashTable *name_map = NULL;
+
/**
* pango_attr_type_register:
- * @name: an identifier for the type (currently unused.)
+ * @name: an identifier for the type
*
- * Allocate a new attribute type ID.
+ * Allocate a new attribute type ID. The attribute type name can be accessed
+ * later by using pango_attr_type_get_name().
*
* Return value: the new type ID.
**/
@@ -66,8 +69,43 @@ PangoAttrType
pango_attr_type_register (const gchar *name)
{
static guint current_type = 0x1000000;
+ guint type = current_type++;
+
+ if (name)
+ {
+ if (G_UNLIKELY (!name_map))
+ name_map = g_hash_table_new (NULL, NULL);
+
+ g_hash_table_insert (name_map, GUINT_TO_POINTER (type), (gpointer) g_intern_string (name));
+ }
- return current_type++;
+ return type;
+}
+
+/**
+ * pango_attr_type_get_name:
+ * @type: an attribute type ID to fetch the name for
+ *
+ * Fetches the attribute type name passed in when registering the type using
+ * pango_attr_type_register().
+ *
+ * The returned value is an interned string (see g_intern_string() for what
+ * that means) that should not be modified or freed.
+ *
+ * Return value: the type ID name (which may be %NULL), or %NULL if @type is
+ * a built-in Pango attribute type or invalid.
+ *
+ * Since: 1.22
+ **/
+G_CONST_RETURN char *
+pango_attr_type_get_name (PangoAttrType type)
+{
+ const char *result = NULL;
+
+ if (name_map)
+ result = g_hash_table_lookup (name_map, GUINT_TO_POINTER ((guint) type));
+
+ return result;
}
/**