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