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