Add 2012 to FSF copyright years for Emacs files
[bpt/emacs.git] / lisp / ps-mule.el
index 1a97f2d..7db3264 100644 (file)
@@ -1,13 +1,13 @@
 ;;; ps-mule.el --- provide multi-byte character facility to ps-print
 
-;; Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004,
-;;   2005, 2006, 2007, 2008 Free Software Foundation, Inc.
+;; Copyright (C) 1998-2012 Free Software Foundation, Inc.
 
 ;; Author: Vinicius Jose Latorre <viniciusjl@ig.com.br>
 ;;     Kenichi Handa <handa@m17n.org> (multi-byte characters)
 ;; Maintainer: Kenichi Handa <handa@m17n.org> (multi-byte characters)
 ;;     Vinicius Jose Latorre <viniciusjl@ig.com.br>
 ;; Keywords: wp, print, PostScript, multibyte, mule
+;; Package: ps-print
 
 ;; This file is part of GNU Emacs.
 
 
 ;;; Code:
 
-(eval-and-compile
-  (require 'ps-print))
+(require 'ps-print)
 
 
 ;;;###autoload
 (defcustom ps-multibyte-buffer nil
-  "*Specifies the multi-byte buffer handling.
+  "Specifies the multi-byte buffer handling.
 
 Valid values are:
 
@@ -188,7 +187,7 @@ See also the variable `ps-font-info-database'.")
 
 (defcustom ps-mule-font-info-database-default
   ps-mule-font-info-database-latin
-  "*The default setting to use when `ps-multibyte-buffer' is nil."
+  "The default setting to use when `ps-multibyte-buffer' is nil."
   :type '(symbol :tag "Multi-Byte Buffer Database Font Default")
   :group 'ps-print-font)
 
@@ -319,31 +318,19 @@ by `ps-font-family' and `ps-header-font-family'.
 
 See also `ps-mule-font-info-database-bdf'.")
 
-(defvar ps-mule-font-spec-list nil
-  "Array of FONT-SPEC lists for each font type.
-
-Elements are for `normal' font, `bold' font, `italic' font, and
-`bold-italic' font in this order.
-
-Each element is a list of FONT-SPEC which has this form:
-
-       (ID CHARSET (FONT-SRC FONT-NAME ENCODING) EXTRA-DATA)
-
-Where
-
-ID is a number for this FONT-SPEC and is unique in the list.
-
-CHARSET, FONT-SRC, FONT-NAME, ENCODING are the same as those in
-`ps-mule-font-info-database' (which see).
-
-EXTRA-DATA is a data attached by external libraries.
-
-Each list is ordered by the current charset priorities.
-
-This variable is setup by `ps-mule-begin-job' from
-`ps-mule-font-info-database'.")
-
 ;; Functions to access each element of FONT-SPEC.
+;;
+;; FONT-SPEC is a vector of this form:
+;;     [ID CHARSET FONT-ID FONT-SRC FONT-NAME ENCODING BYTES EXTRA-DATA]
+;; Where
+;;
+;; ID is an identification number for this FONT-SPEC and is unique in the list.
+;;
+;; CHARSET, FONT-SRC, FONT-NAME, ENCODING, and BYTES are the same as those in
+;; `ps-mule-font-info-database' (which see).
+;;
+;; EXTRA-DATA is a data attached by external libraries.
+
 (defsubst ps-mule-font-spec-id (font-spec) (aref font-spec 0))
 (defsubst ps-mule-font-spec-charset (font-spec) (aref font-spec 1))
 (defsubst ps-mule-font-spec-font-id (font-spec) (aref font-spec 2))
@@ -379,7 +366,7 @@ This variable is setup by `ps-mule-begin-job' from
 ;; character is printed by which FONT-SPEC.  It has one extra slot
 ;; whose value is an alist of the form:
 ;;     (CHARSET . FONT-SPEC)
-;; FONT-SPEC is a vecotr of the form:
+;; FONT-SPEC is a vector of the form:
 ;;     (ID FONT-SRC FONT-NAME ENCODING EXTRA)
 (defvar ps-mule-font-spec-tables nil)
 
@@ -645,7 +632,7 @@ f2, f3, h0, h1, and H0 respectively."
            (ps-output "]"))))))
   (ps-output " ] " (if (nth 3 composition) "RLC" "RBC") "\n"))
 
-(defun ps-mule-plot-string (from to &optional bg-color)
+(defun ps-mule-plot-string (from to &optional _bg-color)
   "Generate PostScript code for plotting characters in the region FROM and TO.
 
 Optional argument BG-COLOR is ignored.
@@ -672,7 +659,7 @@ the sequence."
         width)
     (goto-char from)
     (while (not endpos)
-      (cond ((= (point) stop)
+      (cond ((>= (point) stop)
             (if (= stop to)
                 (setq endpos stop)
               (when (< from stop)
@@ -945,7 +932,7 @@ the sequence."
     (list ps-mule-bitmap-prologue)))
 
 (defun ps-mule-generate-bitmap-font (font-spec size relative-compose
-                                              baselie-offset bbx)
+                                              baseline-offset bbx)
   (let* ((id (ps-mule-font-spec-id font-spec))
         (bytes (ps-mule-font-spec-bytes font-spec))
         output-list)
@@ -954,7 +941,7 @@ the sequence."
              (list (format "/E%02X [ 0 1 255 {pop /.notdef} for ] def\n" id)
                    (format "%%%% %s\n" (ps-mule-font-spec-name font-spec))
                    (format "/F%02X %f %S %d E%02X NBF\n" id size
-                           relative-compose baselie-offset id)))
+                           relative-compose baseline-offset id)))
       (setq output-list
            (list (list (format "/E%02X [ 0 1 255 { pop 0 } for ] def\n" id))
                  (list (format "/V%02X [" id))
@@ -963,7 +950,7 @@ the sequence."
                  (format "/F%02X E%02X V%02X NPF\n" id id id))))
     (aset ps-mule-bitmap-font-record id
          (vector (= bytes 1) output-list
-                 size relative-compose baselie-offset bbx))
+                 size relative-compose baseline-offset bbx))
     (if ps-mule-bitmap-dict-list
        output-list
       (setq ps-mule-bitmap-dict-list (list "/BitmapDict <<\n" ">> def\n"))
@@ -1023,7 +1010,7 @@ the sequence."
          ps-mule-external-libraries))
 
 (defun ps-mule-encode-header-string (string fonttag)
-  "Generate PostScript code for ploting STRING by font FONTTAG.
+  "Generate PostScript code for plotting STRING by font FONTTAG.
 FONTTAG should be a string \"/h0\", \"/h1\", \"/L0\", or \"/H0\".
 Any other value is treated as \"/H0\"."
   (with-temp-buffer
@@ -1040,11 +1027,10 @@ Any other value is treated as \"/H0\"."
 (defun ps-mule-begin-job (from to)
   "Start printing job for multi-byte chars between FROM and TO.
 It checks if all multi-byte characters in the region are printable or not."
-  (auto-compose-region from to)
   (if (and (not (find-composition from to))
           (save-excursion
             (goto-char from)
-            (= (skip-chars-forward "\x00-\xFF" to) to)))
+            (= (skip-chars-forward "\x00-\x7F" to) to)))
       ;; All characters can be printed by normal PostScript fonts.
       (setq ps-basic-plot-string-function 'ps-basic-plot-string
            ps-encode-header-string-function 'identity)
@@ -1086,17 +1072,19 @@ It checks if all multi-byte characters in the region are printable or not."
              (setq font-info-list (cons font-info font-info-list))))
        (setq font-info-list (nreverse font-info-list)))
 
+      ;; Now font-info-list is an alist ordered by charset priority.
       ;; Store FONT-SPECs in each element of font-spec-alist.
       (dolist (font-info font-info-list)
        (let ((font-spec-vec (make-vector 4 nil))
              (charset (car font-info))
-             encoding font-spec)
+             encoding bytes font-spec)
          (dolist (e (cdr font-info))
-           (setq encoding (or (nth 3 e) charset)
-                 font-spec (vector id-max charset font-id
+           (setq encoding (nth 3 e) bytes (nth 4 e))
+           (unless encoding
+             (setq encoding charset bytes (charset-dimension charset)))
+           (setq font-spec (vector id-max charset font-id
                                    (nth 1 e) (nth 2 e) encoding
-                                   (or (nth 4 e) (charset-dimension encoding))
-                                   nil)
+                                   (or bytes 1) nil)
                  id-max (1+ id-max))
            (if (ps-mule-check-font font-spec)
                (aset font-spec-vec
@@ -1153,7 +1141,7 @@ It checks if all multi-byte characters in the region are printable or not."
                           (aref ps-mule-font-spec-tables font-type) 0)))
     (ps-output-prologue
      (list (if (ps-mule-font-spec-src (cdr (car font-spec-alist)))
-              ;; We ignore a font specfied in ps-font-info-database.
+              ;; We ignore a font specified in ps-font-info-database.
               (format "/V%s VTOP%d def\n" fonttag font-type)
             (format "/V%s [ VTOP%d aload pop ] def\n
 V%s 0 /%s-latin1 /%s Latin1Encoding put\n"
@@ -1221,5 +1209,4 @@ V%s 0 /%s-latin1 /%s Latin1Encoding put\n"
 ;; generated-autoload-file: "ps-print.el"
 ;; End:
 
-;; arch-tag: bca017b2-66a7-4e59-8584-103e749eadbe
 ;;; ps-mule.el ends here