summaryrefslogtreecommitdiff
path: root/src/xterm.c
diff options
context:
space:
mode:
authorPip Cet <pipcet@gmail.com>2019-07-22 02:40:35 +0000
committerEli Zaretskii <eliz@gnu.org>2019-07-27 14:05:46 +0300
commit357399014acacc75bd1825fb2f498f1a4be7b362 (patch)
treefbbfbca7fed181b564f5814c6941297e6f5f0372 /src/xterm.c
parente310843d9dc106187d0e45ef7f0b9cd90a881eec (diff)
downloademacs-357399014acacc75bd1825fb2f498f1a4be7b362.tar.gz
Use the CSS convention for #RGB colors (bug#36304)
* src/xterm.c (x_parse_color): Change interpretation of #RGB color triplets to match CSS rather than X conventions. * lisp/term/tty-colors.el (tty-color-standard-values): Change interpretation of #RGB color triplets to match CSS rather than X conventions. Allow upper-case digits. Fix rgb:R/G/B interpretation. * doc/emacs/display.texi (Colors): Specify the convention used for "#RGB" color triplets. * test/lisp/tty-colors-tests.el: New file. * etc/NEWS: Mention the change.
Diffstat (limited to 'src/xterm.c')
-rw-r--r--src/xterm.c33
1 files changed, 31 insertions, 2 deletions
diff --git a/src/xterm.c b/src/xterm.c
index c96aa74a7a6..75568a82a18 100644
--- a/src/xterm.c
+++ b/src/xterm.c
@@ -2381,6 +2381,8 @@ x_query_frame_background_color (struct frame *f, XColor *bgcolor)
x_query_colors (f, bgcolor, 1);
}
+#define HEX_COLOR_NAME_LENGTH 32
+
/* On frame F, translate the color name to RGB values. Use cached
information, if possible.
@@ -2398,9 +2400,36 @@ Status x_parse_color (struct frame *f, const char *color_name,
if (color_name[0] == '#')
{
- /* The hex form is parsed directly by XParseColor without
+ /* Don't pass #RGB strings directly to XParseColor, because that
+ follows the X convention of zero-extending each channel
+ value: #f00 means #f00000. We want the convention of scaling
+ channel values, so #f00 means #ff0000, just as it does for
+ HTML, SVG, and CSS.
+
+ So we translate #f00 to rgb:f/0/0, which X handles
+ differently. */
+ char rgb_color_name[HEX_COLOR_NAME_LENGTH];
+ int len = strlen (color_name);
+ int digits_per_channel;
+ if (len == 4)
+ digits_per_channel = 1;
+ else if (len == 7)
+ digits_per_channel = 2;
+ else if (len == 10)
+ digits_per_channel = 3;
+ else if (len == 13)
+ digits_per_channel = 4;
+ else
+ return 0;
+
+ snprintf (rgb_color_name, sizeof rgb_color_name, "rgb:%.*s/%.*s/%.*s",
+ digits_per_channel, color_name + 1,
+ digits_per_channel, color_name + digits_per_channel + 1,
+ digits_per_channel, color_name + 2 * digits_per_channel + 1);
+
+ /* The rgb form is parsed directly by XParseColor without
talking to the X server. No need for caching. */
- return XParseColor (dpy, cmap, color_name, color);
+ return XParseColor (dpy, cmap, rgb_color_name, color);
}
for (cache_entry = FRAME_DISPLAY_INFO (f)->color_names; cache_entry;