diff options
author | Mattias EngdegÄrd <mattiase@acm.org> | 2020-06-10 19:18:58 +0200 |
---|---|---|
committer | Mattias EngdegÄrd <mattiase@acm.org> | 2020-06-10 20:11:13 +0200 |
commit | 68ae6faa7f1b4c348740667f98fbf1d1ce5a7979 (patch) | |
tree | 2a1e1c310ad97110a9f691d29b5e51505fa7418b /lisp/textmodes/css-mode.el | |
parent | b19259c8412ee2e715c4bd145711e23729411fd0 (diff) | |
download | emacs-68ae6faa7f1b4c348740667f98fbf1d1ce5a7979.tar.gz |
Improved light/dark colour predicate (bug#41544)
Add a predicate, color-dark-p, for deciding whether a colour is more
readable with black or white as contrast. It has experimentally been
shown to be more accurate and robust than the various methods
currently employed.
The new predicate compares the relative luminance of the colour to an
empirically determined cut-off value, and it seems to get it right in
almost all cases, with no value leading to outright bad results.
* lisp/faces.el (readable-foreground-color): Use color-dark-p.
(color-dark-p): New function.
* lisp/facemenu.el (list-colors-print): Use readable-foreground-color,
improving readability of list-colors-display.
* lisp/textmodes/css-mode.el (css--contrasty-color): Remove.
(css--fontify-region): Use readable-foreground-color.
Diffstat (limited to 'lisp/textmodes/css-mode.el')
-rw-r--r-- | lisp/textmodes/css-mode.el | 14 |
1 files changed, 2 insertions, 12 deletions
diff --git a/lisp/textmodes/css-mode.el b/lisp/textmodes/css-mode.el index 0035c5e7b05..2cd99787e8a 100644 --- a/lisp/textmodes/css-mode.el +++ b/lisp/textmodes/css-mode.el @@ -1149,17 +1149,6 @@ returns, point will be at the end of the recognized color." ;; Evaluate to the color if the name is found. ((css--named-color start-point match)))) -(defun css--contrasty-color (name) - "Return a color that contrasts with NAME. -NAME is of any form accepted by `color-distance'. -The returned color will be usable by Emacs and will contrast -with NAME; in particular so that if NAME is used as a background -color, the returned color can be used as the foreground and still -be readable." - ;; See bug#25525 for a discussion of this. - (if (> (color-distance name "black") 292485) - "black" "white")) - (defcustom css-fontify-colors t "Whether CSS colors should be fontified using the color as the background. When non-`nil', a text representing CSS color will be fontified @@ -1199,7 +1188,8 @@ START and END are buffer positions." (add-text-properties start (point) (list 'face (list :background color - :foreground (css--contrasty-color color) + :foreground (readable-foreground-color + color) :box '(:line-width -1)))))))))))) extended-region)) |