]> code.delx.au - gnu-emacs/blobdiff - lisp/ps-mule.el
(rmail-convert-to-babyl-format): Display a message while converting to Babyl.
[gnu-emacs] / lisp / ps-mule.el
index 901ee180083294420a317192e44f8d3fcaf91927..1d13358f53d223c9b7f1d982d04b2e01f92e1f25 100644 (file)
@@ -1,13 +1,14 @@
-;;; ps-mule.el --- Provide multi-byte character facility to ps-print.
+;;; ps-mule.el --- provide multi-byte character facility to ps-print
 
-;; Copyright (C) 1998,99,00,2001 Free Software Foundation, Inc.
+;; Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003
+;; Free Software Foundation, Inc.
 
-;; Author:     Vinicius Jose Latorre <vinicius@cpqd.com.br>
-;; Author:     Kenichi Handa <handa@etl.go.jp> (multi-byte characters)
-;; Maintainer: Kenichi Handa <handa@etl.go.jp> (multi-byte characters)
-;; Maintainer: Vinicius Jose Latorre <vinicius@cpqd.com.br>
-;; Keywords:   wp, print, PostScript, multibyte, mule
-;; Time-stamp: <2001/03/16 18:50:59 Handa>
+;; Author: Vinicius Jose Latorre <vinicius@cpqd.com.br>
+;;     Kenichi Handa <handa@etl.go.jp> (multi-byte characters)
+;; Maintainer: Kenichi Handa <handa@etl.go.jp> (multi-byte characters)
+;;     Vinicius Jose Latorre <vinicius@cpqd.com.br>
+;; Keywords: wp, print, PostScript, multibyte, mule
+;; Time-stamp: <2003/05/14 22:19:41 vinicius>
 
 ;; This file is part of GNU Emacs.
 
   (or (fboundp 'find-charset-region)
       (defun find-charset-region (beg end &optional table)
        (list 'ascii)))
+  (or (fboundp 'char-valid-p)
+      (defun char-valid-p (char)
+       (< (following-char) 256)))
   (or (fboundp 'split-char)
       (defun split-char (char)
        (list (if (char-valid-p char)
        str))
   (or (fboundp 'define-ccl-program)
       (defmacro define-ccl-program (name ccl-program &optional doc)
-       `(defconst ,name nil ,doc))))
+       `(defconst ,name nil ,doc)))
+  (or (fboundp 'multibyte-string-p)
+      (defun multibyte-string-p (str)
+       (let ((len (length str))
+             (i 0)
+             multibyte)
+         (while (and (< i len) (not (setq multibyte (> (aref str i) 255))))
+           (setq i (1+ i)))
+         multibyte)))
+  (or (fboundp 'string-make-multibyte)
+      (defalias 'string-make-multibyte 'copy-sequence))
+  (or (fboundp 'encode-char)
+      (defun encode-char (ch ccs)
+       ch)))
 
 
 ;;;###autoload
@@ -229,11 +246,11 @@ Any other value is treated as nil."
          (+ (* (car rule) 12) (cdr rule)))
        (defun find-composition (pos &rest ignore)
          (let ((ch (char-after pos)))
-           (if (eq (char-charset ch) 'composition)
-               (let ((components (decompose-composite-char ch 'vector t)))
-                 (list pos (ps-mule-next-point pos) components
-                       (integerp (aref components 1)) nil
-                       (char-width ch)))))))
+           (and ch (eq (char-charset ch) 'composition)
+                (let ((components (decompose-composite-char ch 'vector t)))
+                  (list pos (ps-mule-next-point pos) components
+                        (integerp (aref components 1)) nil
+                        (char-width ch)))))))
     ;; mule package isn't loaded
     (or (fboundp 'encode-composition-rule)
        (defun encode-composition-rule (rule)
@@ -383,7 +400,7 @@ Currently, data for Japanese and Korean PostScript printers are listed.")
     (arabic-2-column
      (normal bdf ("arab24-2-etl.bdf" "etl24-arabic2.bdf") ps-mule-encode-7bit 1))
     (indian-is13194
-     (normal bdf ("isci24-etl.bdf" "mule-iscii-24.bdf") ps-mule-encode-7bit 1))
+     (normal bdf ("isci24-mule.bdf" "mule-iscii-24.bdf") ps-mule-encode-7bit 1))
     (indian-1-column
      (normal bdf ("ind1c24-mule.bdf" "mule-indian-1col-24.bdf") ps-mule-encode-7bit 2))
     (tibetan-1-column
@@ -404,16 +421,22 @@ Currently, data for Japanese and Korean PostScript printers are listed.")
      (normal bdf ("ind24-mule.bdf" "mule-indian-24.bdf") ps-mule-encode-7bit 2))
     (tibetan
      (normal bdf ("tib24p-mule.bdf" "tib24-mule.bdf" "mule-tibmdx-24.bdf")
-            ps-mule-encode-7bit 2)))
+            ps-mule-encode-7bit 2))
+    (mule-unicode-0100-24ff
+     (normal bdf "etl24-unicode.bdf" ps-mule-encode-ucs2 2))
+    (mule-unicode-2500-33ff
+     (normal bdf "etl24-unicode.bdf" ps-mule-encode-ucs2 2))
+    (mule-unicode-e000-ffff
+     (normal bdf "etl24-unicode.bdf" ps-mule-encode-ucs2 2)))
   "Sample setting of the `ps-mule-font-info-database' to use BDF fonts.
 BDF (Bitmap Distribution Format) is a format used for distributing X's font
 source file.
 
-Current default value list for BDF fonts is included in `intlfonts-1.2' which is
-a collection of X11 fonts for all characters supported by Emacs.
+Current default value list for BDF fonts is included in `intlfonts-1.2'
+which is a collection of X11 fonts for all characters supported by Emacs.
 
-Using this list as default value to `ps-mule-font-info-database', all characters
-including ASCII and Latin-1 are printed by BDF fonts.
+Using this list as default value to `ps-mule-font-info-database', all
+characters including ASCII and Latin-1 are printed by BDF fonts.
 
 See also `ps-mule-font-info-database-ps-bdf'.")
 
@@ -422,13 +445,13 @@ See also `ps-mule-font-info-database-ps-bdf'.")
        (cdr (cdr ps-mule-font-info-database-bdf)))
   "Sample setting of the `ps-mule-font-info-database' to use BDF fonts.
 
-Current default value list for BDF fonts is included in `intlfonts-1.2' which is
-a collection of X11 fonts for all characters supported by Emacs.
+Current default value list for BDF fonts is included in `intlfonts-1.2'
+which is a collection of X11 fonts for all characters supported by Emacs.
 
-Using this list as default value to `ps-mule-font-info-database', all characters
-except ASCII and Latin-1 characters are printed by BDF fonts.  ASCII and Latin-1
-characters are printed by PostScript font specified by `ps-font-family' and
-`ps-header-font-family'.
+Using this list as default value to `ps-mule-font-info-database', all
+characters except ASCII and Latin-1 characters are printed with BDF fonts.
+ASCII and Latin-1 characters are printed with PostScript font specified
+by `ps-font-family' and `ps-header-font-family'.
 
 See also `ps-mule-font-info-database-bdf'.")
 
@@ -490,6 +513,23 @@ See also `ps-mule-font-info-database-bdf'.")
   (defun ps-mule-encode-ethiopic (string)
     string))
 
+;; Special encoding for mule-unicode-* characters.
+(defun ps-mule-encode-ucs2 (string)
+  (let* ((len (ps-mule-chars-in-string string))
+        (str (make-string (* 2 len) 0))
+        (i 0)
+        (j 0)
+        ch hi lo)
+    (while (< i len)
+      (setq ch (encode-char (ps-mule-string-char string i) 'ucs)
+           hi (lsh ch -8)
+           lo (logand ch 255))
+      (aset str j hi)
+      (aset str (1+ j) lo)
+      (setq i (1+ i)
+           j (+ j 2)))
+    str))
+
 ;; A charset which we are now processing.
 (defvar ps-mule-current-charset nil)
 
@@ -1117,10 +1157,10 @@ the sequence."
        } ifelse } ifelse } ifelse
     } forall ] /components exch def
     grestore
-    
+
     %% Reflect special effects.
     SpecialEffect
-    
+
     %% Draw components while ignoring effects other than shadow and outline.
     components ShowComponents
 
@@ -1349,17 +1389,22 @@ NewBitmapDict
 (defun ps-mule-encode-header-string (string fonttag)
   "Generate PostScript code for ploting STRING by font FONTTAG.
 FONTTAG should be a string \"/h0\" or \"/h1\"."
-  (setq string (if (multibyte-string-p string)
-                  (copy-sequence string)
-                (string-make-multibyte string)))
+  (setq string (cond ((not (stringp string))
+                     "")
+                    ((multibyte-string-p string)
+                     (copy-sequence string))
+                    (t
+                     (string-make-multibyte string))))
   (when ps-mule-header-charsets
     (if (eq (car ps-mule-header-charsets) 'latin-iso8859-1)
        ;; Latin1 characters can be printed by the standard PostScript
        ;; font.  Converts the other non-ASCII characters to `?'.
-       (let ((len (length string)))
-         (dotimes (i len)
+       (let ((len (length string))
+             (i 0))
+         (while (< i len)
            (or (memq (char-charset (aref string i)) '(ascii latin-iso8859-1))
-               (aset string i ??)))
+               (aset string i ??))
+           (setq i (1+ i)))
          (setq string (encode-coding-string string 'iso-latin-1)))
       ;; We must prepare a font for the first non-ASCII and non-Latin1
       ;; character in STRING.
@@ -1374,45 +1419,37 @@ FONTTAG should be a string \"/h0\" or \"/h1\"."
            ;; We don't have a proper font, or we can't print them on
            ;; header because this kind of charset is not ASCII
            ;; compatible.
-           (let ((len (length string)))
-             (dotimes (i len)
+           (let ((len (length string))
+                 (i 0))
+             (while (< i len)
                (or (memq (char-charset (aref string i))
                          '(ascii latin-iso8859-1))
-                   (aset string i ??)))
+                   (aset string i ??))
+               (setq i (1+ i)))
              (setq string (encode-coding-string string 'iso-latin-1)))
          (let ((charsets (list 'ascii (car ps-mule-header-charsets)))
-               (len (length string)))
-           (dotimes (i len)
+               (len (length string))
+               (i 0))
+           (while (< i len)
              (or (memq (char-charset (aref string i)) charsets)
-                 (aset string i ??))))
+                 (aset string i ??))
+             (setq i (1+ i))))
          (setq string (ps-mule-string-encoding font-spec string nil t))))))
   string)
 
 ;;;###autoload
 (defun ps-mule-header-string-charsets ()
   "Return a list of character sets that appears in header strings."
-  (let ((str "")
-       len charset charset-list)
-    (when ps-print-header
-      (dolist (tail (list ps-left-header ps-right-header))
-       ;; Simulate what is done by ps-generate-header-line to get a
-       ;; string to plot.
-       (let ((count 0))
-         (dolist (elt tail)
-           (if (< count ps-header-lines)
-               (setq str (concat str (cond ((stringp elt) elt)
-                                           ((and (symbolp elt) (fboundp elt))
-                                            (funcall elt))
-                                           ((and (symbolp elt) (boundp elt))
-                                            (symbol-value elt))
-                                           (t "")))
-                     count (1+ count)))))))
-    (setq len (length str))
-    (dotimes (i len)
-      (setq charset (char-charset (aref str i)))
-      (or (eq charset 'ascii)
-         (memq charset charset-list)
-         (setq charset-list (cons charset charset-list))))
+  (let* ((str (ps-header-footer-string))
+        (len (length str))
+        (i 0)
+        charset-list)
+    (while (< i len)
+      (let ((charset (char-charset (aref str i))))
+       (setq i (1+ i))
+       (or (eq charset 'ascii)
+           (memq charset charset-list)
+           (setq charset-list (cons charset charset-list)))))
     charset-list))
 
 ;;;###autoload
@@ -1504,7 +1541,7 @@ This checks if all multi-byte characters in the region are printable or not."
                    ps-current-font (1+ ps-current-font)))))))
 
   ;; If the header contains non-ASCII and non-Latin1 characters, prepare a font
-  ;; and glyphs for the first occurance of such characters.
+  ;; and glyphs for the first occurrence of such characters.
   (if (and ps-mule-header-charsets
           (not (eq (car ps-mule-header-charsets) 'latin-iso8859-1)))
       (let ((font-spec (ps-mule-get-font-spec (car ps-mule-header-charsets)
@@ -1533,4 +1570,5 @@ This checks if all multi-byte characters in the region are printable or not."
 
 (provide 'ps-mule)
 
+;;; arch-tag: bca017b2-66a7-4e59-8584-103e749eadbe
 ;;; ps-mule.el ends here