ps-mule.el 42 KB

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