static void
test_parse_string (void)
{
  ColorItem *item;
  GstyleColor *color;
  GdkRGBA rgba;
  GstyleColorKind kind;
  GstyleCielab lab;

  printf ("\n");
  for (item = rgba_table; item->rgb != NULL; item++)
    {
      g_autofree gchar *str_hex3 = NULL;
      g_autofree gchar *str_hex6 = NULL;
      g_autofree gchar *str_rgba = NULL;
      g_autofree gchar *str_rgba_percent = NULL;
      g_autofree gchar *str_hsla = NULL;
      g_autofree gchar *str_original = NULL;
      g_autofree gchar *dst_str = NULL;

      color = gstyle_color_new_from_string (NULL, item->rgb);

      str_hex3 = gstyle_color_to_string (color, GSTYLE_COLOR_KIND_RGB_HEX3);
      str_hex6 = gstyle_color_to_string (color, GSTYLE_COLOR_KIND_RGB_HEX6);
      str_rgba = gstyle_color_to_string (color, GSTYLE_COLOR_KIND_RGBA);
      str_rgba_percent = gstyle_color_to_string (color, GSTYLE_COLOR_KIND_RGBA_PERCENT);
      str_hsla = gstyle_color_to_string (color, GSTYLE_COLOR_KIND_HSLA);
      str_original = gstyle_color_to_string (color, GSTYLE_COLOR_KIND_ORIGINAL);

      gstyle_color_fill_rgba (color, &rgba);
      gstyle_color_convert_rgb_to_cielab (&rgba, &lab);

      kind = gstyle_color_get_kind (color);
      dst_str = gstyle_color_to_string (color, kind);

      printf ("dst:'%s'\n", dst_str);


      printf ("\n----- '%s': rgba: kind:%i\n%s\n%s\n%s\n%s\n%s\n Original: %s\n",
              item->rgb, kind,
              str_hex3, str_hex6, str_rgba, str_rgba_percent, str_hsla, str_original);

      printf ("lab : L=%.3f a=%.3f b=%.3f\n", lab.l, lab.a, lab.b);

      g_assert (g_ascii_strcasecmp (item->rgb, dst_str) == 0);
      g_object_unref (color);
      printf ("\n");
    }
}
static GstyleColorWidget *
create_color_swatch (const gchar *color_str)
{
  GstyleColor *color;
  GstyleColorWidget *swatch;

  color = gstyle_color_new_from_string ("test", color_str);

  swatch = g_object_new (GSTYLE_TYPE_COLOR_WIDGET,
                         "halign", GTK_ALIGN_FILL,
                         "color", color,
                         "name-visible", FALSE,
                         "fallback-name-visible", FALSE,
                         NULL);

  return swatch;
}
Exemple #3
0
static GstyleColor *
gstyle_palette_xml_get_color (xmlTextReaderPtr reader)
{
  GstyleColor *color = NULL;
  g_autofree gchar *name;
  g_autofree gchar *value;

  g_assert (reader != NULL);

  if (xmlTextReaderNodeType (reader) == XML_READER_TYPE_ELEMENT &&
      !g_strcmp0 (XML_TO_CHAR (xmlTextReaderConstName (reader)), "color") &&
      xmlTextReaderDepth (reader) == 1)
    {
      name = strdup_and_xmlfree (xmlTextReaderGetAttribute (reader, CHAR_TO_XML ("name")));
      if (gstyle_utf8_is_spaces (name))
        g_clear_pointer (&name, g_free);

      value = strdup_and_xmlfree (xmlTextReaderGetAttribute (reader, CHAR_TO_XML ("value")));
      if (!gstyle_str_empty0 (value))
        color = gstyle_color_new_from_string (name, value);
    }

  return color;
}