lisp/*.el: Lexical-binding cleanup.
[emacs.git] / lisp / ps-mule.el
blobd95719ba55293c3fad7e333ea2b05e3536fa07cc
1 ;;; ps-mule.el --- provide multi-byte character facility to ps-print
3 ;; Copyright (C) 1998-2011 Free Software Foundation, Inc.
5 ;; Author: Vinicius Jose Latorre <viniciusjl@ig.com.br>
6 ;; Kenichi Handa <handa@m17n.org> (multi-byte characters)
7 ;; Maintainer: Kenichi Handa <handa@m17n.org> (multi-byte characters)
8 ;; Vinicius Jose Latorre <viniciusjl@ig.com.br>
9 ;; Keywords: wp, print, PostScript, multibyte, mule
10 ;; Package: ps-print
12 ;; This file is part of GNU Emacs.
14 ;; GNU Emacs is free software: you can redistribute it and/or modify
15 ;; it under the terms of the GNU General Public License as published by
16 ;; the Free Software Foundation, either version 3 of the License, or
17 ;; (at your option) any later version.
19 ;; GNU Emacs is distributed in the hope that it will be useful,
20 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
21 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 ;; GNU General Public License for more details.
24 ;; You should have received a copy of the GNU General Public License
25 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
27 ;;; Commentary:
29 ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
31 ;; About ps-mule
32 ;; -------------
34 ;; This package is used for ps-print to print multi-byte buffer.
36 ;; See also ps-print.el.
39 ;; Printing Multi-byte Buffer
40 ;; --------------------------
42 ;; The variable `ps-multibyte-buffer' specifies the ps-print multi-byte buffer
43 ;; handling.
45 ;; Valid values for `ps-multibyte-buffer' are:
47 ;; nil This is the value to use the default settings;
48 ;; by default, this only works to print buffers with
49 ;; only ASCII and Latin characters. But this default
50 ;; setting can be changed by setting the variable
51 ;; `ps-mule-font-info-database-default' differently.
52 ;; The initial value of this variable is
53 ;; `ps-mule-font-info-database-latin' (see
54 ;; documentation).
56 ;; `non-latin-printer' This is the value to use when you have a japanese
57 ;; or korean PostScript printer and want to print
58 ;; buffer with ASCII, Latin-1, Japanese (JISX0208 and
59 ;; JISX0201-Kana) and Korean characters. At present,
60 ;; it was not tested with the Korean characters
61 ;; printing. If you have a korean PostScript printer,
62 ;; please, test it.
64 ;; `bdf-font' This is the value to use when you want to print
65 ;; buffer with BDF fonts. BDF fonts include both latin
66 ;; and non-latin fonts. BDF (Bitmap Distribution
67 ;; Format) is a format used for distributing X's font
68 ;; source file. BDF fonts are included in
69 ;; `intlfonts-1.2' which is a collection of X11 fonts
70 ;; for all characters supported by Emacs. In order to
71 ;; use this value, be sure to have installed
72 ;; `intlfonts-1.2' and set the variable
73 ;; `bdf-directory-list' appropriately (see ps-bdf.el
74 ;; for documentation of this variable).
76 ;; `bdf-font-except-latin' This is like `bdf-font' except that it uses
77 ;; PostScript default fonts to print ASCII and Latin-1
78 ;; characters. This is convenient when you want or
79 ;; need to use both latin and non-latin characters on
80 ;; the same buffer. See `ps-font-family',
81 ;; `ps-header-font-family' and `ps-font-info-database'.
83 ;; Any other value is treated as nil.
85 ;; The default is nil.
87 ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
89 ;;; Code:
91 (require 'ps-print)
94 ;;;###autoload
95 (defcustom ps-multibyte-buffer nil
96 "Specifies the multi-byte buffer handling.
98 Valid values are:
100 nil This is the value to use the default settings;
101 by default, this only works to print buffers with
102 only ASCII and Latin characters. But this default
103 setting can be changed by setting the variable
104 `ps-mule-font-info-database-default' differently.
105 The initial value of this variable is
106 `ps-mule-font-info-database-latin' (see
107 documentation).
109 `non-latin-printer' This is the value to use when you have a Japanese
110 or Korean PostScript printer and want to print
111 buffer with ASCII, Latin-1, Japanese (JISX0208 and
112 JISX0201-Kana) and Korean characters. At present,
113 it was not tested with the Korean characters
114 printing. If you have a korean PostScript printer,
115 please, test it.
117 `bdf-font' This is the value to use when you want to print
118 buffer with BDF fonts. BDF fonts include both latin
119 and non-latin fonts. BDF (Bitmap Distribution
120 Format) is a format used for distributing X's font
121 source file. BDF fonts are included in
122 `intlfonts-1.2' which is a collection of X11 fonts
123 for all characters supported by Emacs. In order to
124 use this value, be sure to have installed
125 `intlfonts-1.2' and set the variable
126 `bdf-directory-list' appropriately (see ps-bdf.el for
127 documentation of this variable).
129 `bdf-font-except-latin' This is like `bdf-font' except that it uses
130 PostScript default fonts to print ASCII and Latin-1
131 characters. This is convenient when you want or
132 need to use both latin and non-latin characters on
133 the same buffer. See `ps-font-family',
134 `ps-header-font-family' and `ps-font-info-database'.
136 Any other value is treated as nil."
137 :type '(choice (const non-latin-printer) (const bdf-font)
138 (const bdf-font-except-latin) (const :tag "nil" nil))
139 :group 'ps-print-font)
141 (defvar ps-mule-font-info-database
143 "Alist of charsets with the corresponding font information.
144 Each element has the form:
146 (CHARSET (FONT-TYPE FONT-SRC FONT-NAME ENCODING BYTES) ...)
148 Where
150 CHARSET is a charset (symbol) for this font family,
152 FONT-TYPE is a font type: normal, bold, italic, or bold-italic.
154 FONT-SRC is a font source: builtin, bdf, vflib, or nil.
156 If FONT-SRC is builtin, FONT-NAME is a built-in PostScript font name.
158 If FONT-SRC is bdf, FONT-NAME is a BDF font file name, or a list of
159 alternative font names. To use this font, the external library `ps-bdf'
160 is required.
162 If FONT-SRC is vflib, FONT-NAME is the name of a font that VFlib knows.
163 To use this font, the external library `vflib' is required.
165 If FONT-SRC is nil, a proper ASCII font in the variable
166 `ps-font-info-database' is used. This is useful for Latin-1 characters.
168 ENCODING is a coding system to encode a string of characters of CHARSET into a
169 proper string matching an encoding of the specified font. ENCODING may be a
170 function that does this encoding. In this case, the function is called with
171 one argument, the string to encode, and it should return an encoded string.
173 BYTES specifies how many bytes each character has in the encoded byte
174 sequence; it should be 1 or 2.
176 All multi-byte characters are printed by fonts specified in this database
177 regardless of a font family of ASCII characters. The exception is Latin-1
178 characters which are printed by the same font as ASCII characters, thus obey
179 font family.
181 See also the variable `ps-font-info-database'.")
183 (defconst ps-mule-font-info-database-latin
184 '((iso-8859-1
185 (normal nil nil)))
186 "Sample setting of `ps-mule-font-info-database' to use latin fonts.")
188 (defcustom ps-mule-font-info-database-default
189 ps-mule-font-info-database-latin
190 "The default setting to use when `ps-multibyte-buffer' is nil."
191 :type '(symbol :tag "Multi-Byte Buffer Database Font Default")
192 :group 'ps-print-font)
194 (defconst ps-mule-font-info-database-ps
195 '((katakana-jisx0201
196 (normal builtin "Ryumin-Light.Katakana")
197 (bold builtin "GothicBBB-Medium.Katakana")
198 (bold-italic builtin "GothicBBB-Medium.Katakana"))
199 (latin-jisx0201
200 (normal builtin "Ryumin-Light.Hankaku")
201 (bold builtin "GothicBBB-Medium.Hankaku"))
202 (japanese-jisx0208
203 (normal builtin "Ryumin-Light-H")
204 (bold builtin "GothicBBB-Medium-H"))
205 (korean-ksc5601
206 (normal builtin "Munhwa-Regular-KSC-EUC-H")
207 (bold builtin "Munhwa-Bold-KSC-EUC-H"))
209 "Sample setting of the `ps-mule-font-info-database' to use builtin PS font.
211 Currently, data for Japanese and Korean PostScript printers are listed.")
213 (defconst ps-mule-font-info-database-bdf
214 '((iso-8859-1
215 (normal bdf ("lt1-24-etl.bdf" "etl24-latin1.bdf"))
216 (bold bdf ("lt1-16b-etl.bdf" "etl16b-latin1.bdf"))
217 (italic bdf ("lt1-16i-etl.bdf" "etl16i-latin1.bdf"))
218 (bold-italic bdf ("lt1-16bi-etl.bdf" "etl16bi-latin1.bdf")))
219 (iso-8859-2
220 (normal bdf ("lt2-24-etl.bdf" "etl24-latin2.bdf")))
221 (iso-8859-3
222 (normal bdf ("lt3-24-etl.bdf" "etl24-latin3.bdf")))
223 (iso-8859-4
224 (normal bdf ("lt4-24-etl.bdf" "etl24-latin4.bdf")))
225 (thai-tis620
226 (normal bdf ("thai24.bdf" "thai-24.bdf") iso-8859-11))
227 (greek-iso8859-7
228 (normal bdf ("grk24-etl.bdf" "etl24-greek.bdf") iso-8859-7))
229 (hebrew-iso8859-8
230 (normal bdf ("heb24-etl.bdf" "etl24-hebrew.bdf") iso-8859-8))
231 (jisx0201
232 (normal bdf "12x24rk.bdf" jisx0201))
233 (cyrillic-iso8859-5
234 (normal bdf ("cyr24-etl.bdf" "etl24-cyrillic.bdf") iso-8859-5))
235 (iso-8859-9
236 (normal bdf ("lt5-24-etl.bdf" "etl24-latin5.bdf") iso-8859-9))
237 (chinese-gb2312
238 (normal bdf "gb24st.bdf"))
239 (japanese-jisx0208
240 (normal bdf "jiskan24.bdf"))
241 (korean-ksc5601
242 (normal bdf "hanglm24.bdf"))
243 (japanese-jisx0212
244 (normal bdf ("jksp40.bdf" "jisksp40.bdf")))
245 (chinese-cns11643-1
246 (normal bdf ("cns1-40.bdf" "cns-1-40.bdf")))
247 (chinese-cns11643-2
248 (normal bdf ("cns2-40.bdf" "cns-2-40.bdf")))
249 (big5
250 (normal bdf "taipei24.bdf"))
251 (chinese-sisheng
252 (normal bdf ("sish24-etl.bdf" "etl24-sisheng.bdf")))
253 (ipa
254 (normal bdf ("ipa24-etl.bdf" "etl24-ipa.bdf") ipa))
255 (viscii
256 (normal bdf ("visc24-etl.bdf" "etl24-viscii.bdf")))
257 (arabic-digit
258 (normal bdf ("arab24-0-etl.bdf" "etl24-arabic0.bdf")))
259 (arabic-1-column
260 (normal bdf ("arab24-1-etl.bdf" "etl24-arabic1.bdf")))
261 (lao
262 (normal bdf ("lao24-mule.bdf" "mule-lao-24.bdf") ps-mule-encode-lao 1))
263 (arabic-2-column
264 (normal bdf ("arab24-2-etl.bdf" "etl24-arabic2.bdf")))
265 (devanagari-cdac
266 (normal bdf "dvsr0ntt-32.bdf"))
267 (malayalam-cdac
268 (normal bdf "mlkr0ntt-32.bdf"))
269 (tamil-cdac
270 (normal bdf "tmvl0ntt-32.bdf"))
271 (indian-is13194
272 (normal bdf ("isci24-mule.bdf" "mule-iscii-24.bdf")))
273 (indian-1-column
274 (normal bdf ("ind1c24-mule.bdf" "mule-indian-1col-24.bdf")))
275 (ethiopic
276 (normal bdf ("ethio16f-uni.bdf" "ethiomx24f-uni.bdf") unicode-bmp))
277 (chinese-cns11643-3
278 (normal bdf ("cns3-40.bdf" "cns-3-40.bdf")))
279 (chinese-cns11643-4
280 (normal bdf ("cns4-40.bdf" "cns-4-40.bdf")))
281 (chinese-cns11643-5
282 (normal bdf ("cns5-40.bdf" "cns-5-40.bdf")))
283 (chinese-cns11643-6
284 (normal bdf ("cns6-40.bdf" "cns-6-40.bdf")))
285 (chinese-cns11643-7
286 (normal bdf ("cns7-40.bdf" "cns-7-40.bdf")))
287 (indian-2-column
288 (normal bdf ("ind24-mule.bdf" "mule-indian-24.bdf")))
289 (tibetan
290 (normal bdf ("tib24p-mule.bdf" "tib24-mule.bdf" "mule-tibmdx-24.bdf")))
291 (unicode-bmp
292 (normal bdf "etl24-unicode.bdf"))
294 "Sample setting of the `ps-mule-font-info-database' to use BDF fonts.
295 BDF (Bitmap Distribution Format) is a format used for distributing X's font
296 source file.
298 Current default value list for BDF fonts is included in `intlfonts-1.2'
299 which is a collection of X11 fonts for all characters supported by Emacs.
301 Using this list as default value to `ps-mule-font-info-database', all
302 characters including ASCII and Latin-1 are printed by BDF fonts.
304 See also `ps-mule-font-info-database-ps-bdf'.")
306 (defconst ps-mule-font-info-database-ps-bdf
307 (cons (car ps-mule-font-info-database-latin)
308 (cdr (cdr ps-mule-font-info-database-bdf)))
309 "Sample setting of the `ps-mule-font-info-database' to use BDF fonts.
311 Current default value list for BDF fonts is included in `intlfonts-1.2'
312 which is a collection of X11 fonts for all characters supported by Emacs.
314 Using this list as default value to `ps-mule-font-info-database', all
315 characters except ASCII and Latin-1 characters are printed with BDF fonts.
316 ASCII and Latin-1 characters are printed with PostScript font specified
317 by `ps-font-family' and `ps-header-font-family'.
319 See also `ps-mule-font-info-database-bdf'.")
321 ;; Functions to access each element of FONT-SPEC.
323 ;; FONT-SPEC is a vector of this form:
324 ;; [ID CHARSET FONT-ID FONT-SRC FONT-NAME ENCODING BYTES EXTRA-DATA]
325 ;; Where
327 ;; ID is an identification number for this FONT-SPEC and is unique in the list.
329 ;; CHARSET, FONT-SRC, FONT-NAME, ENCODING, and BYTES are the same as those in
330 ;; `ps-mule-font-info-database' (which see).
332 ;; EXTRA-DATA is a data attached by external libraries.
334 (defsubst ps-mule-font-spec-id (font-spec) (aref font-spec 0))
335 (defsubst ps-mule-font-spec-charset (font-spec) (aref font-spec 1))
336 (defsubst ps-mule-font-spec-font-id (font-spec) (aref font-spec 2))
337 (defsubst ps-mule-font-spec-src (font-spec) (aref font-spec 3))
338 (defsubst ps-mule-font-spec-name (font-spec) (aref font-spec 4))
339 (defsubst ps-mule-font-spec-set-name (font-spec name)
340 (aset font-spec 4 name))
341 (defsubst ps-mule-font-spec-encoding (font-spec) (aref font-spec 5))
342 (defsubst ps-mule-font-spec-bytes (font-spec) (aref font-spec 6))
343 (defsubst ps-mule-font-spec-extra (font-spec) (aref font-spec 7))
344 (defsubst ps-mule-font-spec-set-extra (font-spec extra)
345 (aset font-spec 7 extra))
347 ;; Functions to encode character into glyph code.
348 (defun ps-mule-encode-lao (char)
349 (- char #x0DE0))
351 (defun ps-mule-encode-char (char font-spec)
352 (let ((encoding (ps-mule-font-spec-encoding font-spec)))
353 (cond ((charsetp encoding)
354 (encode-char char encoding))
355 ((fboundp encoding)
356 (funcall encoding char))
358 char))))
360 ;; Array of FONT-SPEC-TABLEs; Nth element is for FONT-TYPE N.
362 ;; FONT-TYPE is 0, 1, 2, or 3 representing normal, bold, italic, and
363 ;; bold-italic respectively.
365 ;; FONT-SPEC-TABLE is a char-table of FONT-SPECs. It records which
366 ;; character is printed by which FONT-SPEC. It has one extra slot
367 ;; whose value is an alist of the form:
368 ;; (CHARSET . FONT-SPEC)
369 ;; FONT-SPEC is a vecotr of the form:
370 ;; (ID FONT-SRC FONT-NAME ENCODING EXTRA)
371 (defvar ps-mule-font-spec-tables nil)
373 ;; Array of FONT-TYPEs; Nth element FONT-NUMBER N.
375 ;; FONT-NUMBER is 0, 1, 2, 3, 4, 5, 6 representing fonts f0, f1, f2,
376 ;; f3, h0, h1, and H0.
377 (defconst ps-mule-font-number-to-type [ 0 1 2 3 1 0 0 ])
379 (defsubst ps-mule-get-font-spec (char font-spec-table font-spec)
380 "Return a font spec for printing CHAR with FONT-SPEC-TABLE.
382 FONT-SPEC, if non-nil, is a font spec to try at first.
384 See the documentation of `ps-mule-font-spec-tables' for the
385 format of font spec."
387 (or (aref font-spec-table char)
388 (aset font-spec-table char
389 (or (and (< char 256)
390 (cdr (car (char-table-extra-slot font-spec-table 0))))
391 (and font-spec
392 (encode-char char (ps-mule-font-spec-charset font-spec))
393 font-spec)
394 (catch 'tag
395 (dolist (elt (char-table-extra-slot font-spec-table 0))
396 (and (encode-char char (car elt))
397 (throw 'tag (cdr elt)))))
398 ;; Record that no font-spec exist for CHAR.
399 t))))
401 (defconst ps-mule-external-libraries
402 '((builtin nil nil nil
403 nil nil nil)
404 (bdf ps-bdf nil bdf-generate-prologue
405 bdf-check-font bdf-generate-font bdf-generate-glyph)
406 (pcf nil nil pcf-generate-prologue
407 pcf-check-font pcf-generate-font pcf-generate-glyph)
408 (vflib nil nil vflib-generate-prologue
409 vflib-check-font vflib-generate-font vflib-generate-glyphs))
410 "Alist of external libraries information to support PostScript printing.
411 Each element has the form:
413 (FONT-SRC FEATURE INITIALIZED-P PROLOGUE-FUNC
414 CHECK-FUNC FONT-FUNC GLYPH-FUNC)
416 FONT-SRC is the font source: builtin, bdf, pcf, or vflib.
418 FEATURE is the feature that provide a facility to handle FONT-SRC. Except for
419 `builtin' FONT-SRC, this feature is automatically `require'd before handling
420 FONT-SRC. Currently, we only have the feature `ps-bdf'.
422 INITIALIZED-P indicates if this library is initialized or not.
424 PROLOGUE-FUNC is a function to generate PostScript code which define several
425 PostScript procedures that will be called by FONT-FUNC and GLYPHS-FUNC. It is
426 called with no argument, and should return a list of strings.
428 CHECK-FUNC is a function to check if a font is available or not.
429 It is called with one argument FONT-SPEC, and should return non-nil if and
430 only if the font specified in FONT-SPEC is available.
432 FONT-FUNC is a function to generate PostScript code which define a new font.
433 It is called with one argument FONT-SPEC, and should return a list of strings.
435 GLYPH-FUNC is a function to generate PostScript code which define glyphs of
436 characters. It is called with two arguments FONT-SPEC and CODE, and should
437 return a list of strings.")
439 (defsubst ps-mule-exlib-feature (exlib) (nth 1 exlib))
440 (defsubst ps-mule-exlib-initialized-p (exlib) (nth 2 exlib))
441 (defsubst ps-mule-exlib-set-initialized-p (exlib val)
442 (setcar (nthcdr 2 exlib) val))
443 (defsubst ps-mule-exlib-prologue (exlib) (nth 3 exlib))
444 (defsubst ps-mule-exlib-check (exlib) (nth 4 exlib))
445 (defsubst ps-mule-exlib-font (exlib) (nth 5 exlib))
446 (defsubst ps-mule-exlib-glyph (exlib) (nth 6 exlib))
448 (defun ps-mule-init-external-library (exlib)
449 "Initialize external library specified by EXLIB for PostScript printing.
450 See the documentation of `ps-mule-external-libraries' for EXLIB's meaning."
451 (or (ps-mule-exlib-initialized-p exlib)
452 (let ((prologue-func (ps-mule-exlib-prologue exlib)))
453 (if prologue-func
454 (let ((feature (ps-mule-exlib-feature exlib)))
455 (if feature
456 (require feature))
457 (ps-output-prologue (funcall prologue-func))))
458 (ps-mule-exlib-set-initialized-p exlib t))))
460 (defvar ps-mule-output-list nil)
462 (defun ps-mule-check-font (font-spec)
463 "Check if a font specified in FONT-SPEC is available or not."
464 (let ((font-src (ps-mule-font-spec-src font-spec)))
465 (or (not font-src)
466 (let ((exlib (assq font-src ps-mule-external-libraries)))
467 (ps-mule-init-external-library exlib)
468 (or (not (ps-mule-exlib-check exlib))
469 (funcall (ps-mule-exlib-check exlib) font-spec))))))
471 (defun ps-mule-prepare-font (font-spec)
472 "Generate PostScript codes defining a new font of FONT-SPEC for charset."
473 (let* ((font-src (ps-mule-font-spec-src font-spec))
474 (exlib (assq font-src ps-mule-external-libraries))
475 (id (ps-mule-font-spec-id font-spec))
476 (ftag (format "%02X" id))
477 (font-func (ps-mule-exlib-font exlib))
478 output-list)
479 (if font-func
480 (setq output-list (funcall font-func font-spec))
481 (setq output-list
482 (format "/F%s /%s findfont def\n"
483 ftag (or (ps-mule-font-spec-name font-spec) "Courier")))
484 (ps-mule-font-spec-set-extra font-spec t))
485 (and output-list
486 (nconc ps-mule-output-list (list output-list)))))
488 (defun ps-mule-prepare-glyph (char font-spec)
489 "Generate PostScript codes to print CHAR by FONT-SPEC.
491 If CHAR is a cons (FROM TO), generate codes for characters
492 specified by the character code range FROM and TO.
494 The generated code is inserted on prologue part."
495 (if (vectorp font-spec)
496 (progn
497 (or (ps-mule-font-spec-extra font-spec)
498 (ps-mule-prepare-font font-spec))
499 (let ((glyph-func (ps-mule-exlib-glyph
500 (assq (ps-mule-font-spec-src font-spec)
501 ps-mule-external-libraries))))
502 (if glyph-func
503 (let (from to output-list)
504 (if (consp char)
505 (setq from (car char) to (cdr char))
506 (setq from char to char))
507 (while (<= from to)
508 (setq output-list
509 (funcall glyph-func font-spec from))
510 (and output-list
511 (ps-output-prologue output-list))
512 (setq from (1+ from)))))))))
514 ;; This is a PostScript code inserted in the header of generated PostScript.
515 (defconst ps-mule-prologue
516 "%%%% Start of Mule Section
518 /Latin1Encoding { % newname fontname | font
519 findfont dup length dict begin
520 { 1 index /FID ne { def } { pop pop } ifelse } forall
521 /Encoding ISOLatin1Encoding def
522 currentdict
524 definefont
525 } bind def
527 %% Redefine fonts for multiple charsets.
528 /ReDefFont { % fontname encoding fdepvector size | -
529 20 dict begin
530 3 index findfont {
531 1 index /FID ne 2 index /UniqueID ne and {def} {pop pop} ifelse
532 } forall
533 /FontType 0 def
534 /FMapType 3 def
535 /EscChar 0 def
536 % FontMatrix ::= [ size 0 0 size 0 0 ]
537 /FontMatrix exch [ exch dup 0 exch 0 exch 0 0 ] def
538 /FDepVector exch def
539 /Encoding exch def
540 currentdict
541 end % fontname dic
542 definefont pop
543 } bind def
545 "PostScript code for printing multi-byte characters.")
547 (defvar ps-mule-prologue-generated nil)
549 ;; EscChar used in generated composite fonts.
550 (defconst ps-mule-esc-char 0)
552 (defun ps-mule-prologue-generated ()
553 (unless ps-mule-prologue-generated
554 (ps-output-prologue ps-mule-prologue)
555 (ps-output-prologue
556 (format "\n/EscChar %d def\n\n%%%% End of Mule Section\n\n"
557 ps-mule-esc-char))
558 (setq ps-mule-prologue-generated t)))
560 (defun ps-mule-encode-region (from to font-spec-table)
561 "Generate PostScript code for plotting characters in the region FROM and TO.
563 FONT-SPEC-TABLE is 0, 1, 2, 3, 4, 5, or 6, each represents font tags f0, f1,
564 f2, f3, h0, h1, and H0 respectively."
565 (let* ((font-spec nil)
566 (font-id 0)
567 (code-list nil))
568 (goto-char from)
569 (while (< (point) to)
570 (let* ((char (following-char))
571 (this-spec (ps-mule-get-font-spec char font-spec-table font-spec))
572 this-id)
573 (if (vectorp this-spec)
574 (setq this-id (ps-mule-font-spec-font-id this-spec))
575 ;; Can't print CHAR. Replace it with '?'.
576 (setq char ??
577 this-spec (ps-mule-get-font-spec char font-spec-table nil)
578 this-id (ps-mule-font-spec-font-id this-spec)))
579 (unless (= font-id this-id)
580 (setq font-id this-id)
581 (push ps-mule-esc-char code-list)
582 (push font-id code-list))
583 (setq font-spec this-spec)
584 (if (< char 128)
585 (push char code-list)
586 (let* ((code (ps-mule-encode-char char font-spec)))
587 (if (= (ps-mule-font-spec-bytes font-spec) 1)
588 (push code code-list)
589 (push (/ code 256) code-list)
590 (push (% code 256) code-list))))
591 (forward-char 1)))
592 (apply 'unibyte-string (nreverse code-list))))
594 (defun ps-mule-plot-composition (composition font-spec-table)
595 "Generate PostScript code for plotting COMPOSITION with FONT-SPEC-TABLE."
596 (ps-output "[")
597 (let ((components (copy-sequence (nth 2 composition)))
598 (font-spec nil))
599 (dotimes (i (length components))
600 (let ((elt (aref components i))
601 this-spec)
602 (if (consp elt)
603 ;; ELT is a composition rule.
604 (ps-output (format " %d" (encode-composition-rule elt)))
605 ;; ELT is a glyph character.
606 (setq this-spec
607 (ps-mule-get-font-spec elt font-spec-table font-spec))
608 (or (vectorp this-spec)
609 ;; Can't print CHAR. Replace it with '?'.
610 (setq elt ??
611 this-spec
612 (ps-mule-get-font-spec elt font-spec-table font-spec)))
613 (setq font-spec this-spec)
614 (let* ((bytes (ps-mule-font-spec-bytes font-spec))
615 (code (ps-mule-encode-char elt font-spec))
616 (font-id (ps-mule-font-spec-font-id font-spec))
617 (str (make-string (if (= font-id 0) 1 (+ 2 bytes)) 0)))
618 (if (= font-id 0)
619 (aset str 0 code)
620 (aset str 0 ps-mule-esc-char)
621 (aset str 1 font-id)
622 (if (= bytes 1)
623 (aset str 2 code)
624 (aset str 2 (/ code 256))
625 (aset str 3 (% code 256))))
626 (ps-output "[")
627 (ps-output-string str)
628 (ps-output (if (eq (ps-mule-font-spec-src font-spec) 'bdf)
629 (format "/C%02X-%X" (ps-mule-font-spec-id font-spec)
630 elt)
631 "false"))
632 (ps-output "]"))))))
633 (ps-output " ] " (if (nth 3 composition) "RLC" "RBC") "\n"))
635 (defun ps-mule-plot-string (from to &optional _bg-color)
636 "Generate PostScript code for plotting characters in the region FROM and TO.
638 Optional argument BG-COLOR is ignored.
640 Returns the value:
642 (ENDPOS . RUN-WIDTH)
644 Where ENDPOS is the end position of the sequence and RUN-WIDTH is the width of
645 the sequence."
646 (let* ((average-width (ps-avg-char-width 'ps-font-for-text))
647 (point (point))
648 (composition (find-composition from to nil t))
649 (stop (if (and composition
650 (not (vectorp (aref (nth 2 composition) 0))))
651 (car composition)
652 to))
653 (ascii-or-latin-1 "[\000-\377]+")
654 (run-width 0)
655 (endpos nil)
656 (font-spec-table (aref ps-mule-font-spec-tables
657 (aref ps-mule-font-number-to-type
658 ps-current-font)))
659 width)
660 (goto-char from)
661 (while (not endpos)
662 (cond ((= (point) stop)
663 (if (= stop to)
664 (setq endpos stop)
665 (when (< from stop)
666 (ps-output-string (ps-mule-encode-region from (point)
667 font-spec-table))
668 (ps-output " S\n"))
669 (setq width (* (nth 5 composition) average-width))
670 (if (< ps-width-remaining (+ run-width width))
671 (setq endpos stop)
672 (ps-mule-plot-composition composition font-spec-table)
673 (setq run-width (+ run-width width)
674 from (nth 1 composition))
675 (goto-char from)
676 (setq composition (find-composition (point) to nil t))
677 (setq stop (if composition (car composition) to)))))
679 ((looking-at ascii-or-latin-1)
680 (let ((nchars (- (min (match-end 0) stop) (point))))
681 (setq width (* average-width nchars))
682 (if (< ps-width-remaining (+ run-width width))
683 (setq nchars (truncate (- ps-width-remaining run-width)
684 average-width)
685 run-width (+ run-width (* nchars average-width))
686 endpos (+ (point) nchars))
687 (setq run-width (+ run-width width))
688 (forward-char nchars))))
691 (while (and (< (point) stop) (not endpos))
692 (setq width (char-width (following-char)))
693 (if (< ps-width-remaining (+ run-width width))
694 (setq endpos (point))
695 (setq run-width (+ run-width width))
696 (forward-char 1))))))
698 (when (< from endpos)
699 (ps-output-string (ps-mule-encode-region from endpos font-spec-table))
700 (ps-output " S\n"))
701 (goto-char point)
702 (cons endpos run-width)))
704 ;; Character composition support
706 (defvar ps-mule-composition-prologue-generated nil)
708 (defconst ps-mule-composition-prologue
709 "%%%% Procedures for character composition.
710 /RelativeCompositionSkip 0.4 def
712 %% Get a bounding box (relative to currentpoint) of STR.
713 /GetPathBox { % [ str cname ] | -
714 dup 1 get dup false ne {
715 BitmapDict exch get /bmp exch def
716 %% bmp ::= [ DWIDTH WIDTH HEIGHT XOFF YOFF BITMAP RELATIVE-COMPOSE]
717 /LLY bmp 4 get def
718 /URY LLY bmp 2 get add def
719 /RelativeCompose bmp 6 get dup false ne {
720 dup LLY le { pop 1 } { URY ge { -1 } { 0 } ifelse } ifelse
722 pop 0
723 } ifelse def
724 dup 0 get stringwidth pop dup /WIDTH exch def bmp 0 get div
725 dup LLY mul /LLY exch def
726 URY mul /URY exch def
729 dup 0 get stringwidth pop /WIDTH exch def
730 gsave 0 0 moveto
731 dup 0 get false charpath flattenpath pathbbox
732 /URY exch def pop /LLY exch def pop
733 grestore
734 /RelativeCompose 0 def
735 } ifelse
736 } bind def
738 %% Apply effects except for shadow and outline to the rectangle
739 %% specified by TOP BOTTOM LEFT RIGHT.
740 /SpecialEffect { % -- | --
741 currentpoint dup TOP add /yy exch def BOTTOM add /YY exch def
742 dup LEFT add /xx exch def RIGHT add /XX exch def
743 %% Adjust positions for future shadowing.
744 Effect 8 and 0 ne {
745 /yy yy Yshadow add def
746 /XX XX Xshadow add def
747 } if
748 Effect 1 and 0 ne { UnderlinePosition Hline } if % underline
749 Effect 2 and 0 ne { StrikeoutPosition Hline } if % strikeout
750 Effect 4 and 0 ne { OverlinePosition Hline } if % overline
751 bg { % background
752 true
753 Effect 16 and 0 ne {SpaceBackground doBox} { xx yy XX YY doRect} ifelse
754 } if
755 Effect 16 and 0 ne { false 0 doBox } if % box
756 } def
758 %% Draw COMPONENTS which has the form [ [str0 xoff0 yoff0] ... ] with
759 %% effects shadow and outline.
760 /ShowComponents { % components | -
761 gsave
762 { gsave aload pop rmoveto
763 Effect 8 and 0 ne { dup doShadow } if
764 Effect 32 and 0 ne { true doOutline } { show } ifelse
765 grestore
766 } forall
767 grestore
768 RIGHT 0 rmoveto
769 } def
771 %% Show relative composition.
772 /RLC { % [[str0 cname0] [str1 cname1] ... [strN cnameN]] | -
773 /components exch def
774 [ % push [str xoff yoff] one by one
775 [ components 0 get GetPathBox aload pop pop 0 0 ]
776 %% Bounding box of overall glyphs.
777 /LEFT 0 def
778 /RIGHT WIDTH def
779 /TOP URY def
780 /BOTTOM LLY def
782 1 1 components length 1 sub {
783 components exch get
784 [ exch
785 GetPathBox
786 aload pop pop % str
787 0 % xoff
788 RelativeCompose 1 eq { % compose on TOP
789 TOP LLY sub RelativeCompositionSkip add % yoff
790 /TOP TOP URY LLY sub add RelativeCompositionSkip add def
791 } { RelativeCompose -1 eq { % compose under BOTTOM
792 BOTTOM URY sub RelativeCompositionSkip sub % yoff
793 /BOTTOM BOTTOM URY LLY sub sub
794 RelativeCompositionSkip sub def
796 0 % yoff
797 URY TOP gt { /TOP URY def } if
798 LLY BOTTOM lt { /BOTTOM LLY def } if
799 } ifelse } ifelse
801 } for
803 SpecialEffect % Reflect special effects.
804 ShowComponents % Draw components.
805 } def
807 %% Show rule-base composition.
808 /RBC { % [[str0 cname0] rule1 [str1 cname0] rule2 ... [strN cnameN]] | -
809 /components exch def
810 [ % push [str xoff yoff] one by one
811 [ components 0 get GetPathBox aload pop pop 0 0 ]
812 %% Bounding box of overall glyphs.
813 /LEFT 0 def
814 /RIGHT WIDTH def
815 /TOP URY def
816 /BOTTOM LLY def
817 1 1 components length 1 sub {
818 components exch get /elt exch def
819 elt type /integertype eq { % rule
820 %% Do the same RULE decoding as the macro
821 %% COMPOSITION_DECODE_RULE in emacs/src/composite.h.
822 elt 12 idiv dup 3 mod /grefx exch def 3 idiv /grefy exch def
823 elt 12 mod dup 3 mod /nrefx exch def 3 idiv /nrefy exch def
824 } { % other strings
826 elt GetPathBox
827 aload pop pop
828 /height URY LLY sub def
829 /left LEFT [ 0 RIGHT LEFT sub dup 2 div exch ] grefx get add
830 [ 0 WIDTH 2 div WIDTH ] nrefx get sub def
831 /bottom [ TOP 0 BOTTOM TOP BOTTOM add 2 div ] grefy get
832 [ height LLY neg 0 height 2 div ] nrefy get sub def
833 %% Update bounding box
834 left LEFT lt { /LEFT left def } if
835 left WIDTH add RIGHT gt { /RIGHT left WIDTH add def } if
836 bottom BOTTOM lt { /BOTTOM bottom def } if
837 bottom height add TOP gt { /TOP bottom height add def } if
838 left bottom LLY sub ]
839 } ifelse
840 } for
843 LEFT 0 lt { % Adjust xoff to the right.
844 dup { dup 1 get LEFT sub 1 exch put } forall
845 /RIGHT RIGHT LEFT sub def
846 } if
848 SpecialEffect % Reflect special effects.
849 ShowComponents % Draw components.
850 } def
852 %%%% End of procedures for character composition
854 "PostScript code for printing character composition.")
856 (defun ps-mule-composition-prologue-generated ()
857 (unless ps-mule-composition-prologue-generated
858 (ps-mule-prologue-generated)
859 (ps-output-prologue ps-mule-composition-prologue)
860 (setq ps-mule-composition-prologue-generated t)))
862 ;; Bitmap font support
864 (defvar ps-mule-bitmap-prologue-generated nil)
866 (defconst ps-mule-bitmap-prologue
867 "%%%% Procedures for bitmap fonts.
869 %% Create a base bitmap font.
870 /NBF { % fontname fontsize relative-compose baseline-offset enc | --
871 11 dict begin
872 /FontType 3 def
873 /FontMatrix matrix def
874 /FontBBox [ 0 0 0 0 ] def
875 /Encoding exch def
876 /BaselineOffset exch def
877 /RelativeCompose exch def
878 /FontSize exch def
879 /FontMatrix [ 1 FontSize div 0 0 1 FontSize div 0 0 ] def
880 /BuildGlyph { % fontdict charname | -
881 BitmapDict exch get /bmp exch def pop
882 %% bmp ::= [ DWIDTH WIDTH HEIGHT XOFF YOFF BITMAP RELATIVE-COMPOSE ]
883 /llx bmp 3 get def
884 /lly bmp 4 get def
885 /urx llx bmp 1 get add def
886 /ury lly bmp 2 get add def
887 bmp 0 get 0 llx lly urx ury setcachedevice
888 bmp 5 get length 0 gt {
889 llx ury translate
890 bmp 1 get bmp 2 get
891 true [ 1 0 0 -1 0 0 ] { bmp 5 get } imagemask
892 } if
893 } bind def
894 /BuildChar { % fontdict byte | -
895 1 index /Encoding get exch get
896 1 index /BuildGlyph get exec
897 } bind def
898 dup currentdict end
899 definefont def
900 } bind def
902 %% Create a parent font of 8/8 mapping.
903 /NPF { % fontname encoding fdepvector | -
904 8 dict begin
905 /FontType 0 def
906 /FMapType 2 def
907 /FontMatrix matrix def
908 /FDepVector exch def
909 /Encoding exch def
910 dup currentdict
912 definefont def
913 } bind def
915 %%%% End of procedures for bitmap fonts.
918 ;; External library support.
920 (defvar ps-mule-bitmap-dict-list nil)
921 (defvar ps-mule-bitmap-font-record nil)
923 ;; The following three functions are to be called from external
924 ;; libraries which support bitmap fonts (e.g. `bdf') to get
925 ;; appropriate PostScript code.
927 (defun ps-mule-generate-bitmap-prologue ()
928 (unless ps-mule-bitmap-prologue-generated
929 (setq ps-mule-bitmap-prologue-generated t
930 ps-mule-bitmap-dict-list nil
931 ps-mule-bitmap-font-record (make-vector 1024 nil))
932 (list ps-mule-bitmap-prologue)))
934 (defun ps-mule-generate-bitmap-font (font-spec size relative-compose
935 baselie-offset bbx)
936 (let* ((id (ps-mule-font-spec-id font-spec))
937 (bytes (ps-mule-font-spec-bytes font-spec))
938 output-list)
939 (if (= bytes 1)
940 (setq output-list
941 (list (format "/E%02X [ 0 1 255 {pop /.notdef} for ] def\n" id)
942 (format "%%%% %s\n" (ps-mule-font-spec-name font-spec))
943 (format "/F%02X %f %S %d E%02X NBF\n" id size
944 relative-compose baselie-offset id)))
945 (setq output-list
946 (list (list (format "/E%02X [ 0 1 255 { pop 0 } for ] def\n" id))
947 (list (format "/V%02X [" id))
948 " ] def\n"
949 (format "%%%% %s\n" (ps-mule-font-spec-name font-spec))
950 (format "/F%02X E%02X V%02X NPF\n" id id id))))
951 (aset ps-mule-bitmap-font-record id
952 (vector (= bytes 1) output-list
953 size relative-compose baselie-offset bbx))
954 (if ps-mule-bitmap-dict-list
955 output-list
956 (setq ps-mule-bitmap-dict-list (list "/BitmapDict <<\n" ">> def\n"))
957 (cons ps-mule-bitmap-dict-list output-list))))
959 (defun ps-mule-generate-bitmap-glyph (font-spec char code bitmap)
960 (let* ((id (ps-mule-font-spec-id font-spec))
961 ;; FONT-RECORD ::= ([(SUBFONT-OUTPUT-LIST ...) | t]
962 ;; BASEFONT-OUTPUT-LIST SIZE REL-COMP B-OFFSET BBX)
963 (font-record (aref ps-mule-bitmap-font-record id))
964 enc-name
965 output-list)
966 (if (listp (aref font-record 0))
967 ;; This is a 2-dimensional font. Create a subfont for this
968 ;; glyph if not yet created.
969 (let* ((high (/ code 256))
970 (id2 (+ (* id 256) high)))
971 (setq output-list (cdr (assq high (aref font-record 0)))
972 code (% code 256))
973 (or output-list
974 ;; We must create a subfont.
975 (let ((enc-list (car (aref font-record 1)))
976 (fdep-list (nth 1 (aref font-record 1))))
977 (setq output-list
978 (list
979 (format "/E%04X [ 0 1 255 {pop /.notdef} for ] def\n"
980 id2)
981 (format "/F%04X %f %S %d E%04X NBF\n"
982 id2 (aref font-record 2) (aref font-record 3)
983 (aref font-record 4) id2)
984 (format "E%02X %d %d put\n"
985 id high (1- (length fdep-list)))))
986 (nconc enc-list (list output-list))
987 (nconc fdep-list (list (format " F%04X" id2)))
988 (aset font-record 0
989 (cons (cons high output-list) (aref font-record 0)))))
990 (setq enc-name (format "%04X" id2)))
991 (setq output-list (aref font-record 1)
992 enc-name (format "%02X" id)))
993 (setcdr ps-mule-bitmap-dict-list
994 (cons (format "/C%02X-%X %s\n" id char bitmap)
995 (cdr ps-mule-bitmap-dict-list)))
996 (setcdr output-list
997 (cons (format "E%s %d /C%02X-%X put\n" enc-name code id char)
998 (cdr output-list))))
999 nil)
1001 ;; Mule specific initializers.
1003 ;;;###autoload
1004 (defun ps-mule-initialize ()
1005 "Initialize global data for printing multi-byte characters."
1006 (setq ps-mule-prologue-generated nil
1007 ps-mule-composition-prologue-generated nil
1008 ps-mule-bitmap-prologue-generated nil)
1009 (mapcar `(lambda (x) (setcar (nthcdr 2 x) nil))
1010 ps-mule-external-libraries))
1012 (defun ps-mule-encode-header-string (string fonttag)
1013 "Generate PostScript code for ploting STRING by font FONTTAG.
1014 FONTTAG should be a string \"/h0\", \"/h1\", \"/L0\", or \"/H0\".
1015 Any other value is treated as \"/H0\"."
1016 (with-temp-buffer
1017 (insert string)
1018 (list (ps-mule-encode-region (point-min) (point-max)
1019 (aref ps-mule-font-spec-tables
1020 (aref ps-mule-font-number-to-type
1021 (cond ((string= fonttag "/h0") 4)
1022 ((string= fonttag "/h1") 5)
1023 ((string= fonttag "/L0") 6)
1024 (t 0))))))))
1026 ;;;###autoload
1027 (defun ps-mule-begin-job (from to)
1028 "Start printing job for multi-byte chars between FROM and TO.
1029 It checks if all multi-byte characters in the region are printable or not."
1030 (if (and (not (find-composition from to))
1031 (save-excursion
1032 (goto-char from)
1033 (= (skip-chars-forward "\x00-\x7F" to) to)))
1034 ;; All characters can be printed by normal PostScript fonts.
1035 (setq ps-basic-plot-string-function 'ps-basic-plot-string
1036 ps-encode-header-string-function 'identity)
1037 (setq ps-basic-plot-string-function 'ps-mule-plot-string
1038 ps-encode-header-string-function 'ps-mule-encode-header-string
1039 ps-mule-font-info-database
1040 (cond ((eq ps-multibyte-buffer 'non-latin-printer)
1041 ps-mule-font-info-database-ps)
1042 ((eq ps-multibyte-buffer 'bdf-font)
1043 ps-mule-font-info-database-bdf)
1044 ((eq ps-multibyte-buffer 'bdf-font-except-latin)
1045 ps-mule-font-info-database-ps-bdf)
1047 ps-mule-font-info-database-default)))
1049 ;; Be sure to have font information for Latin-1.
1050 (or (assq 'iso-8859-1 ps-mule-font-info-database)
1051 (setq ps-mule-font-info-database
1052 (cons '(iso-8859-1 (normal nil nil))
1053 ps-mule-font-info-database)))
1055 ;; Generate ps-mule-font-spec-tables.
1056 (let ((font-spec-alist (make-vector 4 nil))
1057 (id-max 0)
1058 (font-id 0)
1059 font-info-list)
1060 ;; Generate properly ordered font-info-list from
1061 ;; ps-mule-font-info-database.
1062 (let ((charset-list
1063 (copy-sequence (get-language-info current-language-environment
1064 'charset))))
1065 (setq charset-list (cons 'iso-8859-1 (delq 'iso-8859-1 charset-list)))
1066 (dolist (charset charset-list)
1067 (let ((font-info (assq charset ps-mule-font-info-database)))
1068 (and font-info
1069 (setq font-info-list (cons font-info font-info-list)))))
1070 (dolist (font-info ps-mule-font-info-database)
1071 (or (memq (car font-info) charset-list)
1072 (setq font-info-list (cons font-info font-info-list))))
1073 (setq font-info-list (nreverse font-info-list)))
1075 ;; Now font-info-list is an alist ordered by charset priority.
1076 ;; Store FONT-SPECs in each element of font-spec-alist.
1077 (dolist (font-info font-info-list)
1078 (let ((font-spec-vec (make-vector 4 nil))
1079 (charset (car font-info))
1080 encoding bytes font-spec)
1081 (dolist (e (cdr font-info))
1082 (setq encoding (nth 3 e) bytes (nth 4 e))
1083 (unless encoding
1084 (setq encoding charset bytes (charset-dimension charset)))
1085 (setq font-spec (vector id-max charset font-id
1086 (nth 1 e) (nth 2 e) encoding
1087 (or bytes 1) nil)
1088 id-max (1+ id-max))
1089 (if (ps-mule-check-font font-spec)
1090 (aset font-spec-vec
1091 (cond ((eq (car e) 'normal) 0)
1092 ((eq (car e) 'bold) 1)
1093 ((eq (car e) 'italic) 2)
1094 (t 3)) font-spec)))
1095 (when (aref font-spec-vec 0)
1096 (or (aref font-spec-vec 3)
1097 (aset font-spec-vec 3 (or (aref font-spec-vec 1)
1098 (aref font-spec-vec 2)
1099 (aref font-spec-vec 0))))
1100 (or (aref font-spec-vec 1)
1101 (aset font-spec-vec 1 (aref font-spec-vec 0)))
1102 (or (aref font-spec-vec 2)
1103 (aset font-spec-vec 2 (aref font-spec-vec 1)))
1104 (dotimes (i 4)
1105 (aset font-spec-alist i
1106 (nconc (aref font-spec-alist i)
1107 (list (cons charset (aref font-spec-vec i))))))
1108 (setq font-id (1+ font-id)))))
1110 ;; Make four FONT-SPEC-TABLEs and set them in
1111 ;; ps-mule-font-spec-tables. Each char table has one extra slot
1112 ;; whose value is an element of font-spec-alist.
1113 (setq ps-mule-font-spec-tables (make-vector 4 nil))
1114 (put 'font-spec-table 'char-table-extra-slots 1)
1115 (dotimes (i 4)
1116 (let ((table (make-char-table 'font-spec-table)))
1117 (aset ps-mule-font-spec-tables i table)
1118 (set-char-table-extra-slot table 0 (aref font-spec-alist i))
1119 ;; Be sure to have glyphs for "0123456789/" in advance for
1120 ;; page numbering.
1121 (let ((str " 0123456789/"))
1122 (dotimes (i (length str))
1123 (or (vectorp (ps-mule-get-font-spec (aref str i) table nil))
1124 (error "ASCII font not available")))))))
1126 (ps-mule-prologue-generated)
1127 (if (find-composition from to)
1128 (ps-mule-composition-prologue-generated))))
1130 (defun ps-mule-restruct-output-list (list tail)
1131 (dolist (elt list)
1132 (if (listp elt)
1133 (setq tail (ps-mule-restruct-output-list elt tail))
1134 (setcdr tail (cons elt (cdr tail)))
1135 (setq tail (cdr tail))))
1136 tail)
1138 (defun ps-mule-redefine-font (font-number fonttag size ps-font)
1139 (let* ((font-type (aref ps-mule-font-number-to-type font-number))
1140 (font-spec-alist (char-table-extra-slot
1141 (aref ps-mule-font-spec-tables font-type) 0)))
1142 (ps-output-prologue
1143 (list (if (ps-mule-font-spec-src (cdr (car font-spec-alist)))
1144 ;; We ignore a font specfied in ps-font-info-database.
1145 (format "/V%s VTOP%d def\n" fonttag font-type)
1146 (format "/V%s [ VTOP%d aload pop ] def\n
1147 V%s 0 /%s-latin1 /%s Latin1Encoding put\n"
1148 fonttag font-type fonttag ps-font ps-font))
1149 (format "/%s ETOP%d V%s %f ReDefFont\n"
1150 fonttag font-type fonttag size)))))
1153 ;;;###autoload
1154 (defun ps-mule-end-job ()
1155 "Finish printing job for multi-byte chars."
1157 ;; Prepare root and sub fonts while generating glyphs if necessary.
1158 (let ((output-head (list t))
1159 (ps-mule-output-list (list t)))
1160 (dotimes (i 4)
1161 (map-char-table 'ps-mule-prepare-glyph
1162 (aref ps-mule-font-spec-tables i)))
1163 (ps-mule-restruct-output-list (cdr ps-mule-output-list) output-head)
1164 (ps-output-prologue (cdr output-head)))
1166 ;; Prepare top Encoding and templates of FDepVector.
1167 (dotimes (i 4)
1168 (let ((font-spec-alist (char-table-extra-slot
1169 (aref ps-mule-font-spec-tables i) 0))
1170 font-list font-spec)
1171 (dolist (elt font-spec-alist)
1172 (setq font-spec (cdr elt))
1173 (if (ps-mule-font-spec-extra font-spec)
1174 (push (cons (ps-mule-font-spec-font-id font-spec)
1175 (ps-mule-font-spec-id font-spec))
1176 font-list)))
1177 (setq font-list (nreverse font-list))
1178 (ps-output-prologue
1179 (list (format "/ETOP%d 256 array def\n" i)
1180 (format "0 1 255 { ETOP%d exch 0 put } for\n" i)))
1181 (let ((index 0))
1182 (dolist (font font-list)
1183 (ps-output-prologue (format "ETOP%d %d %d put\n" i (car font) index))
1184 (setq index (1+ index))))
1185 (ps-output-prologue (format "/VTOP%d [%s] def\n" i
1186 (mapconcat #'(lambda (x)
1187 (format "F%02X" (cdr x)))
1188 font-list " ")))))
1190 ;; Redefine fonts f0, f1, f2, f3, h0, h1, H0.
1191 (ps-mule-redefine-font 4 "h0" ps-header-title-font-size-internal
1192 (ps-font 'ps-font-for-header 'bold))
1193 (ps-mule-redefine-font 5 "h1" ps-header-font-size-internal
1194 (ps-font 'ps-font-for-header 'normal))
1195 (ps-mule-redefine-font 6 "H0" ps-footer-font-size-internal
1196 (ps-font 'ps-font-for-footer 'normal))
1197 (let ((font (ps-font-alist 'ps-font-for-text))
1198 (i 0))
1199 (while font
1200 (ps-mule-redefine-font i (format "f%d" i)
1201 ps-font-size-internal
1202 (ps-font 'ps-font-for-text (car (car font))))
1203 (setq font (cdr font)
1204 i (1+ i)))))
1206 (provide 'ps-mule)
1208 ;; Local Variables:
1209 ;; generated-autoload-file: "ps-print.el"
1210 ;; End:
1212 ;;; ps-mule.el ends here