aboutsummaryrefslogtreecommitdiffstats
path: root/lisp
diff options
context:
space:
mode:
authorKenichi Handa2003-09-26 11:42:33 +0000
committerKenichi Handa2003-09-26 11:42:33 +0000
commit76875dcbe40c0a6666a20b533d4957dbe69b2b86 (patch)
tree9bd9bf46e7aec8e0d1fa387754c59a625c74114c /lisp
parente7894f8e97c37266a18a1ea617aa61213685b1b2 (diff)
downloademacs-76875dcbe40c0a6666a20b533d4957dbe69b2b86.tar.gz
emacs-76875dcbe40c0a6666a20b533d4957dbe69b2b86.zip
Mostly re-written.
Diffstat (limited to 'lisp')
-rw-r--r--lisp/ps-bdf.el228
-rw-r--r--lisp/ps-mule.el1932
2 files changed, 968 insertions, 1192 deletions
diff --git a/lisp/ps-bdf.el b/lisp/ps-bdf.el
index 838cec330bd..92cc333e768 100644
--- a/lisp/ps-bdf.el
+++ b/lisp/ps-bdf.el
@@ -1,10 +1,14 @@
1;;; ps-bdf.el --- BDF font file handler for ps-print 1;;; ps-bdf.el --- BDF font file handler for ps-print
2 2
3;; Copyright (C) 1998, 1999, 2001, 2003 Electrotechnical Laboratory, JAPAN. 3;; Copyright (C) 1998, 1999, 2001 Electrotechnical Laboratory, JAPAN.
4;; Licensed to the Free Software Foundation. 4;; Licensed to the Free Software Foundation.
5;; Copyright (C) 2001, 2002, 2003 Free Software Foundation, Inc.
6;; Copyright (C) 2003
7;; National Institute of Advanced Industrial Science and Technology (AIST)
8;; Registration Number H13PRO009
5 9
6;; Keywords: wp, BDF, font, PostScript 10;; Keywords: wp, BDF, font, PostScript
7;; Maintainer: Kenichi Handa <handa@etl.go.jp> 11;; Maintainer: Kenichi Handa <handa@m17n.org>
8;; Time-stamp: <2003/07/11 21:13:44 vinicius> 12;; Time-stamp: <2003/07/11 21:13:44 vinicius>
9 13
10;; This file is part of GNU Emacs. 14;; This file is part of GNU Emacs.
@@ -59,15 +63,11 @@ for BDFNAME."
59 (if (file-name-absolute-p bdfname) 63 (if (file-name-absolute-p bdfname)
60 (and (file-readable-p bdfname) 64 (and (file-readable-p bdfname)
61 bdfname) 65 bdfname)
62 (let ((dir-list bdf-directory-list) 66 (catch 'tag
63 dir) 67 (dolist (dir bdf-directory-list)
64 (while (and dir-list 68 (let ((absolute-path (expand-file-name bdfname dir)))
65 (progn 69 (if (file-readable-p absolute-path)
66 (setq dir (expand-file-name bdfname (car dir-list))) 70 (throw 'tag absolute-path)))))))
67 (not (file-readable-p dir))))
68 (setq dir nil
69 dir-list (cdr dir-list)))
70 dir)))
71 71
72(defsubst bdf-file-mod-time (filename) 72(defsubst bdf-file-mod-time (filename)
73 "Return modification time of FILENAME. 73 "Return modification time of FILENAME.
@@ -79,28 +79,24 @@ The value is a list of two integers, the first integer has high-order
79 "Return non-nil if and only if FILENAME is newer than MOD-TIME. 79 "Return non-nil if and only if FILENAME is newer than MOD-TIME.
80MOD-TIME is a modification time as a list of two integers, the first 80MOD-TIME is a modification time as a list of two integers, the first
81integer has high-order 16 bits, the second has low 16 bits." 81integer has high-order 16 bits, the second has low 16 bits."
82 (let ((file-name (bdf-expand-file-name filename))) 82 (let* ((new-mod-time (bdf-file-mod-time filename))
83 (and file-name 83 (new-time (car new-mod-time))
84 (let* ((new-mod-time (bdf-file-mod-time file-name)) 84 (time (car mod-time)))
85 (new-time (car new-mod-time)) 85 (or (> new-time time)
86 (time (car mod-time))) 86 (and (= new-time time)
87 (or (> new-time time) 87 (> (nth 1 new-mod-time) (nth 1 mod-time))))))
88 (and (= new-time time)
89 (> (nth 1 new-mod-time) (nth 1 mod-time))))))))
90 88
91(defun bdf-find-file (bdfname) 89(defun bdf-find-file (bdfname)
92 "Return a buffer visiting a bdf file BDFNAME. 90 "Return a buffer visiting a bdf file BDFNAME.
93If BDFNAME is not an absolute path, directories listed in 91BDFNAME must be an absolute file name.
94`bdf-directory-list' is searched.
95If BDFNAME doesn't exist, return nil." 92If BDFNAME doesn't exist, return nil."
96 (let ((file-name (bdf-expand-file-name bdfname))) 93 (and (file-readable-p bdfname)
97 (and file-name 94 (let ((buf (generate-new-buffer " *bdf-work*"))
98 (let ((buf (generate-new-buffer " *bdf-work*")) 95 (coding-system-for-read 'no-conversion))
99 (coding-system-for-read 'no-conversion)) 96 (save-excursion
100 (save-excursion 97 (set-buffer buf)
101 (set-buffer buf) 98 (insert-file-contents bdfname)
102 (insert-file-contents file-name) 99 buf))))
103 buf)))))
104 100
105(defvar bdf-cache-file (if (eq system-type 'ms-dos) 101(defvar bdf-cache-file (if (eq system-type 'ms-dos)
106 ;; convert-standard-filename doesn't 102 ;; convert-standard-filename doesn't
@@ -113,7 +109,7 @@ If BDFNAME doesn't exist, return nil."
113(defvar bdf-cache nil 109(defvar bdf-cache nil
114 "Cached information of `BDF' font files. It is a list of FONT-INFO. 110 "Cached information of `BDF' font files. It is a list of FONT-INFO.
115FONT-INFO is a list of the following format: 111FONT-INFO is a list of the following format:
116 (BDFFILE ABSOLUTE-PATH MOD-TIME SIZE FONT-BOUNDING-BOX 112 (ABSOLUTE-FILE-NAME MOD-TIME SIZE FONT-BOUNDING-BOX
117 RELATIVE-COMPOSE BASELINE-OFFSET CODE-RANGE MAXLEN OFFSET-VECTOR) 113 RELATIVE-COMPOSE BASELINE-OFFSET CODE-RANGE MAXLEN OFFSET-VECTOR)
118See the documentation of the function `bdf-read-font-info' for more detail.") 114See the documentation of the function `bdf-read-font-info' for more detail.")
119 115
@@ -144,7 +140,7 @@ The file is written if and only if the file already exists and writable."
144(defun bdf-set-cache (font-info) 140(defun bdf-set-cache (font-info)
145 "Cache FONT-INFO as information about one `BDF' font file. 141 "Cache FONT-INFO as information about one `BDF' font file.
146FONT-INFO is a list of the following format: 142FONT-INFO is a list of the following format:
147 (BDFFILE ABSOLUTE-PATH MOD-TIME SIZE FONT-BOUNDING-BOX 143 (ABSOLUTE-FILE-NAME MOD-TIME SIZE FONT-BOUNDING-BOX
148 RELATIVE-COMPOSE BASELINE-OFFSET CODE-RANGE MAXLEN OFFSET-VECTOR) 144 RELATIVE-COMPOSE BASELINE-OFFSET CODE-RANGE MAXLEN OFFSET-VECTOR)
149See the documentation of the function `bdf-read-font-info' for more detail." 145See the documentation of the function `bdf-read-font-info' for more detail."
150 (let ((slot (assoc (car font-info) bdf-cache))) 146 (let ((slot (assoc (car font-info) bdf-cache)))
@@ -179,19 +175,16 @@ See the documentation of the function `bdf-read-font-info' for more detail."
179 175
180(defun bdf-read-font-info (bdfname) 176(defun bdf-read-font-info (bdfname)
181 "Read `BDF' font file BDFNAME and return information (FONT-INFO) of the file. 177 "Read `BDF' font file BDFNAME and return information (FONT-INFO) of the file.
178BDFNAME must be an absolute file name.
182FONT-INFO is a list of the following format: 179FONT-INFO is a list of the following format:
183 (BDFFILE ABSOLUTE-PATH MOD-TIME FONT-BOUNDING-BOX 180 (BDFFILE MOD-TIME FONT-BOUNDING-BOX
184 RELATIVE-COMPOSE BASELINE-OFFSET CODE-RANGE MAXLEN OFFSET-VECTOR) 181 RELATIVE-COMPOSE BASELINE-OFFSET CODE-RANGE MAXLEN OFFSET-VECTOR)
185 182
186BDFFILE is a name of a font file (excluding directory part).
187
188ABSOLUTE-PATH is an absolute path of the font file.
189
190MOD-TIME is last modification time as a list of two integers, the 183MOD-TIME is last modification time as a list of two integers, the
191first integer has high-order 16 bits, the second has low 16 bits. 184first integer has high-order 16 bits, the second has low 16 bits.
192 185
193SIZE is a size of the font. This value is got from SIZE record of the 186SIZE is a size of the font on 72 dpi device. This value is got
194font. 187from SIZE record of the font.
195 188
196FONT-BOUNDING-BOX is the font bounding box as a list of four integers, 189FONT-BOUNDING-BOX is the font bounding box as a list of four integers,
197BBX-WIDTH, BBX-HEIGHT, BBX-XOFF, and BBX-YOFF. 190BBX-WIDTH, BBX-HEIGHT, BBX-XOFF, and BBX-YOFF.
@@ -216,12 +209,12 @@ of the glyph in the font file.
216Nth element of OFFSET-VECTOR is a file position for the glyph of code 209Nth element of OFFSET-VECTOR is a file position for the glyph of code
217CODE, where N and CODE are in the following relation: 210CODE, where N and CODE are in the following relation:
218 (bdf-compact-code CODE) => N, (bdf-expand-code N) => CODE" 211 (bdf-compact-code CODE) => N, (bdf-expand-code N) => CODE"
219 (let* ((absolute-path (bdf-expand-file-name bdfname)) 212 (let* ((buf (bdf-find-file bdfname))
220 (buf (and absolute-path (bdf-find-file absolute-path)))
221 (maxlen 0) 213 (maxlen 0)
222 (relative-compose 'false) 214 (relative-compose 'false)
223 (baseline-offset 0) 215 (baseline-offset 0)
224 size 216 size
217 dpi
225 font-bounding-box 218 font-bounding-box
226 default-char 219 default-char
227 code-range 220 code-range
@@ -246,12 +239,19 @@ CODE, where N and CODE are in the following relation:
246 (- (aref font-bounding-box 3)))) 239 (- (aref font-bounding-box 3))))
247 240
248 (goto-char (point-min)) 241 (goto-char (point-min))
249 (search-forward "\nSIZE ") 242 (search-forward "\nFONT ")
250 (setq size (read (current-buffer))) 243 (if (looking-at "-[^-]*-[^-]*-[^-]*-[^-]*-[^-]*-[^-]*-\\([0-9]+\\)")
251 ;; The following kludgy code is t avoid bugs of several 244 (setq size (string-to-int (match-string 1)))
252 ;; fonts which have wrong SIZE record. 245 (search-forward "\nSIZE ")
253 (and (<= size (/ (aref font-bounding-box 1) 3)) 246 (setq size (read (current-buffer)))
254 (setq size (aref font-bounding-box 1))) 247 ;; The following kludgy code is t avoid bugs of several
248 ;; fonts which have wrong SIZE record.
249 (and (string-match "jiskan" bdfname)
250 (<= size (/ (aref font-bounding-box 1) 3))
251 (setq size (aref font-bounding-box 1)))
252 (setq dpi (read (current-buffer)))
253 (if (and (> dpi 0) (/= dpi 72))
254 (setq size (/ (* size dpi) 72))))
255 255
256 (setq default-char (bdf-search-and-read "\nDEFAULT_CHAR" nil)) 256 (setq default-char (bdf-search-and-read "\nDEFAULT_CHAR" nil))
257 257
@@ -301,55 +301,39 @@ CODE, where N and CODE are in the following relation:
301 301
302 (kill-buffer buf)) 302 (kill-buffer buf))
303 (message "Reading %s...done" bdfname) 303 (message "Reading %s...done" bdfname)
304 (list bdfname absolute-path (bdf-file-mod-time absolute-path) 304 (list bdfname (bdf-file-mod-time bdfname)
305 size font-bounding-box relative-compose baseline-offset 305 size font-bounding-box relative-compose baseline-offset
306 code-range maxlen offset-vector))) 306 code-range maxlen offset-vector)))
307 307
308(defsubst bdf-info-absolute-path (font-info) (nth 1 font-info)) 308(defsubst bdf-info-absolute-path (font-info) (nth 0 font-info))
309(defsubst bdf-info-mod-time (font-info) (nth 2 font-info)) 309(defsubst bdf-info-mod-time (font-info) (nth 1 font-info))
310(defsubst bdf-info-size (font-info) (nth 3 font-info)) 310(defsubst bdf-info-size (font-info) (nth 2 font-info))
311(defsubst bdf-info-font-bounding-box (font-info) (nth 4 font-info)) 311(defsubst bdf-info-font-bounding-box (font-info) (nth 3 font-info))
312(defsubst bdf-info-relative-compose (font-info) (nth 5 font-info)) 312(defsubst bdf-info-relative-compose (font-info) (nth 4 font-info))
313(defsubst bdf-info-baseline-offset (font-info) (nth 6 font-info)) 313(defsubst bdf-info-baseline-offset (font-info) (nth 5 font-info))
314(defsubst bdf-info-code-range (font-info) (nth 7 font-info)) 314(defsubst bdf-info-code-range (font-info) (nth 6 font-info))
315(defsubst bdf-info-maxlen (font-info) (nth 8 font-info)) 315(defsubst bdf-info-maxlen (font-info) (nth 7 font-info))
316(defsubst bdf-info-offset-vector (font-info) (nth 9 font-info)) 316(defsubst bdf-info-offset-vector (font-info) (nth 8 font-info))
317 317
318(defun bdf-get-font-info (bdfname) 318(defun bdf-get-font-info (bdfname)
319 "Return information about `BDF' font file BDFNAME. 319 "Return information about `BDF' font file BDFNAME.
320BDFNAME must be an absolute file name.
320The value FONT-INFO is a list of the following format: 321The value FONT-INFO is a list of the following format:
321 (BDFFILE ABSOLUTE-PATH MOD-TIME SIZE FONT-BOUNDING-BOX 322 (BDFNAME MOD-TIME SIZE FONT-BOUNDING-BOX
322 RELATIVE-COMPOSE BASELINE-OFFSET CODE-RANGE MAXLEN OFFSET-VECTOR) 323 RELATIVE-COMPOSE BASELINE-OFFSET CODE-RANGE MAXLEN OFFSET-VECTOR)
323See the documentation of the function `bdf-read-font-info' for more detail." 324See the documentation of the function `bdf-read-font-info' for more detail."
324 (or bdf-cache 325 (or bdf-cache
325 (bdf-read-cache)) 326 (bdf-read-cache))
326 (let ((font-info (assoc bdfname bdf-cache))) 327 (let ((font-info (assoc bdfname bdf-cache)))
327 (if (or (not font-info) 328 (if (or (not font-info)
328 (not (file-readable-p (bdf-info-absolute-path font-info))) 329 (not (file-readable-p bdfname))
329 (bdf-file-newer-than-time bdfname (bdf-info-mod-time font-info))) 330 (bdf-file-newer-than-time bdfname (bdf-info-mod-time font-info)))
330 (progn 331 (progn
331 (setq font-info (bdf-read-font-info bdfname)) 332 (setq font-info (bdf-read-font-info bdfname))
332 (bdf-set-cache font-info))) 333 (bdf-set-cache font-info)))
333 font-info)) 334 font-info))
334 335
335(defun bdf-find-font-info (bdfnames) 336(defun bdf-read-bitmap (bdfname offset maxlen relative-compose)
336 "Return information about `BDF' font file with alternative names BDFNAMES.
337
338If BDFNAMES is a list of file names, this function finds the first file
339in the list which exists and is readable, then calls `bdf-get-font-info'
340on that file name."
341 (let ((fnlist bdfnames)
342 (fname bdfnames))
343 (if (consp fnlist)
344 (while (and fnlist
345 (progn
346 (setq fname (car fnlist))
347 (null (bdf-expand-file-name fname))))
348 (setq fname nil
349 fnlist (cdr fnlist))))
350 (bdf-get-font-info (or fname (car bdfnames)))))
351
352(defun bdf-read-bitmap (bdfname offset maxlen)
353 "Read `BDF' font file BDFNAME to get bitmap data at file position OFFSET. 337 "Read `BDF' font file BDFNAME to get bitmap data at file position OFFSET.
354BDFNAME is an absolute path name of the font file. 338BDFNAME is an absolute path name of the font file.
355MAXLEN specifies how many bytes we should read at least. 339MAXLEN specifies how many bytes we should read at least.
@@ -358,7 +342,7 @@ DWIDTH is a pixel width of a glyph.
358BBX is a bounding box of the glyph. 342BBX is a bounding box of the glyph.
359BITMAP-STRING is a string representing bits by hexadecimal digits." 343BITMAP-STRING is a string representing bits by hexadecimal digits."
360 (let* ((coding-system-for-read 'no-conversion) 344 (let* ((coding-system-for-read 'no-conversion)
361 (bbx (elt (bdf-get-font-info bdfname) 4)) 345 (bbx (bdf-info-font-bounding-box (bdf-get-font-info bdfname)))
362 (dwidth (elt bbx 0)) 346 (dwidth (elt bbx 0))
363 (bitmap-string "") 347 (bitmap-string "")
364 height yoff) 348 height yoff)
@@ -368,6 +352,8 @@ BITMAP-STRING is a string representing bits by hexadecimal digits."
368 (goto-char (point-min)) 352 (goto-char (point-min))
369 (search-forward "\nDWIDTH") 353 (search-forward "\nDWIDTH")
370 (setq dwidth (read (current-buffer))) 354 (setq dwidth (read (current-buffer)))
355 (if (= dwidth 0)
356 (setq dwidth 0.1))
371 (goto-char (point-min)) 357 (goto-char (point-min))
372 (search-forward "\nBBX") 358 (search-forward "\nBBX")
373 (setq bbx (vector (read (current-buffer)) (read (current-buffer)) 359 (setq bbx (vector (read (current-buffer)) (read (current-buffer))
@@ -399,29 +385,26 @@ BITMAP-STRING is a string representing bits by hexadecimal digits."
399 (delete-char 1)) 385 (delete-char 1))
400 (setq bitmap-string (buffer-string))) 386 (setq bitmap-string (buffer-string)))
401 (error nil)) 387 (error nil))
402 (list dwidth bbx bitmap-string))) 388 (vector dwidth (aref bbx 0) (aref bbx 1) (aref bbx 2) (aref bbx 3)
403 389 (concat "<" bitmap-string ">")
404(defun bdf-get-bitmaps (bdfname codes) 390 (or relative-compose 'false))))
405 "Return bitmap information of glyphs of CODES in `BDF' font file BDFNAME. 391
406CODES is a list of encoding number of glyphs in the file. 392(defun bdf-get-bitmap (bdfname code)
407The value is a list of CODE, DWIDTH, BBX, and BITMAP-STRING. 393 "Return bitmap information of glyph of CODE in `BDF' font file BDFNAME.
394CODE is an encoding number of glyph in the file.
395The value is a list (DWIDTH BBX BITMAP-STRING).
408DWIDTH is a pixel width of a glyph. 396DWIDTH is a pixel width of a glyph.
409BBX is a bounding box of the glyph. 397BBX is a bounding box of the glyph.
410BITMAP-STRING is a string representing bits by hexadecimal digits." 398BITMAP-STRING is a string representing bits by hexadecimal digits."
411 (let* ((font-info (bdf-find-font-info bdfname)) 399 (let* ((info (bdf-get-font-info bdfname))
412 (absolute-path (bdf-info-absolute-path font-info)) 400 (maxlen (bdf-info-maxlen info))
413 ;;(font-bounding-box (bdf-info-font-bounding-box font-info)) 401 (code-range (bdf-info-code-range info))
414 (maxlen (bdf-info-maxlen font-info)) 402 (offset-vector (bdf-info-offset-vector info)))
415 (code-range (bdf-info-code-range font-info)) 403 (bdf-read-bitmap bdfname
416 (offset-vector (bdf-info-offset-vector font-info))) 404 (aref offset-vector (bdf-compact-code code code-range))
417 (mapcar '(lambda (x) 405 maxlen (bdf-info-relative-compose info))))
418 (cons x (bdf-read-bitmap 406
419 absolute-path 407;;; Interface to ps-mule.el
420 (aref offset-vector (bdf-compact-code x code-range))
421 maxlen)))
422 codes)))
423
424;;; Interface to ps-print.el
425 408
426;; Called from ps-mule-init-external-library. 409;; Called from ps-mule-init-external-library.
427(defun bdf-generate-prologue () 410(defun bdf-generate-prologue ()
@@ -429,27 +412,36 @@ BITMAP-STRING is a string representing bits by hexadecimal digits."
429 (bdf-initialize)) 412 (bdf-initialize))
430 (ps-mule-generate-bitmap-prologue)) 413 (ps-mule-generate-bitmap-prologue))
431 414
415;; Called from ps-mule-check-font.
416(defun bdf-check-font (font-spec)
417 (let ((font-name-list (ps-mule-font-spec-name font-spec)))
418 (ps-mule-font-spec-set-name
419 font-spec
420 (if (stringp font-name-list)
421 (bdf-expand-file-name font-name-list)
422 (catch 'tag
423 (dolist (font-name font-name-list)
424 (setq font-name (bdf-expand-file-name font-name))
425 (if font-name
426 (throw 'tag font-name))))))))
427
432;; Called from ps-mule-generate-font. 428;; Called from ps-mule-generate-font.
433(defun bdf-generate-font (charset font-spec) 429(defun bdf-generate-font (font-spec)
434 (let* ((font-name (ps-mule-font-spec-name font-spec)) 430 (let ((info (bdf-get-font-info (ps-mule-font-spec-name font-spec))))
435 (font-info (bdf-find-font-info font-name)) 431 (ps-mule-font-spec-set-extra
436 (font-name (if (consp font-name) (car font-name) font-name))) 432 font-spec (bdf-info-absolute-path info))
437 (ps-mule-generate-bitmap-font font-name 433 (ps-mule-generate-bitmap-font font-spec
438 (ps-mule-font-spec-bytes font-spec) 434 (bdf-info-size info)
439 (charset-width charset) 435 (bdf-info-relative-compose info)
440 (bdf-info-size font-info) 436 (bdf-info-baseline-offset info)
441 (bdf-info-relative-compose font-info) 437 (bdf-info-font-bounding-box info))))
442 (bdf-info-baseline-offset font-info) 438
443 (bdf-info-font-bounding-box font-info)))) 439;; Called from ps-mule-generate-glyph.
444 440(defun bdf-generate-glyph (font-spec char)
445;; Called from ps-mule-generate-glyphs. 441 (let ((font-name (ps-mule-font-spec-extra font-spec))
446(defun bdf-generate-glyphs (font-spec code-list bytes) 442 (code (ps-mule-encode-char char font-spec)))
447 (let ((font-name (ps-mule-font-spec-name font-spec))) 443 (ps-mule-generate-bitmap-glyph font-spec char code
448 (mapcar '(lambda (x) 444 (bdf-get-bitmap font-name code))))
449 (apply 'ps-mule-generate-bitmap-glyph
450 (if (consp font-name) (car font-name) font-name)
451 x))
452 (bdf-get-bitmaps font-name code-list))))
453 445
454(provide 'ps-bdf) 446(provide 'ps-bdf)
455 447
diff --git a/lisp/ps-mule.el b/lisp/ps-mule.el
index a20853959be..9639abbed01 100644
--- a/lisp/ps-mule.el
+++ b/lisp/ps-mule.el
@@ -107,15 +107,6 @@
107 (or (fboundp 'find-charset-region) 107 (or (fboundp 'find-charset-region)
108 (defun find-charset-region (beg end &optional table) 108 (defun find-charset-region (beg end &optional table)
109 (list 'ascii))) 109 (list 'ascii)))
110 (or (fboundp 'char-valid-p)
111 (defun char-valid-p (char)
112 (< (following-char) 256)))
113 (or (fboundp 'split-char)
114 (defun split-char (char)
115 (list (if (char-valid-p char)
116 'ascii
117 'unknow)
118 char)))
119 (or (fboundp 'char-width) 110 (or (fboundp 'char-width)
120 (defun char-width (char) 1)) ; ascii 111 (defun char-width (char) 1)) ; ascii
121 (or (fboundp 'chars-in-region) 112 (or (fboundp 'chars-in-region)
@@ -235,29 +226,45 @@ Any other value is treated as nil."
235 (defun ps-mule-next-index (string i) 226 (defun ps-mule-next-index (string i)
236 (+ i (charset-bytes (char-charset (string-to-char string))))) 227 (+ i (charset-bytes (char-charset (string-to-char string)))))
237 ) 228 )
238 ;; For Emacs 20.4 and the earlier version. 229 (if (boundp 'mule-version)
239 (if (and (boundp 'mule-version) 230 ;; For Emacs 20.4 and the earlier version.
240 (string< (symbol-value 'mule-version) "5.0")) 231 (if (string< (symbol-value 'mule-version) "5.0")
241 ;; mule package is loaded and mule version is lesser than 5.0 232 ;; mule package is loaded and mule version is lesser than 5.0
242 (progn 233 (progn
243 (defun encode-composition-rule (rule) 234 (defun encode-composition-rule (rule)
244 (if (= (car rule) 4) (setcar rule 10)) 235 (if (= (car rule) 4) (setcar rule 10))
245 (if (= (cdr rule) 4) (setcdr rule 10)) 236 (if (= (cdr rule) 4) (setcdr rule 10))
246 (+ (* (car rule) 12) (cdr rule))) 237 (+ (* (car rule) 12) (cdr rule)))
247 (defun find-composition (pos &rest ignore) 238 (defun ps-mule-search-composition (from to)
248 (let ((ch (char-after pos))) 239 (save-excursion
249 (and ch (eq (char-charset ch) 'composition) 240 (goto-char from)
250 (let ((components (decompose-composite-char ch 'vector t))) 241 (search-forward "\200" to t)))
251 (list pos (ps-mule-next-point pos) components 242 (defun ps-mule-get-composition (pos)
252 (integerp (aref components 1)) nil 243 (let ((ch (char-after pos)))
253 (char-width ch))))))) 244 (and ch (eq (char-charset ch) 'composition)
245 (let ((components
246 (decompose-composite-char ch 'vector t)))
247 (list pos (ps-mule-next-point pos) components
248 (integerp (aref components 1)) nil
249 (char-width ch)))))))
250 (defun ps-mule-search-composition (from to)
251 (let (cmp-info)
252 (while (and (< from to)
253 (setq cmp-info (find-composition from to))
254 (not (nth 2 cmp-info)))
255 (setq from (nth 1 cmp-info)))
256 (< from to)))
257 (defun ps-mule-get-composition (pos)
258 (find-composition pos nil nil t)))
259
254 ;; mule package isn't loaded 260 ;; mule package isn't loaded
255 (or (fboundp 'encode-composition-rule) 261 (or (fboundp 'encode-composition-rule)
256 (defun encode-composition-rule (rule) 262 (defun encode-composition-rule (rule)
257 130)) 263 130))
258 (or (fboundp 'find-composition) 264 (defun ps-mule-search-composition (&rest ignore)
259 (defun find-composition (pos &rest ignore) 265 nil)
260 nil)) 266 (defun ps-mule-get-composition (&rest ignore)
267 nil)
261 )) 268 ))
262 269
263(defvar ps-mule-font-info-database 270(defvar ps-mule-font-info-database
@@ -265,7 +272,7 @@ Any other value is treated as nil."
265 "Alist of charsets with the corresponding font information. 272 "Alist of charsets with the corresponding font information.
266Each element has the form: 273Each element has the form:
267 274
268 (CHARSET (FONT-TYPE FONT-SRC FONT-NAME ENCODING BYTES) ...) 275 (CHARSET (FONT-TYPE FONT-SRC FONT-NAME ENCODING BYTES)) ...)
269 276
270Where 277Where
271 278
@@ -285,15 +292,20 @@ FONT-SRC is a font source: builtin, ps-bdf, vflib, or nil.
285 To use this font, the external library `vflib' is required. 292 To use this font, the external library `vflib' is required.
286 293
287 If FONT-SRC is nil, a proper ASCII font in the variable 294 If FONT-SRC is nil, a proper ASCII font in the variable
288 `ps-font-info-database' is used. This is useful for Latin-1 characters. 295 `ps-font-info-database' is used, and FONT-NAME is ignored.
296 This is useful for Latin-1 characters.
289 297
290ENCODING is a coding system to encode a string of characters of CHARSET into a 298ENCODING is a charset to encode a character of CHARSET to a glyph
291proper string matching an encoding of the specified font. ENCODING may be a 299code of the specifies font. ENCODING may be a function that does
292function that does this encoding. In this case, the function is called with 300this encoding. In this case, the function is called with one
293one argument, the string to encode, and it should return an encoded string. 301argument, the character to encode, and it should return an
302encoded code. ENCODING may be nil, in which case CHARSET is used
303to encode a character.
294 304
295BYTES specifies how many bytes each character has in the encoded byte 305BYTES specifies how many bytes each character has in the encoded
296sequence; it should be 1 or 2. 306byte sequence; it should be 1 or 2. If ENCODING is a charset,
307BYTES may be nil, in chich case the dimension of ENCODING is
308used.
297 309
298All multi-byte characters are printed by fonts specified in this database 310All multi-byte characters are printed by fonts specified in this database
299regardless of a font family of ASCII characters. The exception is Latin-1 311regardless of a font family of ASCII characters. The exception is Latin-1
@@ -303,8 +315,8 @@ font family.
303See also the variable `ps-font-info-database'.") 315See also the variable `ps-font-info-database'.")
304 316
305(defconst ps-mule-font-info-database-latin 317(defconst ps-mule-font-info-database-latin
306 '((latin-iso8859-1 318 '((iso-8859-1
307 (normal nil nil iso-latin-1))) 319 (normal nil nil)))
308 "Sample setting of `ps-mule-font-info-database' to use latin fonts.") 320 "Sample setting of `ps-mule-font-info-database' to use latin fonts.")
309 321
310(defcustom ps-mule-font-info-database-default 322(defcustom ps-mule-font-info-database-default
@@ -315,119 +327,104 @@ See also the variable `ps-font-info-database'.")
315 327
316(defconst ps-mule-font-info-database-ps 328(defconst ps-mule-font-info-database-ps
317 '((katakana-jisx0201 329 '((katakana-jisx0201
318 (normal builtin "Ryumin-Light.Katakana" ps-mule-encode-7bit 1) 330 (normal builtin "Ryumin-Light.Katakana")
319 (bold builtin "GothicBBB-Medium.Katakana" ps-mule-encode-7bit 1) 331 (bold builtin "GothicBBB-Medium.Katakana")
320 (bold-italic builtin "GothicBBB-Medium.Katakana" ps-mule-encode-7bit 1)) 332 (bold-italic builtin "GothicBBB-Medium.Katakana"))
321 (latin-jisx0201 333 (latin-jisx0201
322 (normal builtin "Ryumin-Light.Hankaku" ps-mule-encode-7bit 1) 334 (normal builtin "Ryumin-Light.Hankaku")
323 (bold builtin "GothicBBB-Medium.Hankaku" ps-mule-encode-7bit 1)) 335 (bold builtin "GothicBBB-Medium.Hankaku"))
324 (japanese-jisx0208 336 (japanese-jisx0208
325 (normal builtin "Ryumin-Light-H" ps-mule-encode-7bit 2) 337 (normal builtin "Ryumin-Light-H")
326 (bold builtin "GothicBBB-Medium-H" ps-mule-encode-7bit 2)) 338 (bold builtin "GothicBBB-Medium-H"))
327 (korean-ksc5601 339 (korean-ksc5601
328 (normal builtin "Munhwa-Regular-KSC-EUC-H" ps-mule-encode-7bit 2) 340 (normal builtin "Munhwa-Regular-KSC-EUC-H")
329 (bold builtin "Munhwa-Bold-KSC-EUC-H" ps-mule-encode-7bit 2)) 341 (bold builtin "Munhwa-Bold-KSC-EUC-H"))
330 ) 342 )
331 "Sample setting of the `ps-mule-font-info-database' to use builtin PS font. 343 "Sample setting of the `ps-mule-font-info-database' to use builtin PS font.
332 344
333Currently, data for Japanese and Korean PostScript printers are listed.") 345Currently, data for Japanese and Korean PostScript printers are listed.")
334 346
335(defconst ps-mule-font-info-database-bdf 347(defconst ps-mule-font-info-database-bdf
336 '((ascii 348 '((iso-8859-1
337 (normal bdf ("lt1-24-etl.bdf" "etl24-latin1.bdf") nil 1) 349 (normal bdf ("lt1-24-etl.bdf" "etl24-latin1.bdf"))
338 (bold bdf ("lt1-16b-etl.bdf" "etl16b-latin1.bdf") nil 1) 350 (bold bdf ("lt1-16b-etl.bdf" "etl16b-latin1.bdf"))
339 (italic bdf ("lt1-16i-etl.bdf" "etl16i-latin1.bdf") nil 1) 351 (italic bdf ("lt1-16i-etl.bdf" "etl16i-latin1.bdf"))
340 (bold-italic bdf ("lt1-16bi-etl.bdf" "etl16bi-latin1.bdf") nil 1)) 352 (bold-italic bdf ("lt1-16bi-etl.bdf" "etl16bi-latin1.bdf")))
341 (latin-iso8859-1 353 (iso-8859-2
342 (normal bdf ("lt1-24-etl.bdf" "etl24-latin1.bdf") iso-latin-1 1) 354 (normal bdf ("lt2-24-etl.bdf" "etl24-latin2.bdf")))
343 (bold bdf ("lt1-16b-etl.bdf" "etl16b-latin1.bdf") iso-latin-1 1) 355 (iso-8859-3
344 (italic bdf ("lt1-16i-etl.bdf" "etl16i-latin1.bdf") iso-latin-1 1) 356 (normal bdf ("lt3-24-etl.bdf" "etl24-latin3.bdf")))
345 (bold-italic bdf ("lt1-16bi-etl.bdf" "etl16bi-latin1.bdf") iso-latin-1 1)) 357 (iso-8859-4
346 (latin-iso8859-2 358 (normal bdf ("lt4-24-etl.bdf" "etl24-latin4.bdf")))
347 (normal bdf ("lt2-24-etl.bdf" "etl24-latin2.bdf") iso-latin-2 1))
348 (latin-iso8859-3
349 (normal bdf ("lt3-24-etl.bdf" "etl24-latin3.bdf") iso-latin-3 1))
350 (latin-iso8859-4
351 (normal bdf ("lt4-24-etl.bdf" "etl24-latin4.bdf") iso-latin-4 1))
352 (thai-tis620 359 (thai-tis620
353 (normal bdf ("thai24.bdf" "thai-24.bdf") thai-tis620 1)) 360 (normal bdf ("thai24.bdf" "thai-24.bdf") iso-8859-11))
354 (greek-iso8859-7 361 (greek-iso8859-7
355 (normal bdf ("grk24-etl.bdf" "etl24-greek.bdf") greek-iso-8bit 1)) 362 (normal bdf ("grk24-etl.bdf" "etl24-greek.bdf") iso-8859-7))
356 ;; (arabic-iso8859-6 nil) ; not yet available
357 (hebrew-iso8859-8 363 (hebrew-iso8859-8
358 (normal bdf ("heb24-etl.bdf" "etl24-hebrew.bdf") hebrew-iso-8bit 1)) 364 (normal bdf ("heb24-etl.bdf" "etl24-hebrew.bdf") iso-8859-8))
359 (katakana-jisx0201 365 (jisx0201
360 (normal bdf "12x24rk.bdf" ps-mule-encode-8bit 1)) 366 (normal bdf "12x24rk.bdf" jisx0201))
361 (latin-jisx0201
362 (normal bdf "12x24rk.bdf" ps-mule-encode-7bit 1))
363 (cyrillic-iso8859-5 367 (cyrillic-iso8859-5
364 (normal bdf ("cyr24-etl.bdf" "etl24-cyrillic.bdf") cyrillic-iso-8bit 1)) 368 (normal bdf ("cyr24-etl.bdf" "etl24-cyrillic.bdf") iso-8859-5))
365 (latin-iso8859-9 369 (iso-8859-9
366 (normal bdf ("lt5-24-etl.bdf" "etl24-latin5.bdf") iso-latin-5 1)) 370 (normal bdf ("lt5-24-etl.bdf" "etl24-latin5.bdf") iso-8859-9))
367 (japanese-jisx0208-1978
368 (normal bdf "jiskan24.bdf" ps-mule-encode-7bit 2))
369 (chinese-gb2312 371 (chinese-gb2312
370 (normal bdf "gb24st.bdf" ps-mule-encode-7bit 2)) 372 (normal bdf "gb24st.bdf"))
371 (japanese-jisx0208 373 (japanese-jisx0208
372 (normal bdf "jiskan24.bdf" ps-mule-encode-7bit 2)) 374 (normal bdf "jiskan24.bdf"))
373 (korean-ksc5601 375 (korean-ksc5601
374 (normal bdf "hanglm24.bdf" ps-mule-encode-7bit 2)) 376 (normal bdf "hanglm24.bdf"))
375 (japanese-jisx0212 377 (japanese-jisx0212
376 (normal bdf ("jksp40.bdf" "jisksp40.bdf") ps-mule-encode-7bit 2)) 378 (normal bdf ("jksp40.bdf" "jisksp40.bdf")))
377 (chinese-cns11643-1 379 (chinese-cns11643-1
378 (normal bdf ("cns1-40.bdf" "cns-1-40.bdf") ps-mule-encode-7bit 2)) 380 (normal bdf ("cns1-40.bdf" "cns-1-40.bdf")))
379 (chinese-cns11643-2 381 (chinese-cns11643-2
380 (normal bdf ("cns2-40.bdf" "cns-2-40.bdf") ps-mule-encode-7bit 2)) 382 (normal bdf ("cns2-40.bdf" "cns-2-40.bdf")))
381 (chinese-big5-1 383 (big5
382 (normal bdf "taipei24.bdf" chinese-big5 2)) 384 (normal bdf "taipei24.bdf"))
383 (chinese-big5-2
384 (normal bdf "taipei24.bdf" chinese-big5 2))
385 (chinese-sisheng 385 (chinese-sisheng
386 (normal bdf ("sish24-etl.bdf" "etl24-sisheng.bdf") ps-mule-encode-7bit 1)) 386 (normal bdf ("sish24-etl.bdf" "etl24-sisheng.bdf")))
387 (ipa 387 (ipa
388 (normal bdf ("ipa24-etl.bdf" "etl24-ipa.bdf") ps-mule-encode-8bit 1)) 388 (normal bdf ("ipa24-etl.bdf" "etl24-ipa.bdf") ipa))
389 (vietnamese-viscii-lower 389 (viscii
390 (normal bdf ("visc24-etl.bdf" "etl24-viscii.bdf") vietnamese-viscii 1)) 390 (normal bdf ("visc24-etl.bdf" "etl24-viscii.bdf")))
391 (vietnamese-viscii-upper
392 (normal bdf ("visc24-etl.bdf" "etl24-viscii.bdf") vietnamese-viscii 1))
393 (arabic-digit 391 (arabic-digit
394 (normal bdf ("arab24-0-etl.bdf" "etl24-arabic0.bdf") ps-mule-encode-7bit 1)) 392 (normal bdf ("arab24-0-etl.bdf" "etl24-arabic0.bdf")))
395 (arabic-1-column 393 (arabic-1-column
396 (normal bdf ("arab24-1-etl.bdf" "etl24-arabic1.bdf") ps-mule-encode-7bit 1)) 394 (normal bdf ("arab24-1-etl.bdf" "etl24-arabic1.bdf")))
397 ;; (ascii-right-to-left nil) ; not yet available
398 (lao 395 (lao
399 (normal bdf ("lao24-mule.bdf" "mule-lao-24.bdf") lao 1)) 396 (normal bdf ("lao24-mule.bdf" "mule-lao-24.bdf") ps-mule-encode-lao 1))
400 (arabic-2-column 397 (arabic-2-column
401 (normal bdf ("arab24-2-etl.bdf" "etl24-arabic2.bdf") ps-mule-encode-7bit 1)) 398 (normal bdf ("arab24-2-etl.bdf" "etl24-arabic2.bdf")))
399 (devanagari-cdac
400 (normal bdf "dvsr0ntt-32.bdf"))
401 (malayalam-cdac
402 (normal bdf "mlkr0ntt-32.bdf"))
403 (tamil-cdac
404 (normal bdf "tmvl0ntt-32.bdf"))
402 (indian-is13194 405 (indian-is13194
403 (normal bdf ("isci24-mule.bdf" "mule-iscii-24.bdf") ps-mule-encode-7bit 1)) 406 (normal bdf ("isci24-mule.bdf" "mule-iscii-24.bdf")))
404 (indian-1-column 407 (indian-1-column
405 (normal bdf ("ind1c24-mule.bdf" "mule-indian-1col-24.bdf") ps-mule-encode-7bit 2)) 408 (normal bdf ("ind1c24-mule.bdf" "mule-indian-1col-24.bdf")))
406 (tibetan-1-column
407 (normal bdf ("tib1c24-mule.bdf" "mule-tibmdx-1col-24.bdf") ps-mule-encode-7bit 2))
408 (ethiopic 409 (ethiopic
409 (normal bdf ("ethio24f-uni.bdf" "ethiomx24f-uni.bdf") ps-mule-encode-ethiopic 2)) 410 (normal bdf ("ethio24f-uni.bdf" "ethiomx24f-uni.bdf") unicode-bmp))
410 (chinese-cns11643-3 411 (chinese-cns11643-3
411 (normal bdf ("cns3-40.bdf" "cns-3-40.bdf") ps-mule-encode-7bit 2)) 412 (normal bdf ("cns3-40.bdf" "cns-3-40.bdf")))
412 (chinese-cns11643-4 413 (chinese-cns11643-4
413 (normal bdf ("cns4-40.bdf" "cns-4-40.bdf") ps-mule-encode-7bit 2)) 414 (normal bdf ("cns4-40.bdf" "cns-4-40.bdf")))
414 (chinese-cns11643-5 415 (chinese-cns11643-5
415 (normal bdf ("cns5-40.bdf" "cns-5-40.bdf") ps-mule-encode-7bit 2)) 416 (normal bdf ("cns5-40.bdf" "cns-5-40.bdf")))
416 (chinese-cns11643-6 417 (chinese-cns11643-6
417 (normal bdf ("cns6-40.bdf" "cns-6-40.bdf") ps-mule-encode-7bit 2)) 418 (normal bdf ("cns6-40.bdf" "cns-6-40.bdf")))
418 (chinese-cns11643-7 419 (chinese-cns11643-7
419 (normal bdf ("cns7-40.bdf" "cns-7-40.bdf") ps-mule-encode-7bit 2)) 420 (normal bdf ("cns7-40.bdf" "cns-7-40.bdf")))
420 (indian-2-column 421 (indian-2-column
421 (normal bdf ("ind24-mule.bdf" "mule-indian-24.bdf") ps-mule-encode-7bit 2)) 422 (normal bdf ("ind24-mule.bdf" "mule-indian-24.bdf")))
422 (tibetan 423 (tibetan
423 (normal bdf ("tib24p-mule.bdf" "tib24-mule.bdf" "mule-tibmdx-24.bdf") 424 (normal bdf ("tib24p-mule.bdf" "tib24-mule.bdf" "mule-tibmdx-24.bdf")))
424 ps-mule-encode-7bit 2)) 425 (unicode-bmp
425 (mule-unicode-0100-24ff 426 (normal bdf "etl24-unicode.bdf"))
426 (normal bdf "etl24-unicode.bdf" ps-mule-encode-ucs2 2)) 427 )
427 (mule-unicode-2500-33ff
428 (normal bdf "etl24-unicode.bdf" ps-mule-encode-ucs2 2))
429 (mule-unicode-e000-ffff
430 (normal bdf "etl24-unicode.bdf" ps-mule-encode-ucs2 2)))
431 "Sample setting of the `ps-mule-font-info-database' to use BDF fonts. 428 "Sample setting of the `ps-mule-font-info-database' to use BDF fonts.
432BDF (Bitmap Distribution Format) is a format used for distributing X's font 429BDF (Bitmap Distribution Format) is a format used for distributing X's font
433source file. 430source file.
@@ -455,124 +452,111 @@ by `ps-font-family' and `ps-header-font-family'.
455 452
456See also `ps-mule-font-info-database-bdf'.") 453See also `ps-mule-font-info-database-bdf'.")
457 454
458;; Two typical encoding functions for PostScript fonts. 455(defvar ps-mule-font-spec-list nil
459 456 "Array of FONT-SPEC lists for each font type.
460(defun ps-mule-encode-7bit (string)
461 (ps-mule-encode-bit string 0))
462
463(defun ps-mule-encode-8bit (string)
464 (ps-mule-encode-bit string 128))
465
466(defun ps-mule-encode-bit (string delta)
467 (let* ((dim (charset-dimension (char-charset (string-to-char string))))
468 (len (* (ps-mule-chars-in-string string) dim))
469 (str (make-string len 0))
470 (i 0)
471 (j 0))
472 (if (= dim 1)
473 (while (< j len)
474 (aset str j
475 (+ (nth 1 (split-char (ps-mule-string-char string i))) delta))
476 (setq i (ps-mule-next-index string i)
477 j (1+ j)))
478 (while (< j len)
479 (let ((split (split-char (ps-mule-string-char string i))))
480 (aset str j (+ (nth 1 split) delta))
481 (aset str (1+ j) (+ (nth 2 split) delta))
482 (setq i (ps-mule-next-index string i)
483 j (+ j 2)))))
484 str))
485
486;; Special encoding function for Ethiopic.
487(if (boundp 'mule-version) ; only if mule package is loaded
488 (define-ccl-program ccl-encode-ethio-unicode
489 `(1
490 ((read r2)
491 (loop
492 (if (r2 == ,leading-code-private-22)
493 ((read r0)
494 (if (r0 == ,(charset-id 'ethiopic))
495 ((read r1 r2)
496 (r1 &= 127) (r2 &= 127)
497 (call ccl-encode-ethio-font)
498 (write r1)
499 (write-read-repeat r2))
500 ((write r2 r0)
501 (repeat))))
502 (write-read-repeat r2))))))
503 ;; to avoid compilation gripes
504 (defvar ccl-encode-ethio-unicode nil))
505
506(if (boundp 'mule-version)
507 ;; bound mule-version
508 (defun ps-mule-encode-ethiopic (string)
509 (ccl-execute-on-string (symbol-value 'ccl-encode-ethio-unicode)
510 (make-vector 9 nil)
511 string))
512 ;; unbound mule-version
513 (defun ps-mule-encode-ethiopic (string)
514 string))
515
516;; Special encoding for mule-unicode-* characters.
517(defun ps-mule-encode-ucs2 (string)
518 (let* ((len (ps-mule-chars-in-string string))
519 (str (make-string (* 2 len) 0))
520 (i 0)
521 (j 0)
522 ch hi lo)
523 (while (< i len)
524 (setq ch (encode-char (ps-mule-string-char string i) 'ucs)
525 hi (lsh ch -8)
526 lo (logand ch 255))
527 (aset str j hi)
528 (aset str (1+ j) lo)
529 (setq i (1+ i)
530 j (+ j 2)))
531 str))
532
533;; A charset which we are now processing.
534(defvar ps-mule-current-charset nil)
535
536(defun ps-mule-get-font-spec (charset font-type)
537 "Return FONT-SPEC for printing characters CHARSET with FONT-TYPE.
538FONT-SPEC is a list that has the form:
539
540 (FONT-SRC FONT-NAME ENCODING BYTES)
541
542FONT-SPEC is extracted from `ps-mule-font-info-database'.
543
544See the documentation of `ps-mule-font-info-database' for the meaning of each
545element of the list."
546 (let ((slot (cdr (assq charset ps-mule-font-info-database))))
547 (and slot
548 (cdr (or (assq font-type slot)
549 (and (eq font-type 'bold-italic)
550 (or (assq 'bold slot) (assq 'italic slot)))
551 (assq 'normal slot))))))
552 457
553;; Functions to access each element of FONT-SPEC. 458Elements are for `normal' font, `bold' font, `italic' font, and
554(defsubst ps-mule-font-spec-src (font-spec) (car font-spec)) 459`bold-italic' font in this order.
555(defsubst ps-mule-font-spec-name (font-spec) (nth 1 font-spec)) 460
556(defsubst ps-mule-font-spec-encoding (font-spec) (nth 2 font-spec)) 461Each element is a list of FONT-SPEC which has this form:
557(defsubst ps-mule-font-spec-bytes (font-spec) (nth 3 font-spec))
558 462
559(defsubst ps-mule-printable-p (charset) 463 (ID CHARSET (FONT-SRC FONT-NAME ENCODING) EXTRA-DATA)
560 "Non-nil if characters in CHARSET is printable." 464
561 (ps-mule-get-font-spec charset 'normal)) 465Where
466
467ID is a number for this FONT-SPEC and is unique in the list.
468
469CHARSET, FONT-SRC, FONT-NAME, ENCODING are the same as those in
470`ps-mule-font-info-database' (which see).
471
472EXTRA-DATA is a data attached by external libraries.
473
474Each list is ordered by the current charset priorities.
475
476This variable is setup by `ps-mule-begin-job' from
477`ps-mule-font-info-database'.")
478
479;; Functions to access each element of FONT-SPEC.
480(defsubst ps-mule-font-spec-id (font-spec) (aref font-spec 0))
481(defsubst ps-mule-font-spec-charset (font-spec) (aref font-spec 1))
482(defsubst ps-mule-font-spec-font-id (font-spec) (aref font-spec 2))
483(defsubst ps-mule-font-spec-src (font-spec) (aref font-spec 3))
484(defsubst ps-mule-font-spec-name (font-spec) (aref font-spec 4))
485(defsubst ps-mule-font-spec-set-name (font-spec name)
486 (aset font-spec 4 name))
487(defsubst ps-mule-font-spec-encoding (font-spec) (aref font-spec 5))
488(defsubst ps-mule-font-spec-bytes (font-spec) (aref font-spec 6))
489(defsubst ps-mule-font-spec-extra (font-spec) (aref font-spec 7))
490(defsubst ps-mule-font-spec-set-extra (font-spec extra)
491 (aset font-spec 7 extra))
492
493;; Functions to encode character into glyph code.
494(defun ps-mule-encode-lao (char)
495 (- char #x0DE0))
496
497(defun ps-mule-encode-char (char font-spec)
498 (let ((encoding (ps-mule-font-spec-encoding font-spec)))
499 (cond ((charsetp encoding)
500 (encode-char char encoding))
501 ((fboundp encoding)
502 (funcall encoding char))
503 (t
504 char))))
505
506;; Array of FONT-SPEC-TABLEs; Nth element is for FONT-TYPE N.
507;;
508;; FONT-TYPE is 0, 1, 2, or 3 representing normal, bold, italic, and
509;; bold-italic respectively.
510;;
511;; FONT-SPEC-TABLE is a char-table of FONT-SPECs. It records which
512;; character is printed by which FONT-SPEC. It has one extra slot
513;; whose value is an alist of the form:
514;; (CHARSET . FONT-SPEC)
515;; FONT-SPEC is a vecotr of the form:
516;; (ID FONT-SRC FONT-NAME ENCODING EXTRA)
517(defvar ps-mule-font-spec-tables nil)
518
519;; Array of FONT-TYPEs; Nth element FONT-NUMBER N.
520;;
521;; FONT-NUMBER is 0, 1, 2, 3, 4, 5, 6 representing fonts f0, f1, f2,
522;; f3, h0, h1, and H0.
523(defconst ps-mule-font-number-to-type [ 0 1 2 3 1 0 0 ])
524
525(defsubst ps-mule-get-font-spec (char font-spec-table font-spec)
526 "Return a font spec for printing CHAR with FONT-SPEC-TABLE.
527
528FONT-SPEC, if non-nil, is a font spec to try at first.
529
530See the documentation of `ps-mule-font-spec-tables' for the
531format of font spec."
532
533 (or (aref font-spec-table char)
534 (aset font-spec-table char
535 (or (and (< char 256)
536 (cdr (car (char-table-extra-slot font-spec-table 0))))
537 (and font-spec
538 (encode-char char (ps-mule-font-spec-charset font-spec))
539 font-spec)
540 (catch 'tag
541 (dolist (elt (char-table-extra-slot font-spec-table 0))
542 (and (encode-char char (car elt))
543 (throw 'tag (cdr elt)))))
544 ;; Record that no font-spec exist for CHAR.
545 t))))
562 546
563(defconst ps-mule-external-libraries 547(defconst ps-mule-external-libraries
564 '((builtin nil nil 548 '((builtin nil nil nil nil nil nil)
565 nil nil nil) 549 (bdf ps-bdf nil bdf-generate-prologue
566 (bdf ps-bdf nil 550 bdf-check-font bdf-generate-font bdf-generate-glyph)
567 bdf-generate-prologue bdf-generate-font bdf-generate-glyphs) 551 (pcf nil nil pcf-generate-prologue
568 (pcf nil nil 552 pcf-check-font pcf-generate-font pcf-generate-glyph)
569 pcf-generate-prologue pcf-generate-font pcf-generate-glyphs) 553 (vflib nil nil vflib-generate-prologue
570 (vflib nil nil 554 vflib-check-font vflib-generate-font vflib-generate-glyphs))
571 vflib-generate-prologue vflib-generate-font vflib-generate-glyphs))
572 "Alist of information of external libraries to support PostScript printing. 555 "Alist of information of external libraries to support PostScript printing.
573Each element has the form: 556Each element has the form:
574 557
575 (FONT-SRC FEATURE INITIALIZED-P PROLOGUE-FUNC FONT-FUNC GLYPHS-FUNC) 558 (FONT-SRC FEATURE INITIALIZED-P
559 PROLOGUE-FUNC CHECK-FUNC FONT-FUNC GLYPH-FUNC)
576 560
577FONT-SRC is the font source: builtin, bdf, pcf, or vflib. 561FONT-SRC is the font source: builtin, bdf, pcf, or vflib.
578 562
@@ -582,340 +566,230 @@ FONT-SRC. Currently, we only have the feature `ps-bdf'.
582 566
583INITIALIZED-P indicates if this library is initialized or not. 567INITIALIZED-P indicates if this library is initialized or not.
584 568
585PROLOGUE-FUNC is a function to generate PostScript code which define several 569PROLOGUE-FUNC is a function to generate PostScript code which
586PostScript procedures that will be called by FONT-FUNC and GLYPHS-FUNC. It is 570define several PostScript procedures that will be called by
587called with no argument, and should return a list of strings. 571FONT-FUNC and GLYPHS-FUNC. It is called with no argument, and
572should return a list of strings.
588 573
589FONT-FUNC is a function to generate PostScript code which define a new font. It 574CHECK-FUNC is a function to check if a font is available or not.
590is called with one argument FONT-SPEC, and should return a list of strings. 575It is called with one argument FONT-SPEC, and should return
576non-nil iff the font specified in FONT-SPEC is available.
591 577
592GLYPHS-FUNC is a function to generate PostScript code which define glyphs of 578FONT-FUNC is a function to generate PostScript code which define
593characters. It is called with three arguments FONT-SPEC, CODE-LIST, and BYTES, 579a new font. It is called with one argument FONT-SPEC, and should
580return a list of strings.
581
582GLYPH-FUNC is a function to generate PostScript code which define a glyph of
583characters. It is called with two arguments FONT-SPEC and CODE,
594and should return a list of strings.") 584and should return a list of strings.")
595 585
596(defun ps-mule-init-external-library (font-spec) 586(defsubst ps-mule-exlib-feature (exlib) (nth 1 exlib))
597 "Initialize external library specified by FONT-SPEC for PostScript printing. 587(defsubst ps-mule-exlib-initialized-p (exlib) (nth 2 exlib))
598See the documentation of `ps-mule-get-font-spec' for FONT-SPEC's meaning." 588(defsubst ps-mule-exlib-set-initialized-p (exlib val)
599 (let* ((font-src (ps-mule-font-spec-src font-spec)) 589 (setcar (nthcdr 2 exlib) val))
600 (slot (assq font-src ps-mule-external-libraries))) 590(defsubst ps-mule-exlib-prologue (exlib) (nth 3 exlib))
591(defsubst ps-mule-exlib-check (exlib) (nth 4 exlib))
592(defsubst ps-mule-exlib-font (exlib) (nth 5 exlib))
593(defsubst ps-mule-exlib-glyph (exlib) (nth 6 exlib))
594
595(defun ps-mule-init-external-library (exlib)
596 "Initialize external library specified by EXLIB for PostScript printing.
597See the documentation of `ps-mule-external-libraries' for EXLIB's meaning."
598 (or (ps-mule-exlib-initialized-p exlib)
599 (let ((prologue-func (ps-mule-exlib-prologue exlib)))
600 (if prologue-func
601 (let ((feature (ps-mule-exlib-feature exlib)))
602 (if feature
603 (require feature))
604 (ps-output-prologue (funcall prologue-func))))
605 (ps-mule-exlib-set-initialized-p exlib t))))
606
607(defvar ps-mule-output-list nil)
608
609(defun ps-mule-check-font (font-spec)
610 "Check if a font specified in FONT-SPEC is available or not."
611 (let ((font-src (ps-mule-font-spec-src font-spec)))
601 (or (not font-src) 612 (or (not font-src)
602 (nth 2 slot) 613 (let ((exlib (assq font-src ps-mule-external-libraries)))
603 (let ((func (nth 3 slot))) 614 (ps-mule-init-external-library exlib)
604 (if func 615 (or (not (ps-mule-exlib-check exlib))
605 (progn 616 (funcall (ps-mule-exlib-check exlib) font-spec))))))
606 (require (nth 1 slot))
607 (ps-output-prologue (funcall func))))
608 (setcar (nthcdr 2 slot) t)))))
609
610;; Cached glyph information of fonts, alist of:
611;; (FONT-NAME ((FONT-TYPE-NUMBER . SCALED-FONT-NAME) ...)
612;; cache CODE0 CODE1 ...)
613(defvar ps-mule-font-cache nil)
614
615(defun ps-mule-generate-font (font-spec charset &optional header-p)
616 "Generate PostScript codes to define a new font in FONT-SPEC for CHARSET.
617
618If optional 3rd arg HEADER-P is non-nil, generate codes to define a header
619font."
620 (let* ((font-name (ps-mule-font-spec-name font-spec))
621 (font-name (if (consp font-name) (car font-name) font-name))
622 (font-cache (assoc font-name ps-mule-font-cache))
623 (font-src (ps-mule-font-spec-src font-spec))
624 (func (nth 4 (assq font-src ps-mule-external-libraries)))
625 (font-size (if header-p (if (eq ps-current-font 0)
626 ps-header-title-font-size-internal
627 ps-header-font-size-internal)
628 ps-font-size-internal))
629 (current-font (+ ps-current-font (if header-p 10 0)))
630 (scaled-font-name
631 (cond (header-p
632 (format "h%d" ps-current-font))
633 ((eq charset 'ascii)
634 (format "f%d" ps-current-font))
635 (t
636 (format "f%02x-%d" (charset-id charset) ps-current-font)))))
637 (and func (not font-cache)
638 (ps-output-prologue (funcall func charset font-spec)))
639 (ps-output-prologue
640 (list (format "/%s %f /%s Def%sFontMule\n"
641 scaled-font-name font-size font-name
642 (if (or header-p
643 (eq ps-mule-current-charset 'ascii))
644 "Ascii" ""))))
645 (if font-cache
646 (setcar (cdr font-cache)
647 (cons (cons current-font scaled-font-name)
648 (nth 1 font-cache)))
649 (setq font-cache (list font-name
650 (list (cons current-font scaled-font-name))
651 'cache)
652 ps-mule-font-cache (cons font-cache ps-mule-font-cache)))
653 font-cache))
654
655(defun ps-mule-generate-glyphs (font-spec code-list)
656 "Generate PostScript codes which generate glyphs for CODE-LIST of FONT-SPEC."
657 (let* ((font-src (ps-mule-font-spec-src font-spec))
658 (func (nth 5 (assq font-src ps-mule-external-libraries))))
659 (and func
660 (ps-output-prologue
661 (funcall func font-spec code-list
662 (ps-mule-font-spec-bytes font-spec))))))
663
664(defun ps-mule-prepare-font (font-spec string charset
665 &optional no-setfont header-p)
666 "Generate PostScript codes to print STRING of CHARSET by font FONT-SPEC.
667
668The generated code is inserted on prologue part except the code that sets the
669current font (using PostScript procedure `FM').
670
671If optional 4th arg NO-SETFONT is non-nil, don't generate the code for setting
672the current font.
673
674If optional 5th arg HEADER-P is non-nil, generate a code for setting a header
675font."
676 (let* ((font-name (ps-mule-font-spec-name font-spec))
677 (font-name (if (consp font-name) (car font-name) font-name))
678 (current-font (+ ps-current-font (if header-p 10 0)))
679 (font-cache (assoc font-name ps-mule-font-cache)))
680 (or (and font-cache (assq current-font (nth 1 font-cache)))
681 (setq font-cache (ps-mule-generate-font font-spec charset header-p)))
682 (or no-setfont
683 (let ((new-font (cdr (assq current-font (nth 1 font-cache)))))
684 (or (equal new-font ps-last-font)
685 (progn
686 (ps-output (format "/%s FM\n" new-font))
687 (setq ps-last-font new-font)))))
688 (if (nth 5 (assq (ps-mule-font-spec-src font-spec)
689 ps-mule-external-libraries))
690 ;; We have to generate PostScript codes which define glyphs.
691 (let* ((cached-codes (nthcdr 2 font-cache))
692 (bytes (ps-mule-font-spec-bytes font-spec))
693 (len (length string))
694 (i 0)
695 newcodes code)
696 (while (< i len)
697 (setq code (if (= bytes 1)
698 (aref string i)
699 (+ (* (aref string i) 256) (aref string (1+ i)))))
700 (or (memq code cached-codes)
701 (progn
702 (setq newcodes (cons code newcodes))
703 (setcdr cached-codes (cons code (cdr cached-codes)))))
704 (setq i (+ i bytes)))
705 (and newcodes
706 (ps-mule-generate-glyphs font-spec newcodes))))))
707
708;;;###autoload
709(defun ps-mule-prepare-ascii-font (string)
710 "Setup special ASCII font for STRING.
711STRING should contain only ASCII characters."
712 (let ((font-spec
713 (ps-mule-get-font-spec
714 'ascii
715 (car (nth ps-current-font (ps-font-alist 'ps-font-for-text))))))
716 (and font-spec
717 (ps-mule-prepare-font font-spec string 'ascii))))
718 617
719;;;###autoload 618(defun ps-mule-prepare-font (font-spec)
720(defun ps-mule-set-ascii-font () 619 "Generate PostScript codes defining a new font of FONT-TYPE for CHARSET."
721 (unless (eq ps-mule-current-charset 'ascii) 620 (let* ((font-src (ps-mule-font-spec-src font-spec))
722 (ps-set-font ps-current-font) 621 (exlib (assq font-src ps-mule-external-libraries))
723 (setq ps-mule-current-charset 'ascii))) 622 (id (ps-mule-font-spec-id font-spec))
724 623 (ftag (format "%02X" id))
725;; List of charsets of multi-byte characters in a text being printed. 624 (font-func (ps-mule-exlib-font exlib))
726;; If the text doesn't contain any multi-byte characters (i.e. only ASCII), 625 output-list)
727;; the value is nil. 626 (if font-func
728(defvar ps-mule-charset-list nil) 627 (setq output-list (funcall font-func font-spec))
628 (setq output-list
629 (format "/F%s /%s findfont def\n"
630 ftag (or (ps-mule-font-spec-name font-spec) "Courier")))
631 (ps-mule-font-spec-set-extra font-spec t))
632 (and output-list
633 (nconc ps-mule-output-list (list output-list)))))
634
635(defun ps-mule-prepare-glyph (char font-spec)
636 "Generate PostScript codes to print CHAR by FONT-SPEC.
637
638If CHAR is a cons (FROM TO), generate codes for characters
639specified by the character code range FROM and TO.
640
641The generated code is inserted on prologue part."
642 (if (vectorp font-spec)
643 (progn
644 (or (ps-mule-font-spec-extra font-spec)
645 (ps-mule-prepare-font font-spec))
646 (let ((glyph-func (ps-mule-exlib-glyph
647 (assq (ps-mule-font-spec-src font-spec)
648 ps-mule-external-libraries))))
649 (if glyph-func
650 (let (from to output-list)
651 (if (consp char)
652 (setq from (car char) to (cdr char))
653 (setq from char to char))
654 (while (<= from to)
655 (setq output-list
656 (funcall glyph-func font-spec from))
657 (and output-list
658 (ps-output-prologue output-list))
659 (setq from (1+ from)))))))))
729 660
730;; This is a PostScript code inserted in the header of generated PostScript. 661;; This is a PostScript code inserted in the header of generated PostScript.
731(defconst ps-mule-prologue 662(defconst ps-mule-prologue
732 "%%%% Start of Mule Section 663 "%%%% Start of Mule Section
733 664
734%% Working dictionary for general use. 665%% Redefine fonts for multiple charsets.
735/MuleDict 10 dict def 666/ReDefFont { % fontname encoding fdepvector size | -
736 667 20 dict begin
737%% Adjust /RelativeCompose properly by checking /BaselineOffset. 668 3 index findfont {
738/AdjustRelativeCompose { % fontdict |- fontdict 669 1 index /FID ne 2 index /UniqueID ne and {def} {pop pop} ifelse
739 dup length 2 add dict begin 670 } forall
740 { 1 index /FID ne { def } { pop pop } ifelse } forall 671 /FontType 0 def
741 currentdict /BaselineOffset known { 672 /FMapType 3 def
742 BaselineOffset false eq { /BaselineOffset 0 def } if 673 /EscChar 0 def
743 } { 674 % FontMatrix ::= [ size 0 0 size 0 0 ]
744 /BaselineOffset 0 def 675 /FontMatrix exch [ exch dup 0 exch 0 exch 0 0 ] def
745 } ifelse 676 /FDepVector exch def
746 currentdict /RelativeCompose known not { 677 /Encoding exch def
747 /RelativeCompose [ 0 0.1 ] def 678 currentdict
748 } { 679 end % fontname dic
749 RelativeCompose false ne { 680 definefont pop
750 [ BaselineOffset RelativeCompose BaselineOffset add
751 [ FontMatrix { FontSize div } forall ] transform ]
752 /RelativeCompose exch def
753 } if
754 } ifelse
755 currentdict
756 end
757} def 681} def
758
759%% Define already scaled font for non-ASCII character sets.
760/DefFontMule { % fontname size basefont |- --
761 findfont exch scalefont AdjustRelativeCompose definefont pop
762} bind def
763
764%% Define already scaled font for ASCII character sets.
765/DefAsciiFontMule { % fontname size basefont |-
766 MuleDict begin
767 findfont dup /Encoding get /ISOLatin1Encoding exch def
768 exch scalefont AdjustRelativeCompose reencodeFontISO
769 end
770} def
771
772/CurrentFont false def
773
774%% Set the specified font to use.
775%% For non-ASCII font, don't install Ascent, etc.
776/FM { % fontname |- --
777 /font exch def
778 font /f0 eq font /f1 eq font /f2 eq font /f3 eq or or or {
779 font F
780 } {
781 font findfont setfont
782 } ifelse
783} bind def
784
785%% Show vacant box for characters which don't have appropriate font.
786/SB { % count column |- --
787 SpaceWidth mul /w exch def
788 1 exch 1 exch { %for
789 pop
790 gsave
791 0 setlinewidth
792 0 Descent rmoveto w 0 rlineto
793 0 LineHeight rlineto w neg 0 rlineto closepath stroke
794 grestore
795 w 0 rmoveto
796 } for
797} bind def
798
799%% Flag to tell if we are now handling a composition. This is
800%% defined here because both composition handler and bitmap font
801%% handler require it.
802/Composing false def
803
804%%%% End of Mule Section
805
806" 682"
807 "PostScript code for printing multi-byte characters.") 683 "PostScript code for printing multi-byte characters.")
808 684
809(defvar ps-mule-prologue-generated nil) 685(defvar ps-mule-prologue-generated nil)
810 686
687;; EscChar used in generated composite fonts.
688(defconst ps-mule-esc-char 0)
689
811(defun ps-mule-prologue-generated () 690(defun ps-mule-prologue-generated ()
812 (unless ps-mule-prologue-generated 691 (unless ps-mule-prologue-generated
813 (ps-output-prologue ps-mule-prologue) 692 (ps-output-prologue ps-mule-prologue)
693 (ps-output-prologue (format "/EscChar %d def\n" ps-mule-esc-char))
814 (setq ps-mule-prologue-generated t))) 694 (setq ps-mule-prologue-generated t)))
815 695
816(defun ps-mule-find-wrappoint (from to char-width &optional composition) 696(defsubst ps-mule-eight-bit-char (byte)
817 "Find the longest sequence which is printable in the current line. 697 (if (< byte 128)
818 698 byte
819The search starts at FROM and goes until TO. 699 (decode-char 'eight-bit byte)))
820
821Optional 4th arg COMPOSITION, if non-nil, is information of
822composition starting at FROM.
823
824If COMPOSITION is nil, it is assumed that all characters between FROM
825and TO belong to a charset in `ps-mule-current-charset'. Otherwise,
826it is assumed that all characters between FROM and TO belong to the
827same composition.
828 700
829CHAR-WIDTH is the average width of ASCII characters in the current font. 701(defun ps-mule-encode-region (from to font-spec-table)
830 702 "Generate PostScript code for plotting characters in the region FROM and TO.
831Returns the value:
832
833 (ENDPOS . RUN-WIDTH)
834 703
835Where ENDPOS is the end position of the sequence and RUN-WIDTH is the width of 704FONT-NUM is 0, 1, 2, 3, 4, 5, or 6, each represents font tags
836the sequence." 705f0, f1, f2, f3, h0, h1, and H0 respectively."
837 (if (or composition (eq ps-mule-current-charset 'composition)) 706 (let* ((font-spec nil)
838 ;; We must draw one char by one. 707 (font-id 0)
839 (let ((run-width (if composition 708 (string-list nil)
840 (nth 5 composition) 709 ;; At most 4-byte (EscChar FONT-ID CODE1 CODE2) per character.
841 (* (char-width (char-after from)) char-width)))) 710 (str (make-string (* (- to from) 4) 0))
842 (if (> run-width ps-width-remaining) 711 (i 0))
843 (cons from ps-width-remaining) 712 (goto-char from)
844 (cons (if composition 713 (while (< (point) to)
845 (nth 1 composition) 714 (let* ((char (following-char))
846 (ps-mule-next-point from)) 715 (this-spec (ps-mule-get-font-spec char font-spec-table font-spec))
847 run-width))) 716 this-id)
848 ;; We assume that all characters in this range have the same width. 717 (if (vectorp this-spec)
849 (setq char-width (* char-width (charset-width ps-mule-current-charset))) 718 (setq this-id (ps-mule-font-spec-font-id this-spec))
850 (let ((run-width (* (chars-in-region from to) char-width))) 719 ;; Can't print CHAR. Replace it with '?'.
851 (if (> run-width ps-width-remaining) 720 (setq char ??
852 (cons (min to 721 this-spec (ps-mule-get-font-spec char font-spec-table nil)
853 (save-excursion 722 this-id (ps-mule-font-spec-font-id this-spec)))
854 (goto-char from) 723 (or (= font-id this-id)
855 (forward-point 724 (progn
856 (truncate (/ ps-width-remaining char-width))))) 725 (if font-spec
857 ps-width-remaining) 726 (setq string-list (cons (substring str 0 i) string-list)
858 (cons to run-width))))) 727 i 0))
728 (setq font-id this-id)
729 (or (= font-id 0)
730 (progn
731 (aset str i ps-mule-esc-char)
732 (setq i (1+ i))
733 (aset str i font-id)
734 (setq i (1+ i))))))
735 (setq font-spec this-spec)
736 (if (< char 128)
737 (aset str i char)
738 (let* ((code (ps-mule-encode-char char font-spec)))
739 (if (= (ps-mule-font-spec-bytes font-spec) 1)
740 (aset str i (ps-mule-eight-bit-char code))
741 (aset str i (ps-mule-eight-bit-char (/ code 256)))
742 (setq i (1+ i))
743 (aset str i (ps-mule-eight-bit-char (% code 256))))))
744 (setq i (1+ i))
745 (forward-char 1)))
746 (nreverse (cons (substring str 0 i) string-list))))
747
748(defun ps-mule-plot-composition (composition font-spec-table)
749 "Generate PostScript code for plotting COMPOSITION with FONT-NUM."
750 (ps-output "[")
751 (let ((components (copy-sequence (nth 2 composition)))
752 (font-spec nil))
753 (dotimes (i (length components))
754 (let ((elt (aref components i))
755 this-spec)
756 (if (consp elt)
757 ;; ELT is a composition rule.
758 (ps-output (format " %d" (encode-composition-rule elt)))
759 ;; ELT is a glyph character.
760 (setq this-spec
761 (ps-mule-get-font-spec elt font-spec-table font-spec))
762 (or (vectorp this-spec)
763 ;; Can't print CHAR. Replace it with '?'.
764 (setq elt ??
765 this-spec
766 (ps-mule-get-font-spec elt font-spec-table font-spec)))
767 (setq font-spec this-spec)
768 (let* ((bytes (ps-mule-font-spec-bytes font-spec))
769 (code (ps-mule-encode-char elt font-spec))
770 (font-id (ps-mule-font-spec-font-id font-spec))
771 (str (make-string (if (= font-id 0) 1 (+ 2 bytes)) 0)))
772 (if (= font-id 0)
773 (aset str 0 (ps-mule-eight-bit-char code))
774 (aset str 0 ps-mule-esc-char)
775 (aset str 1 (ps-mule-eight-bit-char font-id))
776 (if (= bytes 1)
777 (aset str 2 (ps-mule-eight-bit-char code))
778 (aset str 2 (ps-mule-eight-bit-char (/ code 256)))
779 (aset str 3 (ps-mule-eight-bit-char (% code 256)))))
780 (ps-output "[")
781 (ps-output-string str)
782 (ps-output (if (eq (ps-mule-font-spec-src font-spec) 'bdf)
783 (format "/C%02X-%X" (ps-mule-font-spec-id font-spec)
784 elt)
785 "false"))
786 (ps-output "]"))))))
787 (ps-output " ] " (if (nth 3 composition) "RLC" "RBC") "\n"))
859 788
860;;;###autoload
861(defun ps-mule-plot-string (from to &optional bg-color) 789(defun ps-mule-plot-string (from to &optional bg-color)
862 "Generate PostScript code for plotting characters in the region FROM and TO. 790 "Generate PostScript code for plotting characters in the region FROM and TO.
863 791
864It is assumed that all characters in this region belong to the same charset. 792Optional argument BG-COLOR is ignored.
865
866Optional argument BG-COLOR specifies background color.
867
868Returns the value:
869
870 (ENDPOS . RUN-WIDTH)
871
872Where ENDPOS is the end position of the sequence and RUN-WIDTH is the width of
873the sequence."
874 (setq ps-mule-current-charset (charset-after from))
875 (let* ((wrappoint (ps-mule-find-wrappoint
876 from to (ps-avg-char-width 'ps-font-for-text)))
877 (to (car wrappoint))
878 (font-type (car (nth ps-current-font
879 (ps-font-alist 'ps-font-for-text))))
880 (font-spec (ps-mule-get-font-spec ps-mule-current-charset font-type))
881 (string (buffer-substring-no-properties from to)))
882 (cond
883 ((= from to)
884 ;; We can't print any more characters in the current line.
885 nil)
886
887 (font-spec
888 ;; We surely have a font for printing this character set.
889 (ps-output-string (ps-mule-string-encoding font-spec string))
890 (ps-output " S\n"))
891
892 ((eq ps-mule-current-charset 'latin-iso8859-1)
893 ;; Latin-1 can be printed by a normal ASCII font.
894 (ps-output-string (ps-mule-string-ascii string))
895 (ps-output " S\n"))
896
897 ;; This case is obsolete for Emacs 21.
898 ((eq ps-mule-current-charset 'composition)
899 (ps-mule-plot-composition from (ps-mule-next-point from) bg-color))
900
901 (t
902 ;; No way to print this charset. Just show a vacant box of an
903 ;; appropriate width.
904 (ps-output (format "%d %d SB\n"
905 (length string)
906 (if (eq ps-mule-current-charset 'composition)
907 (char-width (char-after from))
908 (charset-width ps-mule-current-charset))))))
909 wrappoint))
910
911;;;###autoload
912(defun ps-mule-plot-composition (from to &optional bg-color)
913 "Generate PostScript code for plotting composition in the region FROM and TO.
914
915It is assumed that all characters in this region belong to the same
916composition.
917
918Optional argument BG-COLOR specifies background color.
919 793
920Returns the value: 794Returns the value:
921 795
@@ -923,102 +797,100 @@ Returns the value:
923 797
924Where ENDPOS is the end position of the sequence and RUN-WIDTH is the width of 798Where ENDPOS is the end position of the sequence and RUN-WIDTH is the width of
925the sequence." 799the sequence."
926 (let* ((composition (find-composition from nil nil t)) 800 (let* ((average-width (ps-avg-char-width 'ps-font-for-text))
927 (wrappoint (ps-mule-find-wrappoint 801 (point (point))
928 from to (ps-avg-char-width 'ps-font-for-text) 802 (composition (find-composition from to nil t))
929 composition)) 803 (stop (if composition (car composition) to))
930 (to (car wrappoint)) 804 (ascii-or-latin-1 "[\000-\377]+")
931 (font-type (car (nth ps-current-font 805 (run-width 0)
932 (ps-font-alist 'ps-font-for-text))))) 806 (endpos nil)
933 (if (< from to) 807 (font-spec-table (aref ps-mule-font-spec-tables
934 ;; We can print this composition in the current line. 808 (aref ps-mule-font-number-to-type
935 (let ((components (nth 2 composition))) 809 ps-current-font)))
936 (ps-mule-plot-components 810 width)
937 (ps-mule-prepare-font-for-components components font-type) 811 (goto-char from)
938 (if (nth 3 composition) "RLC" "RBC")))) 812 (while (not endpos)
939 wrappoint)) 813 (cond ((= (point) stop)
940 814 (if (= stop to)
941;; Prepare font of FONT-TYPE for printing COMPONENTS. By side effect, 815 (setq endpos stop)
942;; change character elements in COMPONENTS to the form: 816 (if (< from stop)
943;; ENCODED-STRING or (FONTNAME . ENCODED-STRING) 817 (dolist (l (ps-mule-encode-region from (point)
944;; and change rule elements to the encoded value (integer). 818 font-spec-table))
945;; The latter form is used if we much change font for the character. 819 (ps-output-string l)
946 820 (ps-output " S\n")))
947(defun ps-mule-prepare-font-for-components (components font-type) 821 (setq width (* (nth 5 composition) average-width))
948 (let ((len (length components)) 822 (if (< ps-width-remaining (+ run-width width))
949 (i 0) 823 (setq endpos stop)
950 elt) 824 (ps-mule-plot-composition composition font-spec-table)
951 (while (< i len) 825 (setq run-width (+ run-width width)
952 (setq elt (aref components i)) 826 from (nth 1 composition))
953 (if (consp elt) 827 (goto-char from)
954 ;; ELT is a composition rule. 828 (setq composition (find-composition (point) to nil t))
955 (setq elt (encode-composition-rule elt)) 829 (setq stop (if composition (car composition) to)))))
956 ;; ELT is a glyph character. 830
957 (let* ((charset (char-charset elt)) 831 ((looking-at ascii-or-latin-1)
958 (font (or (eq charset ps-mule-current-charset) 832 (let ((nchars (- (min (match-end 0) stop) (point))))
959 (if (eq charset 'ascii) 833 (setq width (* average-width nchars))
960 (format "/f%d" ps-current-font) 834 (if (< ps-width-remaining (+ run-width width))
961 (format "/f%02x-%d" 835 (setq nchars (truncate (- ps-width-remaining run-width)
962 (charset-id charset) ps-current-font)))) 836 average-width)
963 str) 837 run-width (+ run-width (* nchars average-width))
964 (setq ps-mule-current-charset charset 838 endpos (+ (point) nchars))
965 str (ps-mule-string-encoding 839 (setq run-width (+ run-width width))
966 (ps-mule-get-font-spec charset font-type) 840 (forward-char nchars))))
967 (char-to-string elt) 841
968 'no-setfont)) 842 (t
969 (if (stringp font) 843 (while (and (< (point) stop) (not endpos))
970 (setq elt (cons font str) ps-last-font font) 844 (setq width (char-width (following-char)))
971 (setq elt str)))) 845 (if (< ps-width-remaining (+ run-width width))
972 (aset components i elt) 846 (setq endpos (point))
973 (setq i (1+ i)))) 847 (setq run-width (+ run-width width))
974 components) 848 (forward-char 1))))))
975 849
976(defun ps-mule-plot-components (components tail) 850 (if (< from endpos)
977 (let ((elt (aref components 0)) 851 (dolist (l (ps-mule-encode-region from endpos font-spec-table))
978 (len (length components)) 852 (ps-output-string l)
979 (i 1)) 853 (ps-output " S\n")))
980 (ps-output "[ ") 854 (goto-char point)
981 (if (stringp elt) 855 (cons endpos run-width)))
982 (ps-output-string elt) 856
983 (ps-output (car elt) " ") 857;; Character composition support
984 (ps-output-string (cdr elt)))
985 (while (< i len)
986 (setq elt (aref components i) i (1+ i))
987 (ps-output " ")
988 (cond ((stringp elt)
989 (ps-output-string elt))
990 ((consp elt)
991 (ps-output (car elt) " ")
992 (ps-output-string (cdr elt)))
993 (t ; i.e. (integerp elt)
994 (ps-output (format "%d" elt)))))
995 (ps-output " ] " tail "\n")))
996
997;; Composite font support
998 858
999(defvar ps-mule-composition-prologue-generated nil) 859(defvar ps-mule-composition-prologue-generated nil)
1000 860
1001(defconst ps-mule-composition-prologue 861(defconst ps-mule-composition-prologue
1002 "%%%% Character composition handler 862 "%%%% Procedures for character composition.
1003/RelativeCompositionSkip 0.4 def 863/RelativeCompositionSkip 0.4 def
1004 864
1005%% Get a bounding box (relative to currentpoint) of STR. 865%% Get a bounding box (relative to currentpoint) of STR.
1006/GetPathBox { % str |- -- 866/GetPathBox { % [ str cname ] | -
1007 gsave 867 dup 1 get dup false ne {
1008 currentfont /FontType get 3 eq { %ifelse 868 BitmapDict exch get /bmp exch def
1009 stringwidth pop pop 869 %% bmp ::= [ DWIDTH WIDTH HEIGHT XOFF YOFF BITMAP RELATIVE-COMPOSE]
870 /LLY bmp 4 get def
871 /URY LLY bmp 2 get add def
872 /RelativeCompose bmp 6 get dup false ne {
873 dup LLY le { pop 1 } { URY ge { -1 } { 0 } ifelse } ifelse
874 } {
875 pop 0
876 } ifelse def
877 dup 0 get stringwidth pop dup /WIDTH exch def bmp 0 get div
878 dup LLY mul /LLY exch def
879 URY mul /URY exch def
1010 } { 880 } {
1011 currentpoint /y exch def /x exch def 881 pop
1012 false charpath flattenpath pathbbox 882 dup 0 get stringwidth pop /WIDTH exch def
1013 y sub /URY exch def x sub /URX exch def 883 gsave 0 0 moveto
1014 y sub /LLY exch def x sub /LLX exch def 884 dup 0 get false charpath flattenpath pathbbox
885 /URY exch def pop /LLY exch def pop
886 grestore
887 /RelativeCompose 0 def
1015 } ifelse 888 } ifelse
1016 grestore
1017} bind def 889} bind def
1018 890
1019%% Apply effects (underline, strikeout, overline, box) to the 891%% Apply effects except for shadow and outline to the rectangle
1020%% rectangle specified by TOP BOTTOM LEFT RIGHT. 892%% specified by TOP BOTTOM LEFT RIGHT.
1021/SpecialEffect { % -- |- -- 893/SpecialEffect { % -- | --
1022 currentpoint dup TOP add /yy exch def BOTTOM add /YY exch def 894 currentpoint dup TOP add /yy exch def BOTTOM add /YY exch def
1023 dup LEFT add /xx exch def RIGHT add /XX exch def 895 dup LEFT add /xx exch def RIGHT add /XX exch def
1024 %% Adjust positions for future shadowing. 896 %% Adjust positions for future shadowing.
@@ -1036,537 +908,449 @@ the sequence."
1036 Effect 16 and 0 ne { false 0 doBox } if % box 908 Effect 16 and 0 ne { false 0 doBox } if % box
1037} def 909} def
1038 910
1039%% Show STR with effects (shadow, outline). 911%% Draw COMPONENTS which has the form [ [str0 xoff0 yoff0] ... ] with
1040/ShowWithEffect { % str |- -- 912%% effects shadow and outline.
1041 Effect 8 and 0 ne { dup doShadow } if 913/ShowComponents { % components | -
1042 Effect 32 and 0 ne { true doOutline } { show } ifelse 914 gsave
1043} def 915 { gsave aload pop rmoveto
1044 916 Effect 8 and 0 ne { dup doShadow } if
1045%% Draw COMPONENTS which have the form [ font0? [str0 xoff0 yoff0] ... ]. 917 Effect 32 and 0 ne { true doOutline } { show } ifelse
1046/ShowComponents { % components |- - 918 grestore
1047 LEFT 0 lt { LEFT neg 0 rmoveto } if
1048 {
1049 dup type /nametype eq { % font
1050 FM
1051 } { % [ str xoff yoff ]
1052 gsave
1053 aload pop rmoveto ShowWithEffect
1054 grestore
1055 } ifelse
1056 } forall 919 } forall
920 grestore
1057 RIGHT 0 rmoveto 921 RIGHT 0 rmoveto
1058} def 922} def
1059 923
1060%% Show relative composition. 924%% Show relative composition.
1061/RLC { % [ font0? str0 font1? str1 ... fontN? strN ] |- -- 925/RLC { % [[str0 cname0] [str1 cname1] ... [strN cnameN]] | -
1062 /components exch def 926 /components exch def
1063 /Composing true def 927 [ % push [str xoff yoff] one by one
1064 /first true def 928 [ components 0 get GetPathBox aload pop pop 0 0 ]
1065 gsave 929 %% Bounding box of overall glyphs.
1066 [ components { 930 /LEFT 0 def
1067 /elt exch def 931 /RIGHT WIDTH def
1068 elt type /nametype eq { % font 932 /TOP URY def
1069 elt dup FM 933 /BOTTOM LLY def
1070 } { first { % first string 934
1071 /first false def 935 1 1 components length 1 sub {
1072 elt GetPathBox 936 components exch get
1073 %% Bounding box of overall glyphs. 937 [ exch
1074 /LEFT LLX def 938 GetPathBox
1075 /RIGHT URX def 939 aload pop pop % str
1076 /TOP URY def 940 0 % xoff
1077 /BOTTOM LLY def 941 RelativeCompose 1 eq { % compose on TOP
1078 currentfont /RelativeCompose known { 942 TOP LLY sub RelativeCompositionSkip add % yoff
1079 /relative currentfont /RelativeCompose get def 943 /TOP TOP URY LLY sub add RelativeCompositionSkip add def
944 } { RelativeCompose -1 eq { % compose under BOTTOM
945 BOTTOM URY sub RelativeCompositionSkip sub % yoff
946 /BOTTOM BOTTOM URY LLY sub sub
947 RelativeCompositionSkip sub def
1080 } { 948 } {
1081 %% Disable relative composition by setting sufficiently low 949 0 % yoff
1082 %% and high positions. 950 URY TOP gt { /TOP URY def } if
1083 /relative [ -100000 100000 ] def 951 LLY BOTTOM lt { /BOTTOM LLY def } if
1084 } ifelse 952 } ifelse } ifelse
1085 [ elt 0 0 ] 953 ]
1086 } { % other strings 954 } for
1087 elt GetPathBox 955 ]
1088 [ elt % str 956 SpecialEffect % Reflect special effects.
1089 LLX 0 lt { RIGHT } { 0 } ifelse % xoff 957 ShowComponents % Draw components.
1090 LLY relative 1 get ge { % compose on TOP
1091 TOP LLY sub RelativeCompositionSkip add % yoff
1092 /TOP TOP URY LLY sub add RelativeCompositionSkip add def
1093 } { URY relative 0 get le { % compose under BOTTOM
1094 BOTTOM URY sub RelativeCompositionSkip sub % yoff
1095 /BOTTOM BOTTOM URY LLY sub sub
1096 RelativeCompositionSkip sub def
1097 } {
1098 0 % yoff
1099 URY TOP gt { /TOP URY def } if
1100 LLY BOTTOM lt { /BOTTOM LLY def } if
1101 } ifelse } ifelse
1102 ]
1103 URX RIGHT gt { /RIGHT URX def } if
1104 } ifelse } ifelse
1105 } forall ] /components exch def
1106 grestore
1107
1108 %% Reflect special effects.
1109 SpecialEffect
1110
1111 %% Draw components while ignoring effects other than shadow and outline.
1112 components ShowComponents
1113 /Composing false def
1114
1115} def 958} def
1116 959
1117%% Show rule-base composition. 960%% Show rule-base composition.
1118/RBC { % [ font0? str0 rule1 font1? str1 rule2 ... strN ] |- -- 961/RBC { % [[str0 cname0] rule1 [str1 cname0] rule2 ... [strN cnameN]] | -
1119 /components exch def 962 /components exch def
1120 /Composing true def 963 [ % push [str xoff yoff] one by one
1121 /first true def 964 [ components 0 get GetPathBox aload pop pop 0 0 ]
1122 gsave 965 %% Bounding box of overall glyphs.
1123 [ components { 966 /LEFT 0 def
1124 /elt exch def 967 /RIGHT WIDTH def
1125 elt type /nametype eq { % font 968 /TOP URY def
1126 elt dup FM 969 /BOTTOM LLY def
1127 } { elt type /integertype eq { % rule 970 1 1 components length 1 sub {
1128 %% This RULE decoding should be compatible with macro 971 components exch get /elt exch def
972 elt type /integertype eq { % rule
973 %% Do the same RULE decoding as the macro
1129 %% COMPOSITION_DECODE_RULE in emacs/src/composite.h. 974 %% COMPOSITION_DECODE_RULE in emacs/src/composite.h.
1130 elt 12 idiv dup 3 mod /grefx exch def 3 idiv /grefy exch def 975 elt 12 idiv dup 3 mod /grefx exch def 3 idiv /grefy exch def
1131 elt 12 mod dup 3 mod /nrefx exch def 3 idiv /nrefy exch def 976 elt 12 mod dup 3 mod /nrefx exch def 3 idiv /nrefy exch def
1132 } { first { % first string
1133 /first false def
1134 elt GetPathBox
1135 %% Bounding box of overall glyphs.
1136 /LEFT LLX def
1137 /RIGHT URX def
1138 /TOP URY def
1139 /BOTTOM LLY def
1140 /WIDTH RIGHT LEFT sub def
1141 [ elt 0 0 ]
1142 } { % other strings 977 } { % other strings
978 [
1143 elt GetPathBox 979 elt GetPathBox
1144 /width URX LLX sub def 980 aload pop pop
1145 /height URY LLY sub def 981 /height URY LLY sub def
1146 /left LEFT [ 0 WIDTH 2 div WIDTH ] grefx get add 982 /left LEFT [ 0 RIGHT LEFT sub dup 2 div exch ] grefx get add
1147 [ 0 width 2 div width ] nrefx get sub def 983 [ 0 WIDTH 2 div WIDTH ] nrefx get sub def
1148 /bottom [ TOP 0 BOTTOM TOP BOTTOM add 2 div ] grefy get 984 /bottom [ TOP 0 BOTTOM TOP BOTTOM add 2 div ] grefy get
1149 [ height LLY neg 0 height 2 div ] nrefy get sub def 985 [ height LLY neg 0 height 2 div ] nrefy get sub def
1150 %% Update bounding box 986 %% Update bounding box
1151 left LEFT lt { /LEFT left def } if 987 left LEFT lt { /LEFT left def } if
1152 left width add RIGHT gt { /RIGHT left width add def } if 988 left WIDTH add RIGHT gt { /RIGHT left WIDTH add def } if
1153 /WIDTH RIGHT LEFT sub def
1154 bottom BOTTOM lt { /BOTTOM bottom def } if 989 bottom BOTTOM lt { /BOTTOM bottom def } if
1155 bottom height add TOP gt { /TOP bottom height add def } if 990 bottom height add TOP gt { /TOP bottom height add def } if
1156 [ elt left LLX sub bottom LLY sub ] 991 left bottom LLY sub ]
1157 } ifelse } ifelse } ifelse 992 } ifelse
1158 } forall ] /components exch def 993 } for
1159 grestore 994 ]
1160
1161 %% Reflect special effects.
1162 SpecialEffect
1163 995
1164 %% Draw components while ignoring effects other than shadow and outline. 996 LEFT 0 lt { % Adjust xoff to the right.
1165 components ShowComponents 997 dup { dup 1 get LEFT sub 1 exch put } forall
998 /RIGHT RIGHT LEFT sub def
999 } if
1166 1000
1167 /Composing false def 1001 SpecialEffect % Reflect special effects.
1002 ShowComponents % Draw components.
1168} def 1003} def
1169%%%% End of character composition handler 1004%%%% End of procedures for character composition
1170
1171" 1005"
1172 "PostScript code for printing character composition.") 1006 "PostScript code for printing character composition.")
1173 1007
1174(defun ps-mule-string-ascii (str) 1008(defun ps-mule-composition-prologue-generated ()
1175 (ps-set-font ps-current-font) 1009 (unless ps-mule-composition-prologue-generated
1176 (string-as-unibyte (encode-coding-string str 'iso-latin-1))) 1010 (ps-mule-prologue-generated)
1177 1011 (ps-output-prologue ps-mule-composition-prologue)
1178;; Encode STR for a font specified by FONT-SPEC and return the result. 1012 (setq ps-mule-composition-prologue-generated t)))
1179;; If necessary, it generates the PostScript code for the font and glyphs to
1180;; print STR. If optional 4th arg HEADER-P is non-nil, it is assumed that STR
1181;; is for headers.
1182(defun ps-mule-string-encoding (font-spec str &optional no-setfont header-p)
1183 (let ((encoding (ps-mule-font-spec-encoding font-spec)))
1184 (setq str
1185 (string-as-unibyte
1186 (cond ((coding-system-p encoding)
1187 (encode-coding-string str encoding))
1188 ((functionp encoding)
1189 (funcall encoding str))
1190 (encoding
1191 (error "Invalid coding system or function: %s" encoding))
1192 (t
1193 str))))
1194 (if (ps-mule-font-spec-src font-spec)
1195 (ps-mule-prepare-font font-spec str ps-mule-current-charset
1196 (or no-setfont header-p)
1197 header-p)
1198 (or no-setfont
1199 (ps-set-font ps-current-font)))
1200 str))
1201 1013
1202;; Bitmap font support 1014;; Bitmap font support
1203 1015
1204(defvar ps-mule-bitmap-prologue-generated nil) 1016(defvar ps-mule-bitmap-prologue-generated nil)
1205 1017
1206(defconst ps-mule-bitmap-prologue 1018(defconst ps-mule-bitmap-prologue
1207 "%%%% Bitmap font handler 1019 "%%%% Procedures for bitmap fonts.
1208
1209/str7 7 string def % working area
1210 1020
1211%% We grow the dictionary one bunch (1024 entries) by one. 1021%% Create a base bitmap font.
1212/BitmapDictArray 256 array def 1022/NBF { % fontname fontsize relative-compose baseline-offset enc | --
1213/BitmapDictLength 1024 def 1023 11 dict begin
1214/BitmapDictIndex -1 def 1024 /FontType 3 def
1215 1025 /FontMatrix matrix def
1216/NewBitmapDict { % -- |- -- 1026 /FontBBox [ 0 0 0 0 ] def
1217 /BitmapDictIndex BitmapDictIndex 1 add def 1027 /Encoding exch def
1218 BitmapDictArray BitmapDictIndex BitmapDictLength dict put
1219} bind def
1220
1221%% Make at least one dictionary.
1222NewBitmapDict
1223
1224/AddBitmap { % gloval-charname bitmap-data |- --
1225 BitmapDictArray BitmapDictIndex get
1226 dup length BitmapDictLength ge {
1227 pop
1228 NewBitmapDict
1229 BitmapDictArray BitmapDictIndex get
1230 } if
1231 3 1 roll put
1232} bind def
1233
1234/GetBitmap { % gloval-charname |- bitmap-data
1235 0 1 BitmapDictIndex { BitmapDictArray exch get begin } for
1236 load
1237 0 1 BitmapDictIndex { pop end } for
1238} bind def
1239
1240%% Return a global character name which can be used as a key in the
1241%% bitmap dictionary.
1242/GlobalCharName { % fontidx code1 code2 |- gloval-charname
1243 exch 256 mul add exch 65536 mul add 16777216 add 16 str7 cvrs 0 66 put
1244 str7 cvn
1245} bind def
1246
1247%% Character code holder for a 2-byte character.
1248/FirstCode -1 def
1249
1250%% Glyph rendering procedure
1251/BuildGlyphCommon { % fontdict charname |- --
1252 1 index /FontDimension get 1 eq { /FirstCode 0 store } if
1253 NameIndexDict exch get % STACK: fontdict charcode
1254 FirstCode 0 lt { %ifelse
1255 %% This is the first byte of a 2-byte character. Just
1256 %% remember it for the moment.
1257 /FirstCode exch store
1258 pop
1259 0 0 setcharwidth
1260 } {
1261 1 index /FontSize get /size exch def
1262 1 index /FontSpaceWidthRatio get /ratio exch def
1263 1 index /FontIndex get exch FirstCode exch
1264 GlobalCharName GetBitmap /bmp exch def
1265 %% bmp == [ DWIDTH BBX-WIDTH BBX-HEIGHT BBX-XOFF BBX-YOFF BITMAP ]
1266 Composing { %ifelse
1267 /FontMatrix get [ exch { size div } forall ] /mtrx exch def
1268 bmp 3 get bmp 4 get mtrx transform
1269 /LLY exch def /LLX exch def
1270 bmp 1 get bmp 3 get add bmp 2 get bmp 4 get add mtrx transform
1271 /URY exch def /URX exch def
1272 } {
1273 pop
1274 } ifelse
1275 /FirstCode -1 store
1276
1277 bmp 0 get SpaceWidthRatio ratio div mul size div 0 % wx wy
1278 setcharwidth % We can't use setcachedevice here.
1279
1280 bmp 1 get 0 gt bmp 2 get 0 gt and {
1281 bmp 1 get bmp 2 get % width height
1282 true % polarity
1283 [ size 0 0 size neg bmp 3 get neg bmp 2 get bmp 4 get add ] % matrix
1284 bmp 5 1 getinterval cvx % datasrc
1285 imagemask
1286 } if
1287 } ifelse
1288} bind def
1289
1290/BuildCharCommon {
1291 1 index /Encoding get exch get
1292 1 index /BuildGlyph get exec
1293} bind def
1294
1295%% Bitmap font creator
1296
1297%% Common Encoding shared by all bitmap fonts.
1298/EncodingCommon 256 array def
1299%% Mapping table from character name to character code.
1300/NameIndexDict 256 dict def
13010 1 255 { %for
1302 /idx exch def
1303 /idxname idx 256 add 16 (XXX) cvrs dup 0 67 put cvn def % `C' == 67
1304 EncodingCommon idx idxname put
1305 NameIndexDict idxname idx put
1306} for
1307
1308/GlobalFontIndex 0 def
1309
1310%% fontname dim col fontsize relative-compose baseline-offset fbbx |- --
1311/BitmapFont {
1312 15 dict begin
1313 /FontBBox exch def
1314 /BaselineOffset exch def 1028 /BaselineOffset exch def
1315 /RelativeCompose exch def 1029 /RelativeCompose exch def
1316 /FontSize exch def 1030 /FontSize exch def
1317 /FontBBox [ FontBBox { FontSize div } forall ] def 1031 /FontMatrix [ 1 FontSize div 0 0 1 FontSize div 0 0 ] def
1318 FontBBox 2 get FontBBox 0 get sub exch div 1032 /BuildGlyph { % fontdict charname | -
1319 /FontSpaceWidthRatio exch def 1033 BitmapDict exch get /bmp exch def pop
1320 /FontDimension exch def 1034 %% bmp ::= [ DWIDTH WIDTH HEIGHT XOFF YOFF BITMAP RELATIVE-COMPOSE ]
1321 /FontIndex GlobalFontIndex def 1035 /llx bmp 3 get def
1322 /FontType 3 def 1036 /lly bmp 4 get def
1323 /FontMatrix matrix def 1037 /urx llx bmp 1 get add def
1324 /Encoding EncodingCommon def 1038 /ury lly bmp 2 get add def
1325 /BuildGlyph { BuildGlyphCommon } def 1039 bmp 0 get 0 llx lly urx ury setcachedevice
1326 /BuildChar { BuildCharCommon } def 1040 bmp 5 get length 0 gt {
1327 currentdict end 1041 llx ury translate
1328 definefont pop 1042 bmp 1 get bmp 2 get
1329 /GlobalFontIndex GlobalFontIndex 1 add def 1043 true [ 1 0 0 -1 0 0 ] { bmp 5 get } imagemask
1330} bind def 1044 } if
1331 1045 } bind def
1332%% Define a new bitmap font. 1046 /BuildChar { % fontdict byte | -
1333%% fontname dim col fontsize relative-compose baseline-offset fbbx |- -- 1047 1 index /Encoding get exch get
1334/NF { 1048 1 index /BuildGlyph get exec
1335 /fbbx exch def 1049 } bind def
1336 %% Convert BDF's FontBoundingBox to PostScript's FontBBox 1050 dup currentdict end
1337 [ fbbx 2 get fbbx 3 get 1051 definefont def
1338 fbbx 2 get fbbx 0 get add fbbx 3 get fbbx 1 get add ]
1339 BitmapFont
1340} bind def 1052} bind def
1341 1053
1342%% Define a glyph for the specified font and character. 1054%% Create a parent font of 8/8 mapping.
1343/NG { % fontname charcode bitmap-data |- -- 1055/NPF { % fontname encoding fdepvector | -
1344 /bmp exch def 1056 8 dict begin
1345 exch findfont dup /BaselineOffset get bmp 4 get add bmp exch 4 exch put 1057 /FontType 0 def
1346 /FontIndex get exch 1058 /FMapType 2 def
1347 dup 256 idiv exch 256 mod GlobalCharName 1059 /FontMatrix matrix def
1348 bmp AddBitmap 1060 /FDepVector exch def
1061 /Encoding exch def
1062 dup currentdict
1063 end
1064 definefont def
1349} bind def 1065} bind def
1350%%%% End of bitmap font handler
1351 1066
1067%%%% End of procedures for bitmap fonts.
1352") 1068")
1353 1069
1354;; External library support. 1070;; External library support.
1355 1071
1072(defvar ps-mule-bitmap-dict-list nil)
1073(defvar ps-mule-bitmap-parent-table nil)
1074
1356;; The following three functions are to be called from external 1075;; The following three functions are to be called from external
1357;; libraries which support bitmap fonts (e.g. `bdf') to get 1076;; libraries which support bitmap fonts (e.g. `bdf') to get
1358;; appropriate PostScript code. 1077;; appropriate PostScript code.
1359 1078
1360(defun ps-mule-generate-bitmap-prologue () 1079(defun ps-mule-generate-bitmap-prologue ()
1361 (unless ps-mule-bitmap-prologue-generated 1080 (unless ps-mule-bitmap-prologue-generated
1362 (setq ps-mule-bitmap-prologue-generated t) 1081 (setq ps-mule-bitmap-prologue-generated t
1082 ps-mule-bitmap-dict-list nil
1083 ps-mule-bitmap-font-record (make-vector 1024 nil))
1363 (list ps-mule-bitmap-prologue))) 1084 (list ps-mule-bitmap-prologue)))
1364 1085
1365(defun ps-mule-generate-bitmap-font (&rest args) 1086(defun ps-mule-generate-bitmap-font (font-spec size relative-compose
1366 (list (apply 'format "/%s %d %d %f %S %d %S NF\n" args))) 1087 baselie-offset bbx)
1367 1088 (let* ((id (ps-mule-font-spec-id font-spec))
1368(defun ps-mule-generate-bitmap-glyph (font-name code dwidth bbx bitmap) 1089 (bytes (ps-mule-font-spec-bytes font-spec))
1369 (format "/%s %d [ %d %d %d %d %d <%s> ] NG\n" 1090 output-list)
1370 font-name code 1091 (if (= bytes 1)
1371 dwidth (aref bbx 0) (aref bbx 1) (aref bbx 2) (aref bbx 3) 1092 (setq output-list
1372 bitmap)) 1093 (list (format "/E%02X [ 0 1 255 {pop /.notdef} for ] def\n" id)
1094 (format "%%%% %s\n" (ps-mule-font-spec-name font-spec))
1095 (format "/F%02X %f %S %d E%02X NBF\n" id size
1096 relative-compose baselie-offset id)))
1097 (setq output-list
1098 (list (list (format "/E%02X [ 0 1 255 { pop 0 } for ] def\n" id))
1099 (list (format "/V%02X [" id))
1100 " ] def\n"
1101 (format "%%%% %s\n" (ps-mule-font-spec-name font-spec))
1102 (format "/F%02X E%02X V%02X NPF\n" id id id))))
1103 (aset ps-mule-bitmap-font-record id
1104 (vector (= bytes 1) output-list
1105 size relative-compose baselie-offset bbx))
1106 (if ps-mule-bitmap-dict-list
1107 output-list
1108 (setq ps-mule-bitmap-dict-list (list "/BitmapDict <<\n" ">> def\n"))
1109 (cons ps-mule-bitmap-dict-list output-list))))
1110
1111(defun ps-mule-generate-bitmap-glyph (font-spec char code bitmap)
1112 (let* ((id (ps-mule-font-spec-id font-spec))
1113 ;; FONT-RECORD ::= ([(SUBFONT-OUTPUT-LIST ...) | t]
1114 ;; BASEFONT-OUTPUT-LIST SIZE REL-COMP B-OFFSET BBX)
1115 (font-record (aref ps-mule-bitmap-font-record id))
1116 enc-name
1117 output-list)
1118 (if (listp (aref font-record 0))
1119 ;; This is a 2-dimensional font. Create a subfont for this
1120 ;; glyph if not yet created.
1121 (let* ((high (/ code 256))
1122 (id2 (+ (* id 256) high)))
1123 (setq output-list (cdr (assq high (aref font-record 0)))
1124 code (% code 256))
1125 (or output-list
1126 ;; We must create a subfont.
1127 (let ((enc-list (car (aref font-record 1)))
1128 (fdep-list (nth 1 (aref font-record 1))))
1129 (setq output-list
1130 (list
1131 (format "/E%04X [ 0 1 255 {pop /.notdef} for ] def\n"
1132 id2)
1133 (format "/F%04X %f %S %d E%04X NBF\n"
1134 id2 (aref font-record 2) (aref font-record 3)
1135 (aref font-record 4) id2)
1136 (format "E%02X %d %d put\n"
1137 id high (1- (length fdep-list)))))
1138 (nconc enc-list (list output-list))
1139 (nconc fdep-list (list (format " F%04X" id2)))
1140 (aset font-record 0
1141 (cons (cons high output-list) (aref font-record 0)))))
1142 (setq enc-name (format "%04X" id2)))
1143 (setq output-list (aref font-record 1)
1144 enc-name (format "%02X" id)))
1145 (setcdr ps-mule-bitmap-dict-list
1146 (cons (format "/C%02X-%X %s\n" id char bitmap)
1147 (cdr ps-mule-bitmap-dict-list)))
1148 (setcdr output-list
1149 (cons (format "E%s %d /C%02X-%X put\n" enc-name code id char)
1150 (cdr output-list))))
1151 nil)
1373 1152
1374;; Mule specific initializers. 1153;; Mule specific initializers.
1375 1154
1376;;;###autoload 1155;;;###autoload
1377(defun ps-mule-initialize () 1156(defun ps-mule-initialize ()
1378 "Initialize global data for printing multi-byte characters." 1157 "Initialize global data for printing multi-byte characters."
1379 (setq ps-mule-font-cache nil 1158 (setq ps-mule-prologue-generated nil
1380 ps-mule-prologue-generated nil
1381 ps-mule-composition-prologue-generated nil 1159 ps-mule-composition-prologue-generated nil
1382 ps-mule-bitmap-prologue-generated nil) 1160 ps-mule-bitmap-prologue-generated nil)
1383 (mapcar `(lambda (x) (setcar (nthcdr 2 x) nil)) 1161 (mapcar `(lambda (x) (setcar (nthcdr 2 x) nil))
1384 ps-mule-external-libraries)) 1162 ps-mule-external-libraries))
1385 1163
1386(defvar ps-mule-header-charsets nil)
1387
1388;;;###autoload
1389(defun ps-mule-encode-header-string (string fonttag) 1164(defun ps-mule-encode-header-string (string fonttag)
1390 "Generate PostScript code for ploting STRING by font FONTTAG. 1165 "Generate PostScript code for ploting STRING by font FONTTAG.
1391FONTTAG should be a string \"/h0\" or \"/h1\"." 1166FONTTAG should be a string \"/h0\", \"/h1\", \"/L0\", or \"/H0\"."
1392 (setq string (cond ((not (stringp string)) 1167 (with-temp-buffer
1393 "") 1168 (insert string)
1394 ((multibyte-string-p string) 1169 (ps-mule-encode-region (point-min) (point-max)
1395 (copy-sequence string)) 1170 (aref ps-mule-font-spec-tables
1396 (t 1171 (aref ps-mule-font-number-to-type
1397 (string-make-multibyte string)))) 1172 (cond ((string= fonttag "/h0") 4)
1398 (when ps-mule-header-charsets 1173 ((string= fonttag "/h1") 5)
1399 (if (eq (car ps-mule-header-charsets) 'latin-iso8859-1) 1174 ((string= fonttag "/L0") 6)
1400 ;; Latin1 characters can be printed by the standard PostScript 1175 (t 0)))))))
1401 ;; font. Converts the other non-ASCII characters to `?'.
1402 (let ((len (length string))
1403 (i 0))
1404 (while (< i len)
1405 (or (memq (char-charset (aref string i)) '(ascii latin-iso8859-1))
1406 (aset string i ??))
1407 (setq i (1+ i)))
1408 (setq string (encode-coding-string string 'iso-latin-1)))
1409 ;; We must prepare a font for the first non-ASCII and non-Latin1
1410 ;; character in STRING.
1411 (let* ((ps-current-font (if (string= fonttag "/h0") 0 1))
1412 (ps-mule-current-charset (car ps-mule-header-charsets))
1413 (font-type (car (nth ps-current-font
1414 (ps-font-alist 'ps-font-for-header))))
1415 (font-spec (ps-mule-get-font-spec ps-mule-current-charset
1416 font-type)))
1417 (if (or (not font-spec)
1418 (/= (charset-dimension ps-mule-current-charset) 1))
1419 ;; We don't have a proper font, or we can't print them on
1420 ;; header because this kind of charset is not ASCII
1421 ;; compatible.
1422 (let ((len (length string))
1423 (i 0))
1424 (while (< i len)
1425 (or (memq (char-charset (aref string i))
1426 '(ascii latin-iso8859-1))
1427 (aset string i ??))
1428 (setq i (1+ i)))
1429 (setq string (encode-coding-string string 'iso-latin-1)))
1430 (let ((charsets (list 'ascii (car ps-mule-header-charsets)))
1431 (len (length string))
1432 (i 0))
1433 (while (< i len)
1434 (or (memq (char-charset (aref string i)) charsets)
1435 (aset string i ??))
1436 (setq i (1+ i))))
1437 (setq string (ps-mule-string-encoding font-spec string nil t))))))
1438 string)
1439
1440;;;###autoload
1441(defun ps-mule-header-string-charsets ()
1442 "Return a list of character sets that appears in header strings."
1443 (let* ((str (ps-header-footer-string))
1444 (len (length str))
1445 (i 0)
1446 charset-list)
1447 (while (< i len)
1448 (let ((charset (char-charset (aref str i))))
1449 (setq i (1+ i))
1450 (or (eq charset 'ascii)
1451 (memq charset charset-list)
1452 (setq charset-list (cons charset charset-list)))))
1453 charset-list))
1454 1176
1455;;;###autoload 1177;;;###autoload
1456(defun ps-mule-begin-job (from to) 1178(defun ps-mule-begin-job (from to)
1457 "Start printing job for multi-byte chars between FROM and TO. 1179 "Start printing job for multi-byte chars between FROM and TO.
1458This checks if all multi-byte characters in the region are printable or not." 1180This checks if all multi-byte characters in the region are printable or not."
1459 (setq ps-mule-charset-list nil 1181 (auto-compose-region from to)
1460 ps-mule-header-charsets nil 1182 (if (and (not (find-composition from to))
1461 ps-mule-font-info-database 1183 (save-excursion
1462 (cond ((eq ps-multibyte-buffer 'non-latin-printer) 1184 (goto-char from)
1463 ps-mule-font-info-database-ps) 1185 (= (skip-chars-forward "\x00-\xFF" to) to)))
1464 ((eq ps-multibyte-buffer 'bdf-font) 1186 ;; All characters can be printed by normal PostScript fonts.
1465 ps-mule-font-info-database-bdf) 1187 (setq ps-basic-plot-string-function 'ps-basic-plot-string
1466 ((eq ps-multibyte-buffer 'bdf-font-except-latin) 1188 ps-encode-header-string-function 'identity)
1467 ps-mule-font-info-database-ps-bdf) 1189 (setq ps-basic-plot-string-function 'ps-mule-plot-string
1468 (t 1190 ps-encode-header-string-function 'ps-mule-encode-header-string
1469 ps-mule-font-info-database-default))) 1191 ps-mule-font-info-database
1470 (and (boundp 'enable-multibyte-characters) 1192 (cond ((eq ps-multibyte-buffer 'non-latin-printer)
1471 enable-multibyte-characters 1193 ps-mule-font-info-database-ps)
1472 ;; Initialize `ps-mule-charset-list'. If some characters aren't 1194 ((eq ps-multibyte-buffer 'bdf-font)
1473 ;; printable, warn it. 1195 ps-mule-font-info-database-bdf)
1474 (let ((charsets (find-charset-region from to))) 1196 ((eq ps-multibyte-buffer 'bdf-font-except-latin)
1475 (setq charsets (delq 'ascii (delq 'unknown (delq nil charsets))) 1197 ps-mule-font-info-database-ps-bdf)
1476 ps-mule-charset-list charsets) 1198 (t
1477 (save-excursion 1199 ps-mule-font-info-database-default)))
1478 (goto-char from) 1200
1479 (and (search-forward "\200" to t) 1201 ;; Be sure to have font information for Latin-1.
1480 (setq ps-mule-charset-list 1202 (or (assq 'iso-8859-1 ps-mule-font-info-database)
1481 (cons 'composition ps-mule-charset-list)))) 1203 (setq ps-mule-font-info-database
1482 ;; We also have to check non-ASCII charsets in the header strings. 1204 (cons '((iso-8859-1 (normal nil nil)))
1483 (let ((tail (ps-mule-header-string-charsets))) 1205 ps-mule-font-info-database)))
1484 (while tail 1206
1485 (unless (eq (car tail) 'ascii) 1207 ;; Generate ps-mule-font-spec-tables.
1486 (setq ps-mule-header-charsets 1208 (let ((font-spec-alist (make-vector 4 nil))
1487 (cons (car tail) ps-mule-header-charsets)) 1209 (id-max 0)
1488 (or (memq (car tail) charsets) 1210 (font-id 0)
1489 (setq charsets (cons (car tail) charsets)))) 1211 font-info-list)
1490 (setq tail (cdr tail)))) 1212 ;; Generate properly ordered font-info-list from
1491 (while charsets 1213 ;; ps-mule-font-info-database.
1492 (setq charsets 1214 (let ((charset-list
1493 (cond 1215 (copy-sequence (get-language-info current-language-environment
1494 ((or (eq (car charsets) 'composition) 1216 'charset))))
1495 (ps-mule-printable-p (car charsets))) 1217 (setq charset-list (cons 'iso-8859-1 (delq 'iso-8859-1 charset-list)))
1496 (cdr charsets)) 1218 (dolist (charset charset-list)
1497 ((y-or-n-p 1219 (let ((font-info (assq charset ps-mule-font-info-database)))
1498 "Font for some characters not found, continue anyway? ") 1220 (and font-info
1499 nil) 1221 (setq font-info-list (cons font-info font-info-list)))))
1500 (t 1222 (dolist (font-info ps-mule-font-info-database)
1501 (error "Printing cancelled"))))))) 1223 (or (memq (car font-info) charset-list)
1502 1224 (setq font-info-list (cons font-info font-info-list))))
1503 (setq ps-mule-current-charset 'ascii) 1225 (setq font-info-list (nreverse font-info-list)))
1504 1226
1505 (if (and (nth 2 (find-composition from to)) 1227 ;; Store FONT-SPECs in each element of font-spec-alist.
1506 (not ps-mule-composition-prologue-generated)) 1228 (dolist (font-info font-info-list)
1507 (progn 1229 (let ((font-spec-vec (make-vector 4 nil))
1508 (ps-mule-prologue-generated) 1230 (charset (car font-info))
1509 (ps-output-prologue ps-mule-composition-prologue) 1231 encoding font-spec)
1510 (setq ps-mule-composition-prologue-generated t))) 1232 (dolist (e (cdr font-info))
1511 1233 (setq encoding (or (nth 3 e) charset)
1512 (if (or ps-mule-charset-list ps-mule-header-charsets) 1234 font-spec (vector id-max charset font-id
1513 (let ((the-list (append ps-mule-header-charsets ps-mule-charset-list)) 1235 (nth 1 e) (nth 2 e) encoding
1514 font-spec elt) 1236 (or (nth 4 e) (charset-dimension encoding))
1515 (ps-mule-prologue-generated) 1237 nil)
1516 ;; If external functions are necessary, generate prologues for them. 1238 id-max (1+ id-max))
1517 (while the-list 1239 (if (ps-mule-check-font font-spec)
1518 (setq elt (car the-list) 1240 (aset font-spec-vec
1519 the-list (cdr the-list)) 1241 (cond ((eq (car e) 'normal) 0)
1520 (cond ((and (eq elt 'composition) 1242 ((eq (car e) 'bold) 1)
1521 (not ps-mule-composition-prologue-generated)) 1243 ((eq (car e) 'italic) 2)
1522 (ps-output-prologue ps-mule-composition-prologue) 1244 (t 3)) font-spec)))
1523 (setq ps-mule-composition-prologue-generated t)) 1245 (when (aref font-spec-vec 0)
1524 ((setq font-spec (ps-mule-get-font-spec elt 'normal)) 1246 (or (aref font-spec-vec 3)
1525 (ps-mule-init-external-library font-spec)))))) 1247 (aset font-spec-vec 3 (or (aref font-spec-vec 1)
1526 1248 (aref font-spec-vec 2)
1527 ;; If ASCII font is also specified in ps-mule-font-info-database, 1249 (aref font-spec-vec 0))))
1528 ;; use it instead of what specified in ps-font-info-database. 1250 (or (aref font-spec-vec 1)
1529 (let ((font-spec (ps-mule-get-font-spec 'ascii 'normal))) 1251 (aset font-spec-vec 1 (aref font-spec-vec 0)))
1530 (if font-spec 1252 (or (aref font-spec-vec 2)
1531 (progn 1253 (aset font-spec-vec 2 (aref font-spec-vec 1)))
1532 (ps-mule-prologue-generated) 1254 (dotimes (i 4)
1533 (ps-mule-init-external-library font-spec) 1255 (aset font-spec-alist i
1534 (let ((font (ps-font-alist 'ps-font-for-text)) 1256 (nconc (aref font-spec-alist i)
1535 (ps-current-font 0)) 1257 (list (cons charset (aref font-spec-vec i))))))
1536 (while font 1258 (setq font-id (1+ font-id)))))
1537 ;; Be sure to download a glyph for SPACE in advance. 1259
1538 (ps-mule-prepare-font (ps-mule-get-font-spec 'ascii (car font)) 1260 ;; Make four FONT-SPEC-TABLEs and set them in
1539 " " 'ascii 'no-setfont) 1261 ;; ps-mule-font-spec-tables. Each char table has one extra slot
1540 (setq font (cdr font) 1262 ;; whose value is an element of font-spec-alist.
1541 ps-current-font (1+ ps-current-font))))))) 1263 (setq ps-mule-font-spec-tables (make-vector 4 nil))
1542 1264 (put 'font-spec-table 'char-table-extra-slots 1)
1543 ;; If the header contains non-ASCII and non-Latin1 characters, prepare a font 1265 (dotimes (i 4)
1544 ;; and glyphs for the first occurrence of such characters. 1266 (let ((table (make-char-table 'font-spec-table)))
1545 (if (and ps-mule-header-charsets 1267 (aset ps-mule-font-spec-tables i table)
1546 (not (eq (car ps-mule-header-charsets) 'latin-iso8859-1))) 1268 (set-char-table-extra-slot table 0 (aref font-spec-alist i))
1547 (let ((font-spec (ps-mule-get-font-spec (car ps-mule-header-charsets) 1269 ;; Be sure to have glyphs for "0123456789/" in advance for
1548 'normal))) 1270 ;; page numbering.
1549 (if font-spec 1271 (let ((str " 0123456789/"))
1550 ;; Be sure to download glyphs for "0123456789/" in advance for page 1272 (dotimes (i (length str))
1551 ;; numbering. 1273 (or (vectorp (ps-mule-get-font-spec (aref str i) table nil))
1552 (let ((ps-current-font 0)) 1274 (error "ASCII font not available")))))))
1553 (ps-mule-prepare-font font-spec "0123456789/" 'ascii t t))))) 1275
1554 1276 (ps-mule-prologue-generated)
1555 (if ps-mule-charset-list 1277 (if (find-composition from to)
1556 ;; We must change this regexp for multi-byte buffer. 1278 (ps-mule-composition-prologue-generated))))
1557 (setq ps-control-or-escape-regexp 1279
1558 (cond ((eq ps-print-control-characters '8-bit) 1280(defun ps-mule-restruct-output-list (list tail)
1559 "[^\040-\176]") 1281 (dolist (elt list)
1560 ((eq ps-print-control-characters 'control-8-bit) 1282 (if (listp elt)
1561 (string-as-multibyte "[^\040-\176\240-\377]")) 1283 (setq tail (ps-mule-restruct-output-list elt tail))
1562 ((eq ps-print-control-characters 'control) 1284 (setcdr tail (cons elt (cdr tail)))
1563 (string-as-multibyte "[^\040-\176\200-\377]")) 1285 (setq tail (cdr tail))))
1564 (t (string-as-multibyte "[^\000-\011\013\015-\377]")))))) 1286 tail)
1287
1288(defun ps-mule-redefine-font (font-number fonttag size ps-font)
1289 (let* ((font-type (aref ps-mule-font-number-to-type font-number))
1290 (font-spec-alist (char-table-extra-slot
1291 (aref ps-mule-font-spec-tables font-type) 0)))
1292 (ps-output-prologue
1293 (list (if (ps-mule-font-spec-src (cdr (car font-spec-alist)))
1294 ;; We ignore a font specfied in ps-font-info-database.
1295 (format "/V%s VTOP%d def\n" fonttag font-type)
1296 (format "/V%s [ VTOP%d aload pop ] def V%s 0 /%s findfont put\n"
1297 fonttag font-type fonttag ps-font))
1298 (format "/%s ETOP%d V%s %f ReDefFont\n"
1299 fonttag font-type fonttag size)))))
1565 1300
1566;;;###autoload
1567(defun ps-mule-begin-page ()
1568 (setq ps-mule-current-charset 'ascii))
1569 1301
1302;;;###autoload
1303(defun ps-mule-end-job ()
1304 "Finish printing job for multi-byte chars."
1305
1306 ;; Prepare root and sub fonts while generating glyphs if necessary.
1307 (let ((output-head (list t))
1308 (ps-mule-output-list (list t)))
1309 (dotimes (i 4)
1310 (map-char-table 'ps-mule-prepare-glyph
1311 (aref ps-mule-font-spec-tables i)))
1312 (ps-mule-restruct-output-list (cdr ps-mule-output-list) output-head)
1313 (ps-output-prologue (cdr output-head)))
1314
1315 ;; Prepare top Encoding and templates of FDepVector.
1316 (dotimes (i 4)
1317 (let ((font-spec-alist (char-table-extra-slot
1318 (aref ps-mule-font-spec-tables i) 0))
1319 font-list font-spec)
1320 (dolist (elt font-spec-alist)
1321 (setq font-spec (cdr elt))
1322 (if (ps-mule-font-spec-extra font-spec)
1323 (push (cons (ps-mule-font-spec-font-id font-spec)
1324 (ps-mule-font-spec-id font-spec))
1325 font-list)))
1326 (setq font-list (nreverse font-list))
1327 (ps-output-prologue
1328 (list (format "/ETOP%d 256 array def\n" i)
1329 (format "0 1 255 { ETOP%d exch 0 put } for\n" i)))
1330 (let ((index 0))
1331 (dolist (font font-list)
1332 (ps-output-prologue (format "ETOP%d %d %d put\n" i (car font) index))
1333 (setq index (1+ index))))
1334 (ps-output-prologue (format "/VTOP%d [%s] def\n" i
1335 (mapconcat #'(lambda (x)
1336 (format "F%02X" (cdr x)))
1337 font-list " ")))))
1338
1339 ;; Redefine fonts f0, f1, f2, f3, h0, h1, H0.
1340 (ps-mule-redefine-font 4 "h0" ps-header-title-font-size-internal
1341 (ps-font 'ps-font-for-header 'bold))
1342 (ps-mule-redefine-font 5 "h1" ps-header-font-size-internal
1343 (ps-font 'ps-font-for-header 'normal))
1344 (ps-mule-redefine-font 6 "H0" ps-footer-font-size-internal
1345 (ps-font 'ps-font-for-footer 'normal))
1346 (let ((font (ps-font-alist 'ps-font-for-text))
1347 (i 0))
1348 (while font
1349 (ps-mule-redefine-font i (format "f%d" i)
1350 ps-font-size-internal
1351 (ps-font 'ps-font-for-text (car (car font))))
1352 (setq font (cdr font)
1353 i (1+ i)))))
1570 1354
1571(provide 'ps-mule) 1355(provide 'ps-mule)
1572 1356