[gtk+/parser: 3/74] API: gtk: Add gtk_symbolic_color_to_string()



commit 7c9032ba0a77a4b95afdf631330bae4424f068f3
Author: Benjamin Otte <otte redhat com>
Date:   Wed Apr 6 21:41:42 2011 +0200

    API: gtk: Add gtk_symbolic_color_to_string()
    
    See future commits for why this is useful. Or try to debug some color
    problem.

 docs/reference/gtk/gtk3-sections.txt |    1 +
 gtk/gtk.symbols                      |    1 +
 gtk/gtksymboliccolor.c               |   67 ++++++++++++++++++++++++++++++++++
 gtk/gtksymboliccolor.h               |    2 +
 4 files changed, 71 insertions(+), 0 deletions(-)
---
diff --git a/docs/reference/gtk/gtk3-sections.txt b/docs/reference/gtk/gtk3-sections.txt
index d995d71..1fed765 100644
--- a/docs/reference/gtk/gtk3-sections.txt
+++ b/docs/reference/gtk/gtk3-sections.txt
@@ -5728,6 +5728,7 @@ gtk_symbolic_color_new_mix
 gtk_symbolic_color_ref
 gtk_symbolic_color_unref
 gtk_symbolic_color_resolve
+gtk_symbolic_color_to_string
 
 <SUBSECTION Standard>
 GTK_TYPE_SYMBOLIC_COLOR
diff --git a/gtk/gtk.symbols b/gtk/gtk.symbols
index 33fb915..643bc35 100644
--- a/gtk/gtk.symbols
+++ b/gtk/gtk.symbols
@@ -2548,6 +2548,7 @@ gtk_symbolic_color_new_name
 gtk_symbolic_color_new_shade
 gtk_symbolic_color_ref
 gtk_symbolic_color_resolve
+gtk_symbolic_color_to_string
 gtk_symbolic_color_unref
 gtk_table_attach
 gtk_table_attach_defaults
diff --git a/gtk/gtksymboliccolor.c b/gtk/gtksymboliccolor.c
index ee7b714..a359fe1 100644
--- a/gtk/gtksymboliccolor.c
+++ b/gtk/gtksymboliccolor.c
@@ -560,3 +560,70 @@ gtk_symbolic_color_resolve (GtkSymbolicColor   *color,
 
   return FALSE;
 }
+
+/**
+ * gtk_symbolic_color_to_string:
+ * @color: color to convert to a string
+ *
+ * Converts the given @color to a string representation. This is useful
+ * both for debugging and for serialization of strings. The format of
+ * the string may change between different versions of GTK, but it is
+ * guaranteed that the GTK css parser is able to read the string and
+ * create the same symbolic color from it.
+ *
+ * Returns: a new string representing @color
+ **/
+char *
+gtk_symbolic_color_to_string (GtkSymbolicColor *color)
+{
+  char *s;
+
+  g_return_val_if_fail (color != NULL, NULL);
+
+  switch (color->type)
+    {
+    case COLOR_TYPE_LITERAL:
+      s = gdk_rgba_to_string (&color->color);
+      break;
+    case COLOR_TYPE_NAME:
+      s = g_strconcat ("@", color->name, NULL);
+      break;
+    case COLOR_TYPE_SHADE:
+      {
+        char *color_string = gtk_symbolic_color_to_string (color->shade.color);
+        char factor[G_ASCII_DTOSTR_BUF_SIZE];
+
+        g_ascii_dtostr (factor, sizeof (factor), color->shade.factor);
+        s = g_strdup_printf ("shade (%s, %s)", color_string, factor);
+        g_free (color_string);
+      }
+      break;
+    case COLOR_TYPE_ALPHA:
+      {
+        char *color_string = gtk_symbolic_color_to_string (color->shade.color);
+        char factor[G_ASCII_DTOSTR_BUF_SIZE];
+
+        g_ascii_dtostr (factor, sizeof (factor), color->alpha.factor);
+        s = g_strdup_printf ("alpha (%s, %s)", color_string, factor);
+        g_free (color_string);
+      }
+      break;
+    case COLOR_TYPE_MIX:
+      {
+        char *color_string1 = gtk_symbolic_color_to_string (color->mix.color1);
+        char *color_string2 = gtk_symbolic_color_to_string (color->mix.color2);
+        char factor[G_ASCII_DTOSTR_BUF_SIZE];
+
+        g_ascii_dtostr (factor, sizeof (factor), color->mix.factor);
+        s = g_strdup_printf ("mix (%s, %s, %s)", color_string1, color_string2, factor);
+        g_free (color_string1);
+        g_free (color_string2);
+      }
+      break;
+    default:
+      g_assert_not_reached ();
+    }
+
+  return s;
+
+}
diff --git a/gtk/gtksymboliccolor.h b/gtk/gtksymboliccolor.h
index 4f4b813..7be051a 100644
--- a/gtk/gtksymboliccolor.h
+++ b/gtk/gtksymboliccolor.h
@@ -46,6 +46,8 @@ GtkSymbolicColor * gtk_symbolic_color_new_mix     (GtkSymbolicColor   *color1,
 GtkSymbolicColor * gtk_symbolic_color_ref         (GtkSymbolicColor   *color);
 void               gtk_symbolic_color_unref       (GtkSymbolicColor   *color);
 
+char *             gtk_symbolic_color_to_string   (GtkSymbolicColor   *color);
+
 gboolean           gtk_symbolic_color_resolve     (GtkSymbolicColor   *color,
                                                    GtkStyleProperties *props,
                                                    GdkRGBA            *resolved_color);



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]