Commit 3be9ce0e authored by Owen Taylor's avatar Owen Taylor Committed by Owen Taylor

Implement gdk_color_parse() in terms of pango_color_parse().

Sun Nov  4 19:16:23 2001  Owen Taylor  <otaylor@redhat.com>

        * gdk/gdkcolor.c (gdk_color_parse): Implement gdk_color_parse()
        in terms of pango_color_parse().

        * gdk/{linux-fb,win32,x11}/gdkcolor-*.c: Remove port-specific
        gdk_color_parse() implementations.
parent 37c87ccd
Sun Nov 4 19:16:23 2001 Owen Taylor <otaylor@redhat.com>
* gdk/gdkcolor.c (gdk_color_parse): Implement gdk_color_parse()
in terms of pango_color_parse().
* gdk/{linux-fb,win32,x11}/gdkcolor-*.c: Remove port-specific
gdk_color_parse() implementations.
Sun Nov 4 18:39:43 2001 Owen Taylor <otaylor@redhat.com>
* gtk/gtksizegroup.c (gtk_size_group_set_mode):
......
Sun Nov 4 19:16:23 2001 Owen Taylor <otaylor@redhat.com>
* gdk/gdkcolor.c (gdk_color_parse): Implement gdk_color_parse()
in terms of pango_color_parse().
* gdk/{linux-fb,win32,x11}/gdkcolor-*.c: Remove port-specific
gdk_color_parse() implementations.
Sun Nov 4 18:39:43 2001 Owen Taylor <otaylor@redhat.com>
* gtk/gtksizegroup.c (gtk_size_group_set_mode):
......
Sun Nov 4 19:16:23 2001 Owen Taylor <otaylor@redhat.com>
* gdk/gdkcolor.c (gdk_color_parse): Implement gdk_color_parse()
in terms of pango_color_parse().
* gdk/{linux-fb,win32,x11}/gdkcolor-*.c: Remove port-specific
gdk_color_parse() implementations.
Sun Nov 4 18:39:43 2001 Owen Taylor <otaylor@redhat.com>
* gtk/gtksizegroup.c (gtk_size_group_set_mode):
......
Sun Nov 4 19:16:23 2001 Owen Taylor <otaylor@redhat.com>
* gdk/gdkcolor.c (gdk_color_parse): Implement gdk_color_parse()
in terms of pango_color_parse().
* gdk/{linux-fb,win32,x11}/gdkcolor-*.c: Remove port-specific
gdk_color_parse() implementations.
Sun Nov 4 18:39:43 2001 Owen Taylor <otaylor@redhat.com>
* gtk/gtksizegroup.c (gtk_size_group_set_mode):
......
Sun Nov 4 19:16:23 2001 Owen Taylor <otaylor@redhat.com>
* gdk/gdkcolor.c (gdk_color_parse): Implement gdk_color_parse()
in terms of pango_color_parse().
* gdk/{linux-fb,win32,x11}/gdkcolor-*.c: Remove port-specific
gdk_color_parse() implementations.
Sun Nov 4 18:39:43 2001 Owen Taylor <otaylor@redhat.com>
* gtk/gtksizegroup.c (gtk_size_group_set_mode):
......
Sun Nov 4 19:16:23 2001 Owen Taylor <otaylor@redhat.com>
* gdk/gdkcolor.c (gdk_color_parse): Implement gdk_color_parse()
in terms of pango_color_parse().
* gdk/{linux-fb,win32,x11}/gdkcolor-*.c: Remove port-specific
gdk_color_parse() implementations.
Sun Nov 4 18:39:43 2001 Owen Taylor <otaylor@redhat.com>
* gtk/gtksizegroup.c (gtk_size_group_set_mode):
......
Sun Nov 4 19:16:23 2001 Owen Taylor <otaylor@redhat.com>
* gdk/gdkcolor.c (gdk_color_parse): Implement gdk_color_parse()
in terms of pango_color_parse().
* gdk/{linux-fb,win32,x11}/gdkcolor-*.c: Remove port-specific
gdk_color_parse() implementations.
Sun Nov 4 18:39:43 2001 Owen Taylor <otaylor@redhat.com>
* gtk/gtksizegroup.c (gtk_size_group_set_mode):
......
......@@ -228,3 +228,21 @@ gdk_color_get_type (void)
(GBoxedFreeFunc)gdk_color_free);
return our_type;
}
gboolean
gdk_color_parse (const gchar *spec,
GdkColor *color)
{
PangoColor pango_color;
if (pango_color_parse (&pango_color, spec))
{
color->red = pango_color.red;
color->green = pango_color.green;
color->blue = pango_color.blue;
return TRUE;
}
else
return FALSE;
}
......@@ -360,94 +360,6 @@ gdk_colormap_change (GdkColormap *colormap,
}
}
gboolean
gdk_color_parse (const gchar *spec,
GdkColor *color)
{
char aline[512];
FILE *fh;
g_return_val_if_fail(spec, FALSE);
g_return_val_if_fail(color, FALSE);
if (spec[0] == '#')
{
if (strlen(spec) == 7)
{
guint num;
sscanf (spec + 1, "%x", &num);
color->red = (num & 0xFF0000) >> 8;
color->green = (num & 0xFF00);
color->blue = (num & 0xFF) << 8;
}
else if (strlen(spec) == 13)
{
char s1[5], s2[5], s3[5];
g_snprintf (s1, sizeof(s1), spec + 1);
g_snprintf (s2, sizeof(s2), spec + 5);
g_snprintf (s3, sizeof(s3), spec + 9);
if (!sscanf(s1, "%hx", &color->red))
g_error ("sscanf failed");
if (!sscanf(s2, "%hx", &color->green))
g_error ("sscanf failed");
if (!sscanf (s3, "%hx", &color->blue))
g_error ("sscanf failed");
}
else
{
g_warning ("Couldn't parse color specifier `%s'", spec);
return FALSE;
}
return TRUE;
}
else
{
fh = fopen ("/usr/lib/X11/rgb.txt", "r");
if (!fh)
return FALSE;
while(fgets (aline, sizeof(aline), fh))
{
int red, green, blue;
char *ctmp;
g_strstrip (aline);
if (!aline[0] || aline[0] == '#' || aline[0] == '!')
continue;
ctmp = strtok (aline, " \t");
if (!ctmp)
continue;
red = atoi (ctmp);
ctmp = strtok (NULL, " \t");
if (!ctmp)
continue;
green = atoi (ctmp);
ctmp = strtok (NULL, " \t");
if (!ctmp)
continue;
blue = atoi (ctmp);
ctmp = strtok (NULL, " \t");
if (!ctmp || strcmp (ctmp, spec))
continue;
color->red = red << 8;
color->green = green << 8;
color->blue = blue << 8;
return TRUE;
}
fclose (fh);
}
return FALSE;
}
void
gdk_colormap_free_colors (GdkColormap *colormap,
GdkColor *colors,
......
This diff is collapsed.
......@@ -465,32 +465,6 @@ gdk_colors_alloc (GdkColormap *colormap,
return return_val != 0;
}
gboolean
gdk_color_parse (const gchar *spec,
GdkColor *color)
{
Colormap xcolormap;
XColor xcolor;
gboolean return_val;
g_return_val_if_fail (spec != NULL, FALSE);
g_return_val_if_fail (color != NULL, FALSE);
xcolormap = DefaultColormap (gdk_display, _gdk_screen);
if (XParseColor (gdk_display, xcolormap, spec, &xcolor))
{
return_val = TRUE;
color->red = xcolor.red;
color->green = xcolor.green;
color->blue = xcolor.blue;
}
else
return_val = FALSE;
return return_val;
}
/* This is almost identical to gdk_colormap_free_colors.
* Keep them in sync!
*/
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment