1 ;;; ps-mule.el --- Provide multi-byte character facility to ps-print.
3 ;; Copyright (C) 1998,99,00,2001 Free Software Foundation, Inc.
5 ;; Author: Vinicius Jose Latorre <vinicius@cpqd.com.br>
6 ;; Author: Kenichi Handa <handa@etl.go.jp> (multi-byte characters)
7 ;; Maintainer: Kenichi Handa <handa@etl.go.jp> (multi-byte characters)
8 ;; Maintainer: Vinicius Jose Latorre <vinicius@cpqd.com.br>
9 ;; Keywords: wp, print, PostScript, multibyte, mule
10 ;; Time-stamp: <2001/03/16 18:50:59 Handa>
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 2, or (at your option)
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; see the file COPYING. If not, write to the
26 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
27 ;; Boston, MA 02111-1307, USA.
31 ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
36 ;; This package is used for ps-print to print multi-byte buffer.
38 ;; See also ps-print.el.
41 ;; Printing Multi-byte Buffer
42 ;; --------------------------
44 ;; The variable `ps-multibyte-buffer' specifies the ps-print multi-byte buffer
47 ;; Valid values for `ps-multibyte-buffer' are:
49 ;; nil This is the value to use the default settings which
50 ;; is by default for printing buffer with only ASCII
51 ;; and Latin characters. The default setting can be
52 ;; changed by setting the variable
53 ;; `ps-mule-font-info-database-default' differently.
54 ;; The initial value of this variable is
55 ;; `ps-mule-font-info-database-latin' (see
58 ;; `non-latin-printer' This is the value to use when you have a japanese
59 ;; or korean PostScript printer and want to print
60 ;; buffer with ASCII, Latin-1, Japanese (JISX0208 and
61 ;; JISX0201-Kana) and Korean characters. At present,
62 ;; it was not tested the Korean characters printing.
63 ;; If you have a korean PostScript printer, please,
66 ;; `bdf-font' This is the value to use when you want to print
67 ;; buffer with BDF fonts. BDF fonts include both latin
68 ;; and non-latin fonts. BDF (Bitmap Distribution
69 ;; Format) is a format used for distributing X's font
70 ;; source file. BDF fonts are included in
71 ;; `intlfonts-1.2' which is a collection of X11 fonts
72 ;; for all characters supported by Emacs. In order to
73 ;; use this value, be sure to have installed
74 ;; `intlfonts-1.2' and set the variable
75 ;; `bdf-directory-list' appropriately (see ps-bdf.el
76 ;; for documentation of this variable).
78 ;; `bdf-font-except-latin' This is like `bdf-font' except that it is used
79 ;; PostScript default fonts to print ASCII and Latin-1
80 ;; characters. This is convenient when you want or
81 ;; need to use both latin and non-latin characters on
82 ;; the same buffer. See `ps-font-family',
83 ;; `ps-header-font-family' and `ps-font-info-database'.
85 ;; Any other value is treated as nil.
87 ;; The default is nil.
89 ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
96 ;; to avoid XEmacs compilation gripes
97 (defvar leading-code-private-22
157)
98 (or (fboundp 'charset-bytes
)
99 (defun charset-bytes (charset) 1)) ; ascii
100 (or (fboundp 'charset-dimension
)
101 (defun charset-dimension (charset) 1)) ; ascii
102 (or (fboundp 'charset-id
)
103 (defun charset-id (charset) 0)) ; ascii
104 (or (fboundp 'charset-width
)
105 (defun charset-width (charset) 1)) ; ascii
106 (or (fboundp 'find-charset-region
)
107 (defun find-charset-region (beg end
&optional table
)
109 (or (fboundp 'split-char
)
110 (defun split-char (char)
111 (list (if (char-valid-p char
)
115 (or (fboundp 'char-width
)
116 (defun char-width (char) 1)) ; ascii
117 (or (fboundp 'chars-in-region
)
118 (defun chars-in-region (beg end
)
119 (- (max beg end
) (min beg end
))))
120 (or (fboundp 'forward-point
)
121 (defun forward-point (arg)
123 (let ((count (abs arg
))
124 (step (if (zerop arg
)
127 (while (and (> count
0)
128 (< (point-min) (point)) (< (point) (point-max)))
130 (setq count
(1- count
)))
131 (+ (point) (* count step
))))))
132 (or (fboundp 'decompose-composite-char
)
133 (defun decompose-composite-char (char &optional type
134 with-composition-rule
)
136 (or (fboundp 'encode-coding-string
)
137 (defun encode-coding-string (string coding-system
&optional nocopy
)
140 (copy-sequence string
))))
141 (or (fboundp 'coding-system-p
)
142 (defun coding-system-p (obj) nil
))
143 (or (fboundp 'ccl-execute-on-string
)
144 (defun ccl-execute-on-string (ccl-prog status str
145 &optional contin unibyte-p
)
147 (or (fboundp 'define-ccl-program
)
148 (defmacro define-ccl-program
(name ccl-program
&optional doc
)
149 `(defconst ,name nil
,doc
))))
153 (defcustom ps-multibyte-buffer nil
154 "*Specifies the multi-byte buffer handling.
158 nil This is the value to use the default settings which
159 is by default for printing buffer with only ASCII
160 and Latin characters. The default setting can be
161 changed by setting the variable
162 `ps-mule-font-info-database-default' differently.
163 The initial value of this variable is
164 `ps-mule-font-info-database-latin' (see
167 `non-latin-printer' This is the value to use when you have a Japanese
168 or Korean PostScript printer and want to print
169 buffer with ASCII, Latin-1, Japanese (JISX0208 and
170 JISX0201-Kana) and Korean characters. At present,
171 it was not tested the Korean characters printing.
172 If you have a korean PostScript printer, please,
175 `bdf-font' This is the value to use when you want to print
176 buffer with BDF fonts. BDF fonts include both latin
177 and non-latin fonts. BDF (Bitmap Distribution
178 Format) is a format used for distributing X's font
179 source file. BDF fonts are included in
180 `intlfonts-1.2' which is a collection of X11 fonts
181 for all characters supported by Emacs. In order to
182 use this value, be sure to have installed
183 `intlfonts-1.2' and set the variable
184 `bdf-directory-list' appropriately (see ps-bdf.el for
185 documentation of this variable).
187 `bdf-font-except-latin' This is like `bdf-font' except that it is used
188 PostScript default fonts to print ASCII and Latin-1
189 characters. This is convenient when you want or
190 need to use both latin and non-latin characters on
191 the same buffer. See `ps-font-family',
192 `ps-header-font-family' and `ps-font-info-database'.
194 Any other value is treated as nil."
195 :type
'(choice (const non-latin-printer
) (const bdf-font
)
196 (const bdf-font-except-latin
) (const :tag
"nil" nil
))
197 :group
'ps-print-font
)
201 ;; For Emacs 20.2 and the earlier version.
202 (if (and (boundp 'mule-version
)
203 (not (string< (symbol-value 'mule-version
) "4.0")))
204 ;; mule package is loaded
206 (defalias 'ps-mule-next-point
'1+)
207 (defalias 'ps-mule-chars-in-string
'length
)
208 (defalias 'ps-mule-string-char
'aref
)
209 (defsubst ps-mule-next-index
(str i
) (1+ i
)))
210 ;; mule package isn't loaded or mule version lesser than 4.0
211 (defun ps-mule-next-point (arg)
212 (save-excursion (goto-char arg
) (forward-char 1) (point)))
213 (defun ps-mule-chars-in-string (string)
215 (charset-bytes (char-charset (string-to-char string
)))))
216 (defun ps-mule-string-char (string idx
)
217 (string-to-char (substring string idx
)))
218 (defun ps-mule-next-index (string i
)
219 (+ i
(charset-bytes (char-charset (string-to-char string
)))))
221 ;; For Emacs 20.4 and the earlier version.
222 (if (and (boundp 'mule-version
)
223 (string< (symbol-value 'mule-version
) "5.0"))
224 ;; mule package is loaded and mule version is lesser than 5.0
226 (defun encode-composition-rule (rule)
227 (if (= (car rule
) 4) (setcar rule
10))
228 (if (= (cdr rule
) 4) (setcdr rule
10))
229 (+ (* (car rule
) 12) (cdr rule
)))
230 (defun find-composition (pos &rest ignore
)
231 (let ((ch (char-after pos
)))
232 (if (eq (char-charset ch
) 'composition
)
233 (let ((components (decompose-composite-char ch
'vector t
)))
234 (list pos
(ps-mule-next-point pos
) components
235 (integerp (aref components
1)) nil
236 (char-width ch
)))))))
237 ;; mule package isn't loaded
238 (or (fboundp 'encode-composition-rule
)
239 (defun encode-composition-rule (rule)
241 (or (fboundp 'find-composition
)
242 (defun find-composition (pos &rest ignore
)
246 (defvar ps-mule-font-info-database
248 "Alist of charsets with the corresponding font information.
249 Each element has the form:
251 (CHARSET (FONT-TYPE FONT-SRC FONT-NAME ENCODING BYTES) ...)
255 CHARSET is a charset (symbol) for this font family,
257 FONT-TYPE is a font type: normal, bold, italic, or bold-italic.
259 FONT-SRC is a font source: builtin, ps-bdf, vflib, or nil.
261 If FONT-SRC is builtin, FONT-NAME is a built-in PostScript font name.
263 If FONT-SRC is bdf, FONT-NAME is a BDF font file name, or a list of
264 alternative font names. To use this font, the external library `ps-bdf'
267 If FONT-SRC is vflib, FONT-NAME is the name of a font that VFlib knows.
268 To use this font, the external library `vflib' is required.
270 If FONT-SRC is nil, a proper ASCII font in the variable
271 `ps-font-info-database' is used. This is useful for Latin-1 characters.
273 ENCODING is a coding system to encode a string of characters of CHARSET into a
274 proper string matching an encoding of the specified font. ENCODING may be a
275 function that does this encoding. In this case, the function is called with
276 one argument, the string to encode, and it should return an encoded string.
278 BYTES specifies how many bytes each character has in the encoded byte
279 sequence; it should be 1 or 2.
281 All multi-byte characters are printed by fonts specified in this database
282 regardless of a font family of ASCII characters. The exception is Latin-1
283 characters which are printed by the same font as ASCII characters, thus obey
286 See also the variable `ps-font-info-database'.")
288 (defconst ps-mule-font-info-database-latin
290 (normal nil nil iso-latin-1
)))
291 "Sample setting of `ps-mule-font-info-database' to use latin fonts.")
293 (defcustom ps-mule-font-info-database-default
294 ps-mule-font-info-database-latin
295 "*The default setting to use when `ps-multibyte-buffer' is nil."
296 :type
'(symbol :tag
"Multi-Byte Buffer Database Font Default")
297 :group
'ps-print-font
)
299 (defconst ps-mule-font-info-database-ps
301 (normal builtin
"Ryumin-Light.Katakana" ps-mule-encode-7bit
1)
302 (bold builtin
"GothicBBB-Medium.Katakana" ps-mule-encode-7bit
1)
303 (bold-italic builtin
"GothicBBB-Medium.Katakana" ps-mule-encode-7bit
1))
305 (normal builtin
"Ryumin-Light.Hankaku" ps-mule-encode-7bit
1)
306 (bold builtin
"GothicBBB-Medium.Hankaku" ps-mule-encode-7bit
1))
308 (normal builtin
"Ryumin-Light-H" ps-mule-encode-7bit
2)
309 (bold builtin
"GothicBBB-Medium-H" ps-mule-encode-7bit
2))
311 (normal builtin
"Munhwa-Regular-KSC-EUC-H" ps-mule-encode-7bit
2)
312 (bold builtin
"Munhwa-Bold-KSC-EUC-H" ps-mule-encode-7bit
2))
314 "Sample setting of the `ps-mule-font-info-database' to use builtin PS font.
316 Currently, data for Japanese and Korean PostScript printers are listed.")
318 (defconst ps-mule-font-info-database-bdf
320 (normal bdf
("lt1-24-etl.bdf" "etl24-latin1.bdf") nil
1)
321 (bold bdf
("lt1-16b-etl.bdf" "etl16b-latin1.bdf") nil
1)
322 (italic bdf
("lt1-16i-etl.bdf" "etl16i-latin1.bdf") nil
1)
323 (bold-italic bdf
("lt1-16bi-etl.bdf" "etl16bi-latin1.bdf") nil
1))
325 (normal bdf
("lt1-24-etl.bdf" "etl24-latin1.bdf") iso-latin-1
1)
326 (bold bdf
("lt1-16b-etl.bdf" "etl16b-latin1.bdf") iso-latin-1
1)
327 (italic bdf
("lt1-16i-etl.bdf" "etl16i-latin1.bdf") iso-latin-1
1)
328 (bold-italic bdf
("lt1-16bi-etl.bdf" "etl16bi-latin1.bdf") iso-latin-1
1))
330 (normal bdf
("lt2-24-etl.bdf" "etl24-latin2.bdf") iso-latin-2
1))
332 (normal bdf
("lt3-24-etl.bdf" "etl24-latin3.bdf") iso-latin-3
1))
334 (normal bdf
("lt4-24-etl.bdf" "etl24-latin4.bdf") iso-latin-4
1))
336 (normal bdf
("thai24.bdf" "thai-24.bdf") thai-tis620
1))
338 (normal bdf
("grk24-etl.bdf" "etl24-greek.bdf") greek-iso-8bit
1))
339 ;; (arabic-iso8859-6 nil) ; not yet available
341 (normal bdf
("heb24-etl.bdf" "etl24-hebrew.bdf") hebrew-iso-8bit
1))
343 (normal bdf
"12x24rk.bdf" ps-mule-encode-8bit
1))
345 (normal bdf
"12x24rk.bdf" ps-mule-encode-7bit
1))
347 (normal bdf
("cyr24-etl.bdf" "etl24-cyrillic.bdf") cyrillic-iso-8bit
1))
349 (normal bdf
("lt5-24-etl.bdf" "etl24-latin5.bdf") iso-latin-5
1))
350 (japanese-jisx0208-1978
351 (normal bdf
"jiskan24.bdf" ps-mule-encode-7bit
2))
353 (normal bdf
"gb24st.bdf" ps-mule-encode-7bit
2))
355 (normal bdf
"jiskan24.bdf" ps-mule-encode-7bit
2))
357 (normal bdf
"hanglm24.bdf" ps-mule-encode-7bit
2))
359 (normal bdf
("jksp40.bdf" "jisksp40.bdf") ps-mule-encode-7bit
2))
361 (normal bdf
("cns1-40.bdf" "cns-1-40.bdf") ps-mule-encode-7bit
2))
363 (normal bdf
("cns2-40.bdf" "cns-2-40.bdf") ps-mule-encode-7bit
2))
365 (normal bdf
"taipei24.bdf" chinese-big5
2))
367 (normal bdf
"taipei24.bdf" chinese-big5
2))
369 (normal bdf
("sish24-etl.bdf" "etl24-sisheng.bdf") ps-mule-encode-7bit
1))
371 (normal bdf
("ipa24-etl.bdf" "etl24-ipa.bdf") ps-mule-encode-8bit
1))
372 (vietnamese-viscii-lower
373 (normal bdf
("visc24-etl.bdf" "etl24-viscii.bdf") vietnamese-viscii
1))
374 (vietnamese-viscii-upper
375 (normal bdf
("visc24-etl.bdf" "etl24-viscii.bdf") vietnamese-viscii
1))
377 (normal bdf
("arab24-0-etl.bdf" "etl24-arabic0.bdf") ps-mule-encode-7bit
1))
379 (normal bdf
("arab24-1-etl.bdf" "etl24-arabic1.bdf") ps-mule-encode-7bit
1))
380 ;; (ascii-right-to-left nil) ; not yet available
382 (normal bdf
("lao24-mule.bdf" "mule-lao-24.bdf") lao
1))
384 (normal bdf
("arab24-2-etl.bdf" "etl24-arabic2.bdf") ps-mule-encode-7bit
1))
386 (normal bdf
("isci24-mule.bdf" "mule-iscii-24.bdf") ps-mule-encode-7bit
1))
388 (normal bdf
("ind1c24-mule.bdf" "mule-indian-1col-24.bdf") ps-mule-encode-7bit
2))
390 (normal bdf
("tib1c24-mule.bdf" "mule-tibmdx-1col-24.bdf") ps-mule-encode-7bit
2))
392 (normal bdf
("ethio24f-uni.bdf" "ethiomx24f-uni.bdf") ps-mule-encode-ethiopic
2))
394 (normal bdf
("cns3-40.bdf" "cns-3-40.bdf") ps-mule-encode-7bit
2))
396 (normal bdf
("cns4-40.bdf" "cns-4-40.bdf") ps-mule-encode-7bit
2))
398 (normal bdf
("cns5-40.bdf" "cns-5-40.bdf") ps-mule-encode-7bit
2))
400 (normal bdf
("cns6-40.bdf" "cns-6-40.bdf") ps-mule-encode-7bit
2))
402 (normal bdf
("cns7-40.bdf" "cns-7-40.bdf") ps-mule-encode-7bit
2))
404 (normal bdf
("ind24-mule.bdf" "mule-indian-24.bdf") ps-mule-encode-7bit
2))
406 (normal bdf
("tib24p-mule.bdf" "tib24-mule.bdf" "mule-tibmdx-24.bdf")
407 ps-mule-encode-7bit
2)))
408 "Sample setting of the `ps-mule-font-info-database' to use BDF fonts.
409 BDF (Bitmap Distribution Format) is a format used for distributing X's font
412 Current default value list for BDF fonts is included in `intlfonts-1.2' which is
413 a collection of X11 fonts for all characters supported by Emacs.
415 Using this list as default value to `ps-mule-font-info-database', all characters
416 including ASCII and Latin-1 are printed by BDF fonts.
418 See also `ps-mule-font-info-database-ps-bdf'.")
420 (defconst ps-mule-font-info-database-ps-bdf
421 (cons (car ps-mule-font-info-database-latin
)
422 (cdr (cdr ps-mule-font-info-database-bdf
)))
423 "Sample setting of the `ps-mule-font-info-database' to use BDF fonts.
425 Current default value list for BDF fonts is included in `intlfonts-1.2' which is
426 a collection of X11 fonts for all characters supported by Emacs.
428 Using this list as default value to `ps-mule-font-info-database', all characters
429 except ASCII and Latin-1 characters are printed by BDF fonts. ASCII and Latin-1
430 characters are printed by PostScript font specified by `ps-font-family' and
431 `ps-header-font-family'.
433 See also `ps-mule-font-info-database-bdf'.")
435 ;; Two typical encoding functions for PostScript fonts.
437 (defun ps-mule-encode-7bit (string)
438 (ps-mule-encode-bit string
0))
440 (defun ps-mule-encode-8bit (string)
441 (ps-mule-encode-bit string
128))
443 (defun ps-mule-encode-bit (string delta
)
444 (let* ((dim (charset-dimension (char-charset (string-to-char string
))))
445 (len (* (ps-mule-chars-in-string string
) dim
))
446 (str (make-string len
0))
452 (+ (nth 1 (split-char (ps-mule-string-char string i
))) delta
))
453 (setq i
(ps-mule-next-index string i
)
456 (let ((split (split-char (ps-mule-string-char string i
))))
457 (aset str j
(+ (nth 1 split
) delta
))
458 (aset str
(1+ j
) (+ (nth 2 split
) delta
))
459 (setq i
(ps-mule-next-index string i
)
463 ;; Special encoding function for Ethiopic.
464 (if (boundp 'mule-version
) ; only if mule package is loaded
465 (define-ccl-program ccl-encode-ethio-unicode
469 (if (r2 == ,leading-code-private-22
)
471 (if (r0 == ,(charset-id 'ethiopic
))
473 (r1 &= 127) (r2 &= 127)
474 (call ccl-encode-ethio-font
)
476 (write-read-repeat r2
))
479 (write-read-repeat r2
))))))
480 ;; to avoid compilation gripes
481 (defvar ccl-encode-ethio-unicode nil
))
483 (if (boundp 'mule-version
)
484 ;; bound mule-version
485 (defun ps-mule-encode-ethiopic (string)
486 (ccl-execute-on-string (symbol-value 'ccl-encode-ethio-unicode
)
489 ;; unbound mule-version
490 (defun ps-mule-encode-ethiopic (string)
493 ;; A charset which we are now processing.
494 (defvar ps-mule-current-charset nil
)
496 (defun ps-mule-get-font-spec (charset font-type
)
497 "Return FONT-SPEC for printing characters CHARSET with FONT-TYPE.
498 FONT-SPEC is a list that has the form:
500 (FONT-SRC FONT-NAME ENCODING BYTES)
502 FONT-SPEC is extracted from `ps-mule-font-info-database'.
504 See the documentation of `ps-mule-font-info-database' for the meaning of each
505 element of the list."
506 (let ((slot (cdr (assq charset ps-mule-font-info-database
))))
508 (cdr (or (assq font-type slot
)
509 (and (eq font-type
'bold-italic
)
510 (or (assq 'bold slot
) (assq 'italic slot
)))
511 (assq 'normal slot
))))))
513 ;; Functions to access each element of FONT-SPEC.
514 (defsubst ps-mule-font-spec-src
(font-spec) (car font-spec
))
515 (defsubst ps-mule-font-spec-name
(font-spec) (nth 1 font-spec
))
516 (defsubst ps-mule-font-spec-encoding
(font-spec) (nth 2 font-spec
))
517 (defsubst ps-mule-font-spec-bytes
(font-spec) (nth 3 font-spec
))
519 (defsubst ps-mule-printable-p
(charset)
520 "Non-nil if characters in CHARSET is printable."
521 (ps-mule-get-font-spec charset
'normal
))
523 (defconst ps-mule-external-libraries
527 bdf-generate-prologue bdf-generate-font bdf-generate-glyphs
)
529 pcf-generate-prologue pcf-generate-font pcf-generate-glyphs
)
531 vflib-generate-prologue vflib-generate-font vflib-generate-glyphs
))
532 "Alist of information of external libraries to support PostScript printing.
533 Each element has the form:
535 (FONT-SRC FEATURE INITIALIZED-P PROLOGUE-FUNC FONT-FUNC GLYPHS-FUNC)
537 FONT-SRC is the font source: builtin, bdf, pcf, or vflib.
539 FEATURE is the feature that provide a facility to handle FONT-SRC. Except for
540 `builtin' FONT-SRC, this feature is automatically `require'd before handling
541 FONT-SRC. Currently, we only have the feature `ps-bdf'.
543 INITIALIZED-P indicates if this library is initialized or not.
545 PROLOGUE-FUNC is a function to generate PostScript code which define several
546 PostScript procedures that will be called by FONT-FUNC and GLYPHS-FUNC. It is
547 called with no argument, and should return a list of strings.
549 FONT-FUNC is a function to generate PostScript code which define a new font. It
550 is called with one argument FONT-SPEC, and should return a list of strings.
552 GLYPHS-FUNC is a function to generate PostScript code which define glyphs of
553 characters. It is called with three arguments FONT-SPEC, CODE-LIST, and BYTES,
554 and should return a list of strings.")
556 (defun ps-mule-init-external-library (font-spec)
557 "Initialize external library specified by FONT-SPEC for PostScript printing.
558 See the documentation of `ps-mule-get-font-spec' for FONT-SPEC's meaning."
559 (let* ((font-src (ps-mule-font-spec-src font-spec
))
560 (slot (assq font-src ps-mule-external-libraries
)))
563 (let ((func (nth 3 slot
)))
566 (require (nth 1 slot
))
567 (ps-output-prologue (funcall func
))))
568 (setcar (nthcdr 2 slot
) t
)))))
570 ;; Cached glyph information of fonts, alist of:
571 ;; (FONT-NAME ((FONT-TYPE-NUMBER . SCALED-FONT-NAME) ...)
572 ;; cache CODE0 CODE1 ...)
573 (defvar ps-mule-font-cache nil
)
575 (defun ps-mule-generate-font (font-spec charset
&optional header-p
)
576 "Generate PostScript codes to define a new font in FONT-SPEC for CHARSET.
578 If optional 3rd arg HEADER-P is non-nil, generate codes to define a header
580 (let* ((font-name (ps-mule-font-spec-name font-spec
))
581 (font-name (if (consp font-name
) (car font-name
) font-name
))
582 (font-cache (assoc font-name ps-mule-font-cache
))
583 (font-src (ps-mule-font-spec-src font-spec
))
584 (func (nth 4 (assq font-src ps-mule-external-libraries
)))
585 (font-size (if header-p
(if (eq ps-current-font
0)
586 ps-header-title-font-size-internal
587 ps-header-font-size-internal
)
588 ps-font-size-internal
))
589 (current-font (+ ps-current-font
(if header-p
10 0)))
592 (format "h%d" ps-current-font
))
594 (format "f%d" ps-current-font
))
596 (format "f%02x-%d" (charset-id charset
) ps-current-font
)))))
597 (and func
(not font-cache
)
598 (ps-output-prologue (funcall func charset font-spec
)))
600 (list (format "/%s %f /%s Def%sFontMule\n"
601 scaled-font-name font-size font-name
603 (eq ps-mule-current-charset
'ascii
))
606 (setcar (cdr font-cache
)
607 (cons (cons current-font scaled-font-name
)
609 (setq font-cache
(list font-name
610 (list (cons current-font scaled-font-name
))
612 ps-mule-font-cache
(cons font-cache ps-mule-font-cache
)))
615 (defun ps-mule-generate-glyphs (font-spec code-list
)
616 "Generate PostScript codes which generate glyphs for CODE-LIST of FONT-SPEC."
617 (let* ((font-src (ps-mule-font-spec-src font-spec
))
618 (func (nth 5 (assq font-src ps-mule-external-libraries
))))
621 (funcall func font-spec code-list
622 (ps-mule-font-spec-bytes font-spec
))))))
624 (defun ps-mule-prepare-font (font-spec string charset
625 &optional no-setfont header-p
)
626 "Generate PostScript codes to print STRING of CHARSET by font FONT-SPEC.
628 The generated code is inserted on prologue part except the code that sets the
629 current font (using PostScript procedure `FM').
631 If optional 4th arg NO-SETFONT is non-nil, don't generate the code for setting
634 If optional 5th arg HEADER-P is non-nil, generate a code for setting a header
636 (let* ((font-name (ps-mule-font-spec-name font-spec
))
637 (font-name (if (consp font-name
) (car font-name
) font-name
))
638 (current-font (+ ps-current-font
(if header-p
10 0)))
639 (font-cache (assoc font-name ps-mule-font-cache
)))
640 (or (and font-cache
(assq current-font
(nth 1 font-cache
)))
641 (setq font-cache
(ps-mule-generate-font font-spec charset header-p
)))
643 (let ((new-font (cdr (assq current-font
(nth 1 font-cache
)))))
644 (or (equal new-font ps-last-font
)
646 (ps-output (format "/%s FM\n" new-font
))
647 (setq ps-last-font new-font
)))))
648 (if (nth 5 (assq (ps-mule-font-spec-src font-spec
)
649 ps-mule-external-libraries
))
650 ;; We have to generate PostScript codes which define glyphs.
651 (let* ((cached-codes (nthcdr 2 font-cache
))
652 (bytes (ps-mule-font-spec-bytes font-spec
))
653 (len (length string
))
657 (setq code
(if (= bytes
1)
659 (+ (* (aref string i
) 256) (aref string
(1+ i
)))))
660 (or (memq code cached-codes
)
662 (setq newcodes
(cons code newcodes
))
663 (setcdr cached-codes
(cons code
(cdr cached-codes
)))))
664 (setq i
(+ i bytes
)))
666 (ps-mule-generate-glyphs font-spec newcodes
))))))
669 (defun ps-mule-prepare-ascii-font (string)
670 "Setup special ASCII font for STRING.
671 STRING should contain only ASCII characters."
673 (ps-mule-get-font-spec
675 (car (nth ps-current-font
(ps-font-alist 'ps-font-for-text
))))))
677 (ps-mule-prepare-font font-spec string
'ascii
))))
680 (defun ps-mule-set-ascii-font ()
681 (unless (eq ps-mule-current-charset
'ascii
)
682 (ps-set-font ps-current-font
)
683 (setq ps-mule-current-charset
'ascii
)))
685 ;; List of charsets of multi-byte characters in a text being printed.
686 ;; If the text doesn't contain any multi-byte characters (i.e. only ASCII),
688 (defvar ps-mule-charset-list nil
)
690 ;; This is a PostScript code inserted in the header of generated PostScript.
691 (defconst ps-mule-prologue
692 "%%%% Start of Mule Section
694 %% Working dictionary for general use.
695 /MuleDict 10 dict def
697 %% Adjust /RelativeCompose properly by checking /BaselineOffset.
698 /AdjustRelativeCompose { % fontdict |- fontdict
699 dup length 2 add dict begin
700 { 1 index /FID ne { def } { pop pop } ifelse } forall
701 currentdict /BaselineOffset known {
702 BaselineOffset false eq { /BaselineOffset 0 def } if
704 /BaselineOffset 0 def
706 currentdict /RelativeCompose known not {
707 /RelativeCompose [ 0 0.1 ] def
709 RelativeCompose false ne {
710 [ BaselineOffset RelativeCompose BaselineOffset add
711 [ FontMatrix { FontSize div } forall ] transform ]
712 /RelativeCompose exch def
719 %% Define already scaled font for non-ASCII character sets.
720 /DefFontMule { % fontname size basefont |- --
721 findfont exch scalefont AdjustRelativeCompose definefont pop
724 %% Define already scaled font for ASCII character sets.
725 /DefAsciiFontMule { % fontname size basefont |-
727 findfont dup /Encoding get /ISOLatin1Encoding exch def
728 exch scalefont AdjustRelativeCompose reencodeFontISO
732 /CurrentFont false def
734 %% Set the specified font to use.
735 %% For non-ASCII font, don't install Ascent, etc.
736 /FM { % fontname |- --
738 font /f0 eq font /f1 eq font /f2 eq font /f3 eq or or or {
741 font findfont setfont
745 %% Show vacant box for characters which don't have appropriate font.
746 /SB { % count column |- --
747 SpaceWidth mul /w exch def
752 0 Descent rmoveto w 0 rlineto
753 0 LineHeight rlineto w neg 0 rlineto closepath stroke
759 %% Flag to tell if we are now handling a composition. This is
760 %% defined here because both composition handler and bitmap font
761 %% handler require it.
764 %%%% End of Mule Section
767 "PostScript code for printing multi-byte characters.")
769 (defvar ps-mule-prologue-generated nil
)
771 (defun ps-mule-prologue-generated ()
772 (unless ps-mule-prologue-generated
773 (ps-output-prologue ps-mule-prologue
)
774 (setq ps-mule-prologue-generated t
)))
776 (defun ps-mule-find-wrappoint (from to char-width
&optional composition
)
777 "Find the longest sequence which is printable in the current line.
779 The search starts at FROM and goes until TO.
781 Optional 4th arg COMPOSITION, if non-nil, is information of
782 composition starting at FROM.
784 If COMPOSITION is nil, it is assumed that all characters between FROM
785 and TO belong to a charset in `ps-mule-current-charset'. Otherwise,
786 it is assumed that all characters between FROM and TO belong to the
789 CHAR-WIDTH is the average width of ASCII characters in the current font.
795 Where ENDPOS is the end position of the sequence and RUN-WIDTH is the width of
797 (if (or composition
(eq ps-mule-current-charset
'composition
))
798 ;; We must draw one char by one.
799 (let ((run-width (if composition
801 (* (char-width (char-after from
)) char-width
))))
802 (if (> run-width ps-width-remaining
)
803 (cons from ps-width-remaining
)
804 (cons (if composition
806 (ps-mule-next-point from
))
808 ;; We assume that all characters in this range have the same width.
809 (setq char-width
(* char-width
(charset-width ps-mule-current-charset
)))
810 (let ((run-width (* (chars-in-region from to
) char-width
)))
811 (if (> run-width ps-width-remaining
)
816 (truncate (/ ps-width-remaining char-width
)))))
818 (cons to run-width
)))))
821 (defun ps-mule-plot-string (from to
&optional bg-color
)
822 "Generate PostScript code for plotting characters in the region FROM and TO.
824 It is assumed that all characters in this region belong to the same charset.
826 Optional argument BG-COLOR specifies background color.
832 Where ENDPOS is the end position of the sequence and RUN-WIDTH is the width of
834 (setq ps-mule-current-charset
(charset-after from
))
835 (let* ((wrappoint (ps-mule-find-wrappoint
836 from to
(ps-avg-char-width 'ps-font-for-text
)))
838 (font-type (car (nth ps-current-font
839 (ps-font-alist 'ps-font-for-text
))))
840 (font-spec (ps-mule-get-font-spec ps-mule-current-charset font-type
))
841 (string (buffer-substring-no-properties from to
)))
844 ;; We can't print any more characters in the current line.
848 ;; We surely have a font for printing this character set.
849 (ps-output-string (ps-mule-string-encoding font-spec string
))
852 ((eq ps-mule-current-charset
'latin-iso8859-1
)
853 ;; Latin-1 can be printed by a normal ASCII font.
854 (ps-output-string (ps-mule-string-ascii string
))
857 ;; This case is obsolete for Emacs 21.
858 ((eq ps-mule-current-charset
'composition
)
859 (ps-mule-plot-composition from
(ps-mule-next-point from
) bg-color
))
862 ;; No way to print this charset. Just show a vacant box of an
863 ;; appropriate width.
864 (ps-output (format "%d %d SB\n"
866 (if (eq ps-mule-current-charset
'composition
)
867 (char-width (char-after from
))
868 (charset-width ps-mule-current-charset
))))))
872 (defun ps-mule-plot-composition (from to
&optional bg-color
)
873 "Generate PostScript code for plotting composition in the region FROM and TO.
875 It is assumed that all characters in this region belong to the same
878 Optional argument BG-COLOR specifies background color.
884 Where ENDPOS is the end position of the sequence and RUN-WIDTH is the width of
886 (let* ((composition (find-composition from nil nil t
))
887 (wrappoint (ps-mule-find-wrappoint
888 from to
(ps-avg-char-width 'ps-font-for-text
)
891 (font-type (car (nth ps-current-font
892 (ps-font-alist 'ps-font-for-text
)))))
894 ;; We can print this composition in the current line.
895 (let ((components (nth 2 composition
)))
896 (ps-mule-plot-components
897 (ps-mule-prepare-font-for-components components font-type
)
898 (if (nth 3 composition
) "RLC" "RBC"))))
901 ;; Prepare font of FONT-TYPE for printing COMPONENTS. By side effect,
902 ;; change character elements in COMPONENTS to the form:
903 ;; ENCODED-STRING or (FONTNAME . ENCODED-STRING)
904 ;; and change rule elements to the encoded value (integer).
905 ;; The latter form is used if we much change font for the character.
907 (defun ps-mule-prepare-font-for-components (components font-type
)
908 (let ((len (length components
))
912 (setq elt
(aref components i
))
914 ;; ELT is a composition rule.
915 (setq elt
(encode-composition-rule elt
))
916 ;; ELT is a glyph character.
917 (let* ((charset (char-charset elt
))
918 (font (or (eq charset ps-mule-current-charset
)
919 (if (eq charset
'ascii
)
920 (format "/f%d" ps-current-font
)
922 (charset-id charset
) ps-current-font
))))
924 (setq ps-mule-current-charset charset
925 str
(ps-mule-string-encoding
926 (ps-mule-get-font-spec charset font-type
)
930 (setq elt
(cons font str
) ps-last-font font
)
932 (aset components i elt
)
936 (defun ps-mule-plot-components (components tail
)
937 (let ((elt (aref components
0))
938 (len (length components
))
942 (ps-output-string elt
)
943 (ps-output (car elt
) " ")
944 (ps-output-string (cdr elt
)))
946 (setq elt
(aref components i
) i
(1+ i
))
949 (ps-output-string elt
))
951 (ps-output (car elt
) " ")
952 (ps-output-string (cdr elt
)))
953 (t ; i.e. (integerp elt)
954 (ps-output (format "%d" elt
)))))
955 (ps-output " ] " tail
"\n")))
957 ;; Composite font support
959 (defvar ps-mule-composition-prologue-generated nil
)
961 (defconst ps-mule-composition-prologue
962 "%%%% Character composition handler
963 /RelativeCompositionSkip 0.4 def
965 %% Get a bounding box (relative to currentpoint) of STR.
966 /GetPathBox { % str |- --
968 currentfont /FontType get 3 eq { %ifelse
971 currentpoint /y exch def /x exch def
972 false charpath flattenpath pathbbox
973 y sub /URY exch def x sub /URX exch def
974 y sub /LLY exch def x sub /LLX exch def
979 %% Apply effects (underline, strikeout, overline, box) to the
980 %% rectangle specified by TOP BOTTOM LEFT RIGHT.
981 /SpecialEffect { % -- |- --
982 currentpoint dup TOP add /yy exch def BOTTOM add /YY exch def
983 dup LEFT add /xx exch def RIGHT add /XX exch def
984 %% Adjust positions for future shadowing.
986 /yy yy Yshadow add def
987 /XX XX Xshadow add def
989 Effect 1 and 0 ne { UnderlinePosition Hline } if % underline
990 Effect 2 and 0 ne { StrikeoutPosition Hline } if % strikeout
991 Effect 4 and 0 ne { OverlinePosition Hline } if % overline
994 Effect 16 and 0 ne {SpaceBackground doBox} { xx yy XX YY doRect} ifelse
996 Effect 16 and 0 ne { false 0 doBox } if % box
999 %% Show STR with effects (shadow, outline).
1000 /ShowWithEffect { % str |- --
1001 Effect 8 and 0 ne { dup doShadow } if
1002 Effect 32 and 0 ne { true doOutline } { show } ifelse
1005 %% Draw COMPONENTS which have the form [ font0? [str0 xoff0 yoff0] ... ].
1006 /ShowComponents { % components |- -
1007 LEFT 0 lt { LEFT neg 0 rmoveto } if
1009 dup type /nametype eq { % font
1011 } { % [ str xoff yoff ]
1013 aload pop rmoveto ShowWithEffect
1020 %% Show relative composition.
1021 /RLC { % [ font0? str0 font1? str1 ... fontN? strN ] |- --
1022 /components exch def
1028 elt type /nametype eq { % font
1030 } { first { % first string
1033 %% Bounding box of overall glyphs.
1038 currentfont /RelativeCompose known {
1039 /relative currentfont /RelativeCompose get def
1041 %% Disable relative composition by setting sufficiently low
1042 %% and high positions.
1043 /relative [ -100000 100000 ] def
1049 LLX 0 lt { RIGHT } { 0 } ifelse % xoff
1050 LLY relative 1 get ge { % compose on TOP
1051 TOP LLY sub RelativeCompositionSkip add % yoff
1052 /TOP TOP URY LLY sub add RelativeCompositionSkip add def
1053 } { URY relative 0 get le { % compose under BOTTOM
1054 BOTTOM URY sub RelativeCompositionSkip sub % yoff
1055 /BOTTOM BOTTOM URY LLY sub sub
1056 RelativeCompositionSkip sub def
1059 URY TOP gt { /TOP URY def } if
1060 LLY BOTTOM lt { /BOTTOM LLY def } if
1063 URX RIGHT gt { /RIGHT URX def } if
1065 } forall ] /components exch def
1068 %% Reflect special effects.
1071 %% Draw components while ignoring effects other than shadow and outline.
1072 components ShowComponents
1073 /Composing false def
1077 %% Show rule-base composition.
1078 /RBC { % [ font0? str0 rule1 font1? str1 rule2 ... strN ] |- --
1079 /components exch def
1085 elt type /nametype eq { % font
1087 } { elt type /integertype eq { % rule
1088 %% This RULE decoding should be compatible with macro
1089 %% COMPOSITION_DECODE_RULE in emacs/src/composite.h.
1090 elt 12 idiv dup 3 mod /grefx exch def 3 idiv /grefy exch def
1091 elt 12 mod dup 3 mod /nrefx exch def 3 idiv /nrefy exch def
1092 } { first { % first string
1095 %% Bounding box of overall glyphs.
1100 /WIDTH RIGHT LEFT sub def
1104 /width URX LLX sub def
1105 /height URY LLY sub def
1106 /left LEFT [ 0 WIDTH 2 div WIDTH ] grefx get add
1107 [ 0 width 2 div width ] nrefx get sub def
1108 /bottom [ TOP 0 BOTTOM TOP BOTTOM add 2 div ] grefy get
1109 [ height LLY neg 0 height 2 div ] nrefy get sub def
1110 %% Update bounding box
1111 left LEFT lt { /LEFT left def } if
1112 left width add RIGHT gt { /RIGHT left width add def } if
1113 /WIDTH RIGHT LEFT sub def
1114 bottom BOTTOM lt { /BOTTOM bottom def } if
1115 bottom height add TOP gt { /TOP bottom height add def } if
1116 [ elt left LLX sub bottom LLY sub ]
1117 } ifelse } ifelse } ifelse
1118 } forall ] /components exch def
1121 %% Reflect special effects.
1124 %% Draw components while ignoring effects other than shadow and outline.
1125 components ShowComponents
1127 /Composing false def
1129 %%%% End of character composition handler
1132 "PostScript code for printing character composition.")
1134 (defun ps-mule-string-ascii (str)
1135 (ps-set-font ps-current-font
)
1136 (string-as-unibyte (encode-coding-string str
'iso-latin-1
)))
1138 ;; Encode STR for a font specified by FONT-SPEC and return the result.
1139 ;; If necessary, it generates the PostScript code for the font and glyphs to
1140 ;; print STR. If optional 4th arg HEADER-P is non-nil, it is assumed that STR
1142 (defun ps-mule-string-encoding (font-spec str
&optional no-setfont header-p
)
1143 (let ((encoding (ps-mule-font-spec-encoding font-spec
)))
1146 (cond ((coding-system-p encoding
)
1147 (encode-coding-string str encoding
))
1148 ((functionp encoding
)
1149 (funcall encoding str
))
1151 (error "Invalid coding system or function: %s" encoding
))
1154 (if (ps-mule-font-spec-src font-spec
)
1155 (ps-mule-prepare-font font-spec str ps-mule-current-charset
1156 (or no-setfont header-p
)
1159 (ps-set-font ps-current-font
)))
1162 ;; Bitmap font support
1164 (defvar ps-mule-bitmap-prologue-generated nil
)
1166 (defconst ps-mule-bitmap-prologue
1167 "%%%% Bitmap font handler
1169 /str7 7 string def % working area
1171 %% We grow the dictionary one bunch (1024 entries) by one.
1172 /BitmapDictArray 256 array def
1173 /BitmapDictLength 1024 def
1174 /BitmapDictIndex -1 def
1176 /NewBitmapDict { % -- |- --
1177 /BitmapDictIndex BitmapDictIndex 1 add def
1178 BitmapDictArray BitmapDictIndex BitmapDictLength dict put
1181 %% Make at least one dictionary.
1184 /AddBitmap { % gloval-charname bitmap-data |- --
1185 BitmapDictArray BitmapDictIndex get
1186 dup length BitmapDictLength ge {
1189 BitmapDictArray BitmapDictIndex get
1194 /GetBitmap { % gloval-charname |- bitmap-data
1195 0 1 BitmapDictIndex { BitmapDictArray exch get begin } for
1197 0 1 BitmapDictIndex { pop end } for
1200 %% Return a global character name which can be used as a key in the
1201 %% bitmap dictionary.
1202 /GlobalCharName { % fontidx code1 code2 |- gloval-charname
1203 exch 256 mul add exch 65536 mul add 16777216 add 16 str7 cvrs 0 66 put
1207 %% Character code holder for a 2-byte character.
1210 %% Glyph rendering procedure
1211 /BuildGlyphCommon { % fontdict charname |- --
1212 1 index /FontDimension get 1 eq { /FirstCode 0 store } if
1213 NameIndexDict exch get % STACK: fontdict charcode
1214 FirstCode 0 lt { %ifelse
1215 %% This is the first byte of a 2-byte character. Just
1216 %% remember it for the moment.
1217 /FirstCode exch store
1221 1 index /FontSize get /size exch def
1222 1 index /FontSpaceWidthRatio get /ratio exch def
1223 1 index /FontIndex get exch FirstCode exch
1224 GlobalCharName GetBitmap /bmp exch def
1225 %% bmp == [ DWIDTH BBX-WIDTH BBX-HEIGHT BBX-XOFF BBX-YOFF BITMAP ]
1227 /FontMatrix get [ exch { size div } forall ] /mtrx exch def
1228 bmp 3 get bmp 4 get mtrx transform
1229 /LLY exch def /LLX exch def
1230 bmp 1 get bmp 3 get add bmp 2 get bmp 4 get add mtrx transform
1231 /URY exch def /URX exch def
1237 bmp 0 get SpaceWidthRatio ratio div mul size div 0 % wx wy
1238 setcharwidth % We can't use setcachedevice here.
1240 bmp 1 get 0 gt bmp 2 get 0 gt and {
1241 bmp 1 get bmp 2 get % width height
1243 [ size 0 0 size neg bmp 3 get neg bmp 2 get bmp 4 get add ] % matrix
1244 bmp 5 1 getinterval cvx % datasrc
1251 1 index /Encoding get exch get
1252 1 index /BuildGlyph get exec
1255 %% Bitmap font creator
1257 %% Common Encoding shared by all bitmap fonts.
1258 /EncodingCommon 256 array def
1259 %% Mapping table from character name to character code.
1260 /NameIndexDict 256 dict def
1263 /idxname idx 256 add 16 (XXX) cvrs dup 0 67 put cvn def % `C' == 67
1264 EncodingCommon idx idxname put
1265 NameIndexDict idxname idx put
1268 /GlobalFontIndex 0 def
1270 %% fontname dim col fontsize relative-compose baseline-offset fbbx |- --
1274 /BaselineOffset exch def
1275 /RelativeCompose exch def
1277 /FontBBox [ FontBBox { FontSize div } forall ] def
1278 FontBBox 2 get FontBBox 0 get sub exch div
1279 /FontSpaceWidthRatio exch def
1280 /FontDimension exch def
1281 /FontIndex GlobalFontIndex def
1283 /FontMatrix matrix def
1284 /Encoding EncodingCommon def
1285 /BuildGlyph { BuildGlyphCommon } def
1286 /BuildChar { BuildCharCommon } def
1289 /GlobalFontIndex GlobalFontIndex 1 add def
1292 %% Define a new bitmap font.
1293 %% fontname dim col fontsize relative-compose baseline-offset fbbx |- --
1296 %% Convert BDF's FontBoundingBox to PostScript's FontBBox
1297 [ fbbx 2 get fbbx 3 get
1298 fbbx 2 get fbbx 0 get add fbbx 3 get fbbx 1 get add ]
1302 %% Define a glyph for the specified font and character.
1303 /NG { % fontname charcode bitmap-data |- --
1305 exch findfont dup /BaselineOffset get bmp 4 get add bmp exch 4 exch put
1307 dup 256 idiv exch 256 mod GlobalCharName
1310 %%%% End of bitmap font handler
1314 ;; External library support.
1316 ;; The following three functions are to be called from external
1317 ;; libraries which support bitmap fonts (e.g. `bdf') to get
1318 ;; appropriate PostScript code.
1320 (defun ps-mule-generate-bitmap-prologue ()
1321 (unless ps-mule-bitmap-prologue-generated
1322 (setq ps-mule-bitmap-prologue-generated t
)
1323 (list ps-mule-bitmap-prologue
)))
1325 (defun ps-mule-generate-bitmap-font (&rest args
)
1326 (list (apply 'format
"/%s %d %d %f %S %d %S NF\n" args
)))
1328 (defun ps-mule-generate-bitmap-glyph (font-name code dwidth bbx bitmap
)
1329 (format "/%s %d [ %d %d %d %d %d <%s> ] NG\n"
1331 dwidth
(aref bbx
0) (aref bbx
1) (aref bbx
2) (aref bbx
3)
1334 ;; Mule specific initializers.
1337 (defun ps-mule-initialize ()
1338 "Initialize global data for printing multi-byte characters."
1339 (setq ps-mule-font-cache nil
1340 ps-mule-prologue-generated nil
1341 ps-mule-composition-prologue-generated nil
1342 ps-mule-bitmap-prologue-generated nil
)
1343 (mapcar `(lambda (x) (setcar (nthcdr 2 x
) nil
))
1344 ps-mule-external-libraries
))
1346 (defvar ps-mule-header-charsets nil
)
1349 (defun ps-mule-encode-header-string (string fonttag
)
1350 "Generate PostScript code for ploting STRING by font FONTTAG.
1351 FONTTAG should be a string \"/h0\" or \"/h1\"."
1352 (setq string
(if (multibyte-string-p string
)
1353 (copy-sequence string
)
1354 (string-make-multibyte string
)))
1355 (when ps-mule-header-charsets
1356 (if (eq (car ps-mule-header-charsets
) 'latin-iso8859-1
)
1357 ;; Latin1 characters can be printed by the standard PostScript
1358 ;; font. Converts the other non-ASCII characters to `?'.
1359 (let ((len (length string
)))
1361 (or (memq (char-charset (aref string i
)) '(ascii latin-iso8859-1
))
1362 (aset string i ??
)))
1363 (setq string
(encode-coding-string string
'iso-latin-1
)))
1364 ;; We must prepare a font for the first non-ASCII and non-Latin1
1365 ;; character in STRING.
1366 (let* ((ps-current-font (if (string= fonttag
"/h0") 0 1))
1367 (ps-mule-current-charset (car ps-mule-header-charsets
))
1368 (font-type (car (nth ps-current-font
1369 (ps-font-alist 'ps-font-for-header
))))
1370 (font-spec (ps-mule-get-font-spec ps-mule-current-charset
1372 (if (or (not font-spec
)
1373 (/= (charset-dimension ps-mule-current-charset
) 1))
1374 ;; We don't have a proper font, or we can't print them on
1375 ;; header because this kind of charset is not ASCII
1377 (let ((len (length string
)))
1379 (or (memq (char-charset (aref string i
))
1380 '(ascii latin-iso8859-1
))
1381 (aset string i ??
)))
1382 (setq string
(encode-coding-string string
'iso-latin-1
)))
1383 (let ((charsets (list 'ascii
(car ps-mule-header-charsets
)))
1384 (len (length string
)))
1386 (or (memq (char-charset (aref string i
)) charsets
)
1387 (aset string i ??
))))
1388 (setq string
(ps-mule-string-encoding font-spec string nil t
))))))
1392 (defun ps-mule-header-string-charsets ()
1393 "Return a list of character sets that appears in header strings."
1395 len charset charset-list
)
1396 (when ps-print-header
1397 (dolist (tail (list ps-left-header ps-right-header
))
1398 ;; Simulate what is done by ps-generate-header-line to get a
1402 (if (< count ps-header-lines
)
1403 (setq str
(concat str
(cond ((stringp elt
) elt
)
1404 ((and (symbolp elt
) (fboundp elt
))
1406 ((and (symbolp elt
) (boundp elt
))
1409 count
(1+ count
)))))))
1410 (setq len
(length str
))
1412 (setq charset
(char-charset (aref str i
)))
1413 (or (eq charset
'ascii
)
1414 (memq charset charset-list
)
1415 (setq charset-list
(cons charset charset-list
))))
1419 (defun ps-mule-begin-job (from to
)
1420 "Start printing job for multi-byte chars between FROM and TO.
1421 This checks if all multi-byte characters in the region are printable or not."
1422 (setq ps-mule-charset-list nil
1423 ps-mule-header-charsets nil
1424 ps-mule-font-info-database
1425 (cond ((eq ps-multibyte-buffer
'non-latin-printer
)
1426 ps-mule-font-info-database-ps
)
1427 ((eq ps-multibyte-buffer
'bdf-font
)
1428 ps-mule-font-info-database-bdf
)
1429 ((eq ps-multibyte-buffer
'bdf-font-except-latin
)
1430 ps-mule-font-info-database-ps-bdf
)
1432 ps-mule-font-info-database-default
)))
1433 (and (boundp 'enable-multibyte-characters
)
1434 enable-multibyte-characters
1435 ;; Initialize `ps-mule-charset-list'. If some characters aren't
1436 ;; printable, warn it.
1437 (let ((charsets (find-charset-region from to
)))
1438 (setq charsets
(delq 'ascii
(delq 'unknown
(delq nil charsets
)))
1439 ps-mule-charset-list charsets
)
1442 (and (search-forward "\200" to t
)
1443 (setq ps-mule-charset-list
1444 (cons 'composition ps-mule-charset-list
))))
1445 ;; We also have to check non-ASCII charsets in the header strings.
1446 (let ((tail (ps-mule-header-string-charsets)))
1448 (unless (eq (car tail
) 'ascii
)
1449 (setq ps-mule-header-charsets
1450 (cons (car tail
) ps-mule-header-charsets
))
1451 (or (memq (car tail
) charsets
)
1452 (setq charsets
(cons (car tail
) charsets
))))
1453 (setq tail
(cdr tail
))))
1457 ((or (eq (car charsets
) 'composition
)
1458 (ps-mule-printable-p (car charsets
)))
1461 "Font for some characters not found, continue anyway? ")
1464 (error "Printing cancelled")))))))
1466 (setq ps-mule-current-charset
'ascii
)
1468 (if (and (nth 2 (find-composition from to
))
1469 (not ps-mule-composition-prologue-generated
))
1471 (ps-mule-prologue-generated)
1472 (ps-output-prologue ps-mule-composition-prologue
)
1473 (setq ps-mule-composition-prologue-generated t
)))
1475 (if (or ps-mule-charset-list ps-mule-header-charsets
)
1476 (let ((the-list (append ps-mule-header-charsets ps-mule-charset-list
))
1478 (ps-mule-prologue-generated)
1479 ;; If external functions are necessary, generate prologues for them.
1481 (setq elt
(car the-list
)
1482 the-list
(cdr the-list
))
1483 (cond ((and (eq elt
'composition
)
1484 (not ps-mule-composition-prologue-generated
))
1485 (ps-output-prologue ps-mule-composition-prologue
)
1486 (setq ps-mule-composition-prologue-generated t
))
1487 ((setq font-spec
(ps-mule-get-font-spec elt
'normal
))
1488 (ps-mule-init-external-library font-spec
))))))
1490 ;; If ASCII font is also specified in ps-mule-font-info-database,
1491 ;; use it instead of what specified in ps-font-info-database.
1492 (let ((font-spec (ps-mule-get-font-spec 'ascii
'normal
)))
1495 (ps-mule-prologue-generated)
1496 (ps-mule-init-external-library font-spec
)
1497 (let ((font (ps-font-alist 'ps-font-for-text
))
1498 (ps-current-font 0))
1500 ;; Be sure to download a glyph for SPACE in advance.
1501 (ps-mule-prepare-font (ps-mule-get-font-spec 'ascii
(car font
))
1502 " " 'ascii
'no-setfont
)
1503 (setq font
(cdr font
)
1504 ps-current-font
(1+ ps-current-font
)))))))
1506 ;; If the header contains non-ASCII and non-Latin1 characters, prepare a font
1507 ;; and glyphs for the first occurance of such characters.
1508 (if (and ps-mule-header-charsets
1509 (not (eq (car ps-mule-header-charsets
) 'latin-iso8859-1
)))
1510 (let ((font-spec (ps-mule-get-font-spec (car ps-mule-header-charsets
)
1513 ;; Be sure to download glyphs for "0123456789/" in advance for page
1515 (let ((ps-current-font 0))
1516 (ps-mule-prepare-font font-spec
"0123456789/" 'ascii t t
)))))
1518 (if ps-mule-charset-list
1519 ;; We must change this regexp for multi-byte buffer.
1520 (setq ps-control-or-escape-regexp
1521 (cond ((eq ps-print-control-characters
'8-bit
)
1523 ((eq ps-print-control-characters
'control-8-bit
)
1524 (string-as-multibyte "[^\040-\176\240-\377]"))
1525 ((eq ps-print-control-characters
'control
)
1526 (string-as-multibyte "[^\040-\176\200-\377]"))
1527 (t (string-as-multibyte "[^\000-\011\013\015-\377]"))))))
1530 (defun ps-mule-begin-page ()
1531 (setq ps-mule-current-charset
'ascii
))
1536 ;;; ps-mule.el ends here