pidgin: 4ef43084: Support rgb(r,g,b) style css color defin...
datallah at pidgin.im
datallah at pidgin.im
Fri Oct 24 00:25:40 EDT 2008
-----------------------------------------------------------------
Revision: 4ef430848d380eda5938f38a09d3560b83e3f91b
Ancestor: 351069ce032cca102c0beecf9c1ad448295fce32
Author: datallah at pidgin.im
Date: 2008-10-24T04:19:10
Branch: im.pidgin.pidgin
URL: http://d.pidgin.im/viewmtn/revision/info/4ef430848d380eda5938f38a09d3560b83e3f91b
Modified files:
pidgin/gtkimhtml.c
ChangeLog:
Support rgb(r,g,b) style css color definitions. Fixes #7288.
-------------- next part --------------
============================================================
--- pidgin/gtkimhtml.c 78cd8b8bf3967a49cdbedcd53036173d3dd5915f
+++ pidgin/gtkimhtml.c 1e96a64b8209b49c9751afea1f9db538a6d81b02
@@ -2522,6 +2522,68 @@ void gtk_imhtml_scroll_to_end(GtkIMHtml
}
}
+/* CSS colors are either rgb (x,y,z) or #hex
+ * we need to convert to hex if it is RGB */
+static gchar*
+parse_css_color(gchar *in_color)
+{
+ char *tmp = in_color;
+
+ if (*tmp == 'r' && *(++tmp) == 'g' && *(++tmp) == 'b'
+ && *(++tmp) == '(' && *(++tmp)) {
+ int rgbval[] = {0, 0, 0};
+ int count = 0;
+ const char *v_start;
+
+ while (count < 3) {
+ /* Skip any leading spaces */
+ while (*tmp && g_ascii_isspace(*tmp))
+ tmp++;
+
+ /* Find the subsequent contiguous digits */
+ v_start = tmp;
+ while (*tmp && g_ascii_isdigit(*tmp))
+ tmp++;
+
+ if (tmp != v_start) {
+ char prev = *tmp;
+ *tmp = '\0';
+ rgbval[count] = atoi(v_start);
+ *tmp = prev;
+
+ /* deal with % */
+ while (*tmp && g_ascii_isspace(*tmp))
+ tmp++;
+ if (*tmp == '%') {
+ rgbval[count] = (rgbval[count] / 100.0) * 255;
+ tmp++;
+ }
+ } else {
+ purple_debug_warning("gtkimhtml", "Invalid rgb CSS color in '%s'!\n", in_color);
+ return in_color;
+ }
+
+ if (rgbval[count] > 255) {
+ rgbval[count] = 255;
+ } else if (rgbval[count] < 0) {
+ rgbval[count] = 0;
+ }
+
+ while (*tmp && g_ascii_isspace(*tmp))
+ tmp++;
+ if (*tmp == ',')
+ tmp++;
+
+ count++;
+ }
+
+ g_free(in_color);
+ return g_strdup_printf("#%02X%02X%02X", rgbval[0], rgbval[1], rgbval[2]);
+ }
+
+ return in_color;
+}
+
void gtk_imhtml_insert_html_at_iter(GtkIMHtml *imhtml,
const gchar *text,
GtkIMHtmlOptions options,
@@ -2982,7 +3044,7 @@ void gtk_imhtml_insert_html_at_iter(GtkI
oldfont = fonts->data;
if (color && !(options & GTK_IMHTML_NO_COLOURS) && (imhtml->format_functions & GTK_IMHTML_FORECOLOR)) {
- font->fore = color;
+ font->fore = parse_css_color(color);
gtk_imhtml_toggle_forecolor(imhtml, font->fore);
} else {
if (oldfont && oldfont->fore)
@@ -2991,7 +3053,7 @@ void gtk_imhtml_insert_html_at_iter(GtkI
}
if (background && !(options & GTK_IMHTML_NO_COLOURS) && (imhtml->format_functions & GTK_IMHTML_BACKCOLOR)) {
- font->back = background;
+ font->back = parse_css_color(background);
gtk_imhtml_toggle_backcolor(imhtml, font->back);
} else {
if (oldfont && oldfont->back)
More information about the Commits
mailing list