summaryrefslogtreecommitdiffstats
path: root/TOOLS/subfont-c/osd/gen.py
blob: 03080b81307805699001e83bf8e5ba7f0ba4d5db (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
#!/usr/bin/python

from math import *
import sys
import string

k = (sqrt(2.)-1.)*4./3.

chars = []
encoding = []
count = 1
first = 1

def append(s):
    chars.append(s)

def rint(x):
    return int(round(x))
"""
    if x>=0:
	return int(x+0.5)
    else:
	return int(x-0.5)
"""

class vec:
    def __init__(self, x, y=0):
        if type(x) is type(()):
	    self.x, self.y = x
	else:
	    self.x = x
	    self.y = y
    def set(self, x, y):
        self.__init__(x, y)
    def move(self, x, y):
        self.x = self.x + x
        self.y = self.y + y
    def __add__(self, v):
        return vec(self.x+v.x, self.y+v.y)
    def __sub__(self, v):
        return vec(self.x-v.x, self.y-v.y)
    def int(self):
        return vec(rint(self.x), rint(self.y))
    def t(self):
        return (self.x, self.y)

class pvec(vec):
    def __init__(self, l, a):
        self.x = l * cos(a)
        self.y = l * sin(a)


pen = vec(0,0)

def moveto(x, y=0):
    global first
    dx = rint(x-pen.x)
    dy = rint(y-pen.y)
    if dx!=0:
        if dy!=0:
	    append("\t%i %i rmoveto" % (dx, dy))
	else:
	    append("\t%i hmoveto" % (dx))
    elif dy!=0:
	    append("\t%i vmoveto" % (dy))
    elif first:
	    append("\t0 hmoveto")
	    first = 0
    pen.x = pen.x+dx
    pen.y = pen.y+dx

def rlineto(v):
    if v.x!=0:
        if v.y!=0:
	    append("\t%i %i rlineto" % (v.x, v.y))
	else:
	    append("\t%i hlineto" % (v.x))
    elif v.y!=0:
	    append("\t%i vlineto" % (v.y))

def closepath():
    append("\tclosepath")

history = []
def movebase(x, y=0):
    history.append((x,y))
    pen.move(-x, -y)

def moveback():
    x, y = history.pop()
    pen.move(x, y)

def ellipse(rx, ry = None, half=0):
    # rx>0 => counter-clockwise (filled)
    # rx<0 => clockwise

    if ry==None: ry = abs(rx)

    dx1 = rint(k*rx)
    dx2 = rx-dx1

    dy1 = rint(k*ry)
    dy2 = ry-dy1

    rx = abs(rx)
    moveto(0, -ry)
    append("\t%i 0 %i %i 0 %i rrcurveto" % (+dx1, +dx2, +dy2, +dy1))
    append("\t0 %i %i %i %i 0 rrcurveto" % (+dy1, -dx2, +dy2, -dx1))
    if not half:
	append("\t%i 0 %i %i 0 %i rrcurveto" % (-dx1, -dx2, -dy2, -dy1))
	append("\t0 %i %i %i %i 0 rrcurveto" % (-dy1, +dx2, -dy2, +dx1))
    closepath()
    if half:
	pen.set(0, ry)
    else:
	pen.set(0, -ry)

circle = ellipse

def rect(w, h):
    moveto(0, 0)
    if w>0:
	append("\t%i hlineto" % (w))
	append("\t%i vlineto" % (h))
	append("\t%i hlineto" % (-w))
	pen.set(0, h)
    else:
	append("\t%i vlineto" % (h))
	append("\t%i hlineto" % (-w))
	append("\t%i vlineto" % (-h))
	pen.set(-w, 0)
    closepath()

def poly(p):
    moveto(0, 0)
    prev = vec(0, 0)
    for q in p:
        rlineto(vec(q)-prev)
	prev = vec(q)
    closepath()
    pen.set(prev.x, prev.y)

def line(w, l, a):
    vw = pvec(w*.5, a-pi*.5)
    vl = pvec(l, a)
    p = vw
    moveto(p.x, p.y)
    p0 = p
    #print '%%wla %i %i %.3f: %.3f %.3f' % (w, l, a, p0.x, p0.y)
    p = p+vl
    rlineto((p-p0).int())
    p0 = p
    #print '%%wla %i %i %.3f: %.3f %.3f' % (w, l, a, p0.x, p0.y)
    p = p-vw-vw
    rlineto((p-p0).int())
    p0 = p
    #print '%%wla %i %i %.3f: %.3f %.3f' % (w, l, a, p0.x, p0.y)
    p = p-vl
    #print '%%wla %i %i %.3f: %.3f %.3f' % (w, l, a, p.x, p.y)
    rlineto((p-p0).int())
    closepath()
    pen.set(p.x, p.y)


def begin(name, code, hsb, w):
    global first, count, history
    history = []
    pen.set(0, 0)
    append("""\
/uni%04X { %% %s
	%i %i hsbw""" % (code+0xE000, name, hsb, w))
    i = len(encoding)
    while i<code:
	encoding.append('dup %i /.notdef put' % (i,))
	i = i+1
    encoding.append('dup %i /uni%04X put' % (code, code+0xE000))
    count = count + 1
    first = 1


def end():
    append("""\
	endchar
} ND""")



########################################

r = 400
s = 375
hsb = 200	# horizontal side bearing
hsb2 = 30
over = 10	# overshoot
width = 2*r+2*over+2*hsb2

########################################
begin('play', 0x01, hsb, width)
poly((  (s,r),
	(0, 2*r),))
end()


########################################
w=150
begin('pause', 0x02, hsb, width)
rect(w, 2*r)
movebase(2*w)
rect(w, 2*r)
end()


########################################
begin('stop', 0x03, hsb, width)
rect(665, 720)
end()


########################################
begin('rewind', 0x04, hsb/2, width)
movebase(2*s+15)
poly((  (0, 2*r),
	(-s, r),))
movebase(-s-15)
poly((  (0, 2*r),
	(-s, r),))
end()


########################################
begin('fast forward', 0x05, hsb/2, width)
poly((  (s,r),
	(0, 2*r),))
movebase(s+15)
poly((  (s,r),
	(0, 2*r),))
end()


########################################
begin('clock', 0x06, hsb2, width)
movebase(r, r)
circle(r+over)
wc = 65
r0 = r-3*wc
n = 4
movebase(-wc/2, -wc/2)
rect(-wc, wc)
moveback()
for i in range(n):
    a = i*2*pi/n
    v = pvec(r0, a)
    movebase(v.x, v.y)
    line(-wc, r-r0, a)
    moveback()
hh = 11
mm = 8
line(-50, r*.5, pi/2-2*pi*(hh+mm/60.)/12)
line(-40, r*.9, pi/2-2*pi*mm/60.)
end()


########################################
begin('contrast', 0x07, hsb2, width)
movebase(r, r)
circle(r+over)
circle(-(r+over-80), half=1)
end()


########################################
begin('saturation', 0x08, hsb2, width)
movebase(r, r)
circle(r+over)
circle(-(r+over-80))

v = pvec(160, pi/2)
movebase(v.x, v.y)
circle(80)
moveback()

v = pvec(160, pi/2+pi*2/3)
movebase(v.x, v.y)
circle(80)
moveback()

v = pvec(160, pi/2-pi*2/3)
movebase(v.x, v.y)
circle(80)
end()


########################################
begin('volume', 0x09, 0, 1000)
poly((  (1000, 0),
	(0, 500),))
end()


########################################
begin('brightness', 0x0A, hsb2, width)
movebase(r, r)
circle(150)
circle(-100)

rb = 375
wb = 50
l = 140
n = 8
for i in range(n):
    a = i*2*pi/n
    v = pvec(l, a)
    movebase(v.x, v.y)
    line(wb, rb-l, a)
    moveback()
end()


########################################
begin('hue', 0x0B, hsb2, width)
movebase(r, r)
circle(r+over)
ellipse(-(322), 166)
movebase(0, 280)
circle(-(60))
end()


########################################
begin('progress [', 0x10, (334-182)/2, 334)
poly((  (182, 0),
	(182, 90),
	(145, 90),
	(145, 550),
	(182, 550),
	(182, 640),
	(0, 640),
))
end()


########################################
begin('progress |', 0x11, (334-166)/2, 334)
rect(166, 640)
end()


########################################
begin('progress ]', 0x12, (334-182)/2, 334)
poly((  (182, 0),
	(182, 640),
	(0, 640),
	(0, 550),
	(37, 550),
	(37, 90),
	(0, 90),
))
end()


########################################
begin('progress .', 0x13, (334-130)/2, 334)
movebase(0, (640-130)/2)
rect(130, 130)
end()



########################################
print """\
%!PS-AdobeFont-1.0: OSD 1.00
%%CreationDate: Sun Jul 22 12:38:28 2001
%
%%EndComments
12 dict begin
/FontInfo 9 dict dup begin
/version (Version 1.00) readonly def
/Notice (This is generated file.) readonly def
/FullName (OSD) readonly def
/FamilyName (OSD) readonly def
/Weight (Regular) readonly def
/ItalicAngle 0.000000 def
/isFixedPitch false def
/UnderlinePosition -133 def
/UnderlineThickness 49 def
end readonly def
/FontName /OSD def
/PaintType 0 def
/StrokeWidth 0 def
/FontMatrix [0.001 0 0 0.001 0 0] def
/FontBBox {0 -10 1000 800} readonly def
/Encoding 256 array"""

print string.join(encoding, '\n')
i = len(encoding)
while i<256:
    print 'dup %i /.notdef put' % i
    i = i+1


print """\
readonly def
currentdict end
currentfile eexec
dup /Private 15 dict dup begin
/RD{string currentfile exch readstring pop}executeonly def
/ND{noaccess def}executeonly def
/NP{noaccess put}executeonly def
/ForceBold false def
/BlueValues [ -15 0 717 734 693 708 630 649 593 611 658 679 780 800 ] def
/OtherBlues [ -112 -93 -200 -178 -45 -26 -134 -116 -71 -51 ] def
/StdHW [ 7 ] def
/StdVW [ 8 ] def
/StemSnapH [ 4 7 10 13 18 22 27 30 33 38 61 65 ] def
/StemSnapV [ 5 8 11 15 18 21 25 30 33 36 52 64 ] def
/MinFeature {16 16} def
/password 5839 def
/Subrs 1 array
dup 0 {
	return
	} NP
 ND
2 index
/CharStrings %i dict dup begin""" % count

print """\
/.notdef {
	0 400 hsbw
	endchar
} ND"""

print string.join(chars, '\n')


print """\
end
end
readonly put
noaccess put
dup/FontName get exch definefont pop
mark currentfile closefile"""