Mercurial > mplayer.hg
comparison TOOLS/subfont-c/osd/gen.py @ 1505:842c29861e25
upgraded to 1.0b version by Artur Zaprzala <artur.zaprzala@talex.com.pl>
author | arpi |
---|---|
date | Mon, 13 Aug 2001 18:37:10 +0000 |
parents | |
children | 39119eb74363 |
comparison
equal
deleted
inserted
replaced
1504:f4f686aed404 | 1505:842c29861e25 |
---|---|
1 #!/usr/bin/python | |
2 | |
3 from math import * | |
4 import sys | |
5 import string | |
6 | |
7 k = (sqrt(2.)-1.)*4./3. | |
8 | |
9 chars = [] | |
10 encoding = [] | |
11 count = 1 | |
12 first = 1 | |
13 | |
14 def append(s): | |
15 chars.append(s) | |
16 | |
17 def rint(x): | |
18 return int(round(x)) | |
19 """ | |
20 if x>=0: | |
21 return int(x+0.5) | |
22 else: | |
23 return int(x-0.5) | |
24 """ | |
25 | |
26 class vec: | |
27 def __init__(self, x, y=0): | |
28 if type(x) is type(()): | |
29 self.x, self.y = x | |
30 else: | |
31 self.x = x | |
32 self.y = y | |
33 def set(self, x, y): | |
34 self.__init__(x, y) | |
35 def move(self, x, y): | |
36 self.x = self.x + x | |
37 self.y = self.y + y | |
38 def __add__(self, v): | |
39 return vec(self.x+v.x, self.y+v.y) | |
40 def __sub__(self, v): | |
41 return vec(self.x-v.x, self.y-v.y) | |
42 def int(self): | |
43 return vec(rint(self.x), rint(self.y)) | |
44 def t(self): | |
45 return (self.x, self.y) | |
46 | |
47 class pvec(vec): | |
48 def __init__(self, l, a): | |
49 self.x = l * cos(a) | |
50 self.y = l * sin(a) | |
51 | |
52 | |
53 pen = vec(0,0) | |
54 | |
55 def moveto(x, y=0): | |
56 global first | |
57 dx = rint(x-pen.x) | |
58 dy = rint(y-pen.y) | |
59 if dx!=0: | |
60 if dy!=0: | |
61 append("\t%i %i rmoveto" % (dx, dy)) | |
62 else: | |
63 append("\t%i hmoveto" % (dx)) | |
64 elif dy!=0: | |
65 append("\t%i vmoveto" % (dy)) | |
66 elif first: | |
67 append("\t0 hmoveto") | |
68 first = 0 | |
69 pen.x = pen.x+dx | |
70 pen.y = pen.y+dx | |
71 | |
72 def rlineto(v): | |
73 if v.x!=0: | |
74 if v.y!=0: | |
75 append("\t%i %i rlineto" % (v.x, v.y)) | |
76 else: | |
77 append("\t%i hlineto" % (v.x)) | |
78 elif v.y!=0: | |
79 append("\t%i vlineto" % (v.y)) | |
80 | |
81 def closepath(): | |
82 append("\tclosepath") | |
83 | |
84 history = [] | |
85 def movebase(x, y=0): | |
86 history.append((x,y)) | |
87 pen.move(-x, -y) | |
88 | |
89 def moveback(): | |
90 x, y = history.pop() | |
91 pen.move(x, y) | |
92 | |
93 def ellipse(rx, ry = None, half=0): | |
94 # rx>0 => counter-clockwise (filled) | |
95 # rx<0 => clockwise | |
96 | |
97 if ry==None: ry = abs(rx) | |
98 | |
99 dx1 = rint(k*rx) | |
100 dx2 = rx-dx1 | |
101 | |
102 dy1 = rint(k*ry) | |
103 dy2 = ry-dy1 | |
104 | |
105 rx = abs(rx) | |
106 moveto(0, -ry) | |
107 append("\t%i 0 %i %i 0 %i rrcurveto" % (+dx1, +dx2, +dy2, +dy1)) | |
108 append("\t0 %i %i %i %i 0 rrcurveto" % (+dy1, -dx2, +dy2, -dx1)) | |
109 if not half: | |
110 append("\t%i 0 %i %i 0 %i rrcurveto" % (-dx1, -dx2, -dy2, -dy1)) | |
111 append("\t0 %i %i %i %i 0 rrcurveto" % (-dy1, +dx2, -dy2, +dx1)) | |
112 closepath() | |
113 if half: | |
114 pen.set(0, ry) | |
115 else: | |
116 pen.set(0, -ry) | |
117 | |
118 circle = ellipse | |
119 | |
120 def rect(w, h): | |
121 moveto(0, 0) | |
122 if w>0: | |
123 append("\t%i hlineto" % (w)) | |
124 append("\t%i vlineto" % (h)) | |
125 append("\t%i hlineto" % (-w)) | |
126 pen.set(0, h) | |
127 else: | |
128 append("\t%i vlineto" % (h)) | |
129 append("\t%i hlineto" % (-w)) | |
130 append("\t%i vlineto" % (-h)) | |
131 pen.set(-w, 0) | |
132 closepath() | |
133 | |
134 def poly(p): | |
135 moveto(0, 0) | |
136 prev = vec(0, 0) | |
137 for q in p: | |
138 rlineto(vec(q)-prev) | |
139 prev = vec(q) | |
140 closepath() | |
141 pen.set(prev.x, prev.y) | |
142 | |
143 def line(w, l, a): | |
144 vw = pvec(w*.5, a-pi*.5) | |
145 vl = pvec(l, a) | |
146 p = vw | |
147 moveto(p.x, p.y) | |
148 p0 = p | |
149 #print '%%wla %i %i %.3f: %.3f %.3f' % (w, l, a, p0.x, p0.y) | |
150 p = p+vl | |
151 rlineto((p-p0).int()) | |
152 p0 = p | |
153 #print '%%wla %i %i %.3f: %.3f %.3f' % (w, l, a, p0.x, p0.y) | |
154 p = p-vw-vw | |
155 rlineto((p-p0).int()) | |
156 p0 = p | |
157 #print '%%wla %i %i %.3f: %.3f %.3f' % (w, l, a, p0.x, p0.y) | |
158 p = p-vl | |
159 #print '%%wla %i %i %.3f: %.3f %.3f' % (w, l, a, p.x, p.y) | |
160 rlineto((p-p0).int()) | |
161 closepath() | |
162 pen.set(p.x, p.y) | |
163 | |
164 | |
165 def begin(name, code, hsb, w): | |
166 global first, count, history | |
167 history = [] | |
168 pen.set(0, 0) | |
169 append("""\ | |
170 /uni%04X { %% %s | |
171 %i %i hsbw""" % (code+0xE000, name, hsb, w)) | |
172 i = len(encoding) | |
173 while i<code: | |
174 encoding.append('dup %i /.notdef put' % (i,)) | |
175 i = i+1 | |
176 encoding.append('dup %i /uni%04X put' % (code, code+0xE000)) | |
177 count = count + 1 | |
178 first = 1 | |
179 | |
180 | |
181 def end(): | |
182 append("""\ | |
183 endchar | |
184 } ND""") | |
185 | |
186 | |
187 | |
188 ######################################## | |
189 | |
190 r = 400 | |
191 s = 375 | |
192 hsb = 200 # horizontal side bearing | |
193 hsb2 = 30 | |
194 over = 10 # overshoot | |
195 width = 2*r+2*over+2*hsb2 | |
196 | |
197 ######################################## | |
198 begin('play', 0x01, hsb, width) | |
199 poly(( (s,r), | |
200 (0, 2*r),)) | |
201 end() | |
202 | |
203 | |
204 ######################################## | |
205 w=150 | |
206 begin('pause', 0x02, hsb, width) | |
207 rect(w, 2*r) | |
208 movebase(2*w) | |
209 rect(w, 2*r) | |
210 end() | |
211 | |
212 | |
213 ######################################## | |
214 begin('stop', 0x03, hsb, width) | |
215 rect(665, 720) | |
216 end() | |
217 | |
218 | |
219 ######################################## | |
220 begin('rewind', 0x04, hsb/2, width) | |
221 movebase(2*s+15) | |
222 poly(( (0, 2*r), | |
223 (-s, r),)) | |
224 movebase(-s-15) | |
225 poly(( (0, 2*r), | |
226 (-s, r),)) | |
227 end() | |
228 | |
229 | |
230 ######################################## | |
231 begin('fast forward', 0x05, hsb/2, width) | |
232 poly(( (s,r), | |
233 (0, 2*r),)) | |
234 movebase(s+15) | |
235 poly(( (s,r), | |
236 (0, 2*r),)) | |
237 end() | |
238 | |
239 | |
240 ######################################## | |
241 begin('clock', 0x06, hsb2, width) | |
242 movebase(r, r) | |
243 circle(r+over) | |
244 wc = 65 | |
245 r0 = r-3*wc | |
246 n = 4 | |
247 movebase(-wc/2, -wc/2) | |
248 rect(-wc, wc) | |
249 moveback() | |
250 for i in range(n): | |
251 a = i*2*pi/n | |
252 v = pvec(r0, a) | |
253 movebase(v.x, v.y) | |
254 line(-wc, r-r0, a) | |
255 moveback() | |
256 hh = 11 | |
257 mm = 8 | |
258 line(-50, r*.5, pi/2-2*pi*(hh+mm/60.)/12) | |
259 line(-40, r*.9, pi/2-2*pi*mm/60.) | |
260 end() | |
261 | |
262 | |
263 ######################################## | |
264 begin('contrast', 0x07, hsb2, width) | |
265 movebase(r, r) | |
266 circle(r+over) | |
267 circle(-(r+over-80), half=1) | |
268 end() | |
269 | |
270 | |
271 ######################################## | |
272 begin('saturation', 0x08, hsb2, width) | |
273 movebase(r, r) | |
274 circle(r+over) | |
275 circle(-(r+over-80)) | |
276 | |
277 v = pvec(160, pi/2) | |
278 movebase(v.x, v.y) | |
279 circle(80) | |
280 moveback() | |
281 | |
282 v = pvec(160, pi/2+pi*2/3) | |
283 movebase(v.x, v.y) | |
284 circle(80) | |
285 moveback() | |
286 | |
287 v = pvec(160, pi/2-pi*2/3) | |
288 movebase(v.x, v.y) | |
289 circle(80) | |
290 end() | |
291 | |
292 | |
293 ######################################## | |
294 begin('volume', 0x09, 0, 1000) | |
295 poly(( (1000, 0), | |
296 (0, 500),)) | |
297 end() | |
298 | |
299 | |
300 ######################################## | |
301 begin('brightness', 0x0A, hsb2, width) | |
302 movebase(r, r) | |
303 circle(150) | |
304 circle(-100) | |
305 | |
306 rb = 375 | |
307 wb = 50 | |
308 l = 140 | |
309 n = 8 | |
310 for i in range(n): | |
311 a = i*2*pi/n | |
312 v = pvec(l, a) | |
313 movebase(v.x, v.y) | |
314 line(wb, rb-l, a) | |
315 moveback() | |
316 end() | |
317 | |
318 | |
319 ######################################## | |
320 begin('hue', 0x0B, hsb2, width) | |
321 movebase(r, r) | |
322 circle(r+over) | |
323 ellipse(-(322), 166) | |
324 movebase(0, 280) | |
325 circle(-(60)) | |
326 end() | |
327 | |
328 | |
329 ######################################## | |
330 begin('progress [', 0x10, (334-182)/2, 334) | |
331 poly(( (182, 0), | |
332 (182, 90), | |
333 (145, 90), | |
334 (145, 550), | |
335 (182, 550), | |
336 (182, 640), | |
337 (0, 640), | |
338 )) | |
339 end() | |
340 | |
341 | |
342 ######################################## | |
343 begin('progress |', 0x11, (334-166)/2, 334) | |
344 rect(166, 640) | |
345 end() | |
346 | |
347 | |
348 ######################################## | |
349 begin('progress ]', 0x12, (334-182)/2, 334) | |
350 poly(( (182, 0), | |
351 (182, 640), | |
352 (0, 640), | |
353 (0, 550), | |
354 (37, 550), | |
355 (37, 90), | |
356 (0, 90), | |
357 )) | |
358 end() | |
359 | |
360 | |
361 ######################################## | |
362 begin('progress .', 0x13, (334-130)/2, 334) | |
363 movebase(0, (640-130)/2) | |
364 rect(130, 130) | |
365 end() | |
366 | |
367 | |
368 | |
369 ######################################## | |
370 print """\ | |
371 %!PS-AdobeFont-1.0: OSD 1.00 | |
372 %%CreationDate: Sun Jul 22 12:38:28 2001 | |
373 % | |
374 %%EndComments | |
375 12 dict begin | |
376 /FontInfo 9 dict dup begin | |
377 /version (Version 1.00) readonly def | |
378 /Notice () readonly def | |
379 /FullName (OSD) readonly def | |
380 /FamilyName (OSD) readonly def | |
381 /Weight (Regular) readonly def | |
382 /ItalicAngle 0.000000 def | |
383 /isFixedPitch false def | |
384 /UnderlinePosition -133 def | |
385 /UnderlineThickness 49 def | |
386 end readonly def | |
387 /FontName /OSD def | |
388 /PaintType 0 def | |
389 /StrokeWidth 0 def | |
390 /FontMatrix [0.001 0 0 0.001 0 0] def | |
391 /FontBBox {0 -10 1000 800} readonly def | |
392 /Encoding 256 array""" | |
393 | |
394 print string.join(encoding, '\n') | |
395 i = len(encoding) | |
396 while i<256: | |
397 print 'dup %i /.notdef put' % i | |
398 i = i+1 | |
399 | |
400 | |
401 print """\ | |
402 readonly def | |
403 currentdict end | |
404 currentfile eexec | |
405 dup /Private 15 dict dup begin | |
406 /RD{string currentfile exch readstring pop}executeonly def | |
407 /ND{noaccess def}executeonly def | |
408 /NP{noaccess put}executeonly def | |
409 /ForceBold false def | |
410 /BlueValues [ -15 0 717 734 693 708 630 649 593 611 658 679 780 800 ] def | |
411 /OtherBlues [ -112 -93 -200 -178 -45 -26 -134 -116 -71 -51 ] def | |
412 /StdHW [ 7 ] def | |
413 /StdVW [ 8 ] def | |
414 /StemSnapH [ 4 7 10 13 18 22 27 30 33 38 61 65 ] def | |
415 /StemSnapV [ 5 8 11 15 18 21 25 30 33 36 52 64 ] def | |
416 /MinFeature {16 16} def | |
417 /password 5839 def | |
418 /Subrs 1 array | |
419 dup 0 { | |
420 return | |
421 } NP | |
422 ND | |
423 2 index | |
424 /CharStrings %i dict dup begin""" % count | |
425 | |
426 print """\ | |
427 /.notdef { | |
428 0 400 hsbw | |
429 endchar | |
430 } ND""" | |
431 | |
432 print string.join(chars, '\n') | |
433 | |
434 | |
435 print """\ | |
436 end | |
437 end | |
438 readonly put | |
439 noaccess put | |
440 dup/FontName get exch definefont pop | |
441 mark currentfile closefile""" |