Revision: 1.2 - (view) (download)
1 : | ktanaka | 1.1 | (declare (crypt_r crypt_c1 crypt_c2) special) |
2 : | (setq crypt_r 4330) | ||
3 : | (setq crypt_c1 52845) | ||
4 : | (setq crypt_c2 22719) | ||
5 : | (defun init_crypt () | ||
6 : | (setq crypt_r 4330)) | ||
7 : | ; | ||
8 : | (defun putc_crypt (c) | ||
9 : | (let ((cipher (logand 255 (logxor c (logshift crypt_r -8))))) | ||
10 : | (setq crypt_r (remainder (plus crypt_c2 (times crypt_c1 (plus cipher crypt_r))) 65536)) | ||
11 : | (string (hex2 cipher)))) | ||
12 : | ; | ||
13 : | (defun put_int (val) | ||
14 : | (cond ((<= -107 val 107) | ||
15 : | (putc_crypt (+ val 139))) | ||
16 : | ((<= 108 val 1131) | ||
17 : | (string-append | ||
18 : | (putc_crypt (+ 247 (// (- val 108) 256))) | ||
19 : | (putc_crypt (\ (- val 108) 256)))) | ||
20 : | ((<= -1131 val -108) | ||
21 : | (string-append | ||
22 : | (putc_crypt (+ 251 (// (- (+ val 108)) 256))) | ||
23 : | (putc_crypt (\ (- (+ val 108)) 256)))) | ||
24 : | (t | ||
25 : | (print `(error ,val) terminal-output) | ||
26 : | (break)))) | ||
27 : | ; | ||
28 : | (defun long-hex-image (n) | ||
29 : | (cond ((lessp n 16)(string (hex-image-char n))) | ||
30 : | (t (string-append (long-hex-image (quotient n 16)) | ||
31 : | (string (hex-image-char (remainder n 16))))))) | ||
32 : | ; | ||
33 : | (defun hex2 (n) | ||
34 : | (string-append (string (hex-image-char (quotient n 16))) | ||
35 : | (string (hex-image-char (remainder n 16))))) | ||
36 : | ; | ||
37 : | ; Adobe Type1 Font Format ¤Î½ÐÎÏ | ||
38 : | ; | ||
39 : | (defun klist2type1 (klist tag (fontfile)) | ||
40 : | (let ((standard-output (cond (fontfile (outopen (stream fontfile))) | ||
41 : | (t standard-output)))) | ||
42 : | (do ((l klist (cdr l)) | ||
43 : | (outline) | ||
44 : | (kanji)) | ||
45 : | ((atom l)(and fontfile (close standard-output))) | ||
46 : | (setq kanji (car l)) | ||
47 : | (format "/c/c ;/c/n" | ||
48 : | (long-hex-image (logand 127 (sref kanji 0))) | ||
49 : | (long-hex-image (logand 127 (sref kanji 1))) | ||
50 : | kanji) | ||
51 : | (princ (out2type1 (makeoutline | ||
52 : | (skelton2list (applykanji (car l)) tag))))))) | ||
53 : | (setq type1max 1000) | ||
54 : | (setq type1ratio 2.5) | ||
55 : | (defun skelton2type1 (kanji type) | ||
56 : | (lets ((meshsize 0.4) | ||
57 : | (skelton (normkanji (applykanji kanji type))) | ||
58 : | (outline (skelton2list skelton type)) | ||
59 : | (hints (type1hints skelton type))) | ||
60 : | (out2type1 outline hints))) | ||
61 : | (defun out2type1 (outline (hints)) | ||
62 : | (cond | ||
63 : | ((atom outline)) | ||
64 : | (t | ||
65 : | (init_crypt) | ||
66 : | (let ((retstr (string-append "<" (putc_crypt 0)(putc_crypt 0) | ||
67 : | (putc_crypt 0)(putc_crypt 0) | ||
68 : | (put_int 0)(put_int 1000)(putc_crypt 13)))) | ||
69 : | (do ((l hints (cdr l))(base)(width)) | ||
70 : | ((atom l)) | ||
71 : | (cond ((eq 'v (caar l)) | ||
72 : | ; (print (car l)) | ||
73 : | (setq base (fix (times type1ratio (cadar l)))) | ||
74 : | (setq width (- (fix (times type1ratio (cddar l))) base)) | ||
75 : | ; (print `(vstem ,base ,width)) | ||
76 : | (setq retstr (string-append retstr | ||
77 : | (put_int base) | ||
78 : | (put_int width) | ||
79 : | (putc_crypt 3)))) | ||
80 : | ((eq 'h (caar l)) | ||
81 : | ; (print (car l)) | ||
82 : | (setq base (- type1max (fix (times type1ratio (cddar l))))) | ||
83 : | (setq width (- (- type1max (fix (times type1ratio (cadar l)))) | ||
84 : | base)) | ||
85 : | ; (print `(hstem ,base ,width)) | ||
86 : | (setq retstr (string-append retstr | ||
87 : | (put_int base) | ||
88 : | (put_int width) | ||
89 : | (putc_crypt 1)))))) | ||
90 : | (do ((ll outline (cdr ll)) | ||
91 : | (next)(nextnext) | ||
92 : | (curx 0)(cury 0)(newx)(newy)(dx1)(dy1)(dx2)(dy2)(dx3)(dy3)(last)); | ||
93 : | ((atom ll)) | ||
94 : | (and (car ll) | ||
95 : | (setq last (caar ll)) | ||
96 : | (setq newx (fix (times type1ratio (cadr last))) | ||
97 : | newy (- type1max (fix (times type1ratio (caddr last))))) | ||
98 : | ; (print `(moveto ,newx ,newy)) | ||
99 : | (cond ((eq newx curx) | ||
100 : | (setq retstr (string-append retstr | ||
101 : | (put_int (- newy cury)) | ||
102 : | (putc_crypt 4)))) | ||
103 : | ((eq newy cury) | ||
104 : | (setq retstr (string-append retstr (put_int (- newx curx)) | ||
105 : | (putc_crypt 22)))) | ||
106 : | (t | ||
107 : | (setq retstr (string-append retstr (put_int (- newx curx)) | ||
108 : | (put_int (- newy cury)) | ||
109 : | (putc_crypt 21))))) | ||
110 : | (setq curx newx cury newy) | ||
111 : | (do ((lll (cdar ll) (cdr lll))) | ||
112 : | ((atom lll)) | ||
113 : | (match | ||
114 : | (car lll) | ||
115 : | (('angle x y) | ||
116 : | (setq newx (fix (times type1ratio x)) | ||
117 : | newy (- type1max (fix (times type1ratio y)))) | ||
118 : | ; (print `(lineto ,newx ,newy)) | ||
119 : | (cond ((eq newx curx) | ||
120 : | (setq retstr (string-append retstr (put_int (- newy cury)) | ||
121 : | (putc_crypt 7)))) | ||
122 : | ((eq newy cury) | ||
123 : | (setq retstr (string-append retstr (put_int (- newx curx)) | ||
124 : | (putc_crypt 6)))) | ||
125 : | (t (setq retstr (string-append retstr (put_int (- newx curx)) | ||
126 : | (put_int (- newy cury)) | ||
127 : | (putc_crypt 5))))) | ||
128 : | (setq curx newx cury newy)) | ||
129 : | (('bezier x0 y0) | ||
130 : | (setq next (cadr lll)) | ||
131 : | (setq nextnext | ||
132 : | (cond ((cddr lll)(setq lll (cddr lll))(car lll)) | ||
133 : | (t (setq lll (cdr lll))last))) | ||
134 : | (setq newx (fix (times type1ratio x0)) newy (- type1max (fix (times type1ratio y0)))) | ||
135 : | (setq dx1 (- newx curx) dy1 (- newy cury)) | ||
136 : | (setq curx newx cury newy) | ||
137 : | (setq newx (fix (times type1ratio (cadr next))) | ||
138 : | newy (- type1max (fix (times type1ratio (caddr next))))) | ||
139 : | (setq dx2 (- newx curx) dy2 (- newy cury)) | ||
140 : | (setq curx newx cury newy) | ||
141 : | (setq newx (fix (times type1ratio (cadr nextnext))) | ||
142 : | newy (- type1max (fix (times type1ratio (caddr nextnext))))) | ||
143 : | (setq dx3 (- newx curx) dy3 (- newy cury)) | ||
144 : | ; (print `(curveto ,newx ,newy)) | ||
145 : | (setq curx newx cury newy) | ||
146 : | (cond ((and (zerop dx1)(zerop dy3)) | ||
147 : | (setq retstr (string-append retstr | ||
148 : | (put_int dy1)(put_int dx2) | ||
149 : | (put_int dy2)(put_int dx3) | ||
150 : | (putc_crypt 30)))) | ||
151 : | ((and (zerop dy1)(zerop dx3)) | ||
152 : | (setq retstr (string-append retstr | ||
153 : | (put_int dx1)(put_int dx2) | ||
154 : | (put_int dy2)(put_int dy3) | ||
155 : | (putc_crypt 31)))) | ||
156 : | (t | ||
157 : | (setq retstr (string-append retstr | ||
158 : | (put_int dx1)(put_int dy1) | ||
159 : | (put_int dx2)(put_int dy2) | ||
160 : | (put_int dx3)(put_int dy3) | ||
161 : | (putc_crypt 8)))))))))) | ||
162 : | (string-append retstr | ||
163 : | (putc_crypt 9)(putc_crypt 14)">"))))) | ||
164 : | |||
165 : | ; | ||
166 : | (defun type1hints (skelton type) | ||
167 : | (lets ((points (car skelton)) | ||
168 : | (elements (cadr skelton)) | ||
169 : | (hints)) | ||
170 : | (do ((l elements (cdr l))(element)(eltype)(elpoints nil nil)) | ||
171 : | ((atom l)) | ||
172 : | (setq element (car l)) | ||
173 : | (setq eltype (car element)) | ||
174 : | (setq elhint (and (setq type1list (get eltype 'type1)) | ||
175 : | (do ((ll type (get ll 'parent))(ret)) | ||
176 : | ((null ll)) | ||
177 : | (and (setq ret (assq ll type1list))(exit ret))))) | ||
178 : | (cond (elhint | ||
179 : | (do ((ll (cadr element)(cdr ll))(hint)) | ||
180 : | ((atom ll)(setq elpoints (nreverse elpoints))) | ||
181 : | (push (nth (car ll) points) elpoints)) | ||
182 : | (setq hint (funcall (cdr elhint) elpoints)) | ||
183 : | ; (prind `(,element ,elhint ,elpoints ,hint)) | ||
184 : | (and hint (setq hints (nconc hint hints)))))) | ||
185 : | (setq hints (sort hints #'(lambda (x y) | ||
186 : | (cond ((eq (car x)(car y)) | ||
187 : | (cond ((equal (cadr x)(cadr y)) | ||
188 : | (lessp (cddr x)(cddr y))) | ||
189 : | (t | ||
190 : | (lessp (cadr x)(cadr y))))) | ||
191 : | (t | ||
192 : | (eq (car x) 'h)))))) | ||
193 : | (do ((l hints (cdr l)) | ||
194 : | (ret)) | ||
195 : | ((atom l) ret) | ||
196 : | (cond ((and (cdr l) | ||
197 : | (eq (caar l)(caadr l)) | ||
198 : | (equal (cadr (car l))(cadr (cadr l)))) | ||
199 : | (push (car l) ret) | ||
200 : | (setq l (cdr l))) | ||
201 : | ((and (cdr l) | ||
202 : | (eq (caar l)(caadr l)) | ||
203 : | (equal (cddr (car l))(cddr (cadr l))))) | ||
204 : | ((and (cdr l) | ||
205 : | (eq (caar l)(caadr l)) | ||
206 : | (greaterp (cddr (car l))(cadr (cadr l)))) | ||
207 : | (setq l (cdr l))) | ||
208 : | (t (push (car l) ret)))))) |
ktanaka Powered by ViewCVS 1.0-dev |
ViewCVS and CVS Help |