GNOME Bugzilla – Bug 373856
Wish: Function to convert a GdkColor to a string
Last modified: 2006-12-21 12:35:14 UTC
Applications sometimes allow users to customize colors using a color selection dialog. These preferences must be retained across sessions, usually by writing a textual representation of a GdkColor to GConf or a configuration file. Later, the textual representation is passed to gdk_color_parse() to recreate the original GdkColor. While generating such a representation can be as simple as a one-line "printf" operation, it would be courteous for the GDK API to provide a standard method. Hence, I propose the following addition to GDK: gchar * gdk_color_to_string (GdkColor *color) This function returns a newly-allocated string representation of the GdkColor in the form of "#rrrrggggbbbb", where 'rrrr', 'gggg' and 'bbbb' are the hexadecimal values of the GdkColor's red, green and blue components, respectively. Note that the pixel component of the GdkColor is lost in the conversion. The resulting string can be passed to gdk_color_parse() to recreate the original GdkColor (sans the pixel component).
Created attachment 76396 [details] [review] Proposed patch
Should this go down to Pango too?
Not sure if that question was for me, but I think since GDK defers to Pango for parsing color strings it might make sense to do the same for generating color strings. Would Pango benefit from a pango_color_to_string() function?
(In reply to comment #3) > Not sure if that question was for me, but I think since GDK defers to Pango for > parsing color strings it might make sense to do the same for generating color > strings. Would Pango benefit from a pango_color_to_string() function? That would be useful in language bindings at least. I'm fine with adding it. I'll go ahead and add that today. Will be in Pango 1.16.
Will be in Pango 1.15.2: 2006-12-06 Behdad Esfahbod <behdad@gnome.org> Bug 373856 – Wish: Function to convert a GdkColor to a string Patch from Matthew Barnes * docs/pango-sections.txt: * docs/tmpl/text-attributes.sgml: * pango/pango-attributes.h: * pango/pango.def: * pango/pango-color.c (pango_color_to_string): New public function pango_color_to_string(). Note that your patch doesn't have the Since: tag in docs. You can now use pango_color_to_string() for the one-line function in gdk. :)
Created attachment 77869 [details] [review] Revised patch Here's a revised patch that uses pango_color_to_string().
I'm not normally a fan of adding too many trivial functions like this, but since you've already got it into pango, go ahead and add this to HEAD, but please make sure that you bump the pango requirement to 1.15.2 in configure.in
Committed. 2006-12-21 Matthew Barnes <mbarnes@redhat.com> * docs/reference/gdk/gdk-sections.txt: * gdk/gdkcolor.[ch] (gdk_color_to_string): Add a function for converting a GdkColor to a string (#373856). * configure.in: Bump pango requirement to 1.15.2.