Sync to HEAD
[bpt/emacs.git] / lisp / international / mule-util.el
index 0ba9bf5..c3ea76c 100644 (file)
@@ -2,12 +2,11 @@
 
 ;; Copyright (C) 1995 Electrotechnical Laboratory, JAPAN.
 ;;   Licensed to the Free Software Foundation.
-;; Copyright (C) 2002 Free Software Foundation, Inc.
+;; Copyright (C) 2000, 2002 Free Software Foundation, Inc.
 ;; Copyright (C) 2003
 ;;   National Institute of Advanced Industrial Science and Technology (AIST)
 ;;   Registration Number H13PRO009
 
-
 ;; Keywords: mule, multilingual
 
 ;; This file is part of GNU Emacs.
@@ -186,18 +185,18 @@ defaults to \"...\"."
 ;;             (("foobarbaz" 6 nil nil "...") . "foo...")
 ;;             (("foobarbaz" 7 2 nil "...") . "ob...")
 ;;             (("foobarbaz" 9 3 nil "...") . "barbaz")
-;;             (("\e$B$3\e(Bh\e$B$s\e(Be\e$B$K\e(Bl\e$B$A\e(Bl\e$B$O\e(Bo" 15 1 ?  t) . " h\e$B$s\e(Be\e$B$K\e(Bl\e$B$A\e(Bl\e$B$O\e(Bo")
-;;             (("\e$B$3\e(Bh\e$B$s\e(Be\e$B$K\e(Bl\e$B$A\e(Bl\e$B$O\e(Bo" 14 1 ?  t) . " h\e$B$s\e(Be\e$B$K\e(Bl\e$B$A\e(B...")
-;;             (("x" 3 nil nil "\e$(0GnM$\e(B") . "x")
-;;             (("\e$AVP\e(B" 2 nil nil "\e$(0GnM$\e(B") . "\e$AVP\e(B")
-;;             (("\e$AVP\e(B" 1 nil ?x "\e$(0GnM$\e(B") . "x") ;; XEmacs error
-;;             (("\e$AVPND\e(B" 3 nil ?  "\e$(0GnM$\e(B") . "\e$AVP\e(B ") ;; XEmacs error
-;;             (("foobarbaz" 4 nil nil  "\e$(0GnM$\e(B") . "\e$(0GnM$\e(B")
-;;             (("foobarbaz" 5 nil nil  "\e$(0GnM$\e(B") . "f\e$(0GnM$\e(B")
-;;             (("foobarbaz" 6 nil nil  "\e$(0GnM$\e(B") . "fo\e$(0GnM$\e(B")
-;;             (("foobarbaz" 8 3 nil "\e$(0GnM$\e(B") . "b\e$(0GnM$\e(B")
-;;             (("\e$B$3\e(Bh\e$B$s\e(Be\e$B$K\e(Bl\e$B$A\e(Bl\e$B$O\e(Bo" 14 4 ?x "\e$BF|K\8l\e(B") . "xe\e$B$KF|K\8l\e(B")
-;;             (("\e$B$3\e(Bh\e$B$s\e(Be\e$B$K\e(Bl\e$B$A\e(Bl\e$B$O\e(Bo" 13 4 ?x "\e$BF|K\8l\e(B") . "xex\e$BF|K\8l\e(B")
+;;             (("\e$A$3\e(Bh\e$A$s\e(Be\e$A$K\e(Bl\e$A$A\e(Bl\e$A$O\e(Bo" 15 1 ?  t) . " h\e$A$s\e(Be\e$A$K\e(Bl\e$A$A\e(Bl\e$A$O\e(Bo")
+;;             (("\e$A$3\e(Bh\e$A$s\e(Be\e$A$K\e(Bl\e$A$A\e(Bl\e$A$O\e(Bo" 14 1 ?  t) . " h\e$A$s\e(Be\e$A$K\e(Bl\e$A$A\e(B...")
+;;             (("x" 3 nil nil "\e$(Gemk#\e(B") . "x")
+;;             (("\e$AVP\e(B" 2 nil nil "\e$(Gemk#\e(B") . "\e$AVP\e(B")
+;;             (("\e$AVP\e(B" 1 nil ?x "\e$(Gemk#\e(B") . "x") ;; XEmacs error
+;;             (("\e$AVPND\e(B" 3 nil ?  "\e$(Gemk#\e(B") . "\e$AVP\e(B ") ;; XEmacs error
+;;             (("foobarbaz" 4 nil nil  "\e$(Gemk#\e(B") . "\e$(Gemk#\e(B")
+;;             (("foobarbaz" 5 nil nil  "\e$(Gemk#\e(B") . "f\e$(Gemk#\e(B")
+;;             (("foobarbaz" 6 nil nil  "\e$(Gemk#\e(B") . "fo\e$(Gemk#\e(B")
+;;             (("foobarbaz" 8 3 nil "\e$(Gemk#\e(B") . "b\e$(Gemk#\e(B")
+;;             (("\e$A$3\e(Bh\e$A$s\e(Be\e$A$K\e(Bl\e$A$A\e(Bl\e$A$O\e(Bo" 14 4 ?x "\e$AHU1>\e$(Gk#\e(B") . "xe\e$A$KHU1>\e$(Gk#\e(B")
+;;             (("\e$A$3\e(Bh\e$A$s\e(Be\e$A$K\e(Bl\e$A$A\e(Bl\e$A$O\e(Bo" 13 4 ?x "\e$AHU1>\e$(Gk#\e(B") . "xex\e$AHU1>\e$(Gk#\e(B")
 ;;             ))
 ;;   (let (ret)
 ;;     (condition-case e
@@ -366,6 +365,50 @@ language environment LANG-ENV."
        (with-coding-priority coding-priority
           (detect-coding-region from to)))))
 
+;;;###autoload
+(defun char-displayable-p (char)
+  "Return non-nil if we should be able to display CHAR.
+On a multi-font display, the test is only whether there is an
+appropriate font from the selected frame's fontset to display CHAR's
+charset in general.  Since fonts may be specified on a per-character
+basis, this may not be accurate."
+  (cond ((< char 256)
+        ;; Single byte characters are always displayable.
+        t)
+       ((display-multi-font-p)
+        ;; On a window system, a character is displayable if we have
+        ;; a font for that character in the default face of the
+        ;; currently selected frame.
+        (let ((fontset (frame-parameter (selected-frame) 'font))
+              font-pattern)
+          (if (query-fontset fontset)
+              (setq font-pattern (fontset-font fontset char)))
+          (or font-pattern
+              (setq font-pattern (fontset-font "fontset-default" char)))
+          (if font-pattern
+              (progn
+                ;; Now FONT-PATTERN is a string or a cons of family
+                ;; field pattern and registry field pattern.
+                (or (stringp font-pattern)
+                    (let ((family (or (car font-pattern) "*"))
+                          (registry (or (cdr font-pattern) "*")))
+                      (or (string-match "-" family)
+                          (setq family (concat "*-" family)))
+                      (or (string-match "-" registry)
+                          (setq registry (concat registry "-*")))
+                      (setq font-pattern
+                            (format "-%s-*-*-*-*-*-*-*-*-*-*-%s"
+                                    family registry))))
+                (x-list-fonts font-pattern 'default (selected-frame) 1)))))
+       (t
+        (let ((coding (terminal-coding-system)))
+          (if coding
+              (let ((safe-chars (coding-system-get coding 'safe-chars))
+                    (safe-charsets (coding-system-get coding 'safe-charsets)))
+                (or (and safe-chars
+                         (aref safe-chars char))
+                    (and safe-charsets
+                         (memq (char-charset char) safe-charsets)))))))))
 \f
 (provide 'mule-util)
 
@@ -373,4 +416,5 @@ language environment LANG-ENV."
 ;; coding: iso-2022-7bit
 ;; End:
 
+;;; arch-tag: 5bdb52b6-a3a5-4529-b7a0-37d01b0e570b
 ;;; mule-util.el ends here