Mercurial > hg > xemacs-beta
comparison lisp/tl/bitmap.el @ 4:b82b59fe008d r19-15b3
Import from CVS: tag r19-15b3
author | cvs |
---|---|
date | Mon, 13 Aug 2007 08:46:56 +0200 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
3:30df88044ec6 | 4:b82b59fe008d |
---|---|
1 ;; bitmap.el -- bitmap (xbm) file handler on Mule | |
2 | |
3 ;; Copyright (C) 1992 Electrotechnical Laboratory, JAPAN. | |
4 ;; Copyright (C) 1996 UENO Hiroshi | |
5 ;; Copyright (C) 1996 MORIOKA Tomohiko | |
6 | |
7 ;; Author: Ken'ichi HANDA <handa@etl.go.jp> | |
8 ;; Hiroshi Ueno <jl07715@yamato.ibm.co.jp> | |
9 ;; MORIOKA Tomohiko <morioka@jaist.ac.jp> | |
10 ;; Version: | |
11 ;; $Id: bitmap.el,v 1.1.1.1 1996/12/18 03:55:31 steve Exp $ | |
12 ;; Keywords: bitmap, xbm, X-Face, Mule | |
13 | |
14 ;; This file is part of tl (Tiny Library). | |
15 | |
16 ;; This program is free software; you can redistribute it and/or modify | |
17 ;; it under the terms of the GNU General Public License as published by | |
18 ;; the Free Software Foundation; either version 2, or (at your option) | |
19 ;; any later version. | |
20 | |
21 ;; This program is distributed in the hope that it will be useful, | |
22 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
23 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
24 ;; GNU General Public License for more details. | |
25 | |
26 ;; You should have received a copy of the GNU General Public License | |
27 ;; along with this program; if not, write to the Free Software | |
28 ;; Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | |
29 | |
30 ;; Code: | |
31 | |
32 (require 'tl-822) | |
33 | |
34 (defvar lc-bitmap | |
35 (new-private-character-set 2 1 3 0 ?0 0 "BITMAP 8x16" "bitmap") | |
36 "Leading character for BITMAP.8x16.") | |
37 | |
38 (mapcar (lambda (fontset) | |
39 (if (= (fontset-pixel-size fontset) 16) | |
40 (set-fontset-font | |
41 fontset lc-bitmap | |
42 "-etl-fixed-medium-r-*--16-*-100-100-m-*-bitmap.8x16-0") | |
43 )) | |
44 (fontset-list)) | |
45 | |
46 ;; Block (all bits set) character | |
47 (defvar bitmap-block (make-character lc-bitmap 32 33)) | |
48 | |
49 ;; Simple examples: | |
50 ;; (bitmap-compose "00FF00FF00FF00FF00FF00FF00FF00FF") | |
51 ;; (bitmap-compose | |
52 ;; "FF00FF00FF00FF00FF00FF00FF00FF00AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA") | |
53 | |
54 (defun read-hexa (str) | |
55 (let ((result 0) (i 0) (max (length str))) | |
56 (while (< i max) | |
57 (let ((ch (aref str i))) | |
58 (cond((and (<= ?0 ch) (<= ch ?9)) | |
59 (setq result (+ (* result 16) (- ch ?0)))) | |
60 ((and (<= ?a ch) (<= ch ?f)) | |
61 (setq result (+ (* result 16) (+ (- ch ?a) 10)))) | |
62 ((and (<= ?A ch) (<= ch ?F)) | |
63 (setq result (+ (* result 16) (+ (- ch ?A) 10))))) | |
64 (setq i (1+ i)))) | |
65 result)) | |
66 | |
67 (defun bitmap-compose (hex) | |
68 "Return a string of composite characters which represents BITMAP-PATTERN. | |
69 BITMAP-PATTERN is a string of hexa decimal for 8x16 dot-pattern. | |
70 For example the pattern \"0081814242242442111124244242818100\" is | |
71 for a bitmap of shape something like 'X' character." | |
72 (let* ((len (/ (length hex) 2)) | |
73 (bytes (char-bytes lc-bitmap)) | |
74 (cmpstr "") | |
75 (buf (make-string 64 0)) | |
76 block-flag i j row code c1 c2) | |
77 (setq i 0 j 0 block-flag t) | |
78 (while (< i len) | |
79 (setq row (read-hexa (substring hex (* i 2) (+ (* i 2) 2)))) | |
80 (if block-flag | |
81 (setq block-flag (= row 255))) | |
82 (if (/= row 0) | |
83 (progn | |
84 (setq code (+ (* (% i 16) 255) row -1)) | |
85 (setq c1 (+ (/ code 96) 33) | |
86 c2 (+ (% code 96) 32)) | |
87 (sset buf j (make-character lc-bitmap c1 c2)) | |
88 (setq j (+ j bytes)))) | |
89 (setq i (1+ i)) | |
90 (if (or (= (% i 16) 0) (>= i len)) | |
91 (setq cmpstr | |
92 (concat cmpstr | |
93 (if (and block-flag (= j 64)) | |
94 (char-to-string bitmap-block) | |
95 (if (= j 0) | |
96 " " | |
97 (compose-string (substring buf 0 j))))) | |
98 block-flag t | |
99 j 0))) | |
100 cmpstr)) | |
101 | |
102 | |
103 ;;; @ BDF | |
104 ;;; | |
105 | |
106 ;; Internal variables -- declared here to reduce garbage collection. | |
107 (defconst *hex* (vector (make-string 96 0) (make-string 96 0))) | |
108 (defconst *hex-len* (length *hex*)) | |
109 (defconst *cmp* (make-vector *hex-len* nil)) | |
110 | |
111 (defun bdf-to-bitmap (bdf) | |
112 "Set *cmp* a vector of string for BDF. | |
113 BDF is a vector of string, each elements corresponds to a line of bitmap | |
114 of difinition of a character glyph in bdf file." | |
115 (let ((width (length (aref bdf 0))) | |
116 (height (length bdf)) | |
117 i j) | |
118 (if (or (/= (/ (+ height 15) 16) *hex-len*) | |
119 (/= width (length (aref *hex* 0)))) | |
120 (progn | |
121 (setq *hex-len* (/ (+ height 15) 16)) | |
122 (setq *hex* (make-vector *hex-len* nil)) | |
123 (setq *cmp* (make-vector *hex-len* nil)) | |
124 (setq i 0) | |
125 (while (< i *hex-len*) | |
126 (aset *hex* i (make-string 96 0)) | |
127 (setq i (1+ i))))) | |
128 (setq j 0) | |
129 (while (< j width) | |
130 (setq i 0) | |
131 (while (< i (* *hex-len* 16)) | |
132 (aset (aref *hex* (/ i 16)) | |
133 (+ (* (/ j 2) 32) (* (% i 16) 2) (% j 2)) | |
134 (if (< i height) (aref (aref bdf i) j) 0)) | |
135 (setq i (1+ i))) | |
136 (setq j (1+ j))) | |
137 (setq i 0) | |
138 (while (< i *hex-len*) | |
139 (aset *cmp* i (bitmap-compose (aref *hex* i))) | |
140 (setq i (1+ i))) | |
141 *cmp* | |
142 )) | |
143 | |
144 | |
145 ;;; @ XBM | |
146 ;;; | |
147 | |
148 (defun bitmap-show-xbm (buf) | |
149 "Show bitmap in buffer BUF. Very slow! [bitmap.el]" | |
150 (let ((hexa-string "0123456789ABCDEF") | |
151 (reverse-bit '[0 8 4 12 2 10 6 14 1 9 5 13 3 11 7 15]) | |
152 i j w h bitmap cmp c temp) | |
153 (save-excursion | |
154 (set-buffer buf) | |
155 (goto-char 1) | |
156 (search-forward "width " nil t) | |
157 (setq w (read (current-buffer))) | |
158 (goto-char 1) | |
159 (search-forward "height " nil t) | |
160 (setq h (read (current-buffer))) | |
161 (search-forward "0x" nil t) | |
162 (setq bitmap (make-vector h 0)) | |
163 (setq cmp (make-vector (/ (+ h 15) 16) nil)) | |
164 (setq j 0) | |
165 (setq w (/ (+ w 7) 8)) | |
166 (while (< j h) | |
167 (aset bitmap j (make-vector w 0)) | |
168 (setq j (1+ j))) | |
169 (setq j 0) | |
170 (message "%dx%d" w h) | |
171 (while (< j h) | |
172 (setq i 0) | |
173 (while (< i w) | |
174 (setq temp (buffer-substring (point) (+ (point) 2))) | |
175 (aset (aref bitmap j) i temp) | |
176 (setq c (read-hexa temp)) | |
177 (aset temp 0 (aref hexa-string (aref reverse-bit (% c 16)))) | |
178 (aset temp 1 (aref hexa-string (aref reverse-bit (/ c 16)))) | |
179 (setq i (1+ i)) | |
180 (search-forward "0x" nil t)) | |
181 (setq j (1+ j))) | |
182 (message "bitmap translating...") | |
183 (setq i 0) | |
184 (while (< i w) | |
185 (setq j 0) | |
186 (while (< j h) | |
187 (aset cmp (/ j 16) | |
188 (concat (aref cmp (/ j 16)) | |
189 (aref (aref bitmap j) i))) | |
190 (setq j (1+ j))) | |
191 (if (> (% h 16) 0) | |
192 (aset cmp (/ h 16) | |
193 (concat (aref cmp (/ h 16)) | |
194 (make-string (* (- 16 (% h 16)) 2) ?0)))) | |
195 (setq i (1+ i))) | |
196 (message "cmp created")) | |
197 (setq j 0) | |
198 (while (< j (length cmp)) | |
199 (insert (bitmap-compose (aref cmp j)) ?\n) | |
200 ;;(insert (aref cmp j) ?\n) | |
201 (setq j (1+ j))))) | |
202 | |
203 (defun bitmap-read-xbm (file) | |
204 "Read .xbm file and show the bitmap. | |
205 Very slow! [bitmap.el]" | |
206 (interactive "fBitmap-file: ") | |
207 (bitmap-show-xbm (find-file-noselect (expand-file-name file))) | |
208 ) | |
209 | |
210 | |
211 ;;; @ X-Face | |
212 ;;; | |
213 | |
214 (defvar bitmap-uncompface-program "uncompface") | |
215 | |
216 (defun bitmap-decode-x-face () | |
217 (save-restriction | |
218 (rfc822/narrow-to-header) | |
219 (goto-char (point-min)) | |
220 (if (re-search-forward "^X-Face:[ \t]*" nil t) | |
221 (let ((p (match-beginning 0)) | |
222 (beg (match-end 0)) | |
223 (end (rfc822/field-end)) | |
224 (cur-buf (current-buffer)) | |
225 ) | |
226 (if (< end (point-max)) | |
227 (setq end (1+ end)) | |
228 ) | |
229 (save-restriction | |
230 (narrow-to-region p end) | |
231 (delete-region p beg) | |
232 (call-process-region p (point-max) | |
233 bitmap-uncompface-program t t nil) | |
234 (let (i k k+6 cmp temp) | |
235 (goto-char (point-min)) | |
236 (search-forward "0x" nil t) | |
237 (setq cmp (make-vector 18 nil)) | |
238 (setq i 0) | |
239 (while (< i 48) | |
240 (setq k (* (/ i 16) 6)) | |
241 (setq k+6 (+ k 6)) | |
242 (while (< k k+6) | |
243 (setq temp (buffer-substring (point) (+ (point) 2))) | |
244 (aset cmp k (concat (aref cmp k) temp)) | |
245 (setq k (1+ k)) | |
246 (setq temp (buffer-substring (+ (point) 2) (+ (point) 4))) | |
247 (aset cmp k (concat (aref cmp k) temp)) | |
248 (setq k (1+ k)) | |
249 (search-forward "0x" nil t) | |
250 ) | |
251 (setq i (1+ i))) | |
252 (delete-region (point-min)(point-max)) | |
253 (insert "X-Face: ") | |
254 (setq k 0) | |
255 (while (< k 6) | |
256 (insert (bitmap-compose (aref cmp k))) | |
257 (setq k (1+ k)) | |
258 ) | |
259 (insert ?\n) | |
260 (setq i 1) | |
261 (while (< i 3) | |
262 (insert " ") | |
263 (setq k (* i 6) | |
264 k+6 (+ k 6)) | |
265 (while (< k k+6) | |
266 (insert (bitmap-compose (aref cmp k))) | |
267 (setq k (1+ k)) | |
268 ) | |
269 (insert ?\n) | |
270 (setq i (1+ i)) | |
271 ))))))) | |
272 | |
273 | |
274 ;;; @ end | |
275 ;;; | |
276 | |
277 (provide 'bitmap) | |
278 | |
279 ;;; bitmap.el ends here |