Spelling fixes.
[bpt/emacs.git] / lisp / ps-mule.el
index f3bbd53..c8bdc27 100644 (file)
@@ -1,20 +1,20 @@
 ;;; 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-2011 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.
 
-;; GNU Emacs is free software; you can redistribute it and/or modify
+;; GNU Emacs is free software: you can redistribute it and/or modify
 ;; it under the terms of the GNU General Public License as published by
-;; the Free Software Foundation; either version 3, or (at your option)
-;; any later version.
+;; the Free Software Foundation, either version 3 of the License, or
+;; (at your option) any later version.
 
 ;; GNU Emacs is distributed in the hope that it will be useful,
 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -22,9 +22,7 @@
 ;; GNU General Public License for more details.
 
 ;; You should have received a copy of the GNU General Public License
-;; along with GNU Emacs; see the file COPYING.  If not, write to the
-;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-;; Boston, MA 02110-1301, USA.
+;; along with GNU Emacs.  If not, see <http://www.gnu.org/licenses/>.
 
 ;;; Commentary:
 
 
 ;;; 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:
 
@@ -190,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)
 
@@ -321,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))
@@ -381,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)
 
@@ -441,8 +426,8 @@ PostScript procedures that will be called by FONT-FUNC and GLYPHS-FUNC.  It is
 called with no argument, and should return a list of strings.
 
 CHECK-FUNC is a function to check if a font is available or not.
-It is called with one argument FONT-SPEC, and should return non-nil iff the
-font specified in FONT-SPEC is available.
+It is called with one argument FONT-SPEC, and should return non-nil if and
+only if the font specified in FONT-SPEC is available.
 
 FONT-FUNC is a function to generate PostScript code which define a new font.
 It is called with one argument FONT-SPEC, and should return a list of strings.
@@ -647,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.
@@ -674,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)
@@ -738,7 +723,7 @@ the sequence."
        } ifelse def
        dup 0 get stringwidth pop dup /WIDTH exch def bmp 0 get div
        dup LLY mul /LLY exch def
-       URY mul /URY exch def   
+       URY mul /URY exch def
     } {
        pop
        dup 0 get stringwidth pop /WIDTH exch def
@@ -793,7 +778,7 @@ the sequence."
     /RIGHT WIDTH def
     /TOP URY def
     /BOTTOM LLY def
-       
+
     1 1 components length 1 sub {
        components exch get
        [ exch
@@ -973,7 +958,7 @@ the sequence."
 
 (defun ps-mule-generate-bitmap-glyph (font-spec char code bitmap)
   (let* ((id (ps-mule-font-spec-id font-spec))
-        ;; FONT-RECORD ::= ([(SUBFONT-OUTPUT-LIST ...) | t] 
+        ;; FONT-RECORD ::= ([(SUBFONT-OUTPUT-LIST ...) | t]
         ;;                  BASEFONT-OUTPUT-LIST SIZE REL-COMP B-OFFSET BBX)
         (font-record (aref ps-mule-bitmap-font-record id))
         enc-name
@@ -1025,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
@@ -1042,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)
@@ -1088,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
@@ -1151,7 +1137,7 @@ It checks if all multi-byte characters in the region are printable or not."
 
 (defun ps-mule-redefine-font (font-number fonttag size ps-font)
   (let* ((font-type (aref ps-mule-font-number-to-type font-number))
-        (font-spec-alist (char-table-extra-slot 
+        (font-spec-alist (char-table-extra-slot
                           (aref ps-mule-font-spec-tables font-type) 0)))
     (ps-output-prologue
      (list (if (ps-mule-font-spec-src (cdr (car font-spec-alist)))
@@ -1172,7 +1158,7 @@ V%s 0 /%s-latin1 /%s Latin1Encoding put\n"
   (let ((output-head (list t))
        (ps-mule-output-list (list t)))
     (dotimes (i 4)
-      (map-char-table 'ps-mule-prepare-glyph 
+      (map-char-table 'ps-mule-prepare-glyph
                      (aref ps-mule-font-spec-tables i)))
     (ps-mule-restruct-output-list (cdr ps-mule-output-list) output-head)
     (ps-output-prologue (cdr output-head)))
@@ -1200,7 +1186,7 @@ V%s 0 /%s-latin1 /%s Latin1Encoding put\n"
                                  (mapconcat #'(lambda (x)
                                                 (format "F%02X" (cdr x)))
                                             font-list " ")))))
-       
+
   ;; Redefine fonts f0, f1, f2, f3, h0, h1, H0.
   (ps-mule-redefine-font 4 "h0" ps-header-title-font-size-internal
                         (ps-font 'ps-font-for-header 'bold))
@@ -1223,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