diff options
-rw-r--r-- | ChangeLog | 14 | ||||
-rw-r--r-- | docs/pango-sections.txt | 1 | ||||
-rw-r--r-- | docs/tmpl/text-attributes.sgml | 9 | ||||
-rw-r--r-- | pango/pango-attributes.c | 44 | ||||
-rw-r--r-- | pango/pango-attributes.h | 3 | ||||
-rw-r--r-- | pango/pango.def | 1 |
6 files changed, 68 insertions, 4 deletions
@@ -1,3 +1,17 @@ +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() + 2008-04-20 Behdad Esfahbod <behdad@gnome.org> * pango/pango-ot-info.c (pango_ot_info_get_gdef), diff --git a/docs/pango-sections.txt b/docs/pango-sections.txt index ab799b6d..149e90b1 100644 --- a/docs/pango-sections.txt +++ b/docs/pango-sections.txt @@ -325,6 +325,7 @@ PangoAttrShape PangoAttrSize pango_parse_markup pango_attr_type_register +pango_attr_type_get_name pango_attribute_init pango_attribute_copy pango_attribute_equal diff --git a/docs/tmpl/text-attributes.sgml b/docs/tmpl/text-attributes.sgml index f2f66fdc..43cc1686 100644 --- a/docs/tmpl/text-attributes.sgml +++ b/docs/tmpl/text-attributes.sgml @@ -195,6 +195,15 @@ set font size. @Returns: +<!-- ##### FUNCTION pango_attr_type_get_name ##### --> +<para> + +</para> + +@type: +@Returns: + + <!-- ##### FUNCTION pango_attribute_init ##### --> <para> 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; } /** diff --git a/pango/pango-attributes.h b/pango/pango-attributes.h index ad7a0861..d4ce8404 100644 --- a/pango/pango-attributes.h +++ b/pango/pango-attributes.h @@ -176,7 +176,8 @@ struct _PangoAttrFontDesc PangoFontDescription *desc; }; -PangoAttrType pango_attr_type_register (const gchar *name); +PangoAttrType pango_attr_type_register (const gchar *name); +G_CONST_RETURN char * pango_attr_type_get_name (PangoAttrType type) G_GNUC_CONST; void pango_attribute_init (PangoAttribute *attr, const PangoAttrClass *klass); diff --git a/pango/pango.def b/pango/pango.def index 69fe4651..a71705ff 100644 --- a/pango/pango.def +++ b/pango/pango.def @@ -39,6 +39,7 @@ EXPORTS pango_attr_style_new pango_attr_type_get_type pango_attr_type_register + pango_attr_type_get_name pango_attr_underline_color_new pango_attr_underline_new pango_attr_variant_new |