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 void dnd_color_fill (GstyleColorWidget *self, GstyleColor *src_color, GstyleColor *dst_color) { const gchar *name; GdkRGBA src_rgba; GdkRGBA dst_rgba; g_assert (GSTYLE_COLOR_WIDGET (self)); g_assert (GSTYLE_COLOR (src_color)); g_assert (GSTYLE_COLOR (dst_color)); gstyle_color_fill_rgba (src_color, &src_rgba); gstyle_color_fill_rgba (dst_color, &dst_rgba); if (!(self->dnd_lock & GSTYLE_COLOR_WIDGET_DND_LOCK_FLAGS_COLOR)) { dst_rgba.red = src_rgba.red; dst_rgba.green = src_rgba.green; dst_rgba.blue = src_rgba.blue; } if (!(self->dnd_lock & GSTYLE_COLOR_WIDGET_DND_LOCK_FLAGS_ALPHA)) dst_rgba.alpha = src_rgba.alpha; gstyle_color_set_rgba (self->color, &dst_rgba); if (!(self->dnd_lock & GSTYLE_COLOR_WIDGET_DND_LOCK_FLAGS_KIND)) gstyle_color_set_kind (dst_color, gstyle_color_get_kind (src_color)); if (!(self->dnd_lock & GSTYLE_COLOR_WIDGET_DND_LOCK_FLAGS_NAME)) { name = gstyle_color_get_name (src_color); gstyle_color_set_name (dst_color, name); } }
/** * gstyle_palette_save_to_xml: * @self: a #GstylePalette * @file: a #GFile * @error: (nullable): a #GError location or %NULL * * Save a palette to Gnome-Builder .xml palette format. * * Returns: %TRUE if succesfull, %FALSE otherwise. */ gboolean gstyle_palette_save_to_xml (GstylePalette *self, GFile *file, GError **error) { g_autofree gchar *file_path = NULL; const gchar *id; const gchar *name; xmlDocPtr doc; xmlNodePtr root_node; xmlNodePtr palette_node; xmlNodePtr color_node; gint n_colors; gint succes; gchar *header = "Copyright (C) 2016 GNOME Builder Team at irc.gimp.net/#gnome-builder\n" \ "This program is free software: you can redistribute it and/or modify\n" \ "it under the terms of the GNU General Public License as published by\n" \ "the Free Software Foundation, either version 3 of the License, or\n" \ "(at your option) any later version.\n\n" \ "This program is distributed in the hope that it will be useful,\n" \ "but WITHOUT ANY WARRANTY; without even the implied warranty of\n" \ "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n" \ "GNU General Public License for more details.\n\n" \ "You should have received a copy of the GNU General Public License\n" \ "along with this program. If not, see <http://www.gnu.org/licenses/>\n"; g_return_val_if_fail (GSTYLE_IS_PALETTE (self), FALSE); g_return_val_if_fail (G_IS_FILE (file), FALSE); doc = xmlNewDoc(CHAR_TO_XML ("1.0")); root_node = xmlNewDocComment (doc, CHAR_TO_XML (header)); xmlDocSetRootElement(doc, root_node); palette_node = xmlNewNode (NULL, CHAR_TO_XML ("palette")); xmlAddSibling (root_node, palette_node); id = gstyle_palette_get_id (self); name = gstyle_palette_get_name (self); xmlNewProp (palette_node, CHAR_TO_XML ("id"), CHAR_TO_XML (id)); if (self->gettext_domain) { xmlNewProp (palette_node, CHAR_TO_XML ("_name"), CHAR_TO_XML (name)); xmlNewProp (palette_node, CHAR_TO_XML ("gettext-domain"), CHAR_TO_XML (self->gettext_domain)); } else xmlNewProp (palette_node, CHAR_TO_XML ("name"), CHAR_TO_XML (name)); n_colors = gstyle_palette_get_len (self); for (gint i = 0; i < n_colors; ++i) { const GstyleColor *color; const gchar *color_name; g_autofree gchar *color_string = NULL; color = gstyle_palette_get_color_at_index (self, i); color_name = gstyle_color_get_name ((GstyleColor *)color); if (gstyle_color_get_kind ((GstyleColor *)color) == GSTYLE_COLOR_KIND_PREDEFINED) color_string = gstyle_color_to_string ((GstyleColor *)color, GSTYLE_COLOR_KIND_RGB_HEX6); else color_string = gstyle_color_to_string ((GstyleColor *)color, GSTYLE_COLOR_KIND_ORIGINAL); color_node = xmlNewChild (palette_node, NULL, CHAR_TO_XML ("color"), NULL); xmlNewProp (color_node, CHAR_TO_XML ("name"), CHAR_TO_XML (color_name)); xmlNewProp (color_node, CHAR_TO_XML ("value"), CHAR_TO_XML (color_string)); } file_path = g_file_get_path (file); succes = xmlSaveFormatFileEnc (file_path, doc, "UTF-8", 1); xmlFreeDoc(doc); if (succes == -1) { g_set_error (error, GSTYLE_PALETTE_ERROR, GSTYLE_PALETTE_ERROR_FILE, _("Unable to save %s\n"), file_path); return FALSE; } else { gstyle_palette_set_changed (self, FALSE); return TRUE; } }