annotate lisp/bdf.el @ 24270:02ae21f066ec

(imenu--last-menubar-index-alist): Add doc. (imenu-add-to-menubar): Reset imenu--last-menubar-index-alist.
author Richard M. Stallman <rms@gnu.org>
date Sat, 06 Feb 1999 21:50:53 +0000
parents ced1e63179e6
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
23169
ced1e63179e6 (bdf-generate-font): New argument CHARSET. Give WIDTH
Kenichi Handa <handa@m17n.org>
parents: 23093
diff changeset
1 ;;; bdf.el --- BDF font file handler for ps-print.
23093
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
3 ;; Copyright (C) 1998 Electrotechnical Laboratory, JAPAN.
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
4 ;; Licensed to the Free Software Foundation.
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
5
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
6 ;; Keywords: BDF, font, PostScript
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
7
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
8 ;; This file is part of GNU Emacs.
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
9
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
10 ;; GNU Emacs is free software; you can redistribute it and/or modify
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
11 ;; it under the terms of the GNU General Public License as published by
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
12 ;; the Free Software Foundation; either version 2, or (at your option)
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
13 ;; any later version.
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
14
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
15 ;; GNU Emacs is distributed in the hope that it will be useful,
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
18 ;; GNU General Public License for more details.
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
19
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
20 ;; You should have received a copy of the GNU General Public License
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
21 ;; along with GNU Emacs; see the file COPYING. If not, write to the
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
23 ;; Boston, MA 02111-1307, USA.
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
24
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
25 ;;; Commentary:
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
26
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
27 ;; Functions for getting bitmap information from X's BDF font file are
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
28 ;; provided.
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
29
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
30 ;;; Code:
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
31
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
32 (eval-when-compile (require 'ps-print))
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
33
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
34 (defvar bdf-directory-list
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
35 nil
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
36 "*List of directories to search for `BDF' font files.")
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
37
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
38 (defun bdf-expand-file-name (bdfname)
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
39 "Return an abosolute path name of a `BDF' font file BDFNAME.
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
40 It searches directories listed in the variable `bdf-directory-list'
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
41 for BDFNAME."
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
42 (if (file-name-absolute-p bdfname)
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
43 (if (file-readable-p bdfname)
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
44 bdfname)
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
45 (let ((l bdf-directory-list))
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
46 (catch 'tag
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
47 (while l
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
48 (if (file-readable-p (expand-file-name bdfname (car l)))
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
49 (throw 'tag (expand-file-name bdfname (car l))))
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
50 (setq l (cdr l)))))))
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
51
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
52 (defsubst bdf-file-mod-time (filename)
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
53 "Return modification time of FILENAME.
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
54 The value is a list of two integers, the first integer has high-order
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
55 16 bits, the second has low 16 bits."
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
56 (nth 5 (file-attributes filename)))
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
57
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
58 (defun bdf-file-newer-than-time (filename mod-time)
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
59 "Return non-nil if and only if FILENAME is newer than MOD-TIME.
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
60 MOD-TIME is a modification time as a list of two integers, the first
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
61 integer has high-order 16 bits, the second has low 16 bits."
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
62 (let ((new-mod-time (bdf-file-mod-time (bdf-expand-file-name filename))))
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
63 (or (> (car new-mod-time) (car mod-time))
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
64 (and (= (car new-mod-time) (car mod-time))
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
65 (> (nth 1 new-mod-time) (nth 1 mod-time))))))
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
66
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
67 (defun bdf-find-file (bdfname)
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
68 "Return a buffer visiting a bdf file BDFNAME.
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
69 If BDFNAME is not an absolute path, directories listed in
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
70 `bdf-directory-list' is searched.
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
71 If BDFNAME doesn't exist, return nil."
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
72 (let ((buf (generate-new-buffer " *bdf-work*"))
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
73 (coding-system-for-read 'no-conversion))
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
74 (save-excursion
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
75 (set-buffer buf)
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
76 (insert-file-contents (bdf-expand-file-name bdfname))
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
77 buf)))
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
78
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
79 (defvar bdf-cache-file "~/.bdfcache.el"
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
80 "Name of cache file which contains information of `BDF' font files.")
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
81
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
82 (defvar bdf-cache nil
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
83 "Cached information of `BDF' font files. It is a list of FONT-INFO.
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
84 FONT-INFO is a list of the following format:
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
85 (BDFFILE ABSOLUTE-PATH MOD-TIME SIZE FONT-BOUNDING-BOX
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
86 RELATIVE-COMPOSE BASELINE-OFFSET CODE-RANGE MAXLEN OFFSET-VECTOR)
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
87 See the documentation of the function `bdf-read-font-info' for more detail.")
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
88
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
89 (defun bdf-read-cache ()
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
90 "Return a cached information about `BDF' font files from a cache file.
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
91 The variable `bdf-cache-file' holds the cache file name.
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
92 If the cache file is not readable, this return nil."
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
93 (setq bdf-cache nil)
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
94 (condition-case nil
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
95 (if (file-readable-p bdf-cache-file)
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
96 (load-file bdf-cache-file))
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
97 (error nil))
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
98 (if (not (listp bdf-cache))
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
99 (setq bdf-cache nil)))
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
100
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
101 (defun bdf-write-cache ()
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
102 "Write out cached information of `BDF' font file to a file.
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
103 The variable `bdf-cache-file' holds the cache file name.
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
104 The file is written if and only if the file alreay exists and writable."
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
105 (if (and bdf-cache
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
106 (file-exists-p bdf-cache-file)
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
107 (file-writable-p bdf-cache-file))
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
108 (write-region (format "(setq bdf-cache '%S)\n" bdf-cache)
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
109 nil bdf-cache-file)))
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
110
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
111 (defun bdf-set-cache (font-info)
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
112 "Cache FONT-INFO as information about one `BDF' font file.
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
113 FONT-INFO is a list of the following format:
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
114 (BDFFILE ABSOLUTE-PATH MOD-TIME SIZE FONT-BOUNDING-BOX
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
115 RELATIVE-COMPOSE BASELINE-OFFSET CODE-RANGE MAXLEN OFFSET-VECTOR)
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
116 See the documentation of the function `bdf-read-font-info' for more detail."
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
117 (let ((slot (assoc (car font-info) bdf-cache)))
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
118 (if slot
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
119 (setcdr slot (cdr font-info))
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
120 (setq bdf-cache (cons font-info bdf-cache)))))
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
121
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
122 (defun bdf-initialize ()
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
123 "Initialize `bdf' library."
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
124 (if (bdf-read-cache)
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
125 (add-hook 'kill-emacs-hook 'bdf-write-cache)))
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
126
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
127 (defun bdf-compact-code (code code-range)
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
128 (if (or (< code (aref code-range 4))
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
129 (> code (aref code-range 5)))
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
130 (setq code (aref code-range 6)))
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
131 (+ (* (- (lsh code -8) (aref code-range 0))
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
132 (1+ (- (aref code-range 3) (aref code-range 2))))
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
133 (- (logand code 255) (aref code-range 2))))
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
134
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
135 (defun bdf-expand-code (code code-range)
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
136 (let ((code0-range (1+ (- (aref code-range 3) (aref code-range 2)))))
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
137 (+ (* (+ (/ code code0-range) (aref code-range 0)) 256)
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
138 (+ (% code code0-range) (aref code-range 2)))))
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
139
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
140 (defun bdf-read-font-info (bdfname)
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
141 "Read `BDF' font file BDFNAME and return information (FONT-INFO) of the file.
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
142 FONT-INFO is a list of the following format:
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
143 (BDFFILE ABSOLUTE-PATH MOD-TIME FONT-BOUNDING-BOX
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
144 RELATIVE-COMPOSE BASELINE-OFFSET CODE-RANGE MAXLEN OFFSET-VECTOR)
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
145
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
146 BDFFILE is a name of a font file (excluding directory part).
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
147
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
148 ABSOLUTE-PATH is an absolute path of the font file.
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
149
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
150 MOD-TIME is last modification time as a list of two integers, the
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
151 first integer has high-order 16 bits, the second has low 16 bits.
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
152
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
153 SIZE is a size of the font. This value is got from SIZE record of the
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
154 font.
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
155
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
156 FONT-BOUNDING-BOX is the font bounding box as a list of four integers,
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
157 BBX-WIDTH, BBX-HEIGHT, BBX-XOFF, and BBX-YOFF.
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
158
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
159 RELATIVE-COMPOSE is an integer value of the font's property
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
160 `_MULE_RELATIVE_COMPOSE'. If the font doesn't have this property, the
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
161 value is 0.
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
162
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
163 BASELINE-OFFSET is an integer value of the font's property
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
164 `_MULE_BASELINE_OFFSET'. If the font doesn't have this property, the
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
165 value is 0.
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
166
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
167 CODE-RANGE is a vector of minimum 1st byte, maximum 1st byte, minimum
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
168 2nd byte, maximum 2nd byte, minimum code, maximum code, and default
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
169 code. For 1-byte fonts, the first two elements are 0.
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
170
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
171 MAXLEN is a maximum bytes of one glyph informaion in the font file.
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
172
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
173 OFFSET-VECTOR is a vector of a file position which starts bitmap data
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
174 of the glyph in the font file.
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
175
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
176 Nth element of OFFSET-VECTOR is a file position for the glyph of code
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
177 CODE, where N and CODE are in the following relation:
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
178 (bdf-compact-code CODE) => N, (bdf-expand-code N) => CODE"
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
179 (let ((absolute-path (bdf-expand-file-name bdfname))
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
180 (maxlen 0)
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
181 size
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
182 font-bounding-box
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
183 (relative-compose 'false)
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
184 (baseline-offset 0)
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
185 default-char
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
186 code-range
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
187 offset-vector
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
188 buf)
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
189 (if absolute-path
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
190 (message "Reading %s..." bdfname)
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
191 (error "BDF file %s doesn't exist" bdfname))
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
192 (setq buf (bdf-find-file absolute-path))
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
193 (unwind-protect
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
194 (save-excursion
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
195 (set-buffer buf)
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
196 (goto-char (point-min))
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
197 (search-forward "\nFONTBOUNDINGBOX")
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
198 (setq font-bounding-box (vector (read (current-buffer))
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
199 (read (current-buffer))
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
200 (read (current-buffer))
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
201 (read (current-buffer))))
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
202 ;; The following kludgy code is to avoid bugs of fonts
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
203 ;; jiskan16.bdf and jiskan24.bdf distributed with X.
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
204 ;; They contain wrong FONTBOUNDINGBOX.
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
205 (if (and (> (aref font-bounding-box 3) 0)
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
206 (string-match "jiskan\\(16\\|24\\)" bdfname))
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
207 (aset font-bounding-box 3
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
208 (- (aref font-bounding-box 3))))
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
209
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
210 (goto-char (point-min))
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
211 (search-forward "\nSIZE ")
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
212 (setq size (read (current-buffer)))
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
213 ;; The following kludgy code is t avoid bugs of several
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
214 ;; fonts which have wrong SIZE record.
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
215 (if (<= size (/ (aref font-bounding-box 1) 2))
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
216 (setq size (aref font-bounding-box 1)))
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
217
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
218 (goto-char (point-min))
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
219 (if (search-forward "\nDEFAULT_CHAR" nil t)
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
220 (setq default-char (read (current-buffer))))
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
221
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
222 (search-forward "\nSTARTCHAR")
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
223 (forward-line -1)
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
224 (let ((limit (point)))
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
225 (goto-char (point-min))
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
226 (if (search-forward "\n_MULE_RELATIVE_COMPOSE" limit t)
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
227 (progn
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
228 (goto-char (match-end 0))
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
229 (setq relative-compose (read (current-buffer)))))
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
230 (goto-char (point-min))
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
231 (if (search-forward "\n_MULE_BASELINE_OFFSET" limit t)
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
232 (progn
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
233 (goto-char (match-end 0))
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
234 (setq baseline-offset (read (current-buffer))))))
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
235
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
236 (let ((min-code0 256) (min-code1 256) (max-code0 0) (max-code1 0)
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
237 (min-code 65536)
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
238 (max-code 0)
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
239 (glyph-list nil)
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
240 code bbx offset)
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
241 (while (search-forward "\nSTARTCHAR" nil t)
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
242 (setq offset (line-beginning-position))
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
243 (search-forward "\nENCODING")
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
244 (setq code (read (current-buffer)))
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
245 (let ((code0 (lsh code -8))
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
246 (code1 (logand code 255)))
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
247 (if (< code0 min-code0) (setq min-code0 code0)
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
248 (if (> code0 max-code0) (setq max-code0 code0)))
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
249 (if (< code1 min-code1) (setq min-code1 code1)
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
250 (if (> code1 max-code1) (setq max-code1 code1))))
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
251 (if (< code min-code)
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
252 (setq min-code code)
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
253 (if (> code max-code)
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
254 (setq max-code code)))
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
255 (search-forward "ENDCHAR")
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
256 (if (< maxlen (- (point) offset))
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
257 (setq maxlen (- (point) offset)))
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
258 (setq glyph-list (cons (cons code offset) glyph-list)))
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
259 (setq code-range
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
260 (vector min-code0 max-code0 min-code1 max-code1
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
261 min-code max-code (or default-char min-code)))
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
262 (setq offset-vector
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
263 (make-vector (1+ (bdf-compact-code max-code code-range))
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
264 nil))
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
265 (while glyph-list
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
266 (let ((glyph (car glyph-list)))
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
267 (aset offset-vector
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
268 (bdf-compact-code (car glyph) code-range)
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
269 (cdr glyph)))
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
270 (setq glyph-list (cdr glyph-list)))))
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
271 (kill-buffer buf))
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
272 (message "Reading %s...done" bdfname)
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
273 (list bdfname absolute-path (bdf-file-mod-time absolute-path)
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
274 size font-bounding-box relative-compose baseline-offset
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
275 code-range maxlen offset-vector)))
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
276
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
277 (defsubst bdf-info-absolute-path (font-info) (nth 1 font-info))
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
278 (defsubst bdf-info-mod-time (font-info) (nth 2 font-info))
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
279 (defsubst bdf-info-size (font-info) (nth 3 font-info))
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
280 (defsubst bdf-info-font-bounding-box (font-info) (nth 4 font-info))
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
281 (defsubst bdf-info-relative-compose (font-info) (nth 5 font-info))
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
282 (defsubst bdf-info-baseline-offset (font-info) (nth 6 font-info))
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
283 (defsubst bdf-info-code-range (font-info) (nth 7 font-info))
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
284 (defsubst bdf-info-maxlen (font-info) (nth 8 font-info))
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
285 (defsubst bdf-info-offset-vector (font-info) (nth 9 font-info))
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
286
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
287 (defun bdf-get-font-info (bdfname)
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
288 "Return information about `BDF' font file BDFNAME.
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
289 The value FONT-INFO is a list of the following format:
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
290 (BDFFILE ABSOLUTE-PATH MOD-TIME SIZE FONT-BOUNDING-BOX
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
291 RELATIVE-COMPOSE BASELINE-OFFSET CODE-RANGE MAXLEN OFFSET-VECTOR)
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
292 See the documentation of the function `bdf-read-font-info' for more detail."
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
293 (or bdf-cache
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
294 (bdf-read-cache))
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
295 (let ((font-info (assoc bdfname bdf-cache)))
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
296 (if (or (not font-info)
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
297 (not (file-readable-p (bdf-info-absolute-path font-info)))
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
298 (bdf-file-newer-than-time bdfname (bdf-info-mod-time font-info)))
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
299 (progn
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
300 (setq font-info (bdf-read-font-info bdfname))
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
301 (bdf-set-cache font-info)))
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
302 font-info))
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
303
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
304 (defun bdf-read-bitmap (bdfname offset maxlen)
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
305 "Read `BDF' font file BDFNAME to get bitmap data at file poistion OFFSET.
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
306 BDFNAME is an abosolute path name of the font file.
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
307 MAXLEN specifies how many bytes we should read at least.
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
308 The value is a list of DWIDTH, BBX, and BITMAP-STRING.
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
309 DWIDTH is a pixel width of a glyph.
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
310 BBX is a bounding box of the glyph.
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
311 BITMAP-STRING is a string representing bits by hexadecimal digits."
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
312 (let ((coding-system-for-read 'no-conversion)
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
313 dwidth bbx height yoff bitmap-string)
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
314 (condition-case nil
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
315 (with-temp-buffer
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
316 (insert-file-contents bdfname nil offset (+ offset maxlen))
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
317 (goto-char (point-min))
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
318 (search-forward "\nDWIDTH")
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
319 (setq dwidth (read (current-buffer)))
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
320 (goto-char (point-min))
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
321 (search-forward "\nBBX")
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
322 (setq bbx (vector (read (current-buffer)) (read (current-buffer))
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
323 (read (current-buffer)) (read (current-buffer))))
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
324 (setq height (aref bbx 1) yoff (aref bbx 3))
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
325 (search-forward "\nBITMAP")
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
326 (forward-line 1)
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
327 (delete-region (point-min) (point))
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
328 (if (looking-at "\\(0+\n\\)+")
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
329 (progn
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
330 (setq height
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
331 (- height (count-lines (point) (match-end 0))))
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
332 (delete-region (point) (match-end 0))))
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
333 (or (looking-at "ENDCHAR")
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
334 (progn
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
335 (search-forward "ENDCHAR" nil 'move)
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
336 (forward-line -1)
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
337 (while (looking-at "0+$")
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
338 (setq yoff (1+ yoff) height (1- height))
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
339 (forward-line -1))
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
340 (forward-line 1)))
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
341 (aset bbx 1 height)
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
342 (aset bbx 3 yoff)
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
343 (delete-region (point) (point-max))
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
344 (goto-char (point-min))
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
345 (while (not (eobp))
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
346 (end-of-line)
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
347 (delete-char 1))
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
348 (setq bitmap-string (buffer-string)))
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
349 (error nil))
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
350 (list dwidth bbx bitmap-string)))
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
351
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
352 (defun bdf-get-bitmaps (bdfname codes)
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
353 "Return bitmap information of glyphs of CODES in `BDF' font file BDFNAME.
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
354 CODES is a list of encoding number of glyphs in the file.
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
355 The value is a list of CODE, DWIDTH, BBX, and BITMAP-STRING.
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
356 DWIDTH is a pixel width of a glyph.
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
357 BBX is a bounding box of the glyph.
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
358 BITMAP-STRING is a string representing bits by hexadecimal digits."
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
359 (let* ((font-info (bdf-get-font-info bdfname))
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
360 (absolute-path (bdf-info-absolute-path font-info))
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
361 (font-bounding-box (bdf-info-font-bounding-box font-info))
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
362 (maxlen (bdf-info-maxlen font-info))
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
363 (code-range (bdf-info-code-range font-info))
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
364 (offset-vector (bdf-info-offset-vector font-info)))
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
365 (mapcar (function
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
366 (lambda (x)
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
367 (cons x (bdf-read-bitmap
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
368 absolute-path
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
369 (aref offset-vector (bdf-compact-code x code-range))
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
370 maxlen))))
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
371 codes)))
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
372
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
373 ;;; Interface to ps-print.el
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
374
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
375 ;; Called from ps-mule-init-external-library.
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
376 (defun bdf-generate-prologue ()
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
377 (or bdf-cache
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
378 (bdf-initialize))
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
379 (ps-mule-generate-bitmap-prologue))
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
380
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
381 ;; Called from ps-mule-generate-font.
23169
ced1e63179e6 (bdf-generate-font): New argument CHARSET. Give WIDTH
Kenichi Handa <handa@m17n.org>
parents: 23093
diff changeset
382 (defun bdf-generate-font (charset font-spec)
23093
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
383 (let* ((font-name (ps-mule-font-spec-name font-spec))
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
384 (font-info (bdf-get-font-info font-name)))
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
385 (ps-mule-generate-bitmap-font font-name
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
386 (ps-mule-font-spec-bytes font-spec)
23169
ced1e63179e6 (bdf-generate-font): New argument CHARSET. Give WIDTH
Kenichi Handa <handa@m17n.org>
parents: 23093
diff changeset
387 (charset-width charset)
23093
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
388 (bdf-info-size font-info)
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
389 (bdf-info-relative-compose font-info)
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
390 (bdf-info-baseline-offset font-info)
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
391 (bdf-info-font-bounding-box font-info))))
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
392
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
393 ;; Called from ps-mule-generate-glyphs.
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
394 (defun bdf-generate-glyphs (font-spec code-list bytes)
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
395 (let ((font-name (ps-mule-font-spec-name font-spec)))
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
396 (mapcar (function
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
397 (lambda (x)
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
398 (apply 'ps-mule-generate-bitmap-glyph font-name x)))
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
399 (bdf-get-bitmaps font-name code-list))))
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
400
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
401 (provide 'bdf)
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
402
bea8f793853d Initial revision
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
403 ;;; bdf.el ends here