aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEli Zaretskii1999-02-01 13:25:12 +0000
committerEli Zaretskii1999-02-01 13:25:12 +0000
commita13b5fad5decb653a3fe129def087fc120ba54a2 (patch)
tree4214071d7d37780210d2bbeb2bf27d85b8197643
parentf670496a300de6ae65625d82ecd3ef26ea522587 (diff)
downloademacs-a13b5fad5decb653a3fe129def087fc120ba54a2.tar.gz
emacs-a13b5fad5decb653a3fe129def087fc120ba54a2.zip
(msdos-approximate-color): New function.
(msdos-color-translate): Call it to find a DOS color that best approximates an X-style "#NNNNNN" color specification.
-rw-r--r--lisp/term/pc-win.el29
1 files changed, 28 insertions, 1 deletions
diff --git a/lisp/term/pc-win.el b/lisp/term/pc-win.el
index 2a20dea4527..c97391060c8 100644
--- a/lisp/term/pc-win.el
+++ b/lisp/term/pc-win.el
@@ -175,6 +175,7 @@
175 "List of alternate names for colors.") 175 "List of alternate names for colors.")
176 176
177(defun msdos-color-translate (name) 177(defun msdos-color-translate (name)
178 "Translate color specification in NAME into something DOS terminal groks."
178 (setq name (downcase name)) 179 (setq name (downcase name))
179 (let* ((len (length name)) 180 (let* ((len (length name))
180 (val (- (length x-colors) 181 (val (- (length x-colors)
@@ -232,7 +233,33 @@
232 (and 233 (and
233 (string-match "[1-4]\\'" name) 234 (string-match "[1-4]\\'" name)
234 (msdos-color-translate 235 (msdos-color-translate
235 (substring name 0 (match-beginning 0))))))))) 236 (substring name 0 (match-beginning 0))))))
237 (and (= len 7) ;; X-style "#XXYYZZ" color spec
238 (eq (aref name 0) ?#)
239 (member (aref name 1)
240 '(?0 ?1 ?2 ?3 ?4 ?5 ?6 ?7 ?8 ?9
241 ?A ?B ?C ?D ?E ?F ?a ?b ?c ?d ?e ?f))
242 (msdos-color-translate
243 (msdos-approximate-color (string-to-number
244 (substring name 1) 16)))))))
245
246(defun msdos-approximate-color (num)
247 "Return a DOS color name which is the best approximation for the number NUM."
248 (let ((color-values msdos-color-values)
249 (candidate (car msdos-color-values))
250 (best-distance 16777216) ;; 0xFFFFFF + 1
251 best-color)
252 (while candidate
253 (let* ((values (cdr candidate))
254 (value (+ (lsh (car values) 16)
255 (lsh (car (cdr values)) 8)
256 (nth 2 values))))
257 (if (< (abs (- value num)) best-distance)
258 (setq best-distance (abs (- value num))
259 best-color (car candidate))))
260 (setq color-values (cdr color-values))
261 (setq candidate (car color-values)))
262 best-color))
236;; --------------------------------------------------------------------------- 263;; ---------------------------------------------------------------------------
237;; We want to delay setting frame parameters until the faces are setup 264;; We want to delay setting frame parameters until the faces are setup
238(defvar default-frame-alist nil) 265(defvar default-frame-alist nil)